blob: b4d914dbbe28119013d294fca08a24e8b74f0c51 [file] [log] [blame]
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001/* //device/libs/telephony/ril.cpp
2**
3** Copyright 2006, The Android Open Source Project
4**
Wink Saville7f856802009-06-09 10:23:37 -07005** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08008**
Wink Saville7f856802009-06-09 10:23:37 -07009** http://www.apache.org/licenses/LICENSE-2.0
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080010**
Wink Saville7f856802009-06-09 10:23:37 -070011** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080015** limitations under the License.
16*/
17
18#define LOG_TAG "RILC"
19
20#include <hardware_legacy/power.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080021#include <telephony/ril.h>
Wink Savillef4c4d362009-04-02 01:37:03 -070022#include <telephony/ril_cdma_sms.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080023#include <cutils/sockets.h>
24#include <cutils/jstring.h>
Dima Zavin622bf2b2013-05-22 11:29:34 -070025#include <telephony/record_stream.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080026#include <utils/Log.h>
27#include <utils/SystemClock.h>
28#include <pthread.h>
Mathias Agopian8a3c48c2009-05-19 19:11:50 -070029#include <binder/Parcel.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080030#include <cutils/jstring.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080031#include <sys/types.h>
Wink Saville18e4ab12013-04-07 17:31:04 -070032#include <sys/limits.h>
Sanket Padawe88cf6a52016-01-11 12:45:43 -080033#include <sys/system_properties.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080034#include <pwd.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080035#include <stdio.h>
36#include <stdlib.h>
37#include <stdarg.h>
38#include <string.h>
39#include <unistd.h>
40#include <fcntl.h>
41#include <time.h>
42#include <errno.h>
43#include <assert.h>
44#include <ctype.h>
45#include <alloca.h>
46#include <sys/un.h>
47#include <assert.h>
48#include <netinet/in.h>
49#include <cutils/properties.h>
Dheeraj Shetty27976c42014-07-02 21:27:57 +020050#include <RilSapSocket.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080051
Dheeraj Shetty27976c42014-07-02 21:27:57 +020052extern "C" void
53RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen);
Sanket Padawe6ff9a872016-01-27 15:09:12 -080054
55extern "C" void
56RIL_onRequestAck(RIL_Token t);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080057namespace android {
58
59#define PHONE_PROCESS "radio"
Dheeraj Shetty27976c42014-07-02 21:27:57 +020060#define BLUETOOTH_PROCESS "bluetooth"
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080061
62#define SOCKET_NAME_RIL "rild"
Etan Cohend3652192014-06-20 08:28:44 -070063#define SOCKET2_NAME_RIL "rild2"
64#define SOCKET3_NAME_RIL "rild3"
65#define SOCKET4_NAME_RIL "rild4"
66
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080067#define SOCKET_NAME_RIL_DEBUG "rild-debug"
68
69#define ANDROID_WAKE_LOCK_NAME "radio-interface"
70
Nathan Harolda0153392015-07-28 14:54:58 -070071#define ANDROID_WAKE_LOCK_SECS 0
72#define ANDROID_WAKE_LOCK_USECS 200000
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080073
74#define PROPERTY_RIL_IMPL "gsm.version.ril-impl"
75
76// match with constant in RIL.java
77#define MAX_COMMAND_BYTES (8 * 1024)
78
79// Basically: memset buffers that the client library
80// shouldn't be using anymore in an attempt to find
81// memory usage issues sooner.
82#define MEMSET_FREED 1
83
84#define NUM_ELEMS(a) (sizeof (a) / sizeof (a)[0])
85
Wink Savillef4c4d362009-04-02 01:37:03 -070086#define MIN(a,b) ((a)<(b) ? (a) : (b))
87
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080088/* Constants for response types */
89#define RESPONSE_SOLICITED 0
90#define RESPONSE_UNSOLICITED 1
Sanket Padawe6ff9a872016-01-27 15:09:12 -080091#define RESPONSE_SOLICITED_ACK 2
92#define RESPONSE_SOLICITED_ACK_EXP 3
Sanket Padawed8c0b462016-02-03 11:46:02 -080093#define RESPONSE_UNSOLICITED_ACK_EXP 4
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080094
95/* Negative values for private RIL errno's */
96#define RIL_ERRNO_INVALID_RESPONSE -1
Sanket Padawe55227b52016-02-29 10:09:26 -080097#define RIL_ERRNO_NO_MEMORY -12
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080098
99// request, response, and unsolicited msg print macro
100#define PRINTBUF_SIZE 8096
101
Robert Greenwalt191e4dc2015-04-29 16:57:39 -0700102// Enable verbose logging
103#define VDBG 0
104
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800105// Enable RILC log
106#define RILC_LOG 0
107
108#if RILC_LOG
109 #define startRequest sprintf(printBuf, "(")
110 #define closeRequest sprintf(printBuf, "%s)", printBuf)
111 #define printRequest(token, req) \
Wink Saville8eb2a122012-11-19 16:05:13 -0800112 RLOGD("[%04d]> %s %s", token, requestToString(req), printBuf)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800113
114 #define startResponse sprintf(printBuf, "%s {", printBuf)
115 #define closeResponse sprintf(printBuf, "%s}", printBuf)
Wink Saville8eb2a122012-11-19 16:05:13 -0800116 #define printResponse RLOGD("%s", printBuf)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800117
118 #define clearPrintBuf printBuf[0] = 0
119 #define removeLastChar printBuf[strlen(printBuf)-1] = 0
120 #define appendPrintBuf(x...) sprintf(printBuf, x)
121#else
122 #define startRequest
123 #define closeRequest
124 #define printRequest(token, req)
125 #define startResponse
126 #define closeResponse
127 #define printResponse
128 #define clearPrintBuf
129 #define removeLastChar
130 #define appendPrintBuf(x...)
131#endif
132
133enum WakeType {DONT_WAKE, WAKE_PARTIAL};
134
135typedef struct {
136 int requestNumber;
137 void (*dispatchFunction) (Parcel &p, struct RequestInfo *pRI);
138 int(*responseFunction) (Parcel &p, void *response, size_t responselen);
139} CommandInfo;
140
141typedef struct {
142 int requestNumber;
143 int (*responseFunction) (Parcel &p, void *response, size_t responselen);
144 WakeType wakeType;
145} UnsolResponseInfo;
146
147typedef struct RequestInfo {
Wink Saville7f856802009-06-09 10:23:37 -0700148 int32_t token; //this is not RIL_Token
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800149 CommandInfo *pCI;
150 struct RequestInfo *p_next;
151 char cancelled;
152 char local; // responses to local commands do not go back to command process
Etan Cohend3652192014-06-20 08:28:44 -0700153 RIL_SOCKET_ID socket_id;
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800154 int wasAckSent; // Indicates whether an ack was sent earlier
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800155} RequestInfo;
156
Wink Saville3d54e742009-05-18 18:00:44 -0700157typedef struct UserCallbackInfo {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800158 RIL_TimedCallback p_callback;
159 void *userParam;
160 struct ril_event event;
161 struct UserCallbackInfo *p_next;
162} UserCallbackInfo;
163
Etan Cohend3652192014-06-20 08:28:44 -0700164extern "C" const char * requestToString(int request);
165extern "C" const char * failCauseToString(RIL_Errno);
166extern "C" const char * callStateToString(RIL_CallState);
167extern "C" const char * radioStateToString(RIL_RadioState);
168extern "C" const char * rilSocketIdToString(RIL_SOCKET_ID socket_id);
169
170extern "C"
171char rild[MAX_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800172/*******************************************************************/
173
174RIL_RadioFunctions s_callbacks = {0, NULL, NULL, NULL, NULL, NULL};
175static int s_registerCalled = 0;
176
177static pthread_t s_tid_dispatch;
178static pthread_t s_tid_reader;
179static int s_started = 0;
180
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800181static int s_fdDebug = -1;
Etan Cohend3652192014-06-20 08:28:44 -0700182static int s_fdDebug_socket2 = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800183
184static int s_fdWakeupRead;
185static int s_fdWakeupWrite;
186
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800187int s_wakelock_count = 0;
188
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800189static struct ril_event s_commands_event;
190static struct ril_event s_wakeupfd_event;
191static struct ril_event s_listen_event;
Etan Cohend3652192014-06-20 08:28:44 -0700192static SocketListenParam s_ril_param_socket;
193
194static pthread_mutex_t s_pendingRequestsMutex = PTHREAD_MUTEX_INITIALIZER;
195static pthread_mutex_t s_writeMutex = PTHREAD_MUTEX_INITIALIZER;
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800196static pthread_mutex_t s_wakeLockCountMutex = PTHREAD_MUTEX_INITIALIZER;
Etan Cohend3652192014-06-20 08:28:44 -0700197static RequestInfo *s_pendingRequests = NULL;
198
199#if (SIM_COUNT >= 2)
200static struct ril_event s_commands_event_socket2;
201static struct ril_event s_listen_event_socket2;
202static SocketListenParam s_ril_param_socket2;
203
204static pthread_mutex_t s_pendingRequestsMutex_socket2 = PTHREAD_MUTEX_INITIALIZER;
205static pthread_mutex_t s_writeMutex_socket2 = PTHREAD_MUTEX_INITIALIZER;
206static RequestInfo *s_pendingRequests_socket2 = NULL;
207#endif
208
209#if (SIM_COUNT >= 3)
210static struct ril_event s_commands_event_socket3;
211static struct ril_event s_listen_event_socket3;
212static SocketListenParam s_ril_param_socket3;
213
214static pthread_mutex_t s_pendingRequestsMutex_socket3 = PTHREAD_MUTEX_INITIALIZER;
215static pthread_mutex_t s_writeMutex_socket3 = PTHREAD_MUTEX_INITIALIZER;
216static RequestInfo *s_pendingRequests_socket3 = NULL;
217#endif
218
219#if (SIM_COUNT >= 4)
220static struct ril_event s_commands_event_socket4;
221static struct ril_event s_listen_event_socket4;
222static SocketListenParam s_ril_param_socket4;
223
224static pthread_mutex_t s_pendingRequestsMutex_socket4 = PTHREAD_MUTEX_INITIALIZER;
225static pthread_mutex_t s_writeMutex_socket4 = PTHREAD_MUTEX_INITIALIZER;
226static RequestInfo *s_pendingRequests_socket4 = NULL;
227#endif
228
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800229static struct ril_event s_wake_timeout_event;
230static struct ril_event s_debug_event;
231
232
Nathan Harolda0153392015-07-28 14:54:58 -0700233static const struct timeval TIMEVAL_WAKE_TIMEOUT = {ANDROID_WAKE_LOCK_SECS,ANDROID_WAKE_LOCK_USECS};
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800234
Etan Cohend3652192014-06-20 08:28:44 -0700235
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800236static pthread_mutex_t s_startupMutex = PTHREAD_MUTEX_INITIALIZER;
237static pthread_cond_t s_startupCond = PTHREAD_COND_INITIALIZER;
238
239static pthread_mutex_t s_dispatchMutex = PTHREAD_MUTEX_INITIALIZER;
240static pthread_cond_t s_dispatchCond = PTHREAD_COND_INITIALIZER;
241
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800242static RequestInfo *s_toDispatchHead = NULL;
243static RequestInfo *s_toDispatchTail = NULL;
244
245static UserCallbackInfo *s_last_wake_timeout_info = NULL;
246
247static void *s_lastNITZTimeData = NULL;
248static size_t s_lastNITZTimeDataSize;
249
250#if RILC_LOG
251 static char printBuf[PRINTBUF_SIZE];
252#endif
253
254/*******************************************************************/
Etan Cohend3652192014-06-20 08:28:44 -0700255static int sendResponse (Parcel &p, RIL_SOCKET_ID socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800256
257static void dispatchVoid (Parcel& p, RequestInfo *pRI);
258static void dispatchString (Parcel& p, RequestInfo *pRI);
259static void dispatchStrings (Parcel& p, RequestInfo *pRI);
260static void dispatchInts (Parcel& p, RequestInfo *pRI);
261static void dispatchDial (Parcel& p, RequestInfo *pRI);
262static void dispatchSIM_IO (Parcel& p, RequestInfo *pRI);
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800263static void dispatchSIM_APDU (Parcel& p, RequestInfo *pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800264static void dispatchCallForward(Parcel& p, RequestInfo *pRI);
265static void dispatchRaw(Parcel& p, RequestInfo *pRI);
266static void dispatchSmsWrite (Parcel &p, RequestInfo *pRI);
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -0700267static void dispatchDataCall (Parcel& p, RequestInfo *pRI);
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800268static void dispatchVoiceRadioTech (Parcel& p, RequestInfo *pRI);
Sungmin Choi75697532013-04-26 15:04:45 -0700269static void dispatchSetInitialAttachApn (Parcel& p, RequestInfo *pRI);
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800270static void dispatchCdmaSubscriptionSource (Parcel& p, RequestInfo *pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800271
Wink Savillef4c4d362009-04-02 01:37:03 -0700272static void dispatchCdmaSms(Parcel &p, RequestInfo *pRI);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -0700273static void dispatchImsSms(Parcel &p, RequestInfo *pRI);
274static void dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
275static void dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
Wink Savillef4c4d362009-04-02 01:37:03 -0700276static void dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI);
Wink Savillea592eeb2009-05-22 13:26:36 -0700277static void dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI);
Wink Savillef4c4d362009-04-02 01:37:03 -0700278static void dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI);
279static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI);
Jake Hamby8a4a2332014-01-15 13:12:05 -0800280static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI);
281static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI);
Etan Cohend3652192014-06-20 08:28:44 -0700282static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI);
Amit Mahajan90530a62014-07-01 15:54:08 -0700283static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI);
Amit Mahajanc796e222014-08-13 16:54:01 +0000284static void dispatchDataProfile(Parcel &p, RequestInfo *pRI);
Wink Saville8b4e4f72014-10-17 15:01:45 -0700285static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800286static int responseInts(Parcel &p, void *response, size_t responselen);
Chao Liu548a81e2015-05-14 16:13:46 -0700287static int responseFailCause(Parcel &p, void *response, size_t responselen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800288static int responseStrings(Parcel &p, void *response, size_t responselen);
289static int responseString(Parcel &p, void *response, size_t responselen);
290static int responseVoid(Parcel &p, void *response, size_t responselen);
291static int responseCallList(Parcel &p, void *response, size_t responselen);
292static int responseSMS(Parcel &p, void *response, size_t responselen);
293static int responseSIM_IO(Parcel &p, void *response, size_t responselen);
294static int responseCallForwards(Parcel &p, void *response, size_t responselen);
Wink Savillef4c4d362009-04-02 01:37:03 -0700295static int responseDataCallList(Parcel &p, void *response, size_t responselen);
Wink Saville43808972011-01-13 17:39:51 -0800296static int responseSetupDataCall(Parcel &p, void *response, size_t responselen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800297static int responseRaw(Parcel &p, void *response, size_t responselen);
298static int responseSsn(Parcel &p, void *response, size_t responselen);
Wink Savillef4c4d362009-04-02 01:37:03 -0700299static int responseSimStatus(Parcel &p, void *response, size_t responselen);
Wink Savillea592eeb2009-05-22 13:26:36 -0700300static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen);
301static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen);
Wink Savillef4c4d362009-04-02 01:37:03 -0700302static int responseCdmaSms(Parcel &p, void *response, size_t responselen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800303static int responseCellList(Parcel &p, void *response, size_t responselen);
Wink Saville3d54e742009-05-18 18:00:44 -0700304static int responseCdmaInformationRecords(Parcel &p,void *response, size_t responselen);
305static int responseRilSignalStrength(Parcel &p,void *response, size_t responselen);
306static int responseCallRing(Parcel &p, void *response, size_t responselen);
307static int responseCdmaSignalInfoRecord(Parcel &p,void *response, size_t responselen);
308static int responseCdmaCallWaiting(Parcel &p,void *response, size_t responselen);
Alex Yakavenka45e740e2012-01-31 11:48:27 -0800309static int responseSimRefresh(Parcel &p, void *response, size_t responselen);
Wink Saville8a9e0212013-04-09 12:11:38 -0700310static int responseCellInfoList(Parcel &p, void *response, size_t responselen);
Etan Cohend3652192014-06-20 08:28:44 -0700311static int responseHardwareConfig(Parcel &p, void *response, size_t responselen);
Wink Savillec29360a2014-07-13 05:17:28 -0700312static int responseDcRtInfo(Parcel &p, void *response, size_t responselen);
Wink Saville8b4e4f72014-10-17 15:01:45 -0700313static int responseRadioCapability(Parcel &p, void *response, size_t responselen);
Amit Mahajan54563d32014-11-22 00:54:49 +0000314static int responseSSData(Parcel &p, void *response, size_t responselen);
fengluf7408292015-04-14 14:53:55 -0700315static int responseLceStatus(Parcel &p, void *response, size_t responselen);
316static int responseLceData(Parcel &p, void *response, size_t responselen);
Prerepa Viswanadham73157492015-05-28 00:37:32 -0700317static int responseActivityData(Parcel &p, void *response, size_t responselen);
Amit Mahajan54563d32014-11-22 00:54:49 +0000318
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800319static int decodeVoiceRadioTechnology (RIL_RadioState radioState);
320static int decodeCdmaSubscriptionSource (RIL_RadioState radioState);
321static RIL_RadioState processRadioState(RIL_RadioState newRadioState);
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800322static void grabPartialWakeLock();
323static void releaseWakeLock();
324static void wakeTimeoutCallback(void *);
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800325
Amit Mahajan54563d32014-11-22 00:54:49 +0000326static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType);
327
Sanket Padawe88cf6a52016-01-11 12:45:43 -0800328static bool isDebuggable();
329
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800330#ifdef RIL_SHLIB
Etan Cohend3652192014-06-20 08:28:44 -0700331#if defined(ANDROID_MULTI_SIM)
Vinit Deshpande1b1ec2d2015-04-15 13:31:05 -0700332extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Etan Cohend3652192014-06-20 08:28:44 -0700333 size_t datalen, RIL_SOCKET_ID socket_id);
334#else
Vinit Deshpande1b1ec2d2015-04-15 13:31:05 -0700335extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800336 size_t datalen);
337#endif
Etan Cohend3652192014-06-20 08:28:44 -0700338#endif
339
340#if defined(ANDROID_MULTI_SIM)
341#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c), (d))
342#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d), (e))
343#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest(a)
344#else
345#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c))
346#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d))
347#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest()
348#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800349
Wink Saville7f856802009-06-09 10:23:37 -0700350static UserCallbackInfo * internalRequestTimedCallback
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -0700351 (RIL_TimedCallback callback, void *param,
352 const struct timeval *relativeTime);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800353
354/** Index == requestNumber */
355static CommandInfo s_commands[] = {
356#include "ril_commands.h"
357};
358
359static UnsolResponseInfo s_unsolResponses[] = {
360#include "ril_unsol_commands.h"
361};
362
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800363/* For older RILs that do not support new commands RIL_REQUEST_VOICE_RADIO_TECH and
364 RIL_UNSOL_VOICE_RADIO_TECH_CHANGED messages, decode the voice radio tech from
365 radio state message and store it. Every time there is a change in Radio State
366 check to see if voice radio tech changes and notify telephony
367 */
368int voiceRadioTech = -1;
369
370/* For older RILs that do not support new commands RIL_REQUEST_GET_CDMA_SUBSCRIPTION_SOURCE
371 and RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED messages, decode the subscription
372 source from radio state and store it. Every time there is a change in Radio State
373 check to see if subscription source changed and notify telephony
374 */
375int cdmaSubscriptionSource = -1;
376
377/* For older RILs that do not send RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, decode the
378 SIM/RUIM state from radio state and store it. Every time there is a change in Radio State,
379 check to see if SIM/RUIM status changed and notify telephony
380 */
381int simRuimStatus = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800382
Etan Cohend3652192014-06-20 08:28:44 -0700383static char * RIL_getRilSocketName() {
384 return rild;
385}
386
387extern "C"
Dheeraj Shetty27976c42014-07-02 21:27:57 +0200388void RIL_setRilSocketName(const char * s) {
Etan Cohend3652192014-06-20 08:28:44 -0700389 strncpy(rild, s, MAX_SOCKET_NAME_LENGTH);
390}
391
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800392static char *
Wink Savillef4c4d362009-04-02 01:37:03 -0700393strdupReadString(Parcel &p) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800394 size_t stringlen;
395 const char16_t *s16;
Wink Saville7f856802009-06-09 10:23:37 -0700396
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800397 s16 = p.readString16Inplace(&stringlen);
Wink Saville7f856802009-06-09 10:23:37 -0700398
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800399 return strndup16to8(s16, stringlen);
400}
401
Wink Saville8b4e4f72014-10-17 15:01:45 -0700402static status_t
403readStringFromParcelInplace(Parcel &p, char *str, size_t maxLen) {
404 size_t s16Len;
405 const char16_t *s16;
406
407 s16 = p.readString16Inplace(&s16Len);
408 if (s16 == NULL) {
409 return NO_MEMORY;
410 }
411 size_t strLen = strnlen16to8(s16, s16Len);
412 if ((strLen + 1) > maxLen) {
413 return NO_MEMORY;
414 }
415 if (strncpy16to8(str, s16, strLen) == NULL) {
416 return NO_MEMORY;
417 } else {
418 return NO_ERROR;
419 }
420}
421
Wink Savillef4c4d362009-04-02 01:37:03 -0700422static void writeStringToParcel(Parcel &p, const char *s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800423 char16_t *s16;
424 size_t s16_len;
425 s16 = strdup8to16(s, &s16_len);
426 p.writeString16(s16, s16_len);
427 free(s16);
428}
429
430
431static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700432memsetString (char *s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800433 if (s != NULL) {
434 memset (s, 0, strlen(s));
435 }
436}
437
438void nullParcelReleaseFunction (const uint8_t* data, size_t dataSize,
439 const size_t* objects, size_t objectsSize,
Wink Savillef4c4d362009-04-02 01:37:03 -0700440 void* cookie) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800441 // do nothing -- the data reference lives longer than the Parcel object
442}
443
Wink Saville7f856802009-06-09 10:23:37 -0700444/**
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800445 * To be called from dispatch thread
446 * Issue a single local request, ensuring that the response
Wink Saville7f856802009-06-09 10:23:37 -0700447 * is not sent back up to the command process
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800448 */
449static void
Etan Cohend3652192014-06-20 08:28:44 -0700450issueLocalRequest(int request, void *data, int len, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800451 RequestInfo *pRI;
452 int ret;
Etan Cohend3652192014-06-20 08:28:44 -0700453 /* Hook for current context */
454 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
455 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
456 /* pendingRequestsHook refer to &s_pendingRequests */
457 RequestInfo** pendingRequestsHook = &s_pendingRequests;
458
459#if (SIM_COUNT == 2)
460 if (socket_id == RIL_SOCKET_2) {
461 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
462 pendingRequestsHook = &s_pendingRequests_socket2;
463 }
464#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800465
466 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
Sanket Padawe55227b52016-02-29 10:09:26 -0800467 if (pRI == NULL) {
468 RLOGE("Memory allocation failed for request %s", requestToString(request));
469 return;
470 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800471
472 pRI->local = 1;
473 pRI->token = 0xffffffff; // token is not used in this context
474 pRI->pCI = &(s_commands[request]);
Etan Cohend3652192014-06-20 08:28:44 -0700475 pRI->socket_id = socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800476
Etan Cohend3652192014-06-20 08:28:44 -0700477 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800478 assert (ret == 0);
479
Etan Cohend3652192014-06-20 08:28:44 -0700480 pRI->p_next = *pendingRequestsHook;
481 *pendingRequestsHook = pRI;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800482
Etan Cohend3652192014-06-20 08:28:44 -0700483 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800484 assert (ret == 0);
485
Wink Saville8eb2a122012-11-19 16:05:13 -0800486 RLOGD("C[locl]> %s", requestToString(request));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800487
Etan Cohend3652192014-06-20 08:28:44 -0700488 CALL_ONREQUEST(request, data, len, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800489}
490
491
492
493static int
Etan Cohend3652192014-06-20 08:28:44 -0700494processCommandBuffer(void *buffer, size_t buflen, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800495 Parcel p;
496 status_t status;
497 int32_t request;
498 int32_t token;
499 RequestInfo *pRI;
500 int ret;
Etan Cohend3652192014-06-20 08:28:44 -0700501 /* Hook for current context */
502 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
503 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
504 /* pendingRequestsHook refer to &s_pendingRequests */
505 RequestInfo** pendingRequestsHook = &s_pendingRequests;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800506
507 p.setData((uint8_t *) buffer, buflen);
508
509 // status checked at end
510 status = p.readInt32(&request);
511 status = p.readInt32 (&token);
512
Etan Cohend3652192014-06-20 08:28:44 -0700513#if (SIM_COUNT >= 2)
514 if (socket_id == RIL_SOCKET_2) {
515 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
516 pendingRequestsHook = &s_pendingRequests_socket2;
517 }
518#if (SIM_COUNT >= 3)
519 else if (socket_id == RIL_SOCKET_3) {
520 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
521 pendingRequestsHook = &s_pendingRequests_socket3;
522 }
523#endif
524#if (SIM_COUNT >= 4)
525 else if (socket_id == RIL_SOCKET_4) {
526 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
527 pendingRequestsHook = &s_pendingRequests_socket4;
528 }
529#endif
530#endif
531
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800532 if (status != NO_ERROR) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800533 RLOGE("invalid request block");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800534 return 0;
535 }
536
537 if (request < 1 || request >= (int32_t)NUM_ELEMS(s_commands)) {
Etan Cohend3652192014-06-20 08:28:44 -0700538 Parcel pErr;
Wink Saville8eb2a122012-11-19 16:05:13 -0800539 RLOGE("unsupported request code %d token %d", request, token);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800540 // FIXME this should perhaps return a response
Etan Cohend3652192014-06-20 08:28:44 -0700541 pErr.writeInt32 (RESPONSE_SOLICITED);
542 pErr.writeInt32 (token);
543 pErr.writeInt32 (RIL_E_GENERIC_FAILURE);
544
545 sendResponse(pErr, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800546 return 0;
547 }
548
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800549 // Received an Ack for the previous result sent to RIL.java,
550 // so release wakelock and exit
551 if (request == RIL_RESPONSE_ACKNOWLEDGEMENT) {
552 releaseWakeLock();
553 return 0;
554 }
555
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800556
557 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
Sanket Padawe55227b52016-02-29 10:09:26 -0800558 if (pRI == NULL) {
559 RLOGE("Memory allocation failed for request %s", requestToString(request));
560 return 0;
561 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800562
563 pRI->token = token;
564 pRI->pCI = &(s_commands[request]);
Etan Cohend3652192014-06-20 08:28:44 -0700565 pRI->socket_id = socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800566
Etan Cohend3652192014-06-20 08:28:44 -0700567 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800568 assert (ret == 0);
569
Etan Cohend3652192014-06-20 08:28:44 -0700570 pRI->p_next = *pendingRequestsHook;
571 *pendingRequestsHook = pRI;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800572
Etan Cohend3652192014-06-20 08:28:44 -0700573 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800574 assert (ret == 0);
575
576/* sLastDispatchedToken = token; */
577
Wink Saville7f856802009-06-09 10:23:37 -0700578 pRI->pCI->dispatchFunction(p, pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800579
580 return 0;
581}
582
583static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700584invalidCommandBlock (RequestInfo *pRI) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800585 RLOGE("invalid command block for token %d request %s",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800586 pRI->token, requestToString(pRI->pCI->requestNumber));
587}
588
589/** Callee expects NULL */
Wink Saville7f856802009-06-09 10:23:37 -0700590static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700591dispatchVoid (Parcel& p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800592 clearPrintBuf;
593 printRequest(pRI->token, pRI->pCI->requestNumber);
Etan Cohend3652192014-06-20 08:28:44 -0700594 CALL_ONREQUEST(pRI->pCI->requestNumber, NULL, 0, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800595}
596
597/** Callee expects const char * */
598static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700599dispatchString (Parcel& p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800600 status_t status;
601 size_t datalen;
602 size_t stringlen;
603 char *string8 = NULL;
604
605 string8 = strdupReadString(p);
606
607 startRequest;
608 appendPrintBuf("%s%s", printBuf, string8);
609 closeRequest;
610 printRequest(pRI->token, pRI->pCI->requestNumber);
611
Etan Cohend3652192014-06-20 08:28:44 -0700612 CALL_ONREQUEST(pRI->pCI->requestNumber, string8,
613 sizeof(char *), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800614
615#ifdef MEMSET_FREED
616 memsetString(string8);
617#endif
618
619 free(string8);
620 return;
621invalid:
622 invalidCommandBlock(pRI);
623 return;
624}
625
626/** Callee expects const char ** */
627static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700628dispatchStrings (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800629 int32_t countStrings;
630 status_t status;
631 size_t datalen;
632 char **pStrings;
633
634 status = p.readInt32 (&countStrings);
635
636 if (status != NO_ERROR) {
637 goto invalid;
638 }
639
640 startRequest;
641 if (countStrings == 0) {
642 // just some non-null pointer
643 pStrings = (char **)alloca(sizeof(char *));
Sanket Padawe55227b52016-02-29 10:09:26 -0800644 if (pStrings == NULL) {
645 RLOGE("Memory allocation failed for request %s",
646 requestToString(pRI->pCI->requestNumber));
647 closeRequest;
648 return;
649 }
650
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800651 datalen = 0;
652 } else if (((int)countStrings) == -1) {
653 pStrings = NULL;
654 datalen = 0;
655 } else {
656 datalen = sizeof(char *) * countStrings;
Wink Saville7f856802009-06-09 10:23:37 -0700657
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800658 pStrings = (char **)alloca(datalen);
Sanket Padawe55227b52016-02-29 10:09:26 -0800659 if (pStrings == NULL) {
660 RLOGE("Memory allocation failed for request %s",
661 requestToString(pRI->pCI->requestNumber));
662 closeRequest;
663 return;
664 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800665
666 for (int i = 0 ; i < countStrings ; i++) {
667 pStrings[i] = strdupReadString(p);
668 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
669 }
670 }
671 removeLastChar;
672 closeRequest;
673 printRequest(pRI->token, pRI->pCI->requestNumber);
674
Etan Cohend3652192014-06-20 08:28:44 -0700675 CALL_ONREQUEST(pRI->pCI->requestNumber, pStrings, datalen, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800676
677 if (pStrings != NULL) {
678 for (int i = 0 ; i < countStrings ; i++) {
679#ifdef MEMSET_FREED
680 memsetString (pStrings[i]);
681#endif
682 free(pStrings[i]);
683 }
684
685#ifdef MEMSET_FREED
686 memset(pStrings, 0, datalen);
687#endif
688 }
Wink Saville7f856802009-06-09 10:23:37 -0700689
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800690 return;
691invalid:
692 invalidCommandBlock(pRI);
693 return;
694}
695
696/** Callee expects const int * */
697static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700698dispatchInts (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800699 int32_t count;
700 status_t status;
701 size_t datalen;
702 int *pInts;
703
704 status = p.readInt32 (&count);
705
706 if (status != NO_ERROR || count == 0) {
707 goto invalid;
708 }
709
710 datalen = sizeof(int) * count;
711 pInts = (int *)alloca(datalen);
Sanket Padawe55227b52016-02-29 10:09:26 -0800712 if (pInts == NULL) {
713 RLOGE("Memory allocation failed for request %s", requestToString(pRI->pCI->requestNumber));
714 return;
715 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800716
717 startRequest;
718 for (int i = 0 ; i < count ; i++) {
719 int32_t t;
720
721 status = p.readInt32(&t);
722 pInts[i] = (int)t;
723 appendPrintBuf("%s%d,", printBuf, t);
724
725 if (status != NO_ERROR) {
726 goto invalid;
727 }
728 }
729 removeLastChar;
730 closeRequest;
731 printRequest(pRI->token, pRI->pCI->requestNumber);
732
Etan Cohend3652192014-06-20 08:28:44 -0700733 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<int *>(pInts),
734 datalen, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800735
736#ifdef MEMSET_FREED
737 memset(pInts, 0, datalen);
738#endif
739
740 return;
741invalid:
742 invalidCommandBlock(pRI);
743 return;
744}
745
746
Wink Saville7f856802009-06-09 10:23:37 -0700747/**
748 * Callee expects const RIL_SMS_WriteArgs *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800749 * Payload is:
750 * int32_t status
751 * String pdu
752 */
753static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700754dispatchSmsWrite (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800755 RIL_SMS_WriteArgs args;
756 int32_t t;
757 status_t status;
758
Mark Salyzyndba25612015-04-09 07:18:35 -0700759 RLOGD("dispatchSmsWrite");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800760 memset (&args, 0, sizeof(args));
761
762 status = p.readInt32(&t);
763 args.status = (int)t;
764
765 args.pdu = strdupReadString(p);
766
767 if (status != NO_ERROR || args.pdu == NULL) {
768 goto invalid;
769 }
770
771 args.smsc = strdupReadString(p);
772
773 startRequest;
774 appendPrintBuf("%s%d,%s,smsc=%s", printBuf, args.status,
775 (char*)args.pdu, (char*)args.smsc);
776 closeRequest;
777 printRequest(pRI->token, pRI->pCI->requestNumber);
Wink Saville7f856802009-06-09 10:23:37 -0700778
Etan Cohend3652192014-06-20 08:28:44 -0700779 CALL_ONREQUEST(pRI->pCI->requestNumber, &args, sizeof(args), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800780
781#ifdef MEMSET_FREED
782 memsetString (args.pdu);
783#endif
784
785 free (args.pdu);
Wink Saville7f856802009-06-09 10:23:37 -0700786
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800787#ifdef MEMSET_FREED
788 memset(&args, 0, sizeof(args));
789#endif
790
791 return;
792invalid:
793 invalidCommandBlock(pRI);
794 return;
795}
796
Wink Saville7f856802009-06-09 10:23:37 -0700797/**
798 * Callee expects const RIL_Dial *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800799 * Payload is:
800 * String address
801 * int32_t clir
802 */
803static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700804dispatchDial (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800805 RIL_Dial dial;
Wink Saville74fa3882009-12-22 15:35:41 -0800806 RIL_UUS_Info uusInfo;
Wink Saville7bce0822010-01-08 15:20:12 -0800807 int32_t sizeOfDial;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800808 int32_t t;
Wink Saville74fa3882009-12-22 15:35:41 -0800809 int32_t uusPresent;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800810 status_t status;
811
Mark Salyzyndba25612015-04-09 07:18:35 -0700812 RLOGD("dispatchDial");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800813 memset (&dial, 0, sizeof(dial));
814
815 dial.address = strdupReadString(p);
816
817 status = p.readInt32(&t);
818 dial.clir = (int)t;
819
820 if (status != NO_ERROR || dial.address == NULL) {
821 goto invalid;
822 }
823
Wink Saville3a4840b2010-04-07 13:29:58 -0700824 if (s_callbacks.version < 3) { // Remove when partners upgrade to version 3
Wink Saville74fa3882009-12-22 15:35:41 -0800825 uusPresent = 0;
Wink Saville7bce0822010-01-08 15:20:12 -0800826 sizeOfDial = sizeof(dial) - sizeof(RIL_UUS_Info *);
Wink Saville74fa3882009-12-22 15:35:41 -0800827 } else {
828 status = p.readInt32(&uusPresent);
829
830 if (status != NO_ERROR) {
831 goto invalid;
832 }
833
834 if (uusPresent == 0) {
835 dial.uusInfo = NULL;
836 } else {
837 int32_t len;
838
839 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
840
841 status = p.readInt32(&t);
842 uusInfo.uusType = (RIL_UUS_Type) t;
843
844 status = p.readInt32(&t);
845 uusInfo.uusDcs = (RIL_UUS_DCS) t;
846
847 status = p.readInt32(&len);
848 if (status != NO_ERROR) {
849 goto invalid;
850 }
851
852 // The java code writes -1 for null arrays
853 if (((int) len) == -1) {
854 uusInfo.uusData = NULL;
855 len = 0;
856 } else {
857 uusInfo.uusData = (char*) p.readInplace(len);
858 }
859
860 uusInfo.uusLength = len;
861 dial.uusInfo = &uusInfo;
862 }
Wink Saville7bce0822010-01-08 15:20:12 -0800863 sizeOfDial = sizeof(dial);
Wink Saville74fa3882009-12-22 15:35:41 -0800864 }
865
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800866 startRequest;
867 appendPrintBuf("%snum=%s,clir=%d", printBuf, dial.address, dial.clir);
Wink Saville74fa3882009-12-22 15:35:41 -0800868 if (uusPresent) {
869 appendPrintBuf("%s,uusType=%d,uusDcs=%d,uusLen=%d", printBuf,
870 dial.uusInfo->uusType, dial.uusInfo->uusDcs,
871 dial.uusInfo->uusLength);
872 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800873 closeRequest;
874 printRequest(pRI->token, pRI->pCI->requestNumber);
875
Etan Cohend3652192014-06-20 08:28:44 -0700876 CALL_ONREQUEST(pRI->pCI->requestNumber, &dial, sizeOfDial, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800877
878#ifdef MEMSET_FREED
879 memsetString (dial.address);
880#endif
881
882 free (dial.address);
Wink Saville7f856802009-06-09 10:23:37 -0700883
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800884#ifdef MEMSET_FREED
Wink Saville74fa3882009-12-22 15:35:41 -0800885 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800886 memset(&dial, 0, sizeof(dial));
887#endif
888
889 return;
890invalid:
891 invalidCommandBlock(pRI);
892 return;
893}
894
Wink Saville7f856802009-06-09 10:23:37 -0700895/**
896 * Callee expects const RIL_SIM_IO *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800897 * Payload is:
898 * int32_t command
899 * int32_t fileid
900 * String path
901 * int32_t p1, p2, p3
Wink Saville7f856802009-06-09 10:23:37 -0700902 * String data
903 * String pin2
Wink Savillec0114b32011-02-18 10:14:07 -0800904 * String aidPtr
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800905 */
906static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700907dispatchSIM_IO (Parcel &p, RequestInfo *pRI) {
Wink Savillec0114b32011-02-18 10:14:07 -0800908 union RIL_SIM_IO {
909 RIL_SIM_IO_v6 v6;
910 RIL_SIM_IO_v5 v5;
911 } simIO;
912
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800913 int32_t t;
Wink Savillec0114b32011-02-18 10:14:07 -0800914 int size;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800915 status_t status;
916
Robert Greenwalt191e4dc2015-04-29 16:57:39 -0700917#if VDBG
Mark Salyzyndba25612015-04-09 07:18:35 -0700918 RLOGD("dispatchSIM_IO");
Robert Greenwalt191e4dc2015-04-29 16:57:39 -0700919#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800920 memset (&simIO, 0, sizeof(simIO));
921
Wink Saville7f856802009-06-09 10:23:37 -0700922 // note we only check status at the end
923
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800924 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800925 simIO.v6.command = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800926
927 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800928 simIO.v6.fileid = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800929
Wink Savillec0114b32011-02-18 10:14:07 -0800930 simIO.v6.path = strdupReadString(p);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800931
932 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800933 simIO.v6.p1 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800934
935 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800936 simIO.v6.p2 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800937
938 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800939 simIO.v6.p3 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800940
Wink Savillec0114b32011-02-18 10:14:07 -0800941 simIO.v6.data = strdupReadString(p);
942 simIO.v6.pin2 = strdupReadString(p);
943 simIO.v6.aidPtr = strdupReadString(p);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800944
945 startRequest;
Wink Savillec0114b32011-02-18 10:14:07 -0800946 appendPrintBuf("%scmd=0x%X,efid=0x%X,path=%s,%d,%d,%d,%s,pin2=%s,aid=%s", printBuf,
947 simIO.v6.command, simIO.v6.fileid, (char*)simIO.v6.path,
948 simIO.v6.p1, simIO.v6.p2, simIO.v6.p3,
949 (char*)simIO.v6.data, (char*)simIO.v6.pin2, simIO.v6.aidPtr);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800950 closeRequest;
951 printRequest(pRI->token, pRI->pCI->requestNumber);
Wink Saville7f856802009-06-09 10:23:37 -0700952
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800953 if (status != NO_ERROR) {
954 goto invalid;
955 }
956
Wink Savillec0114b32011-02-18 10:14:07 -0800957 size = (s_callbacks.version < 6) ? sizeof(simIO.v5) : sizeof(simIO.v6);
Etan Cohend3652192014-06-20 08:28:44 -0700958 CALL_ONREQUEST(pRI->pCI->requestNumber, &simIO, size, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800959
960#ifdef MEMSET_FREED
Wink Savillec0114b32011-02-18 10:14:07 -0800961 memsetString (simIO.v6.path);
962 memsetString (simIO.v6.data);
963 memsetString (simIO.v6.pin2);
964 memsetString (simIO.v6.aidPtr);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800965#endif
966
Wink Savillec0114b32011-02-18 10:14:07 -0800967 free (simIO.v6.path);
968 free (simIO.v6.data);
969 free (simIO.v6.pin2);
970 free (simIO.v6.aidPtr);
Wink Saville7f856802009-06-09 10:23:37 -0700971
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800972#ifdef MEMSET_FREED
973 memset(&simIO, 0, sizeof(simIO));
974#endif
975
976 return;
977invalid:
978 invalidCommandBlock(pRI);
979 return;
980}
981
982/**
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800983 * Callee expects const RIL_SIM_APDU *
984 * Payload is:
985 * int32_t sessionid
986 * int32_t cla
987 * int32_t instruction
988 * int32_t p1, p2, p3
989 * String data
990 */
991static void
992dispatchSIM_APDU (Parcel &p, RequestInfo *pRI) {
993 int32_t t;
994 status_t status;
995 RIL_SIM_APDU apdu;
996
Robert Greenwalt191e4dc2015-04-29 16:57:39 -0700997#if VDBG
Mark Salyzyndba25612015-04-09 07:18:35 -0700998 RLOGD("dispatchSIM_APDU");
Robert Greenwalt191e4dc2015-04-29 16:57:39 -0700999#endif
Shishir Agrawal2458d8d2013-11-27 14:53:05 -08001000 memset (&apdu, 0, sizeof(RIL_SIM_APDU));
1001
1002 // Note we only check status at the end. Any single failure leads to
1003 // subsequent reads filing.
1004 status = p.readInt32(&t);
1005 apdu.sessionid = (int)t;
1006
1007 status = p.readInt32(&t);
1008 apdu.cla = (int)t;
1009
1010 status = p.readInt32(&t);
1011 apdu.instruction = (int)t;
1012
1013 status = p.readInt32(&t);
1014 apdu.p1 = (int)t;
1015
1016 status = p.readInt32(&t);
1017 apdu.p2 = (int)t;
1018
1019 status = p.readInt32(&t);
1020 apdu.p3 = (int)t;
1021
1022 apdu.data = strdupReadString(p);
1023
1024 startRequest;
1025 appendPrintBuf("%ssessionid=%d,cla=%d,ins=%d,p1=%d,p2=%d,p3=%d,data=%s",
1026 printBuf, apdu.sessionid, apdu.cla, apdu.instruction, apdu.p1, apdu.p2,
1027 apdu.p3, (char*)apdu.data);
1028 closeRequest;
1029 printRequest(pRI->token, pRI->pCI->requestNumber);
1030
1031 if (status != NO_ERROR) {
1032 goto invalid;
1033 }
1034
Etan Cohend3652192014-06-20 08:28:44 -07001035 CALL_ONREQUEST(pRI->pCI->requestNumber, &apdu, sizeof(RIL_SIM_APDU), pRI, pRI->socket_id);
Shishir Agrawal2458d8d2013-11-27 14:53:05 -08001036
1037#ifdef MEMSET_FREED
1038 memsetString(apdu.data);
1039#endif
1040 free(apdu.data);
1041
1042#ifdef MEMSET_FREED
1043 memset(&apdu, 0, sizeof(RIL_SIM_APDU));
1044#endif
1045
1046 return;
1047invalid:
1048 invalidCommandBlock(pRI);
1049 return;
1050}
1051
1052
1053/**
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001054 * Callee expects const RIL_CallForwardInfo *
1055 * Payload is:
1056 * int32_t status/action
1057 * int32_t reason
1058 * int32_t serviceCode
1059 * int32_t toa
1060 * String number (0 length -> null)
1061 * int32_t timeSeconds
1062 */
Wink Saville7f856802009-06-09 10:23:37 -07001063static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001064dispatchCallForward(Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001065 RIL_CallForwardInfo cff;
1066 int32_t t;
1067 status_t status;
1068
Mark Salyzyndba25612015-04-09 07:18:35 -07001069 RLOGD("dispatchCallForward");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001070 memset (&cff, 0, sizeof(cff));
1071
Wink Saville7f856802009-06-09 10:23:37 -07001072 // note we only check status at the end
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001073
1074 status = p.readInt32(&t);
1075 cff.status = (int)t;
Wink Saville7f856802009-06-09 10:23:37 -07001076
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001077 status = p.readInt32(&t);
1078 cff.reason = (int)t;
1079
1080 status = p.readInt32(&t);
1081 cff.serviceClass = (int)t;
1082
1083 status = p.readInt32(&t);
1084 cff.toa = (int)t;
1085
1086 cff.number = strdupReadString(p);
1087
1088 status = p.readInt32(&t);
1089 cff.timeSeconds = (int)t;
1090
1091 if (status != NO_ERROR) {
1092 goto invalid;
1093 }
1094
1095 // special case: number 0-length fields is null
1096
1097 if (cff.number != NULL && strlen (cff.number) == 0) {
1098 cff.number = NULL;
1099 }
1100
1101 startRequest;
1102 appendPrintBuf("%sstat=%d,reason=%d,serv=%d,toa=%d,%s,tout=%d", printBuf,
1103 cff.status, cff.reason, cff.serviceClass, cff.toa,
1104 (char*)cff.number, cff.timeSeconds);
1105 closeRequest;
1106 printRequest(pRI->token, pRI->pCI->requestNumber);
1107
Etan Cohend3652192014-06-20 08:28:44 -07001108 CALL_ONREQUEST(pRI->pCI->requestNumber, &cff, sizeof(cff), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001109
1110#ifdef MEMSET_FREED
1111 memsetString(cff.number);
1112#endif
1113
1114 free (cff.number);
1115
1116#ifdef MEMSET_FREED
1117 memset(&cff, 0, sizeof(cff));
1118#endif
1119
1120 return;
1121invalid:
1122 invalidCommandBlock(pRI);
1123 return;
1124}
1125
1126
Wink Saville7f856802009-06-09 10:23:37 -07001127static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001128dispatchRaw(Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001129 int32_t len;
1130 status_t status;
1131 const void *data;
1132
1133 status = p.readInt32(&len);
1134
1135 if (status != NO_ERROR) {
1136 goto invalid;
1137 }
1138
1139 // The java code writes -1 for null arrays
1140 if (((int)len) == -1) {
1141 data = NULL;
1142 len = 0;
Wink Saville7f856802009-06-09 10:23:37 -07001143 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001144
1145 data = p.readInplace(len);
1146
1147 startRequest;
1148 appendPrintBuf("%sraw_size=%d", printBuf, len);
1149 closeRequest;
1150 printRequest(pRI->token, pRI->pCI->requestNumber);
1151
Etan Cohend3652192014-06-20 08:28:44 -07001152 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<void *>(data), len, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001153
1154 return;
1155invalid:
1156 invalidCommandBlock(pRI);
1157 return;
1158}
1159
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001160static status_t
1161constructCdmaSms(Parcel &p, RequestInfo *pRI, RIL_CDMA_SMS_Message& rcsm) {
Wink Savillef4c4d362009-04-02 01:37:03 -07001162 int32_t t;
1163 uint8_t ut;
1164 status_t status;
1165 int32_t digitCount;
1166 int digitLimit;
Wink Saville7f856802009-06-09 10:23:37 -07001167
Wink Savillef4c4d362009-04-02 01:37:03 -07001168 memset(&rcsm, 0, sizeof(rcsm));
1169
1170 status = p.readInt32(&t);
1171 rcsm.uTeleserviceID = (int) t;
1172
1173 status = p.read(&ut,sizeof(ut));
1174 rcsm.bIsServicePresent = (uint8_t) ut;
1175
1176 status = p.readInt32(&t);
1177 rcsm.uServicecategory = (int) t;
1178
1179 status = p.readInt32(&t);
1180 rcsm.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1181
1182 status = p.readInt32(&t);
1183 rcsm.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1184
1185 status = p.readInt32(&t);
1186 rcsm.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1187
1188 status = p.readInt32(&t);
1189 rcsm.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1190
1191 status = p.read(&ut,sizeof(ut));
1192 rcsm.sAddress.number_of_digits= (uint8_t) ut;
1193
1194 digitLimit= MIN((rcsm.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
1195 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1196 status = p.read(&ut,sizeof(ut));
1197 rcsm.sAddress.digits[digitCount] = (uint8_t) ut;
1198 }
1199
Wink Saville7f856802009-06-09 10:23:37 -07001200 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001201 rcsm.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1202
Wink Saville7f856802009-06-09 10:23:37 -07001203 status = p.read(&ut,sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001204 rcsm.sSubAddress.odd = (uint8_t) ut;
1205
1206 status = p.read(&ut,sizeof(ut));
1207 rcsm.sSubAddress.number_of_digits = (uint8_t) ut;
1208
1209 digitLimit= MIN((rcsm.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
Wink Saville7f856802009-06-09 10:23:37 -07001210 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1211 status = p.read(&ut,sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001212 rcsm.sSubAddress.digits[digitCount] = (uint8_t) ut;
1213 }
1214
Wink Saville7f856802009-06-09 10:23:37 -07001215 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001216 rcsm.uBearerDataLen = (int) t;
1217
1218 digitLimit= MIN((rcsm.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
Wink Saville7f856802009-06-09 10:23:37 -07001219 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1220 status = p.read(&ut, sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001221 rcsm.aBearerData[digitCount] = (uint8_t) ut;
1222 }
1223
1224 if (status != NO_ERROR) {
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001225 return status;
Wink Savillef4c4d362009-04-02 01:37:03 -07001226 }
1227
1228 startRequest;
1229 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
Wink Saville1b5fd232009-04-22 14:50:00 -07001230 sAddress.digit_mode=%d, sAddress.Number_mode=%d, sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07001231 printBuf, rcsm.uTeleserviceID,rcsm.bIsServicePresent,rcsm.uServicecategory,
Wink Saville1b5fd232009-04-22 14:50:00 -07001232 rcsm.sAddress.digit_mode, rcsm.sAddress.number_mode,rcsm.sAddress.number_type);
Wink Savillef4c4d362009-04-02 01:37:03 -07001233 closeRequest;
Wink Saville7f856802009-06-09 10:23:37 -07001234
Wink Savillef4c4d362009-04-02 01:37:03 -07001235 printRequest(pRI->token, pRI->pCI->requestNumber);
1236
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001237 return status;
1238}
1239
1240static void
1241dispatchCdmaSms(Parcel &p, RequestInfo *pRI) {
1242 RIL_CDMA_SMS_Message rcsm;
1243
Mark Salyzyndba25612015-04-09 07:18:35 -07001244 RLOGD("dispatchCdmaSms");
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001245 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1246 goto invalid;
1247 }
1248
Etan Cohend3652192014-06-20 08:28:44 -07001249 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001250
1251#ifdef MEMSET_FREED
1252 memset(&rcsm, 0, sizeof(rcsm));
1253#endif
1254
1255 return;
1256
1257invalid:
1258 invalidCommandBlock(pRI);
1259 return;
1260}
1261
Wink Saville7f856802009-06-09 10:23:37 -07001262static void
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001263dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1264 RIL_IMS_SMS_Message rism;
1265 RIL_CDMA_SMS_Message rcsm;
1266
Mark Salyzyndba25612015-04-09 07:18:35 -07001267 RLOGD("dispatchImsCdmaSms: retry=%d, messageRef=%d", retry, messageRef);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001268
1269 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1270 goto invalid;
1271 }
1272 memset(&rism, 0, sizeof(rism));
1273 rism.tech = RADIO_TECH_3GPP2;
1274 rism.retry = retry;
1275 rism.messageRef = messageRef;
1276 rism.message.cdmaMessage = &rcsm;
1277
Etan Cohend3652192014-06-20 08:28:44 -07001278 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001279 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Etan Cohend3652192014-06-20 08:28:44 -07001280 +sizeof(rcsm),pRI, pRI->socket_id);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001281
1282#ifdef MEMSET_FREED
1283 memset(&rcsm, 0, sizeof(rcsm));
1284 memset(&rism, 0, sizeof(rism));
1285#endif
1286
1287 return;
1288
1289invalid:
1290 invalidCommandBlock(pRI);
1291 return;
1292}
1293
1294static void
1295dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1296 RIL_IMS_SMS_Message rism;
1297 int32_t countStrings;
1298 status_t status;
1299 size_t datalen;
1300 char **pStrings;
Mark Salyzyndba25612015-04-09 07:18:35 -07001301 RLOGD("dispatchImsGsmSms: retry=%d, messageRef=%d", retry, messageRef);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001302
1303 status = p.readInt32 (&countStrings);
1304
1305 if (status != NO_ERROR) {
1306 goto invalid;
1307 }
1308
1309 memset(&rism, 0, sizeof(rism));
1310 rism.tech = RADIO_TECH_3GPP;
1311 rism.retry = retry;
1312 rism.messageRef = messageRef;
1313
1314 startRequest;
Etan Cohen5d891b72014-02-27 17:25:17 -08001315 appendPrintBuf("%stech=%d, retry=%d, messageRef=%d, ", printBuf,
1316 (int)rism.tech, (int)rism.retry, rism.messageRef);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001317 if (countStrings == 0) {
1318 // just some non-null pointer
1319 pStrings = (char **)alloca(sizeof(char *));
Sanket Padawe55227b52016-02-29 10:09:26 -08001320 if (pStrings == NULL) {
1321 RLOGE("Memory allocation failed for request %s",
1322 requestToString(pRI->pCI->requestNumber));
1323 closeRequest;
1324 return;
1325 }
1326
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001327 datalen = 0;
1328 } else if (((int)countStrings) == -1) {
1329 pStrings = NULL;
1330 datalen = 0;
1331 } else {
1332 datalen = sizeof(char *) * countStrings;
1333
1334 pStrings = (char **)alloca(datalen);
Sanket Padawe55227b52016-02-29 10:09:26 -08001335 if (pStrings == NULL) {
1336 RLOGE("Memory allocation failed for request %s",
1337 requestToString(pRI->pCI->requestNumber));
1338 closeRequest;
1339 return;
1340 }
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001341
1342 for (int i = 0 ; i < countStrings ; i++) {
1343 pStrings[i] = strdupReadString(p);
1344 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
1345 }
1346 }
1347 removeLastChar;
1348 closeRequest;
1349 printRequest(pRI->token, pRI->pCI->requestNumber);
1350
1351 rism.message.gsmMessage = pStrings;
Etan Cohend3652192014-06-20 08:28:44 -07001352 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001353 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Etan Cohend3652192014-06-20 08:28:44 -07001354 +datalen, pRI, pRI->socket_id);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001355
1356 if (pStrings != NULL) {
1357 for (int i = 0 ; i < countStrings ; i++) {
1358#ifdef MEMSET_FREED
1359 memsetString (pStrings[i]);
1360#endif
1361 free(pStrings[i]);
1362 }
1363
1364#ifdef MEMSET_FREED
1365 memset(pStrings, 0, datalen);
1366#endif
1367 }
1368
1369#ifdef MEMSET_FREED
1370 memset(&rism, 0, sizeof(rism));
1371#endif
1372 return;
1373invalid:
1374 ALOGE("dispatchImsGsmSms invalid block");
1375 invalidCommandBlock(pRI);
1376 return;
1377}
1378
1379static void
1380dispatchImsSms(Parcel &p, RequestInfo *pRI) {
1381 int32_t t;
1382 status_t status = p.readInt32(&t);
1383 RIL_RadioTechnologyFamily format;
1384 uint8_t retry;
1385 int32_t messageRef;
1386
Mark Salyzyndba25612015-04-09 07:18:35 -07001387 RLOGD("dispatchImsSms");
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001388 if (status != NO_ERROR) {
1389 goto invalid;
1390 }
1391 format = (RIL_RadioTechnologyFamily) t;
1392
1393 // read retry field
1394 status = p.read(&retry,sizeof(retry));
1395 if (status != NO_ERROR) {
1396 goto invalid;
1397 }
1398 // read messageRef field
1399 status = p.read(&messageRef,sizeof(messageRef));
1400 if (status != NO_ERROR) {
1401 goto invalid;
1402 }
1403
1404 if (RADIO_TECH_3GPP == format) {
1405 dispatchImsGsmSms(p, pRI, retry, messageRef);
1406 } else if (RADIO_TECH_3GPP2 == format) {
1407 dispatchImsCdmaSms(p, pRI, retry, messageRef);
1408 } else {
1409 ALOGE("requestImsSendSMS invalid format value =%d", format);
1410 }
1411
1412 return;
1413
1414invalid:
1415 invalidCommandBlock(pRI);
1416 return;
1417}
1418
1419static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001420dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI) {
1421 RIL_CDMA_SMS_Ack rcsa;
1422 int32_t t;
1423 status_t status;
1424 int32_t digitCount;
1425
Mark Salyzyndba25612015-04-09 07:18:35 -07001426 RLOGD("dispatchCdmaSmsAck");
Wink Savillef4c4d362009-04-02 01:37:03 -07001427 memset(&rcsa, 0, sizeof(rcsa));
1428
1429 status = p.readInt32(&t);
1430 rcsa.uErrorClass = (RIL_CDMA_SMS_ErrorClass) t;
1431
1432 status = p.readInt32(&t);
1433 rcsa.uSMSCauseCode = (int) t;
1434
1435 if (status != NO_ERROR) {
1436 goto invalid;
1437 }
1438
1439 startRequest;
Wink Saville1b5fd232009-04-22 14:50:00 -07001440 appendPrintBuf("%suErrorClass=%d, uTLStatus=%d, ",
1441 printBuf, rcsa.uErrorClass, rcsa.uSMSCauseCode);
Wink Savillef4c4d362009-04-02 01:37:03 -07001442 closeRequest;
1443
1444 printRequest(pRI->token, pRI->pCI->requestNumber);
1445
Etan Cohend3652192014-06-20 08:28:44 -07001446 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsa, sizeof(rcsa),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001447
1448#ifdef MEMSET_FREED
1449 memset(&rcsa, 0, sizeof(rcsa));
1450#endif
1451
1452 return;
1453
1454invalid:
1455 invalidCommandBlock(pRI);
1456 return;
1457}
1458
Wink Savillea592eeb2009-05-22 13:26:36 -07001459static void
1460dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1461 int32_t t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001462 status_t status;
Wink Savillea592eeb2009-05-22 13:26:36 -07001463 int32_t num;
Wink Savillef4c4d362009-04-02 01:37:03 -07001464
Wink Savillea592eeb2009-05-22 13:26:36 -07001465 status = p.readInt32(&num);
Wink Savillef4c4d362009-04-02 01:37:03 -07001466 if (status != NO_ERROR) {
1467 goto invalid;
1468 }
1469
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001470 {
1471 RIL_GSM_BroadcastSmsConfigInfo gsmBci[num];
1472 RIL_GSM_BroadcastSmsConfigInfo *gsmBciPtrs[num];
Wink Savillea592eeb2009-05-22 13:26:36 -07001473
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001474 startRequest;
1475 for (int i = 0 ; i < num ; i++ ) {
1476 gsmBciPtrs[i] = &gsmBci[i];
Wink Savillef4c4d362009-04-02 01:37:03 -07001477
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001478 status = p.readInt32(&t);
1479 gsmBci[i].fromServiceId = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001480
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001481 status = p.readInt32(&t);
1482 gsmBci[i].toServiceId = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001483
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001484 status = p.readInt32(&t);
1485 gsmBci[i].fromCodeScheme = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001486
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001487 status = p.readInt32(&t);
1488 gsmBci[i].toCodeScheme = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001489
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001490 status = p.readInt32(&t);
1491 gsmBci[i].selected = (uint8_t) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001492
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001493 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId =%d, \
1494 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]", printBuf, i,
1495 gsmBci[i].fromServiceId, gsmBci[i].toServiceId,
1496 gsmBci[i].fromCodeScheme, gsmBci[i].toCodeScheme,
1497 gsmBci[i].selected);
1498 }
1499 closeRequest;
Wink Savillef4c4d362009-04-02 01:37:03 -07001500
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001501 if (status != NO_ERROR) {
1502 goto invalid;
1503 }
Wink Savillef4c4d362009-04-02 01:37:03 -07001504
Etan Cohend3652192014-06-20 08:28:44 -07001505 CALL_ONREQUEST(pRI->pCI->requestNumber,
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001506 gsmBciPtrs,
1507 num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *),
Etan Cohend3652192014-06-20 08:28:44 -07001508 pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001509
1510#ifdef MEMSET_FREED
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001511 memset(gsmBci, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo));
1512 memset(gsmBciPtrs, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *));
Wink Savillef4c4d362009-04-02 01:37:03 -07001513#endif
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001514 }
Wink Savillef4c4d362009-04-02 01:37:03 -07001515
1516 return;
1517
1518invalid:
1519 invalidCommandBlock(pRI);
1520 return;
Wink Savillea592eeb2009-05-22 13:26:36 -07001521}
Wink Savillef4c4d362009-04-02 01:37:03 -07001522
Wink Savillea592eeb2009-05-22 13:26:36 -07001523static void
1524dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1525 int32_t t;
1526 status_t status;
1527 int32_t num;
1528
1529 status = p.readInt32(&num);
1530 if (status != NO_ERROR) {
1531 goto invalid;
1532 }
1533
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001534 {
1535 RIL_CDMA_BroadcastSmsConfigInfo cdmaBci[num];
1536 RIL_CDMA_BroadcastSmsConfigInfo *cdmaBciPtrs[num];
Wink Savillea592eeb2009-05-22 13:26:36 -07001537
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001538 startRequest;
1539 for (int i = 0 ; i < num ; i++ ) {
1540 cdmaBciPtrs[i] = &cdmaBci[i];
Wink Savillea592eeb2009-05-22 13:26:36 -07001541
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001542 status = p.readInt32(&t);
1543 cdmaBci[i].service_category = (int) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001544
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001545 status = p.readInt32(&t);
1546 cdmaBci[i].language = (int) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001547
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001548 status = p.readInt32(&t);
1549 cdmaBci[i].selected = (uint8_t) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001550
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001551 appendPrintBuf("%s [%d: service_category=%d, language =%d, \
1552 entries.bSelected =%d]", printBuf, i, cdmaBci[i].service_category,
1553 cdmaBci[i].language, cdmaBci[i].selected);
1554 }
1555 closeRequest;
Wink Savillea592eeb2009-05-22 13:26:36 -07001556
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001557 if (status != NO_ERROR) {
1558 goto invalid;
1559 }
Wink Savillea592eeb2009-05-22 13:26:36 -07001560
Etan Cohend3652192014-06-20 08:28:44 -07001561 CALL_ONREQUEST(pRI->pCI->requestNumber,
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001562 cdmaBciPtrs,
1563 num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *),
Etan Cohend3652192014-06-20 08:28:44 -07001564 pRI, pRI->socket_id);
Wink Savillea592eeb2009-05-22 13:26:36 -07001565
1566#ifdef MEMSET_FREED
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001567 memset(cdmaBci, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo));
1568 memset(cdmaBciPtrs, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *));
Wink Savillea592eeb2009-05-22 13:26:36 -07001569#endif
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001570 }
Wink Savillea592eeb2009-05-22 13:26:36 -07001571
1572 return;
1573
1574invalid:
1575 invalidCommandBlock(pRI);
1576 return;
Wink Savillef4c4d362009-04-02 01:37:03 -07001577}
1578
1579static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI) {
1580 RIL_CDMA_SMS_WriteArgs rcsw;
1581 int32_t t;
1582 uint32_t ut;
1583 uint8_t uct;
1584 status_t status;
1585 int32_t digitCount;
Sukanya Rajkhowa605c7842013-10-29 14:55:30 +08001586 int32_t digitLimit;
Wink Savillef4c4d362009-04-02 01:37:03 -07001587
1588 memset(&rcsw, 0, sizeof(rcsw));
1589
1590 status = p.readInt32(&t);
1591 rcsw.status = t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001592
Wink Savillef4c4d362009-04-02 01:37:03 -07001593 status = p.readInt32(&t);
1594 rcsw.message.uTeleserviceID = (int) t;
1595
1596 status = p.read(&uct,sizeof(uct));
1597 rcsw.message.bIsServicePresent = (uint8_t) uct;
1598
1599 status = p.readInt32(&t);
1600 rcsw.message.uServicecategory = (int) t;
1601
1602 status = p.readInt32(&t);
1603 rcsw.message.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1604
1605 status = p.readInt32(&t);
1606 rcsw.message.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1607
1608 status = p.readInt32(&t);
1609 rcsw.message.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1610
1611 status = p.readInt32(&t);
1612 rcsw.message.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1613
1614 status = p.read(&uct,sizeof(uct));
1615 rcsw.message.sAddress.number_of_digits = (uint8_t) uct;
1616
Sukanya Rajkhowa605c7842013-10-29 14:55:30 +08001617 digitLimit = MIN((rcsw.message.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
1618
1619 for(digitCount = 0 ; digitCount < digitLimit; digitCount ++) {
Wink Savillef4c4d362009-04-02 01:37:03 -07001620 status = p.read(&uct,sizeof(uct));
1621 rcsw.message.sAddress.digits[digitCount] = (uint8_t) uct;
1622 }
1623
Wink Savillea592eeb2009-05-22 13:26:36 -07001624 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001625 rcsw.message.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1626
Wink Savillea592eeb2009-05-22 13:26:36 -07001627 status = p.read(&uct,sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001628 rcsw.message.sSubAddress.odd = (uint8_t) uct;
1629
1630 status = p.read(&uct,sizeof(uct));
1631 rcsw.message.sSubAddress.number_of_digits = (uint8_t) uct;
1632
Sukanya Rajkhowa605c7842013-10-29 14:55:30 +08001633 digitLimit = MIN((rcsw.message.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
1634
1635 for(digitCount = 0 ; digitCount < digitLimit; digitCount ++) {
Wink Savillea592eeb2009-05-22 13:26:36 -07001636 status = p.read(&uct,sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001637 rcsw.message.sSubAddress.digits[digitCount] = (uint8_t) uct;
1638 }
1639
Wink Savillea592eeb2009-05-22 13:26:36 -07001640 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001641 rcsw.message.uBearerDataLen = (int) t;
1642
Sukanya Rajkhowa605c7842013-10-29 14:55:30 +08001643 digitLimit = MIN((rcsw.message.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
1644
1645 for(digitCount = 0 ; digitCount < digitLimit; digitCount ++) {
Wink Savillea592eeb2009-05-22 13:26:36 -07001646 status = p.read(&uct, sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001647 rcsw.message.aBearerData[digitCount] = (uint8_t) uct;
1648 }
1649
1650 if (status != NO_ERROR) {
1651 goto invalid;
1652 }
1653
1654 startRequest;
Wink Saville1b5fd232009-04-22 14:50:00 -07001655 appendPrintBuf("%sstatus=%d, message.uTeleserviceID=%d, message.bIsServicePresent=%d, \
1656 message.uServicecategory=%d, message.sAddress.digit_mode=%d, \
1657 message.sAddress.number_mode=%d, \
1658 message.sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07001659 printBuf, rcsw.status, rcsw.message.uTeleserviceID, rcsw.message.bIsServicePresent,
Wink Saville1b5fd232009-04-22 14:50:00 -07001660 rcsw.message.uServicecategory, rcsw.message.sAddress.digit_mode,
1661 rcsw.message.sAddress.number_mode,
1662 rcsw.message.sAddress.number_type);
Wink Savillef4c4d362009-04-02 01:37:03 -07001663 closeRequest;
1664
1665 printRequest(pRI->token, pRI->pCI->requestNumber);
1666
Etan Cohend3652192014-06-20 08:28:44 -07001667 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsw, sizeof(rcsw),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001668
1669#ifdef MEMSET_FREED
1670 memset(&rcsw, 0, sizeof(rcsw));
1671#endif
1672
1673 return;
1674
1675invalid:
1676 invalidCommandBlock(pRI);
1677 return;
1678
1679}
1680
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -07001681// For backwards compatibility in RIL_REQUEST_SETUP_DATA_CALL.
1682// Version 4 of the RIL interface adds a new PDP type parameter to support
1683// IPv6 and dual-stack PDP contexts. When dealing with a previous version of
1684// RIL, remove the parameter from the request.
1685static void dispatchDataCall(Parcel& p, RequestInfo *pRI) {
1686 // In RIL v3, REQUEST_SETUP_DATA_CALL takes 6 parameters.
1687 const int numParamsRilV3 = 6;
1688
1689 // The first bytes of the RIL parcel contain the request number and the
1690 // serial number - see processCommandBuffer(). Copy them over too.
1691 int pos = p.dataPosition();
1692
1693 int numParams = p.readInt32();
1694 if (s_callbacks.version < 4 && numParams > numParamsRilV3) {
1695 Parcel p2;
1696 p2.appendFrom(&p, 0, pos);
1697 p2.writeInt32(numParamsRilV3);
1698 for(int i = 0; i < numParamsRilV3; i++) {
1699 p2.writeString16(p.readString16());
1700 }
1701 p2.setDataPosition(pos);
1702 dispatchStrings(p2, pRI);
1703 } else {
Lorenzo Colitti57ce1f22010-09-13 12:23:50 -07001704 p.setDataPosition(pos);
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -07001705 dispatchStrings(p, pRI);
1706 }
1707}
1708
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001709// For backwards compatibility with RILs that dont support RIL_REQUEST_VOICE_RADIO_TECH.
1710// When all RILs handle this request, this function can be removed and
1711// the request can be sent directly to the RIL using dispatchVoid.
1712static void dispatchVoiceRadioTech(Parcel& p, RequestInfo *pRI) {
Etan Cohend3652192014-06-20 08:28:44 -07001713 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001714
1715 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1716 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1717 }
1718
1719 // RILs that support RADIO_STATE_ON should support this request.
1720 if (RADIO_STATE_ON == state) {
1721 dispatchVoid(p, pRI);
1722 return;
1723 }
1724
1725 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1726 // will not support this new request either and decode Voice Radio Technology
1727 // from Radio State
1728 voiceRadioTech = decodeVoiceRadioTechnology(state);
1729
1730 if (voiceRadioTech < 0)
1731 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1732 else
1733 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &voiceRadioTech, sizeof(int));
1734}
1735
1736// For backwards compatibility in RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE:.
1737// When all RILs handle this request, this function can be removed and
1738// the request can be sent directly to the RIL using dispatchVoid.
1739static void dispatchCdmaSubscriptionSource(Parcel& p, RequestInfo *pRI) {
Etan Cohend3652192014-06-20 08:28:44 -07001740 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001741
1742 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1743 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1744 }
1745
1746 // RILs that support RADIO_STATE_ON should support this request.
1747 if (RADIO_STATE_ON == state) {
1748 dispatchVoid(p, pRI);
1749 return;
1750 }
1751
1752 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1753 // will not support this new request either and decode CDMA Subscription Source
1754 // from Radio State
1755 cdmaSubscriptionSource = decodeCdmaSubscriptionSource(state);
1756
1757 if (cdmaSubscriptionSource < 0)
1758 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1759 else
1760 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &cdmaSubscriptionSource, sizeof(int));
1761}
1762
Sungmin Choi75697532013-04-26 15:04:45 -07001763static void dispatchSetInitialAttachApn(Parcel &p, RequestInfo *pRI)
1764{
1765 RIL_InitialAttachApn pf;
1766 int32_t t;
1767 status_t status;
1768
1769 memset(&pf, 0, sizeof(pf));
1770
1771 pf.apn = strdupReadString(p);
1772 pf.protocol = strdupReadString(p);
1773
1774 status = p.readInt32(&t);
1775 pf.authtype = (int) t;
1776
1777 pf.username = strdupReadString(p);
1778 pf.password = strdupReadString(p);
1779
1780 startRequest;
Etan Cohen5d891b72014-02-27 17:25:17 -08001781 appendPrintBuf("%sapn=%s, protocol=%s, authtype=%d, username=%s, password=%s",
1782 printBuf, pf.apn, pf.protocol, pf.authtype, pf.username, pf.password);
Sungmin Choi75697532013-04-26 15:04:45 -07001783 closeRequest;
1784 printRequest(pRI->token, pRI->pCI->requestNumber);
1785
1786 if (status != NO_ERROR) {
1787 goto invalid;
1788 }
Etan Cohend3652192014-06-20 08:28:44 -07001789 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
Sungmin Choi75697532013-04-26 15:04:45 -07001790
1791#ifdef MEMSET_FREED
1792 memsetString(pf.apn);
1793 memsetString(pf.protocol);
1794 memsetString(pf.username);
1795 memsetString(pf.password);
1796#endif
1797
1798 free(pf.apn);
1799 free(pf.protocol);
1800 free(pf.username);
1801 free(pf.password);
1802
1803#ifdef MEMSET_FREED
1804 memset(&pf, 0, sizeof(pf));
1805#endif
1806
1807 return;
1808invalid:
1809 invalidCommandBlock(pRI);
1810 return;
1811}
1812
Jake Hamby8a4a2332014-01-15 13:12:05 -08001813static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI) {
1814 RIL_NV_ReadItem nvri;
1815 int32_t t;
1816 status_t status;
1817
1818 memset(&nvri, 0, sizeof(nvri));
1819
1820 status = p.readInt32(&t);
1821 nvri.itemID = (RIL_NV_Item) t;
1822
1823 if (status != NO_ERROR) {
1824 goto invalid;
1825 }
1826
1827 startRequest;
1828 appendPrintBuf("%snvri.itemID=%d, ", printBuf, nvri.itemID);
1829 closeRequest;
1830
1831 printRequest(pRI->token, pRI->pCI->requestNumber);
1832
Etan Cohend3652192014-06-20 08:28:44 -07001833 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvri, sizeof(nvri), pRI, pRI->socket_id);
Jake Hamby8a4a2332014-01-15 13:12:05 -08001834
1835#ifdef MEMSET_FREED
1836 memset(&nvri, 0, sizeof(nvri));
1837#endif
1838
1839 return;
1840
1841invalid:
1842 invalidCommandBlock(pRI);
1843 return;
1844}
1845
1846static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI) {
1847 RIL_NV_WriteItem nvwi;
1848 int32_t t;
1849 status_t status;
1850
1851 memset(&nvwi, 0, sizeof(nvwi));
1852
1853 status = p.readInt32(&t);
1854 nvwi.itemID = (RIL_NV_Item) t;
1855
1856 nvwi.value = strdupReadString(p);
1857
1858 if (status != NO_ERROR || nvwi.value == NULL) {
1859 goto invalid;
1860 }
1861
1862 startRequest;
1863 appendPrintBuf("%snvwi.itemID=%d, value=%s, ", printBuf, nvwi.itemID,
1864 nvwi.value);
1865 closeRequest;
1866
1867 printRequest(pRI->token, pRI->pCI->requestNumber);
1868
Etan Cohend3652192014-06-20 08:28:44 -07001869 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvwi, sizeof(nvwi), pRI, pRI->socket_id);
Jake Hamby8a4a2332014-01-15 13:12:05 -08001870
1871#ifdef MEMSET_FREED
1872 memsetString(nvwi.value);
1873#endif
1874
1875 free(nvwi.value);
1876
1877#ifdef MEMSET_FREED
1878 memset(&nvwi, 0, sizeof(nvwi));
1879#endif
1880
1881 return;
1882
1883invalid:
1884 invalidCommandBlock(pRI);
1885 return;
1886}
1887
1888
Etan Cohend3652192014-06-20 08:28:44 -07001889static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI) {
1890 RIL_SelectUiccSub uicc_sub;
1891 status_t status;
1892 int32_t t;
1893 memset(&uicc_sub, 0, sizeof(uicc_sub));
1894
1895 status = p.readInt32(&t);
1896 if (status != NO_ERROR) {
1897 goto invalid;
1898 }
1899 uicc_sub.slot = (int) t;
1900
1901 status = p.readInt32(&t);
1902 if (status != NO_ERROR) {
1903 goto invalid;
1904 }
1905 uicc_sub.app_index = (int) t;
1906
1907 status = p.readInt32(&t);
1908 if (status != NO_ERROR) {
1909 goto invalid;
1910 }
1911 uicc_sub.sub_type = (RIL_SubscriptionType) t;
1912
1913 status = p.readInt32(&t);
1914 if (status != NO_ERROR) {
1915 goto invalid;
1916 }
1917 uicc_sub.act_status = (RIL_UiccSubActStatus) t;
1918
1919 startRequest;
1920 appendPrintBuf("slot=%d, app_index=%d, act_status = %d", uicc_sub.slot, uicc_sub.app_index,
1921 uicc_sub.act_status);
1922 RLOGD("dispatchUiccSubscription, slot=%d, app_index=%d, act_status = %d", uicc_sub.slot,
1923 uicc_sub.app_index, uicc_sub.act_status);
1924 closeRequest;
1925 printRequest(pRI->token, pRI->pCI->requestNumber);
1926
1927 CALL_ONREQUEST(pRI->pCI->requestNumber, &uicc_sub, sizeof(uicc_sub), pRI, pRI->socket_id);
1928
1929#ifdef MEMSET_FREED
1930 memset(&uicc_sub, 0, sizeof(uicc_sub));
1931#endif
1932 return;
1933
1934invalid:
1935 invalidCommandBlock(pRI);
1936 return;
1937}
1938
Amit Mahajan90530a62014-07-01 15:54:08 -07001939static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI)
1940{
1941 RIL_SimAuthentication pf;
1942 int32_t t;
1943 status_t status;
1944
1945 memset(&pf, 0, sizeof(pf));
1946
1947 status = p.readInt32(&t);
1948 pf.authContext = (int) t;
1949 pf.authData = strdupReadString(p);
1950 pf.aid = strdupReadString(p);
1951
1952 startRequest;
1953 appendPrintBuf("authContext=%s, authData=%s, aid=%s", pf.authContext, pf.authData, pf.aid);
1954 closeRequest;
1955 printRequest(pRI->token, pRI->pCI->requestNumber);
1956
1957 if (status != NO_ERROR) {
1958 goto invalid;
1959 }
1960 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
1961
1962#ifdef MEMSET_FREED
1963 memsetString(pf.authData);
1964 memsetString(pf.aid);
1965#endif
1966
1967 free(pf.authData);
1968 free(pf.aid);
1969
1970#ifdef MEMSET_FREED
1971 memset(&pf, 0, sizeof(pf));
1972#endif
1973
1974 return;
1975invalid:
1976 invalidCommandBlock(pRI);
1977 return;
1978}
1979
Amit Mahajanc796e222014-08-13 16:54:01 +00001980static void dispatchDataProfile(Parcel &p, RequestInfo *pRI) {
1981 int32_t t;
1982 status_t status;
1983 int32_t num;
1984
1985 status = p.readInt32(&num);
1986 if (status != NO_ERROR) {
1987 goto invalid;
1988 }
1989
1990 {
Sanket Padawe55227b52016-02-29 10:09:26 -08001991 RIL_DataProfileInfo *dataProfiles =
1992 (RIL_DataProfileInfo *)malloc(num * sizeof(RIL_DataProfileInfo));
1993 if (dataProfiles == NULL) {
1994 RLOGE("Memory allocation failed for request %s",
1995 requestToString(pRI->pCI->requestNumber));
1996 return;
1997 }
1998 RIL_DataProfileInfo **dataProfilePtrs =
1999 (RIL_DataProfileInfo **)malloc(num * sizeof(RIL_DataProfileInfo *));
2000 if (dataProfilePtrs == NULL) {
2001 RLOGE("Memory allocation failed for request %s",
2002 requestToString(pRI->pCI->requestNumber));
2003 free(dataProfiles);
2004 return;
2005 }
Amit Mahajanc796e222014-08-13 16:54:01 +00002006
2007 startRequest;
2008 for (int i = 0 ; i < num ; i++ ) {
2009 dataProfilePtrs[i] = &dataProfiles[i];
2010
2011 status = p.readInt32(&t);
2012 dataProfiles[i].profileId = (int) t;
2013
2014 dataProfiles[i].apn = strdupReadString(p);
2015 dataProfiles[i].protocol = strdupReadString(p);
2016 status = p.readInt32(&t);
2017 dataProfiles[i].authType = (int) t;
2018
2019 dataProfiles[i].user = strdupReadString(p);
2020 dataProfiles[i].password = strdupReadString(p);
2021
2022 status = p.readInt32(&t);
2023 dataProfiles[i].type = (int) t;
2024
2025 status = p.readInt32(&t);
2026 dataProfiles[i].maxConnsTime = (int) t;
2027 status = p.readInt32(&t);
2028 dataProfiles[i].maxConns = (int) t;
2029 status = p.readInt32(&t);
2030 dataProfiles[i].waitTime = (int) t;
2031
2032 status = p.readInt32(&t);
2033 dataProfiles[i].enabled = (int) t;
2034
2035 appendPrintBuf("%s [%d: profileId=%d, apn =%s, protocol =%s, authType =%d, \
2036 user =%s, password =%s, type =%d, maxConnsTime =%d, maxConns =%d, \
2037 waitTime =%d, enabled =%d]", printBuf, i, dataProfiles[i].profileId,
2038 dataProfiles[i].apn, dataProfiles[i].protocol, dataProfiles[i].authType,
2039 dataProfiles[i].user, dataProfiles[i].password, dataProfiles[i].type,
2040 dataProfiles[i].maxConnsTime, dataProfiles[i].maxConns,
2041 dataProfiles[i].waitTime, dataProfiles[i].enabled);
2042 }
2043 closeRequest;
2044 printRequest(pRI->token, pRI->pCI->requestNumber);
2045
2046 if (status != NO_ERROR) {
Sanket Padawe55227b52016-02-29 10:09:26 -08002047 free(dataProfiles);
2048 free(dataProfilePtrs);
Amit Mahajanc796e222014-08-13 16:54:01 +00002049 goto invalid;
2050 }
2051 CALL_ONREQUEST(pRI->pCI->requestNumber,
2052 dataProfilePtrs,
2053 num * sizeof(RIL_DataProfileInfo *),
2054 pRI, pRI->socket_id);
2055
2056#ifdef MEMSET_FREED
2057 memset(dataProfiles, 0, num * sizeof(RIL_DataProfileInfo));
2058 memset(dataProfilePtrs, 0, num * sizeof(RIL_DataProfileInfo *));
2059#endif
Sanket Padawe55227b52016-02-29 10:09:26 -08002060 free(dataProfiles);
2061 free(dataProfilePtrs);
Amit Mahajanc796e222014-08-13 16:54:01 +00002062 }
2063
2064 return;
2065
2066invalid:
2067 invalidCommandBlock(pRI);
2068 return;
2069}
2070
Wink Saville8b4e4f72014-10-17 15:01:45 -07002071static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI){
2072 RIL_RadioCapability rc;
2073 int32_t t;
2074 status_t status;
2075
2076 memset (&rc, 0, sizeof(RIL_RadioCapability));
2077
2078 status = p.readInt32(&t);
2079 rc.version = (int)t;
2080 if (status != NO_ERROR) {
2081 goto invalid;
2082 }
2083
2084 status = p.readInt32(&t);
2085 rc.session= (int)t;
2086 if (status != NO_ERROR) {
2087 goto invalid;
2088 }
2089
2090 status = p.readInt32(&t);
2091 rc.phase= (int)t;
2092 if (status != NO_ERROR) {
2093 goto invalid;
2094 }
2095
2096 status = p.readInt32(&t);
2097 rc.rat = (int)t;
2098 if (status != NO_ERROR) {
2099 goto invalid;
2100 }
2101
2102 status = readStringFromParcelInplace(p, rc.logicalModemUuid, sizeof(rc.logicalModemUuid));
2103 if (status != NO_ERROR) {
2104 goto invalid;
2105 }
2106
2107 status = p.readInt32(&t);
2108 rc.status = (int)t;
2109
2110 if (status != NO_ERROR) {
2111 goto invalid;
2112 }
2113
2114 startRequest;
2115 appendPrintBuf("%s [version:%d, session:%d, phase:%d, rat:%d, \
Chih-Wei Huang8593f262015-10-02 15:09:52 +08002116 logicalModemUuid:%s, status:%d", printBuf, rc.version, rc.session,
Legler Wu8caf06f2014-10-29 14:02:14 +08002117 rc.phase, rc.rat, rc.logicalModemUuid, rc.session);
Wink Saville8b4e4f72014-10-17 15:01:45 -07002118
2119 closeRequest;
2120 printRequest(pRI->token, pRI->pCI->requestNumber);
2121
2122 CALL_ONREQUEST(pRI->pCI->requestNumber,
2123 &rc,
2124 sizeof(RIL_RadioCapability),
2125 pRI, pRI->socket_id);
2126 return;
2127invalid:
2128 invalidCommandBlock(pRI);
2129 return;
2130}
2131
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002132static int
Wink Savillef4c4d362009-04-02 01:37:03 -07002133blockingWrite(int fd, const void *buffer, size_t len) {
Wink Saville7f856802009-06-09 10:23:37 -07002134 size_t writeOffset = 0;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002135 const uint8_t *toWrite;
2136
2137 toWrite = (const uint8_t *)buffer;
2138
2139 while (writeOffset < len) {
2140 ssize_t written;
2141 do {
2142 written = write (fd, toWrite + writeOffset,
2143 len - writeOffset);
Banavathu, Srinivas Naik38884902011-07-05 20:04:25 +05302144 } while (written < 0 && ((errno == EINTR) || (errno == EAGAIN)));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002145
2146 if (written >= 0) {
2147 writeOffset += written;
2148 } else { // written < 0
Wink Saville8eb2a122012-11-19 16:05:13 -08002149 RLOGE ("RIL Response: unexpected error on write errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002150 close(fd);
2151 return -1;
2152 }
2153 }
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07002154#if VDBG
Dheeraj Shetty27976c42014-07-02 21:27:57 +02002155 RLOGE("RIL Response bytes written:%d", writeOffset);
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07002156#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002157 return 0;
2158}
2159
2160static int
Etan Cohend3652192014-06-20 08:28:44 -07002161sendResponseRaw (const void *data, size_t dataSize, RIL_SOCKET_ID socket_id) {
2162 int fd = s_ril_param_socket.fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002163 int ret;
2164 uint32_t header;
Etan Cohend3652192014-06-20 08:28:44 -07002165 pthread_mutex_t * writeMutexHook = &s_writeMutex;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002166
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07002167#if VDBG
Etan Cohend3652192014-06-20 08:28:44 -07002168 RLOGE("Send Response to %s", rilSocketIdToString(socket_id));
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07002169#endif
Etan Cohend3652192014-06-20 08:28:44 -07002170
2171#if (SIM_COUNT >= 2)
2172 if (socket_id == RIL_SOCKET_2) {
2173 fd = s_ril_param_socket2.fdCommand;
2174 writeMutexHook = &s_writeMutex_socket2;
2175 }
2176#if (SIM_COUNT >= 3)
2177 else if (socket_id == RIL_SOCKET_3) {
2178 fd = s_ril_param_socket3.fdCommand;
2179 writeMutexHook = &s_writeMutex_socket3;
2180 }
2181#endif
2182#if (SIM_COUNT >= 4)
2183 else if (socket_id == RIL_SOCKET_4) {
2184 fd = s_ril_param_socket4.fdCommand;
2185 writeMutexHook = &s_writeMutex_socket4;
2186 }
2187#endif
2188#endif
2189 if (fd < 0) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002190 return -1;
2191 }
2192
2193 if (dataSize > MAX_COMMAND_BYTES) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002194 RLOGE("RIL: packet larger than %u (%u)",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002195 MAX_COMMAND_BYTES, (unsigned int )dataSize);
2196
2197 return -1;
2198 }
Wink Saville7f856802009-06-09 10:23:37 -07002199
Etan Cohend3652192014-06-20 08:28:44 -07002200 pthread_mutex_lock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002201
2202 header = htonl(dataSize);
2203
2204 ret = blockingWrite(fd, (void *)&header, sizeof(header));
2205
2206 if (ret < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002207 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002208 return ret;
2209 }
2210
Kennyee1fadc2009-08-13 00:45:53 +08002211 ret = blockingWrite(fd, data, dataSize);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002212
2213 if (ret < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002214 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002215 return ret;
2216 }
2217
Etan Cohend3652192014-06-20 08:28:44 -07002218 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002219
2220 return 0;
2221}
2222
2223static int
Etan Cohend3652192014-06-20 08:28:44 -07002224sendResponse (Parcel &p, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002225 printResponse;
Etan Cohend3652192014-06-20 08:28:44 -07002226 return sendResponseRaw(p.data(), p.dataSize(), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002227}
2228
Mohamad Ayyash74f7e662014-04-18 11:43:28 -07002229/** response is an int* pointing to an array of ints */
Wink Saville7f856802009-06-09 10:23:37 -07002230
2231static int
Wink Savillef4c4d362009-04-02 01:37:03 -07002232responseInts(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002233 int numInts;
2234
2235 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002236 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002237 return RIL_ERRNO_INVALID_RESPONSE;
2238 }
2239 if (responselen % sizeof(int) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002240 RLOGE("responseInts: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002241 (int)responselen, (int)sizeof(int));
2242 return RIL_ERRNO_INVALID_RESPONSE;
2243 }
2244
2245 int *p_int = (int *) response;
2246
Mohamad Ayyash74f7e662014-04-18 11:43:28 -07002247 numInts = responselen / sizeof(int);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002248 p.writeInt32 (numInts);
2249
2250 /* each int*/
2251 startResponse;
2252 for (int i = 0 ; i < numInts ; i++) {
2253 appendPrintBuf("%s%d,", printBuf, p_int[i]);
2254 p.writeInt32(p_int[i]);
2255 }
2256 removeLastChar;
2257 closeResponse;
2258
2259 return 0;
2260}
2261
Chao Liu548a81e2015-05-14 16:13:46 -07002262// Response is an int or RIL_LastCallFailCauseInfo.
2263// Currently, only Shamu plans to use RIL_LastCallFailCauseInfo.
2264// TODO(yjl): Let all implementations use RIL_LastCallFailCauseInfo.
2265static int responseFailCause(Parcel &p, void *response, size_t responselen) {
2266 if (response == NULL && responselen != 0) {
2267 RLOGE("invalid response: NULL");
2268 return RIL_ERRNO_INVALID_RESPONSE;
2269 }
2270
2271 if (responselen == sizeof(int)) {
Sungmin Choia408c252015-07-01 16:22:46 +09002272 startResponse;
2273 int *p_int = (int *) response;
2274 appendPrintBuf("%s%d,", printBuf, p_int[0]);
2275 p.writeInt32(p_int[0]);
2276 removeLastChar;
2277 closeResponse;
Chao Liu548a81e2015-05-14 16:13:46 -07002278 } else if (responselen == sizeof(RIL_LastCallFailCauseInfo)) {
2279 startResponse;
2280 RIL_LastCallFailCauseInfo *p_fail_cause_info = (RIL_LastCallFailCauseInfo *) response;
2281 appendPrintBuf("%s[cause_code=%d,vendor_cause=%s]", printBuf, p_fail_cause_info->cause_code,
2282 p_fail_cause_info->vendor_cause);
2283 p.writeInt32(p_fail_cause_info->cause_code);
2284 writeStringToParcel(p, p_fail_cause_info->vendor_cause);
2285 removeLastChar;
2286 closeResponse;
2287 } else {
2288 RLOGE("responseFailCause: invalid response length %d expected an int or "
2289 "RIL_LastCallFailCauseInfo", (int)responselen);
2290 return RIL_ERRNO_INVALID_RESPONSE;
2291 }
2292
2293 return 0;
2294}
2295
Wink Saville43808972011-01-13 17:39:51 -08002296/** response is a char **, pointing to an array of char *'s
2297 The parcel will begin with the version */
2298static int responseStringsWithVersion(int version, Parcel &p, void *response, size_t responselen) {
2299 p.writeInt32(version);
2300 return responseStrings(p, response, responselen);
2301}
2302
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002303/** response is a char **, pointing to an array of char *'s */
Wink Savillef4c4d362009-04-02 01:37:03 -07002304static int responseStrings(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002305 int numStrings;
Wink Saville7f856802009-06-09 10:23:37 -07002306
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002307 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002308 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002309 return RIL_ERRNO_INVALID_RESPONSE;
2310 }
2311 if (responselen % sizeof(char *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002312 RLOGE("responseStrings: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002313 (int)responselen, (int)sizeof(char *));
2314 return RIL_ERRNO_INVALID_RESPONSE;
2315 }
2316
2317 if (response == NULL) {
2318 p.writeInt32 (0);
2319 } else {
2320 char **p_cur = (char **) response;
2321
2322 numStrings = responselen / sizeof(char *);
2323 p.writeInt32 (numStrings);
2324
2325 /* each string*/
2326 startResponse;
2327 for (int i = 0 ; i < numStrings ; i++) {
2328 appendPrintBuf("%s%s,", printBuf, (char*)p_cur[i]);
2329 writeStringToParcel (p, p_cur[i]);
2330 }
2331 removeLastChar;
2332 closeResponse;
2333 }
2334 return 0;
2335}
2336
2337
2338/**
Wink Saville7f856802009-06-09 10:23:37 -07002339 * NULL strings are accepted
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002340 * FIXME currently ignores responselen
2341 */
Wink Savillef4c4d362009-04-02 01:37:03 -07002342static int responseString(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002343 /* one string only */
2344 startResponse;
2345 appendPrintBuf("%s%s", printBuf, (char*)response);
2346 closeResponse;
2347
2348 writeStringToParcel(p, (const char *)response);
2349
2350 return 0;
2351}
2352
Wink Savillef4c4d362009-04-02 01:37:03 -07002353static int responseVoid(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002354 startResponse;
2355 removeLastChar;
2356 return 0;
2357}
2358
Wink Savillef4c4d362009-04-02 01:37:03 -07002359static int responseCallList(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002360 int num;
2361
2362 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002363 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002364 return RIL_ERRNO_INVALID_RESPONSE;
2365 }
2366
2367 if (responselen % sizeof (RIL_Call *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002368 RLOGE("responseCallList: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002369 (int)responselen, (int)sizeof (RIL_Call *));
2370 return RIL_ERRNO_INVALID_RESPONSE;
2371 }
2372
2373 startResponse;
2374 /* number of call info's */
2375 num = responselen / sizeof(RIL_Call *);
2376 p.writeInt32(num);
2377
2378 for (int i = 0 ; i < num ; i++) {
2379 RIL_Call *p_cur = ((RIL_Call **) response)[i];
2380 /* each call info */
2381 p.writeInt32(p_cur->state);
2382 p.writeInt32(p_cur->index);
2383 p.writeInt32(p_cur->toa);
2384 p.writeInt32(p_cur->isMpty);
2385 p.writeInt32(p_cur->isMT);
2386 p.writeInt32(p_cur->als);
2387 p.writeInt32(p_cur->isVoice);
Wink Saville1b5fd232009-04-22 14:50:00 -07002388 p.writeInt32(p_cur->isVoicePrivacy);
2389 writeStringToParcel(p, p_cur->number);
John Wangff368742009-03-24 17:56:29 -07002390 p.writeInt32(p_cur->numberPresentation);
Wink Saville1b5fd232009-04-22 14:50:00 -07002391 writeStringToParcel(p, p_cur->name);
2392 p.writeInt32(p_cur->namePresentation);
Wink Saville3a4840b2010-04-07 13:29:58 -07002393 // Remove when partners upgrade to version 3
Wink Saville74fa3882009-12-22 15:35:41 -08002394 if ((s_callbacks.version < 3) || (p_cur->uusInfo == NULL || p_cur->uusInfo->uusData == NULL)) {
2395 p.writeInt32(0); /* UUS Information is absent */
2396 } else {
2397 RIL_UUS_Info *uusInfo = p_cur->uusInfo;
2398 p.writeInt32(1); /* UUS Information is present */
2399 p.writeInt32(uusInfo->uusType);
2400 p.writeInt32(uusInfo->uusDcs);
2401 p.writeInt32(uusInfo->uusLength);
2402 p.write(uusInfo->uusData, uusInfo->uusLength);
2403 }
Wink Saville3d54e742009-05-18 18:00:44 -07002404 appendPrintBuf("%s[id=%d,%s,toa=%d,",
John Wangff368742009-03-24 17:56:29 -07002405 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002406 p_cur->index,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002407 callStateToString(p_cur->state),
Wink Saville3d54e742009-05-18 18:00:44 -07002408 p_cur->toa);
2409 appendPrintBuf("%s%s,%s,als=%d,%s,%s,",
2410 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002411 (p_cur->isMpty)?"conf":"norm",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002412 (p_cur->isMT)?"mt":"mo",
2413 p_cur->als,
2414 (p_cur->isVoice)?"voc":"nonvoc",
Wink Saville3d54e742009-05-18 18:00:44 -07002415 (p_cur->isVoicePrivacy)?"evp":"noevp");
2416 appendPrintBuf("%s%s,cli=%d,name='%s',%d]",
2417 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002418 p_cur->number,
2419 p_cur->numberPresentation,
2420 p_cur->name,
2421 p_cur->namePresentation);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002422 }
2423 removeLastChar;
2424 closeResponse;
2425
2426 return 0;
2427}
2428
Wink Savillef4c4d362009-04-02 01:37:03 -07002429static int responseSMS(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002430 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002431 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002432 return RIL_ERRNO_INVALID_RESPONSE;
2433 }
2434
2435 if (responselen != sizeof (RIL_SMS_Response) ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002436 RLOGE("invalid response length %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002437 (int)responselen, (int)sizeof (RIL_SMS_Response));
2438 return RIL_ERRNO_INVALID_RESPONSE;
2439 }
2440
2441 RIL_SMS_Response *p_cur = (RIL_SMS_Response *) response;
2442
2443 p.writeInt32(p_cur->messageRef);
2444 writeStringToParcel(p, p_cur->ackPDU);
Jaikumar Ganesh920c78f2009-06-04 10:53:15 -07002445 p.writeInt32(p_cur->errorCode);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002446
2447 startResponse;
Jaikumar Ganesh920c78f2009-06-04 10:53:15 -07002448 appendPrintBuf("%s%d,%s,%d", printBuf, p_cur->messageRef,
2449 (char*)p_cur->ackPDU, p_cur->errorCode);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002450 closeResponse;
2451
2452 return 0;
2453}
2454
Wink Savillec0114b32011-02-18 10:14:07 -08002455static int responseDataCallListV4(Parcel &p, void *response, size_t responselen)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002456{
2457 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002458 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002459 return RIL_ERRNO_INVALID_RESPONSE;
2460 }
2461
Wink Savillec0114b32011-02-18 10:14:07 -08002462 if (responselen % sizeof(RIL_Data_Call_Response_v4) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002463 RLOGE("responseDataCallListV4: invalid response length %d expected multiple of %d",
Wink Savillec0114b32011-02-18 10:14:07 -08002464 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v4));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002465 return RIL_ERRNO_INVALID_RESPONSE;
2466 }
2467
Amit Mahajan52500162014-07-29 17:36:48 -07002468 // Write version
2469 p.writeInt32(4);
2470
Wink Savillec0114b32011-02-18 10:14:07 -08002471 int num = responselen / sizeof(RIL_Data_Call_Response_v4);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002472 p.writeInt32(num);
2473
Wink Savillec0114b32011-02-18 10:14:07 -08002474 RIL_Data_Call_Response_v4 *p_cur = (RIL_Data_Call_Response_v4 *) response;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002475 startResponse;
2476 int i;
2477 for (i = 0; i < num; i++) {
2478 p.writeInt32(p_cur[i].cid);
2479 p.writeInt32(p_cur[i].active);
2480 writeStringToParcel(p, p_cur[i].type);
Wink Savillec0114b32011-02-18 10:14:07 -08002481 // apn is not used, so don't send.
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002482 writeStringToParcel(p, p_cur[i].address);
Wink Savillec0114b32011-02-18 10:14:07 -08002483 appendPrintBuf("%s[cid=%d,%s,%s,%s],", printBuf,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002484 p_cur[i].cid,
2485 (p_cur[i].active==0)?"down":"up",
2486 (char*)p_cur[i].type,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002487 (char*)p_cur[i].address);
2488 }
2489 removeLastChar;
2490 closeResponse;
2491
2492 return 0;
2493}
2494
Etan Cohend3652192014-06-20 08:28:44 -07002495static int responseDataCallListV6(Parcel &p, void *response, size_t responselen)
2496{
Amit Mahajan52500162014-07-29 17:36:48 -07002497 if (response == NULL && responselen != 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002498 RLOGE("invalid response: NULL");
2499 return RIL_ERRNO_INVALID_RESPONSE;
2500 }
2501
2502 if (responselen % sizeof(RIL_Data_Call_Response_v6) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002503 RLOGE("responseDataCallListV6: invalid response length %d expected multiple of %d",
Etan Cohend3652192014-06-20 08:28:44 -07002504 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v6));
2505 return RIL_ERRNO_INVALID_RESPONSE;
2506 }
2507
Amit Mahajan52500162014-07-29 17:36:48 -07002508 // Write version
2509 p.writeInt32(6);
2510
Etan Cohend3652192014-06-20 08:28:44 -07002511 int num = responselen / sizeof(RIL_Data_Call_Response_v6);
2512 p.writeInt32(num);
2513
2514 RIL_Data_Call_Response_v6 *p_cur = (RIL_Data_Call_Response_v6 *) response;
2515 startResponse;
2516 int i;
2517 for (i = 0; i < num; i++) {
2518 p.writeInt32((int)p_cur[i].status);
2519 p.writeInt32(p_cur[i].suggestedRetryTime);
2520 p.writeInt32(p_cur[i].cid);
2521 p.writeInt32(p_cur[i].active);
2522 writeStringToParcel(p, p_cur[i].type);
2523 writeStringToParcel(p, p_cur[i].ifname);
2524 writeStringToParcel(p, p_cur[i].addresses);
2525 writeStringToParcel(p, p_cur[i].dnses);
2526 writeStringToParcel(p, p_cur[i].gateways);
2527 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s],", printBuf,
2528 p_cur[i].status,
2529 p_cur[i].suggestedRetryTime,
2530 p_cur[i].cid,
2531 (p_cur[i].active==0)?"down":"up",
2532 (char*)p_cur[i].type,
2533 (char*)p_cur[i].ifname,
2534 (char*)p_cur[i].addresses,
2535 (char*)p_cur[i].dnses,
2536 (char*)p_cur[i].gateways);
2537 }
2538 removeLastChar;
2539 closeResponse;
2540
2541 return 0;
2542}
2543
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002544static int responseDataCallListV9(Parcel &p, void *response, size_t responselen)
2545{
2546 if (response == NULL && responselen != 0) {
2547 RLOGE("invalid response: NULL");
2548 return RIL_ERRNO_INVALID_RESPONSE;
2549 }
2550
2551 if (responselen % sizeof(RIL_Data_Call_Response_v9) != 0) {
2552 RLOGE("responseDataCallListV9: invalid response length %d expected multiple of %d",
2553 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v9));
2554 return RIL_ERRNO_INVALID_RESPONSE;
2555 }
2556
2557 // Write version
2558 p.writeInt32(10);
2559
2560 int num = responselen / sizeof(RIL_Data_Call_Response_v9);
2561 p.writeInt32(num);
2562
2563 RIL_Data_Call_Response_v9 *p_cur = (RIL_Data_Call_Response_v9 *) response;
2564 startResponse;
2565 int i;
2566 for (i = 0; i < num; i++) {
2567 p.writeInt32((int)p_cur[i].status);
2568 p.writeInt32(p_cur[i].suggestedRetryTime);
2569 p.writeInt32(p_cur[i].cid);
2570 p.writeInt32(p_cur[i].active);
2571 writeStringToParcel(p, p_cur[i].type);
2572 writeStringToParcel(p, p_cur[i].ifname);
2573 writeStringToParcel(p, p_cur[i].addresses);
2574 writeStringToParcel(p, p_cur[i].dnses);
2575 writeStringToParcel(p, p_cur[i].gateways);
2576 writeStringToParcel(p, p_cur[i].pcscf);
2577 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s],", printBuf,
2578 p_cur[i].status,
2579 p_cur[i].suggestedRetryTime,
2580 p_cur[i].cid,
2581 (p_cur[i].active==0)?"down":"up",
2582 (char*)p_cur[i].type,
2583 (char*)p_cur[i].ifname,
2584 (char*)p_cur[i].addresses,
2585 (char*)p_cur[i].dnses,
2586 (char*)p_cur[i].gateways,
2587 (char*)p_cur[i].pcscf);
2588 }
2589 removeLastChar;
2590 closeResponse;
2591
2592 return 0;
2593}
2594
Sanket Padawe88cf6a52016-01-11 12:45:43 -08002595static int responseDataCallListV11(Parcel &p, void *response, size_t responselen) {
2596 if (response == NULL && responselen != 0) {
2597 RLOGE("invalid response: NULL");
2598 return RIL_ERRNO_INVALID_RESPONSE;
2599 }
2600
2601 if (responselen % sizeof(RIL_Data_Call_Response_v11) != 0) {
2602 RLOGE("invalid response length %d expected multiple of %d",
2603 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v11));
2604 return RIL_ERRNO_INVALID_RESPONSE;
2605 }
2606
2607 // Write version
2608 p.writeInt32(11);
2609
2610 int num = responselen / sizeof(RIL_Data_Call_Response_v11);
2611 p.writeInt32(num);
2612
2613 RIL_Data_Call_Response_v11 *p_cur = (RIL_Data_Call_Response_v11 *) response;
2614 startResponse;
2615 int i;
2616 for (i = 0; i < num; i++) {
2617 p.writeInt32((int)p_cur[i].status);
2618 p.writeInt32(p_cur[i].suggestedRetryTime);
2619 p.writeInt32(p_cur[i].cid);
2620 p.writeInt32(p_cur[i].active);
2621 writeStringToParcel(p, p_cur[i].type);
2622 writeStringToParcel(p, p_cur[i].ifname);
2623 writeStringToParcel(p, p_cur[i].addresses);
2624 writeStringToParcel(p, p_cur[i].dnses);
2625 writeStringToParcel(p, p_cur[i].gateways);
2626 writeStringToParcel(p, p_cur[i].pcscf);
2627 p.writeInt32(p_cur[i].mtu);
2628 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s,mtu=%d],", printBuf,
2629 p_cur[i].status,
2630 p_cur[i].suggestedRetryTime,
2631 p_cur[i].cid,
2632 (p_cur[i].active==0)?"down":"up",
2633 (char*)p_cur[i].type,
2634 (char*)p_cur[i].ifname,
2635 (char*)p_cur[i].addresses,
2636 (char*)p_cur[i].dnses,
2637 (char*)p_cur[i].gateways,
2638 (char*)p_cur[i].pcscf,
2639 p_cur[i].mtu);
2640 }
2641 removeLastChar;
2642 closeResponse;
2643
2644 return 0;
2645}
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002646
Wink Saville43808972011-01-13 17:39:51 -08002647static int responseDataCallList(Parcel &p, void *response, size_t responselen)
2648{
Sanket Padawe88cf6a52016-01-11 12:45:43 -08002649 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
2650 if (s_callbacks.version < 5) {
2651 RLOGD("responseDataCallList: v4");
2652 return responseDataCallListV4(p, response, responselen);
2653 } else if (responselen % sizeof(RIL_Data_Call_Response_v6) == 0) {
2654 return responseDataCallListV6(p, response, responselen);
2655 } else if (responselen % sizeof(RIL_Data_Call_Response_v9) == 0) {
2656 return responseDataCallListV9(p, response, responselen);
2657 } else {
2658 return responseDataCallListV11(p, response, responselen);
Wink Saville43808972011-01-13 17:39:51 -08002659 }
Sanket Padawef53c5fa2016-01-27 10:00:38 -08002660 } else { // RIL version >= 13
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002661 if (responselen % sizeof(RIL_Data_Call_Response_v11) != 0) {
Sanket Padawe88cf6a52016-01-11 12:45:43 -08002662 RLOGE("Data structure expected is RIL_Data_Call_Response_v11");
2663 if (!isDebuggable()) {
2664 return RIL_ERRNO_INVALID_RESPONSE;
2665 } else {
2666 assert(0);
2667 }
Wink Saville43808972011-01-13 17:39:51 -08002668 }
Sanket Padawe88cf6a52016-01-11 12:45:43 -08002669 return responseDataCallListV11(p, response, responselen);
Wink Saville43808972011-01-13 17:39:51 -08002670 }
Wink Saville43808972011-01-13 17:39:51 -08002671}
2672
2673static int responseSetupDataCall(Parcel &p, void *response, size_t responselen)
2674{
2675 if (s_callbacks.version < 5) {
2676 return responseStringsWithVersion(s_callbacks.version, p, response, responselen);
2677 } else {
2678 return responseDataCallList(p, response, responselen);
2679 }
2680}
2681
Wink Savillef4c4d362009-04-02 01:37:03 -07002682static int responseRaw(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002683 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002684 RLOGE("invalid response: NULL with responselen != 0");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002685 return RIL_ERRNO_INVALID_RESPONSE;
2686 }
2687
2688 // The java code reads -1 size as null byte array
2689 if (response == NULL) {
Wink Saville7f856802009-06-09 10:23:37 -07002690 p.writeInt32(-1);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002691 } else {
2692 p.writeInt32(responselen);
2693 p.write(response, responselen);
2694 }
2695
2696 return 0;
2697}
2698
2699
Wink Savillef4c4d362009-04-02 01:37:03 -07002700static int responseSIM_IO(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002701 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002702 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002703 return RIL_ERRNO_INVALID_RESPONSE;
2704 }
2705
2706 if (responselen != sizeof (RIL_SIM_IO_Response) ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002707 RLOGE("invalid response length was %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002708 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
2709 return RIL_ERRNO_INVALID_RESPONSE;
2710 }
2711
2712 RIL_SIM_IO_Response *p_cur = (RIL_SIM_IO_Response *) response;
2713 p.writeInt32(p_cur->sw1);
2714 p.writeInt32(p_cur->sw2);
2715 writeStringToParcel(p, p_cur->simResponse);
2716
2717 startResponse;
2718 appendPrintBuf("%ssw1=0x%X,sw2=0x%X,%s", printBuf, p_cur->sw1, p_cur->sw2,
2719 (char*)p_cur->simResponse);
2720 closeResponse;
2721
2722
2723 return 0;
2724}
2725
Wink Savillef4c4d362009-04-02 01:37:03 -07002726static int responseCallForwards(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002727 int num;
Wink Saville7f856802009-06-09 10:23:37 -07002728
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002729 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002730 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002731 return RIL_ERRNO_INVALID_RESPONSE;
2732 }
2733
2734 if (responselen % sizeof(RIL_CallForwardInfo *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002735 RLOGE("responseCallForwards: invalid response length %d expected multiple of %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002736 (int)responselen, (int)sizeof(RIL_CallForwardInfo *));
2737 return RIL_ERRNO_INVALID_RESPONSE;
2738 }
2739
2740 /* number of call info's */
2741 num = responselen / sizeof(RIL_CallForwardInfo *);
2742 p.writeInt32(num);
2743
2744 startResponse;
2745 for (int i = 0 ; i < num ; i++) {
2746 RIL_CallForwardInfo *p_cur = ((RIL_CallForwardInfo **) response)[i];
2747
2748 p.writeInt32(p_cur->status);
2749 p.writeInt32(p_cur->reason);
2750 p.writeInt32(p_cur->serviceClass);
2751 p.writeInt32(p_cur->toa);
2752 writeStringToParcel(p, p_cur->number);
2753 p.writeInt32(p_cur->timeSeconds);
2754 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
2755 (p_cur->status==1)?"enable":"disable",
2756 p_cur->reason, p_cur->serviceClass, p_cur->toa,
2757 (char*)p_cur->number,
2758 p_cur->timeSeconds);
2759 }
2760 removeLastChar;
2761 closeResponse;
Wink Saville7f856802009-06-09 10:23:37 -07002762
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002763 return 0;
2764}
2765
Wink Savillef4c4d362009-04-02 01:37:03 -07002766static int responseSsn(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002767 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002768 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002769 return RIL_ERRNO_INVALID_RESPONSE;
2770 }
2771
2772 if (responselen != sizeof(RIL_SuppSvcNotification)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002773 RLOGE("invalid response length was %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002774 (int)responselen, (int)sizeof (RIL_SuppSvcNotification));
2775 return RIL_ERRNO_INVALID_RESPONSE;
2776 }
2777
2778 RIL_SuppSvcNotification *p_cur = (RIL_SuppSvcNotification *) response;
2779 p.writeInt32(p_cur->notificationType);
2780 p.writeInt32(p_cur->code);
2781 p.writeInt32(p_cur->index);
2782 p.writeInt32(p_cur->type);
2783 writeStringToParcel(p, p_cur->number);
2784
2785 startResponse;
2786 appendPrintBuf("%s%s,code=%d,id=%d,type=%d,%s", printBuf,
2787 (p_cur->notificationType==0)?"mo":"mt",
2788 p_cur->code, p_cur->index, p_cur->type,
2789 (char*)p_cur->number);
2790 closeResponse;
2791
2792 return 0;
2793}
2794
Wink Saville3d54e742009-05-18 18:00:44 -07002795static int responseCellList(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002796 int num;
2797
2798 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002799 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002800 return RIL_ERRNO_INVALID_RESPONSE;
2801 }
2802
2803 if (responselen % sizeof (RIL_NeighboringCell *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002804 RLOGE("responseCellList: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002805 (int)responselen, (int)sizeof (RIL_NeighboringCell *));
2806 return RIL_ERRNO_INVALID_RESPONSE;
2807 }
2808
2809 startResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002810 /* number of records */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002811 num = responselen / sizeof(RIL_NeighboringCell *);
2812 p.writeInt32(num);
2813
2814 for (int i = 0 ; i < num ; i++) {
2815 RIL_NeighboringCell *p_cur = ((RIL_NeighboringCell **) response)[i];
2816
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002817 p.writeInt32(p_cur->rssi);
2818 writeStringToParcel (p, p_cur->cid);
2819
2820 appendPrintBuf("%s[cid=%s,rssi=%d],", printBuf,
2821 p_cur->cid, p_cur->rssi);
2822 }
2823 removeLastChar;
2824 closeResponse;
2825
2826 return 0;
2827}
2828
Wink Saville3d54e742009-05-18 18:00:44 -07002829/**
2830 * Marshall the signalInfoRecord into the parcel if it exists.
2831 */
Wink Savillea592eeb2009-05-22 13:26:36 -07002832static void marshallSignalInfoRecord(Parcel &p,
2833 RIL_CDMA_SignalInfoRecord &p_signalInfoRecord) {
Wink Saville3d54e742009-05-18 18:00:44 -07002834 p.writeInt32(p_signalInfoRecord.isPresent);
2835 p.writeInt32(p_signalInfoRecord.signalType);
2836 p.writeInt32(p_signalInfoRecord.alertPitch);
2837 p.writeInt32(p_signalInfoRecord.signal);
2838}
2839
Wink Savillea592eeb2009-05-22 13:26:36 -07002840static int responseCdmaInformationRecords(Parcel &p,
2841 void *response, size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07002842 int num;
Wink Savillea592eeb2009-05-22 13:26:36 -07002843 char* string8 = NULL;
2844 int buffer_lenght;
2845 RIL_CDMA_InformationRecord *infoRec;
Wink Saville3d54e742009-05-18 18:00:44 -07002846
2847 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002848 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002849 return RIL_ERRNO_INVALID_RESPONSE;
2850 }
2851
Wink Savillea592eeb2009-05-22 13:26:36 -07002852 if (responselen != sizeof (RIL_CDMA_InformationRecords)) {
Amit Mahajan52500162014-07-29 17:36:48 -07002853 RLOGE("responseCdmaInformationRecords: invalid response length %d expected multiple of %d\n",
Wink Savillea592eeb2009-05-22 13:26:36 -07002854 (int)responselen, (int)sizeof (RIL_CDMA_InformationRecords *));
Wink Saville3d54e742009-05-18 18:00:44 -07002855 return RIL_ERRNO_INVALID_RESPONSE;
2856 }
2857
Wink Savillea592eeb2009-05-22 13:26:36 -07002858 RIL_CDMA_InformationRecords *p_cur =
2859 (RIL_CDMA_InformationRecords *) response;
2860 num = MIN(p_cur->numberOfInfoRecs, RIL_CDMA_MAX_NUMBER_OF_INFO_RECS);
Wink Saville3d54e742009-05-18 18:00:44 -07002861
2862 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07002863 p.writeInt32(num);
Wink Saville3d54e742009-05-18 18:00:44 -07002864
Wink Savillea592eeb2009-05-22 13:26:36 -07002865 for (int i = 0 ; i < num ; i++) {
2866 infoRec = &p_cur->infoRec[i];
2867 p.writeInt32(infoRec->name);
2868 switch (infoRec->name) {
Wink Saville3d54e742009-05-18 18:00:44 -07002869 case RIL_CDMA_DISPLAY_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002870 case RIL_CDMA_EXTENDED_DISPLAY_INFO_REC:
2871 if (infoRec->rec.display.alpha_len >
2872 CDMA_ALPHA_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002873 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002874 expected not more than %d\n",
2875 (int)infoRec->rec.display.alpha_len,
2876 CDMA_ALPHA_INFO_BUFFER_LENGTH);
2877 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002878 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002879 string8 = (char*) malloc((infoRec->rec.display.alpha_len + 1)
2880 * sizeof(char) );
Sanket Padawe55227b52016-02-29 10:09:26 -08002881 if (string8 == NULL) {
2882 RLOGE("Memory allocation failed for responseCdmaInformationRecords");
2883 closeRequest;
2884 return RIL_ERRNO_NO_MEMORY;
2885 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002886 for (int i = 0 ; i < infoRec->rec.display.alpha_len ; i++) {
2887 string8[i] = infoRec->rec.display.alpha_buf[i];
2888 }
Wink Saville43808972011-01-13 17:39:51 -08002889 string8[(int)infoRec->rec.display.alpha_len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002890 writeStringToParcel(p, (const char*)string8);
2891 free(string8);
2892 string8 = NULL;
Wink Saville3d54e742009-05-18 18:00:44 -07002893 break;
2894 case RIL_CDMA_CALLED_PARTY_NUMBER_INFO_REC:
Wink Saville3d54e742009-05-18 18:00:44 -07002895 case RIL_CDMA_CALLING_PARTY_NUMBER_INFO_REC:
Wink Saville3d54e742009-05-18 18:00:44 -07002896 case RIL_CDMA_CONNECTED_NUMBER_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002897 if (infoRec->rec.number.len > CDMA_NUMBER_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002898 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002899 expected not more than %d\n",
2900 (int)infoRec->rec.number.len,
2901 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2902 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002903 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002904 string8 = (char*) malloc((infoRec->rec.number.len + 1)
2905 * sizeof(char) );
Sanket Padawe55227b52016-02-29 10:09:26 -08002906 if (string8 == NULL) {
2907 RLOGE("Memory allocation failed for responseCdmaInformationRecords");
2908 closeRequest;
2909 return RIL_ERRNO_NO_MEMORY;
2910 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002911 for (int i = 0 ; i < infoRec->rec.number.len; i++) {
2912 string8[i] = infoRec->rec.number.buf[i];
2913 }
Wink Saville43808972011-01-13 17:39:51 -08002914 string8[(int)infoRec->rec.number.len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002915 writeStringToParcel(p, (const char*)string8);
2916 free(string8);
2917 string8 = NULL;
2918 p.writeInt32(infoRec->rec.number.number_type);
2919 p.writeInt32(infoRec->rec.number.number_plan);
2920 p.writeInt32(infoRec->rec.number.pi);
2921 p.writeInt32(infoRec->rec.number.si);
Wink Saville3d54e742009-05-18 18:00:44 -07002922 break;
2923 case RIL_CDMA_SIGNAL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002924 p.writeInt32(infoRec->rec.signal.isPresent);
2925 p.writeInt32(infoRec->rec.signal.signalType);
2926 p.writeInt32(infoRec->rec.signal.alertPitch);
2927 p.writeInt32(infoRec->rec.signal.signal);
2928
2929 appendPrintBuf("%sisPresent=%X, signalType=%X, \
2930 alertPitch=%X, signal=%X, ",
2931 printBuf, (int)infoRec->rec.signal.isPresent,
2932 (int)infoRec->rec.signal.signalType,
2933 (int)infoRec->rec.signal.alertPitch,
2934 (int)infoRec->rec.signal.signal);
2935 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002936 break;
2937 case RIL_CDMA_REDIRECTING_NUMBER_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002938 if (infoRec->rec.redir.redirectingNumber.len >
2939 CDMA_NUMBER_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002940 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002941 expected not more than %d\n",
2942 (int)infoRec->rec.redir.redirectingNumber.len,
2943 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2944 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002945 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002946 string8 = (char*) malloc((infoRec->rec.redir.redirectingNumber
2947 .len + 1) * sizeof(char) );
Sanket Padawe55227b52016-02-29 10:09:26 -08002948 if (string8 == NULL) {
2949 RLOGE("Memory allocation failed for responseCdmaInformationRecords");
2950 closeRequest;
2951 return RIL_ERRNO_NO_MEMORY;
2952 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002953 for (int i = 0;
2954 i < infoRec->rec.redir.redirectingNumber.len;
2955 i++) {
2956 string8[i] = infoRec->rec.redir.redirectingNumber.buf[i];
2957 }
Wink Saville43808972011-01-13 17:39:51 -08002958 string8[(int)infoRec->rec.redir.redirectingNumber.len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002959 writeStringToParcel(p, (const char*)string8);
2960 free(string8);
2961 string8 = NULL;
2962 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_type);
2963 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_plan);
2964 p.writeInt32(infoRec->rec.redir.redirectingNumber.pi);
2965 p.writeInt32(infoRec->rec.redir.redirectingNumber.si);
2966 p.writeInt32(infoRec->rec.redir.redirectingReason);
Wink Saville3d54e742009-05-18 18:00:44 -07002967 break;
2968 case RIL_CDMA_LINE_CONTROL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002969 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPolarityIncluded);
2970 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlToggle);
2971 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlReverse);
2972 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2973
2974 appendPrintBuf("%slineCtrlPolarityIncluded=%d, \
2975 lineCtrlToggle=%d, lineCtrlReverse=%d, \
2976 lineCtrlPowerDenial=%d, ", printBuf,
2977 (int)infoRec->rec.lineCtrl.lineCtrlPolarityIncluded,
2978 (int)infoRec->rec.lineCtrl.lineCtrlToggle,
2979 (int)infoRec->rec.lineCtrl.lineCtrlReverse,
2980 (int)infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2981 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002982 break;
2983 case RIL_CDMA_T53_CLIR_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002984 p.writeInt32((int)(infoRec->rec.clir.cause));
Wink Saville3d54e742009-05-18 18:00:44 -07002985
Wink Savillea592eeb2009-05-22 13:26:36 -07002986 appendPrintBuf("%scause%d", printBuf, infoRec->rec.clir.cause);
2987 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002988 break;
2989 case RIL_CDMA_T53_AUDIO_CONTROL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002990 p.writeInt32(infoRec->rec.audioCtrl.upLink);
2991 p.writeInt32(infoRec->rec.audioCtrl.downLink);
2992
2993 appendPrintBuf("%supLink=%d, downLink=%d, ", printBuf,
2994 infoRec->rec.audioCtrl.upLink,
2995 infoRec->rec.audioCtrl.downLink);
2996 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002997 break;
Wink Savillea592eeb2009-05-22 13:26:36 -07002998 case RIL_CDMA_T53_RELEASE_INFO_REC:
2999 // TODO(Moto): See David Krause, he has the answer:)
Wink Saville8eb2a122012-11-19 16:05:13 -08003000 RLOGE("RIL_CDMA_T53_RELEASE_INFO_REC: return INVALID_RESPONSE");
Wink Savillea592eeb2009-05-22 13:26:36 -07003001 return RIL_ERRNO_INVALID_RESPONSE;
3002 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08003003 RLOGE("Incorrect name value");
Wink Savillea592eeb2009-05-22 13:26:36 -07003004 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07003005 }
3006 }
Wink Savillea592eeb2009-05-22 13:26:36 -07003007 closeResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07003008
Wink Savillea592eeb2009-05-22 13:26:36 -07003009 return 0;
Wink Saville3d54e742009-05-18 18:00:44 -07003010}
3011
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003012static void responseRilSignalStrengthV5(Parcel &p, RIL_SignalStrength_v10 *p_cur) {
3013 p.writeInt32(p_cur->GW_SignalStrength.signalStrength);
3014 p.writeInt32(p_cur->GW_SignalStrength.bitErrorRate);
3015 p.writeInt32(p_cur->CDMA_SignalStrength.dbm);
3016 p.writeInt32(p_cur->CDMA_SignalStrength.ecio);
3017 p.writeInt32(p_cur->EVDO_SignalStrength.dbm);
3018 p.writeInt32(p_cur->EVDO_SignalStrength.ecio);
3019 p.writeInt32(p_cur->EVDO_SignalStrength.signalNoiseRatio);
3020}
3021
3022static void responseRilSignalStrengthV6Extra(Parcel &p, RIL_SignalStrength_v10 *p_cur) {
3023 /*
3024 * Fixup LTE for backwards compatibility
3025 */
3026 // signalStrength: -1 -> 99
3027 if (p_cur->LTE_SignalStrength.signalStrength == -1) {
3028 p_cur->LTE_SignalStrength.signalStrength = 99;
3029 }
3030 // rsrp: -1 -> INT_MAX all other negative value to positive.
3031 // So remap here
3032 if (p_cur->LTE_SignalStrength.rsrp == -1) {
3033 p_cur->LTE_SignalStrength.rsrp = INT_MAX;
3034 } else if (p_cur->LTE_SignalStrength.rsrp < -1) {
3035 p_cur->LTE_SignalStrength.rsrp = -p_cur->LTE_SignalStrength.rsrp;
3036 }
3037 // rsrq: -1 -> INT_MAX
3038 if (p_cur->LTE_SignalStrength.rsrq == -1) {
3039 p_cur->LTE_SignalStrength.rsrq = INT_MAX;
3040 }
3041 // Not remapping rssnr is already using INT_MAX
3042
3043 // cqi: -1 -> INT_MAX
3044 if (p_cur->LTE_SignalStrength.cqi == -1) {
3045 p_cur->LTE_SignalStrength.cqi = INT_MAX;
3046 }
3047
3048 p.writeInt32(p_cur->LTE_SignalStrength.signalStrength);
3049 p.writeInt32(p_cur->LTE_SignalStrength.rsrp);
3050 p.writeInt32(p_cur->LTE_SignalStrength.rsrq);
3051 p.writeInt32(p_cur->LTE_SignalStrength.rssnr);
3052 p.writeInt32(p_cur->LTE_SignalStrength.cqi);
3053}
3054
3055static void responseRilSignalStrengthV10(Parcel &p, RIL_SignalStrength_v10 *p_cur) {
3056 responseRilSignalStrengthV5(p, p_cur);
3057 responseRilSignalStrengthV6Extra(p, p_cur);
3058 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
3059}
3060
Wink Savillea592eeb2009-05-22 13:26:36 -07003061static int responseRilSignalStrength(Parcel &p,
3062 void *response, size_t responselen) {
3063 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003064 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07003065 return RIL_ERRNO_INVALID_RESPONSE;
3066 }
3067
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003068 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
3069 if (responselen >= sizeof (RIL_SignalStrength_v5)) {
3070 RIL_SignalStrength_v10 *p_cur = ((RIL_SignalStrength_v10 *) response);
Wink Saville3d54e742009-05-18 18:00:44 -07003071
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003072 responseRilSignalStrengthV5(p, p_cur);
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07003073
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003074 if (responselen >= sizeof (RIL_SignalStrength_v6)) {
3075 responseRilSignalStrengthV6Extra(p, p_cur);
3076 if (responselen >= sizeof (RIL_SignalStrength_v10)) {
3077 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
3078 } else {
3079 p.writeInt32(INT_MAX);
Wink Saville18e4ab12013-04-07 17:31:04 -07003080 }
Etan Cohend3652192014-06-20 08:28:44 -07003081 } else {
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003082 p.writeInt32(99);
3083 p.writeInt32(INT_MAX);
3084 p.writeInt32(INT_MAX);
3085 p.writeInt32(INT_MAX);
3086 p.writeInt32(INT_MAX);
Etan Cohend3652192014-06-20 08:28:44 -07003087 p.writeInt32(INT_MAX);
3088 }
Wink Savillec0114b32011-02-18 10:14:07 -08003089 } else {
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003090 RLOGE("invalid response length");
3091 return RIL_ERRNO_INVALID_RESPONSE;
Wink Savillec0114b32011-02-18 10:14:07 -08003092 }
Sanket Padawef53c5fa2016-01-27 10:00:38 -08003093 } else { // RIL version >= 13
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003094 if (responselen % sizeof(RIL_SignalStrength_v10) != 0) {
3095 RLOGE("Data structure expected is RIL_SignalStrength_v10");
3096 if (!isDebuggable()) {
3097 return RIL_ERRNO_INVALID_RESPONSE;
3098 } else {
3099 assert(0);
3100 }
3101 }
3102 RIL_SignalStrength_v10 *p_cur = ((RIL_SignalStrength_v10 *) response);
3103 responseRilSignalStrengthV10(p, p_cur);
Wink Saville3d54e742009-05-18 18:00:44 -07003104 }
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003105 startResponse;
3106 appendPrintBuf("%s[signalStrength=%d,bitErrorRate=%d,\
3107 CDMA_SS.dbm=%d,CDMA_SSecio=%d,\
3108 EVDO_SS.dbm=%d,EVDO_SS.ecio=%d,\
3109 EVDO_SS.signalNoiseRatio=%d,\
3110 LTE_SS.signalStrength=%d,LTE_SS.rsrp=%d,LTE_SS.rsrq=%d,\
3111 LTE_SS.rssnr=%d,LTE_SS.cqi=%d,TDSCDMA_SS.rscp=%d]",
3112 printBuf,
3113 p_cur->GW_SignalStrength.signalStrength,
3114 p_cur->GW_SignalStrength.bitErrorRate,
3115 p_cur->CDMA_SignalStrength.dbm,
3116 p_cur->CDMA_SignalStrength.ecio,
3117 p_cur->EVDO_SignalStrength.dbm,
3118 p_cur->EVDO_SignalStrength.ecio,
3119 p_cur->EVDO_SignalStrength.signalNoiseRatio,
3120 p_cur->LTE_SignalStrength.signalStrength,
3121 p_cur->LTE_SignalStrength.rsrp,
3122 p_cur->LTE_SignalStrength.rsrq,
3123 p_cur->LTE_SignalStrength.rssnr,
3124 p_cur->LTE_SignalStrength.cqi,
3125 p_cur->TD_SCDMA_SignalStrength.rscp);
3126 closeResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07003127 return 0;
3128}
3129
3130static int responseCallRing(Parcel &p, void *response, size_t responselen) {
3131 if ((response == NULL) || (responselen == 0)) {
3132 return responseVoid(p, response, responselen);
3133 } else {
3134 return responseCdmaSignalInfoRecord(p, response, responselen);
3135 }
3136}
3137
3138static int responseCdmaSignalInfoRecord(Parcel &p, void *response, size_t responselen) {
3139 if (response == NULL || responselen == 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003140 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07003141 return RIL_ERRNO_INVALID_RESPONSE;
3142 }
3143
3144 if (responselen != sizeof (RIL_CDMA_SignalInfoRecord)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003145 RLOGE("invalid response length %d expected sizeof (RIL_CDMA_SignalInfoRecord) of %d\n",
Wink Saville3d54e742009-05-18 18:00:44 -07003146 (int)responselen, (int)sizeof (RIL_CDMA_SignalInfoRecord));
3147 return RIL_ERRNO_INVALID_RESPONSE;
3148 }
3149
3150 startResponse;
3151
3152 RIL_CDMA_SignalInfoRecord *p_cur = ((RIL_CDMA_SignalInfoRecord *) response);
3153 marshallSignalInfoRecord(p, *p_cur);
3154
3155 appendPrintBuf("%s[isPresent=%d,signalType=%d,alertPitch=%d\
3156 signal=%d]",
3157 printBuf,
3158 p_cur->isPresent,
3159 p_cur->signalType,
3160 p_cur->alertPitch,
3161 p_cur->signal);
3162
3163 closeResponse;
3164 return 0;
3165}
3166
Wink Savillea592eeb2009-05-22 13:26:36 -07003167static int responseCdmaCallWaiting(Parcel &p, void *response,
3168 size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07003169 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003170 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07003171 return RIL_ERRNO_INVALID_RESPONSE;
3172 }
3173
Wink Savillec0114b32011-02-18 10:14:07 -08003174 if (responselen < sizeof(RIL_CDMA_CallWaiting_v6)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003175 RLOGW("Upgrade to ril version %d\n", RIL_VERSION);
Wink Savillec0114b32011-02-18 10:14:07 -08003176 }
3177
3178 RIL_CDMA_CallWaiting_v6 *p_cur = ((RIL_CDMA_CallWaiting_v6 *) response);
3179
3180 writeStringToParcel(p, p_cur->number);
3181 p.writeInt32(p_cur->numberPresentation);
3182 writeStringToParcel(p, p_cur->name);
3183 marshallSignalInfoRecord(p, p_cur->signalInfoRecord);
3184
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003185 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
3186 if (responselen >= sizeof(RIL_CDMA_CallWaiting_v6)) {
3187 p.writeInt32(p_cur->number_type);
3188 p.writeInt32(p_cur->number_plan);
3189 } else {
3190 p.writeInt32(0);
3191 p.writeInt32(0);
3192 }
Sanket Padawef53c5fa2016-01-27 10:00:38 -08003193 } else { // RIL version >= 13
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003194 if (responselen % sizeof(RIL_CDMA_CallWaiting_v6) != 0) {
3195 RLOGE("Data structure expected is RIL_CDMA_CallWaiting_v6");
3196 if (!isDebuggable()) {
3197 return RIL_ERRNO_INVALID_RESPONSE;
3198 } else {
3199 assert(0);
3200 }
3201 }
Wink Savillec0114b32011-02-18 10:14:07 -08003202 p.writeInt32(p_cur->number_type);
3203 p.writeInt32(p_cur->number_plan);
Wink Saville3d54e742009-05-18 18:00:44 -07003204 }
3205
3206 startResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07003207 appendPrintBuf("%snumber=%s,numberPresentation=%d, name=%s,\
3208 signalInfoRecord[isPresent=%d,signalType=%d,alertPitch=%d\
Wink Savillec0114b32011-02-18 10:14:07 -08003209 signal=%d,number_type=%d,number_plan=%d]",
Wink Saville3d54e742009-05-18 18:00:44 -07003210 printBuf,
3211 p_cur->number,
3212 p_cur->numberPresentation,
3213 p_cur->name,
3214 p_cur->signalInfoRecord.isPresent,
3215 p_cur->signalInfoRecord.signalType,
3216 p_cur->signalInfoRecord.alertPitch,
Wink Savillec0114b32011-02-18 10:14:07 -08003217 p_cur->signalInfoRecord.signal,
3218 p_cur->number_type,
3219 p_cur->number_plan);
Wink Saville3d54e742009-05-18 18:00:44 -07003220 closeResponse;
3221
3222 return 0;
3223}
3224
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003225static void responseSimRefreshV7(Parcel &p, void *response) {
3226 RIL_SimRefreshResponse_v7 *p_cur = ((RIL_SimRefreshResponse_v7 *) response);
3227 p.writeInt32(p_cur->result);
3228 p.writeInt32(p_cur->ef_id);
3229 writeStringToParcel(p, p_cur->aid);
3230
3231 appendPrintBuf("%sresult=%d, ef_id=%d, aid=%s",
3232 printBuf,
3233 p_cur->result,
3234 p_cur->ef_id,
3235 p_cur->aid);
3236
3237}
3238
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003239static int responseSimRefresh(Parcel &p, void *response, size_t responselen) {
3240 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003241 RLOGE("responseSimRefresh: invalid response: NULL");
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003242 return RIL_ERRNO_INVALID_RESPONSE;
3243 }
3244
3245 startResponse;
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003246 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
Sanket Padawe41c94d02016-01-21 15:49:33 -08003247 if (s_callbacks.version >= 7) {
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003248 responseSimRefreshV7(p, response);
3249 } else {
3250 int *p_cur = ((int *) response);
3251 p.writeInt32(p_cur[0]);
3252 p.writeInt32(p_cur[1]);
3253 writeStringToParcel(p, NULL);
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003254
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003255 appendPrintBuf("%sresult=%d, ef_id=%d",
3256 printBuf,
3257 p_cur[0],
3258 p_cur[1]);
3259 }
Sanket Padawef53c5fa2016-01-27 10:00:38 -08003260 } else { // RIL version >= 13
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003261 if (responselen % sizeof(RIL_SimRefreshResponse_v7) != 0) {
3262 RLOGE("Data structure expected is RIL_SimRefreshResponse_v7");
3263 if (!isDebuggable()) {
3264 return RIL_ERRNO_INVALID_RESPONSE;
3265 } else {
3266 assert(0);
3267 }
3268 }
3269 responseSimRefreshV7(p, response);
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003270
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003271 }
3272 closeResponse;
3273
3274 return 0;
3275}
3276
Sanket Padawef53c5fa2016-01-27 10:00:38 -08003277static int responseCellInfoListV6(Parcel &p, void *response, size_t responselen) {
Wink Saville8a9e0212013-04-09 12:11:38 -07003278 if (response == NULL && responselen != 0) {
3279 RLOGE("invalid response: NULL");
3280 return RIL_ERRNO_INVALID_RESPONSE;
3281 }
3282
3283 if (responselen % sizeof(RIL_CellInfo) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07003284 RLOGE("responseCellInfoList: invalid response length %d expected multiple of %d",
Wink Saville8a9e0212013-04-09 12:11:38 -07003285 (int)responselen, (int)sizeof(RIL_CellInfo));
3286 return RIL_ERRNO_INVALID_RESPONSE;
3287 }
3288
3289 int num = responselen / sizeof(RIL_CellInfo);
3290 p.writeInt32(num);
3291
3292 RIL_CellInfo *p_cur = (RIL_CellInfo *) response;
3293 startResponse;
3294 int i;
3295 for (i = 0; i < num; i++) {
3296 appendPrintBuf("%s[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", printBuf, i,
3297 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
3298 p.writeInt32((int)p_cur->cellInfoType);
3299 p.writeInt32(p_cur->registered);
3300 p.writeInt32(p_cur->timeStampType);
3301 p.writeInt64(p_cur->timeStamp);
3302 switch(p_cur->cellInfoType) {
3303 case RIL_CELL_INFO_TYPE_GSM: {
Wink Savillec57b3eb2013-04-17 12:51:41 -07003304 appendPrintBuf("%s GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,", printBuf,
Wink Saville8a9e0212013-04-09 12:11:38 -07003305 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
3306 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
3307 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
Wink Savillec57b3eb2013-04-17 12:51:41 -07003308 p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3309 appendPrintBuf("%s gsmSS: ss=%d,ber=%d],", printBuf,
Wink Saville8a9e0212013-04-09 12:11:38 -07003310 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
3311 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3312
3313 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
3314 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
3315 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
3316 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
Wink Saville8a9e0212013-04-09 12:11:38 -07003317 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
3318 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3319 break;
3320 }
Wink Savillec57b3eb2013-04-17 12:51:41 -07003321 case RIL_CELL_INFO_TYPE_WCDMA: {
3322 appendPrintBuf("%s WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,", printBuf,
3323 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
3324 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
3325 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
3326 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
3327 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3328 appendPrintBuf("%s wcdmaSS: ss=%d,ber=%d],", printBuf,
3329 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
3330 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3331
3332 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
3333 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
3334 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
3335 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
3336 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3337 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
3338 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3339 break;
3340 }
Wink Saville8a9e0212013-04-09 12:11:38 -07003341 case RIL_CELL_INFO_TYPE_CDMA: {
3342 appendPrintBuf("%s CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d", printBuf,
3343 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
3344 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
3345 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
3346 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
3347 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3348
3349 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
3350 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
3351 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
3352 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
3353 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3354
3355 appendPrintBuf("%s cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d", printBuf,
3356 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
3357 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
3358 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
3359 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
3360 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3361
3362 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
3363 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
3364 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
3365 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
3366 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3367 break;
3368 }
3369 case RIL_CELL_INFO_TYPE_LTE: {
3370 appendPrintBuf("%s LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d", printBuf,
3371 p_cur->CellInfo.lte.cellIdentityLte.mcc,
3372 p_cur->CellInfo.lte.cellIdentityLte.mnc,
3373 p_cur->CellInfo.lte.cellIdentityLte.ci,
3374 p_cur->CellInfo.lte.cellIdentityLte.pci,
3375 p_cur->CellInfo.lte.cellIdentityLte.tac);
3376
3377 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
3378 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
3379 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
3380 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
3381 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
3382
3383 appendPrintBuf("%s lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d", printBuf,
3384 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
3385 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
3386 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
3387 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
3388 p_cur->CellInfo.lte.signalStrengthLte.cqi,
3389 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3390 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
3391 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
3392 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
3393 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
3394 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
3395 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3396 break;
3397 }
Etan Cohend3652192014-06-20 08:28:44 -07003398 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
3399 appendPrintBuf("%s TDSCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,cpid=%d,", printBuf,
3400 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc,
3401 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc,
3402 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac,
3403 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid,
3404 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3405 appendPrintBuf("%s tdscdmaSS: rscp=%d],", printBuf,
3406 p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3407
3408 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
3409 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
3410 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
3411 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
3412 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3413 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3414 break;
3415 }
Wink Saville8a9e0212013-04-09 12:11:38 -07003416 }
3417 p_cur += 1;
3418 }
3419 removeLastChar;
3420 closeResponse;
3421
3422 return 0;
3423}
3424
Sanket Padawef53c5fa2016-01-27 10:00:38 -08003425static int responseCellInfoListV12(Parcel &p, void *response, size_t responselen) {
3426 if (response == NULL && responselen != 0) {
3427 RLOGE("invalid response: NULL");
3428 return RIL_ERRNO_INVALID_RESPONSE;
3429 }
3430
3431 if (responselen % sizeof(RIL_CellInfo_v12) != 0) {
3432 RLOGE("responseCellInfoList: invalid response length %d expected multiple of %d",
3433 (int)responselen, (int)sizeof(RIL_CellInfo_v12));
3434 return RIL_ERRNO_INVALID_RESPONSE;
3435 }
3436
3437 int num = responselen / sizeof(RIL_CellInfo_v12);
3438 p.writeInt32(num);
3439
3440 RIL_CellInfo_v12 *p_cur = (RIL_CellInfo_v12 *) response;
3441 startResponse;
3442 int i;
3443 for (i = 0; i < num; i++) {
3444 appendPrintBuf("%s[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", printBuf, i,
3445 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
3446 RLOGE("[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", i,
3447 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
3448 p.writeInt32((int)p_cur->cellInfoType);
3449 p.writeInt32(p_cur->registered);
3450 p.writeInt32(p_cur->timeStampType);
3451 p.writeInt64(p_cur->timeStamp);
3452 switch(p_cur->cellInfoType) {
3453 case RIL_CELL_INFO_TYPE_GSM: {
3454 appendPrintBuf("%s GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,arfcn=%d,bsic=%x", printBuf,
3455 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
3456 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
3457 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
3458 p_cur->CellInfo.gsm.cellIdentityGsm.cid,
3459 p_cur->CellInfo.gsm.cellIdentityGsm.arfcn,
3460 p_cur->CellInfo.gsm.cellIdentityGsm.bsic);
3461 RLOGE("GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,arfcn=%d,bsic=%x",
3462 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
3463 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
3464 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
3465 p_cur->CellInfo.gsm.cellIdentityGsm.cid,
3466 p_cur->CellInfo.gsm.cellIdentityGsm.arfcn,
3467 p_cur->CellInfo.gsm.cellIdentityGsm.bsic);
3468 RLOGE("gsmSS: ss=%d,ber=%d, ta=%d],",
3469 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
3470 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate,
3471 p_cur->CellInfo.gsm.signalStrengthGsm.timingAdvance);
3472 appendPrintBuf("%s gsmSS: ss=%d,ber=%d, ta=%d],", printBuf,
3473 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
3474 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate,
3475 p_cur->CellInfo.gsm.signalStrengthGsm.timingAdvance);
3476
3477 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
3478 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
3479 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
3480 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3481 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.arfcn);
3482 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.bsic);
3483 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
3484 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3485 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.timingAdvance);
3486 break;
3487 }
3488 case RIL_CELL_INFO_TYPE_WCDMA: {
3489 RLOGE("WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,uarfcn=%d",
3490 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
3491 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
3492 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
3493 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
3494 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc,
3495 p_cur->CellInfo.wcdma.cellIdentityWcdma.uarfcn);
3496 RLOGE("wcdmaSS: ss=%d,ber=%d],",
3497 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
3498 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3499 appendPrintBuf("%s WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,uarfcn=%d", printBuf,
3500 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
3501 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
3502 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
3503 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
3504 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc,
3505 p_cur->CellInfo.wcdma.cellIdentityWcdma.uarfcn);
3506 appendPrintBuf("%s wcdmaSS: ss=%d,ber=%d],", printBuf,
3507 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
3508 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3509
3510 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
3511 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
3512 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
3513 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
3514 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3515 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.uarfcn);
3516 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
3517 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3518 break;
3519 }
3520 case RIL_CELL_INFO_TYPE_CDMA: {
3521 RLOGE("CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d",
3522 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
3523 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
3524 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
3525 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
3526 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3527
3528 appendPrintBuf("%s CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d", printBuf,
3529 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
3530 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
3531 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
3532 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
3533 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3534
3535 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
3536 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
3537 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
3538 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
3539 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3540
3541 RLOGE("cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d",
3542 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
3543 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
3544 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
3545 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
3546 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3547
3548 appendPrintBuf("%s cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d", printBuf,
3549 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
3550 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
3551 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
3552 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
3553 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3554
3555 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
3556 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
3557 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
3558 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
3559 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3560 break;
3561 }
3562 case RIL_CELL_INFO_TYPE_LTE: {
3563 RLOGE("LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d,earfcn=%d",
3564 p_cur->CellInfo.lte.cellIdentityLte.mcc,
3565 p_cur->CellInfo.lte.cellIdentityLte.mnc,
3566 p_cur->CellInfo.lte.cellIdentityLte.ci,
3567 p_cur->CellInfo.lte.cellIdentityLte.pci,
3568 p_cur->CellInfo.lte.cellIdentityLte.tac,
3569 p_cur->CellInfo.lte.cellIdentityLte.earfcn);
3570
3571 appendPrintBuf("%s LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d,earfcn=%d", printBuf,
3572 p_cur->CellInfo.lte.cellIdentityLte.mcc,
3573 p_cur->CellInfo.lte.cellIdentityLte.mnc,
3574 p_cur->CellInfo.lte.cellIdentityLte.ci,
3575 p_cur->CellInfo.lte.cellIdentityLte.pci,
3576 p_cur->CellInfo.lte.cellIdentityLte.tac,
3577 p_cur->CellInfo.lte.cellIdentityLte.earfcn);
3578
3579 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
3580 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
3581 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
3582 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
3583 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
3584 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.earfcn);
3585
3586 RLOGE("lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d",
3587 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
3588 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
3589 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
3590 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
3591 p_cur->CellInfo.lte.signalStrengthLte.cqi,
3592 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3593 appendPrintBuf("%s lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d", printBuf,
3594 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
3595 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
3596 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
3597 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
3598 p_cur->CellInfo.lte.signalStrengthLte.cqi,
3599 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3600 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
3601 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
3602 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
3603 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
3604 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
3605 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3606 break;
3607 }
3608 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
3609 appendPrintBuf("%s TDSCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,cpid=%d,", printBuf,
3610 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc,
3611 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc,
3612 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac,
3613 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid,
3614 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3615 appendPrintBuf("%s tdscdmaSS: rscp=%d],", printBuf,
3616 p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3617
3618 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
3619 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
3620 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
3621 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
3622 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3623 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3624 break;
3625 }
3626 }
3627 p_cur += 1;
3628 }
3629 removeLastChar;
3630 closeResponse;
3631 return 0;
3632}
3633
3634static int responseCellInfoList(Parcel &p, void *response, size_t responselen)
3635{
3636 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
3637 if (s_callbacks.version < 12) {
3638 RLOGD("responseCellInfoList: v6");
3639 return responseCellInfoListV6(p, response, responselen);
3640 } else {
3641 RLOGD("responseCellInfoList: v12");
3642 return responseCellInfoListV12(p, response, responselen);
3643 }
3644 } else { // RIL version >= 13
3645 if (responselen % sizeof(RIL_CellInfo_v12) != 0) {
3646 RLOGE("Data structure expected is RIL_CellInfo_v12");
3647 if (!isDebuggable()) {
3648 return RIL_ERRNO_INVALID_RESPONSE;
3649 } else {
3650 assert(0);
3651 }
3652 }
3653 return responseCellInfoListV12(p, response, responselen);
3654 }
3655
3656 return 0;
3657}
3658
Etan Cohend3652192014-06-20 08:28:44 -07003659static int responseHardwareConfig(Parcel &p, void *response, size_t responselen)
3660{
3661 if (response == NULL && responselen != 0) {
3662 RLOGE("invalid response: NULL");
3663 return RIL_ERRNO_INVALID_RESPONSE;
3664 }
3665
3666 if (responselen % sizeof(RIL_HardwareConfig) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07003667 RLOGE("responseHardwareConfig: invalid response length %d expected multiple of %d",
Etan Cohend3652192014-06-20 08:28:44 -07003668 (int)responselen, (int)sizeof(RIL_HardwareConfig));
3669 return RIL_ERRNO_INVALID_RESPONSE;
3670 }
3671
3672 int num = responselen / sizeof(RIL_HardwareConfig);
3673 int i;
3674 RIL_HardwareConfig *p_cur = (RIL_HardwareConfig *) response;
3675
3676 p.writeInt32(num);
3677
3678 startResponse;
3679 for (i = 0; i < num; i++) {
3680 switch (p_cur[i].type) {
3681 case RIL_HARDWARE_CONFIG_MODEM: {
3682 writeStringToParcel(p, p_cur[i].uuid);
3683 p.writeInt32((int)p_cur[i].state);
3684 p.writeInt32(p_cur[i].cfg.modem.rat);
3685 p.writeInt32(p_cur[i].cfg.modem.maxVoice);
3686 p.writeInt32(p_cur[i].cfg.modem.maxData);
3687 p.writeInt32(p_cur[i].cfg.modem.maxStandby);
3688
3689 appendPrintBuf("%s modem: uuid=%s,state=%d,rat=%08x,maxV=%d,maxD=%d,maxS=%d", printBuf,
3690 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.modem.rat,
3691 p_cur[i].cfg.modem.maxVoice, p_cur[i].cfg.modem.maxData, p_cur[i].cfg.modem.maxStandby);
3692 break;
3693 }
3694 case RIL_HARDWARE_CONFIG_SIM: {
3695 writeStringToParcel(p, p_cur[i].uuid);
3696 p.writeInt32((int)p_cur[i].state);
3697 writeStringToParcel(p, p_cur[i].cfg.sim.modemUuid);
3698
3699 appendPrintBuf("%s sim: uuid=%s,state=%d,modem-uuid=%s", printBuf,
3700 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.sim.modemUuid);
3701 break;
3702 }
3703 }
3704 }
3705 removeLastChar;
3706 closeResponse;
3707 return 0;
3708}
3709
Wink Saville8b4e4f72014-10-17 15:01:45 -07003710static int responseRadioCapability(Parcel &p, void *response, size_t responselen) {
3711 if (response == NULL) {
3712 RLOGE("invalid response: NULL");
3713 return RIL_ERRNO_INVALID_RESPONSE;
3714 }
3715
3716 if (responselen != sizeof (RIL_RadioCapability) ) {
3717 RLOGE("invalid response length was %d expected %d",
3718 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3719 return RIL_ERRNO_INVALID_RESPONSE;
3720 }
3721
3722 RIL_RadioCapability *p_cur = (RIL_RadioCapability *) response;
3723 p.writeInt32(p_cur->version);
3724 p.writeInt32(p_cur->session);
3725 p.writeInt32(p_cur->phase);
3726 p.writeInt32(p_cur->rat);
3727 writeStringToParcel(p, p_cur->logicalModemUuid);
3728 p.writeInt32(p_cur->status);
3729
3730 startResponse;
3731 appendPrintBuf("%s[version=%d,session=%d,phase=%d,\
Legler Wu8caf06f2014-10-29 14:02:14 +08003732 rat=%s,logicalModemUuid=%s,status=%d]",
Wink Saville8b4e4f72014-10-17 15:01:45 -07003733 printBuf,
3734 p_cur->version,
3735 p_cur->session,
3736 p_cur->phase,
3737 p_cur->rat,
Legler Wu8caf06f2014-10-29 14:02:14 +08003738 p_cur->logicalModemUuid,
Wink Saville8b4e4f72014-10-17 15:01:45 -07003739 p_cur->status);
3740 closeResponse;
3741 return 0;
3742}
3743
Amit Mahajan54563d32014-11-22 00:54:49 +00003744static int responseSSData(Parcel &p, void *response, size_t responselen) {
3745 RLOGD("In responseSSData");
3746 int num;
3747
3748 if (response == NULL && responselen != 0) {
3749 RLOGE("invalid response length was %d expected %d",
3750 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3751 return RIL_ERRNO_INVALID_RESPONSE;
3752 }
3753
3754 if (responselen != sizeof(RIL_StkCcUnsolSsResponse)) {
3755 RLOGE("invalid response length %d, expected %d",
3756 (int)responselen, (int)sizeof(RIL_StkCcUnsolSsResponse));
3757 return RIL_ERRNO_INVALID_RESPONSE;
3758 }
3759
3760 startResponse;
3761 RIL_StkCcUnsolSsResponse *p_cur = (RIL_StkCcUnsolSsResponse *) response;
3762 p.writeInt32(p_cur->serviceType);
3763 p.writeInt32(p_cur->requestType);
3764 p.writeInt32(p_cur->teleserviceType);
3765 p.writeInt32(p_cur->serviceClass);
3766 p.writeInt32(p_cur->result);
3767
3768 if (isServiceTypeCfQuery(p_cur->serviceType, p_cur->requestType)) {
3769 RLOGD("responseSSData CF type, num of Cf elements %d", p_cur->cfData.numValidIndexes);
3770 if (p_cur->cfData.numValidIndexes > NUM_SERVICE_CLASSES) {
3771 RLOGE("numValidIndexes is greater than max value %d, "
3772 "truncating it to max value", NUM_SERVICE_CLASSES);
3773 p_cur->cfData.numValidIndexes = NUM_SERVICE_CLASSES;
3774 }
3775 /* number of call info's */
3776 p.writeInt32(p_cur->cfData.numValidIndexes);
3777
3778 for (int i = 0; i < p_cur->cfData.numValidIndexes; i++) {
3779 RIL_CallForwardInfo cf = p_cur->cfData.cfInfo[i];
3780
3781 p.writeInt32(cf.status);
3782 p.writeInt32(cf.reason);
3783 p.writeInt32(cf.serviceClass);
3784 p.writeInt32(cf.toa);
3785 writeStringToParcel(p, cf.number);
3786 p.writeInt32(cf.timeSeconds);
3787 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
3788 (cf.status==1)?"enable":"disable", cf.reason, cf.serviceClass, cf.toa,
3789 (char*)cf.number, cf.timeSeconds);
3790 RLOGD("Data: %d,reason=%d,cls=%d,toa=%d,num=%s,tout=%d],", cf.status,
3791 cf.reason, cf.serviceClass, cf.toa, (char*)cf.number, cf.timeSeconds);
3792 }
3793 } else {
3794 p.writeInt32 (SS_INFO_MAX);
3795
3796 /* each int*/
3797 for (int i = 0; i < SS_INFO_MAX; i++) {
3798 appendPrintBuf("%s%d,", printBuf, p_cur->ssInfo[i]);
3799 RLOGD("Data: %d",p_cur->ssInfo[i]);
3800 p.writeInt32(p_cur->ssInfo[i]);
3801 }
3802 }
3803 removeLastChar;
3804 closeResponse;
3805
3806 return 0;
3807}
3808
3809static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType) {
3810 if ((reqType == SS_INTERROGATION) &&
3811 (serType == SS_CFU ||
3812 serType == SS_CF_BUSY ||
3813 serType == SS_CF_NO_REPLY ||
3814 serType == SS_CF_NOT_REACHABLE ||
3815 serType == SS_CF_ALL ||
3816 serType == SS_CF_ALL_CONDITIONAL)) {
3817 return true;
3818 }
3819 return false;
3820}
3821
Wink Saville3d54e742009-05-18 18:00:44 -07003822static void triggerEvLoop() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003823 int ret;
3824 if (!pthread_equal(pthread_self(), s_tid_dispatch)) {
3825 /* trigger event loop to wakeup. No reason to do this,
3826 * if we're in the event loop thread */
3827 do {
3828 ret = write (s_fdWakeupWrite, " ", 1);
3829 } while (ret < 0 && errno == EINTR);
3830 }
3831}
3832
Wink Saville3d54e742009-05-18 18:00:44 -07003833static void rilEventAddWakeup(struct ril_event *ev) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003834 ril_event_add(ev);
3835 triggerEvLoop();
3836}
3837
Wink Savillefd729372011-02-22 16:19:39 -08003838static void sendSimStatusAppInfo(Parcel &p, int num_apps, RIL_AppStatus appStatus[]) {
3839 p.writeInt32(num_apps);
3840 startResponse;
3841 for (int i = 0; i < num_apps; i++) {
3842 p.writeInt32(appStatus[i].app_type);
3843 p.writeInt32(appStatus[i].app_state);
3844 p.writeInt32(appStatus[i].perso_substate);
3845 writeStringToParcel(p, (const char*)(appStatus[i].aid_ptr));
3846 writeStringToParcel(p, (const char*)
3847 (appStatus[i].app_label_ptr));
3848 p.writeInt32(appStatus[i].pin1_replaced);
3849 p.writeInt32(appStatus[i].pin1);
3850 p.writeInt32(appStatus[i].pin2);
3851 appendPrintBuf("%s[app_type=%d,app_state=%d,perso_substate=%d,\
3852 aid_ptr=%s,app_label_ptr=%s,pin1_replaced=%d,pin1=%d,pin2=%d],",
3853 printBuf,
3854 appStatus[i].app_type,
3855 appStatus[i].app_state,
3856 appStatus[i].perso_substate,
3857 appStatus[i].aid_ptr,
3858 appStatus[i].app_label_ptr,
3859 appStatus[i].pin1_replaced,
3860 appStatus[i].pin1,
3861 appStatus[i].pin2);
3862 }
3863 closeResponse;
3864}
3865
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003866static void responseSimStatusV5(Parcel &p, void *response) {
3867 RIL_CardStatus_v5 *p_cur = ((RIL_CardStatus_v5 *) response);
3868
3869 p.writeInt32(p_cur->card_state);
3870 p.writeInt32(p_cur->universal_pin_state);
3871 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3872 p.writeInt32(p_cur->cdma_subscription_app_index);
3873
3874 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
3875}
3876
3877static void responseSimStatusV6(Parcel &p, void *response) {
3878 RIL_CardStatus_v6 *p_cur = ((RIL_CardStatus_v6 *) response);
3879
3880 p.writeInt32(p_cur->card_state);
3881 p.writeInt32(p_cur->universal_pin_state);
3882 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3883 p.writeInt32(p_cur->cdma_subscription_app_index);
3884 p.writeInt32(p_cur->ims_subscription_app_index);
3885
3886 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
3887}
3888
Wink Savillef4c4d362009-04-02 01:37:03 -07003889static int responseSimStatus(Parcel &p, void *response, size_t responselen) {
3890 int i;
3891
3892 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003893 RLOGE("invalid response: NULL");
Wink Savillef4c4d362009-04-02 01:37:03 -07003894 return RIL_ERRNO_INVALID_RESPONSE;
3895 }
3896
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003897 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
3898 if (responselen == sizeof (RIL_CardStatus_v6)) {
3899 responseSimStatusV6(p, response);
3900 } else if (responselen == sizeof (RIL_CardStatus_v5)) {
3901 responseSimStatusV5(p, response);
3902 } else {
3903 RLOGE("responseSimStatus: A RilCardStatus_v6 or _v5 expected\n");
3904 return RIL_ERRNO_INVALID_RESPONSE;
3905 }
Sanket Padawef53c5fa2016-01-27 10:00:38 -08003906 } else { // RIL version >= 13
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003907 if (responselen % sizeof(RIL_CardStatus_v6) != 0) {
3908 RLOGE("Data structure expected is RIL_CardStatus_v6");
3909 if (!isDebuggable()) {
3910 return RIL_ERRNO_INVALID_RESPONSE;
3911 } else {
3912 assert(0);
3913 }
3914 }
3915 responseSimStatusV6(p, response);
Wink Savillef4c4d362009-04-02 01:37:03 -07003916 }
Wink Savillef4c4d362009-04-02 01:37:03 -07003917
3918 return 0;
Wink Saville3d54e742009-05-18 18:00:44 -07003919}
Wink Savillef4c4d362009-04-02 01:37:03 -07003920
Wink Savillea592eeb2009-05-22 13:26:36 -07003921static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3922 int num = responselen / sizeof(RIL_GSM_BroadcastSmsConfigInfo *);
Wink Savillef4c4d362009-04-02 01:37:03 -07003923 p.writeInt32(num);
3924
Wink Savillef4c4d362009-04-02 01:37:03 -07003925 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07003926 RIL_GSM_BroadcastSmsConfigInfo **p_cur =
3927 (RIL_GSM_BroadcastSmsConfigInfo **) response;
3928 for (int i = 0; i < num; i++) {
3929 p.writeInt32(p_cur[i]->fromServiceId);
3930 p.writeInt32(p_cur[i]->toServiceId);
3931 p.writeInt32(p_cur[i]->fromCodeScheme);
3932 p.writeInt32(p_cur[i]->toCodeScheme);
3933 p.writeInt32(p_cur[i]->selected);
3934
3935 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId=%d, \
3936 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]",
3937 printBuf, i, p_cur[i]->fromServiceId, p_cur[i]->toServiceId,
3938 p_cur[i]->fromCodeScheme, p_cur[i]->toCodeScheme,
3939 p_cur[i]->selected);
3940 }
Wink Savillef4c4d362009-04-02 01:37:03 -07003941 closeResponse;
3942
3943 return 0;
3944}
3945
Wink Savillea592eeb2009-05-22 13:26:36 -07003946static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3947 RIL_CDMA_BroadcastSmsConfigInfo **p_cur =
3948 (RIL_CDMA_BroadcastSmsConfigInfo **) response;
Wink Savillef4c4d362009-04-02 01:37:03 -07003949
Wink Savillea592eeb2009-05-22 13:26:36 -07003950 int num = responselen / sizeof (RIL_CDMA_BroadcastSmsConfigInfo *);
3951 p.writeInt32(num);
Wink Savillef4c4d362009-04-02 01:37:03 -07003952
3953 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07003954 for (int i = 0 ; i < num ; i++ ) {
3955 p.writeInt32(p_cur[i]->service_category);
3956 p.writeInt32(p_cur[i]->language);
3957 p.writeInt32(p_cur[i]->selected);
Wink Savillef4c4d362009-04-02 01:37:03 -07003958
Wink Savillea592eeb2009-05-22 13:26:36 -07003959 appendPrintBuf("%s [%d: srvice_category=%d, language =%d, \
3960 selected =%d], ",
3961 printBuf, i, p_cur[i]->service_category, p_cur[i]->language,
3962 p_cur[i]->selected);
Wink Savillef5903df2009-04-24 11:54:14 -07003963 }
Wink Savillea592eeb2009-05-22 13:26:36 -07003964 closeResponse;
Wink Savillef5903df2009-04-24 11:54:14 -07003965
Wink Savillef4c4d362009-04-02 01:37:03 -07003966 return 0;
3967}
3968
3969static int responseCdmaSms(Parcel &p, void *response, size_t responselen) {
3970 int num;
3971 int digitCount;
3972 int digitLimit;
3973 uint8_t uct;
3974 void* dest;
3975
Wink Saville8eb2a122012-11-19 16:05:13 -08003976 RLOGD("Inside responseCdmaSms");
Wink Savillef5903df2009-04-24 11:54:14 -07003977
Wink Savillef4c4d362009-04-02 01:37:03 -07003978 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003979 RLOGE("invalid response: NULL");
Wink Savillef4c4d362009-04-02 01:37:03 -07003980 return RIL_ERRNO_INVALID_RESPONSE;
3981 }
3982
Wink Savillef5903df2009-04-24 11:54:14 -07003983 if (responselen != sizeof(RIL_CDMA_SMS_Message)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003984 RLOGE("invalid response length was %d expected %d",
Wink Savillef5903df2009-04-24 11:54:14 -07003985 (int)responselen, (int)sizeof(RIL_CDMA_SMS_Message));
Wink Savillef4c4d362009-04-02 01:37:03 -07003986 return RIL_ERRNO_INVALID_RESPONSE;
3987 }
3988
3989 RIL_CDMA_SMS_Message *p_cur = (RIL_CDMA_SMS_Message *) response;
3990 p.writeInt32(p_cur->uTeleserviceID);
3991 p.write(&(p_cur->bIsServicePresent),sizeof(uct));
3992 p.writeInt32(p_cur->uServicecategory);
3993 p.writeInt32(p_cur->sAddress.digit_mode);
3994 p.writeInt32(p_cur->sAddress.number_mode);
3995 p.writeInt32(p_cur->sAddress.number_type);
3996 p.writeInt32(p_cur->sAddress.number_plan);
3997 p.write(&(p_cur->sAddress.number_of_digits), sizeof(uct));
3998 digitLimit= MIN((p_cur->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
3999 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
4000 p.write(&(p_cur->sAddress.digits[digitCount]),sizeof(uct));
4001 }
4002
4003 p.writeInt32(p_cur->sSubAddress.subaddressType);
4004 p.write(&(p_cur->sSubAddress.odd),sizeof(uct));
4005 p.write(&(p_cur->sSubAddress.number_of_digits),sizeof(uct));
4006 digitLimit= MIN((p_cur->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
4007 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
4008 p.write(&(p_cur->sSubAddress.digits[digitCount]),sizeof(uct));
4009 }
4010
4011 digitLimit= MIN((p_cur->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
4012 p.writeInt32(p_cur->uBearerDataLen);
4013 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
4014 p.write(&(p_cur->aBearerData[digitCount]), sizeof(uct));
4015 }
4016
4017 startResponse;
4018 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
Wink Saville1b5fd232009-04-22 14:50:00 -07004019 sAddress.digit_mode=%d, sAddress.number_mode=%d, sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07004020 printBuf, p_cur->uTeleserviceID,p_cur->bIsServicePresent,p_cur->uServicecategory,
4021 p_cur->sAddress.digit_mode, p_cur->sAddress.number_mode,p_cur->sAddress.number_type);
4022 closeResponse;
4023
4024 return 0;
4025}
4026
Wink Savillec29360a2014-07-13 05:17:28 -07004027static int responseDcRtInfo(Parcel &p, void *response, size_t responselen)
4028{
4029 int num = responselen / sizeof(RIL_DcRtInfo);
4030 if ((responselen % sizeof(RIL_DcRtInfo) != 0) || (num != 1)) {
Amit Mahajan52500162014-07-29 17:36:48 -07004031 RLOGE("responseDcRtInfo: invalid response length %d expected multiple of %d",
Wink Savillec29360a2014-07-13 05:17:28 -07004032 (int)responselen, (int)sizeof(RIL_DcRtInfo));
4033 return RIL_ERRNO_INVALID_RESPONSE;
4034 }
4035
4036 startResponse;
4037 RIL_DcRtInfo *pDcRtInfo = (RIL_DcRtInfo *)response;
4038 p.writeInt64(pDcRtInfo->time);
4039 p.writeInt32(pDcRtInfo->powerState);
4040 appendPrintBuf("%s[time=%d,powerState=%d]", printBuf,
4041 pDcRtInfo->time,
4042 pDcRtInfo->powerState);
4043 closeResponse;
4044
4045 return 0;
4046}
4047
fengluf7408292015-04-14 14:53:55 -07004048static int responseLceStatus(Parcel &p, void *response, size_t responselen) {
4049 if (response == NULL || responselen != sizeof(RIL_LceStatusInfo)) {
4050 if (response == NULL) {
4051 RLOGE("invalid response: NULL");
4052 }
4053 else {
4054 RLOGE("responseLceStatus: invalid response length %d expecting len: d%",
4055 sizeof(RIL_LceStatusInfo), responselen);
4056 }
4057 return RIL_ERRNO_INVALID_RESPONSE;
4058 }
4059
4060 RIL_LceStatusInfo *p_cur = (RIL_LceStatusInfo *)response;
4061 p.write((void *)p_cur, 1); // p_cur->lce_status takes one byte.
4062 p.writeInt32(p_cur->actual_interval_ms);
4063
4064 startResponse;
4065 appendPrintBuf("LCE Status: %d, actual_interval_ms: %d",
4066 p_cur->lce_status, p_cur->actual_interval_ms);
4067 closeResponse;
4068
4069 return 0;
4070}
4071
4072static int responseLceData(Parcel &p, void *response, size_t responselen) {
4073 if (response == NULL || responselen != sizeof(RIL_LceDataInfo)) {
4074 if (response == NULL) {
4075 RLOGE("invalid response: NULL");
4076 }
4077 else {
4078 RLOGE("responseLceData: invalid response length %d expecting len: d%",
4079 sizeof(RIL_LceDataInfo), responselen);
4080 }
4081 return RIL_ERRNO_INVALID_RESPONSE;
4082 }
4083
4084 RIL_LceDataInfo *p_cur = (RIL_LceDataInfo *)response;
4085 p.writeInt32(p_cur->last_hop_capacity_kbps);
4086
4087 /* p_cur->confidence_level and p_cur->lce_suspended take 1 byte each.*/
4088 p.write((void *)&(p_cur->confidence_level), 1);
4089 p.write((void *)&(p_cur->lce_suspended), 1);
4090
4091 startResponse;
4092 appendPrintBuf("LCE info received: capacity %d confidence level %d
4093 and suspended %d",
4094 p_cur->last_hop_capacity_kbps, p_cur->confidence_level,
4095 p_cur->lce_suspended);
4096 closeResponse;
4097
4098 return 0;
4099}
4100
Prerepa Viswanadham73157492015-05-28 00:37:32 -07004101static int responseActivityData(Parcel &p, void *response, size_t responselen) {
4102 if (response == NULL || responselen != sizeof(RIL_ActivityStatsInfo)) {
4103 if (response == NULL) {
4104 RLOGE("invalid response: NULL");
4105 }
4106 else {
4107 RLOGE("responseActivityData: invalid response length %d expecting len: d%",
4108 sizeof(RIL_ActivityStatsInfo), responselen);
4109 }
4110 return RIL_ERRNO_INVALID_RESPONSE;
4111 }
4112
4113 RIL_ActivityStatsInfo *p_cur = (RIL_ActivityStatsInfo *)response;
4114 p.writeInt32(p_cur->sleep_mode_time_ms);
4115 p.writeInt32(p_cur->idle_mode_time_ms);
4116 for(int i = 0; i < RIL_NUM_TX_POWER_LEVELS; i++) {
4117 p.writeInt32(p_cur->tx_mode_time_ms[i]);
4118 }
4119 p.writeInt32(p_cur->rx_mode_time_ms);
4120
4121 startResponse;
4122 appendPrintBuf("Modem activity info received: sleep_mode_time_ms %d idle_mode_time_ms %d
4123 tx_mode_time_ms %d %d %d %d %d and rx_mode_time_ms %d",
4124 p_cur->sleep_mode_time_ms, p_cur->idle_mode_time_ms, p_cur->tx_mode_time_ms[0],
4125 p_cur->tx_mode_time_ms[1], p_cur->tx_mode_time_ms[2], p_cur->tx_mode_time_ms[3],
4126 p_cur->tx_mode_time_ms[4], p_cur->rx_mode_time_ms);
4127 closeResponse;
4128
4129 return 0;
4130}
4131
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004132/**
4133 * A write on the wakeup fd is done just to pop us out of select()
4134 * We empty the buffer here and then ril_event will reset the timers on the
4135 * way back down
4136 */
Wink Savillef4c4d362009-04-02 01:37:03 -07004137static void processWakeupCallback(int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004138 char buff[16];
4139 int ret;
4140
Wink Saville8eb2a122012-11-19 16:05:13 -08004141 RLOGV("processWakeupCallback");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004142
4143 /* empty our wakeup socket out */
4144 do {
4145 ret = read(s_fdWakeupRead, &buff, sizeof(buff));
Wink Saville7f856802009-06-09 10:23:37 -07004146 } while (ret > 0 || (ret < 0 && errno == EINTR));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004147}
4148
Etan Cohend3652192014-06-20 08:28:44 -07004149static void onCommandsSocketClosed(RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004150 int ret;
4151 RequestInfo *p_cur;
Etan Cohend3652192014-06-20 08:28:44 -07004152 /* Hook for current context
4153 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
4154 pthread_mutex_t * pendingRequestsMutexHook = &s_pendingRequestsMutex;
4155 /* pendingRequestsHook refer to &s_pendingRequests */
4156 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004157
Etan Cohend3652192014-06-20 08:28:44 -07004158#if (SIM_COUNT >= 2)
4159 if (socket_id == RIL_SOCKET_2) {
4160 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
4161 pendingRequestsHook = &s_pendingRequests_socket2;
4162 }
4163#if (SIM_COUNT >= 3)
4164 else if (socket_id == RIL_SOCKET_3) {
4165 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
4166 pendingRequestsHook = &s_pendingRequests_socket3;
4167 }
4168#endif
4169#if (SIM_COUNT >= 4)
4170 else if (socket_id == RIL_SOCKET_4) {
4171 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
4172 pendingRequestsHook = &s_pendingRequests_socket4;
4173 }
4174#endif
4175#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004176 /* mark pending requests as "cancelled" so we dont report responses */
Etan Cohend3652192014-06-20 08:28:44 -07004177 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004178 assert (ret == 0);
4179
Etan Cohend3652192014-06-20 08:28:44 -07004180 p_cur = *pendingRequestsHook;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004181
Etan Cohend3652192014-06-20 08:28:44 -07004182 for (p_cur = *pendingRequestsHook
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004183 ; p_cur != NULL
4184 ; p_cur = p_cur->p_next
4185 ) {
4186 p_cur->cancelled = 1;
4187 }
4188
Etan Cohend3652192014-06-20 08:28:44 -07004189 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004190 assert (ret == 0);
4191}
4192
Wink Savillef4c4d362009-04-02 01:37:03 -07004193static void processCommandsCallback(int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004194 RecordStream *p_rs;
4195 void *p_record;
4196 size_t recordlen;
4197 int ret;
Etan Cohend3652192014-06-20 08:28:44 -07004198 SocketListenParam *p_info = (SocketListenParam *)param;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004199
Etan Cohend3652192014-06-20 08:28:44 -07004200 assert(fd == p_info->fdCommand);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004201
Etan Cohend3652192014-06-20 08:28:44 -07004202 p_rs = p_info->p_rs;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004203
4204 for (;;) {
4205 /* loop until EAGAIN/EINTR, end of stream, or other error */
4206 ret = record_stream_get_next(p_rs, &p_record, &recordlen);
4207
4208 if (ret == 0 && p_record == NULL) {
4209 /* end-of-stream */
4210 break;
4211 } else if (ret < 0) {
4212 break;
4213 } else if (ret == 0) { /* && p_record != NULL */
Etan Cohend3652192014-06-20 08:28:44 -07004214 processCommandBuffer(p_record, recordlen, p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004215 }
4216 }
4217
4218 if (ret == 0 || !(errno == EAGAIN || errno == EINTR)) {
4219 /* fatal error or end-of-stream */
4220 if (ret != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004221 RLOGE("error on reading command socket errno:%d\n", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004222 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08004223 RLOGW("EOS. Closing command socket.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004224 }
Wink Saville7f856802009-06-09 10:23:37 -07004225
Etan Cohend3652192014-06-20 08:28:44 -07004226 close(fd);
4227 p_info->fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004228
Etan Cohend3652192014-06-20 08:28:44 -07004229 ril_event_del(p_info->commands_event);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004230
4231 record_stream_free(p_rs);
4232
4233 /* start listening for new connections again */
4234 rilEventAddWakeup(&s_listen_event);
4235
Etan Cohend3652192014-06-20 08:28:44 -07004236 onCommandsSocketClosed(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004237 }
4238}
4239
4240
Etan Cohend3652192014-06-20 08:28:44 -07004241static void onNewCommandConnect(RIL_SOCKET_ID socket_id) {
Wink Saville5b9df332011-04-06 16:24:21 -07004242 // Inform we are connected and the ril version
Jake Hambya9c18d12011-04-12 23:32:08 -07004243 int rilVer = s_callbacks.version;
Etan Cohend3652192014-06-20 08:28:44 -07004244 RIL_UNSOL_RESPONSE(RIL_UNSOL_RIL_CONNECTED,
4245 &rilVer, sizeof(rilVer), socket_id);
Wink Saville5b9df332011-04-06 16:24:21 -07004246
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004247 // implicit radio state changed
Etan Cohend3652192014-06-20 08:28:44 -07004248 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
4249 NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004250
4251 // Send last NITZ time data, in case it was missed
4252 if (s_lastNITZTimeData != NULL) {
Etan Cohend3652192014-06-20 08:28:44 -07004253 sendResponseRaw(s_lastNITZTimeData, s_lastNITZTimeDataSize, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004254
4255 free(s_lastNITZTimeData);
4256 s_lastNITZTimeData = NULL;
4257 }
4258
4259 // Get version string
4260 if (s_callbacks.getVersion != NULL) {
4261 const char *version;
4262 version = s_callbacks.getVersion();
Wink Saville8eb2a122012-11-19 16:05:13 -08004263 RLOGI("RIL Daemon version: %s\n", version);
Wink Saville7f856802009-06-09 10:23:37 -07004264
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004265 property_set(PROPERTY_RIL_IMPL, version);
4266 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08004267 RLOGI("RIL Daemon version: unavailable\n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004268 property_set(PROPERTY_RIL_IMPL, "unavailable");
4269 }
4270
4271}
4272
Wink Savillef4c4d362009-04-02 01:37:03 -07004273static void listenCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004274 int ret;
4275 int err;
4276 int is_phone_socket;
Etan Cohend3652192014-06-20 08:28:44 -07004277 int fdCommand = -1;
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004278 char* processName;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004279 RecordStream *p_rs;
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004280 MySocketListenParam* listenParam;
4281 RilSocket *sapSocket = NULL;
4282 socketClient *sClient = NULL;
4283
Etan Cohend3652192014-06-20 08:28:44 -07004284 SocketListenParam *p_info = (SocketListenParam *)param;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004285
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004286 if(RIL_SAP_SOCKET == p_info->type) {
4287 listenParam = (MySocketListenParam *)param;
4288 sapSocket = listenParam->socket;
4289 }
4290
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004291 struct sockaddr_un peeraddr;
4292 socklen_t socklen = sizeof (peeraddr);
4293
4294 struct ucred creds;
4295 socklen_t szCreds = sizeof(creds);
4296
4297 struct passwd *pwd = NULL;
4298
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004299 if(NULL == sapSocket) {
4300 assert (*p_info->fdCommand < 0);
4301 assert (fd == *p_info->fdListen);
4302 processName = PHONE_PROCESS;
4303 } else {
4304 assert (sapSocket->commandFd < 0);
4305 assert (fd == sapSocket->listenFd);
4306 processName = BLUETOOTH_PROCESS;
4307 }
4308
Wink Saville7f856802009-06-09 10:23:37 -07004309
Etan Cohend3652192014-06-20 08:28:44 -07004310 fdCommand = accept(fd, (sockaddr *) &peeraddr, &socklen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004311
Etan Cohend3652192014-06-20 08:28:44 -07004312 if (fdCommand < 0 ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004313 RLOGE("Error on accept() errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004314 /* start listening for new connections again */
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004315 if(NULL == sapSocket) {
4316 rilEventAddWakeup(p_info->listen_event);
4317 } else {
4318 rilEventAddWakeup(sapSocket->getListenEvent());
4319 }
Etan Cohend3652192014-06-20 08:28:44 -07004320 return;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004321 }
4322
4323 /* check the credential of the other side and only accept socket from
4324 * phone process
Wink Saville7f856802009-06-09 10:23:37 -07004325 */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004326 errno = 0;
4327 is_phone_socket = 0;
Wink Savillef4c4d362009-04-02 01:37:03 -07004328
Etan Cohend3652192014-06-20 08:28:44 -07004329 err = getsockopt(fdCommand, SOL_SOCKET, SO_PEERCRED, &creds, &szCreds);
Wink Savillef4c4d362009-04-02 01:37:03 -07004330
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004331 if (err == 0 && szCreds > 0) {
Wink Savillef4c4d362009-04-02 01:37:03 -07004332 errno = 0;
4333 pwd = getpwuid(creds.uid);
4334 if (pwd != NULL) {
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004335 if (strcmp(pwd->pw_name, processName) == 0) {
Wink Savillef4c4d362009-04-02 01:37:03 -07004336 is_phone_socket = 1;
4337 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08004338 RLOGE("RILD can't accept socket from process %s", pwd->pw_name);
Wink Savillef4c4d362009-04-02 01:37:03 -07004339 }
4340 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08004341 RLOGE("Error on getpwuid() errno: %d", errno);
Wink Savillef4c4d362009-04-02 01:37:03 -07004342 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004343 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08004344 RLOGD("Error on getsockopt() errno: %d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004345 }
4346
Etan Cohend3652192014-06-20 08:28:44 -07004347 if (!is_phone_socket) {
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004348 RLOGE("RILD must accept socket from %s", processName);
Wink Saville7f856802009-06-09 10:23:37 -07004349
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004350 close(fdCommand);
4351 fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004352
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004353 if(NULL == sapSocket) {
4354 onCommandsSocketClosed(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004355
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004356 /* start listening for new connections again */
4357 rilEventAddWakeup(p_info->listen_event);
4358 } else {
4359 sapSocket->onCommandsSocketClosed();
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004360
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004361 /* start listening for new connections again */
4362 rilEventAddWakeup(sapSocket->getListenEvent());
4363 }
4364
4365 return;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004366 }
4367
Etan Cohend3652192014-06-20 08:28:44 -07004368 ret = fcntl(fdCommand, F_SETFL, O_NONBLOCK);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004369
4370 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004371 RLOGE ("Error setting O_NONBLOCK errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004372 }
4373
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004374 if(NULL == sapSocket) {
4375 RLOGI("libril: new connection to %s", rilSocketIdToString(p_info->socket_id));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004376
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004377 p_info->fdCommand = fdCommand;
4378 p_rs = record_stream_new(p_info->fdCommand, MAX_COMMAND_BYTES);
4379 p_info->p_rs = p_rs;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004380
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004381 ril_event_set (p_info->commands_event, p_info->fdCommand, 1,
Etan Cohend3652192014-06-20 08:28:44 -07004382 p_info->processCommandsCallback, p_info);
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004383 rilEventAddWakeup (p_info->commands_event);
Etan Cohend3652192014-06-20 08:28:44 -07004384
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004385 onNewCommandConnect(p_info->socket_id);
4386 } else {
4387 RLOGI("libril: new connection");
Etan Cohend3652192014-06-20 08:28:44 -07004388
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004389 sapSocket->setCommandFd(fdCommand);
4390 p_rs = record_stream_new(sapSocket->getCommandFd(), MAX_COMMAND_BYTES);
4391 sClient = new socketClient(sapSocket,p_rs);
4392 ril_event_set (sapSocket->getCallbackEvent(), sapSocket->getCommandFd(), 1,
4393 sapSocket->getCommandCb(), sClient);
4394
4395 rilEventAddWakeup(sapSocket->getCallbackEvent());
4396 sapSocket->onNewCommandConnect();
4397 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004398}
4399
4400static void freeDebugCallbackArgs(int number, char **args) {
4401 for (int i = 0; i < number; i++) {
4402 if (args[i] != NULL) {
4403 free(args[i]);
4404 }
4405 }
4406 free(args);
4407}
4408
Wink Savillef4c4d362009-04-02 01:37:03 -07004409static void debugCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004410 int acceptFD, option;
4411 struct sockaddr_un peeraddr;
4412 socklen_t socklen = sizeof (peeraddr);
4413 int data;
4414 unsigned int qxdm_data[6];
4415 const char *deactData[1] = {"1"};
4416 char *actData[1];
4417 RIL_Dial dialData;
4418 int hangupData[1] = {1};
4419 int number;
4420 char **args;
Etan Cohend3652192014-06-20 08:28:44 -07004421 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
4422 int sim_id = 0;
4423
4424 RLOGI("debugCallback for socket %s", rilSocketIdToString(socket_id));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004425
4426 acceptFD = accept (fd, (sockaddr *) &peeraddr, &socklen);
4427
4428 if (acceptFD < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004429 RLOGE ("error accepting on debug port: %d\n", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004430 return;
4431 }
4432
4433 if (recv(acceptFD, &number, sizeof(int), 0) != sizeof(int)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004434 RLOGE ("error reading on socket: number of Args: \n");
Sanket Padawe55227b52016-02-29 10:09:26 -08004435 close(acceptFD);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004436 return;
4437 }
Sanket Padawe55227b52016-02-29 10:09:26 -08004438
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004439 args = (char **) malloc(sizeof(char*) * number);
Sanket Padawe55227b52016-02-29 10:09:26 -08004440 if (args == NULL) {
4441 RLOGE("Memory allocation failed for debug args");
4442 close(acceptFD);
4443 return;
4444 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004445
4446 for (int i = 0; i < number; i++) {
4447 int len;
4448 if (recv(acceptFD, &len, sizeof(int), 0) != sizeof(int)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004449 RLOGE ("error reading on socket: Len of Args: \n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004450 freeDebugCallbackArgs(i, args);
Sanket Padawe55227b52016-02-29 10:09:26 -08004451 close(acceptFD);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004452 return;
4453 }
Sanket Padawe55227b52016-02-29 10:09:26 -08004454
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004455 // +1 for null-term
4456 args[i] = (char *) malloc((sizeof(char) * len) + 1);
Sanket Padawe55227b52016-02-29 10:09:26 -08004457 if (args[i] == NULL) {
4458 RLOGE("Memory allocation failed for debug args");
4459 freeDebugCallbackArgs(i, args);
4460 close(acceptFD);
4461 return;
4462 }
Wink Saville7f856802009-06-09 10:23:37 -07004463 if (recv(acceptFD, args[i], sizeof(char) * len, 0)
Wink Saville1b5fd232009-04-22 14:50:00 -07004464 != (int)sizeof(char) * len) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004465 RLOGE ("error reading on socket: Args[%d] \n", i);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004466 freeDebugCallbackArgs(i, args);
Sanket Padawe55227b52016-02-29 10:09:26 -08004467 close(acceptFD);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004468 return;
4469 }
4470 char * buf = args[i];
4471 buf[len] = 0;
Etan Cohend3652192014-06-20 08:28:44 -07004472 if ((i+1) == number) {
4473 /* The last argument should be sim id 0(SIM1)~3(SIM4) */
4474 sim_id = atoi(args[i]);
4475 switch (sim_id) {
4476 case 0:
4477 socket_id = RIL_SOCKET_1;
4478 break;
4479 #if (SIM_COUNT >= 2)
4480 case 1:
4481 socket_id = RIL_SOCKET_2;
4482 break;
4483 #endif
4484 #if (SIM_COUNT >= 3)
4485 case 2:
4486 socket_id = RIL_SOCKET_3;
4487 break;
4488 #endif
4489 #if (SIM_COUNT >= 4)
4490 case 3:
4491 socket_id = RIL_SOCKET_4;
4492 break;
4493 #endif
4494 default:
4495 socket_id = RIL_SOCKET_1;
4496 break;
4497 }
4498 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004499 }
4500
4501 switch (atoi(args[0])) {
4502 case 0:
Wink Saville8eb2a122012-11-19 16:05:13 -08004503 RLOGI ("Connection on debug port: issuing reset.");
Etan Cohend3652192014-06-20 08:28:44 -07004504 issueLocalRequest(RIL_REQUEST_RESET_RADIO, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004505 break;
4506 case 1:
Wink Saville8eb2a122012-11-19 16:05:13 -08004507 RLOGI ("Connection on debug port: issuing radio power off.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004508 data = 0;
Etan Cohend3652192014-06-20 08:28:44 -07004509 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004510 // Close the socket
Etan Cohend3652192014-06-20 08:28:44 -07004511 if (socket_id == RIL_SOCKET_1 && s_ril_param_socket.fdCommand > 0) {
4512 close(s_ril_param_socket.fdCommand);
4513 s_ril_param_socket.fdCommand = -1;
4514 }
4515 #if (SIM_COUNT == 2)
4516 else if (socket_id == RIL_SOCKET_2 && s_ril_param_socket2.fdCommand > 0) {
4517 close(s_ril_param_socket2.fdCommand);
4518 s_ril_param_socket2.fdCommand = -1;
4519 }
4520 #endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004521 break;
4522 case 2:
Wink Saville8eb2a122012-11-19 16:05:13 -08004523 RLOGI ("Debug port: issuing unsolicited voice network change.");
Etan Cohend3652192014-06-20 08:28:44 -07004524 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004525 break;
4526 case 3:
Wink Saville8eb2a122012-11-19 16:05:13 -08004527 RLOGI ("Debug port: QXDM log enable.");
Xia Wangd855ef42010-07-27 17:26:55 -07004528 qxdm_data[0] = 65536; // head.func_tag
4529 qxdm_data[1] = 16; // head.len
4530 qxdm_data[2] = 1; // mode: 1 for 'start logging'
4531 qxdm_data[3] = 32; // log_file_size: 32megabytes
4532 qxdm_data[4] = 0; // log_mask
4533 qxdm_data[5] = 8; // log_max_fileindex
Wink Saville7f856802009-06-09 10:23:37 -07004534 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Etan Cohend3652192014-06-20 08:28:44 -07004535 6 * sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004536 break;
4537 case 4:
Wink Saville8eb2a122012-11-19 16:05:13 -08004538 RLOGI ("Debug port: QXDM log disable.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004539 qxdm_data[0] = 65536;
4540 qxdm_data[1] = 16;
Xia Wangd855ef42010-07-27 17:26:55 -07004541 qxdm_data[2] = 0; // mode: 0 for 'stop logging'
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004542 qxdm_data[3] = 32;
4543 qxdm_data[4] = 0;
Xia Wangd855ef42010-07-27 17:26:55 -07004544 qxdm_data[5] = 8;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004545 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Etan Cohend3652192014-06-20 08:28:44 -07004546 6 * sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004547 break;
4548 case 5:
Wink Saville8eb2a122012-11-19 16:05:13 -08004549 RLOGI("Debug port: Radio On");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004550 data = 1;
Etan Cohend3652192014-06-20 08:28:44 -07004551 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004552 sleep(2);
4553 // Set network selection automatic.
Etan Cohend3652192014-06-20 08:28:44 -07004554 issueLocalRequest(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004555 break;
4556 case 6:
Wink Saville8eb2a122012-11-19 16:05:13 -08004557 RLOGI("Debug port: Setup Data Call, Apn :%s\n", args[1]);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004558 actData[0] = args[1];
Wink Saville7f856802009-06-09 10:23:37 -07004559 issueLocalRequest(RIL_REQUEST_SETUP_DATA_CALL, &actData,
Etan Cohend3652192014-06-20 08:28:44 -07004560 sizeof(actData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004561 break;
4562 case 7:
Wink Saville8eb2a122012-11-19 16:05:13 -08004563 RLOGI("Debug port: Deactivate Data Call");
Wink Saville7f856802009-06-09 10:23:37 -07004564 issueLocalRequest(RIL_REQUEST_DEACTIVATE_DATA_CALL, &deactData,
Etan Cohend3652192014-06-20 08:28:44 -07004565 sizeof(deactData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004566 break;
4567 case 8:
Wink Saville8eb2a122012-11-19 16:05:13 -08004568 RLOGI("Debug port: Dial Call");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004569 dialData.clir = 0;
4570 dialData.address = args[1];
Etan Cohend3652192014-06-20 08:28:44 -07004571 issueLocalRequest(RIL_REQUEST_DIAL, &dialData, sizeof(dialData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004572 break;
4573 case 9:
Wink Saville8eb2a122012-11-19 16:05:13 -08004574 RLOGI("Debug port: Answer Call");
Etan Cohend3652192014-06-20 08:28:44 -07004575 issueLocalRequest(RIL_REQUEST_ANSWER, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004576 break;
4577 case 10:
Wink Saville8eb2a122012-11-19 16:05:13 -08004578 RLOGI("Debug port: End Call");
Wink Saville7f856802009-06-09 10:23:37 -07004579 issueLocalRequest(RIL_REQUEST_HANGUP, &hangupData,
Etan Cohend3652192014-06-20 08:28:44 -07004580 sizeof(hangupData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004581 break;
4582 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004583 RLOGE ("Invalid request");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004584 break;
4585 }
4586 freeDebugCallbackArgs(number, args);
4587 close(acceptFD);
4588}
4589
4590
Wink Savillef4c4d362009-04-02 01:37:03 -07004591static void userTimerCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004592 UserCallbackInfo *p_info;
4593
4594 p_info = (UserCallbackInfo *)param;
4595
4596 p_info->p_callback(p_info->userParam);
4597
4598
4599 // FIXME generalize this...there should be a cancel mechanism
4600 if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) {
4601 s_last_wake_timeout_info = NULL;
4602 }
4603
4604 free(p_info);
4605}
4606
4607
4608static void *
Wink Savillef4c4d362009-04-02 01:37:03 -07004609eventLoop(void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004610 int ret;
4611 int filedes[2];
4612
4613 ril_event_init();
4614
4615 pthread_mutex_lock(&s_startupMutex);
4616
4617 s_started = 1;
4618 pthread_cond_broadcast(&s_startupCond);
4619
4620 pthread_mutex_unlock(&s_startupMutex);
4621
4622 ret = pipe(filedes);
4623
4624 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004625 RLOGE("Error in pipe() errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004626 return NULL;
4627 }
4628
4629 s_fdWakeupRead = filedes[0];
4630 s_fdWakeupWrite = filedes[1];
4631
4632 fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK);
4633
4634 ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,
4635 processWakeupCallback, NULL);
4636
4637 rilEventAddWakeup (&s_wakeupfd_event);
4638
4639 // Only returns on error
4640 ril_event_loop();
Wink Saville8eb2a122012-11-19 16:05:13 -08004641 RLOGE ("error in event_loop_base errno:%d", errno);
Kazuhiro Ondo5cdc1352011-10-14 17:50:58 -05004642 // kill self to restart on error
4643 kill(0, SIGKILL);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004644
4645 return NULL;
4646}
4647
Wink Saville7f856802009-06-09 10:23:37 -07004648extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07004649RIL_startEventLoop(void) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004650 /* spin up eventLoop thread and wait for it to get started */
4651 s_started = 0;
4652 pthread_mutex_lock(&s_startupMutex);
4653
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004654 pthread_attr_t attr;
4655 pthread_attr_init(&attr);
Wink Saville7f856802009-06-09 10:23:37 -07004656 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004657
Elliott Hughesfd81e712014-01-06 12:46:02 -08004658 int result = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
4659 if (result != 0) {
4660 RLOGE("Failed to create dispatch thread: %s", strerror(result));
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004661 goto done;
4662 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004663
4664 while (s_started == 0) {
4665 pthread_cond_wait(&s_startupCond, &s_startupMutex);
4666 }
4667
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004668done:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004669 pthread_mutex_unlock(&s_startupMutex);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004670}
4671
4672// Used for testing purpose only.
4673extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) {
4674 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4675}
4676
Etan Cohend3652192014-06-20 08:28:44 -07004677static void startListen(RIL_SOCKET_ID socket_id, SocketListenParam* socket_listen_p) {
4678 int fdListen = -1;
4679 int ret;
4680 char socket_name[10];
4681
4682 memset(socket_name, 0, sizeof(char)*10);
4683
4684 switch(socket_id) {
4685 case RIL_SOCKET_1:
4686 strncpy(socket_name, RIL_getRilSocketName(), 9);
4687 break;
4688 #if (SIM_COUNT >= 2)
4689 case RIL_SOCKET_2:
4690 strncpy(socket_name, SOCKET2_NAME_RIL, 9);
4691 break;
4692 #endif
4693 #if (SIM_COUNT >= 3)
4694 case RIL_SOCKET_3:
4695 strncpy(socket_name, SOCKET3_NAME_RIL, 9);
4696 break;
4697 #endif
4698 #if (SIM_COUNT >= 4)
4699 case RIL_SOCKET_4:
4700 strncpy(socket_name, SOCKET4_NAME_RIL, 9);
4701 break;
4702 #endif
4703 default:
4704 RLOGE("Socket id is wrong!!");
4705 return;
4706 }
4707
4708 RLOGI("Start to listen %s", rilSocketIdToString(socket_id));
4709
4710 fdListen = android_get_control_socket(socket_name);
4711 if (fdListen < 0) {
4712 RLOGE("Failed to get socket %s", socket_name);
4713 exit(-1);
4714 }
4715
4716 ret = listen(fdListen, 4);
4717
4718 if (ret < 0) {
4719 RLOGE("Failed to listen on control socket '%d': %s",
4720 fdListen, strerror(errno));
4721 exit(-1);
4722 }
4723 socket_listen_p->fdListen = fdListen;
4724
4725 /* note: non-persistent so we can accept only one connection at a time */
4726 ril_event_set (socket_listen_p->listen_event, fdListen, false,
4727 listenCallback, socket_listen_p);
4728
4729 rilEventAddWakeup (socket_listen_p->listen_event);
4730}
4731
Wink Saville7f856802009-06-09 10:23:37 -07004732extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07004733RIL_register (const RIL_RadioFunctions *callbacks) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004734 int ret;
4735 int flags;
4736
Etan Cohend3652192014-06-20 08:28:44 -07004737 RLOGI("SIM_COUNT: %d", SIM_COUNT);
4738
Wink Saville43808972011-01-13 17:39:51 -08004739 if (callbacks == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004740 RLOGE("RIL_register: RIL_RadioFunctions * null");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004741 return;
4742 }
Wink Saville43808972011-01-13 17:39:51 -08004743 if (callbacks->version < RIL_VERSION_MIN) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004744 RLOGE("RIL_register: version %d is to old, min version is %d",
Wink Saville43808972011-01-13 17:39:51 -08004745 callbacks->version, RIL_VERSION_MIN);
4746 return;
Wink Saville3a4840b2010-04-07 13:29:58 -07004747 }
Sanket Padawe88cf6a52016-01-11 12:45:43 -08004748
Wink Saville8eb2a122012-11-19 16:05:13 -08004749 RLOGE("RIL_register: RIL version %d", callbacks->version);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004750
4751 if (s_registerCalled > 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004752 RLOGE("RIL_register has been called more than once. "
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004753 "Subsequent call ignored");
4754 return;
4755 }
4756
4757 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4758
Etan Cohend3652192014-06-20 08:28:44 -07004759 /* Initialize socket1 parameters */
4760 s_ril_param_socket = {
4761 RIL_SOCKET_1, /* socket_id */
4762 -1, /* fdListen */
4763 -1, /* fdCommand */
4764 PHONE_PROCESS, /* processName */
4765 &s_commands_event, /* commands_event */
4766 &s_listen_event, /* listen_event */
4767 processCommandsCallback, /* processCommandsCallback */
4768 NULL /* p_rs */
4769 };
4770
4771#if (SIM_COUNT >= 2)
4772 s_ril_param_socket2 = {
4773 RIL_SOCKET_2, /* socket_id */
4774 -1, /* fdListen */
4775 -1, /* fdCommand */
4776 PHONE_PROCESS, /* processName */
4777 &s_commands_event_socket2, /* commands_event */
4778 &s_listen_event_socket2, /* listen_event */
4779 processCommandsCallback, /* processCommandsCallback */
4780 NULL /* p_rs */
4781 };
4782#endif
4783
4784#if (SIM_COUNT >= 3)
4785 s_ril_param_socket3 = {
4786 RIL_SOCKET_3, /* socket_id */
4787 -1, /* fdListen */
4788 -1, /* fdCommand */
4789 PHONE_PROCESS, /* processName */
4790 &s_commands_event_socket3, /* commands_event */
4791 &s_listen_event_socket3, /* listen_event */
4792 processCommandsCallback, /* processCommandsCallback */
4793 NULL /* p_rs */
4794 };
4795#endif
4796
4797#if (SIM_COUNT >= 4)
4798 s_ril_param_socket4 = {
4799 RIL_SOCKET_4, /* socket_id */
4800 -1, /* fdListen */
4801 -1, /* fdCommand */
4802 PHONE_PROCESS, /* processName */
4803 &s_commands_event_socket4, /* commands_event */
4804 &s_listen_event_socket4, /* listen_event */
4805 processCommandsCallback, /* processCommandsCallback */
4806 NULL /* p_rs */
4807 };
4808#endif
4809
4810
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004811 s_registerCalled = 1;
4812
Etan Cohend3652192014-06-20 08:28:44 -07004813 RLOGI("s_registerCalled flag set, %d", s_started);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004814 // Little self-check
4815
Wink Savillef4c4d362009-04-02 01:37:03 -07004816 for (int i = 0; i < (int)NUM_ELEMS(s_commands); i++) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004817 assert(i == s_commands[i].requestNumber);
4818 }
4819
Wink Savillef4c4d362009-04-02 01:37:03 -07004820 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses); i++) {
Wink Saville7f856802009-06-09 10:23:37 -07004821 assert(i + RIL_UNSOL_RESPONSE_BASE
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004822 == s_unsolResponses[i].requestNumber);
4823 }
4824
4825 // New rild impl calls RIL_startEventLoop() first
4826 // old standalone impl wants it here.
4827
4828 if (s_started == 0) {
4829 RIL_startEventLoop();
4830 }
4831
Etan Cohend3652192014-06-20 08:28:44 -07004832 // start listen socket1
4833 startListen(RIL_SOCKET_1, &s_ril_param_socket);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004834
Etan Cohend3652192014-06-20 08:28:44 -07004835#if (SIM_COUNT >= 2)
4836 // start listen socket2
4837 startListen(RIL_SOCKET_2, &s_ril_param_socket2);
4838#endif /* (SIM_COUNT == 2) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004839
Etan Cohend3652192014-06-20 08:28:44 -07004840#if (SIM_COUNT >= 3)
4841 // start listen socket3
4842 startListen(RIL_SOCKET_3, &s_ril_param_socket3);
4843#endif /* (SIM_COUNT == 3) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004844
Etan Cohend3652192014-06-20 08:28:44 -07004845#if (SIM_COUNT >= 4)
4846 // start listen socket4
4847 startListen(RIL_SOCKET_4, &s_ril_param_socket4);
4848#endif /* (SIM_COUNT == 4) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004849
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004850
4851#if 1
4852 // start debug interface socket
4853
Etan Cohend3652192014-06-20 08:28:44 -07004854 char *inst = NULL;
4855 if (strlen(RIL_getRilSocketName()) >= strlen(SOCKET_NAME_RIL)) {
4856 inst = RIL_getRilSocketName() + strlen(SOCKET_NAME_RIL);
4857 }
4858
4859 char rildebug[MAX_DEBUG_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL_DEBUG;
4860 if (inst != NULL) {
Nick Kralevichc52e45e2015-02-08 07:54:16 -08004861 strlcat(rildebug, inst, MAX_DEBUG_SOCKET_NAME_LENGTH);
Etan Cohend3652192014-06-20 08:28:44 -07004862 }
4863
4864 s_fdDebug = android_get_control_socket(rildebug);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004865 if (s_fdDebug < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07004866 RLOGE("Failed to get socket : %s errno:%d", rildebug, errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004867 exit(-1);
4868 }
4869
4870 ret = listen(s_fdDebug, 4);
4871
4872 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004873 RLOGE("Failed to listen on ril debug socket '%d': %s",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004874 s_fdDebug, strerror(errno));
4875 exit(-1);
4876 }
4877
4878 ril_event_set (&s_debug_event, s_fdDebug, true,
4879 debugCallback, NULL);
4880
4881 rilEventAddWakeup (&s_debug_event);
4882#endif
4883
4884}
4885
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004886extern "C" void
4887RIL_register_socket (RIL_RadioFunctions *(*Init)(const struct RIL_Env *, int, char **),RIL_SOCKET_TYPE socketType, int argc, char **argv) {
4888
4889 RIL_RadioFunctions* UimFuncs = NULL;
4890
4891 if(Init) {
4892 UimFuncs = Init(&RilSapSocket::uimRilEnv, argc, argv);
4893
4894 switch(socketType) {
4895 case RIL_SAP_SOCKET:
4896 RilSapSocket::initSapSocket("sap_uim_socket1", UimFuncs);
4897
4898#if (SIM_COUNT >= 2)
4899 RilSapSocket::initSapSocket("sap_uim_socket2", UimFuncs);
4900#endif
4901
4902#if (SIM_COUNT >= 3)
4903 RilSapSocket::initSapSocket("sap_uim_socket3", UimFuncs);
4904#endif
4905
4906#if (SIM_COUNT >= 4)
4907 RilSapSocket::initSapSocket("sap_uim_socket4", UimFuncs);
4908#endif
4909 }
4910 }
4911}
4912
Sanket Padawe6ff9a872016-01-27 15:09:12 -08004913// Check and remove RequestInfo if its a response and not just ack sent back
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004914static int
Sanket Padawe6ff9a872016-01-27 15:09:12 -08004915checkAndDequeueRequestInfoIfAck(struct RequestInfo *pRI, bool isAck) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004916 int ret = 0;
Etan Cohend3652192014-06-20 08:28:44 -07004917 /* Hook for current context
4918 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
4919 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
4920 /* pendingRequestsHook refer to &s_pendingRequests */
4921 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
Wink Saville7f856802009-06-09 10:23:37 -07004922
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004923 if (pRI == NULL) {
4924 return 0;
4925 }
4926
Etan Cohend3652192014-06-20 08:28:44 -07004927#if (SIM_COUNT >= 2)
4928 if (pRI->socket_id == RIL_SOCKET_2) {
4929 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
4930 pendingRequestsHook = &s_pendingRequests_socket2;
4931 }
4932#if (SIM_COUNT >= 3)
4933 if (pRI->socket_id == RIL_SOCKET_3) {
4934 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
4935 pendingRequestsHook = &s_pendingRequests_socket3;
4936 }
4937#endif
4938#if (SIM_COUNT >= 4)
4939 if (pRI->socket_id == RIL_SOCKET_4) {
4940 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
4941 pendingRequestsHook = &s_pendingRequests_socket4;
4942 }
4943#endif
4944#endif
4945 pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004946
Etan Cohend3652192014-06-20 08:28:44 -07004947 for(RequestInfo **ppCur = pendingRequestsHook
Wink Saville7f856802009-06-09 10:23:37 -07004948 ; *ppCur != NULL
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004949 ; ppCur = &((*ppCur)->p_next)
4950 ) {
4951 if (pRI == *ppCur) {
4952 ret = 1;
Sanket Padawe6ff9a872016-01-27 15:09:12 -08004953 if (isAck) { // Async ack
4954 if (pRI->wasAckSent == 1) {
4955 RLOGD("Ack was already sent for %s", requestToString(pRI->pCI->requestNumber));
4956 } else {
4957 pRI->wasAckSent = 1;
4958 }
4959 } else {
4960 *ppCur = (*ppCur)->p_next;
4961 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004962 break;
4963 }
4964 }
4965
Etan Cohend3652192014-06-20 08:28:44 -07004966 pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004967
4968 return ret;
4969}
4970
Sanket Padawe6ff9a872016-01-27 15:09:12 -08004971static int findFd(int socket_id) {
Etan Cohend3652192014-06-20 08:28:44 -07004972 int fd = s_ril_param_socket.fdCommand;
Etan Cohend3652192014-06-20 08:28:44 -07004973#if (SIM_COUNT >= 2)
4974 if (socket_id == RIL_SOCKET_2) {
4975 fd = s_ril_param_socket2.fdCommand;
4976 }
4977#if (SIM_COUNT >= 3)
Sanket Padawe6ff9a872016-01-27 15:09:12 -08004978 if (socket_id == RIL_SOCKET_3) {
4979 fd = s_ril_param_socket3.fdCommand;
4980 }
Etan Cohend3652192014-06-20 08:28:44 -07004981#endif
4982#if (SIM_COUNT >= 4)
4983 if (socket_id == RIL_SOCKET_4) {
4984 fd = s_ril_param_socket4.fdCommand;
4985 }
4986#endif
4987#endif
Sanket Padawe6ff9a872016-01-27 15:09:12 -08004988 return fd;
4989}
4990
4991extern "C" void
4992RIL_onRequestAck(RIL_Token t) {
4993 RequestInfo *pRI;
4994 int ret, fd;
4995
4996 size_t errorOffset;
4997 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
4998
4999 pRI = (RequestInfo *)t;
5000
5001 if (!checkAndDequeueRequestInfoIfAck(pRI, true)) {
5002 RLOGE ("RIL_onRequestAck: invalid RIL_Token");
5003 return;
5004 }
5005
5006 socket_id = pRI->socket_id;
5007 fd = findFd(socket_id);
5008
5009#if VDBG
5010 RLOGD("Request Ack, %s", rilSocketIdToString(socket_id));
5011#endif
5012
5013 appendPrintBuf("Ack [%04d]< %s", pRI->token, requestToString(pRI->pCI->requestNumber));
5014
5015 if (pRI->cancelled == 0) {
5016 Parcel p;
5017
5018 p.writeInt32 (RESPONSE_SOLICITED_ACK);
5019 p.writeInt32 (pRI->token);
5020
5021 if (fd < 0) {
5022 RLOGD ("RIL onRequestComplete: Command channel closed");
5023 }
5024
5025 sendResponse(p, socket_id);
5026 }
5027}
5028
5029extern "C" void
5030RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) {
5031 RequestInfo *pRI;
5032 int ret;
5033 int fd;
5034 size_t errorOffset;
5035 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
5036
5037 pRI = (RequestInfo *)t;
5038
5039 if (!checkAndDequeueRequestInfoIfAck(pRI, false)) {
5040 RLOGE ("RIL_onRequestComplete: invalid RIL_Token");
5041 return;
5042 }
5043
5044 socket_id = pRI->socket_id;
5045 fd = findFd(socket_id);
5046
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07005047#if VDBG
Etan Cohend3652192014-06-20 08:28:44 -07005048 RLOGD("RequestComplete, %s", rilSocketIdToString(socket_id));
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07005049#endif
Etan Cohend3652192014-06-20 08:28:44 -07005050
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005051 if (pRI->local > 0) {
5052 // Locally issued command...void only!
5053 // response does not go back up the command socket
Wink Saville8eb2a122012-11-19 16:05:13 -08005054 RLOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005055
5056 goto done;
5057 }
5058
5059 appendPrintBuf("[%04d]< %s",
5060 pRI->token, requestToString(pRI->pCI->requestNumber));
5061
5062 if (pRI->cancelled == 0) {
5063 Parcel p;
5064
Sanket Padawe6ff9a872016-01-27 15:09:12 -08005065 if (s_callbacks.version >= 13 && pRI->wasAckSent == 1) {
5066 // If ack was already sent, then this call is an asynchronous response. So we need to
5067 // send id indicating that we expect an ack from RIL.java as we acquire wakelock here.
5068 p.writeInt32 (RESPONSE_SOLICITED_ACK_EXP);
5069 grabPartialWakeLock();
5070 } else {
5071 p.writeInt32 (RESPONSE_SOLICITED);
5072 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005073 p.writeInt32 (pRI->token);
5074 errorOffset = p.dataPosition();
5075
5076 p.writeInt32 (e);
5077
johnwangb2a61842009-06-02 14:55:45 -07005078 if (response != NULL) {
5079 // there is a response payload, no matter success or not.
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005080 ret = pRI->pCI->responseFunction(p, response, responselen);
5081
5082 /* if an error occurred, rewind and mark it */
5083 if (ret != 0) {
Etan Cohend3652192014-06-20 08:28:44 -07005084 RLOGE ("responseFunction error, ret %d", ret);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005085 p.setDataPosition(errorOffset);
5086 p.writeInt32 (ret);
5087 }
johnwangb2a61842009-06-02 14:55:45 -07005088 }
5089
5090 if (e != RIL_E_SUCCESS) {
5091 appendPrintBuf("%s fails by %s", printBuf, failCauseToString(e));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005092 }
5093
Etan Cohend3652192014-06-20 08:28:44 -07005094 if (fd < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08005095 RLOGD ("RIL onRequestComplete: Command channel closed");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005096 }
Etan Cohend3652192014-06-20 08:28:44 -07005097 sendResponse(p, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005098 }
5099
5100done:
5101 free(pRI);
5102}
5103
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005104static void
Wink Savillef4c4d362009-04-02 01:37:03 -07005105grabPartialWakeLock() {
Sanket Padawe6ff9a872016-01-27 15:09:12 -08005106 if (s_callbacks.version >= 13) {
5107 int ret;
5108 ret = pthread_mutex_lock(&s_wakeLockCountMutex);
5109 assert(ret == 0);
5110 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
Sanket Padawe55227b52016-02-29 10:09:26 -08005111
5112 UserCallbackInfo *p_info =
5113 internalRequestTimedCallback(wakeTimeoutCallback, NULL, &TIMEVAL_WAKE_TIMEOUT);
5114 if (p_info == NULL) {
5115 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
5116 } else {
5117 s_wakelock_count++;
5118 if (s_last_wake_timeout_info != NULL) {
5119 s_last_wake_timeout_info->userParam = (void *)1;
5120 }
5121 s_last_wake_timeout_info = p_info;
Sanket Padawe6ff9a872016-01-27 15:09:12 -08005122 }
Sanket Padawe6ff9a872016-01-27 15:09:12 -08005123 ret = pthread_mutex_unlock(&s_wakeLockCountMutex);
5124 assert(ret == 0);
5125 } else {
5126 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
5127 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005128}
5129
5130static void
Wink Savillef4c4d362009-04-02 01:37:03 -07005131releaseWakeLock() {
Sanket Padawe6ff9a872016-01-27 15:09:12 -08005132 if (s_callbacks.version >= 13) {
5133 int ret;
5134 ret = pthread_mutex_lock(&s_wakeLockCountMutex);
5135 assert(ret == 0);
5136
5137 if (s_wakelock_count > 1) {
5138 s_wakelock_count--;
5139 } else {
5140 s_wakelock_count = 0;
5141 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
5142 if (s_last_wake_timeout_info != NULL) {
5143 s_last_wake_timeout_info->userParam = (void *)1;
5144 }
5145 }
5146
5147 ret = pthread_mutex_unlock(&s_wakeLockCountMutex);
5148 assert(ret == 0);
5149 } else {
5150 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
5151 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005152}
5153
5154/**
5155 * Timer callback to put us back to sleep before the default timeout
5156 */
5157static void
Wink Savillef4c4d362009-04-02 01:37:03 -07005158wakeTimeoutCallback (void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005159 // We're using "param != NULL" as a cancellation mechanism
Sanket Padawe6ff9a872016-01-27 15:09:12 -08005160 if (s_callbacks.version >= 13) {
5161 if (param == NULL) {
5162 int ret;
5163 ret = pthread_mutex_lock(&s_wakeLockCountMutex);
5164 assert(ret == 0);
5165 s_wakelock_count = 0;
5166 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
5167 ret = pthread_mutex_unlock(&s_wakeLockCountMutex);
5168 assert(ret == 0);
5169 }
5170 } else {
5171 if (param == NULL) {
5172 releaseWakeLock();
5173 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005174 }
5175}
5176
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005177static int
5178decodeVoiceRadioTechnology (RIL_RadioState radioState) {
5179 switch (radioState) {
5180 case RADIO_STATE_SIM_NOT_READY:
5181 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
5182 case RADIO_STATE_SIM_READY:
5183 return RADIO_TECH_UMTS;
5184
5185 case RADIO_STATE_RUIM_NOT_READY:
5186 case RADIO_STATE_RUIM_READY:
5187 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
5188 case RADIO_STATE_NV_NOT_READY:
5189 case RADIO_STATE_NV_READY:
5190 return RADIO_TECH_1xRTT;
5191
5192 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08005193 RLOGD("decodeVoiceRadioTechnology: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005194 return -1;
5195 }
5196}
5197
5198static int
5199decodeCdmaSubscriptionSource (RIL_RadioState radioState) {
5200 switch (radioState) {
5201 case RADIO_STATE_SIM_NOT_READY:
5202 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
5203 case RADIO_STATE_SIM_READY:
5204 case RADIO_STATE_RUIM_NOT_READY:
5205 case RADIO_STATE_RUIM_READY:
5206 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
5207 return CDMA_SUBSCRIPTION_SOURCE_RUIM_SIM;
5208
5209 case RADIO_STATE_NV_NOT_READY:
5210 case RADIO_STATE_NV_READY:
5211 return CDMA_SUBSCRIPTION_SOURCE_NV;
5212
5213 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08005214 RLOGD("decodeCdmaSubscriptionSource: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005215 return -1;
5216 }
5217}
5218
5219static int
5220decodeSimStatus (RIL_RadioState radioState) {
5221 switch (radioState) {
5222 case RADIO_STATE_SIM_NOT_READY:
5223 case RADIO_STATE_RUIM_NOT_READY:
5224 case RADIO_STATE_NV_NOT_READY:
5225 case RADIO_STATE_NV_READY:
5226 return -1;
5227 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
5228 case RADIO_STATE_SIM_READY:
5229 case RADIO_STATE_RUIM_READY:
5230 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
5231 return radioState;
5232 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08005233 RLOGD("decodeSimStatus: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005234 return -1;
5235 }
5236}
5237
5238static bool is3gpp2(int radioTech) {
5239 switch (radioTech) {
5240 case RADIO_TECH_IS95A:
5241 case RADIO_TECH_IS95B:
5242 case RADIO_TECH_1xRTT:
5243 case RADIO_TECH_EVDO_0:
5244 case RADIO_TECH_EVDO_A:
5245 case RADIO_TECH_EVDO_B:
5246 case RADIO_TECH_EHRPD:
5247 return true;
5248 default:
5249 return false;
5250 }
5251}
5252
5253/* If RIL sends SIM states or RUIM states, store the voice radio
5254 * technology and subscription source information so that they can be
5255 * returned when telephony framework requests them
5256 */
5257static RIL_RadioState
Etan Cohend3652192014-06-20 08:28:44 -07005258processRadioState(RIL_RadioState newRadioState, RIL_SOCKET_ID socket_id) {
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005259
5260 if((newRadioState > RADIO_STATE_UNAVAILABLE) && (newRadioState < RADIO_STATE_ON)) {
5261 int newVoiceRadioTech;
5262 int newCdmaSubscriptionSource;
5263 int newSimStatus;
5264
5265 /* This is old RIL. Decode Subscription source and Voice Radio Technology
5266 from Radio State and send change notifications if there has been a change */
5267 newVoiceRadioTech = decodeVoiceRadioTechnology(newRadioState);
5268 if(newVoiceRadioTech != voiceRadioTech) {
5269 voiceRadioTech = newVoiceRadioTech;
Etan Cohend3652192014-06-20 08:28:44 -07005270 RIL_UNSOL_RESPONSE(RIL_UNSOL_VOICE_RADIO_TECH_CHANGED,
5271 &voiceRadioTech, sizeof(voiceRadioTech), socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005272 }
5273 if(is3gpp2(newVoiceRadioTech)) {
5274 newCdmaSubscriptionSource = decodeCdmaSubscriptionSource(newRadioState);
5275 if(newCdmaSubscriptionSource != cdmaSubscriptionSource) {
5276 cdmaSubscriptionSource = newCdmaSubscriptionSource;
Etan Cohend3652192014-06-20 08:28:44 -07005277 RIL_UNSOL_RESPONSE(RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED,
5278 &cdmaSubscriptionSource, sizeof(cdmaSubscriptionSource), socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005279 }
5280 }
5281 newSimStatus = decodeSimStatus(newRadioState);
5282 if(newSimStatus != simRuimStatus) {
5283 simRuimStatus = newSimStatus;
Etan Cohend3652192014-06-20 08:28:44 -07005284 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0, socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005285 }
5286
5287 /* Send RADIO_ON to telephony */
5288 newRadioState = RADIO_STATE_ON;
5289 }
5290
5291 return newRadioState;
5292}
5293
Etan Cohend3652192014-06-20 08:28:44 -07005294
5295#if defined(ANDROID_MULTI_SIM)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005296extern "C"
Bernhard Rosenkränzerd613b962014-11-17 20:52:09 +01005297void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Etan Cohend3652192014-06-20 08:28:44 -07005298 size_t datalen, RIL_SOCKET_ID socket_id)
5299#else
5300extern "C"
Bernhard Rosenkränzerd613b962014-11-17 20:52:09 +01005301void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005302 size_t datalen)
Etan Cohend3652192014-06-20 08:28:44 -07005303#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005304{
5305 int unsolResponseIndex;
5306 int ret;
5307 int64_t timeReceived = 0;
5308 bool shouldScheduleTimeout = false;
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005309 RIL_RadioState newState;
Etan Cohend3652192014-06-20 08:28:44 -07005310 RIL_SOCKET_ID soc_id = RIL_SOCKET_1;
5311
5312#if defined(ANDROID_MULTI_SIM)
5313 soc_id = socket_id;
5314#endif
5315
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005316
5317 if (s_registerCalled == 0) {
5318 // Ignore RIL_onUnsolicitedResponse before RIL_register
Wink Saville8eb2a122012-11-19 16:05:13 -08005319 RLOGW("RIL_onUnsolicitedResponse called before RIL_register");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005320 return;
5321 }
Wink Saville7f856802009-06-09 10:23:37 -07005322
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005323 unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
5324
5325 if ((unsolResponseIndex < 0)
5326 || (unsolResponseIndex >= (int32_t)NUM_ELEMS(s_unsolResponses))) {
Wink Saville8eb2a122012-11-19 16:05:13 -08005327 RLOGE("unsupported unsolicited response code %d", unsolResponse);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005328 return;
5329 }
5330
5331 // Grab a wake lock if needed for this reponse,
5332 // as we exit we'll either release it immediately
5333 // or set a timer to release it later.
5334 switch (s_unsolResponses[unsolResponseIndex].wakeType) {
5335 case WAKE_PARTIAL:
5336 grabPartialWakeLock();
5337 shouldScheduleTimeout = true;
5338 break;
5339
5340 case DONT_WAKE:
5341 default:
5342 // No wake lock is grabed so don't set timeout
5343 shouldScheduleTimeout = false;
5344 break;
5345 }
5346
5347 // Mark the time this was received, doing this
5348 // after grabing the wakelock incase getting
5349 // the elapsedRealTime might cause us to goto
5350 // sleep.
5351 if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
5352 timeReceived = elapsedRealtime();
5353 }
5354
5355 appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
5356
5357 Parcel p;
Sanket Padawed8c0b462016-02-03 11:46:02 -08005358 if (s_callbacks.version >= 13
5359 && s_unsolResponses[unsolResponseIndex].wakeType == WAKE_PARTIAL) {
5360 p.writeInt32 (RESPONSE_UNSOLICITED_ACK_EXP);
5361 } else {
5362 p.writeInt32 (RESPONSE_UNSOLICITED);
5363 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005364 p.writeInt32 (unsolResponse);
5365
5366 ret = s_unsolResponses[unsolResponseIndex]
Bernhard Rosenkränzer6e7c1962013-12-12 10:01:10 +01005367 .responseFunction(p, const_cast<void*>(data), datalen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005368 if (ret != 0) {
5369 // Problem with the response. Don't continue;
5370 goto error_exit;
5371 }
5372
5373 // some things get more payload
5374 switch(unsolResponse) {
5375 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
Etan Cohend3652192014-06-20 08:28:44 -07005376 newState = processRadioState(CALL_ONSTATEREQUEST(soc_id), soc_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005377 p.writeInt32(newState);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005378 appendPrintBuf("%s {%s}", printBuf,
Etan Cohend3652192014-06-20 08:28:44 -07005379 radioStateToString(CALL_ONSTATEREQUEST(soc_id)));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005380 break;
5381
5382
5383 case RIL_UNSOL_NITZ_TIME_RECEIVED:
5384 // Store the time that this was received so the
5385 // handler of this message can account for
5386 // the time it takes to arrive and process. In
5387 // particular the system has been known to sleep
5388 // before this message can be processed.
5389 p.writeInt64(timeReceived);
5390 break;
5391 }
5392
Sanket Padawe55227b52016-02-29 10:09:26 -08005393 if (s_callbacks.version < 13) {
5394 if (shouldScheduleTimeout) {
5395 UserCallbackInfo *p_info = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
5396 &TIMEVAL_WAKE_TIMEOUT);
5397
5398 if (p_info == NULL) {
5399 goto error_exit;
5400 } else {
5401 // Cancel the previous request
5402 if (s_last_wake_timeout_info != NULL) {
5403 s_last_wake_timeout_info->userParam = (void *)1;
5404 }
5405 s_last_wake_timeout_info = p_info;
5406 }
5407 }
5408 }
5409
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07005410#if VDBG
Etan Cohend3652192014-06-20 08:28:44 -07005411 RLOGI("%s UNSOLICITED: %s length:%d", rilSocketIdToString(soc_id), requestToString(unsolResponse), p.dataSize());
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07005412#endif
Etan Cohend3652192014-06-20 08:28:44 -07005413 ret = sendResponse(p, soc_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005414 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
5415
5416 // Unfortunately, NITZ time is not poll/update like everything
5417 // else in the system. So, if the upstream client isn't connected,
5418 // keep a copy of the last NITZ response (with receive time noted
5419 // above) around so we can deliver it when it is connected
5420
5421 if (s_lastNITZTimeData != NULL) {
5422 free (s_lastNITZTimeData);
5423 s_lastNITZTimeData = NULL;
5424 }
5425
5426 s_lastNITZTimeData = malloc(p.dataSize());
Sanket Padawe55227b52016-02-29 10:09:26 -08005427 if (s_lastNITZTimeData == NULL) {
5428 RLOGE("Memory allocation failed in RIL_onUnsolicitedResponse");
5429 goto error_exit;
5430 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005431 s_lastNITZTimeDataSize = p.dataSize();
5432 memcpy(s_lastNITZTimeData, p.data(), p.dataSize());
5433 }
5434
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005435 // Normal exit
5436 return;
5437
5438error_exit:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005439 if (shouldScheduleTimeout) {
5440 releaseWakeLock();
5441 }
5442}
5443
Wink Saville7f856802009-06-09 10:23:37 -07005444/** FIXME generalize this if you track UserCAllbackInfo, clear it
5445 when the callback occurs
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005446*/
5447static UserCallbackInfo *
Wink Saville7f856802009-06-09 10:23:37 -07005448internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07005449 const struct timeval *relativeTime)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005450{
5451 struct timeval myRelativeTime;
5452 UserCallbackInfo *p_info;
5453
5454 p_info = (UserCallbackInfo *) malloc (sizeof(UserCallbackInfo));
Sanket Padawe55227b52016-02-29 10:09:26 -08005455 if (p_info == NULL) {
5456 RLOGE("Memory allocation failed in internalRequestTimedCallback");
5457 return p_info;
5458
5459 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005460
Wink Saville7f856802009-06-09 10:23:37 -07005461 p_info->p_callback = callback;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005462 p_info->userParam = param;
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07005463
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005464 if (relativeTime == NULL) {
5465 /* treat null parameter as a 0 relative time */
5466 memset (&myRelativeTime, 0, sizeof(myRelativeTime));
5467 } else {
5468 /* FIXME I think event_add's tv param is really const anyway */
5469 memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
5470 }
5471
5472 ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
5473
5474 ril_timer_add(&(p_info->event), &myRelativeTime);
5475
5476 triggerEvLoop();
5477 return p_info;
5478}
5479
Naveen Kalla7edd07c2010-06-21 18:54:47 -07005480
5481extern "C" void
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07005482RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
5483 const struct timeval *relativeTime) {
5484 internalRequestTimedCallback (callback, param, relativeTime);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005485}
5486
5487const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07005488failCauseToString(RIL_Errno e) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005489 switch(e) {
5490 case RIL_E_SUCCESS: return "E_SUCCESS";
Robert Greenwalt2126ab22013-04-09 12:20:45 -07005491 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RADIO_NOT_AVAILABLE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005492 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
5493 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
5494 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
5495 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
5496 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
5497 case RIL_E_CANCELLED: return "E_CANCELLED";
5498 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
5499 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
5500 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
Wink Savillef4c4d362009-04-02 01:37:03 -07005501 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
John Wang75534472010-04-20 15:11:42 -07005502 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
Wink Saville7f856802009-06-09 10:23:37 -07005503#ifdef FEATURE_MULTIMODE_ANDROID
Wink Savillef4c4d362009-04-02 01:37:03 -07005504 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
5505 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
5506#endif
Sanket Padaweb39e5c92016-02-08 14:28:59 -08005507 case RIL_E_FDN_CHECK_FAILURE: return "E_FDN_CHECK_FAILURE";
5508 case RIL_E_MISSING_RESOURCE: return "E_MISSING_RESOURCE";
5509 case RIL_E_NO_SUCH_ELEMENT: return "E_NO_SUCH_ELEMENT";
5510 case RIL_E_DIAL_MODIFIED_TO_USSD: return "E_DIAL_MODIFIED_TO_USSD";
5511 case RIL_E_DIAL_MODIFIED_TO_SS: return "E_DIAL_MODIFIED_TO_SS";
5512 case RIL_E_DIAL_MODIFIED_TO_DIAL: return "E_DIAL_MODIFIED_TO_DIAL";
5513 case RIL_E_USSD_MODIFIED_TO_DIAL: return "E_USSD_MODIFIED_TO_DIAL";
5514 case RIL_E_USSD_MODIFIED_TO_SS: return "E_USSD_MODIFIED_TO_SS";
5515 case RIL_E_USSD_MODIFIED_TO_USSD: return "E_USSD_MODIFIED_TO_USSD";
5516 case RIL_E_SS_MODIFIED_TO_DIAL: return "E_SS_MODIFIED_TO_DIAL";
5517 case RIL_E_SS_MODIFIED_TO_USSD: return "E_SS_MODIFIED_TO_USSD";
5518 case RIL_E_SUBSCRIPTION_NOT_SUPPORTED: return "E_SUBSCRIPTION_NOT_SUPPORTED";
5519 case RIL_E_SS_MODIFIED_TO_SS: return "E_SS_MODIFIED_TO_SS";
5520 case RIL_E_LCE_NOT_SUPPORTED: return "E_LCE_NOT_SUPPORTED";
5521 case RIL_E_NO_MEMORY: return "E_NO_MEMORY";
5522 case RIL_E_INTERNAL_ERR: return "E_INTERNAL_ERR";
5523 case RIL_E_SYSTEM_ERR: return "E_SYSTEM_ERR";
5524 case RIL_E_MODEM_ERR: return "E_MODEM_ERR";
5525 case RIL_E_INVALID_STATE: return "E_INVALID_STATE";
5526 case RIL_E_NO_RESOURCES: return "E_NO_RESOURCES";
5527 case RIL_E_SIM_ERR: return "E_SIM_ERR";
5528 case RIL_E_INVALID_ARGUMENTS: return "E_INVALID_ARGUMENTS";
5529 case RIL_E_INVALID_SIM_STATE: return "E_INVALID_SIM_STATE";
5530 case RIL_E_INVALID_MODEM_STATE: return "E_INVALID_MODEM_STATE";
5531 case RIL_E_INVALID_CALL_ID: return "E_INVALID_CALL_ID";
5532 case RIL_E_NO_SMS_TO_ACK: return "E_NO_SMS_TO_ACK";
5533 case RIL_E_NETWORK_ERR: return "E_NETWORK_ERR";
5534 case RIL_E_REQUEST_RATE_LIMITED: return "E_REQUEST_RATE_LIMITED";
Sanket Padawe0106aed2016-02-09 09:56:31 -08005535 case RIL_E_OEM_ERROR_1: return "E_OEM_ERROR_1";
5536 case RIL_E_OEM_ERROR_2: return "E_OEM_ERROR_2";
5537 case RIL_E_OEM_ERROR_3: return "E_OEM_ERROR_3";
5538 case RIL_E_OEM_ERROR_4: return "E_OEM_ERROR_4";
5539 case RIL_E_OEM_ERROR_5: return "E_OEM_ERROR_5";
5540 case RIL_E_OEM_ERROR_6: return "E_OEM_ERROR_6";
5541 case RIL_E_OEM_ERROR_7: return "E_OEM_ERROR_7";
5542 case RIL_E_OEM_ERROR_8: return "E_OEM_ERROR_8";
5543 case RIL_E_OEM_ERROR_9: return "E_OEM_ERROR_9";
5544 case RIL_E_OEM_ERROR_10: return "E_OEM_ERROR_10";
5545 case RIL_E_OEM_ERROR_11: return "E_OEM_ERROR_11";
5546 case RIL_E_OEM_ERROR_12: return "E_OEM_ERROR_12";
5547 case RIL_E_OEM_ERROR_13: return "E_OEM_ERROR_13";
5548 case RIL_E_OEM_ERROR_14: return "E_OEM_ERROR_14";
5549 case RIL_E_OEM_ERROR_15: return "E_OEM_ERROR_15";
5550 case RIL_E_OEM_ERROR_16: return "E_OEM_ERROR_16";
5551 case RIL_E_OEM_ERROR_17: return "E_OEM_ERROR_17";
5552 case RIL_E_OEM_ERROR_18: return "E_OEM_ERROR_18";
5553 case RIL_E_OEM_ERROR_19: return "E_OEM_ERROR_19";
5554 case RIL_E_OEM_ERROR_20: return "E_OEM_ERROR_20";
5555 case RIL_E_OEM_ERROR_21: return "E_OEM_ERROR_21";
5556 case RIL_E_OEM_ERROR_22: return "E_OEM_ERROR_22";
5557 case RIL_E_OEM_ERROR_23: return "E_OEM_ERROR_23";
5558 case RIL_E_OEM_ERROR_24: return "E_OEM_ERROR_24";
5559 case RIL_E_OEM_ERROR_25: return "E_OEM_ERROR_25";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005560 default: return "<unknown error>";
5561 }
5562}
5563
5564const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07005565radioStateToString(RIL_RadioState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005566 switch(s) {
5567 case RADIO_STATE_OFF: return "RADIO_OFF";
5568 case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
5569 case RADIO_STATE_SIM_NOT_READY: return "RADIO_SIM_NOT_READY";
5570 case RADIO_STATE_SIM_LOCKED_OR_ABSENT: return "RADIO_SIM_LOCKED_OR_ABSENT";
5571 case RADIO_STATE_SIM_READY: return "RADIO_SIM_READY";
Wink Savillef4c4d362009-04-02 01:37:03 -07005572 case RADIO_STATE_RUIM_NOT_READY:return"RADIO_RUIM_NOT_READY";
5573 case RADIO_STATE_RUIM_READY:return"RADIO_RUIM_READY";
5574 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:return"RADIO_RUIM_LOCKED_OR_ABSENT";
5575 case RADIO_STATE_NV_NOT_READY:return"RADIO_NV_NOT_READY";
5576 case RADIO_STATE_NV_READY:return"RADIO_NV_READY";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005577 case RADIO_STATE_ON:return"RADIO_ON";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005578 default: return "<unknown state>";
5579 }
5580}
5581
5582const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07005583callStateToString(RIL_CallState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005584 switch(s) {
5585 case RIL_CALL_ACTIVE : return "ACTIVE";
5586 case RIL_CALL_HOLDING: return "HOLDING";
5587 case RIL_CALL_DIALING: return "DIALING";
5588 case RIL_CALL_ALERTING: return "ALERTING";
5589 case RIL_CALL_INCOMING: return "INCOMING";
5590 case RIL_CALL_WAITING: return "WAITING";
5591 default: return "<unknown state>";
5592 }
5593}
5594
5595const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07005596requestToString(int request) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005597/*
5598 cat libs/telephony/ril_commands.h \
5599 | egrep "^ *{RIL_" \
5600 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
5601
5602
5603 cat libs/telephony/ril_unsol_commands.h \
5604 | egrep "^ *{RIL_" \
5605 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
5606
5607*/
5608 switch(request) {
5609 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
5610 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
5611 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
5612 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
5613 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
5614 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
5615 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
5616 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
5617 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
5618 case RIL_REQUEST_DIAL: return "DIAL";
5619 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
5620 case RIL_REQUEST_HANGUP: return "HANGUP";
5621 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
5622 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
5623 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
5624 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
5625 case RIL_REQUEST_UDUB: return "UDUB";
5626 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
5627 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
Wink Savillec0114b32011-02-18 10:14:07 -08005628 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
5629 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005630 case RIL_REQUEST_OPERATOR: return "OPERATOR";
5631 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
5632 case RIL_REQUEST_DTMF: return "DTMF";
5633 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
5634 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
Wink Savillef4c4d362009-04-02 01:37:03 -07005635 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005636 case RIL_REQUEST_SIM_IO: return "SIM_IO";
5637 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
5638 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
5639 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
5640 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
5641 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
5642 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
5643 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
5644 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
5645 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
5646 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
5647 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
5648 case RIL_REQUEST_ANSWER: return "ANSWER";
Wink Savillef4c4d362009-04-02 01:37:03 -07005649 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005650 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
5651 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
5652 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
5653 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
5654 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
5655 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
5656 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";
5657 case RIL_REQUEST_DTMF_START: return "DTMF_START";
5658 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
5659 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
5660 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
5661 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
5662 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
5663 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
5664 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
5665 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
5666 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
Wink Savillef4c4d362009-04-02 01:37:03 -07005667 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
5668 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005669 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
5670 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
5671 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
Wink Savillef4c4d362009-04-02 01:37:03 -07005672 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
5673 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005674 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
5675 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
5676 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
5677 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
5678 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
5679 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
5680 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
5681 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
Wink Savillec0114b32011-02-18 10:14:07 -08005682 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE:return"CDMA_SET_SUBSCRIPTION_SOURCE";
Wink Savillef4c4d362009-04-02 01:37:03 -07005683 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"CDMA_SET_ROAMING_PREFERENCE";
5684 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"CDMA_QUERY_ROAMING_PREFERENCE";
5685 case RIL_REQUEST_SET_TTY_MODE:return"SET_TTY_MODE";
5686 case RIL_REQUEST_QUERY_TTY_MODE:return"QUERY_TTY_MODE";
5687 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
5688 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
5689 case RIL_REQUEST_CDMA_FLASH:return"CDMA_FLASH";
5690 case RIL_REQUEST_CDMA_BURST_DTMF:return"CDMA_BURST_DTMF";
5691 case RIL_REQUEST_CDMA_SEND_SMS:return"CDMA_SEND_SMS";
5692 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:return"CDMA_SMS_ACKNOWLEDGE";
Wink Savillea592eeb2009-05-22 13:26:36 -07005693 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG:return"GSM_GET_BROADCAST_SMS_CONFIG";
5694 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG:return"GSM_SET_BROADCAST_SMS_CONFIG";
5695 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG:return "CDMA_GET_BROADCAST_SMS_CONFIG";
5696 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG:return "CDMA_SET_BROADCAST_SMS_CONFIG";
5697 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION:return "CDMA_SMS_BROADCAST_ACTIVATION";
Naveen Kalla03c1edf2009-09-23 11:18:35 -07005698 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return"CDMA_VALIDATE_AND_WRITE_AKEY";
Wink Savillef4c4d362009-04-02 01:37:03 -07005699 case RIL_REQUEST_CDMA_SUBSCRIPTION: return"CDMA_SUBSCRIPTION";
5700 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
5701 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
5702 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
jsh000a9fe2009-05-11 14:52:35 -07005703 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
5704 case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
5705 case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
jsh09a68ba2009-06-10 11:56:38 -07005706 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
jsh563fd722010-06-08 16:52:24 -07005707 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
Wink Savillec0114b32011-02-18 10:14:07 -08005708 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
Jake Hambyfa8d5842011-08-19 16:22:18 -07005709 case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
Jake Hamby300105d2011-09-26 01:01:44 -07005710 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
5711 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005712 case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
Ajay Nambic27945d2011-11-15 11:19:30 -08005713 case RIL_REQUEST_WRITE_SMS_TO_SIM: return "WRITE_SMS_TO_SIM";
Wink Saville8a9e0212013-04-09 12:11:38 -07005714 case RIL_REQUEST_GET_CELL_INFO_LIST: return"GET_CELL_INFO_LIST";
5715 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return"SET_UNSOL_CELL_INFO_LIST_RATE";
Sungmin Choi75697532013-04-26 15:04:45 -07005716 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "RIL_REQUEST_SET_INITIAL_ATTACH_APN";
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07005717 case RIL_REQUEST_IMS_REGISTRATION_STATE: return "IMS_REGISTRATION_STATE";
5718 case RIL_REQUEST_IMS_SEND_SMS: return "IMS_SEND_SMS";
Shishir Agrawal2458d8d2013-11-27 14:53:05 -08005719 case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "SIM_TRANSMIT_APDU_BASIC";
5720 case RIL_REQUEST_SIM_OPEN_CHANNEL: return "SIM_OPEN_CHANNEL";
5721 case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "SIM_CLOSE_CHANNEL";
5722 case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "SIM_TRANSMIT_APDU_CHANNEL";
Wink Saville8b4e4f72014-10-17 15:01:45 -07005723 case RIL_REQUEST_GET_RADIO_CAPABILITY: return "RIL_REQUEST_GET_RADIO_CAPABILITY";
5724 case RIL_REQUEST_SET_RADIO_CAPABILITY: return "RIL_REQUEST_SET_RADIO_CAPABILITY";
Etan Cohend3652192014-06-20 08:28:44 -07005725 case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "SET_UICC_SUBSCRIPTION";
5726 case RIL_REQUEST_ALLOW_DATA: return "ALLOW_DATA";
Amit Mahajan2b772032014-06-26 14:20:11 -07005727 case RIL_REQUEST_GET_HARDWARE_CONFIG: return "GET_HARDWARE_CONFIG";
5728 case RIL_REQUEST_SIM_AUTHENTICATION: return "SIM_AUTHENTICATION";
Wink Savillec29360a2014-07-13 05:17:28 -07005729 case RIL_REQUEST_GET_DC_RT_INFO: return "GET_DC_RT_INFO";
5730 case RIL_REQUEST_SET_DC_RT_INFO_RATE: return "SET_DC_RT_INFO_RATE";
Amit Mahajanc796e222014-08-13 16:54:01 +00005731 case RIL_REQUEST_SET_DATA_PROFILE: return "SET_DATA_PROFILE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005732 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
5733 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08005734 case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005735 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
5736 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
5737 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
5738 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
5739 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)";
5740 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
5741 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
Ajay Nambic27945d2011-11-15 11:19:30 -08005742 case RIL_UNSOL_SUPP_SVC_NOTIFICATION: return "UNSOL_SUPP_SVC_NOTIFICATION";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005743 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
5744 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
5745 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
5746 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
5747 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL";
5748 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
Wink Savillef4c4d362009-04-02 01:37:03 -07005749 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005750 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
Wink Savillef4c4d362009-04-02 01:37:03 -07005751 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
5752 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_NEW_CDMA_SMS";
5753 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_NEW_BROADCAST_SMS";
5754 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
Wink Saville3d54e742009-05-18 18:00:44 -07005755 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
5756 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
5757 case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
5758 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
5759 case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
Jaikumar Ganeshaf6ecbf2009-04-29 13:27:51 -07005760 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
John Wang5d621da2009-09-18 17:17:48 -07005761 case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
John Wang5909cf82010-01-29 00:18:54 -08005762 case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
Wink Savilleee274582011-04-16 15:05:49 -07005763 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08005764 case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
5765 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
Wink Saville5b9df332011-04-06 16:24:21 -07005766 case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005767 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
Wink Saville8a9e0212013-04-09 12:11:38 -07005768 case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07005769 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "RESPONSE_IMS_NETWORK_STATE_CHANGED";
Etan Cohend3652192014-06-20 08:28:44 -07005770 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return "UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED";
5771 case RIL_UNSOL_SRVCC_STATE_NOTIFY: return "UNSOL_SRVCC_STATE_NOTIFY";
5772 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return "HARDWARE_CONFIG_CHANGED";
Wink Savillec29360a2014-07-13 05:17:28 -07005773 case RIL_UNSOL_DC_RT_INFO_CHANGED: return "UNSOL_DC_RT_INFO_CHANGED";
Naveen Kallaa65a16a2014-07-31 16:48:31 -07005774 case RIL_REQUEST_SHUTDOWN: return "SHUTDOWN";
Wink Saville8b4e4f72014-10-17 15:01:45 -07005775 case RIL_UNSOL_RADIO_CAPABILITY: return "RIL_UNSOL_RADIO_CAPABILITY";
Sanket Padawe6ff9a872016-01-27 15:09:12 -08005776 case RIL_RESPONSE_ACKNOWLEDGEMENT: return "RIL_RESPONSE_ACKNOWLEDGEMENT";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005777 default: return "<unknown request>";
5778 }
5779}
5780
Etan Cohend3652192014-06-20 08:28:44 -07005781const char *
5782rilSocketIdToString(RIL_SOCKET_ID socket_id)
5783{
5784 switch(socket_id) {
5785 case RIL_SOCKET_1:
5786 return "RIL_SOCKET_1";
5787#if (SIM_COUNT >= 2)
5788 case RIL_SOCKET_2:
5789 return "RIL_SOCKET_2";
5790#endif
5791#if (SIM_COUNT >= 3)
5792 case RIL_SOCKET_3:
5793 return "RIL_SOCKET_3";
5794#endif
5795#if (SIM_COUNT >= 4)
5796 case RIL_SOCKET_4:
5797 return "RIL_SOCKET_4";
5798#endif
5799 default:
5800 return "not a valid RIL";
5801 }
5802}
5803
Sanket Padawe88cf6a52016-01-11 12:45:43 -08005804/*
5805 * Returns true for a debuggable build.
5806 */
5807static bool isDebuggable() {
5808 char debuggable[PROP_VALUE_MAX];
5809 property_get("ro.debuggable", debuggable, "0");
5810 if (strcmp(debuggable, "1") == 0) {
5811 return true;
5812 }
5813 return false;
5814}
5815
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005816} /* namespace android */
Dheeraj Shetty27976c42014-07-02 21:27:57 +02005817
5818void rilEventAddWakeup_helper(struct ril_event *ev) {
5819 android::rilEventAddWakeup(ev);
5820}
5821
5822void listenCallback_helper(int fd, short flags, void *param) {
5823 android::listenCallback(fd, flags, param);
5824}
5825
5826int blockingWrite_helper(int fd, void *buffer, size_t len) {
5827 return android::blockingWrite(fd, buffer, len);
5828}