blob: 6a7e6942f03751c03e427f7d8947ec90cd91356f [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>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080029#include <cutils/jstring.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080030#include <sys/types.h>
Wink Saville18e4ab12013-04-07 17:31:04 -070031#include <sys/limits.h>
Sanket Padawe4c05f352016-01-26 16:19:00 -080032#include <sys/system_properties.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080033#include <pwd.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080034#include <stdio.h>
35#include <stdlib.h>
36#include <stdarg.h>
37#include <string.h>
38#include <unistd.h>
39#include <fcntl.h>
40#include <time.h>
41#include <errno.h>
42#include <assert.h>
43#include <ctype.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080044#include <sys/un.h>
45#include <assert.h>
46#include <netinet/in.h>
47#include <cutils/properties.h>
Dheeraj Shetty27976c42014-07-02 21:27:57 +020048#include <RilSapSocket.h>
Amit Mahajan18fe36b2016-08-25 11:19:21 -070049#include <ril_service.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080050
Dheeraj Shetty27976c42014-07-02 21:27:57 +020051extern "C" void
52RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen);
Sanket Padawe6ff9a872016-01-27 15:09:12 -080053
54extern "C" void
55RIL_onRequestAck(RIL_Token t);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080056namespace android {
57
58#define PHONE_PROCESS "radio"
Dheeraj Shetty27976c42014-07-02 21:27:57 +020059#define BLUETOOTH_PROCESS "bluetooth"
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080060
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080061#define SOCKET_NAME_RIL_DEBUG "rild-debug"
62
63#define ANDROID_WAKE_LOCK_NAME "radio-interface"
64
Nathan Harolda0153392015-07-28 14:54:58 -070065#define ANDROID_WAKE_LOCK_SECS 0
66#define ANDROID_WAKE_LOCK_USECS 200000
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080067
68#define PROPERTY_RIL_IMPL "gsm.version.ril-impl"
69
70// match with constant in RIL.java
71#define MAX_COMMAND_BYTES (8 * 1024)
72
73// Basically: memset buffers that the client library
74// shouldn't be using anymore in an attempt to find
75// memory usage issues sooner.
76#define MEMSET_FREED 1
77
78#define NUM_ELEMS(a) (sizeof (a) / sizeof (a)[0])
79
Wink Savillef4c4d362009-04-02 01:37:03 -070080#define MIN(a,b) ((a)<(b) ? (a) : (b))
81
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080082/* Negative values for private RIL errno's */
Chih-Hung Hsieh434554c2016-05-12 10:01:16 -070083#define RIL_ERRNO_INVALID_RESPONSE (-1)
Robert Greenwalt78e2c9c2016-05-16 12:36:42 -070084#define RIL_ERRNO_NO_MEMORY (-12)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080085
86// request, response, and unsolicited msg print macro
87#define PRINTBUF_SIZE 8096
88
Robert Greenwalt191e4dc2015-04-29 16:57:39 -070089// Enable verbose logging
90#define VDBG 0
91
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080092// Enable RILC log
93#define RILC_LOG 0
94
95#if RILC_LOG
96 #define startRequest sprintf(printBuf, "(")
97 #define closeRequest sprintf(printBuf, "%s)", printBuf)
98 #define printRequest(token, req) \
Wink Saville8eb2a122012-11-19 16:05:13 -080099 RLOGD("[%04d]> %s %s", token, requestToString(req), printBuf)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800100
101 #define startResponse sprintf(printBuf, "%s {", printBuf)
102 #define closeResponse sprintf(printBuf, "%s}", printBuf)
Wink Saville8eb2a122012-11-19 16:05:13 -0800103 #define printResponse RLOGD("%s", printBuf)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800104
105 #define clearPrintBuf printBuf[0] = 0
106 #define removeLastChar printBuf[strlen(printBuf)-1] = 0
Ajay Nambifa49a7f2015-08-05 14:53:50 +0530107 #define appendPrintBuf(x...) snprintf(printBuf, PRINTBUF_SIZE, x)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800108#else
109 #define startRequest
110 #define closeRequest
111 #define printRequest(token, req)
112 #define startResponse
113 #define closeResponse
114 #define printResponse
115 #define clearPrintBuf
116 #define removeLastChar
117 #define appendPrintBuf(x...)
118#endif
119
120enum WakeType {DONT_WAKE, WAKE_PARTIAL};
121
122typedef struct {
123 int requestNumber;
Amit Mahajan18fe36b2016-08-25 11:19:21 -0700124 int (*responseFunction) (Parcel &p, int slotId, int requestNumber, int responseType, int token,
125 RIL_Errno e, void *response, size_t responselen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800126 WakeType wakeType;
127} UnsolResponseInfo;
128
Wink Saville3d54e742009-05-18 18:00:44 -0700129typedef struct UserCallbackInfo {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800130 RIL_TimedCallback p_callback;
131 void *userParam;
132 struct ril_event event;
133 struct UserCallbackInfo *p_next;
134} UserCallbackInfo;
135
Etan Cohend3652192014-06-20 08:28:44 -0700136extern "C" const char * failCauseToString(RIL_Errno);
137extern "C" const char * callStateToString(RIL_CallState);
138extern "C" const char * radioStateToString(RIL_RadioState);
139extern "C" const char * rilSocketIdToString(RIL_SOCKET_ID socket_id);
140
141extern "C"
142char rild[MAX_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800143/*******************************************************************/
144
145RIL_RadioFunctions s_callbacks = {0, NULL, NULL, NULL, NULL, NULL};
146static int s_registerCalled = 0;
147
148static pthread_t s_tid_dispatch;
149static pthread_t s_tid_reader;
150static int s_started = 0;
151
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800152static int s_fdDebug = -1;
Etan Cohend3652192014-06-20 08:28:44 -0700153static int s_fdDebug_socket2 = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800154
155static int s_fdWakeupRead;
156static int s_fdWakeupWrite;
157
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800158int s_wakelock_count = 0;
159
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800160static struct ril_event s_commands_event;
161static struct ril_event s_wakeupfd_event;
162static struct ril_event s_listen_event;
Etan Cohend3652192014-06-20 08:28:44 -0700163static SocketListenParam s_ril_param_socket;
164
165static pthread_mutex_t s_pendingRequestsMutex = PTHREAD_MUTEX_INITIALIZER;
166static pthread_mutex_t s_writeMutex = PTHREAD_MUTEX_INITIALIZER;
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800167static pthread_mutex_t s_wakeLockCountMutex = PTHREAD_MUTEX_INITIALIZER;
Etan Cohend3652192014-06-20 08:28:44 -0700168static RequestInfo *s_pendingRequests = NULL;
169
170#if (SIM_COUNT >= 2)
171static struct ril_event s_commands_event_socket2;
172static struct ril_event s_listen_event_socket2;
173static SocketListenParam s_ril_param_socket2;
174
175static pthread_mutex_t s_pendingRequestsMutex_socket2 = PTHREAD_MUTEX_INITIALIZER;
176static pthread_mutex_t s_writeMutex_socket2 = PTHREAD_MUTEX_INITIALIZER;
177static RequestInfo *s_pendingRequests_socket2 = NULL;
178#endif
179
180#if (SIM_COUNT >= 3)
181static struct ril_event s_commands_event_socket3;
182static struct ril_event s_listen_event_socket3;
183static SocketListenParam s_ril_param_socket3;
184
185static pthread_mutex_t s_pendingRequestsMutex_socket3 = PTHREAD_MUTEX_INITIALIZER;
186static pthread_mutex_t s_writeMutex_socket3 = PTHREAD_MUTEX_INITIALIZER;
187static RequestInfo *s_pendingRequests_socket3 = NULL;
188#endif
189
190#if (SIM_COUNT >= 4)
191static struct ril_event s_commands_event_socket4;
192static struct ril_event s_listen_event_socket4;
193static SocketListenParam s_ril_param_socket4;
194
195static pthread_mutex_t s_pendingRequestsMutex_socket4 = PTHREAD_MUTEX_INITIALIZER;
196static pthread_mutex_t s_writeMutex_socket4 = PTHREAD_MUTEX_INITIALIZER;
197static RequestInfo *s_pendingRequests_socket4 = NULL;
198#endif
199
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800200static struct ril_event s_wake_timeout_event;
201static struct ril_event s_debug_event;
202
203
Nathan Harolda0153392015-07-28 14:54:58 -0700204static const struct timeval TIMEVAL_WAKE_TIMEOUT = {ANDROID_WAKE_LOCK_SECS,ANDROID_WAKE_LOCK_USECS};
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800205
Etan Cohend3652192014-06-20 08:28:44 -0700206
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800207static pthread_mutex_t s_startupMutex = PTHREAD_MUTEX_INITIALIZER;
208static pthread_cond_t s_startupCond = PTHREAD_COND_INITIALIZER;
209
210static pthread_mutex_t s_dispatchMutex = PTHREAD_MUTEX_INITIALIZER;
211static pthread_cond_t s_dispatchCond = PTHREAD_COND_INITIALIZER;
212
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800213static RequestInfo *s_toDispatchHead = NULL;
214static RequestInfo *s_toDispatchTail = NULL;
215
216static UserCallbackInfo *s_last_wake_timeout_info = NULL;
217
218static void *s_lastNITZTimeData = NULL;
219static size_t s_lastNITZTimeDataSize;
220
221#if RILC_LOG
222 static char printBuf[PRINTBUF_SIZE];
223#endif
224
225/*******************************************************************/
Etan Cohend3652192014-06-20 08:28:44 -0700226static int sendResponse (Parcel &p, RIL_SOCKET_ID socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800227
228static void dispatchVoid (Parcel& p, RequestInfo *pRI);
229static void dispatchString (Parcel& p, RequestInfo *pRI);
230static void dispatchStrings (Parcel& p, RequestInfo *pRI);
231static void dispatchInts (Parcel& p, RequestInfo *pRI);
232static void dispatchDial (Parcel& p, RequestInfo *pRI);
233static void dispatchSIM_IO (Parcel& p, RequestInfo *pRI);
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800234static void dispatchSIM_APDU (Parcel& p, RequestInfo *pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800235static void dispatchCallForward(Parcel& p, RequestInfo *pRI);
236static void dispatchRaw(Parcel& p, RequestInfo *pRI);
237static void dispatchSmsWrite (Parcel &p, RequestInfo *pRI);
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -0700238static void dispatchDataCall (Parcel& p, RequestInfo *pRI);
Sungmin Choi75697532013-04-26 15:04:45 -0700239static void dispatchSetInitialAttachApn (Parcel& p, RequestInfo *pRI);
Wink Savillef4c4d362009-04-02 01:37:03 -0700240static void dispatchCdmaSms(Parcel &p, RequestInfo *pRI);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -0700241static void dispatchImsSms(Parcel &p, RequestInfo *pRI);
242static void dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
243static void dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
Wink Savillef4c4d362009-04-02 01:37:03 -0700244static void dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI);
Wink Savillea592eeb2009-05-22 13:26:36 -0700245static void dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI);
Wink Savillef4c4d362009-04-02 01:37:03 -0700246static void dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI);
247static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI);
Jake Hamby8a4a2332014-01-15 13:12:05 -0800248static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI);
249static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI);
Etan Cohend3652192014-06-20 08:28:44 -0700250static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI);
Amit Mahajan90530a62014-07-01 15:54:08 -0700251static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI);
Amit Mahajanc796e222014-08-13 16:54:01 +0000252static void dispatchDataProfile(Parcel &p, RequestInfo *pRI);
Wink Saville8b4e4f72014-10-17 15:01:45 -0700253static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI);
Meng Wangb4e34312016-05-12 14:54:36 -0700254static void dispatchCarrierRestrictions(Parcel &p, RequestInfo *pRI);
Amit Mahajan18fe36b2016-08-25 11:19:21 -0700255static int responseInts(Parcel &p, int slotId, int requestNumber, int responseType, int token,
256 RIL_Errno e, void *response, size_t responselen);
257static int responseFailCause(Parcel &p, int slotId, int requestNumber, int responseType, int token,
258 RIL_Errno e, void *response, size_t responselen);
259static int responseStrings(Parcel &p, int slotId, int requestNumber, int responseType, int token,
260 RIL_Errno e, void *response, size_t responselen);
261static int responseString(Parcel &p, int slotId, int requestNumber, int responseType, int token,
262 RIL_Errno e, void *response, size_t responselen);
263static int responseVoid(Parcel &p, int slotId, int requestNumber, int responseType, int token,
264 RIL_Errno e, void *response, size_t responselen);
265static int responseCallList(Parcel &p, int slotId, int requestNumber, int responseType, int token,
266 RIL_Errno e, void *response, size_t responselen);
267static int responseSMS(Parcel &p, int slotId, int requestNumber, int responseType, int token,
268 RIL_Errno e, void *response, size_t responselen);
269static int responseSIM_IO(Parcel &p, int slotId, int requestNumber, int responseType, int token,
270 RIL_Errno e, void *response, size_t responselen);
271static int responseCallForwards(Parcel &p, int slotId, int requestNumber, int responseType,
272 int token, RIL_Errno e, void *response, size_t responselen);
273static int responseDataCallList(Parcel &p, int slotId, int requestNumber, int responseType,
274 int token, RIL_Errno e, void *response, size_t responselen);
275static int responseSetupDataCall(Parcel &p, int slotId, int requestNumber, int responseType,
276 int token, RIL_Errno e, void *response, size_t responselen);
277static int responseRaw(Parcel &p, int slotId, int requestNumber, int responseType, int token,
278 RIL_Errno e, void *response, size_t responselen);
279static int responseSsn(Parcel &p, int slotId, int requestNumber, int responseType, int token,
280 RIL_Errno e, void *response, size_t responselen);
281static int responseGsmBrSmsCnf(Parcel &p, int slotId, int requestNumber, int responseType,
282 int token, RIL_Errno e, void *response, size_t responselen);
283static int responseCdmaBrSmsCnf(Parcel &p, int slotId, int requestNumber, int responseType,
284 int token, RIL_Errno e, void *response, size_t responselen);
285static int responseCdmaSms(Parcel &p, int slotId, int requestNumber, int responseType, int token,
286 RIL_Errno e, void *response, size_t responselen);
287static int responseCellList(Parcel &p, int slotId, int requestNumber, int responseType, int token,
288 RIL_Errno e, void *response, size_t responselen);
289static int responseCdmaInformationRecords(Parcel &p, int slotId, int requestNumber,
290 int responseType, int token, RIL_Errno e,void *response, size_t responselen);
291static int responseRilSignalStrength(Parcel &p, int slotId, int requestNumber, int responseType,
292 int token, RIL_Errno e,void *response, size_t responselen);
293static int responseCallRing(Parcel &p, int slotId, int requestNumber, int responseType, int token,
294 RIL_Errno e, void *response, size_t responselen);
295static int responseCdmaSignalInfoRecord(Parcel &p, int slotId, int requestNumber, int responseType,
296 int token, RIL_Errno e,void *response, size_t responselen);
297static int responseCdmaCallWaiting(Parcel &p, int slotId, int requestNumber, int responseType,
298 int token, RIL_Errno e,void *response, size_t responselen);
299static int responseSimRefresh(Parcel &p, int slotId, int requestNumber, int responseType, int token,
300 RIL_Errno e, void *response, size_t responselen);
301static int responseCellInfoList(Parcel &p, int slotId, int requestNumber, int responseType,
302 int token, RIL_Errno e, void *response, size_t responselen);
303static int responseHardwareConfig(Parcel &p, int slotId, int requestNumber, int responseType,
304 int token, RIL_Errno e, void *response, size_t responselen);
305static int responseDcRtInfo(Parcel &p, int slotId, int requestNumber, int responseType, int token,
306 RIL_Errno e, void *response, size_t responselen);
307static int responseRadioCapability(Parcel &p, int slotId, int requestNumber, int responseType,
308 int token, RIL_Errno e, void *response, size_t responselen);
309static int responseSSData(Parcel &p, int slotId, int requestNumber, int responseType, int token,
310 RIL_Errno e, void *response, size_t responselen);
311static int responseLceStatus(Parcel &p, int slotId, int requestNumber, int responseType, int token,
312 RIL_Errno e, void *response, size_t responselen);
313static int responseLceData(Parcel &p, int slotId, int requestNumber, int responseType, int token,
314 RIL_Errno e, void *response, size_t responselen);
315static int responseActivityData(Parcel &p, int slotId, int requestNumber, int responseType,
316 int token, RIL_Errno e, void *response, size_t responselen);
317static int responseCarrierRestrictions(Parcel &p, int slotId, int requestNumber, int responseType,
318 int token, RIL_Errno e, void *response, size_t responselen);
319static int responsePcoData(Parcel &p, int slotId, int requestNumber, int responseType, int token,
320 RIL_Errno e, void *response, size_t responselen);
Amit Mahajan54563d32014-11-22 00:54:49 +0000321
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 Padawe4c05f352016-01-26 16:19:00 -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
Amit Mahajan18fe36b2016-08-25 11:19:21 -0700363char * RIL_getRilSocketName() {
Etan Cohend3652192014-06-20 08:28:44 -0700364 return rild;
365}
366
367extern "C"
Dheeraj Shetty27976c42014-07-02 21:27:57 +0200368void RIL_setRilSocketName(const char * s) {
Etan Cohend3652192014-06-20 08:28:44 -0700369 strncpy(rild, s, MAX_SOCKET_NAME_LENGTH);
370}
371
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800372static char *
Wink Savillef4c4d362009-04-02 01:37:03 -0700373strdupReadString(Parcel &p) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800374 size_t stringlen;
375 const char16_t *s16;
Wink Saville7f856802009-06-09 10:23:37 -0700376
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800377 s16 = p.readString16Inplace(&stringlen);
Wink Saville7f856802009-06-09 10:23:37 -0700378
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800379 return strndup16to8(s16, stringlen);
380}
381
Wink Saville8b4e4f72014-10-17 15:01:45 -0700382static status_t
383readStringFromParcelInplace(Parcel &p, char *str, size_t maxLen) {
384 size_t s16Len;
385 const char16_t *s16;
386
387 s16 = p.readString16Inplace(&s16Len);
388 if (s16 == NULL) {
389 return NO_MEMORY;
390 }
391 size_t strLen = strnlen16to8(s16, s16Len);
392 if ((strLen + 1) > maxLen) {
393 return NO_MEMORY;
394 }
395 if (strncpy16to8(str, s16, strLen) == NULL) {
396 return NO_MEMORY;
397 } else {
398 return NO_ERROR;
399 }
400}
401
Wink Savillef4c4d362009-04-02 01:37:03 -0700402static void writeStringToParcel(Parcel &p, const char *s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800403 char16_t *s16;
404 size_t s16_len;
405 s16 = strdup8to16(s, &s16_len);
406 p.writeString16(s16, s16_len);
407 free(s16);
408}
409
410
411static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700412memsetString (char *s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800413 if (s != NULL) {
414 memset (s, 0, strlen(s));
415 }
416}
417
418void nullParcelReleaseFunction (const uint8_t* data, size_t dataSize,
419 const size_t* objects, size_t objectsSize,
Wink Savillef4c4d362009-04-02 01:37:03 -0700420 void* cookie) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800421 // do nothing -- the data reference lives longer than the Parcel object
422}
423
Wink Saville7f856802009-06-09 10:23:37 -0700424/**
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800425 * To be called from dispatch thread
426 * Issue a single local request, ensuring that the response
Wink Saville7f856802009-06-09 10:23:37 -0700427 * is not sent back up to the command process
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800428 */
429static void
Etan Cohend3652192014-06-20 08:28:44 -0700430issueLocalRequest(int request, void *data, int len, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800431 RequestInfo *pRI;
432 int ret;
Etan Cohend3652192014-06-20 08:28:44 -0700433 /* Hook for current context */
434 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
435 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
436 /* pendingRequestsHook refer to &s_pendingRequests */
437 RequestInfo** pendingRequestsHook = &s_pendingRequests;
438
439#if (SIM_COUNT == 2)
440 if (socket_id == RIL_SOCKET_2) {
441 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
442 pendingRequestsHook = &s_pendingRequests_socket2;
443 }
444#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800445
446 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
Sanket Padawe55227b52016-02-29 10:09:26 -0800447 if (pRI == NULL) {
448 RLOGE("Memory allocation failed for request %s", requestToString(request));
449 return;
450 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800451
452 pRI->local = 1;
453 pRI->token = 0xffffffff; // token is not used in this context
454 pRI->pCI = &(s_commands[request]);
Etan Cohend3652192014-06-20 08:28:44 -0700455 pRI->socket_id = socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800456
Etan Cohend3652192014-06-20 08:28:44 -0700457 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800458 assert (ret == 0);
459
Etan Cohend3652192014-06-20 08:28:44 -0700460 pRI->p_next = *pendingRequestsHook;
461 *pendingRequestsHook = pRI;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800462
Etan Cohend3652192014-06-20 08:28:44 -0700463 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800464 assert (ret == 0);
465
Wink Saville8eb2a122012-11-19 16:05:13 -0800466 RLOGD("C[locl]> %s", requestToString(request));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800467
Etan Cohend3652192014-06-20 08:28:44 -0700468 CALL_ONREQUEST(request, data, len, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800469}
470
471
472
473static int
Etan Cohend3652192014-06-20 08:28:44 -0700474processCommandBuffer(void *buffer, size_t buflen, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800475 Parcel p;
476 status_t status;
477 int32_t request;
478 int32_t token;
479 RequestInfo *pRI;
480 int ret;
Etan Cohend3652192014-06-20 08:28:44 -0700481 /* Hook for current context */
482 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
483 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
484 /* pendingRequestsHook refer to &s_pendingRequests */
485 RequestInfo** pendingRequestsHook = &s_pendingRequests;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800486
487 p.setData((uint8_t *) buffer, buflen);
488
489 // status checked at end
490 status = p.readInt32(&request);
491 status = p.readInt32 (&token);
492
Etan Cohend3652192014-06-20 08:28:44 -0700493#if (SIM_COUNT >= 2)
494 if (socket_id == RIL_SOCKET_2) {
495 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
496 pendingRequestsHook = &s_pendingRequests_socket2;
497 }
498#if (SIM_COUNT >= 3)
499 else if (socket_id == RIL_SOCKET_3) {
500 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
501 pendingRequestsHook = &s_pendingRequests_socket3;
502 }
503#endif
504#if (SIM_COUNT >= 4)
505 else if (socket_id == RIL_SOCKET_4) {
506 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
507 pendingRequestsHook = &s_pendingRequests_socket4;
508 }
509#endif
510#endif
511
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800512 if (status != NO_ERROR) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800513 RLOGE("invalid request block");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800514 return 0;
515 }
516
Sooraj Sasindran405313f2016-05-06 16:19:56 -0700517 // Received an Ack for the previous result sent to RIL.java,
518 // so release wakelock and exit
519 if (request == RIL_RESPONSE_ACKNOWLEDGEMENT) {
520 releaseWakeLock();
521 return 0;
522 }
523
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800524 if (request < 1 || request >= (int32_t)NUM_ELEMS(s_commands)) {
Etan Cohend3652192014-06-20 08:28:44 -0700525 Parcel pErr;
Wink Saville8eb2a122012-11-19 16:05:13 -0800526 RLOGE("unsupported request code %d token %d", request, token);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800527 // FIXME this should perhaps return a response
Etan Cohend3652192014-06-20 08:28:44 -0700528 pErr.writeInt32 (RESPONSE_SOLICITED);
529 pErr.writeInt32 (token);
530 pErr.writeInt32 (RIL_E_GENERIC_FAILURE);
531
532 sendResponse(pErr, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800533 return 0;
534 }
535
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800536 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
Sanket Padawe55227b52016-02-29 10:09:26 -0800537 if (pRI == NULL) {
538 RLOGE("Memory allocation failed for request %s", requestToString(request));
539 return 0;
540 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800541
542 pRI->token = token;
543 pRI->pCI = &(s_commands[request]);
Etan Cohend3652192014-06-20 08:28:44 -0700544 pRI->socket_id = socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800545
Etan Cohend3652192014-06-20 08:28:44 -0700546 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800547 assert (ret == 0);
548
Etan Cohend3652192014-06-20 08:28:44 -0700549 pRI->p_next = *pendingRequestsHook;
550 *pendingRequestsHook = pRI;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800551
Etan Cohend3652192014-06-20 08:28:44 -0700552 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800553 assert (ret == 0);
554
Wink Saville7f856802009-06-09 10:23:37 -0700555 pRI->pCI->dispatchFunction(p, pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800556
557 return 0;
558}
559
Amit Mahajan18fe36b2016-08-25 11:19:21 -0700560int
561addRequestToList(RequestInfo *pRI, int request, int token, RIL_SOCKET_ID socket_id) {
562 status_t status;
563 int ret;
564 /* Hook for current context */
565 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
566 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
567 /* pendingRequestsHook refer to &s_pendingRequests */
568 RequestInfo** pendingRequestsHook = &s_pendingRequests;
569
570#if (SIM_COUNT >= 2)
571 if (socket_id == RIL_SOCKET_2) {
572 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
573 pendingRequestsHook = &s_pendingRequests_socket2;
574 }
575#if (SIM_COUNT >= 3)
576 else if (socket_id == RIL_SOCKET_3) {
577 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
578 pendingRequestsHook = &s_pendingRequests_socket3;
579 }
580#endif
581#if (SIM_COUNT >= 4)
582 else if (socket_id == RIL_SOCKET_4) {
583 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
584 pendingRequestsHook = &s_pendingRequests_socket4;
585 }
586#endif
587#endif
588
589 // Received an Ack for the previous result sent to RIL.java,
590 // so release wakelock and exit
591 if (request == RIL_RESPONSE_ACKNOWLEDGEMENT) {
592 releaseWakeLock();
593 return 0;
594 }
595
596 ret = pthread_mutex_lock(pendingRequestsMutexHook);
597 assert (ret == 0);
598
599 pRI->p_next = *pendingRequestsHook;
600 *pendingRequestsHook = pRI;
601
602 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
603 assert (ret == 0);
604
605 return 0;
606}
607
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800608static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700609invalidCommandBlock (RequestInfo *pRI) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800610 RLOGE("invalid command block for token %d request %s",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800611 pRI->token, requestToString(pRI->pCI->requestNumber));
612}
613
614/** Callee expects NULL */
Wink Saville7f856802009-06-09 10:23:37 -0700615static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700616dispatchVoid (Parcel& p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800617 clearPrintBuf;
618 printRequest(pRI->token, pRI->pCI->requestNumber);
Etan Cohend3652192014-06-20 08:28:44 -0700619 CALL_ONREQUEST(pRI->pCI->requestNumber, NULL, 0, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800620}
621
622/** Callee expects const char * */
623static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700624dispatchString (Parcel& p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800625 status_t status;
626 size_t datalen;
627 size_t stringlen;
628 char *string8 = NULL;
629
630 string8 = strdupReadString(p);
631
632 startRequest;
633 appendPrintBuf("%s%s", printBuf, string8);
634 closeRequest;
635 printRequest(pRI->token, pRI->pCI->requestNumber);
636
Etan Cohend3652192014-06-20 08:28:44 -0700637 CALL_ONREQUEST(pRI->pCI->requestNumber, string8,
638 sizeof(char *), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800639
640#ifdef MEMSET_FREED
641 memsetString(string8);
642#endif
643
644 free(string8);
645 return;
646invalid:
647 invalidCommandBlock(pRI);
648 return;
649}
650
651/** Callee expects const char ** */
652static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700653dispatchStrings (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800654 int32_t countStrings;
655 status_t status;
656 size_t datalen;
657 char **pStrings;
658
659 status = p.readInt32 (&countStrings);
660
661 if (status != NO_ERROR) {
662 goto invalid;
663 }
664
665 startRequest;
666 if (countStrings == 0) {
667 // just some non-null pointer
Sanket Padawe0cfc5532016-03-07 17:12:19 -0800668 pStrings = (char **)calloc(1, sizeof(char *));
Sanket Padawe55227b52016-02-29 10:09:26 -0800669 if (pStrings == NULL) {
670 RLOGE("Memory allocation failed for request %s",
671 requestToString(pRI->pCI->requestNumber));
672 closeRequest;
673 return;
674 }
675
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800676 datalen = 0;
Sanket Padawe0cfc5532016-03-07 17:12:19 -0800677 } else if (countStrings < 0) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800678 pStrings = NULL;
679 datalen = 0;
680 } else {
681 datalen = sizeof(char *) * countStrings;
Wink Saville7f856802009-06-09 10:23:37 -0700682
Sanket Padawe0cfc5532016-03-07 17:12:19 -0800683 pStrings = (char **)calloc(countStrings, sizeof(char *));
Sanket Padawe55227b52016-02-29 10:09:26 -0800684 if (pStrings == NULL) {
685 RLOGE("Memory allocation failed for request %s",
686 requestToString(pRI->pCI->requestNumber));
687 closeRequest;
688 return;
689 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800690
691 for (int i = 0 ; i < countStrings ; i++) {
692 pStrings[i] = strdupReadString(p);
693 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
694 }
695 }
696 removeLastChar;
697 closeRequest;
698 printRequest(pRI->token, pRI->pCI->requestNumber);
699
Etan Cohend3652192014-06-20 08:28:44 -0700700 CALL_ONREQUEST(pRI->pCI->requestNumber, pStrings, datalen, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800701
702 if (pStrings != NULL) {
703 for (int i = 0 ; i < countStrings ; i++) {
704#ifdef MEMSET_FREED
705 memsetString (pStrings[i]);
706#endif
707 free(pStrings[i]);
708 }
709
710#ifdef MEMSET_FREED
711 memset(pStrings, 0, datalen);
712#endif
Sanket Padawe0cfc5532016-03-07 17:12:19 -0800713 free(pStrings);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800714 }
Wink Saville7f856802009-06-09 10:23:37 -0700715
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800716 return;
717invalid:
718 invalidCommandBlock(pRI);
719 return;
720}
721
722/** Callee expects const int * */
723static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700724dispatchInts (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800725 int32_t count;
726 status_t status;
727 size_t datalen;
728 int *pInts;
729
730 status = p.readInt32 (&count);
731
Sanket Padawe0cfc5532016-03-07 17:12:19 -0800732 if (status != NO_ERROR || count <= 0) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800733 goto invalid;
734 }
735
736 datalen = sizeof(int) * count;
Sanket Padawe0cfc5532016-03-07 17:12:19 -0800737 pInts = (int *)calloc(count, sizeof(int));
Sanket Padawe55227b52016-02-29 10:09:26 -0800738 if (pInts == NULL) {
739 RLOGE("Memory allocation failed for request %s", requestToString(pRI->pCI->requestNumber));
740 return;
741 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800742
743 startRequest;
744 for (int i = 0 ; i < count ; i++) {
745 int32_t t;
746
747 status = p.readInt32(&t);
748 pInts[i] = (int)t;
749 appendPrintBuf("%s%d,", printBuf, t);
750
751 if (status != NO_ERROR) {
Sanket Padawe0cfc5532016-03-07 17:12:19 -0800752 free(pInts);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800753 goto invalid;
754 }
755 }
756 removeLastChar;
757 closeRequest;
758 printRequest(pRI->token, pRI->pCI->requestNumber);
759
Etan Cohend3652192014-06-20 08:28:44 -0700760 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<int *>(pInts),
761 datalen, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800762
763#ifdef MEMSET_FREED
764 memset(pInts, 0, datalen);
765#endif
Sanket Padawe0cfc5532016-03-07 17:12:19 -0800766 free(pInts);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800767 return;
768invalid:
769 invalidCommandBlock(pRI);
770 return;
771}
772
773
Wink Saville7f856802009-06-09 10:23:37 -0700774/**
775 * Callee expects const RIL_SMS_WriteArgs *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800776 * Payload is:
777 * int32_t status
778 * String pdu
779 */
780static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700781dispatchSmsWrite (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800782 RIL_SMS_WriteArgs args;
783 int32_t t;
784 status_t status;
785
Mark Salyzyndba25612015-04-09 07:18:35 -0700786 RLOGD("dispatchSmsWrite");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800787 memset (&args, 0, sizeof(args));
788
789 status = p.readInt32(&t);
790 args.status = (int)t;
791
792 args.pdu = strdupReadString(p);
793
794 if (status != NO_ERROR || args.pdu == NULL) {
795 goto invalid;
796 }
797
798 args.smsc = strdupReadString(p);
799
800 startRequest;
801 appendPrintBuf("%s%d,%s,smsc=%s", printBuf, args.status,
802 (char*)args.pdu, (char*)args.smsc);
803 closeRequest;
804 printRequest(pRI->token, pRI->pCI->requestNumber);
Wink Saville7f856802009-06-09 10:23:37 -0700805
Etan Cohend3652192014-06-20 08:28:44 -0700806 CALL_ONREQUEST(pRI->pCI->requestNumber, &args, sizeof(args), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800807
808#ifdef MEMSET_FREED
809 memsetString (args.pdu);
810#endif
811
812 free (args.pdu);
Wink Saville7f856802009-06-09 10:23:37 -0700813
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800814#ifdef MEMSET_FREED
815 memset(&args, 0, sizeof(args));
816#endif
817
818 return;
819invalid:
820 invalidCommandBlock(pRI);
821 return;
822}
823
Wink Saville7f856802009-06-09 10:23:37 -0700824/**
825 * Callee expects const RIL_Dial *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800826 * Payload is:
827 * String address
828 * int32_t clir
829 */
830static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700831dispatchDial (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800832 RIL_Dial dial;
Wink Saville74fa3882009-12-22 15:35:41 -0800833 RIL_UUS_Info uusInfo;
Wink Saville7bce0822010-01-08 15:20:12 -0800834 int32_t sizeOfDial;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800835 int32_t t;
Wink Saville74fa3882009-12-22 15:35:41 -0800836 int32_t uusPresent;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800837 status_t status;
838
Mark Salyzyndba25612015-04-09 07:18:35 -0700839 RLOGD("dispatchDial");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800840 memset (&dial, 0, sizeof(dial));
841
842 dial.address = strdupReadString(p);
843
844 status = p.readInt32(&t);
845 dial.clir = (int)t;
846
847 if (status != NO_ERROR || dial.address == NULL) {
848 goto invalid;
849 }
850
Wink Saville3a4840b2010-04-07 13:29:58 -0700851 if (s_callbacks.version < 3) { // Remove when partners upgrade to version 3
Wink Saville74fa3882009-12-22 15:35:41 -0800852 uusPresent = 0;
Wink Saville7bce0822010-01-08 15:20:12 -0800853 sizeOfDial = sizeof(dial) - sizeof(RIL_UUS_Info *);
Wink Saville74fa3882009-12-22 15:35:41 -0800854 } else {
855 status = p.readInt32(&uusPresent);
856
857 if (status != NO_ERROR) {
858 goto invalid;
859 }
860
861 if (uusPresent == 0) {
862 dial.uusInfo = NULL;
863 } else {
864 int32_t len;
865
866 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
867
868 status = p.readInt32(&t);
869 uusInfo.uusType = (RIL_UUS_Type) t;
870
871 status = p.readInt32(&t);
872 uusInfo.uusDcs = (RIL_UUS_DCS) t;
873
874 status = p.readInt32(&len);
875 if (status != NO_ERROR) {
876 goto invalid;
877 }
878
879 // The java code writes -1 for null arrays
880 if (((int) len) == -1) {
881 uusInfo.uusData = NULL;
882 len = 0;
883 } else {
884 uusInfo.uusData = (char*) p.readInplace(len);
Sooraj Sasindrane0491222016-09-23 11:20:39 -0700885 // check if the length is invalid
886 if (uusInfo.uusData == NULL) {
887 goto invalid;
888 }
Wink Saville74fa3882009-12-22 15:35:41 -0800889 }
890
891 uusInfo.uusLength = len;
892 dial.uusInfo = &uusInfo;
893 }
Wink Saville7bce0822010-01-08 15:20:12 -0800894 sizeOfDial = sizeof(dial);
Wink Saville74fa3882009-12-22 15:35:41 -0800895 }
896
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800897 startRequest;
898 appendPrintBuf("%snum=%s,clir=%d", printBuf, dial.address, dial.clir);
Wink Saville74fa3882009-12-22 15:35:41 -0800899 if (uusPresent) {
900 appendPrintBuf("%s,uusType=%d,uusDcs=%d,uusLen=%d", printBuf,
901 dial.uusInfo->uusType, dial.uusInfo->uusDcs,
902 dial.uusInfo->uusLength);
903 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800904 closeRequest;
905 printRequest(pRI->token, pRI->pCI->requestNumber);
906
Etan Cohend3652192014-06-20 08:28:44 -0700907 CALL_ONREQUEST(pRI->pCI->requestNumber, &dial, sizeOfDial, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800908
909#ifdef MEMSET_FREED
910 memsetString (dial.address);
911#endif
912
913 free (dial.address);
Wink Saville7f856802009-06-09 10:23:37 -0700914
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800915#ifdef MEMSET_FREED
Wink Saville74fa3882009-12-22 15:35:41 -0800916 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800917 memset(&dial, 0, sizeof(dial));
918#endif
919
920 return;
921invalid:
922 invalidCommandBlock(pRI);
923 return;
924}
925
Wink Saville7f856802009-06-09 10:23:37 -0700926/**
927 * Callee expects const RIL_SIM_IO *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800928 * Payload is:
929 * int32_t command
930 * int32_t fileid
931 * String path
932 * int32_t p1, p2, p3
Wink Saville7f856802009-06-09 10:23:37 -0700933 * String data
934 * String pin2
Wink Savillec0114b32011-02-18 10:14:07 -0800935 * String aidPtr
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800936 */
937static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700938dispatchSIM_IO (Parcel &p, RequestInfo *pRI) {
Wink Savillec0114b32011-02-18 10:14:07 -0800939 union RIL_SIM_IO {
940 RIL_SIM_IO_v6 v6;
941 RIL_SIM_IO_v5 v5;
942 } simIO;
943
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800944 int32_t t;
Wink Savillec0114b32011-02-18 10:14:07 -0800945 int size;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800946 status_t status;
947
Robert Greenwalt191e4dc2015-04-29 16:57:39 -0700948#if VDBG
Mark Salyzyndba25612015-04-09 07:18:35 -0700949 RLOGD("dispatchSIM_IO");
Robert Greenwalt191e4dc2015-04-29 16:57:39 -0700950#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800951 memset (&simIO, 0, sizeof(simIO));
952
Wink Saville7f856802009-06-09 10:23:37 -0700953 // note we only check status at the end
954
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800955 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800956 simIO.v6.command = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800957
958 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800959 simIO.v6.fileid = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800960
Wink Savillec0114b32011-02-18 10:14:07 -0800961 simIO.v6.path = strdupReadString(p);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800962
963 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800964 simIO.v6.p1 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800965
966 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800967 simIO.v6.p2 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800968
969 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800970 simIO.v6.p3 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800971
Wink Savillec0114b32011-02-18 10:14:07 -0800972 simIO.v6.data = strdupReadString(p);
973 simIO.v6.pin2 = strdupReadString(p);
974 simIO.v6.aidPtr = strdupReadString(p);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800975
976 startRequest;
Wink Savillec0114b32011-02-18 10:14:07 -0800977 appendPrintBuf("%scmd=0x%X,efid=0x%X,path=%s,%d,%d,%d,%s,pin2=%s,aid=%s", printBuf,
978 simIO.v6.command, simIO.v6.fileid, (char*)simIO.v6.path,
979 simIO.v6.p1, simIO.v6.p2, simIO.v6.p3,
980 (char*)simIO.v6.data, (char*)simIO.v6.pin2, simIO.v6.aidPtr);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800981 closeRequest;
982 printRequest(pRI->token, pRI->pCI->requestNumber);
Wink Saville7f856802009-06-09 10:23:37 -0700983
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800984 if (status != NO_ERROR) {
985 goto invalid;
986 }
987
Wink Savillec0114b32011-02-18 10:14:07 -0800988 size = (s_callbacks.version < 6) ? sizeof(simIO.v5) : sizeof(simIO.v6);
Etan Cohend3652192014-06-20 08:28:44 -0700989 CALL_ONREQUEST(pRI->pCI->requestNumber, &simIO, size, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800990
991#ifdef MEMSET_FREED
Wink Savillec0114b32011-02-18 10:14:07 -0800992 memsetString (simIO.v6.path);
993 memsetString (simIO.v6.data);
994 memsetString (simIO.v6.pin2);
995 memsetString (simIO.v6.aidPtr);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800996#endif
997
Wink Savillec0114b32011-02-18 10:14:07 -0800998 free (simIO.v6.path);
999 free (simIO.v6.data);
1000 free (simIO.v6.pin2);
1001 free (simIO.v6.aidPtr);
Wink Saville7f856802009-06-09 10:23:37 -07001002
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001003#ifdef MEMSET_FREED
1004 memset(&simIO, 0, sizeof(simIO));
1005#endif
1006
1007 return;
1008invalid:
1009 invalidCommandBlock(pRI);
1010 return;
1011}
1012
1013/**
Shishir Agrawal2458d8d2013-11-27 14:53:05 -08001014 * Callee expects const RIL_SIM_APDU *
1015 * Payload is:
1016 * int32_t sessionid
1017 * int32_t cla
1018 * int32_t instruction
1019 * int32_t p1, p2, p3
1020 * String data
1021 */
1022static void
1023dispatchSIM_APDU (Parcel &p, RequestInfo *pRI) {
1024 int32_t t;
1025 status_t status;
1026 RIL_SIM_APDU apdu;
1027
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07001028#if VDBG
Mark Salyzyndba25612015-04-09 07:18:35 -07001029 RLOGD("dispatchSIM_APDU");
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07001030#endif
Shishir Agrawal2458d8d2013-11-27 14:53:05 -08001031 memset (&apdu, 0, sizeof(RIL_SIM_APDU));
1032
1033 // Note we only check status at the end. Any single failure leads to
1034 // subsequent reads filing.
1035 status = p.readInt32(&t);
1036 apdu.sessionid = (int)t;
1037
1038 status = p.readInt32(&t);
1039 apdu.cla = (int)t;
1040
1041 status = p.readInt32(&t);
1042 apdu.instruction = (int)t;
1043
1044 status = p.readInt32(&t);
1045 apdu.p1 = (int)t;
1046
1047 status = p.readInt32(&t);
1048 apdu.p2 = (int)t;
1049
1050 status = p.readInt32(&t);
1051 apdu.p3 = (int)t;
1052
1053 apdu.data = strdupReadString(p);
1054
1055 startRequest;
1056 appendPrintBuf("%ssessionid=%d,cla=%d,ins=%d,p1=%d,p2=%d,p3=%d,data=%s",
1057 printBuf, apdu.sessionid, apdu.cla, apdu.instruction, apdu.p1, apdu.p2,
1058 apdu.p3, (char*)apdu.data);
1059 closeRequest;
1060 printRequest(pRI->token, pRI->pCI->requestNumber);
1061
1062 if (status != NO_ERROR) {
1063 goto invalid;
1064 }
1065
Etan Cohend3652192014-06-20 08:28:44 -07001066 CALL_ONREQUEST(pRI->pCI->requestNumber, &apdu, sizeof(RIL_SIM_APDU), pRI, pRI->socket_id);
Shishir Agrawal2458d8d2013-11-27 14:53:05 -08001067
1068#ifdef MEMSET_FREED
1069 memsetString(apdu.data);
1070#endif
1071 free(apdu.data);
1072
1073#ifdef MEMSET_FREED
1074 memset(&apdu, 0, sizeof(RIL_SIM_APDU));
1075#endif
1076
1077 return;
1078invalid:
1079 invalidCommandBlock(pRI);
1080 return;
1081}
1082
1083
1084/**
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001085 * Callee expects const RIL_CallForwardInfo *
1086 * Payload is:
1087 * int32_t status/action
1088 * int32_t reason
1089 * int32_t serviceCode
1090 * int32_t toa
1091 * String number (0 length -> null)
1092 * int32_t timeSeconds
1093 */
Wink Saville7f856802009-06-09 10:23:37 -07001094static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001095dispatchCallForward(Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001096 RIL_CallForwardInfo cff;
1097 int32_t t;
1098 status_t status;
1099
Mark Salyzyndba25612015-04-09 07:18:35 -07001100 RLOGD("dispatchCallForward");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001101 memset (&cff, 0, sizeof(cff));
1102
Wink Saville7f856802009-06-09 10:23:37 -07001103 // note we only check status at the end
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001104
1105 status = p.readInt32(&t);
1106 cff.status = (int)t;
Wink Saville7f856802009-06-09 10:23:37 -07001107
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001108 status = p.readInt32(&t);
1109 cff.reason = (int)t;
1110
1111 status = p.readInt32(&t);
1112 cff.serviceClass = (int)t;
1113
1114 status = p.readInt32(&t);
1115 cff.toa = (int)t;
1116
1117 cff.number = strdupReadString(p);
1118
1119 status = p.readInt32(&t);
1120 cff.timeSeconds = (int)t;
1121
1122 if (status != NO_ERROR) {
1123 goto invalid;
1124 }
1125
1126 // special case: number 0-length fields is null
1127
1128 if (cff.number != NULL && strlen (cff.number) == 0) {
1129 cff.number = NULL;
1130 }
1131
1132 startRequest;
1133 appendPrintBuf("%sstat=%d,reason=%d,serv=%d,toa=%d,%s,tout=%d", printBuf,
1134 cff.status, cff.reason, cff.serviceClass, cff.toa,
1135 (char*)cff.number, cff.timeSeconds);
1136 closeRequest;
1137 printRequest(pRI->token, pRI->pCI->requestNumber);
1138
Etan Cohend3652192014-06-20 08:28:44 -07001139 CALL_ONREQUEST(pRI->pCI->requestNumber, &cff, sizeof(cff), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001140
1141#ifdef MEMSET_FREED
1142 memsetString(cff.number);
1143#endif
1144
1145 free (cff.number);
1146
1147#ifdef MEMSET_FREED
1148 memset(&cff, 0, sizeof(cff));
1149#endif
1150
1151 return;
1152invalid:
1153 invalidCommandBlock(pRI);
1154 return;
1155}
1156
1157
Wink Saville7f856802009-06-09 10:23:37 -07001158static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001159dispatchRaw(Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001160 int32_t len;
1161 status_t status;
1162 const void *data;
1163
1164 status = p.readInt32(&len);
1165
1166 if (status != NO_ERROR) {
1167 goto invalid;
1168 }
1169
1170 // The java code writes -1 for null arrays
1171 if (((int)len) == -1) {
1172 data = NULL;
1173 len = 0;
Wink Saville7f856802009-06-09 10:23:37 -07001174 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001175
1176 data = p.readInplace(len);
1177
1178 startRequest;
1179 appendPrintBuf("%sraw_size=%d", printBuf, len);
1180 closeRequest;
1181 printRequest(pRI->token, pRI->pCI->requestNumber);
1182
Etan Cohend3652192014-06-20 08:28:44 -07001183 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<void *>(data), len, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001184
1185 return;
1186invalid:
1187 invalidCommandBlock(pRI);
1188 return;
1189}
1190
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001191static status_t
1192constructCdmaSms(Parcel &p, RequestInfo *pRI, RIL_CDMA_SMS_Message& rcsm) {
Wink Savillef4c4d362009-04-02 01:37:03 -07001193 int32_t t;
1194 uint8_t ut;
1195 status_t status;
1196 int32_t digitCount;
1197 int digitLimit;
Wink Saville7f856802009-06-09 10:23:37 -07001198
Wink Savillef4c4d362009-04-02 01:37:03 -07001199 memset(&rcsm, 0, sizeof(rcsm));
1200
1201 status = p.readInt32(&t);
1202 rcsm.uTeleserviceID = (int) t;
1203
1204 status = p.read(&ut,sizeof(ut));
1205 rcsm.bIsServicePresent = (uint8_t) ut;
1206
1207 status = p.readInt32(&t);
1208 rcsm.uServicecategory = (int) t;
1209
1210 status = p.readInt32(&t);
1211 rcsm.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1212
1213 status = p.readInt32(&t);
1214 rcsm.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1215
1216 status = p.readInt32(&t);
1217 rcsm.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1218
1219 status = p.readInt32(&t);
1220 rcsm.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1221
1222 status = p.read(&ut,sizeof(ut));
1223 rcsm.sAddress.number_of_digits= (uint8_t) ut;
1224
1225 digitLimit= MIN((rcsm.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
1226 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1227 status = p.read(&ut,sizeof(ut));
1228 rcsm.sAddress.digits[digitCount] = (uint8_t) ut;
1229 }
1230
Wink Saville7f856802009-06-09 10:23:37 -07001231 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001232 rcsm.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1233
Wink Saville7f856802009-06-09 10:23:37 -07001234 status = p.read(&ut,sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001235 rcsm.sSubAddress.odd = (uint8_t) ut;
1236
1237 status = p.read(&ut,sizeof(ut));
1238 rcsm.sSubAddress.number_of_digits = (uint8_t) ut;
1239
1240 digitLimit= MIN((rcsm.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
Wink Saville7f856802009-06-09 10:23:37 -07001241 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1242 status = p.read(&ut,sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001243 rcsm.sSubAddress.digits[digitCount] = (uint8_t) ut;
1244 }
1245
Wink Saville7f856802009-06-09 10:23:37 -07001246 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001247 rcsm.uBearerDataLen = (int) t;
1248
1249 digitLimit= MIN((rcsm.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
Wink Saville7f856802009-06-09 10:23:37 -07001250 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1251 status = p.read(&ut, sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001252 rcsm.aBearerData[digitCount] = (uint8_t) ut;
1253 }
1254
1255 if (status != NO_ERROR) {
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001256 return status;
Wink Savillef4c4d362009-04-02 01:37:03 -07001257 }
1258
1259 startRequest;
1260 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
Wink Saville1b5fd232009-04-22 14:50:00 -07001261 sAddress.digit_mode=%d, sAddress.Number_mode=%d, sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07001262 printBuf, rcsm.uTeleserviceID,rcsm.bIsServicePresent,rcsm.uServicecategory,
Wink Saville1b5fd232009-04-22 14:50:00 -07001263 rcsm.sAddress.digit_mode, rcsm.sAddress.number_mode,rcsm.sAddress.number_type);
Wink Savillef4c4d362009-04-02 01:37:03 -07001264 closeRequest;
Wink Saville7f856802009-06-09 10:23:37 -07001265
Wink Savillef4c4d362009-04-02 01:37:03 -07001266 printRequest(pRI->token, pRI->pCI->requestNumber);
1267
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001268 return status;
1269}
1270
1271static void
1272dispatchCdmaSms(Parcel &p, RequestInfo *pRI) {
1273 RIL_CDMA_SMS_Message rcsm;
1274
Mark Salyzyndba25612015-04-09 07:18:35 -07001275 RLOGD("dispatchCdmaSms");
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001276 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1277 goto invalid;
1278 }
1279
Etan Cohend3652192014-06-20 08:28:44 -07001280 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001281
1282#ifdef MEMSET_FREED
1283 memset(&rcsm, 0, sizeof(rcsm));
1284#endif
1285
1286 return;
1287
1288invalid:
1289 invalidCommandBlock(pRI);
1290 return;
1291}
1292
Wink Saville7f856802009-06-09 10:23:37 -07001293static void
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001294dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1295 RIL_IMS_SMS_Message rism;
1296 RIL_CDMA_SMS_Message rcsm;
1297
Mark Salyzyndba25612015-04-09 07:18:35 -07001298 RLOGD("dispatchImsCdmaSms: retry=%d, messageRef=%d", retry, messageRef);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001299
1300 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1301 goto invalid;
1302 }
1303 memset(&rism, 0, sizeof(rism));
1304 rism.tech = RADIO_TECH_3GPP2;
1305 rism.retry = retry;
1306 rism.messageRef = messageRef;
1307 rism.message.cdmaMessage = &rcsm;
1308
Etan Cohend3652192014-06-20 08:28:44 -07001309 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001310 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Etan Cohend3652192014-06-20 08:28:44 -07001311 +sizeof(rcsm),pRI, pRI->socket_id);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001312
1313#ifdef MEMSET_FREED
1314 memset(&rcsm, 0, sizeof(rcsm));
1315 memset(&rism, 0, sizeof(rism));
1316#endif
1317
1318 return;
1319
1320invalid:
1321 invalidCommandBlock(pRI);
1322 return;
1323}
1324
1325static void
1326dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1327 RIL_IMS_SMS_Message rism;
1328 int32_t countStrings;
1329 status_t status;
1330 size_t datalen;
1331 char **pStrings;
Mark Salyzyndba25612015-04-09 07:18:35 -07001332 RLOGD("dispatchImsGsmSms: retry=%d, messageRef=%d", retry, messageRef);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001333
1334 status = p.readInt32 (&countStrings);
1335
1336 if (status != NO_ERROR) {
1337 goto invalid;
1338 }
1339
1340 memset(&rism, 0, sizeof(rism));
1341 rism.tech = RADIO_TECH_3GPP;
1342 rism.retry = retry;
1343 rism.messageRef = messageRef;
1344
1345 startRequest;
Etan Cohen5d891b72014-02-27 17:25:17 -08001346 appendPrintBuf("%stech=%d, retry=%d, messageRef=%d, ", printBuf,
1347 (int)rism.tech, (int)rism.retry, rism.messageRef);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001348 if (countStrings == 0) {
1349 // just some non-null pointer
Sanket Padawe0cfc5532016-03-07 17:12:19 -08001350 pStrings = (char **)calloc(1, sizeof(char *));
Sanket Padawe55227b52016-02-29 10:09:26 -08001351 if (pStrings == NULL) {
1352 RLOGE("Memory allocation failed for request %s",
1353 requestToString(pRI->pCI->requestNumber));
1354 closeRequest;
1355 return;
1356 }
1357
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001358 datalen = 0;
Sanket Padawe0cfc5532016-03-07 17:12:19 -08001359 } else if (countStrings < 0) {
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001360 pStrings = NULL;
1361 datalen = 0;
1362 } else {
Meng Wangef966a32016-06-20 17:38:18 -07001363 if ((size_t)countStrings > (INT_MAX/sizeof(char *))) {
Sanket Padawe0cfc5532016-03-07 17:12:19 -08001364 RLOGE("Invalid value of countStrings: \n");
1365 closeRequest;
1366 return;
1367 }
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001368 datalen = sizeof(char *) * countStrings;
1369
Sanket Padawe0cfc5532016-03-07 17:12:19 -08001370 pStrings = (char **)calloc(countStrings, sizeof(char *));
Sanket Padawe55227b52016-02-29 10:09:26 -08001371 if (pStrings == NULL) {
1372 RLOGE("Memory allocation failed for request %s",
1373 requestToString(pRI->pCI->requestNumber));
1374 closeRequest;
1375 return;
1376 }
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001377
1378 for (int i = 0 ; i < countStrings ; i++) {
1379 pStrings[i] = strdupReadString(p);
1380 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
1381 }
1382 }
1383 removeLastChar;
1384 closeRequest;
1385 printRequest(pRI->token, pRI->pCI->requestNumber);
1386
1387 rism.message.gsmMessage = pStrings;
Etan Cohend3652192014-06-20 08:28:44 -07001388 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001389 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Etan Cohend3652192014-06-20 08:28:44 -07001390 +datalen, pRI, pRI->socket_id);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001391
1392 if (pStrings != NULL) {
1393 for (int i = 0 ; i < countStrings ; i++) {
1394#ifdef MEMSET_FREED
1395 memsetString (pStrings[i]);
1396#endif
1397 free(pStrings[i]);
1398 }
1399
1400#ifdef MEMSET_FREED
1401 memset(pStrings, 0, datalen);
1402#endif
Sanket Padawe0cfc5532016-03-07 17:12:19 -08001403 free(pStrings);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001404 }
1405
1406#ifdef MEMSET_FREED
1407 memset(&rism, 0, sizeof(rism));
1408#endif
1409 return;
1410invalid:
1411 ALOGE("dispatchImsGsmSms invalid block");
1412 invalidCommandBlock(pRI);
1413 return;
1414}
1415
1416static void
1417dispatchImsSms(Parcel &p, RequestInfo *pRI) {
1418 int32_t t;
1419 status_t status = p.readInt32(&t);
1420 RIL_RadioTechnologyFamily format;
1421 uint8_t retry;
1422 int32_t messageRef;
1423
Mark Salyzyndba25612015-04-09 07:18:35 -07001424 RLOGD("dispatchImsSms");
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001425 if (status != NO_ERROR) {
1426 goto invalid;
1427 }
1428 format = (RIL_RadioTechnologyFamily) t;
1429
1430 // read retry field
1431 status = p.read(&retry,sizeof(retry));
1432 if (status != NO_ERROR) {
1433 goto invalid;
1434 }
1435 // read messageRef field
1436 status = p.read(&messageRef,sizeof(messageRef));
1437 if (status != NO_ERROR) {
1438 goto invalid;
1439 }
1440
1441 if (RADIO_TECH_3GPP == format) {
1442 dispatchImsGsmSms(p, pRI, retry, messageRef);
1443 } else if (RADIO_TECH_3GPP2 == format) {
1444 dispatchImsCdmaSms(p, pRI, retry, messageRef);
1445 } else {
1446 ALOGE("requestImsSendSMS invalid format value =%d", format);
1447 }
1448
1449 return;
1450
1451invalid:
1452 invalidCommandBlock(pRI);
1453 return;
1454}
1455
1456static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001457dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI) {
1458 RIL_CDMA_SMS_Ack rcsa;
1459 int32_t t;
1460 status_t status;
1461 int32_t digitCount;
1462
Mark Salyzyndba25612015-04-09 07:18:35 -07001463 RLOGD("dispatchCdmaSmsAck");
Wink Savillef4c4d362009-04-02 01:37:03 -07001464 memset(&rcsa, 0, sizeof(rcsa));
1465
1466 status = p.readInt32(&t);
1467 rcsa.uErrorClass = (RIL_CDMA_SMS_ErrorClass) t;
1468
1469 status = p.readInt32(&t);
1470 rcsa.uSMSCauseCode = (int) t;
1471
1472 if (status != NO_ERROR) {
1473 goto invalid;
1474 }
1475
1476 startRequest;
Wink Saville1b5fd232009-04-22 14:50:00 -07001477 appendPrintBuf("%suErrorClass=%d, uTLStatus=%d, ",
1478 printBuf, rcsa.uErrorClass, rcsa.uSMSCauseCode);
Wink Savillef4c4d362009-04-02 01:37:03 -07001479 closeRequest;
1480
1481 printRequest(pRI->token, pRI->pCI->requestNumber);
1482
Etan Cohend3652192014-06-20 08:28:44 -07001483 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsa, sizeof(rcsa),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001484
1485#ifdef MEMSET_FREED
1486 memset(&rcsa, 0, sizeof(rcsa));
1487#endif
1488
1489 return;
1490
1491invalid:
1492 invalidCommandBlock(pRI);
1493 return;
1494}
1495
Wink Savillea592eeb2009-05-22 13:26:36 -07001496static void
1497dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1498 int32_t t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001499 status_t status;
Wink Savillea592eeb2009-05-22 13:26:36 -07001500 int32_t num;
Wink Savillef4c4d362009-04-02 01:37:03 -07001501
Wink Savillea592eeb2009-05-22 13:26:36 -07001502 status = p.readInt32(&num);
Wink Savillef4c4d362009-04-02 01:37:03 -07001503 if (status != NO_ERROR) {
1504 goto invalid;
1505 }
1506
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001507 {
1508 RIL_GSM_BroadcastSmsConfigInfo gsmBci[num];
1509 RIL_GSM_BroadcastSmsConfigInfo *gsmBciPtrs[num];
Wink Savillea592eeb2009-05-22 13:26:36 -07001510
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001511 startRequest;
1512 for (int i = 0 ; i < num ; i++ ) {
1513 gsmBciPtrs[i] = &gsmBci[i];
Wink Savillef4c4d362009-04-02 01:37:03 -07001514
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001515 status = p.readInt32(&t);
1516 gsmBci[i].fromServiceId = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001517
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001518 status = p.readInt32(&t);
1519 gsmBci[i].toServiceId = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001520
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001521 status = p.readInt32(&t);
1522 gsmBci[i].fromCodeScheme = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001523
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001524 status = p.readInt32(&t);
1525 gsmBci[i].toCodeScheme = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001526
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001527 status = p.readInt32(&t);
1528 gsmBci[i].selected = (uint8_t) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001529
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001530 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId =%d, \
1531 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]", printBuf, i,
1532 gsmBci[i].fromServiceId, gsmBci[i].toServiceId,
1533 gsmBci[i].fromCodeScheme, gsmBci[i].toCodeScheme,
1534 gsmBci[i].selected);
1535 }
1536 closeRequest;
Wink Savillef4c4d362009-04-02 01:37:03 -07001537
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001538 if (status != NO_ERROR) {
1539 goto invalid;
1540 }
Wink Savillef4c4d362009-04-02 01:37:03 -07001541
Etan Cohend3652192014-06-20 08:28:44 -07001542 CALL_ONREQUEST(pRI->pCI->requestNumber,
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001543 gsmBciPtrs,
1544 num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *),
Etan Cohend3652192014-06-20 08:28:44 -07001545 pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001546
1547#ifdef MEMSET_FREED
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001548 memset(gsmBci, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo));
1549 memset(gsmBciPtrs, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *));
Wink Savillef4c4d362009-04-02 01:37:03 -07001550#endif
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001551 }
Wink Savillef4c4d362009-04-02 01:37:03 -07001552
1553 return;
1554
1555invalid:
1556 invalidCommandBlock(pRI);
1557 return;
Wink Savillea592eeb2009-05-22 13:26:36 -07001558}
Wink Savillef4c4d362009-04-02 01:37:03 -07001559
Wink Savillea592eeb2009-05-22 13:26:36 -07001560static void
1561dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1562 int32_t t;
1563 status_t status;
1564 int32_t num;
1565
1566 status = p.readInt32(&num);
1567 if (status != NO_ERROR) {
1568 goto invalid;
1569 }
1570
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001571 {
1572 RIL_CDMA_BroadcastSmsConfigInfo cdmaBci[num];
1573 RIL_CDMA_BroadcastSmsConfigInfo *cdmaBciPtrs[num];
Wink Savillea592eeb2009-05-22 13:26:36 -07001574
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001575 startRequest;
1576 for (int i = 0 ; i < num ; i++ ) {
1577 cdmaBciPtrs[i] = &cdmaBci[i];
Wink Savillea592eeb2009-05-22 13:26:36 -07001578
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001579 status = p.readInt32(&t);
1580 cdmaBci[i].service_category = (int) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001581
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001582 status = p.readInt32(&t);
1583 cdmaBci[i].language = (int) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001584
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001585 status = p.readInt32(&t);
1586 cdmaBci[i].selected = (uint8_t) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001587
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001588 appendPrintBuf("%s [%d: service_category=%d, language =%d, \
1589 entries.bSelected =%d]", printBuf, i, cdmaBci[i].service_category,
1590 cdmaBci[i].language, cdmaBci[i].selected);
1591 }
1592 closeRequest;
Wink Savillea592eeb2009-05-22 13:26:36 -07001593
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001594 if (status != NO_ERROR) {
1595 goto invalid;
1596 }
Wink Savillea592eeb2009-05-22 13:26:36 -07001597
Etan Cohend3652192014-06-20 08:28:44 -07001598 CALL_ONREQUEST(pRI->pCI->requestNumber,
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001599 cdmaBciPtrs,
1600 num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *),
Etan Cohend3652192014-06-20 08:28:44 -07001601 pRI, pRI->socket_id);
Wink Savillea592eeb2009-05-22 13:26:36 -07001602
1603#ifdef MEMSET_FREED
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001604 memset(cdmaBci, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo));
1605 memset(cdmaBciPtrs, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *));
Wink Savillea592eeb2009-05-22 13:26:36 -07001606#endif
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001607 }
Wink Savillea592eeb2009-05-22 13:26:36 -07001608
1609 return;
1610
1611invalid:
1612 invalidCommandBlock(pRI);
1613 return;
Wink Savillef4c4d362009-04-02 01:37:03 -07001614}
1615
1616static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI) {
1617 RIL_CDMA_SMS_WriteArgs rcsw;
1618 int32_t t;
1619 uint32_t ut;
1620 uint8_t uct;
1621 status_t status;
1622 int32_t digitCount;
Sukanya Rajkhowa605c7842013-10-29 14:55:30 +08001623 int32_t digitLimit;
Wink Savillef4c4d362009-04-02 01:37:03 -07001624
1625 memset(&rcsw, 0, sizeof(rcsw));
1626
1627 status = p.readInt32(&t);
1628 rcsw.status = t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001629
Wink Savillef4c4d362009-04-02 01:37:03 -07001630 status = p.readInt32(&t);
1631 rcsw.message.uTeleserviceID = (int) t;
1632
1633 status = p.read(&uct,sizeof(uct));
1634 rcsw.message.bIsServicePresent = (uint8_t) uct;
1635
1636 status = p.readInt32(&t);
1637 rcsw.message.uServicecategory = (int) t;
1638
1639 status = p.readInt32(&t);
1640 rcsw.message.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1641
1642 status = p.readInt32(&t);
1643 rcsw.message.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1644
1645 status = p.readInt32(&t);
1646 rcsw.message.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1647
1648 status = p.readInt32(&t);
1649 rcsw.message.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1650
1651 status = p.read(&uct,sizeof(uct));
1652 rcsw.message.sAddress.number_of_digits = (uint8_t) uct;
1653
Sukanya Rajkhowa605c7842013-10-29 14:55:30 +08001654 digitLimit = MIN((rcsw.message.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
1655
1656 for(digitCount = 0 ; digitCount < digitLimit; digitCount ++) {
Wink Savillef4c4d362009-04-02 01:37:03 -07001657 status = p.read(&uct,sizeof(uct));
1658 rcsw.message.sAddress.digits[digitCount] = (uint8_t) uct;
1659 }
1660
Wink Savillea592eeb2009-05-22 13:26:36 -07001661 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001662 rcsw.message.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1663
Wink Savillea592eeb2009-05-22 13:26:36 -07001664 status = p.read(&uct,sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001665 rcsw.message.sSubAddress.odd = (uint8_t) uct;
1666
1667 status = p.read(&uct,sizeof(uct));
1668 rcsw.message.sSubAddress.number_of_digits = (uint8_t) uct;
1669
Sukanya Rajkhowa605c7842013-10-29 14:55:30 +08001670 digitLimit = MIN((rcsw.message.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
1671
1672 for(digitCount = 0 ; digitCount < digitLimit; digitCount ++) {
Wink Savillea592eeb2009-05-22 13:26:36 -07001673 status = p.read(&uct,sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001674 rcsw.message.sSubAddress.digits[digitCount] = (uint8_t) uct;
1675 }
1676
Wink Savillea592eeb2009-05-22 13:26:36 -07001677 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001678 rcsw.message.uBearerDataLen = (int) t;
1679
Sukanya Rajkhowa605c7842013-10-29 14:55:30 +08001680 digitLimit = MIN((rcsw.message.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
1681
1682 for(digitCount = 0 ; digitCount < digitLimit; digitCount ++) {
Wink Savillea592eeb2009-05-22 13:26:36 -07001683 status = p.read(&uct, sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001684 rcsw.message.aBearerData[digitCount] = (uint8_t) uct;
1685 }
1686
1687 if (status != NO_ERROR) {
1688 goto invalid;
1689 }
1690
1691 startRequest;
Wink Saville1b5fd232009-04-22 14:50:00 -07001692 appendPrintBuf("%sstatus=%d, message.uTeleserviceID=%d, message.bIsServicePresent=%d, \
1693 message.uServicecategory=%d, message.sAddress.digit_mode=%d, \
1694 message.sAddress.number_mode=%d, \
1695 message.sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07001696 printBuf, rcsw.status, rcsw.message.uTeleserviceID, rcsw.message.bIsServicePresent,
Wink Saville1b5fd232009-04-22 14:50:00 -07001697 rcsw.message.uServicecategory, rcsw.message.sAddress.digit_mode,
1698 rcsw.message.sAddress.number_mode,
1699 rcsw.message.sAddress.number_type);
Wink Savillef4c4d362009-04-02 01:37:03 -07001700 closeRequest;
1701
1702 printRequest(pRI->token, pRI->pCI->requestNumber);
1703
Etan Cohend3652192014-06-20 08:28:44 -07001704 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsw, sizeof(rcsw),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001705
1706#ifdef MEMSET_FREED
1707 memset(&rcsw, 0, sizeof(rcsw));
1708#endif
1709
1710 return;
1711
1712invalid:
1713 invalidCommandBlock(pRI);
1714 return;
1715
1716}
1717
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -07001718// For backwards compatibility in RIL_REQUEST_SETUP_DATA_CALL.
1719// Version 4 of the RIL interface adds a new PDP type parameter to support
1720// IPv6 and dual-stack PDP contexts. When dealing with a previous version of
1721// RIL, remove the parameter from the request.
1722static void dispatchDataCall(Parcel& p, RequestInfo *pRI) {
1723 // In RIL v3, REQUEST_SETUP_DATA_CALL takes 6 parameters.
1724 const int numParamsRilV3 = 6;
1725
1726 // The first bytes of the RIL parcel contain the request number and the
1727 // serial number - see processCommandBuffer(). Copy them over too.
1728 int pos = p.dataPosition();
1729
1730 int numParams = p.readInt32();
1731 if (s_callbacks.version < 4 && numParams > numParamsRilV3) {
1732 Parcel p2;
1733 p2.appendFrom(&p, 0, pos);
1734 p2.writeInt32(numParamsRilV3);
1735 for(int i = 0; i < numParamsRilV3; i++) {
1736 p2.writeString16(p.readString16());
1737 }
1738 p2.setDataPosition(pos);
1739 dispatchStrings(p2, pRI);
1740 } else {
Lorenzo Colitti57ce1f22010-09-13 12:23:50 -07001741 p.setDataPosition(pos);
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -07001742 dispatchStrings(p, pRI);
1743 }
1744}
1745
Sungmin Choi75697532013-04-26 15:04:45 -07001746static void dispatchSetInitialAttachApn(Parcel &p, RequestInfo *pRI)
1747{
1748 RIL_InitialAttachApn pf;
1749 int32_t t;
1750 status_t status;
1751
1752 memset(&pf, 0, sizeof(pf));
1753
1754 pf.apn = strdupReadString(p);
1755 pf.protocol = strdupReadString(p);
1756
1757 status = p.readInt32(&t);
1758 pf.authtype = (int) t;
1759
1760 pf.username = strdupReadString(p);
1761 pf.password = strdupReadString(p);
1762
1763 startRequest;
Etan Cohen5d891b72014-02-27 17:25:17 -08001764 appendPrintBuf("%sapn=%s, protocol=%s, authtype=%d, username=%s, password=%s",
1765 printBuf, pf.apn, pf.protocol, pf.authtype, pf.username, pf.password);
Sungmin Choi75697532013-04-26 15:04:45 -07001766 closeRequest;
1767 printRequest(pRI->token, pRI->pCI->requestNumber);
1768
1769 if (status != NO_ERROR) {
1770 goto invalid;
1771 }
Etan Cohend3652192014-06-20 08:28:44 -07001772 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
Sungmin Choi75697532013-04-26 15:04:45 -07001773
1774#ifdef MEMSET_FREED
1775 memsetString(pf.apn);
1776 memsetString(pf.protocol);
1777 memsetString(pf.username);
1778 memsetString(pf.password);
1779#endif
1780
1781 free(pf.apn);
1782 free(pf.protocol);
1783 free(pf.username);
1784 free(pf.password);
1785
1786#ifdef MEMSET_FREED
1787 memset(&pf, 0, sizeof(pf));
1788#endif
1789
1790 return;
1791invalid:
1792 invalidCommandBlock(pRI);
1793 return;
1794}
1795
Jake Hamby8a4a2332014-01-15 13:12:05 -08001796static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI) {
1797 RIL_NV_ReadItem nvri;
1798 int32_t t;
1799 status_t status;
1800
1801 memset(&nvri, 0, sizeof(nvri));
1802
1803 status = p.readInt32(&t);
1804 nvri.itemID = (RIL_NV_Item) t;
1805
1806 if (status != NO_ERROR) {
1807 goto invalid;
1808 }
1809
1810 startRequest;
1811 appendPrintBuf("%snvri.itemID=%d, ", printBuf, nvri.itemID);
1812 closeRequest;
1813
1814 printRequest(pRI->token, pRI->pCI->requestNumber);
1815
Etan Cohend3652192014-06-20 08:28:44 -07001816 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvri, sizeof(nvri), pRI, pRI->socket_id);
Jake Hamby8a4a2332014-01-15 13:12:05 -08001817
1818#ifdef MEMSET_FREED
1819 memset(&nvri, 0, sizeof(nvri));
1820#endif
1821
1822 return;
1823
1824invalid:
1825 invalidCommandBlock(pRI);
1826 return;
1827}
1828
1829static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI) {
1830 RIL_NV_WriteItem nvwi;
1831 int32_t t;
1832 status_t status;
1833
1834 memset(&nvwi, 0, sizeof(nvwi));
1835
1836 status = p.readInt32(&t);
1837 nvwi.itemID = (RIL_NV_Item) t;
1838
1839 nvwi.value = strdupReadString(p);
1840
1841 if (status != NO_ERROR || nvwi.value == NULL) {
1842 goto invalid;
1843 }
1844
1845 startRequest;
1846 appendPrintBuf("%snvwi.itemID=%d, value=%s, ", printBuf, nvwi.itemID,
1847 nvwi.value);
1848 closeRequest;
1849
1850 printRequest(pRI->token, pRI->pCI->requestNumber);
1851
Etan Cohend3652192014-06-20 08:28:44 -07001852 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvwi, sizeof(nvwi), pRI, pRI->socket_id);
Jake Hamby8a4a2332014-01-15 13:12:05 -08001853
1854#ifdef MEMSET_FREED
1855 memsetString(nvwi.value);
1856#endif
1857
1858 free(nvwi.value);
1859
1860#ifdef MEMSET_FREED
1861 memset(&nvwi, 0, sizeof(nvwi));
1862#endif
1863
1864 return;
1865
1866invalid:
1867 invalidCommandBlock(pRI);
1868 return;
1869}
1870
1871
Etan Cohend3652192014-06-20 08:28:44 -07001872static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI) {
1873 RIL_SelectUiccSub uicc_sub;
1874 status_t status;
1875 int32_t t;
1876 memset(&uicc_sub, 0, sizeof(uicc_sub));
1877
1878 status = p.readInt32(&t);
1879 if (status != NO_ERROR) {
1880 goto invalid;
1881 }
1882 uicc_sub.slot = (int) t;
1883
1884 status = p.readInt32(&t);
1885 if (status != NO_ERROR) {
1886 goto invalid;
1887 }
1888 uicc_sub.app_index = (int) t;
1889
1890 status = p.readInt32(&t);
1891 if (status != NO_ERROR) {
1892 goto invalid;
1893 }
1894 uicc_sub.sub_type = (RIL_SubscriptionType) t;
1895
1896 status = p.readInt32(&t);
1897 if (status != NO_ERROR) {
1898 goto invalid;
1899 }
1900 uicc_sub.act_status = (RIL_UiccSubActStatus) t;
1901
1902 startRequest;
1903 appendPrintBuf("slot=%d, app_index=%d, act_status = %d", uicc_sub.slot, uicc_sub.app_index,
1904 uicc_sub.act_status);
1905 RLOGD("dispatchUiccSubscription, slot=%d, app_index=%d, act_status = %d", uicc_sub.slot,
1906 uicc_sub.app_index, uicc_sub.act_status);
1907 closeRequest;
1908 printRequest(pRI->token, pRI->pCI->requestNumber);
1909
1910 CALL_ONREQUEST(pRI->pCI->requestNumber, &uicc_sub, sizeof(uicc_sub), pRI, pRI->socket_id);
1911
1912#ifdef MEMSET_FREED
1913 memset(&uicc_sub, 0, sizeof(uicc_sub));
1914#endif
1915 return;
1916
1917invalid:
1918 invalidCommandBlock(pRI);
1919 return;
1920}
1921
Amit Mahajan90530a62014-07-01 15:54:08 -07001922static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI)
1923{
1924 RIL_SimAuthentication pf;
1925 int32_t t;
1926 status_t status;
1927
1928 memset(&pf, 0, sizeof(pf));
1929
1930 status = p.readInt32(&t);
1931 pf.authContext = (int) t;
1932 pf.authData = strdupReadString(p);
1933 pf.aid = strdupReadString(p);
1934
1935 startRequest;
1936 appendPrintBuf("authContext=%s, authData=%s, aid=%s", pf.authContext, pf.authData, pf.aid);
1937 closeRequest;
1938 printRequest(pRI->token, pRI->pCI->requestNumber);
1939
1940 if (status != NO_ERROR) {
1941 goto invalid;
1942 }
1943 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
1944
1945#ifdef MEMSET_FREED
1946 memsetString(pf.authData);
1947 memsetString(pf.aid);
1948#endif
1949
1950 free(pf.authData);
1951 free(pf.aid);
1952
1953#ifdef MEMSET_FREED
1954 memset(&pf, 0, sizeof(pf));
1955#endif
1956
1957 return;
1958invalid:
1959 invalidCommandBlock(pRI);
1960 return;
1961}
1962
Amit Mahajanc796e222014-08-13 16:54:01 +00001963static void dispatchDataProfile(Parcel &p, RequestInfo *pRI) {
1964 int32_t t;
1965 status_t status;
1966 int32_t num;
1967
1968 status = p.readInt32(&num);
Sanket Padawe0cfc5532016-03-07 17:12:19 -08001969 if (status != NO_ERROR || num < 0) {
Amit Mahajanc796e222014-08-13 16:54:01 +00001970 goto invalid;
1971 }
1972
1973 {
Sanket Padawe55227b52016-02-29 10:09:26 -08001974 RIL_DataProfileInfo *dataProfiles =
Sanket Padawe0cfc5532016-03-07 17:12:19 -08001975 (RIL_DataProfileInfo *)calloc(num, sizeof(RIL_DataProfileInfo));
Sanket Padawe55227b52016-02-29 10:09:26 -08001976 if (dataProfiles == NULL) {
1977 RLOGE("Memory allocation failed for request %s",
1978 requestToString(pRI->pCI->requestNumber));
1979 return;
1980 }
1981 RIL_DataProfileInfo **dataProfilePtrs =
Sanket Padawe0cfc5532016-03-07 17:12:19 -08001982 (RIL_DataProfileInfo **)calloc(num, sizeof(RIL_DataProfileInfo *));
Sanket Padawe55227b52016-02-29 10:09:26 -08001983 if (dataProfilePtrs == NULL) {
1984 RLOGE("Memory allocation failed for request %s",
1985 requestToString(pRI->pCI->requestNumber));
1986 free(dataProfiles);
1987 return;
1988 }
Amit Mahajanc796e222014-08-13 16:54:01 +00001989
1990 startRequest;
1991 for (int i = 0 ; i < num ; i++ ) {
1992 dataProfilePtrs[i] = &dataProfiles[i];
1993
1994 status = p.readInt32(&t);
1995 dataProfiles[i].profileId = (int) t;
1996
1997 dataProfiles[i].apn = strdupReadString(p);
1998 dataProfiles[i].protocol = strdupReadString(p);
1999 status = p.readInt32(&t);
2000 dataProfiles[i].authType = (int) t;
2001
2002 dataProfiles[i].user = strdupReadString(p);
2003 dataProfiles[i].password = strdupReadString(p);
2004
2005 status = p.readInt32(&t);
2006 dataProfiles[i].type = (int) t;
2007
2008 status = p.readInt32(&t);
2009 dataProfiles[i].maxConnsTime = (int) t;
2010 status = p.readInt32(&t);
2011 dataProfiles[i].maxConns = (int) t;
2012 status = p.readInt32(&t);
2013 dataProfiles[i].waitTime = (int) t;
2014
2015 status = p.readInt32(&t);
2016 dataProfiles[i].enabled = (int) t;
2017
2018 appendPrintBuf("%s [%d: profileId=%d, apn =%s, protocol =%s, authType =%d, \
2019 user =%s, password =%s, type =%d, maxConnsTime =%d, maxConns =%d, \
2020 waitTime =%d, enabled =%d]", printBuf, i, dataProfiles[i].profileId,
2021 dataProfiles[i].apn, dataProfiles[i].protocol, dataProfiles[i].authType,
2022 dataProfiles[i].user, dataProfiles[i].password, dataProfiles[i].type,
2023 dataProfiles[i].maxConnsTime, dataProfiles[i].maxConns,
2024 dataProfiles[i].waitTime, dataProfiles[i].enabled);
2025 }
2026 closeRequest;
2027 printRequest(pRI->token, pRI->pCI->requestNumber);
2028
2029 if (status != NO_ERROR) {
Sanket Padawe55227b52016-02-29 10:09:26 -08002030 free(dataProfiles);
2031 free(dataProfilePtrs);
Amit Mahajanc796e222014-08-13 16:54:01 +00002032 goto invalid;
2033 }
2034 CALL_ONREQUEST(pRI->pCI->requestNumber,
2035 dataProfilePtrs,
2036 num * sizeof(RIL_DataProfileInfo *),
2037 pRI, pRI->socket_id);
2038
2039#ifdef MEMSET_FREED
2040 memset(dataProfiles, 0, num * sizeof(RIL_DataProfileInfo));
2041 memset(dataProfilePtrs, 0, num * sizeof(RIL_DataProfileInfo *));
2042#endif
Sanket Padawe55227b52016-02-29 10:09:26 -08002043 free(dataProfiles);
2044 free(dataProfilePtrs);
Amit Mahajanc796e222014-08-13 16:54:01 +00002045 }
2046
2047 return;
2048
2049invalid:
2050 invalidCommandBlock(pRI);
2051 return;
2052}
2053
Wink Saville8b4e4f72014-10-17 15:01:45 -07002054static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI){
2055 RIL_RadioCapability rc;
2056 int32_t t;
2057 status_t status;
2058
2059 memset (&rc, 0, sizeof(RIL_RadioCapability));
2060
2061 status = p.readInt32(&t);
2062 rc.version = (int)t;
2063 if (status != NO_ERROR) {
2064 goto invalid;
2065 }
2066
2067 status = p.readInt32(&t);
2068 rc.session= (int)t;
2069 if (status != NO_ERROR) {
2070 goto invalid;
2071 }
2072
2073 status = p.readInt32(&t);
2074 rc.phase= (int)t;
2075 if (status != NO_ERROR) {
2076 goto invalid;
2077 }
2078
2079 status = p.readInt32(&t);
2080 rc.rat = (int)t;
2081 if (status != NO_ERROR) {
2082 goto invalid;
2083 }
2084
2085 status = readStringFromParcelInplace(p, rc.logicalModemUuid, sizeof(rc.logicalModemUuid));
2086 if (status != NO_ERROR) {
2087 goto invalid;
2088 }
2089
2090 status = p.readInt32(&t);
2091 rc.status = (int)t;
2092
2093 if (status != NO_ERROR) {
2094 goto invalid;
2095 }
2096
2097 startRequest;
2098 appendPrintBuf("%s [version:%d, session:%d, phase:%d, rat:%d, \
Chih-Wei Huang8593f262015-10-02 15:09:52 +08002099 logicalModemUuid:%s, status:%d", printBuf, rc.version, rc.session,
Legler Wu8caf06f2014-10-29 14:02:14 +08002100 rc.phase, rc.rat, rc.logicalModemUuid, rc.session);
Wink Saville8b4e4f72014-10-17 15:01:45 -07002101
2102 closeRequest;
2103 printRequest(pRI->token, pRI->pCI->requestNumber);
2104
2105 CALL_ONREQUEST(pRI->pCI->requestNumber,
2106 &rc,
2107 sizeof(RIL_RadioCapability),
2108 pRI, pRI->socket_id);
2109 return;
2110invalid:
2111 invalidCommandBlock(pRI);
2112 return;
2113}
2114
Meng Wangb4e34312016-05-12 14:54:36 -07002115/**
2116 * Callee expects const RIL_CarrierRestrictions *
2117 */
2118static void dispatchCarrierRestrictions(Parcel &p, RequestInfo *pRI) {
2119 RIL_CarrierRestrictions cr;
2120 RIL_Carrier * allowed_carriers = NULL;
2121 RIL_Carrier * excluded_carriers = NULL;
2122 int32_t t;
2123 status_t status;
2124
2125 memset(&cr, 0, sizeof(RIL_CarrierRestrictions));
2126
Robert Greenwalt27e99c52016-06-01 16:31:38 -07002127 if (s_callbacks.version < 14) {
Meng Wangb4e34312016-05-12 14:54:36 -07002128 RLOGE("Unsuppoted RIL version %d, min version expected %d",
Robert Greenwalt27e99c52016-06-01 16:31:38 -07002129 s_callbacks.version, 14);
Meng Wangdf8398c2016-05-25 12:59:15 -07002130 RIL_onRequestComplete(pRI, RIL_E_REQUEST_NOT_SUPPORTED, NULL, 0);
2131 return;
Meng Wangb4e34312016-05-12 14:54:36 -07002132 }
2133
2134 status = p.readInt32(&t);
2135 if (status != NO_ERROR) {
2136 goto invalid;
2137 }
2138 allowed_carriers = (RIL_Carrier *)calloc(t, sizeof(RIL_Carrier));
2139 if (allowed_carriers == NULL) {
2140 RLOGE("Memory allocation failed for request %s", requestToString(pRI->pCI->requestNumber));
2141 goto exit;
2142 }
2143 cr.len_allowed_carriers = t;
2144 cr.allowed_carriers = allowed_carriers;
2145
2146 status = p.readInt32(&t);
2147 if (status != NO_ERROR) {
2148 goto invalid;
2149 }
2150 excluded_carriers = (RIL_Carrier *)calloc(t, sizeof(RIL_Carrier));
2151 if (excluded_carriers == NULL) {
2152 RLOGE("Memory allocation failed for request %s", requestToString(pRI->pCI->requestNumber));
2153 goto exit;
2154 }
2155 cr.len_excluded_carriers = t;
2156 cr.excluded_carriers = excluded_carriers;
2157
Meng Wang5d703cb2016-06-08 11:53:25 -07002158 startRequest;
2159 appendPrintBuf("%s len_allowed_carriers:%d, len_excluded_carriers:%d,",
2160 printBuf, cr.len_allowed_carriers, cr.len_excluded_carriers);
2161
2162 appendPrintBuf("%s allowed_carriers:", printBuf);
Meng Wangb4e34312016-05-12 14:54:36 -07002163 for (int32_t i = 0; i < cr.len_allowed_carriers; i++) {
2164 RIL_Carrier *p_cr = allowed_carriers + i;
Meng Wang5d703cb2016-06-08 11:53:25 -07002165 p_cr->mcc = strdupReadString(p);
2166 p_cr->mnc = strdupReadString(p);
Meng Wangb4e34312016-05-12 14:54:36 -07002167 status = p.readInt32(&t);
2168 p_cr->match_type = static_cast<RIL_CarrierMatchType>(t);
2169 if (status != NO_ERROR) {
2170 goto invalid;
2171 }
Meng Wang5d703cb2016-06-08 11:53:25 -07002172 p_cr->match_data = strdupReadString(p);
2173 appendPrintBuf("%s [%d mcc:%s, mnc:%s, match_type:%d, match_data:%s],",
2174 printBuf, i, p_cr->mcc, p_cr->mnc, p_cr->match_type, p_cr->match_data);
Meng Wangb4e34312016-05-12 14:54:36 -07002175 }
2176
2177 for (int32_t i = 0; i < cr.len_excluded_carriers; i++) {
2178 RIL_Carrier *p_cr = excluded_carriers + i;
Meng Wang5d703cb2016-06-08 11:53:25 -07002179 p_cr->mcc = strdupReadString(p);
2180 p_cr->mnc = strdupReadString(p);
Meng Wangb4e34312016-05-12 14:54:36 -07002181 status = p.readInt32(&t);
2182 p_cr->match_type = static_cast<RIL_CarrierMatchType>(t);
2183 if (status != NO_ERROR) {
2184 goto invalid;
2185 }
Meng Wang5d703cb2016-06-08 11:53:25 -07002186 p_cr->match_data = strdupReadString(p);
2187 appendPrintBuf("%s [%d mcc:%s, mnc:%s, match_type:%d, match_data:%s],",
2188 printBuf, i, p_cr->mcc, p_cr->mnc, p_cr->match_type, p_cr->match_data);
Meng Wangb4e34312016-05-12 14:54:36 -07002189 }
2190
Meng Wangb4e34312016-05-12 14:54:36 -07002191 closeRequest;
2192 printRequest(pRI->token, pRI->pCI->requestNumber);
2193
2194 CALL_ONREQUEST(pRI->pCI->requestNumber,
2195 &cr,
2196 sizeof(RIL_CarrierRestrictions),
2197 pRI, pRI->socket_id);
2198
2199 goto exit;
2200
2201invalid:
2202 invalidCommandBlock(pRI);
Meng Wangdf8398c2016-05-25 12:59:15 -07002203 RIL_onRequestComplete(pRI, RIL_E_INVALID_ARGUMENTS, NULL, 0);
Meng Wangb4e34312016-05-12 14:54:36 -07002204exit:
2205 if (allowed_carriers != NULL) {
2206 free(allowed_carriers);
2207 }
2208 if (excluded_carriers != NULL) {
2209 free(excluded_carriers);
2210 }
2211 return;
2212}
2213
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002214static int
Wink Savillef4c4d362009-04-02 01:37:03 -07002215blockingWrite(int fd, const void *buffer, size_t len) {
Wink Saville7f856802009-06-09 10:23:37 -07002216 size_t writeOffset = 0;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002217 const uint8_t *toWrite;
2218
2219 toWrite = (const uint8_t *)buffer;
2220
2221 while (writeOffset < len) {
2222 ssize_t written;
2223 do {
2224 written = write (fd, toWrite + writeOffset,
2225 len - writeOffset);
Banavathu, Srinivas Naik38884902011-07-05 20:04:25 +05302226 } while (written < 0 && ((errno == EINTR) || (errno == EAGAIN)));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002227
2228 if (written >= 0) {
2229 writeOffset += written;
2230 } else { // written < 0
Wink Saville8eb2a122012-11-19 16:05:13 -08002231 RLOGE ("RIL Response: unexpected error on write errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002232 close(fd);
2233 return -1;
2234 }
2235 }
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07002236#if VDBG
Dheeraj Shetty27976c42014-07-02 21:27:57 +02002237 RLOGE("RIL Response bytes written:%d", writeOffset);
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07002238#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002239 return 0;
2240}
2241
2242static int
Etan Cohend3652192014-06-20 08:28:44 -07002243sendResponseRaw (const void *data, size_t dataSize, RIL_SOCKET_ID socket_id) {
2244 int fd = s_ril_param_socket.fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002245 int ret;
2246 uint32_t header;
Etan Cohend3652192014-06-20 08:28:44 -07002247 pthread_mutex_t * writeMutexHook = &s_writeMutex;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002248
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07002249#if VDBG
Etan Cohend3652192014-06-20 08:28:44 -07002250 RLOGE("Send Response to %s", rilSocketIdToString(socket_id));
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07002251#endif
Etan Cohend3652192014-06-20 08:28:44 -07002252
2253#if (SIM_COUNT >= 2)
2254 if (socket_id == RIL_SOCKET_2) {
2255 fd = s_ril_param_socket2.fdCommand;
2256 writeMutexHook = &s_writeMutex_socket2;
2257 }
2258#if (SIM_COUNT >= 3)
2259 else if (socket_id == RIL_SOCKET_3) {
2260 fd = s_ril_param_socket3.fdCommand;
2261 writeMutexHook = &s_writeMutex_socket3;
2262 }
2263#endif
2264#if (SIM_COUNT >= 4)
2265 else if (socket_id == RIL_SOCKET_4) {
2266 fd = s_ril_param_socket4.fdCommand;
2267 writeMutexHook = &s_writeMutex_socket4;
2268 }
2269#endif
2270#endif
2271 if (fd < 0) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002272 return -1;
2273 }
2274
2275 if (dataSize > MAX_COMMAND_BYTES) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002276 RLOGE("RIL: packet larger than %u (%u)",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002277 MAX_COMMAND_BYTES, (unsigned int )dataSize);
2278
2279 return -1;
2280 }
Wink Saville7f856802009-06-09 10:23:37 -07002281
Etan Cohend3652192014-06-20 08:28:44 -07002282 pthread_mutex_lock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002283
2284 header = htonl(dataSize);
2285
2286 ret = blockingWrite(fd, (void *)&header, sizeof(header));
2287
2288 if (ret < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002289 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002290 return ret;
2291 }
2292
Kennyee1fadc2009-08-13 00:45:53 +08002293 ret = blockingWrite(fd, data, dataSize);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002294
2295 if (ret < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002296 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002297 return ret;
2298 }
2299
Etan Cohend3652192014-06-20 08:28:44 -07002300 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002301
2302 return 0;
2303}
2304
2305static int
Etan Cohend3652192014-06-20 08:28:44 -07002306sendResponse (Parcel &p, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002307 printResponse;
Etan Cohend3652192014-06-20 08:28:44 -07002308 return sendResponseRaw(p.data(), p.dataSize(), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002309}
2310
Mohamad Ayyash74f7e662014-04-18 11:43:28 -07002311/** response is an int* pointing to an array of ints */
Wink Saville7f856802009-06-09 10:23:37 -07002312
2313static int
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002314responseInts(Parcel &p, int slotId, int requestNumber, int responseType, int token, RIL_Errno e,
2315 void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002316 int numInts;
2317
2318 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002319 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002320 return RIL_ERRNO_INVALID_RESPONSE;
2321 }
2322 if (responselen % sizeof(int) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002323 RLOGE("responseInts: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002324 (int)responselen, (int)sizeof(int));
2325 return RIL_ERRNO_INVALID_RESPONSE;
2326 }
2327
2328 int *p_int = (int *) response;
2329
Mohamad Ayyash74f7e662014-04-18 11:43:28 -07002330 numInts = responselen / sizeof(int);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002331 p.writeInt32 (numInts);
2332
2333 /* each int*/
2334 startResponse;
2335 for (int i = 0 ; i < numInts ; i++) {
2336 appendPrintBuf("%s%d,", printBuf, p_int[i]);
2337 p.writeInt32(p_int[i]);
2338 }
2339 removeLastChar;
2340 closeResponse;
2341
2342 return 0;
2343}
2344
Chao Liu548a81e2015-05-14 16:13:46 -07002345// Response is an int or RIL_LastCallFailCauseInfo.
2346// Currently, only Shamu plans to use RIL_LastCallFailCauseInfo.
2347// TODO(yjl): Let all implementations use RIL_LastCallFailCauseInfo.
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002348static int responseFailCause(Parcel &p, int slotId, int requestNumber, int responseType, int token,
2349 RIL_Errno e, void *response, size_t responselen) {
Chao Liu548a81e2015-05-14 16:13:46 -07002350 if (response == NULL && responselen != 0) {
2351 RLOGE("invalid response: NULL");
2352 return RIL_ERRNO_INVALID_RESPONSE;
2353 }
2354
2355 if (responselen == sizeof(int)) {
Sungmin Choia408c252015-07-01 16:22:46 +09002356 startResponse;
2357 int *p_int = (int *) response;
2358 appendPrintBuf("%s%d,", printBuf, p_int[0]);
2359 p.writeInt32(p_int[0]);
2360 removeLastChar;
2361 closeResponse;
Chao Liu548a81e2015-05-14 16:13:46 -07002362 } else if (responselen == sizeof(RIL_LastCallFailCauseInfo)) {
2363 startResponse;
2364 RIL_LastCallFailCauseInfo *p_fail_cause_info = (RIL_LastCallFailCauseInfo *) response;
2365 appendPrintBuf("%s[cause_code=%d,vendor_cause=%s]", printBuf, p_fail_cause_info->cause_code,
2366 p_fail_cause_info->vendor_cause);
2367 p.writeInt32(p_fail_cause_info->cause_code);
2368 writeStringToParcel(p, p_fail_cause_info->vendor_cause);
2369 removeLastChar;
2370 closeResponse;
2371 } else {
2372 RLOGE("responseFailCause: invalid response length %d expected an int or "
2373 "RIL_LastCallFailCauseInfo", (int)responselen);
2374 return RIL_ERRNO_INVALID_RESPONSE;
2375 }
2376
2377 return 0;
2378}
2379
Wink Saville43808972011-01-13 17:39:51 -08002380/** response is a char **, pointing to an array of char *'s
2381 The parcel will begin with the version */
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002382static int responseStringsWithVersion(int version, Parcel &p, int slotId, int requestNumber,
2383 int responseType, int token, RIL_Errno e, void *response, size_t responselen) {
Wink Saville43808972011-01-13 17:39:51 -08002384 p.writeInt32(version);
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002385 return responseStrings(p, slotId, requestNumber, responseType, token, e, response, responselen);
Wink Saville43808972011-01-13 17:39:51 -08002386}
2387
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002388/** response is a char **, pointing to an array of char *'s */
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002389static int responseStrings(Parcel &p, int slotId, int requestNumber, int responseType, int token,
2390 RIL_Errno e, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002391 int numStrings;
Wink Saville7f856802009-06-09 10:23:37 -07002392
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002393 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002394 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002395 return RIL_ERRNO_INVALID_RESPONSE;
2396 }
2397 if (responselen % sizeof(char *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002398 RLOGE("responseStrings: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002399 (int)responselen, (int)sizeof(char *));
2400 return RIL_ERRNO_INVALID_RESPONSE;
2401 }
2402
2403 if (response == NULL) {
2404 p.writeInt32 (0);
2405 } else {
2406 char **p_cur = (char **) response;
2407
2408 numStrings = responselen / sizeof(char *);
2409 p.writeInt32 (numStrings);
2410
2411 /* each string*/
2412 startResponse;
2413 for (int i = 0 ; i < numStrings ; i++) {
2414 appendPrintBuf("%s%s,", printBuf, (char*)p_cur[i]);
2415 writeStringToParcel (p, p_cur[i]);
2416 }
2417 removeLastChar;
2418 closeResponse;
2419 }
2420 return 0;
2421}
2422
2423
2424/**
Wink Saville7f856802009-06-09 10:23:37 -07002425 * NULL strings are accepted
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002426 * FIXME currently ignores responselen
2427 */
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002428static int responseString(Parcel &p, int slotId, int requestNumber, int responseType, int token,
2429 RIL_Errno e, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002430 /* one string only */
2431 startResponse;
2432 appendPrintBuf("%s%s", printBuf, (char*)response);
2433 closeResponse;
2434
2435 writeStringToParcel(p, (const char *)response);
2436
2437 return 0;
2438}
2439
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002440static int responseVoid(Parcel &p, int slotId, int requestNumber, int responseType, int token,
2441 RIL_Errno e, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002442 startResponse;
2443 removeLastChar;
2444 return 0;
2445}
2446
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002447static int responseCallList(Parcel &p, int slotId, int requestNumber, int responseType, int token,
2448 RIL_Errno e, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002449 int num;
2450
2451 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002452 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002453 return RIL_ERRNO_INVALID_RESPONSE;
2454 }
2455
2456 if (responselen % sizeof (RIL_Call *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002457 RLOGE("responseCallList: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002458 (int)responselen, (int)sizeof (RIL_Call *));
2459 return RIL_ERRNO_INVALID_RESPONSE;
2460 }
2461
2462 startResponse;
2463 /* number of call info's */
2464 num = responselen / sizeof(RIL_Call *);
2465 p.writeInt32(num);
2466
2467 for (int i = 0 ; i < num ; i++) {
2468 RIL_Call *p_cur = ((RIL_Call **) response)[i];
2469 /* each call info */
2470 p.writeInt32(p_cur->state);
2471 p.writeInt32(p_cur->index);
2472 p.writeInt32(p_cur->toa);
2473 p.writeInt32(p_cur->isMpty);
2474 p.writeInt32(p_cur->isMT);
2475 p.writeInt32(p_cur->als);
2476 p.writeInt32(p_cur->isVoice);
Wink Saville1b5fd232009-04-22 14:50:00 -07002477 p.writeInt32(p_cur->isVoicePrivacy);
2478 writeStringToParcel(p, p_cur->number);
John Wangff368742009-03-24 17:56:29 -07002479 p.writeInt32(p_cur->numberPresentation);
Wink Saville1b5fd232009-04-22 14:50:00 -07002480 writeStringToParcel(p, p_cur->name);
2481 p.writeInt32(p_cur->namePresentation);
Wink Saville3a4840b2010-04-07 13:29:58 -07002482 // Remove when partners upgrade to version 3
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002483 if (s_callbacks.version < 3 || p_cur->uusInfo == NULL || p_cur->uusInfo->uusData == NULL) {
Wink Saville74fa3882009-12-22 15:35:41 -08002484 p.writeInt32(0); /* UUS Information is absent */
2485 } else {
2486 RIL_UUS_Info *uusInfo = p_cur->uusInfo;
2487 p.writeInt32(1); /* UUS Information is present */
2488 p.writeInt32(uusInfo->uusType);
2489 p.writeInt32(uusInfo->uusDcs);
2490 p.writeInt32(uusInfo->uusLength);
2491 p.write(uusInfo->uusData, uusInfo->uusLength);
2492 }
Wink Saville3d54e742009-05-18 18:00:44 -07002493 appendPrintBuf("%s[id=%d,%s,toa=%d,",
John Wangff368742009-03-24 17:56:29 -07002494 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002495 p_cur->index,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002496 callStateToString(p_cur->state),
Wink Saville3d54e742009-05-18 18:00:44 -07002497 p_cur->toa);
2498 appendPrintBuf("%s%s,%s,als=%d,%s,%s,",
2499 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002500 (p_cur->isMpty)?"conf":"norm",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002501 (p_cur->isMT)?"mt":"mo",
2502 p_cur->als,
2503 (p_cur->isVoice)?"voc":"nonvoc",
Wink Saville3d54e742009-05-18 18:00:44 -07002504 (p_cur->isVoicePrivacy)?"evp":"noevp");
2505 appendPrintBuf("%s%s,cli=%d,name='%s',%d]",
2506 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002507 p_cur->number,
2508 p_cur->numberPresentation,
2509 p_cur->name,
2510 p_cur->namePresentation);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002511 }
2512 removeLastChar;
2513 closeResponse;
2514
2515 return 0;
2516}
2517
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002518static int responseSMS(Parcel &p, int slotId, int requestNumber, int responseType, int token,
2519 RIL_Errno e, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002520 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002521 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002522 return RIL_ERRNO_INVALID_RESPONSE;
2523 }
2524
2525 if (responselen != sizeof (RIL_SMS_Response) ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002526 RLOGE("invalid response length %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002527 (int)responselen, (int)sizeof (RIL_SMS_Response));
2528 return RIL_ERRNO_INVALID_RESPONSE;
2529 }
2530
2531 RIL_SMS_Response *p_cur = (RIL_SMS_Response *) response;
2532
2533 p.writeInt32(p_cur->messageRef);
2534 writeStringToParcel(p, p_cur->ackPDU);
Jaikumar Ganesh920c78f2009-06-04 10:53:15 -07002535 p.writeInt32(p_cur->errorCode);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002536
2537 startResponse;
Jaikumar Ganesh920c78f2009-06-04 10:53:15 -07002538 appendPrintBuf("%s%d,%s,%d", printBuf, p_cur->messageRef,
2539 (char*)p_cur->ackPDU, p_cur->errorCode);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002540 closeResponse;
2541
2542 return 0;
2543}
2544
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002545static int responseDataCallListV4(Parcel &p, int slotId, int requestNumber, int responseType,
2546 int token, RIL_Errno e, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002547 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002548 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002549 return RIL_ERRNO_INVALID_RESPONSE;
2550 }
2551
Wink Savillec0114b32011-02-18 10:14:07 -08002552 if (responselen % sizeof(RIL_Data_Call_Response_v4) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002553 RLOGE("responseDataCallListV4: invalid response length %d expected multiple of %d",
Wink Savillec0114b32011-02-18 10:14:07 -08002554 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v4));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002555 return RIL_ERRNO_INVALID_RESPONSE;
2556 }
2557
Amit Mahajan52500162014-07-29 17:36:48 -07002558 // Write version
2559 p.writeInt32(4);
2560
Wink Savillec0114b32011-02-18 10:14:07 -08002561 int num = responselen / sizeof(RIL_Data_Call_Response_v4);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002562 p.writeInt32(num);
2563
Wink Savillec0114b32011-02-18 10:14:07 -08002564 RIL_Data_Call_Response_v4 *p_cur = (RIL_Data_Call_Response_v4 *) response;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002565 startResponse;
2566 int i;
2567 for (i = 0; i < num; i++) {
2568 p.writeInt32(p_cur[i].cid);
2569 p.writeInt32(p_cur[i].active);
2570 writeStringToParcel(p, p_cur[i].type);
Wink Savillec0114b32011-02-18 10:14:07 -08002571 // apn is not used, so don't send.
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002572 writeStringToParcel(p, p_cur[i].address);
Wink Savillec0114b32011-02-18 10:14:07 -08002573 appendPrintBuf("%s[cid=%d,%s,%s,%s],", printBuf,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002574 p_cur[i].cid,
2575 (p_cur[i].active==0)?"down":"up",
2576 (char*)p_cur[i].type,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002577 (char*)p_cur[i].address);
2578 }
2579 removeLastChar;
2580 closeResponse;
2581
2582 return 0;
2583}
2584
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002585static int responseDataCallListV6(Parcel &p, int slotId, int requestNumber, int responseType,
2586 int token, RIL_Errno e, void *response, size_t responselen) {
Amit Mahajan52500162014-07-29 17:36:48 -07002587 if (response == NULL && responselen != 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002588 RLOGE("invalid response: NULL");
2589 return RIL_ERRNO_INVALID_RESPONSE;
2590 }
2591
2592 if (responselen % sizeof(RIL_Data_Call_Response_v6) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002593 RLOGE("responseDataCallListV6: invalid response length %d expected multiple of %d",
Etan Cohend3652192014-06-20 08:28:44 -07002594 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v6));
2595 return RIL_ERRNO_INVALID_RESPONSE;
2596 }
2597
Amit Mahajan52500162014-07-29 17:36:48 -07002598 // Write version
2599 p.writeInt32(6);
2600
Etan Cohend3652192014-06-20 08:28:44 -07002601 int num = responselen / sizeof(RIL_Data_Call_Response_v6);
2602 p.writeInt32(num);
2603
2604 RIL_Data_Call_Response_v6 *p_cur = (RIL_Data_Call_Response_v6 *) response;
2605 startResponse;
2606 int i;
2607 for (i = 0; i < num; i++) {
2608 p.writeInt32((int)p_cur[i].status);
2609 p.writeInt32(p_cur[i].suggestedRetryTime);
2610 p.writeInt32(p_cur[i].cid);
2611 p.writeInt32(p_cur[i].active);
2612 writeStringToParcel(p, p_cur[i].type);
2613 writeStringToParcel(p, p_cur[i].ifname);
2614 writeStringToParcel(p, p_cur[i].addresses);
2615 writeStringToParcel(p, p_cur[i].dnses);
2616 writeStringToParcel(p, p_cur[i].gateways);
2617 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s],", printBuf,
2618 p_cur[i].status,
2619 p_cur[i].suggestedRetryTime,
2620 p_cur[i].cid,
2621 (p_cur[i].active==0)?"down":"up",
2622 (char*)p_cur[i].type,
2623 (char*)p_cur[i].ifname,
2624 (char*)p_cur[i].addresses,
2625 (char*)p_cur[i].dnses,
2626 (char*)p_cur[i].gateways);
2627 }
2628 removeLastChar;
2629 closeResponse;
2630
2631 return 0;
2632}
2633
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002634static int responseDataCallListV9(Parcel &p, int slotId, int requestNumber, int responseType,
2635 int token, RIL_Errno e, void *response, size_t responselen) {
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002636 if (response == NULL && responselen != 0) {
2637 RLOGE("invalid response: NULL");
2638 return RIL_ERRNO_INVALID_RESPONSE;
2639 }
2640
2641 if (responselen % sizeof(RIL_Data_Call_Response_v9) != 0) {
2642 RLOGE("responseDataCallListV9: invalid response length %d expected multiple of %d",
2643 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v9));
2644 return RIL_ERRNO_INVALID_RESPONSE;
2645 }
2646
2647 // Write version
2648 p.writeInt32(10);
2649
2650 int num = responselen / sizeof(RIL_Data_Call_Response_v9);
2651 p.writeInt32(num);
2652
2653 RIL_Data_Call_Response_v9 *p_cur = (RIL_Data_Call_Response_v9 *) response;
2654 startResponse;
2655 int i;
2656 for (i = 0; i < num; i++) {
2657 p.writeInt32((int)p_cur[i].status);
2658 p.writeInt32(p_cur[i].suggestedRetryTime);
2659 p.writeInt32(p_cur[i].cid);
2660 p.writeInt32(p_cur[i].active);
2661 writeStringToParcel(p, p_cur[i].type);
2662 writeStringToParcel(p, p_cur[i].ifname);
2663 writeStringToParcel(p, p_cur[i].addresses);
2664 writeStringToParcel(p, p_cur[i].dnses);
2665 writeStringToParcel(p, p_cur[i].gateways);
2666 writeStringToParcel(p, p_cur[i].pcscf);
2667 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s],", printBuf,
2668 p_cur[i].status,
2669 p_cur[i].suggestedRetryTime,
2670 p_cur[i].cid,
2671 (p_cur[i].active==0)?"down":"up",
2672 (char*)p_cur[i].type,
2673 (char*)p_cur[i].ifname,
2674 (char*)p_cur[i].addresses,
2675 (char*)p_cur[i].dnses,
2676 (char*)p_cur[i].gateways,
2677 (char*)p_cur[i].pcscf);
2678 }
2679 removeLastChar;
2680 closeResponse;
2681
2682 return 0;
2683}
2684
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002685static int responseDataCallListV11(Parcel &p, int slotId, int requestNumber, int responseType,
2686 int token, RIL_Errno e, void *response, size_t responselen) {
Sanket Padawe4c05f352016-01-26 16:19:00 -08002687 if (response == NULL && responselen != 0) {
2688 RLOGE("invalid response: NULL");
2689 return RIL_ERRNO_INVALID_RESPONSE;
2690 }
2691
2692 if (responselen % sizeof(RIL_Data_Call_Response_v11) != 0) {
2693 RLOGE("invalid response length %d expected multiple of %d",
2694 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v11));
2695 return RIL_ERRNO_INVALID_RESPONSE;
2696 }
2697
2698 // Write version
2699 p.writeInt32(11);
2700
2701 int num = responselen / sizeof(RIL_Data_Call_Response_v11);
2702 p.writeInt32(num);
2703
2704 RIL_Data_Call_Response_v11 *p_cur = (RIL_Data_Call_Response_v11 *) response;
2705 startResponse;
2706 int i;
2707 for (i = 0; i < num; i++) {
2708 p.writeInt32((int)p_cur[i].status);
2709 p.writeInt32(p_cur[i].suggestedRetryTime);
2710 p.writeInt32(p_cur[i].cid);
2711 p.writeInt32(p_cur[i].active);
2712 writeStringToParcel(p, p_cur[i].type);
2713 writeStringToParcel(p, p_cur[i].ifname);
2714 writeStringToParcel(p, p_cur[i].addresses);
2715 writeStringToParcel(p, p_cur[i].dnses);
2716 writeStringToParcel(p, p_cur[i].gateways);
2717 writeStringToParcel(p, p_cur[i].pcscf);
2718 p.writeInt32(p_cur[i].mtu);
2719 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s,mtu=%d],", printBuf,
2720 p_cur[i].status,
2721 p_cur[i].suggestedRetryTime,
2722 p_cur[i].cid,
2723 (p_cur[i].active==0)?"down":"up",
2724 (char*)p_cur[i].type,
2725 (char*)p_cur[i].ifname,
2726 (char*)p_cur[i].addresses,
2727 (char*)p_cur[i].dnses,
2728 (char*)p_cur[i].gateways,
2729 (char*)p_cur[i].pcscf,
2730 p_cur[i].mtu);
2731 }
2732 removeLastChar;
2733 closeResponse;
2734
2735 return 0;
2736}
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002737
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002738static int responseDataCallList(Parcel &p, int slotId, int requestNumber, int responseType,
2739 int token, RIL_Errno e, void *response, size_t responselen) {
Sanket Padawe4c05f352016-01-26 16:19:00 -08002740 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
2741 if (s_callbacks.version < 5) {
2742 RLOGD("responseDataCallList: v4");
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002743 return responseDataCallListV4(p, slotId, requestNumber, responseType, token, e,
2744 response, responselen);
Sanket Padawe4c05f352016-01-26 16:19:00 -08002745 } else if (responselen % sizeof(RIL_Data_Call_Response_v6) == 0) {
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002746 return responseDataCallListV6(p, slotId, requestNumber, responseType, token, e,
2747 response, responselen);
Sanket Padawe4c05f352016-01-26 16:19:00 -08002748 } else if (responselen % sizeof(RIL_Data_Call_Response_v9) == 0) {
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002749 return responseDataCallListV9(p, slotId, requestNumber, responseType, token, e,
2750 response, responselen);
Sanket Padawe4c05f352016-01-26 16:19:00 -08002751 } else {
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002752 return responseDataCallListV11(p, slotId, requestNumber, responseType, token, e,
2753 response, responselen);
Wink Saville43808972011-01-13 17:39:51 -08002754 }
Sanket Padawe00909612016-01-26 18:44:01 -08002755 } else { // RIL version >= 13
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002756 if (responselen % sizeof(RIL_Data_Call_Response_v11) != 0) {
Sanket Padawe4c05f352016-01-26 16:19:00 -08002757 RLOGE("Data structure expected is RIL_Data_Call_Response_v11");
2758 if (!isDebuggable()) {
2759 return RIL_ERRNO_INVALID_RESPONSE;
2760 } else {
2761 assert(0);
2762 }
Wink Saville43808972011-01-13 17:39:51 -08002763 }
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002764 return responseDataCallListV11(p, slotId, requestNumber, responseType, token, e, response,
2765 responselen);
Wink Saville43808972011-01-13 17:39:51 -08002766 }
Wink Saville43808972011-01-13 17:39:51 -08002767}
2768
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002769static int responseSetupDataCall(Parcel &p, int slotId, int requestNumber, int responseType,
2770 int token, RIL_Errno e, void *response, size_t responselen) {
Wink Saville43808972011-01-13 17:39:51 -08002771 if (s_callbacks.version < 5) {
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002772 return responseStringsWithVersion(s_callbacks.version, p, slotId, requestNumber,
2773 responseType, token, e, response, responselen);
Wink Saville43808972011-01-13 17:39:51 -08002774 } else {
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002775 return responseDataCallList(p, slotId, requestNumber, responseType, token, e, response,
2776 responselen);
Wink Saville43808972011-01-13 17:39:51 -08002777 }
2778}
2779
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002780static int responseRaw(Parcel &p, int slotId, int requestNumber, int responseType, int token,
2781 RIL_Errno e, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002782 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002783 RLOGE("invalid response: NULL with responselen != 0");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002784 return RIL_ERRNO_INVALID_RESPONSE;
2785 }
2786
2787 // The java code reads -1 size as null byte array
2788 if (response == NULL) {
Wink Saville7f856802009-06-09 10:23:37 -07002789 p.writeInt32(-1);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002790 } else {
2791 p.writeInt32(responselen);
2792 p.write(response, responselen);
2793 }
2794
2795 return 0;
2796}
2797
2798
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002799static int responseSIM_IO(Parcel &p, int slotId, int requestNumber, int responseType, int token,
2800 RIL_Errno e, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002801 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002802 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002803 return RIL_ERRNO_INVALID_RESPONSE;
2804 }
2805
2806 if (responselen != sizeof (RIL_SIM_IO_Response) ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002807 RLOGE("invalid response length was %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002808 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
2809 return RIL_ERRNO_INVALID_RESPONSE;
2810 }
2811
2812 RIL_SIM_IO_Response *p_cur = (RIL_SIM_IO_Response *) response;
2813 p.writeInt32(p_cur->sw1);
2814 p.writeInt32(p_cur->sw2);
2815 writeStringToParcel(p, p_cur->simResponse);
2816
2817 startResponse;
2818 appendPrintBuf("%ssw1=0x%X,sw2=0x%X,%s", printBuf, p_cur->sw1, p_cur->sw2,
2819 (char*)p_cur->simResponse);
2820 closeResponse;
2821
2822
2823 return 0;
2824}
2825
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002826static int responseCallForwards(Parcel &p, int slotId, int requestNumber, int responseType,
2827 int token, RIL_Errno e, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002828 int num;
Wink Saville7f856802009-06-09 10:23:37 -07002829
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002830 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002831 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002832 return RIL_ERRNO_INVALID_RESPONSE;
2833 }
2834
2835 if (responselen % sizeof(RIL_CallForwardInfo *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002836 RLOGE("responseCallForwards: invalid response length %d expected multiple of %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002837 (int)responselen, (int)sizeof(RIL_CallForwardInfo *));
2838 return RIL_ERRNO_INVALID_RESPONSE;
2839 }
2840
2841 /* number of call info's */
2842 num = responselen / sizeof(RIL_CallForwardInfo *);
2843 p.writeInt32(num);
2844
2845 startResponse;
2846 for (int i = 0 ; i < num ; i++) {
2847 RIL_CallForwardInfo *p_cur = ((RIL_CallForwardInfo **) response)[i];
2848
2849 p.writeInt32(p_cur->status);
2850 p.writeInt32(p_cur->reason);
2851 p.writeInt32(p_cur->serviceClass);
2852 p.writeInt32(p_cur->toa);
2853 writeStringToParcel(p, p_cur->number);
2854 p.writeInt32(p_cur->timeSeconds);
2855 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
2856 (p_cur->status==1)?"enable":"disable",
2857 p_cur->reason, p_cur->serviceClass, p_cur->toa,
2858 (char*)p_cur->number,
2859 p_cur->timeSeconds);
2860 }
2861 removeLastChar;
2862 closeResponse;
Wink Saville7f856802009-06-09 10:23:37 -07002863
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002864 return 0;
2865}
2866
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002867static int responseSsn(Parcel &p, int slotId, int requestNumber, int responseType, int token,
2868 RIL_Errno e, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002869 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002870 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002871 return RIL_ERRNO_INVALID_RESPONSE;
2872 }
2873
2874 if (responselen != sizeof(RIL_SuppSvcNotification)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002875 RLOGE("invalid response length was %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002876 (int)responselen, (int)sizeof (RIL_SuppSvcNotification));
2877 return RIL_ERRNO_INVALID_RESPONSE;
2878 }
2879
2880 RIL_SuppSvcNotification *p_cur = (RIL_SuppSvcNotification *) response;
2881 p.writeInt32(p_cur->notificationType);
2882 p.writeInt32(p_cur->code);
2883 p.writeInt32(p_cur->index);
2884 p.writeInt32(p_cur->type);
2885 writeStringToParcel(p, p_cur->number);
2886
2887 startResponse;
2888 appendPrintBuf("%s%s,code=%d,id=%d,type=%d,%s", printBuf,
2889 (p_cur->notificationType==0)?"mo":"mt",
2890 p_cur->code, p_cur->index, p_cur->type,
2891 (char*)p_cur->number);
2892 closeResponse;
2893
2894 return 0;
2895}
2896
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002897static int responseCellList(Parcel &p, int slotId, int requestNumber, int responseType, int token,
2898 RIL_Errno e, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002899 int num;
2900
2901 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002902 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002903 return RIL_ERRNO_INVALID_RESPONSE;
2904 }
2905
2906 if (responselen % sizeof (RIL_NeighboringCell *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002907 RLOGE("responseCellList: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002908 (int)responselen, (int)sizeof (RIL_NeighboringCell *));
2909 return RIL_ERRNO_INVALID_RESPONSE;
2910 }
2911
2912 startResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002913 /* number of records */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002914 num = responselen / sizeof(RIL_NeighboringCell *);
2915 p.writeInt32(num);
2916
2917 for (int i = 0 ; i < num ; i++) {
2918 RIL_NeighboringCell *p_cur = ((RIL_NeighboringCell **) response)[i];
2919
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002920 p.writeInt32(p_cur->rssi);
2921 writeStringToParcel (p, p_cur->cid);
2922
2923 appendPrintBuf("%s[cid=%s,rssi=%d],", printBuf,
2924 p_cur->cid, p_cur->rssi);
2925 }
2926 removeLastChar;
2927 closeResponse;
2928
2929 return 0;
2930}
2931
Wink Saville3d54e742009-05-18 18:00:44 -07002932/**
2933 * Marshall the signalInfoRecord into the parcel if it exists.
2934 */
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002935static void marshallSignalInfoRecord(Parcel &p, RIL_CDMA_SignalInfoRecord &p_signalInfoRecord) {
Wink Saville3d54e742009-05-18 18:00:44 -07002936 p.writeInt32(p_signalInfoRecord.isPresent);
2937 p.writeInt32(p_signalInfoRecord.signalType);
2938 p.writeInt32(p_signalInfoRecord.alertPitch);
2939 p.writeInt32(p_signalInfoRecord.signal);
2940}
2941
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002942static int responseCdmaInformationRecords(Parcel &p, int slotId, int requestNumber,
2943 int responseType, int token, RIL_Errno e, void *response, size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07002944 int num;
Wink Savillea592eeb2009-05-22 13:26:36 -07002945 char* string8 = NULL;
2946 int buffer_lenght;
2947 RIL_CDMA_InformationRecord *infoRec;
Wink Saville3d54e742009-05-18 18:00:44 -07002948
2949 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002950 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002951 return RIL_ERRNO_INVALID_RESPONSE;
2952 }
2953
Wink Savillea592eeb2009-05-22 13:26:36 -07002954 if (responselen != sizeof (RIL_CDMA_InformationRecords)) {
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002955 RLOGE("responseCdmaInformationRecords: invalid response length %d expected multiple of \
2956 %d\n", (int)responselen, (int)sizeof (RIL_CDMA_InformationRecords *));
Wink Saville3d54e742009-05-18 18:00:44 -07002957 return RIL_ERRNO_INVALID_RESPONSE;
2958 }
2959
Wink Savillea592eeb2009-05-22 13:26:36 -07002960 RIL_CDMA_InformationRecords *p_cur =
2961 (RIL_CDMA_InformationRecords *) response;
2962 num = MIN(p_cur->numberOfInfoRecs, RIL_CDMA_MAX_NUMBER_OF_INFO_RECS);
Wink Saville3d54e742009-05-18 18:00:44 -07002963
2964 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07002965 p.writeInt32(num);
Wink Saville3d54e742009-05-18 18:00:44 -07002966
Wink Savillea592eeb2009-05-22 13:26:36 -07002967 for (int i = 0 ; i < num ; i++) {
2968 infoRec = &p_cur->infoRec[i];
2969 p.writeInt32(infoRec->name);
2970 switch (infoRec->name) {
Wink Saville3d54e742009-05-18 18:00:44 -07002971 case RIL_CDMA_DISPLAY_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002972 case RIL_CDMA_EXTENDED_DISPLAY_INFO_REC:
2973 if (infoRec->rec.display.alpha_len >
2974 CDMA_ALPHA_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002975 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002976 expected not more than %d\n",
2977 (int)infoRec->rec.display.alpha_len,
2978 CDMA_ALPHA_INFO_BUFFER_LENGTH);
2979 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002980 }
Sanket Padawe0cfc5532016-03-07 17:12:19 -08002981 string8 = (char*) calloc(infoRec->rec.display.alpha_len + 1, sizeof(char));
Sanket Padawe55227b52016-02-29 10:09:26 -08002982 if (string8 == NULL) {
2983 RLOGE("Memory allocation failed for responseCdmaInformationRecords");
2984 closeRequest;
2985 return RIL_ERRNO_NO_MEMORY;
2986 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002987 for (int i = 0 ; i < infoRec->rec.display.alpha_len ; i++) {
2988 string8[i] = infoRec->rec.display.alpha_buf[i];
2989 }
Wink Saville43808972011-01-13 17:39:51 -08002990 string8[(int)infoRec->rec.display.alpha_len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002991 writeStringToParcel(p, (const char*)string8);
2992 free(string8);
2993 string8 = NULL;
Wink Saville3d54e742009-05-18 18:00:44 -07002994 break;
2995 case RIL_CDMA_CALLED_PARTY_NUMBER_INFO_REC:
Wink Saville3d54e742009-05-18 18:00:44 -07002996 case RIL_CDMA_CALLING_PARTY_NUMBER_INFO_REC:
Wink Saville3d54e742009-05-18 18:00:44 -07002997 case RIL_CDMA_CONNECTED_NUMBER_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002998 if (infoRec->rec.number.len > CDMA_NUMBER_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002999 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07003000 expected not more than %d\n",
3001 (int)infoRec->rec.number.len,
3002 CDMA_NUMBER_INFO_BUFFER_LENGTH);
3003 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07003004 }
Sanket Padawe0cfc5532016-03-07 17:12:19 -08003005 string8 = (char*) calloc(infoRec->rec.number.len + 1, sizeof(char));
Sanket Padawe55227b52016-02-29 10:09:26 -08003006 if (string8 == NULL) {
3007 RLOGE("Memory allocation failed for responseCdmaInformationRecords");
3008 closeRequest;
3009 return RIL_ERRNO_NO_MEMORY;
3010 }
Wink Savillea592eeb2009-05-22 13:26:36 -07003011 for (int i = 0 ; i < infoRec->rec.number.len; i++) {
3012 string8[i] = infoRec->rec.number.buf[i];
3013 }
Wink Saville43808972011-01-13 17:39:51 -08003014 string8[(int)infoRec->rec.number.len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07003015 writeStringToParcel(p, (const char*)string8);
3016 free(string8);
3017 string8 = NULL;
3018 p.writeInt32(infoRec->rec.number.number_type);
3019 p.writeInt32(infoRec->rec.number.number_plan);
3020 p.writeInt32(infoRec->rec.number.pi);
3021 p.writeInt32(infoRec->rec.number.si);
Wink Saville3d54e742009-05-18 18:00:44 -07003022 break;
3023 case RIL_CDMA_SIGNAL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07003024 p.writeInt32(infoRec->rec.signal.isPresent);
3025 p.writeInt32(infoRec->rec.signal.signalType);
3026 p.writeInt32(infoRec->rec.signal.alertPitch);
3027 p.writeInt32(infoRec->rec.signal.signal);
3028
3029 appendPrintBuf("%sisPresent=%X, signalType=%X, \
3030 alertPitch=%X, signal=%X, ",
3031 printBuf, (int)infoRec->rec.signal.isPresent,
3032 (int)infoRec->rec.signal.signalType,
3033 (int)infoRec->rec.signal.alertPitch,
3034 (int)infoRec->rec.signal.signal);
3035 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07003036 break;
3037 case RIL_CDMA_REDIRECTING_NUMBER_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07003038 if (infoRec->rec.redir.redirectingNumber.len >
3039 CDMA_NUMBER_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003040 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07003041 expected not more than %d\n",
3042 (int)infoRec->rec.redir.redirectingNumber.len,
3043 CDMA_NUMBER_INFO_BUFFER_LENGTH);
3044 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07003045 }
Sanket Padawe0cfc5532016-03-07 17:12:19 -08003046 string8 = (char*) calloc(infoRec->rec.redir.redirectingNumber.len + 1,
3047 sizeof(char));
Sanket Padawe55227b52016-02-29 10:09:26 -08003048 if (string8 == NULL) {
3049 RLOGE("Memory allocation failed for responseCdmaInformationRecords");
3050 closeRequest;
3051 return RIL_ERRNO_NO_MEMORY;
3052 }
Wink Savillea592eeb2009-05-22 13:26:36 -07003053 for (int i = 0;
3054 i < infoRec->rec.redir.redirectingNumber.len;
3055 i++) {
3056 string8[i] = infoRec->rec.redir.redirectingNumber.buf[i];
3057 }
Wink Saville43808972011-01-13 17:39:51 -08003058 string8[(int)infoRec->rec.redir.redirectingNumber.len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07003059 writeStringToParcel(p, (const char*)string8);
3060 free(string8);
3061 string8 = NULL;
3062 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_type);
3063 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_plan);
3064 p.writeInt32(infoRec->rec.redir.redirectingNumber.pi);
3065 p.writeInt32(infoRec->rec.redir.redirectingNumber.si);
3066 p.writeInt32(infoRec->rec.redir.redirectingReason);
Wink Saville3d54e742009-05-18 18:00:44 -07003067 break;
3068 case RIL_CDMA_LINE_CONTROL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07003069 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPolarityIncluded);
3070 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlToggle);
3071 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlReverse);
3072 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPowerDenial);
3073
3074 appendPrintBuf("%slineCtrlPolarityIncluded=%d, \
3075 lineCtrlToggle=%d, lineCtrlReverse=%d, \
3076 lineCtrlPowerDenial=%d, ", printBuf,
3077 (int)infoRec->rec.lineCtrl.lineCtrlPolarityIncluded,
3078 (int)infoRec->rec.lineCtrl.lineCtrlToggle,
3079 (int)infoRec->rec.lineCtrl.lineCtrlReverse,
3080 (int)infoRec->rec.lineCtrl.lineCtrlPowerDenial);
3081 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07003082 break;
3083 case RIL_CDMA_T53_CLIR_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07003084 p.writeInt32((int)(infoRec->rec.clir.cause));
Wink Saville3d54e742009-05-18 18:00:44 -07003085
Wink Savillea592eeb2009-05-22 13:26:36 -07003086 appendPrintBuf("%scause%d", printBuf, infoRec->rec.clir.cause);
3087 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07003088 break;
3089 case RIL_CDMA_T53_AUDIO_CONTROL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07003090 p.writeInt32(infoRec->rec.audioCtrl.upLink);
3091 p.writeInt32(infoRec->rec.audioCtrl.downLink);
3092
3093 appendPrintBuf("%supLink=%d, downLink=%d, ", printBuf,
3094 infoRec->rec.audioCtrl.upLink,
3095 infoRec->rec.audioCtrl.downLink);
3096 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07003097 break;
Wink Savillea592eeb2009-05-22 13:26:36 -07003098 case RIL_CDMA_T53_RELEASE_INFO_REC:
3099 // TODO(Moto): See David Krause, he has the answer:)
Wink Saville8eb2a122012-11-19 16:05:13 -08003100 RLOGE("RIL_CDMA_T53_RELEASE_INFO_REC: return INVALID_RESPONSE");
Wink Savillea592eeb2009-05-22 13:26:36 -07003101 return RIL_ERRNO_INVALID_RESPONSE;
3102 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08003103 RLOGE("Incorrect name value");
Wink Savillea592eeb2009-05-22 13:26:36 -07003104 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07003105 }
3106 }
Wink Savillea592eeb2009-05-22 13:26:36 -07003107 closeResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07003108
Wink Savillea592eeb2009-05-22 13:26:36 -07003109 return 0;
Wink Saville3d54e742009-05-18 18:00:44 -07003110}
3111
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003112static void responseRilSignalStrengthV5(Parcel &p, int slotId, int requestNumber, int responseType,
3113 int token, RIL_Errno e, RIL_SignalStrength_v10 *p_cur) {
Sanket Padawe4c05f352016-01-26 16:19:00 -08003114 p.writeInt32(p_cur->GW_SignalStrength.signalStrength);
3115 p.writeInt32(p_cur->GW_SignalStrength.bitErrorRate);
3116 p.writeInt32(p_cur->CDMA_SignalStrength.dbm);
3117 p.writeInt32(p_cur->CDMA_SignalStrength.ecio);
3118 p.writeInt32(p_cur->EVDO_SignalStrength.dbm);
3119 p.writeInt32(p_cur->EVDO_SignalStrength.ecio);
3120 p.writeInt32(p_cur->EVDO_SignalStrength.signalNoiseRatio);
3121}
3122
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003123static void responseRilSignalStrengthV6Extra(Parcel &p, int slotId, int requestNumber,
3124 int responseType, int token, RIL_Errno e, RIL_SignalStrength_v10 *p_cur) {
Sanket Padawe4c05f352016-01-26 16:19:00 -08003125 /*
3126 * Fixup LTE for backwards compatibility
3127 */
3128 // signalStrength: -1 -> 99
3129 if (p_cur->LTE_SignalStrength.signalStrength == -1) {
3130 p_cur->LTE_SignalStrength.signalStrength = 99;
3131 }
3132 // rsrp: -1 -> INT_MAX all other negative value to positive.
3133 // So remap here
3134 if (p_cur->LTE_SignalStrength.rsrp == -1) {
3135 p_cur->LTE_SignalStrength.rsrp = INT_MAX;
3136 } else if (p_cur->LTE_SignalStrength.rsrp < -1) {
3137 p_cur->LTE_SignalStrength.rsrp = -p_cur->LTE_SignalStrength.rsrp;
3138 }
3139 // rsrq: -1 -> INT_MAX
3140 if (p_cur->LTE_SignalStrength.rsrq == -1) {
3141 p_cur->LTE_SignalStrength.rsrq = INT_MAX;
3142 }
3143 // Not remapping rssnr is already using INT_MAX
3144
3145 // cqi: -1 -> INT_MAX
3146 if (p_cur->LTE_SignalStrength.cqi == -1) {
3147 p_cur->LTE_SignalStrength.cqi = INT_MAX;
3148 }
3149
3150 p.writeInt32(p_cur->LTE_SignalStrength.signalStrength);
3151 p.writeInt32(p_cur->LTE_SignalStrength.rsrp);
3152 p.writeInt32(p_cur->LTE_SignalStrength.rsrq);
3153 p.writeInt32(p_cur->LTE_SignalStrength.rssnr);
3154 p.writeInt32(p_cur->LTE_SignalStrength.cqi);
3155}
3156
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003157static void responseRilSignalStrengthV10(Parcel &p, int slotId, int requestNumber, int responseType,
3158 int token, RIL_Errno e, RIL_SignalStrength_v10 *p_cur) {
3159 responseRilSignalStrengthV5(p, slotId, requestNumber, responseType, token, e, p_cur);
3160 responseRilSignalStrengthV6Extra(p, slotId, requestNumber, responseType, token, e, p_cur);
Sanket Padawe4c05f352016-01-26 16:19:00 -08003161 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
3162}
3163
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003164static int responseRilSignalStrength(Parcel &p, int slotId, int requestNumber, int responseType,
3165 int token, RIL_Errno e, void *response, size_t responselen) {
Wink Savillea592eeb2009-05-22 13:26:36 -07003166 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003167 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07003168 return RIL_ERRNO_INVALID_RESPONSE;
3169 }
3170
Sanket Padawe626099e2016-06-08 14:09:26 -07003171 RIL_SignalStrength_v10 *p_cur;
Sanket Padawe4c05f352016-01-26 16:19:00 -08003172 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
3173 if (responselen >= sizeof (RIL_SignalStrength_v5)) {
Sanket Padawe626099e2016-06-08 14:09:26 -07003174 p_cur = ((RIL_SignalStrength_v10 *) response);
Wink Saville3d54e742009-05-18 18:00:44 -07003175
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003176 responseRilSignalStrengthV5(p, slotId, requestNumber, responseType, token, e, p_cur);
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07003177
Sanket Padawe4c05f352016-01-26 16:19:00 -08003178 if (responselen >= sizeof (RIL_SignalStrength_v6)) {
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003179 responseRilSignalStrengthV6Extra(p, slotId, requestNumber, responseType, token, e,
3180 p_cur);
Sanket Padawe4c05f352016-01-26 16:19:00 -08003181 if (responselen >= sizeof (RIL_SignalStrength_v10)) {
3182 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
3183 } else {
3184 p.writeInt32(INT_MAX);
Wink Saville18e4ab12013-04-07 17:31:04 -07003185 }
Etan Cohend3652192014-06-20 08:28:44 -07003186 } else {
Sanket Padawe4c05f352016-01-26 16:19:00 -08003187 p.writeInt32(99);
3188 p.writeInt32(INT_MAX);
3189 p.writeInt32(INT_MAX);
3190 p.writeInt32(INT_MAX);
3191 p.writeInt32(INT_MAX);
Etan Cohend3652192014-06-20 08:28:44 -07003192 p.writeInt32(INT_MAX);
3193 }
Wink Savillec0114b32011-02-18 10:14:07 -08003194 } else {
Sanket Padawe4c05f352016-01-26 16:19:00 -08003195 RLOGE("invalid response length");
3196 return RIL_ERRNO_INVALID_RESPONSE;
Wink Savillec0114b32011-02-18 10:14:07 -08003197 }
Sanket Padawe00909612016-01-26 18:44:01 -08003198 } else { // RIL version >= 13
Sanket Padawe4c05f352016-01-26 16:19:00 -08003199 if (responselen % sizeof(RIL_SignalStrength_v10) != 0) {
3200 RLOGE("Data structure expected is RIL_SignalStrength_v10");
3201 if (!isDebuggable()) {
3202 return RIL_ERRNO_INVALID_RESPONSE;
3203 } else {
3204 assert(0);
3205 }
3206 }
Sanket Padawe626099e2016-06-08 14:09:26 -07003207 p_cur = ((RIL_SignalStrength_v10 *) response);
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003208 responseRilSignalStrengthV10(p, slotId, requestNumber, responseType, token, e, p_cur);
Wink Saville3d54e742009-05-18 18:00:44 -07003209 }
Sanket Padawe4c05f352016-01-26 16:19:00 -08003210 startResponse;
3211 appendPrintBuf("%s[signalStrength=%d,bitErrorRate=%d,\
3212 CDMA_SS.dbm=%d,CDMA_SSecio=%d,\
3213 EVDO_SS.dbm=%d,EVDO_SS.ecio=%d,\
3214 EVDO_SS.signalNoiseRatio=%d,\
3215 LTE_SS.signalStrength=%d,LTE_SS.rsrp=%d,LTE_SS.rsrq=%d,\
3216 LTE_SS.rssnr=%d,LTE_SS.cqi=%d,TDSCDMA_SS.rscp=%d]",
3217 printBuf,
3218 p_cur->GW_SignalStrength.signalStrength,
3219 p_cur->GW_SignalStrength.bitErrorRate,
3220 p_cur->CDMA_SignalStrength.dbm,
3221 p_cur->CDMA_SignalStrength.ecio,
3222 p_cur->EVDO_SignalStrength.dbm,
3223 p_cur->EVDO_SignalStrength.ecio,
3224 p_cur->EVDO_SignalStrength.signalNoiseRatio,
3225 p_cur->LTE_SignalStrength.signalStrength,
3226 p_cur->LTE_SignalStrength.rsrp,
3227 p_cur->LTE_SignalStrength.rsrq,
3228 p_cur->LTE_SignalStrength.rssnr,
3229 p_cur->LTE_SignalStrength.cqi,
3230 p_cur->TD_SCDMA_SignalStrength.rscp);
3231 closeResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07003232 return 0;
3233}
3234
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003235static int responseCallRing(Parcel &p, int slotId, int requestNumber, int responseType, int token,
3236 RIL_Errno e, void *response, size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07003237 if ((response == NULL) || (responselen == 0)) {
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003238 return responseVoid(p, slotId, requestNumber, responseType, token, e, response,
3239 responselen);
Wink Saville3d54e742009-05-18 18:00:44 -07003240 } else {
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003241 return responseCdmaSignalInfoRecord(p, slotId, requestNumber, responseType, token, e,
3242 response, responselen);
Wink Saville3d54e742009-05-18 18:00:44 -07003243 }
3244}
3245
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003246static int responseCdmaSignalInfoRecord(Parcel &p, int slotId, int requestNumber, int responseType,
3247 int token, RIL_Errno e, void *response, size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07003248 if (response == NULL || responselen == 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003249 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07003250 return RIL_ERRNO_INVALID_RESPONSE;
3251 }
3252
3253 if (responselen != sizeof (RIL_CDMA_SignalInfoRecord)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003254 RLOGE("invalid response length %d expected sizeof (RIL_CDMA_SignalInfoRecord) of %d\n",
Wink Saville3d54e742009-05-18 18:00:44 -07003255 (int)responselen, (int)sizeof (RIL_CDMA_SignalInfoRecord));
3256 return RIL_ERRNO_INVALID_RESPONSE;
3257 }
3258
3259 startResponse;
3260
3261 RIL_CDMA_SignalInfoRecord *p_cur = ((RIL_CDMA_SignalInfoRecord *) response);
3262 marshallSignalInfoRecord(p, *p_cur);
3263
3264 appendPrintBuf("%s[isPresent=%d,signalType=%d,alertPitch=%d\
3265 signal=%d]",
3266 printBuf,
3267 p_cur->isPresent,
3268 p_cur->signalType,
3269 p_cur->alertPitch,
3270 p_cur->signal);
3271
3272 closeResponse;
3273 return 0;
3274}
3275
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003276static int responseCdmaCallWaiting(Parcel &p, int slotId, int requestNumber, int responseType,
3277 int token, RIL_Errno e, void *response, size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07003278 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003279 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07003280 return RIL_ERRNO_INVALID_RESPONSE;
3281 }
3282
Wink Savillec0114b32011-02-18 10:14:07 -08003283 if (responselen < sizeof(RIL_CDMA_CallWaiting_v6)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003284 RLOGW("Upgrade to ril version %d\n", RIL_VERSION);
Wink Savillec0114b32011-02-18 10:14:07 -08003285 }
3286
3287 RIL_CDMA_CallWaiting_v6 *p_cur = ((RIL_CDMA_CallWaiting_v6 *) response);
3288
3289 writeStringToParcel(p, p_cur->number);
3290 p.writeInt32(p_cur->numberPresentation);
3291 writeStringToParcel(p, p_cur->name);
3292 marshallSignalInfoRecord(p, p_cur->signalInfoRecord);
3293
Sanket Padawe4c05f352016-01-26 16:19:00 -08003294 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
3295 if (responselen >= sizeof(RIL_CDMA_CallWaiting_v6)) {
3296 p.writeInt32(p_cur->number_type);
3297 p.writeInt32(p_cur->number_plan);
3298 } else {
3299 p.writeInt32(0);
3300 p.writeInt32(0);
3301 }
Sanket Padawe00909612016-01-26 18:44:01 -08003302 } else { // RIL version >= 13
Sanket Padawe4c05f352016-01-26 16:19:00 -08003303 if (responselen % sizeof(RIL_CDMA_CallWaiting_v6) != 0) {
3304 RLOGE("Data structure expected is RIL_CDMA_CallWaiting_v6");
3305 if (!isDebuggable()) {
3306 return RIL_ERRNO_INVALID_RESPONSE;
3307 } else {
3308 assert(0);
3309 }
3310 }
Wink Savillec0114b32011-02-18 10:14:07 -08003311 p.writeInt32(p_cur->number_type);
3312 p.writeInt32(p_cur->number_plan);
Wink Saville3d54e742009-05-18 18:00:44 -07003313 }
3314
3315 startResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07003316 appendPrintBuf("%snumber=%s,numberPresentation=%d, name=%s,\
3317 signalInfoRecord[isPresent=%d,signalType=%d,alertPitch=%d\
Wink Savillec0114b32011-02-18 10:14:07 -08003318 signal=%d,number_type=%d,number_plan=%d]",
Wink Saville3d54e742009-05-18 18:00:44 -07003319 printBuf,
3320 p_cur->number,
3321 p_cur->numberPresentation,
3322 p_cur->name,
3323 p_cur->signalInfoRecord.isPresent,
3324 p_cur->signalInfoRecord.signalType,
3325 p_cur->signalInfoRecord.alertPitch,
Wink Savillec0114b32011-02-18 10:14:07 -08003326 p_cur->signalInfoRecord.signal,
3327 p_cur->number_type,
3328 p_cur->number_plan);
Wink Saville3d54e742009-05-18 18:00:44 -07003329 closeResponse;
3330
3331 return 0;
3332}
3333
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003334static void responseSimRefreshV7(Parcel &p, int slotId, int requestNumber, int responseType,
3335 int token, RIL_Errno e, void *response) {
Sanket Padawe4c05f352016-01-26 16:19:00 -08003336 RIL_SimRefreshResponse_v7 *p_cur = ((RIL_SimRefreshResponse_v7 *) response);
3337 p.writeInt32(p_cur->result);
3338 p.writeInt32(p_cur->ef_id);
3339 writeStringToParcel(p, p_cur->aid);
3340
3341 appendPrintBuf("%sresult=%d, ef_id=%d, aid=%s",
3342 printBuf,
3343 p_cur->result,
3344 p_cur->ef_id,
3345 p_cur->aid);
3346
3347}
3348
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003349static int responseSimRefresh(Parcel &p, int slotId, int requestNumber, int responseType, int token,
3350 RIL_Errno e, void *response, size_t responselen) {
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003351 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003352 RLOGE("responseSimRefresh: invalid response: NULL");
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003353 return RIL_ERRNO_INVALID_RESPONSE;
3354 }
3355
3356 startResponse;
Sanket Padawe4c05f352016-01-26 16:19:00 -08003357 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
Sanket Padawe66701c52016-01-26 17:44:34 -08003358 if (s_callbacks.version >= 7) {
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003359 responseSimRefreshV7(p, slotId, requestNumber, responseType, token, e, response);
Sanket Padawe4c05f352016-01-26 16:19:00 -08003360 } else {
3361 int *p_cur = ((int *) response);
3362 p.writeInt32(p_cur[0]);
3363 p.writeInt32(p_cur[1]);
3364 writeStringToParcel(p, NULL);
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003365
Sanket Padawe4c05f352016-01-26 16:19:00 -08003366 appendPrintBuf("%sresult=%d, ef_id=%d",
3367 printBuf,
3368 p_cur[0],
3369 p_cur[1]);
3370 }
Sanket Padawe00909612016-01-26 18:44:01 -08003371 } else { // RIL version >= 13
Sanket Padawe4c05f352016-01-26 16:19:00 -08003372 if (responselen % sizeof(RIL_SimRefreshResponse_v7) != 0) {
3373 RLOGE("Data structure expected is RIL_SimRefreshResponse_v7");
3374 if (!isDebuggable()) {
3375 return RIL_ERRNO_INVALID_RESPONSE;
3376 } else {
3377 assert(0);
3378 }
3379 }
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003380 responseSimRefreshV7(p, slotId, requestNumber, responseType, token, e, response);
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003381
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003382 }
3383 closeResponse;
3384
3385 return 0;
3386}
3387
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003388static int responseCellInfoListV6(Parcel &p, int slotId, int requestNumber, int responseType,
3389 int token, RIL_Errno e, void *response, size_t responselen) {
Wink Saville8a9e0212013-04-09 12:11:38 -07003390 if (response == NULL && responselen != 0) {
3391 RLOGE("invalid response: NULL");
3392 return RIL_ERRNO_INVALID_RESPONSE;
3393 }
3394
3395 if (responselen % sizeof(RIL_CellInfo) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07003396 RLOGE("responseCellInfoList: invalid response length %d expected multiple of %d",
Wink Saville8a9e0212013-04-09 12:11:38 -07003397 (int)responselen, (int)sizeof(RIL_CellInfo));
3398 return RIL_ERRNO_INVALID_RESPONSE;
3399 }
3400
3401 int num = responselen / sizeof(RIL_CellInfo);
3402 p.writeInt32(num);
3403
3404 RIL_CellInfo *p_cur = (RIL_CellInfo *) response;
3405 startResponse;
3406 int i;
3407 for (i = 0; i < num; i++) {
Wink Saville8a9e0212013-04-09 12:11:38 -07003408 p.writeInt32((int)p_cur->cellInfoType);
3409 p.writeInt32(p_cur->registered);
3410 p.writeInt32(p_cur->timeStampType);
3411 p.writeInt64(p_cur->timeStamp);
3412 switch(p_cur->cellInfoType) {
3413 case RIL_CELL_INFO_TYPE_GSM: {
Wink Saville8a9e0212013-04-09 12:11:38 -07003414 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
3415 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
3416 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
3417 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
Wink Saville8a9e0212013-04-09 12:11:38 -07003418 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
3419 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3420 break;
3421 }
Wink Savillec57b3eb2013-04-17 12:51:41 -07003422 case RIL_CELL_INFO_TYPE_WCDMA: {
Wink Savillec57b3eb2013-04-17 12:51:41 -07003423 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
3424 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
3425 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
3426 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
3427 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3428 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
3429 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3430 break;
3431 }
Wink Saville8a9e0212013-04-09 12:11:38 -07003432 case RIL_CELL_INFO_TYPE_CDMA: {
Wink Saville8a9e0212013-04-09 12:11:38 -07003433 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
3434 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
3435 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
3436 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
3437 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3438
Wink Saville8a9e0212013-04-09 12:11:38 -07003439 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
3440 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
3441 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
3442 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
3443 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3444 break;
3445 }
3446 case RIL_CELL_INFO_TYPE_LTE: {
Wink Saville8a9e0212013-04-09 12:11:38 -07003447 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
3448 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
3449 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
3450 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
3451 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
3452
Wink Saville8a9e0212013-04-09 12:11:38 -07003453 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
3454 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
3455 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
3456 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
3457 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
3458 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3459 break;
3460 }
Etan Cohend3652192014-06-20 08:28:44 -07003461 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
Etan Cohend3652192014-06-20 08:28:44 -07003462 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
3463 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
3464 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
3465 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
3466 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3467 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3468 break;
3469 }
Wink Saville8a9e0212013-04-09 12:11:38 -07003470 }
3471 p_cur += 1;
3472 }
3473 removeLastChar;
3474 closeResponse;
3475
3476 return 0;
3477}
3478
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003479static int responseCellInfoListV12(Parcel &p, int slotId, int requestNumber, int responseType,
3480 int token, RIL_Errno e, void *response, size_t responselen) {
Sanket Padawe00909612016-01-26 18:44:01 -08003481 if (response == NULL && responselen != 0) {
3482 RLOGE("invalid response: NULL");
3483 return RIL_ERRNO_INVALID_RESPONSE;
3484 }
3485
3486 if (responselen % sizeof(RIL_CellInfo_v12) != 0) {
3487 RLOGE("responseCellInfoList: invalid response length %d expected multiple of %d",
3488 (int)responselen, (int)sizeof(RIL_CellInfo_v12));
3489 return RIL_ERRNO_INVALID_RESPONSE;
3490 }
3491
3492 int num = responselen / sizeof(RIL_CellInfo_v12);
3493 p.writeInt32(num);
3494
3495 RIL_CellInfo_v12 *p_cur = (RIL_CellInfo_v12 *) response;
3496 startResponse;
3497 int i;
3498 for (i = 0; i < num; i++) {
Sanket Padawe00909612016-01-26 18:44:01 -08003499 p.writeInt32((int)p_cur->cellInfoType);
3500 p.writeInt32(p_cur->registered);
3501 p.writeInt32(p_cur->timeStampType);
3502 p.writeInt64(p_cur->timeStamp);
3503 switch(p_cur->cellInfoType) {
3504 case RIL_CELL_INFO_TYPE_GSM: {
Sanket Padawe00909612016-01-26 18:44:01 -08003505 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
3506 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
3507 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
3508 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3509 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.arfcn);
3510 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.bsic);
3511 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
3512 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3513 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.timingAdvance);
3514 break;
3515 }
3516 case RIL_CELL_INFO_TYPE_WCDMA: {
Sanket Padawe00909612016-01-26 18:44:01 -08003517 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
3518 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
3519 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
3520 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
3521 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3522 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.uarfcn);
3523 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
3524 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3525 break;
3526 }
3527 case RIL_CELL_INFO_TYPE_CDMA: {
Sanket Padawe00909612016-01-26 18:44:01 -08003528 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
3529 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
3530 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
3531 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
3532 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3533
Sanket Padawe00909612016-01-26 18:44:01 -08003534 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
3535 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
3536 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
3537 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
3538 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3539 break;
3540 }
3541 case RIL_CELL_INFO_TYPE_LTE: {
Sanket Padawe00909612016-01-26 18:44:01 -08003542 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
3543 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
3544 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
3545 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
3546 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
3547 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.earfcn);
3548
Sanket Padawe00909612016-01-26 18:44:01 -08003549 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
3550 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
3551 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
3552 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
3553 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
3554 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3555 break;
3556 }
3557 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
Sanket Padawe00909612016-01-26 18:44:01 -08003558 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
3559 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
3560 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
3561 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
3562 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3563 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3564 break;
3565 }
3566 }
3567 p_cur += 1;
3568 }
3569 removeLastChar;
3570 closeResponse;
3571 return 0;
3572}
3573
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003574static int responseCellInfoList(Parcel &p, int slotId, int requestNumber, int responseType,
3575 int token, RIL_Errno e, void *response, size_t responselen) {
Sanket Padawe00909612016-01-26 18:44:01 -08003576 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
3577 if (s_callbacks.version < 12) {
3578 RLOGD("responseCellInfoList: v6");
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003579 return responseCellInfoListV6(p, slotId, requestNumber, responseType, token, e,
3580 response, responselen);
Sanket Padawe00909612016-01-26 18:44:01 -08003581 } else {
3582 RLOGD("responseCellInfoList: v12");
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003583 return responseCellInfoListV12(p, slotId, requestNumber, responseType, token, e,
3584 response, responselen);
Sanket Padawe00909612016-01-26 18:44:01 -08003585 }
3586 } else { // RIL version >= 13
3587 if (responselen % sizeof(RIL_CellInfo_v12) != 0) {
3588 RLOGE("Data structure expected is RIL_CellInfo_v12");
3589 if (!isDebuggable()) {
3590 return RIL_ERRNO_INVALID_RESPONSE;
3591 } else {
3592 assert(0);
3593 }
3594 }
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003595 return responseCellInfoListV12(p, slotId, requestNumber, responseType, token, e, response,
3596 responselen);
Sanket Padawe00909612016-01-26 18:44:01 -08003597 }
3598
3599 return 0;
3600}
3601
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003602static int responseHardwareConfig(Parcel &p, int slotId, int requestNumber, int responseType,
3603 int token, RIL_Errno e, void *response, size_t responselen) {
Etan Cohend3652192014-06-20 08:28:44 -07003604 if (response == NULL && responselen != 0) {
3605 RLOGE("invalid response: NULL");
3606 return RIL_ERRNO_INVALID_RESPONSE;
3607 }
3608
3609 if (responselen % sizeof(RIL_HardwareConfig) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07003610 RLOGE("responseHardwareConfig: invalid response length %d expected multiple of %d",
Etan Cohend3652192014-06-20 08:28:44 -07003611 (int)responselen, (int)sizeof(RIL_HardwareConfig));
3612 return RIL_ERRNO_INVALID_RESPONSE;
3613 }
3614
3615 int num = responselen / sizeof(RIL_HardwareConfig);
3616 int i;
3617 RIL_HardwareConfig *p_cur = (RIL_HardwareConfig *) response;
3618
3619 p.writeInt32(num);
3620
3621 startResponse;
3622 for (i = 0; i < num; i++) {
3623 switch (p_cur[i].type) {
3624 case RIL_HARDWARE_CONFIG_MODEM: {
3625 writeStringToParcel(p, p_cur[i].uuid);
3626 p.writeInt32((int)p_cur[i].state);
3627 p.writeInt32(p_cur[i].cfg.modem.rat);
3628 p.writeInt32(p_cur[i].cfg.modem.maxVoice);
3629 p.writeInt32(p_cur[i].cfg.modem.maxData);
3630 p.writeInt32(p_cur[i].cfg.modem.maxStandby);
3631
3632 appendPrintBuf("%s modem: uuid=%s,state=%d,rat=%08x,maxV=%d,maxD=%d,maxS=%d", printBuf,
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003633 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.modem.rat,
3634 p_cur[i].cfg.modem.maxVoice, p_cur[i].cfg.modem.maxData,
3635 p_cur[i].cfg.modem.maxStandby);
Etan Cohend3652192014-06-20 08:28:44 -07003636 break;
3637 }
3638 case RIL_HARDWARE_CONFIG_SIM: {
3639 writeStringToParcel(p, p_cur[i].uuid);
3640 p.writeInt32((int)p_cur[i].state);
3641 writeStringToParcel(p, p_cur[i].cfg.sim.modemUuid);
3642
3643 appendPrintBuf("%s sim: uuid=%s,state=%d,modem-uuid=%s", printBuf,
3644 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.sim.modemUuid);
3645 break;
3646 }
3647 }
3648 }
3649 removeLastChar;
3650 closeResponse;
3651 return 0;
3652}
3653
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003654static int responseRadioCapability(Parcel &p, int slotId, int requestNumber, int responseType,
3655 int token, RIL_Errno e, void *response, size_t responselen) {
Wink Saville8b4e4f72014-10-17 15:01:45 -07003656 if (response == NULL) {
3657 RLOGE("invalid response: NULL");
3658 return RIL_ERRNO_INVALID_RESPONSE;
3659 }
3660
3661 if (responselen != sizeof (RIL_RadioCapability) ) {
3662 RLOGE("invalid response length was %d expected %d",
3663 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3664 return RIL_ERRNO_INVALID_RESPONSE;
3665 }
3666
3667 RIL_RadioCapability *p_cur = (RIL_RadioCapability *) response;
3668 p.writeInt32(p_cur->version);
3669 p.writeInt32(p_cur->session);
3670 p.writeInt32(p_cur->phase);
3671 p.writeInt32(p_cur->rat);
3672 writeStringToParcel(p, p_cur->logicalModemUuid);
3673 p.writeInt32(p_cur->status);
3674
3675 startResponse;
3676 appendPrintBuf("%s[version=%d,session=%d,phase=%d,\
Legler Wu8caf06f2014-10-29 14:02:14 +08003677 rat=%s,logicalModemUuid=%s,status=%d]",
Wink Saville8b4e4f72014-10-17 15:01:45 -07003678 printBuf,
3679 p_cur->version,
3680 p_cur->session,
3681 p_cur->phase,
3682 p_cur->rat,
Legler Wu8caf06f2014-10-29 14:02:14 +08003683 p_cur->logicalModemUuid,
Wink Saville8b4e4f72014-10-17 15:01:45 -07003684 p_cur->status);
3685 closeResponse;
3686 return 0;
3687}
3688
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003689static int responseSSData(Parcel &p, int slotId, int requestNumber, int responseType, int token,
3690 RIL_Errno e, void *response, size_t responselen) {
Amit Mahajan54563d32014-11-22 00:54:49 +00003691 RLOGD("In responseSSData");
3692 int num;
3693
3694 if (response == NULL && responselen != 0) {
3695 RLOGE("invalid response length was %d expected %d",
3696 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3697 return RIL_ERRNO_INVALID_RESPONSE;
3698 }
3699
3700 if (responselen != sizeof(RIL_StkCcUnsolSsResponse)) {
3701 RLOGE("invalid response length %d, expected %d",
3702 (int)responselen, (int)sizeof(RIL_StkCcUnsolSsResponse));
3703 return RIL_ERRNO_INVALID_RESPONSE;
3704 }
3705
3706 startResponse;
3707 RIL_StkCcUnsolSsResponse *p_cur = (RIL_StkCcUnsolSsResponse *) response;
3708 p.writeInt32(p_cur->serviceType);
3709 p.writeInt32(p_cur->requestType);
3710 p.writeInt32(p_cur->teleserviceType);
3711 p.writeInt32(p_cur->serviceClass);
3712 p.writeInt32(p_cur->result);
3713
3714 if (isServiceTypeCfQuery(p_cur->serviceType, p_cur->requestType)) {
3715 RLOGD("responseSSData CF type, num of Cf elements %d", p_cur->cfData.numValidIndexes);
3716 if (p_cur->cfData.numValidIndexes > NUM_SERVICE_CLASSES) {
3717 RLOGE("numValidIndexes is greater than max value %d, "
3718 "truncating it to max value", NUM_SERVICE_CLASSES);
3719 p_cur->cfData.numValidIndexes = NUM_SERVICE_CLASSES;
3720 }
3721 /* number of call info's */
3722 p.writeInt32(p_cur->cfData.numValidIndexes);
3723
3724 for (int i = 0; i < p_cur->cfData.numValidIndexes; i++) {
3725 RIL_CallForwardInfo cf = p_cur->cfData.cfInfo[i];
3726
3727 p.writeInt32(cf.status);
3728 p.writeInt32(cf.reason);
3729 p.writeInt32(cf.serviceClass);
3730 p.writeInt32(cf.toa);
3731 writeStringToParcel(p, cf.number);
3732 p.writeInt32(cf.timeSeconds);
3733 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
3734 (cf.status==1)?"enable":"disable", cf.reason, cf.serviceClass, cf.toa,
3735 (char*)cf.number, cf.timeSeconds);
3736 RLOGD("Data: %d,reason=%d,cls=%d,toa=%d,num=%s,tout=%d],", cf.status,
3737 cf.reason, cf.serviceClass, cf.toa, (char*)cf.number, cf.timeSeconds);
3738 }
3739 } else {
3740 p.writeInt32 (SS_INFO_MAX);
3741
3742 /* each int*/
3743 for (int i = 0; i < SS_INFO_MAX; i++) {
3744 appendPrintBuf("%s%d,", printBuf, p_cur->ssInfo[i]);
3745 RLOGD("Data: %d",p_cur->ssInfo[i]);
3746 p.writeInt32(p_cur->ssInfo[i]);
3747 }
3748 }
3749 removeLastChar;
3750 closeResponse;
3751
3752 return 0;
3753}
3754
3755static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType) {
3756 if ((reqType == SS_INTERROGATION) &&
3757 (serType == SS_CFU ||
3758 serType == SS_CF_BUSY ||
3759 serType == SS_CF_NO_REPLY ||
3760 serType == SS_CF_NOT_REACHABLE ||
3761 serType == SS_CF_ALL ||
3762 serType == SS_CF_ALL_CONDITIONAL)) {
3763 return true;
3764 }
3765 return false;
3766}
3767
Wink Saville3d54e742009-05-18 18:00:44 -07003768static void triggerEvLoop() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003769 int ret;
3770 if (!pthread_equal(pthread_self(), s_tid_dispatch)) {
3771 /* trigger event loop to wakeup. No reason to do this,
3772 * if we're in the event loop thread */
3773 do {
3774 ret = write (s_fdWakeupWrite, " ", 1);
3775 } while (ret < 0 && errno == EINTR);
3776 }
3777}
3778
Wink Saville3d54e742009-05-18 18:00:44 -07003779static void rilEventAddWakeup(struct ril_event *ev) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003780 ril_event_add(ev);
3781 triggerEvLoop();
3782}
3783
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003784static int responseGsmBrSmsCnf(Parcel &p, int slotId, int requestNumber, int responseType,
3785 int token, RIL_Errno e, void *response, size_t responselen) {
Wink Savillea592eeb2009-05-22 13:26:36 -07003786 int num = responselen / sizeof(RIL_GSM_BroadcastSmsConfigInfo *);
Wink Savillef4c4d362009-04-02 01:37:03 -07003787 p.writeInt32(num);
3788
Wink Savillef4c4d362009-04-02 01:37:03 -07003789 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07003790 RIL_GSM_BroadcastSmsConfigInfo **p_cur =
3791 (RIL_GSM_BroadcastSmsConfigInfo **) response;
3792 for (int i = 0; i < num; i++) {
3793 p.writeInt32(p_cur[i]->fromServiceId);
3794 p.writeInt32(p_cur[i]->toServiceId);
3795 p.writeInt32(p_cur[i]->fromCodeScheme);
3796 p.writeInt32(p_cur[i]->toCodeScheme);
3797 p.writeInt32(p_cur[i]->selected);
3798
3799 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId=%d, \
3800 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]",
3801 printBuf, i, p_cur[i]->fromServiceId, p_cur[i]->toServiceId,
3802 p_cur[i]->fromCodeScheme, p_cur[i]->toCodeScheme,
3803 p_cur[i]->selected);
3804 }
Wink Savillef4c4d362009-04-02 01:37:03 -07003805 closeResponse;
3806
3807 return 0;
3808}
3809
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003810static int responseCdmaBrSmsCnf(Parcel &p, int slotId, int requestNumber, int responseType,
3811 int token, RIL_Errno e, void *response, size_t responselen) {
Wink Savillea592eeb2009-05-22 13:26:36 -07003812 RIL_CDMA_BroadcastSmsConfigInfo **p_cur =
3813 (RIL_CDMA_BroadcastSmsConfigInfo **) response;
Wink Savillef4c4d362009-04-02 01:37:03 -07003814
Wink Savillea592eeb2009-05-22 13:26:36 -07003815 int num = responselen / sizeof (RIL_CDMA_BroadcastSmsConfigInfo *);
3816 p.writeInt32(num);
Wink Savillef4c4d362009-04-02 01:37:03 -07003817
3818 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07003819 for (int i = 0 ; i < num ; i++ ) {
3820 p.writeInt32(p_cur[i]->service_category);
3821 p.writeInt32(p_cur[i]->language);
3822 p.writeInt32(p_cur[i]->selected);
Wink Savillef4c4d362009-04-02 01:37:03 -07003823
Wink Savillea592eeb2009-05-22 13:26:36 -07003824 appendPrintBuf("%s [%d: srvice_category=%d, language =%d, \
3825 selected =%d], ",
3826 printBuf, i, p_cur[i]->service_category, p_cur[i]->language,
3827 p_cur[i]->selected);
Wink Savillef5903df2009-04-24 11:54:14 -07003828 }
Wink Savillea592eeb2009-05-22 13:26:36 -07003829 closeResponse;
Wink Savillef5903df2009-04-24 11:54:14 -07003830
Wink Savillef4c4d362009-04-02 01:37:03 -07003831 return 0;
3832}
3833
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003834static int responseCdmaSms(Parcel &p, int slotId, int requestNumber, int responseType, int token,
3835 RIL_Errno e, void *response, size_t responselen) {
Wink Savillef4c4d362009-04-02 01:37:03 -07003836 int num;
3837 int digitCount;
3838 int digitLimit;
3839 uint8_t uct;
3840 void* dest;
3841
Wink Saville8eb2a122012-11-19 16:05:13 -08003842 RLOGD("Inside responseCdmaSms");
Wink Savillef5903df2009-04-24 11:54:14 -07003843
Wink Savillef4c4d362009-04-02 01:37:03 -07003844 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003845 RLOGE("invalid response: NULL");
Wink Savillef4c4d362009-04-02 01:37:03 -07003846 return RIL_ERRNO_INVALID_RESPONSE;
3847 }
3848
Wink Savillef5903df2009-04-24 11:54:14 -07003849 if (responselen != sizeof(RIL_CDMA_SMS_Message)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003850 RLOGE("invalid response length was %d expected %d",
Wink Savillef5903df2009-04-24 11:54:14 -07003851 (int)responselen, (int)sizeof(RIL_CDMA_SMS_Message));
Wink Savillef4c4d362009-04-02 01:37:03 -07003852 return RIL_ERRNO_INVALID_RESPONSE;
3853 }
3854
3855 RIL_CDMA_SMS_Message *p_cur = (RIL_CDMA_SMS_Message *) response;
3856 p.writeInt32(p_cur->uTeleserviceID);
3857 p.write(&(p_cur->bIsServicePresent),sizeof(uct));
3858 p.writeInt32(p_cur->uServicecategory);
3859 p.writeInt32(p_cur->sAddress.digit_mode);
3860 p.writeInt32(p_cur->sAddress.number_mode);
3861 p.writeInt32(p_cur->sAddress.number_type);
3862 p.writeInt32(p_cur->sAddress.number_plan);
3863 p.write(&(p_cur->sAddress.number_of_digits), sizeof(uct));
3864 digitLimit= MIN((p_cur->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
3865 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3866 p.write(&(p_cur->sAddress.digits[digitCount]),sizeof(uct));
3867 }
3868
3869 p.writeInt32(p_cur->sSubAddress.subaddressType);
3870 p.write(&(p_cur->sSubAddress.odd),sizeof(uct));
3871 p.write(&(p_cur->sSubAddress.number_of_digits),sizeof(uct));
3872 digitLimit= MIN((p_cur->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
3873 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3874 p.write(&(p_cur->sSubAddress.digits[digitCount]),sizeof(uct));
3875 }
3876
3877 digitLimit= MIN((p_cur->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
3878 p.writeInt32(p_cur->uBearerDataLen);
3879 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3880 p.write(&(p_cur->aBearerData[digitCount]), sizeof(uct));
3881 }
3882
3883 startResponse;
3884 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
Wink Saville1b5fd232009-04-22 14:50:00 -07003885 sAddress.digit_mode=%d, sAddress.number_mode=%d, sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07003886 printBuf, p_cur->uTeleserviceID,p_cur->bIsServicePresent,p_cur->uServicecategory,
3887 p_cur->sAddress.digit_mode, p_cur->sAddress.number_mode,p_cur->sAddress.number_type);
3888 closeResponse;
3889
3890 return 0;
3891}
3892
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003893static int responseDcRtInfo(Parcel &p, int slotId, int requestNumber, int responseType, int token,
3894 RIL_Errno e, void *response, size_t responselen)
Wink Savillec29360a2014-07-13 05:17:28 -07003895{
3896 int num = responselen / sizeof(RIL_DcRtInfo);
3897 if ((responselen % sizeof(RIL_DcRtInfo) != 0) || (num != 1)) {
Amit Mahajan52500162014-07-29 17:36:48 -07003898 RLOGE("responseDcRtInfo: invalid response length %d expected multiple of %d",
Wink Savillec29360a2014-07-13 05:17:28 -07003899 (int)responselen, (int)sizeof(RIL_DcRtInfo));
3900 return RIL_ERRNO_INVALID_RESPONSE;
3901 }
3902
3903 startResponse;
3904 RIL_DcRtInfo *pDcRtInfo = (RIL_DcRtInfo *)response;
3905 p.writeInt64(pDcRtInfo->time);
3906 p.writeInt32(pDcRtInfo->powerState);
3907 appendPrintBuf("%s[time=%d,powerState=%d]", printBuf,
3908 pDcRtInfo->time,
3909 pDcRtInfo->powerState);
3910 closeResponse;
3911
3912 return 0;
3913}
3914
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003915static int responseLceStatus(Parcel &p, int slotId, int requestNumber, int responseType, int token,
3916 RIL_Errno e, void *response, size_t responselen) {
fengluf7408292015-04-14 14:53:55 -07003917 if (response == NULL || responselen != sizeof(RIL_LceStatusInfo)) {
3918 if (response == NULL) {
3919 RLOGE("invalid response: NULL");
3920 }
3921 else {
Meng Wangef966a32016-06-20 17:38:18 -07003922 RLOGE("responseLceStatus: invalid response length %u expecting len: %u",
3923 (unsigned)sizeof(RIL_LceStatusInfo), (unsigned)responselen);
fengluf7408292015-04-14 14:53:55 -07003924 }
3925 return RIL_ERRNO_INVALID_RESPONSE;
3926 }
3927
3928 RIL_LceStatusInfo *p_cur = (RIL_LceStatusInfo *)response;
3929 p.write((void *)p_cur, 1); // p_cur->lce_status takes one byte.
3930 p.writeInt32(p_cur->actual_interval_ms);
3931
3932 startResponse;
3933 appendPrintBuf("LCE Status: %d, actual_interval_ms: %d",
3934 p_cur->lce_status, p_cur->actual_interval_ms);
3935 closeResponse;
3936
3937 return 0;
3938}
3939
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003940static int responseLceData(Parcel &p, int slotId, int requestNumber, int responseType, int token,
3941 RIL_Errno e, void *response, size_t responselen) {
fengluf7408292015-04-14 14:53:55 -07003942 if (response == NULL || responselen != sizeof(RIL_LceDataInfo)) {
3943 if (response == NULL) {
3944 RLOGE("invalid response: NULL");
3945 }
3946 else {
Meng Wangef966a32016-06-20 17:38:18 -07003947 RLOGE("responseLceData: invalid response length %u expecting len: %u",
3948 (unsigned)sizeof(RIL_LceDataInfo), (unsigned)responselen);
fengluf7408292015-04-14 14:53:55 -07003949 }
3950 return RIL_ERRNO_INVALID_RESPONSE;
3951 }
3952
3953 RIL_LceDataInfo *p_cur = (RIL_LceDataInfo *)response;
3954 p.writeInt32(p_cur->last_hop_capacity_kbps);
3955
3956 /* p_cur->confidence_level and p_cur->lce_suspended take 1 byte each.*/
3957 p.write((void *)&(p_cur->confidence_level), 1);
3958 p.write((void *)&(p_cur->lce_suspended), 1);
3959
3960 startResponse;
Hyejin606dd672015-09-14 16:27:28 -07003961 appendPrintBuf("LCE info received: capacity %d confidence level %d \
fengluf7408292015-04-14 14:53:55 -07003962 and suspended %d",
3963 p_cur->last_hop_capacity_kbps, p_cur->confidence_level,
3964 p_cur->lce_suspended);
3965 closeResponse;
3966
3967 return 0;
3968}
3969
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003970static int responseActivityData(Parcel &p, int slotId, int requestNumber, int responseType,
3971 int token, RIL_Errno e, void *response, size_t responselen) {
Prerepa Viswanadham73157492015-05-28 00:37:32 -07003972 if (response == NULL || responselen != sizeof(RIL_ActivityStatsInfo)) {
3973 if (response == NULL) {
3974 RLOGE("invalid response: NULL");
3975 }
3976 else {
Meng Wangef966a32016-06-20 17:38:18 -07003977 RLOGE("responseActivityData: invalid response length %u expecting len: %u",
3978 (unsigned)sizeof(RIL_ActivityStatsInfo), (unsigned)responselen);
Prerepa Viswanadham73157492015-05-28 00:37:32 -07003979 }
3980 return RIL_ERRNO_INVALID_RESPONSE;
3981 }
3982
3983 RIL_ActivityStatsInfo *p_cur = (RIL_ActivityStatsInfo *)response;
3984 p.writeInt32(p_cur->sleep_mode_time_ms);
3985 p.writeInt32(p_cur->idle_mode_time_ms);
3986 for(int i = 0; i < RIL_NUM_TX_POWER_LEVELS; i++) {
3987 p.writeInt32(p_cur->tx_mode_time_ms[i]);
3988 }
3989 p.writeInt32(p_cur->rx_mode_time_ms);
3990
3991 startResponse;
Hyejin606dd672015-09-14 16:27:28 -07003992 appendPrintBuf("Modem activity info received: sleep_mode_time_ms %d idle_mode_time_ms %d \
Prerepa Viswanadham73157492015-05-28 00:37:32 -07003993 tx_mode_time_ms %d %d %d %d %d and rx_mode_time_ms %d",
3994 p_cur->sleep_mode_time_ms, p_cur->idle_mode_time_ms, p_cur->tx_mode_time_ms[0],
3995 p_cur->tx_mode_time_ms[1], p_cur->tx_mode_time_ms[2], p_cur->tx_mode_time_ms[3],
3996 p_cur->tx_mode_time_ms[4], p_cur->rx_mode_time_ms);
3997 closeResponse;
3998
3999 return 0;
4000}
4001
Amit Mahajan18fe36b2016-08-25 11:19:21 -07004002static int responseCarrierRestrictions(Parcel &p, int slotId, int requestNumber, int responseType,
4003 int token, RIL_Errno e, void *response, size_t responselen) {
Meng Wangb4e34312016-05-12 14:54:36 -07004004 if (response == NULL) {
4005 RLOGE("invalid response: NULL");
4006 return RIL_ERRNO_INVALID_RESPONSE;
4007 }
4008 if (responselen != sizeof(RIL_CarrierRestrictions)) {
Meng Wangef966a32016-06-20 17:38:18 -07004009 RLOGE("responseCarrierRestrictions: invalid response length %u expecting len: %u",
4010 (unsigned)responselen, (unsigned)sizeof(RIL_CarrierRestrictions));
Meng Wangb4e34312016-05-12 14:54:36 -07004011 return RIL_ERRNO_INVALID_RESPONSE;
4012 }
4013
4014 RIL_CarrierRestrictions *p_cr = (RIL_CarrierRestrictions *)response;
Meng Wangb460ba82016-06-09 09:21:26 -07004015 startResponse;
4016
4017 p.writeInt32(p_cr->len_allowed_carriers);
4018 p.writeInt32(p_cr->len_excluded_carriers);
4019 appendPrintBuf(" %s len_allowed_carriers: %d, len_excluded_carriers: %d,", printBuf,
4020 p_cr->len_allowed_carriers,p_cr->len_excluded_carriers);
4021
4022 appendPrintBuf(" %s allowed_carriers:", printBuf);
4023 for(int32_t i = 0; i < p_cr->len_allowed_carriers; i++) {
Meng Wangb4e34312016-05-12 14:54:36 -07004024 RIL_Carrier *carrier = p_cr->allowed_carriers + i;
Meng Wangb460ba82016-06-09 09:21:26 -07004025 writeStringToParcel(p, carrier->mcc);
4026 writeStringToParcel(p, carrier->mnc);
Meng Wangb4e34312016-05-12 14:54:36 -07004027 p.writeInt32(carrier->match_type);
Meng Wangb460ba82016-06-09 09:21:26 -07004028 writeStringToParcel(p, carrier->match_data);
4029 appendPrintBuf(" %s [%d mcc: %s, mnc: %s, match_type: %d, match_data: %s],", printBuf,
4030 i, carrier->mcc, carrier->mnc, carrier->match_type, carrier->match_data);
Meng Wangb4e34312016-05-12 14:54:36 -07004031 }
4032
Meng Wangb460ba82016-06-09 09:21:26 -07004033 appendPrintBuf(" %s excluded_carriers:", printBuf);
4034 for(int32_t i = 0; i < p_cr->len_excluded_carriers; i++) {
4035 RIL_Carrier *carrier = p_cr->excluded_carriers + i;
4036 writeStringToParcel(p, carrier->mcc);
4037 writeStringToParcel(p, carrier->mnc);
4038 p.writeInt32(carrier->match_type);
4039 writeStringToParcel(p, carrier->match_data);
4040 appendPrintBuf(" %s [%d mcc: %s, mnc: %s, match_type: %d, match_data: %s],", printBuf,
4041 i, carrier->mcc, carrier->mnc, carrier->match_type, carrier->match_data);
4042 }
4043
Meng Wangb4e34312016-05-12 14:54:36 -07004044 closeResponse;
4045
4046 return 0;
4047}
4048
Amit Mahajan18fe36b2016-08-25 11:19:21 -07004049static int responsePcoData(Parcel &p, int slotId, int requestNumber, int responseType, int token,
4050 RIL_Errno e, void *response, size_t responselen) {
Robert Greenwalt27e99c52016-06-01 16:31:38 -07004051 if (response == NULL) {
4052 RLOGE("responsePcoData: invalid NULL response");
4053 return RIL_ERRNO_INVALID_RESPONSE;
4054 }
4055 if (responselen != sizeof(RIL_PCO_Data)) {
Meng Wangef966a32016-06-20 17:38:18 -07004056 RLOGE("responsePcoData: invalid response length %u, expecting %u",
4057 (unsigned)responselen, (unsigned)sizeof(RIL_PCO_Data));
Robert Greenwalt27e99c52016-06-01 16:31:38 -07004058 return RIL_ERRNO_INVALID_RESPONSE;
4059 }
4060
4061 RIL_PCO_Data *p_cur = (RIL_PCO_Data *)response;
4062 p.writeInt32(p_cur->cid);
4063 writeStringToParcel(p, p_cur->bearer_proto);
4064 p.writeInt32(p_cur->pco_id);
4065 p.writeInt32(p_cur->contents_length);
4066 p.write(p_cur->contents, p_cur->contents_length);
4067
4068 startResponse;
4069 appendPrintBuf("PCO data received: cid %d, id %d, length %d",
4070 p_cur->cid, p_cur->pco_id, p_cur->contents_length);
4071 closeResponse;
4072
4073 return 0;
4074}
4075
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004076/**
4077 * A write on the wakeup fd is done just to pop us out of select()
4078 * We empty the buffer here and then ril_event will reset the timers on the
4079 * way back down
4080 */
Wink Savillef4c4d362009-04-02 01:37:03 -07004081static void processWakeupCallback(int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004082 char buff[16];
4083 int ret;
4084
Wink Saville8eb2a122012-11-19 16:05:13 -08004085 RLOGV("processWakeupCallback");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004086
4087 /* empty our wakeup socket out */
4088 do {
4089 ret = read(s_fdWakeupRead, &buff, sizeof(buff));
Wink Saville7f856802009-06-09 10:23:37 -07004090 } while (ret > 0 || (ret < 0 && errno == EINTR));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004091}
4092
Etan Cohend3652192014-06-20 08:28:44 -07004093static void onCommandsSocketClosed(RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004094 int ret;
4095 RequestInfo *p_cur;
Etan Cohend3652192014-06-20 08:28:44 -07004096 /* Hook for current context
4097 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
4098 pthread_mutex_t * pendingRequestsMutexHook = &s_pendingRequestsMutex;
4099 /* pendingRequestsHook refer to &s_pendingRequests */
4100 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004101
Etan Cohend3652192014-06-20 08:28:44 -07004102#if (SIM_COUNT >= 2)
4103 if (socket_id == RIL_SOCKET_2) {
4104 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
4105 pendingRequestsHook = &s_pendingRequests_socket2;
4106 }
4107#if (SIM_COUNT >= 3)
4108 else if (socket_id == RIL_SOCKET_3) {
4109 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
4110 pendingRequestsHook = &s_pendingRequests_socket3;
4111 }
4112#endif
4113#if (SIM_COUNT >= 4)
4114 else if (socket_id == RIL_SOCKET_4) {
4115 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
4116 pendingRequestsHook = &s_pendingRequests_socket4;
4117 }
4118#endif
4119#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004120 /* mark pending requests as "cancelled" so we dont report responses */
Etan Cohend3652192014-06-20 08:28:44 -07004121 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004122 assert (ret == 0);
4123
Etan Cohend3652192014-06-20 08:28:44 -07004124 p_cur = *pendingRequestsHook;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004125
Etan Cohend3652192014-06-20 08:28:44 -07004126 for (p_cur = *pendingRequestsHook
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004127 ; p_cur != NULL
4128 ; p_cur = p_cur->p_next
4129 ) {
4130 p_cur->cancelled = 1;
4131 }
4132
Etan Cohend3652192014-06-20 08:28:44 -07004133 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004134 assert (ret == 0);
4135}
4136
Wink Savillef4c4d362009-04-02 01:37:03 -07004137static void processCommandsCallback(int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004138 RecordStream *p_rs;
4139 void *p_record;
4140 size_t recordlen;
4141 int ret;
Etan Cohend3652192014-06-20 08:28:44 -07004142 SocketListenParam *p_info = (SocketListenParam *)param;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004143
Etan Cohend3652192014-06-20 08:28:44 -07004144 assert(fd == p_info->fdCommand);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004145
Etan Cohend3652192014-06-20 08:28:44 -07004146 p_rs = p_info->p_rs;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004147
4148 for (;;) {
4149 /* loop until EAGAIN/EINTR, end of stream, or other error */
4150 ret = record_stream_get_next(p_rs, &p_record, &recordlen);
4151
4152 if (ret == 0 && p_record == NULL) {
4153 /* end-of-stream */
4154 break;
4155 } else if (ret < 0) {
4156 break;
4157 } else if (ret == 0) { /* && p_record != NULL */
Etan Cohend3652192014-06-20 08:28:44 -07004158 processCommandBuffer(p_record, recordlen, p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004159 }
4160 }
4161
4162 if (ret == 0 || !(errno == EAGAIN || errno == EINTR)) {
4163 /* fatal error or end-of-stream */
4164 if (ret != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004165 RLOGE("error on reading command socket errno:%d\n", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004166 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08004167 RLOGW("EOS. Closing command socket.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004168 }
Wink Saville7f856802009-06-09 10:23:37 -07004169
Etan Cohend3652192014-06-20 08:28:44 -07004170 close(fd);
4171 p_info->fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004172
Etan Cohend3652192014-06-20 08:28:44 -07004173 ril_event_del(p_info->commands_event);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004174
4175 record_stream_free(p_rs);
4176
4177 /* start listening for new connections again */
4178 rilEventAddWakeup(&s_listen_event);
4179
Etan Cohend3652192014-06-20 08:28:44 -07004180 onCommandsSocketClosed(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004181 }
4182}
4183
4184
Etan Cohend3652192014-06-20 08:28:44 -07004185static void onNewCommandConnect(RIL_SOCKET_ID socket_id) {
Wink Saville5b9df332011-04-06 16:24:21 -07004186 // Inform we are connected and the ril version
Jake Hambya9c18d12011-04-12 23:32:08 -07004187 int rilVer = s_callbacks.version;
Etan Cohend3652192014-06-20 08:28:44 -07004188 RIL_UNSOL_RESPONSE(RIL_UNSOL_RIL_CONNECTED,
4189 &rilVer, sizeof(rilVer), socket_id);
Wink Saville5b9df332011-04-06 16:24:21 -07004190
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004191 // implicit radio state changed
Etan Cohend3652192014-06-20 08:28:44 -07004192 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
4193 NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004194
4195 // Send last NITZ time data, in case it was missed
4196 if (s_lastNITZTimeData != NULL) {
Etan Cohend3652192014-06-20 08:28:44 -07004197 sendResponseRaw(s_lastNITZTimeData, s_lastNITZTimeDataSize, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004198
4199 free(s_lastNITZTimeData);
4200 s_lastNITZTimeData = NULL;
4201 }
4202
4203 // Get version string
4204 if (s_callbacks.getVersion != NULL) {
4205 const char *version;
4206 version = s_callbacks.getVersion();
Wink Saville8eb2a122012-11-19 16:05:13 -08004207 RLOGI("RIL Daemon version: %s\n", version);
Wink Saville7f856802009-06-09 10:23:37 -07004208
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004209 property_set(PROPERTY_RIL_IMPL, version);
4210 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08004211 RLOGI("RIL Daemon version: unavailable\n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004212 property_set(PROPERTY_RIL_IMPL, "unavailable");
4213 }
4214
4215}
4216
Wink Savillef4c4d362009-04-02 01:37:03 -07004217static void listenCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004218 int ret;
4219 int err;
4220 int is_phone_socket;
Etan Cohend3652192014-06-20 08:28:44 -07004221 int fdCommand = -1;
Meng Wangef966a32016-06-20 17:38:18 -07004222 const char* processName;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004223 RecordStream *p_rs;
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004224 MySocketListenParam* listenParam;
4225 RilSocket *sapSocket = NULL;
4226 socketClient *sClient = NULL;
4227
Etan Cohend3652192014-06-20 08:28:44 -07004228 SocketListenParam *p_info = (SocketListenParam *)param;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004229
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004230 if(RIL_SAP_SOCKET == p_info->type) {
4231 listenParam = (MySocketListenParam *)param;
4232 sapSocket = listenParam->socket;
4233 }
4234
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004235 struct sockaddr_un peeraddr;
4236 socklen_t socklen = sizeof (peeraddr);
4237
4238 struct ucred creds;
4239 socklen_t szCreds = sizeof(creds);
4240
4241 struct passwd *pwd = NULL;
4242
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004243 if(NULL == sapSocket) {
George Burgess IVd9cee0a2016-10-27 22:51:30 -07004244 assert (p_info->fdCommand < 0);
4245 assert (fd == p_info->fdListen);
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004246 processName = PHONE_PROCESS;
4247 } else {
George Burgess IVd9cee0a2016-10-27 22:51:30 -07004248 assert (sapSocket->getCommandFd() < 0);
4249 assert (fd == sapSocket->getListenFd());
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004250 processName = BLUETOOTH_PROCESS;
4251 }
4252
Wink Saville7f856802009-06-09 10:23:37 -07004253
Etan Cohend3652192014-06-20 08:28:44 -07004254 fdCommand = accept(fd, (sockaddr *) &peeraddr, &socklen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004255
Etan Cohend3652192014-06-20 08:28:44 -07004256 if (fdCommand < 0 ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004257 RLOGE("Error on accept() errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004258 /* start listening for new connections again */
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004259 if(NULL == sapSocket) {
4260 rilEventAddWakeup(p_info->listen_event);
4261 } else {
4262 rilEventAddWakeup(sapSocket->getListenEvent());
4263 }
Etan Cohend3652192014-06-20 08:28:44 -07004264 return;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004265 }
4266
4267 /* check the credential of the other side and only accept socket from
4268 * phone process
Wink Saville7f856802009-06-09 10:23:37 -07004269 */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004270 errno = 0;
4271 is_phone_socket = 0;
Wink Savillef4c4d362009-04-02 01:37:03 -07004272
Etan Cohend3652192014-06-20 08:28:44 -07004273 err = getsockopt(fdCommand, SOL_SOCKET, SO_PEERCRED, &creds, &szCreds);
Wink Savillef4c4d362009-04-02 01:37:03 -07004274
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004275 if (err == 0 && szCreds > 0) {
Wink Savillef4c4d362009-04-02 01:37:03 -07004276 errno = 0;
4277 pwd = getpwuid(creds.uid);
4278 if (pwd != NULL) {
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004279 if (strcmp(pwd->pw_name, processName) == 0) {
Wink Savillef4c4d362009-04-02 01:37:03 -07004280 is_phone_socket = 1;
4281 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08004282 RLOGE("RILD can't accept socket from process %s", pwd->pw_name);
Wink Savillef4c4d362009-04-02 01:37:03 -07004283 }
4284 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08004285 RLOGE("Error on getpwuid() errno: %d", errno);
Wink Savillef4c4d362009-04-02 01:37:03 -07004286 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004287 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08004288 RLOGD("Error on getsockopt() errno: %d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004289 }
4290
Etan Cohend3652192014-06-20 08:28:44 -07004291 if (!is_phone_socket) {
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004292 RLOGE("RILD must accept socket from %s", processName);
Wink Saville7f856802009-06-09 10:23:37 -07004293
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004294 close(fdCommand);
4295 fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004296
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004297 if(NULL == sapSocket) {
4298 onCommandsSocketClosed(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004299
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004300 /* start listening for new connections again */
4301 rilEventAddWakeup(p_info->listen_event);
4302 } else {
4303 sapSocket->onCommandsSocketClosed();
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004304
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004305 /* start listening for new connections again */
4306 rilEventAddWakeup(sapSocket->getListenEvent());
4307 }
4308
4309 return;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004310 }
4311
Etan Cohend3652192014-06-20 08:28:44 -07004312 ret = fcntl(fdCommand, F_SETFL, O_NONBLOCK);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004313
4314 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004315 RLOGE ("Error setting O_NONBLOCK errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004316 }
4317
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004318 if(NULL == sapSocket) {
4319 RLOGI("libril: new connection to %s", rilSocketIdToString(p_info->socket_id));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004320
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004321 p_info->fdCommand = fdCommand;
4322 p_rs = record_stream_new(p_info->fdCommand, MAX_COMMAND_BYTES);
4323 p_info->p_rs = p_rs;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004324
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004325 ril_event_set (p_info->commands_event, p_info->fdCommand, 1,
Etan Cohend3652192014-06-20 08:28:44 -07004326 p_info->processCommandsCallback, p_info);
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004327 rilEventAddWakeup (p_info->commands_event);
Etan Cohend3652192014-06-20 08:28:44 -07004328
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004329 onNewCommandConnect(p_info->socket_id);
4330 } else {
4331 RLOGI("libril: new connection");
Etan Cohend3652192014-06-20 08:28:44 -07004332
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004333 sapSocket->setCommandFd(fdCommand);
4334 p_rs = record_stream_new(sapSocket->getCommandFd(), MAX_COMMAND_BYTES);
4335 sClient = new socketClient(sapSocket,p_rs);
4336 ril_event_set (sapSocket->getCallbackEvent(), sapSocket->getCommandFd(), 1,
4337 sapSocket->getCommandCb(), sClient);
4338
4339 rilEventAddWakeup(sapSocket->getCallbackEvent());
4340 sapSocket->onNewCommandConnect();
4341 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004342}
4343
4344static void freeDebugCallbackArgs(int number, char **args) {
4345 for (int i = 0; i < number; i++) {
4346 if (args[i] != NULL) {
4347 free(args[i]);
4348 }
4349 }
4350 free(args);
4351}
4352
Wink Savillef4c4d362009-04-02 01:37:03 -07004353static void debugCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004354 int acceptFD, option;
4355 struct sockaddr_un peeraddr;
4356 socklen_t socklen = sizeof (peeraddr);
4357 int data;
4358 unsigned int qxdm_data[6];
4359 const char *deactData[1] = {"1"};
4360 char *actData[1];
4361 RIL_Dial dialData;
4362 int hangupData[1] = {1};
4363 int number;
4364 char **args;
Etan Cohend3652192014-06-20 08:28:44 -07004365 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
4366 int sim_id = 0;
4367
4368 RLOGI("debugCallback for socket %s", rilSocketIdToString(socket_id));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004369
4370 acceptFD = accept (fd, (sockaddr *) &peeraddr, &socklen);
4371
4372 if (acceptFD < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004373 RLOGE ("error accepting on debug port: %d\n", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004374 return;
4375 }
4376
4377 if (recv(acceptFD, &number, sizeof(int), 0) != sizeof(int)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004378 RLOGE ("error reading on socket: number of Args: \n");
Sanket Padawe55227b52016-02-29 10:09:26 -08004379 close(acceptFD);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004380 return;
4381 }
Sanket Padawe55227b52016-02-29 10:09:26 -08004382
Sanket Padawe0cfc5532016-03-07 17:12:19 -08004383 if (number < 0) {
4384 RLOGE ("Invalid number of arguments: \n");
4385 close(acceptFD);
4386 return;
4387 }
4388
4389 args = (char **) calloc(number, sizeof(char*));
Sanket Padawe55227b52016-02-29 10:09:26 -08004390 if (args == NULL) {
4391 RLOGE("Memory allocation failed for debug args");
4392 close(acceptFD);
4393 return;
4394 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004395
4396 for (int i = 0; i < number; i++) {
4397 int len;
4398 if (recv(acceptFD, &len, sizeof(int), 0) != sizeof(int)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004399 RLOGE ("error reading on socket: Len of Args: \n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004400 freeDebugCallbackArgs(i, args);
Sanket Padawe55227b52016-02-29 10:09:26 -08004401 close(acceptFD);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004402 return;
4403 }
Sanket Padawe0cfc5532016-03-07 17:12:19 -08004404 if (len == INT_MAX || len < 0) {
4405 RLOGE("Invalid value of len: \n");
4406 freeDebugCallbackArgs(i, args);
4407 close(acceptFD);
4408 return;
4409 }
Sanket Padawe55227b52016-02-29 10:09:26 -08004410
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004411 // +1 for null-term
Sanket Padawe0cfc5532016-03-07 17:12:19 -08004412 args[i] = (char *) calloc(len + 1, sizeof(char));
Sanket Padawe55227b52016-02-29 10:09:26 -08004413 if (args[i] == NULL) {
4414 RLOGE("Memory allocation failed for debug args");
4415 freeDebugCallbackArgs(i, args);
4416 close(acceptFD);
4417 return;
4418 }
Wink Saville7f856802009-06-09 10:23:37 -07004419 if (recv(acceptFD, args[i], sizeof(char) * len, 0)
Wink Saville1b5fd232009-04-22 14:50:00 -07004420 != (int)sizeof(char) * len) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004421 RLOGE ("error reading on socket: Args[%d] \n", i);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004422 freeDebugCallbackArgs(i, args);
Sanket Padawe55227b52016-02-29 10:09:26 -08004423 close(acceptFD);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004424 return;
4425 }
4426 char * buf = args[i];
4427 buf[len] = 0;
Etan Cohend3652192014-06-20 08:28:44 -07004428 if ((i+1) == number) {
4429 /* The last argument should be sim id 0(SIM1)~3(SIM4) */
4430 sim_id = atoi(args[i]);
4431 switch (sim_id) {
4432 case 0:
4433 socket_id = RIL_SOCKET_1;
4434 break;
4435 #if (SIM_COUNT >= 2)
4436 case 1:
4437 socket_id = RIL_SOCKET_2;
4438 break;
4439 #endif
4440 #if (SIM_COUNT >= 3)
4441 case 2:
4442 socket_id = RIL_SOCKET_3;
4443 break;
4444 #endif
4445 #if (SIM_COUNT >= 4)
4446 case 3:
4447 socket_id = RIL_SOCKET_4;
4448 break;
4449 #endif
4450 default:
4451 socket_id = RIL_SOCKET_1;
4452 break;
4453 }
4454 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004455 }
4456
4457 switch (atoi(args[0])) {
4458 case 0:
Wink Saville8eb2a122012-11-19 16:05:13 -08004459 RLOGI ("Connection on debug port: issuing reset.");
Etan Cohend3652192014-06-20 08:28:44 -07004460 issueLocalRequest(RIL_REQUEST_RESET_RADIO, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004461 break;
4462 case 1:
Wink Saville8eb2a122012-11-19 16:05:13 -08004463 RLOGI ("Connection on debug port: issuing radio power off.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004464 data = 0;
Etan Cohend3652192014-06-20 08:28:44 -07004465 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004466 // Close the socket
Etan Cohend3652192014-06-20 08:28:44 -07004467 if (socket_id == RIL_SOCKET_1 && s_ril_param_socket.fdCommand > 0) {
4468 close(s_ril_param_socket.fdCommand);
4469 s_ril_param_socket.fdCommand = -1;
4470 }
4471 #if (SIM_COUNT == 2)
4472 else if (socket_id == RIL_SOCKET_2 && s_ril_param_socket2.fdCommand > 0) {
4473 close(s_ril_param_socket2.fdCommand);
4474 s_ril_param_socket2.fdCommand = -1;
4475 }
4476 #endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004477 break;
4478 case 2:
Wink Saville8eb2a122012-11-19 16:05:13 -08004479 RLOGI ("Debug port: issuing unsolicited voice network change.");
Etan Cohend3652192014-06-20 08:28:44 -07004480 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004481 break;
4482 case 3:
Wink Saville8eb2a122012-11-19 16:05:13 -08004483 RLOGI ("Debug port: QXDM log enable.");
Xia Wangd855ef42010-07-27 17:26:55 -07004484 qxdm_data[0] = 65536; // head.func_tag
4485 qxdm_data[1] = 16; // head.len
4486 qxdm_data[2] = 1; // mode: 1 for 'start logging'
4487 qxdm_data[3] = 32; // log_file_size: 32megabytes
4488 qxdm_data[4] = 0; // log_mask
4489 qxdm_data[5] = 8; // log_max_fileindex
Wink Saville7f856802009-06-09 10:23:37 -07004490 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Etan Cohend3652192014-06-20 08:28:44 -07004491 6 * sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004492 break;
4493 case 4:
Wink Saville8eb2a122012-11-19 16:05:13 -08004494 RLOGI ("Debug port: QXDM log disable.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004495 qxdm_data[0] = 65536;
4496 qxdm_data[1] = 16;
Xia Wangd855ef42010-07-27 17:26:55 -07004497 qxdm_data[2] = 0; // mode: 0 for 'stop logging'
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004498 qxdm_data[3] = 32;
4499 qxdm_data[4] = 0;
Xia Wangd855ef42010-07-27 17:26:55 -07004500 qxdm_data[5] = 8;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004501 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Etan Cohend3652192014-06-20 08:28:44 -07004502 6 * sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004503 break;
4504 case 5:
Wink Saville8eb2a122012-11-19 16:05:13 -08004505 RLOGI("Debug port: Radio On");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004506 data = 1;
Etan Cohend3652192014-06-20 08:28:44 -07004507 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004508 sleep(2);
4509 // Set network selection automatic.
Etan Cohend3652192014-06-20 08:28:44 -07004510 issueLocalRequest(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004511 break;
4512 case 6:
Wink Saville8eb2a122012-11-19 16:05:13 -08004513 RLOGI("Debug port: Setup Data Call, Apn :%s\n", args[1]);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004514 actData[0] = args[1];
Wink Saville7f856802009-06-09 10:23:37 -07004515 issueLocalRequest(RIL_REQUEST_SETUP_DATA_CALL, &actData,
Etan Cohend3652192014-06-20 08:28:44 -07004516 sizeof(actData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004517 break;
4518 case 7:
Wink Saville8eb2a122012-11-19 16:05:13 -08004519 RLOGI("Debug port: Deactivate Data Call");
Wink Saville7f856802009-06-09 10:23:37 -07004520 issueLocalRequest(RIL_REQUEST_DEACTIVATE_DATA_CALL, &deactData,
Etan Cohend3652192014-06-20 08:28:44 -07004521 sizeof(deactData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004522 break;
4523 case 8:
Wink Saville8eb2a122012-11-19 16:05:13 -08004524 RLOGI("Debug port: Dial Call");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004525 dialData.clir = 0;
4526 dialData.address = args[1];
Etan Cohend3652192014-06-20 08:28:44 -07004527 issueLocalRequest(RIL_REQUEST_DIAL, &dialData, sizeof(dialData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004528 break;
4529 case 9:
Wink Saville8eb2a122012-11-19 16:05:13 -08004530 RLOGI("Debug port: Answer Call");
Etan Cohend3652192014-06-20 08:28:44 -07004531 issueLocalRequest(RIL_REQUEST_ANSWER, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004532 break;
4533 case 10:
Wink Saville8eb2a122012-11-19 16:05:13 -08004534 RLOGI("Debug port: End Call");
Wink Saville7f856802009-06-09 10:23:37 -07004535 issueLocalRequest(RIL_REQUEST_HANGUP, &hangupData,
Etan Cohend3652192014-06-20 08:28:44 -07004536 sizeof(hangupData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004537 break;
4538 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004539 RLOGE ("Invalid request");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004540 break;
4541 }
4542 freeDebugCallbackArgs(number, args);
4543 close(acceptFD);
4544}
4545
4546
Wink Savillef4c4d362009-04-02 01:37:03 -07004547static void userTimerCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004548 UserCallbackInfo *p_info;
4549
4550 p_info = (UserCallbackInfo *)param;
4551
4552 p_info->p_callback(p_info->userParam);
4553
4554
4555 // FIXME generalize this...there should be a cancel mechanism
4556 if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) {
4557 s_last_wake_timeout_info = NULL;
4558 }
4559
4560 free(p_info);
4561}
4562
4563
4564static void *
Wink Savillef4c4d362009-04-02 01:37:03 -07004565eventLoop(void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004566 int ret;
4567 int filedes[2];
4568
4569 ril_event_init();
4570
4571 pthread_mutex_lock(&s_startupMutex);
4572
4573 s_started = 1;
4574 pthread_cond_broadcast(&s_startupCond);
4575
4576 pthread_mutex_unlock(&s_startupMutex);
4577
4578 ret = pipe(filedes);
4579
4580 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004581 RLOGE("Error in pipe() errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004582 return NULL;
4583 }
4584
4585 s_fdWakeupRead = filedes[0];
4586 s_fdWakeupWrite = filedes[1];
4587
4588 fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK);
4589
4590 ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,
4591 processWakeupCallback, NULL);
4592
4593 rilEventAddWakeup (&s_wakeupfd_event);
4594
4595 // Only returns on error
4596 ril_event_loop();
Wink Saville8eb2a122012-11-19 16:05:13 -08004597 RLOGE ("error in event_loop_base errno:%d", errno);
Kazuhiro Ondo5cdc1352011-10-14 17:50:58 -05004598 // kill self to restart on error
4599 kill(0, SIGKILL);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004600
4601 return NULL;
4602}
4603
Wink Saville7f856802009-06-09 10:23:37 -07004604extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07004605RIL_startEventLoop(void) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004606 /* spin up eventLoop thread and wait for it to get started */
4607 s_started = 0;
4608 pthread_mutex_lock(&s_startupMutex);
4609
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004610 pthread_attr_t attr;
4611 pthread_attr_init(&attr);
Wink Saville7f856802009-06-09 10:23:37 -07004612 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004613
Elliott Hughesfd81e712014-01-06 12:46:02 -08004614 int result = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
4615 if (result != 0) {
4616 RLOGE("Failed to create dispatch thread: %s", strerror(result));
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004617 goto done;
4618 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004619
4620 while (s_started == 0) {
4621 pthread_cond_wait(&s_startupCond, &s_startupMutex);
4622 }
4623
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004624done:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004625 pthread_mutex_unlock(&s_startupMutex);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004626}
4627
4628// Used for testing purpose only.
4629extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) {
4630 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4631}
4632
Etan Cohend3652192014-06-20 08:28:44 -07004633static void startListen(RIL_SOCKET_ID socket_id, SocketListenParam* socket_listen_p) {
4634 int fdListen = -1;
4635 int ret;
4636 char socket_name[10];
4637
4638 memset(socket_name, 0, sizeof(char)*10);
4639
4640 switch(socket_id) {
4641 case RIL_SOCKET_1:
4642 strncpy(socket_name, RIL_getRilSocketName(), 9);
4643 break;
4644 #if (SIM_COUNT >= 2)
4645 case RIL_SOCKET_2:
4646 strncpy(socket_name, SOCKET2_NAME_RIL, 9);
4647 break;
4648 #endif
4649 #if (SIM_COUNT >= 3)
4650 case RIL_SOCKET_3:
4651 strncpy(socket_name, SOCKET3_NAME_RIL, 9);
4652 break;
4653 #endif
4654 #if (SIM_COUNT >= 4)
4655 case RIL_SOCKET_4:
4656 strncpy(socket_name, SOCKET4_NAME_RIL, 9);
4657 break;
4658 #endif
4659 default:
4660 RLOGE("Socket id is wrong!!");
4661 return;
4662 }
4663
4664 RLOGI("Start to listen %s", rilSocketIdToString(socket_id));
4665
4666 fdListen = android_get_control_socket(socket_name);
4667 if (fdListen < 0) {
4668 RLOGE("Failed to get socket %s", socket_name);
4669 exit(-1);
4670 }
4671
4672 ret = listen(fdListen, 4);
4673
4674 if (ret < 0) {
4675 RLOGE("Failed to listen on control socket '%d': %s",
4676 fdListen, strerror(errno));
4677 exit(-1);
4678 }
4679 socket_listen_p->fdListen = fdListen;
4680
4681 /* note: non-persistent so we can accept only one connection at a time */
4682 ril_event_set (socket_listen_p->listen_event, fdListen, false,
4683 listenCallback, socket_listen_p);
4684
4685 rilEventAddWakeup (socket_listen_p->listen_event);
4686}
4687
Wink Saville7f856802009-06-09 10:23:37 -07004688extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07004689RIL_register (const RIL_RadioFunctions *callbacks) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004690 int ret;
4691 int flags;
4692
Etan Cohend3652192014-06-20 08:28:44 -07004693 RLOGI("SIM_COUNT: %d", SIM_COUNT);
4694
Wink Saville43808972011-01-13 17:39:51 -08004695 if (callbacks == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004696 RLOGE("RIL_register: RIL_RadioFunctions * null");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004697 return;
4698 }
Wink Saville43808972011-01-13 17:39:51 -08004699 if (callbacks->version < RIL_VERSION_MIN) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004700 RLOGE("RIL_register: version %d is to old, min version is %d",
Wink Saville43808972011-01-13 17:39:51 -08004701 callbacks->version, RIL_VERSION_MIN);
4702 return;
Wink Saville3a4840b2010-04-07 13:29:58 -07004703 }
Sanket Padawe4c05f352016-01-26 16:19:00 -08004704
Wink Saville8eb2a122012-11-19 16:05:13 -08004705 RLOGE("RIL_register: RIL version %d", callbacks->version);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004706
4707 if (s_registerCalled > 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004708 RLOGE("RIL_register has been called more than once. "
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004709 "Subsequent call ignored");
4710 return;
4711 }
4712
4713 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4714
Etan Cohend3652192014-06-20 08:28:44 -07004715 /* Initialize socket1 parameters */
4716 s_ril_param_socket = {
4717 RIL_SOCKET_1, /* socket_id */
4718 -1, /* fdListen */
4719 -1, /* fdCommand */
4720 PHONE_PROCESS, /* processName */
4721 &s_commands_event, /* commands_event */
4722 &s_listen_event, /* listen_event */
4723 processCommandsCallback, /* processCommandsCallback */
Meng Wangef966a32016-06-20 17:38:18 -07004724 NULL, /* p_rs */
4725 RIL_TELEPHONY_SOCKET /* type */
Etan Cohend3652192014-06-20 08:28:44 -07004726 };
4727
4728#if (SIM_COUNT >= 2)
4729 s_ril_param_socket2 = {
4730 RIL_SOCKET_2, /* socket_id */
4731 -1, /* fdListen */
4732 -1, /* fdCommand */
4733 PHONE_PROCESS, /* processName */
4734 &s_commands_event_socket2, /* commands_event */
4735 &s_listen_event_socket2, /* listen_event */
4736 processCommandsCallback, /* processCommandsCallback */
Meng Wangef966a32016-06-20 17:38:18 -07004737 NULL, /* p_rs */
4738 RIL_TELEPHONY_SOCKET /* type */
Etan Cohend3652192014-06-20 08:28:44 -07004739 };
4740#endif
4741
4742#if (SIM_COUNT >= 3)
4743 s_ril_param_socket3 = {
4744 RIL_SOCKET_3, /* socket_id */
4745 -1, /* fdListen */
4746 -1, /* fdCommand */
4747 PHONE_PROCESS, /* processName */
4748 &s_commands_event_socket3, /* commands_event */
4749 &s_listen_event_socket3, /* listen_event */
4750 processCommandsCallback, /* processCommandsCallback */
Meng Wangef966a32016-06-20 17:38:18 -07004751 NULL, /* p_rs */
4752 RIL_TELEPHONY_SOCKET /* type */
Etan Cohend3652192014-06-20 08:28:44 -07004753 };
4754#endif
4755
4756#if (SIM_COUNT >= 4)
4757 s_ril_param_socket4 = {
4758 RIL_SOCKET_4, /* socket_id */
4759 -1, /* fdListen */
4760 -1, /* fdCommand */
4761 PHONE_PROCESS, /* processName */
4762 &s_commands_event_socket4, /* commands_event */
4763 &s_listen_event_socket4, /* listen_event */
4764 processCommandsCallback, /* processCommandsCallback */
Meng Wangef966a32016-06-20 17:38:18 -07004765 NULL, /* p_rs */
4766 RIL_TELEPHONY_SOCKET /* type */
Etan Cohend3652192014-06-20 08:28:44 -07004767 };
4768#endif
4769
4770
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004771 s_registerCalled = 1;
4772
Etan Cohend3652192014-06-20 08:28:44 -07004773 RLOGI("s_registerCalled flag set, %d", s_started);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004774 // Little self-check
4775
Wink Savillef4c4d362009-04-02 01:37:03 -07004776 for (int i = 0; i < (int)NUM_ELEMS(s_commands); i++) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004777 assert(i == s_commands[i].requestNumber);
4778 }
4779
Wink Savillef4c4d362009-04-02 01:37:03 -07004780 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses); i++) {
Wink Saville7f856802009-06-09 10:23:37 -07004781 assert(i + RIL_UNSOL_RESPONSE_BASE
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004782 == s_unsolResponses[i].requestNumber);
4783 }
4784
4785 // New rild impl calls RIL_startEventLoop() first
4786 // old standalone impl wants it here.
4787
4788 if (s_started == 0) {
4789 RIL_startEventLoop();
4790 }
4791
Etan Cohend3652192014-06-20 08:28:44 -07004792 // start listen socket1
4793 startListen(RIL_SOCKET_1, &s_ril_param_socket);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004794
Etan Cohend3652192014-06-20 08:28:44 -07004795#if (SIM_COUNT >= 2)
4796 // start listen socket2
4797 startListen(RIL_SOCKET_2, &s_ril_param_socket2);
4798#endif /* (SIM_COUNT == 2) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004799
Etan Cohend3652192014-06-20 08:28:44 -07004800#if (SIM_COUNT >= 3)
4801 // start listen socket3
4802 startListen(RIL_SOCKET_3, &s_ril_param_socket3);
4803#endif /* (SIM_COUNT == 3) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004804
Etan Cohend3652192014-06-20 08:28:44 -07004805#if (SIM_COUNT >= 4)
4806 // start listen socket4
4807 startListen(RIL_SOCKET_4, &s_ril_param_socket4);
4808#endif /* (SIM_COUNT == 4) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004809
Amit Mahajan18fe36b2016-08-25 11:19:21 -07004810 RLOGI("RILHIDL calling registerService");
4811 radio::registerService(&s_callbacks, s_commands);
4812 RLOGI("RILHIDL called registerService");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004813
4814#if 1
4815 // start debug interface socket
4816
Etan Cohend3652192014-06-20 08:28:44 -07004817 char *inst = NULL;
4818 if (strlen(RIL_getRilSocketName()) >= strlen(SOCKET_NAME_RIL)) {
4819 inst = RIL_getRilSocketName() + strlen(SOCKET_NAME_RIL);
4820 }
4821
4822 char rildebug[MAX_DEBUG_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL_DEBUG;
4823 if (inst != NULL) {
Nick Kralevichc52e45e2015-02-08 07:54:16 -08004824 strlcat(rildebug, inst, MAX_DEBUG_SOCKET_NAME_LENGTH);
Etan Cohend3652192014-06-20 08:28:44 -07004825 }
4826
4827 s_fdDebug = android_get_control_socket(rildebug);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004828 if (s_fdDebug < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07004829 RLOGE("Failed to get socket : %s errno:%d", rildebug, errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004830 exit(-1);
4831 }
4832
4833 ret = listen(s_fdDebug, 4);
4834
4835 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004836 RLOGE("Failed to listen on ril debug socket '%d': %s",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004837 s_fdDebug, strerror(errno));
4838 exit(-1);
4839 }
4840
4841 ril_event_set (&s_debug_event, s_fdDebug, true,
4842 debugCallback, NULL);
4843
4844 rilEventAddWakeup (&s_debug_event);
4845#endif
4846
4847}
4848
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004849extern "C" void
Amit Mahajan18fe36b2016-08-25 11:19:21 -07004850RIL_register_socket (RIL_RadioFunctions *(*Init)(const struct RIL_Env *, int, char **),
4851 RIL_SOCKET_TYPE socketType, int argc, char **argv) {
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004852
4853 RIL_RadioFunctions* UimFuncs = NULL;
4854
4855 if(Init) {
4856 UimFuncs = Init(&RilSapSocket::uimRilEnv, argc, argv);
4857
4858 switch(socketType) {
4859 case RIL_SAP_SOCKET:
4860 RilSapSocket::initSapSocket("sap_uim_socket1", UimFuncs);
4861
4862#if (SIM_COUNT >= 2)
4863 RilSapSocket::initSapSocket("sap_uim_socket2", UimFuncs);
4864#endif
4865
4866#if (SIM_COUNT >= 3)
4867 RilSapSocket::initSapSocket("sap_uim_socket3", UimFuncs);
4868#endif
4869
4870#if (SIM_COUNT >= 4)
4871 RilSapSocket::initSapSocket("sap_uim_socket4", UimFuncs);
4872#endif
Meng Wangef966a32016-06-20 17:38:18 -07004873 break;
4874 default:;
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004875 }
4876 }
4877}
4878
Sanket Padawe6ff9a872016-01-27 15:09:12 -08004879// Check and remove RequestInfo if its a response and not just ack sent back
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004880static int
Sanket Padawe6ff9a872016-01-27 15:09:12 -08004881checkAndDequeueRequestInfoIfAck(struct RequestInfo *pRI, bool isAck) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004882 int ret = 0;
Etan Cohend3652192014-06-20 08:28:44 -07004883 /* Hook for current context
4884 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
4885 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
4886 /* pendingRequestsHook refer to &s_pendingRequests */
4887 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
Wink Saville7f856802009-06-09 10:23:37 -07004888
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004889 if (pRI == NULL) {
4890 return 0;
4891 }
4892
Etan Cohend3652192014-06-20 08:28:44 -07004893#if (SIM_COUNT >= 2)
4894 if (pRI->socket_id == RIL_SOCKET_2) {
4895 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
4896 pendingRequestsHook = &s_pendingRequests_socket2;
4897 }
4898#if (SIM_COUNT >= 3)
4899 if (pRI->socket_id == RIL_SOCKET_3) {
4900 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
4901 pendingRequestsHook = &s_pendingRequests_socket3;
4902 }
4903#endif
4904#if (SIM_COUNT >= 4)
4905 if (pRI->socket_id == RIL_SOCKET_4) {
4906 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
4907 pendingRequestsHook = &s_pendingRequests_socket4;
4908 }
4909#endif
4910#endif
4911 pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004912
Etan Cohend3652192014-06-20 08:28:44 -07004913 for(RequestInfo **ppCur = pendingRequestsHook
Wink Saville7f856802009-06-09 10:23:37 -07004914 ; *ppCur != NULL
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004915 ; ppCur = &((*ppCur)->p_next)
4916 ) {
4917 if (pRI == *ppCur) {
4918 ret = 1;
Sanket Padawe6ff9a872016-01-27 15:09:12 -08004919 if (isAck) { // Async ack
4920 if (pRI->wasAckSent == 1) {
4921 RLOGD("Ack was already sent for %s", requestToString(pRI->pCI->requestNumber));
4922 } else {
4923 pRI->wasAckSent = 1;
4924 }
4925 } else {
4926 *ppCur = (*ppCur)->p_next;
4927 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004928 break;
4929 }
4930 }
4931
Etan Cohend3652192014-06-20 08:28:44 -07004932 pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004933
4934 return ret;
4935}
4936
Sanket Padawe6ff9a872016-01-27 15:09:12 -08004937static int findFd(int socket_id) {
Etan Cohend3652192014-06-20 08:28:44 -07004938 int fd = s_ril_param_socket.fdCommand;
Etan Cohend3652192014-06-20 08:28:44 -07004939#if (SIM_COUNT >= 2)
4940 if (socket_id == RIL_SOCKET_2) {
4941 fd = s_ril_param_socket2.fdCommand;
4942 }
4943#if (SIM_COUNT >= 3)
Sanket Padawe6ff9a872016-01-27 15:09:12 -08004944 if (socket_id == RIL_SOCKET_3) {
4945 fd = s_ril_param_socket3.fdCommand;
4946 }
Etan Cohend3652192014-06-20 08:28:44 -07004947#endif
4948#if (SIM_COUNT >= 4)
4949 if (socket_id == RIL_SOCKET_4) {
4950 fd = s_ril_param_socket4.fdCommand;
4951 }
4952#endif
4953#endif
Sanket Padawe6ff9a872016-01-27 15:09:12 -08004954 return fd;
4955}
4956
4957extern "C" void
4958RIL_onRequestAck(RIL_Token t) {
4959 RequestInfo *pRI;
4960 int ret, fd;
4961
4962 size_t errorOffset;
4963 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
4964
4965 pRI = (RequestInfo *)t;
4966
4967 if (!checkAndDequeueRequestInfoIfAck(pRI, true)) {
4968 RLOGE ("RIL_onRequestAck: invalid RIL_Token");
4969 return;
4970 }
4971
4972 socket_id = pRI->socket_id;
4973 fd = findFd(socket_id);
4974
4975#if VDBG
4976 RLOGD("Request Ack, %s", rilSocketIdToString(socket_id));
4977#endif
4978
4979 appendPrintBuf("Ack [%04d]< %s", pRI->token, requestToString(pRI->pCI->requestNumber));
4980
4981 if (pRI->cancelled == 0) {
4982 Parcel p;
4983
4984 p.writeInt32 (RESPONSE_SOLICITED_ACK);
4985 p.writeInt32 (pRI->token);
4986
4987 if (fd < 0) {
4988 RLOGD ("RIL onRequestComplete: Command channel closed");
4989 }
4990
4991 sendResponse(p, socket_id);
4992 }
4993}
Sanket Padawe6ff9a872016-01-27 15:09:12 -08004994extern "C" void
4995RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) {
4996 RequestInfo *pRI;
4997 int ret;
4998 int fd;
4999 size_t errorOffset;
5000 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
5001
5002 pRI = (RequestInfo *)t;
5003
5004 if (!checkAndDequeueRequestInfoIfAck(pRI, false)) {
5005 RLOGE ("RIL_onRequestComplete: invalid RIL_Token");
5006 return;
5007 }
5008
5009 socket_id = pRI->socket_id;
5010 fd = findFd(socket_id);
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07005011#if VDBG
Etan Cohend3652192014-06-20 08:28:44 -07005012 RLOGD("RequestComplete, %s", rilSocketIdToString(socket_id));
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07005013#endif
Etan Cohend3652192014-06-20 08:28:44 -07005014
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005015 if (pRI->local > 0) {
5016 // Locally issued command...void only!
5017 // response does not go back up the command socket
Wink Saville8eb2a122012-11-19 16:05:13 -08005018 RLOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005019
5020 goto done;
5021 }
5022
5023 appendPrintBuf("[%04d]< %s",
5024 pRI->token, requestToString(pRI->pCI->requestNumber));
5025
5026 if (pRI->cancelled == 0) {
5027 Parcel p;
5028
Amit Mahajan18fe36b2016-08-25 11:19:21 -07005029 int responseType;
Sanket Padawe6ff9a872016-01-27 15:09:12 -08005030 if (s_callbacks.version >= 13 && pRI->wasAckSent == 1) {
5031 // If ack was already sent, then this call is an asynchronous response. So we need to
5032 // send id indicating that we expect an ack from RIL.java as we acquire wakelock here.
Amit Mahajan18fe36b2016-08-25 11:19:21 -07005033 responseType = RESPONSE_SOLICITED_ACK_EXP;
Sanket Padawe6ff9a872016-01-27 15:09:12 -08005034 grabPartialWakeLock();
5035 } else {
Amit Mahajan18fe36b2016-08-25 11:19:21 -07005036 responseType = RESPONSE_SOLICITED;
Sanket Padawe6ff9a872016-01-27 15:09:12 -08005037 }
Amit Mahajan18fe36b2016-08-25 11:19:21 -07005038 p.writeInt32 (responseType);
5039
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005040 p.writeInt32 (pRI->token);
5041 errorOffset = p.dataPosition();
5042
5043 p.writeInt32 (e);
5044
johnwangb2a61842009-06-02 14:55:45 -07005045 if (response != NULL) {
5046 // there is a response payload, no matter success or not.
Amit Mahajan18fe36b2016-08-25 11:19:21 -07005047 RLOGE ("Calling responseFunction() for token %d", pRI->token);
5048 ret = pRI->pCI->responseFunction(p, (int) socket_id, pRI->pCI->requestNumber,
5049 responseType, pRI->token, e, response, responselen);
5050
5051 if (pRI->pCI->requestNumber == RIL_REQUEST_GET_SIM_STATUS) {
5052 return;
5053 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005054
5055 /* if an error occurred, rewind and mark it */
5056 if (ret != 0) {
Etan Cohend3652192014-06-20 08:28:44 -07005057 RLOGE ("responseFunction error, ret %d", ret);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005058 p.setDataPosition(errorOffset);
5059 p.writeInt32 (ret);
5060 }
johnwangb2a61842009-06-02 14:55:45 -07005061 }
5062
5063 if (e != RIL_E_SUCCESS) {
5064 appendPrintBuf("%s fails by %s", printBuf, failCauseToString(e));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005065 }
5066
Etan Cohend3652192014-06-20 08:28:44 -07005067 if (fd < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08005068 RLOGD ("RIL onRequestComplete: Command channel closed");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005069 }
Etan Cohend3652192014-06-20 08:28:44 -07005070 sendResponse(p, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005071 }
5072
5073done:
5074 free(pRI);
5075}
5076
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005077static void
Wink Savillef4c4d362009-04-02 01:37:03 -07005078grabPartialWakeLock() {
Sanket Padawe6ff9a872016-01-27 15:09:12 -08005079 if (s_callbacks.version >= 13) {
5080 int ret;
5081 ret = pthread_mutex_lock(&s_wakeLockCountMutex);
5082 assert(ret == 0);
5083 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
Sanket Padawe55227b52016-02-29 10:09:26 -08005084
5085 UserCallbackInfo *p_info =
5086 internalRequestTimedCallback(wakeTimeoutCallback, NULL, &TIMEVAL_WAKE_TIMEOUT);
5087 if (p_info == NULL) {
5088 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
5089 } else {
5090 s_wakelock_count++;
5091 if (s_last_wake_timeout_info != NULL) {
5092 s_last_wake_timeout_info->userParam = (void *)1;
5093 }
5094 s_last_wake_timeout_info = p_info;
Sanket Padawe6ff9a872016-01-27 15:09:12 -08005095 }
Sanket Padawe6ff9a872016-01-27 15:09:12 -08005096 ret = pthread_mutex_unlock(&s_wakeLockCountMutex);
5097 assert(ret == 0);
5098 } else {
5099 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
5100 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005101}
5102
5103static void
Wink Savillef4c4d362009-04-02 01:37:03 -07005104releaseWakeLock() {
Sanket Padawe6ff9a872016-01-27 15:09:12 -08005105 if (s_callbacks.version >= 13) {
5106 int ret;
5107 ret = pthread_mutex_lock(&s_wakeLockCountMutex);
5108 assert(ret == 0);
5109
5110 if (s_wakelock_count > 1) {
5111 s_wakelock_count--;
5112 } else {
5113 s_wakelock_count = 0;
5114 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
5115 if (s_last_wake_timeout_info != NULL) {
5116 s_last_wake_timeout_info->userParam = (void *)1;
5117 }
5118 }
5119
5120 ret = pthread_mutex_unlock(&s_wakeLockCountMutex);
5121 assert(ret == 0);
5122 } else {
5123 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
5124 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005125}
5126
5127/**
5128 * Timer callback to put us back to sleep before the default timeout
5129 */
5130static void
Wink Savillef4c4d362009-04-02 01:37:03 -07005131wakeTimeoutCallback (void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005132 // We're using "param != NULL" as a cancellation mechanism
Sanket Padawe6ff9a872016-01-27 15:09:12 -08005133 if (s_callbacks.version >= 13) {
5134 if (param == NULL) {
5135 int ret;
5136 ret = pthread_mutex_lock(&s_wakeLockCountMutex);
5137 assert(ret == 0);
5138 s_wakelock_count = 0;
5139 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
5140 ret = pthread_mutex_unlock(&s_wakeLockCountMutex);
5141 assert(ret == 0);
5142 }
5143 } else {
5144 if (param == NULL) {
5145 releaseWakeLock();
5146 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005147 }
5148}
5149
Etan Cohend3652192014-06-20 08:28:44 -07005150#if defined(ANDROID_MULTI_SIM)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005151extern "C"
Bernhard Rosenkränzerd613b962014-11-17 20:52:09 +01005152void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Etan Cohend3652192014-06-20 08:28:44 -07005153 size_t datalen, RIL_SOCKET_ID socket_id)
5154#else
5155extern "C"
Bernhard Rosenkränzerd613b962014-11-17 20:52:09 +01005156void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005157 size_t datalen)
Etan Cohend3652192014-06-20 08:28:44 -07005158#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005159{
5160 int unsolResponseIndex;
5161 int ret;
5162 int64_t timeReceived = 0;
5163 bool shouldScheduleTimeout = false;
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005164 RIL_RadioState newState;
Etan Cohend3652192014-06-20 08:28:44 -07005165 RIL_SOCKET_ID soc_id = RIL_SOCKET_1;
5166
5167#if defined(ANDROID_MULTI_SIM)
5168 soc_id = socket_id;
5169#endif
5170
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005171
5172 if (s_registerCalled == 0) {
5173 // Ignore RIL_onUnsolicitedResponse before RIL_register
Wink Saville8eb2a122012-11-19 16:05:13 -08005174 RLOGW("RIL_onUnsolicitedResponse called before RIL_register");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005175 return;
5176 }
Wink Saville7f856802009-06-09 10:23:37 -07005177
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005178 unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
5179
5180 if ((unsolResponseIndex < 0)
5181 || (unsolResponseIndex >= (int32_t)NUM_ELEMS(s_unsolResponses))) {
Wink Saville8eb2a122012-11-19 16:05:13 -08005182 RLOGE("unsupported unsolicited response code %d", unsolResponse);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005183 return;
5184 }
5185
5186 // Grab a wake lock if needed for this reponse,
5187 // as we exit we'll either release it immediately
5188 // or set a timer to release it later.
5189 switch (s_unsolResponses[unsolResponseIndex].wakeType) {
5190 case WAKE_PARTIAL:
5191 grabPartialWakeLock();
5192 shouldScheduleTimeout = true;
5193 break;
5194
5195 case DONT_WAKE:
5196 default:
5197 // No wake lock is grabed so don't set timeout
5198 shouldScheduleTimeout = false;
5199 break;
5200 }
5201
5202 // Mark the time this was received, doing this
5203 // after grabing the wakelock incase getting
5204 // the elapsedRealTime might cause us to goto
5205 // sleep.
5206 if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
5207 timeReceived = elapsedRealtime();
5208 }
5209
5210 appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
5211
5212 Parcel p;
Amit Mahajan18fe36b2016-08-25 11:19:21 -07005213 int responseType;
Sanket Padawed8c0b462016-02-03 11:46:02 -08005214 if (s_callbacks.version >= 13
5215 && s_unsolResponses[unsolResponseIndex].wakeType == WAKE_PARTIAL) {
Amit Mahajan18fe36b2016-08-25 11:19:21 -07005216 responseType = RESPONSE_UNSOLICITED_ACK_EXP;
Sanket Padawed8c0b462016-02-03 11:46:02 -08005217 } else {
Amit Mahajan18fe36b2016-08-25 11:19:21 -07005218 responseType = RESPONSE_UNSOLICITED;
Sanket Padawed8c0b462016-02-03 11:46:02 -08005219 }
Amit Mahajan18fe36b2016-08-25 11:19:21 -07005220 p.writeInt32 (responseType);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005221 p.writeInt32 (unsolResponse);
5222
Amit Mahajan18fe36b2016-08-25 11:19:21 -07005223 ret = s_unsolResponses[unsolResponseIndex].responseFunction(
5224 p, (int) soc_id, unsolResponse, responseType, 0, RIL_E_SUCCESS, const_cast<void*>(data),
5225 datalen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005226 if (ret != 0) {
5227 // Problem with the response. Don't continue;
5228 goto error_exit;
5229 }
5230
5231 // some things get more payload
5232 switch(unsolResponse) {
5233 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
Naveen Kalla2baf7232016-10-11 13:49:20 -07005234 newState = CALL_ONSTATEREQUEST(soc_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005235 p.writeInt32(newState);
Naveen Kalla2baf7232016-10-11 13:49:20 -07005236 appendPrintBuf("%s {%s}", printBuf, radioStateToString(newState));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005237 break;
5238
5239
5240 case RIL_UNSOL_NITZ_TIME_RECEIVED:
5241 // Store the time that this was received so the
5242 // handler of this message can account for
5243 // the time it takes to arrive and process. In
5244 // particular the system has been known to sleep
5245 // before this message can be processed.
5246 p.writeInt64(timeReceived);
5247 break;
5248 }
5249
Sanket Padawe55227b52016-02-29 10:09:26 -08005250 if (s_callbacks.version < 13) {
5251 if (shouldScheduleTimeout) {
5252 UserCallbackInfo *p_info = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
5253 &TIMEVAL_WAKE_TIMEOUT);
5254
5255 if (p_info == NULL) {
5256 goto error_exit;
5257 } else {
5258 // Cancel the previous request
5259 if (s_last_wake_timeout_info != NULL) {
5260 s_last_wake_timeout_info->userParam = (void *)1;
5261 }
5262 s_last_wake_timeout_info = p_info;
5263 }
5264 }
5265 }
5266
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07005267#if VDBG
Amit Mahajan18fe36b2016-08-25 11:19:21 -07005268 RLOGI("%s UNSOLICITED: %s length:%d", rilSocketIdToString(soc_id),
5269 requestToString(unsolResponse), p.dataSize());
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07005270#endif
Amit Mahajan18fe36b2016-08-25 11:19:21 -07005271 ret = 0;
5272 switch (unsolResponse) {
5273 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
5274 radio::radioStateChanged(soc_id, responseType, newState);
5275 break;
5276 default:
5277 ret = sendResponse(p, soc_id);
5278 break;
5279 }
5280
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005281 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
5282
5283 // Unfortunately, NITZ time is not poll/update like everything
5284 // else in the system. So, if the upstream client isn't connected,
5285 // keep a copy of the last NITZ response (with receive time noted
5286 // above) around so we can deliver it when it is connected
5287
5288 if (s_lastNITZTimeData != NULL) {
5289 free (s_lastNITZTimeData);
5290 s_lastNITZTimeData = NULL;
5291 }
5292
Sanket Padawe0cfc5532016-03-07 17:12:19 -08005293 s_lastNITZTimeData = calloc(p.dataSize(), 1);
Sanket Padawe55227b52016-02-29 10:09:26 -08005294 if (s_lastNITZTimeData == NULL) {
5295 RLOGE("Memory allocation failed in RIL_onUnsolicitedResponse");
5296 goto error_exit;
5297 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005298 s_lastNITZTimeDataSize = p.dataSize();
5299 memcpy(s_lastNITZTimeData, p.data(), p.dataSize());
5300 }
5301
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005302 // Normal exit
5303 return;
5304
5305error_exit:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005306 if (shouldScheduleTimeout) {
5307 releaseWakeLock();
5308 }
5309}
5310
Wink Saville7f856802009-06-09 10:23:37 -07005311/** FIXME generalize this if you track UserCAllbackInfo, clear it
5312 when the callback occurs
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005313*/
5314static UserCallbackInfo *
Wink Saville7f856802009-06-09 10:23:37 -07005315internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07005316 const struct timeval *relativeTime)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005317{
5318 struct timeval myRelativeTime;
5319 UserCallbackInfo *p_info;
5320
Sanket Padawe0cfc5532016-03-07 17:12:19 -08005321 p_info = (UserCallbackInfo *) calloc(1, sizeof(UserCallbackInfo));
Sanket Padawe55227b52016-02-29 10:09:26 -08005322 if (p_info == NULL) {
5323 RLOGE("Memory allocation failed in internalRequestTimedCallback");
5324 return p_info;
5325
5326 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005327
Wink Saville7f856802009-06-09 10:23:37 -07005328 p_info->p_callback = callback;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005329 p_info->userParam = param;
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07005330
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005331 if (relativeTime == NULL) {
5332 /* treat null parameter as a 0 relative time */
5333 memset (&myRelativeTime, 0, sizeof(myRelativeTime));
5334 } else {
5335 /* FIXME I think event_add's tv param is really const anyway */
5336 memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
5337 }
5338
5339 ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
5340
5341 ril_timer_add(&(p_info->event), &myRelativeTime);
5342
5343 triggerEvLoop();
5344 return p_info;
5345}
5346
Naveen Kalla7edd07c2010-06-21 18:54:47 -07005347
5348extern "C" void
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07005349RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
5350 const struct timeval *relativeTime) {
5351 internalRequestTimedCallback (callback, param, relativeTime);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005352}
5353
5354const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07005355failCauseToString(RIL_Errno e) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005356 switch(e) {
5357 case RIL_E_SUCCESS: return "E_SUCCESS";
Robert Greenwalt2126ab22013-04-09 12:20:45 -07005358 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RADIO_NOT_AVAILABLE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005359 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
5360 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
5361 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
5362 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
5363 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
5364 case RIL_E_CANCELLED: return "E_CANCELLED";
5365 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
5366 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
5367 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
Wink Savillef4c4d362009-04-02 01:37:03 -07005368 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
John Wang75534472010-04-20 15:11:42 -07005369 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
Wink Saville7f856802009-06-09 10:23:37 -07005370#ifdef FEATURE_MULTIMODE_ANDROID
Wink Savillef4c4d362009-04-02 01:37:03 -07005371 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
5372 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
5373#endif
Sanket Padaweb39e5c92016-02-08 14:28:59 -08005374 case RIL_E_FDN_CHECK_FAILURE: return "E_FDN_CHECK_FAILURE";
5375 case RIL_E_MISSING_RESOURCE: return "E_MISSING_RESOURCE";
5376 case RIL_E_NO_SUCH_ELEMENT: return "E_NO_SUCH_ELEMENT";
5377 case RIL_E_DIAL_MODIFIED_TO_USSD: return "E_DIAL_MODIFIED_TO_USSD";
5378 case RIL_E_DIAL_MODIFIED_TO_SS: return "E_DIAL_MODIFIED_TO_SS";
5379 case RIL_E_DIAL_MODIFIED_TO_DIAL: return "E_DIAL_MODIFIED_TO_DIAL";
5380 case RIL_E_USSD_MODIFIED_TO_DIAL: return "E_USSD_MODIFIED_TO_DIAL";
5381 case RIL_E_USSD_MODIFIED_TO_SS: return "E_USSD_MODIFIED_TO_SS";
5382 case RIL_E_USSD_MODIFIED_TO_USSD: return "E_USSD_MODIFIED_TO_USSD";
5383 case RIL_E_SS_MODIFIED_TO_DIAL: return "E_SS_MODIFIED_TO_DIAL";
5384 case RIL_E_SS_MODIFIED_TO_USSD: return "E_SS_MODIFIED_TO_USSD";
5385 case RIL_E_SUBSCRIPTION_NOT_SUPPORTED: return "E_SUBSCRIPTION_NOT_SUPPORTED";
5386 case RIL_E_SS_MODIFIED_TO_SS: return "E_SS_MODIFIED_TO_SS";
5387 case RIL_E_LCE_NOT_SUPPORTED: return "E_LCE_NOT_SUPPORTED";
5388 case RIL_E_NO_MEMORY: return "E_NO_MEMORY";
5389 case RIL_E_INTERNAL_ERR: return "E_INTERNAL_ERR";
5390 case RIL_E_SYSTEM_ERR: return "E_SYSTEM_ERR";
5391 case RIL_E_MODEM_ERR: return "E_MODEM_ERR";
5392 case RIL_E_INVALID_STATE: return "E_INVALID_STATE";
5393 case RIL_E_NO_RESOURCES: return "E_NO_RESOURCES";
5394 case RIL_E_SIM_ERR: return "E_SIM_ERR";
5395 case RIL_E_INVALID_ARGUMENTS: return "E_INVALID_ARGUMENTS";
5396 case RIL_E_INVALID_SIM_STATE: return "E_INVALID_SIM_STATE";
5397 case RIL_E_INVALID_MODEM_STATE: return "E_INVALID_MODEM_STATE";
5398 case RIL_E_INVALID_CALL_ID: return "E_INVALID_CALL_ID";
5399 case RIL_E_NO_SMS_TO_ACK: return "E_NO_SMS_TO_ACK";
5400 case RIL_E_NETWORK_ERR: return "E_NETWORK_ERR";
5401 case RIL_E_REQUEST_RATE_LIMITED: return "E_REQUEST_RATE_LIMITED";
twen.changdf7add02016-03-04 18:27:48 +08005402 case RIL_E_SIM_BUSY: return "E_SIM_BUSY";
5403 case RIL_E_SIM_FULL: return "E_SIM_FULL";
5404 case RIL_E_NETWORK_REJECT: return "E_NETWORK_REJECT";
5405 case RIL_E_OPERATION_NOT_ALLOWED: return "E_OPERATION_NOT_ALLOWED";
5406 case RIL_E_EMPTY_RECORD: "E_EMPTY_RECORD";
Ajay Nambi68900f52016-03-11 12:02:55 -08005407 case RIL_E_INVALID_SMS_FORMAT: return "E_INVALID_SMS_FORMAT";
5408 case RIL_E_ENCODING_ERR: return "E_ENCODING_ERR";
5409 case RIL_E_INVALID_SMSC_ADDRESS: return "E_INVALID_SMSC_ADDRESS";
5410 case RIL_E_NO_SUCH_ENTRY: return "E_NO_SUCH_ENTRY";
5411 case RIL_E_NETWORK_NOT_READY: return "E_NETWORK_NOT_READY";
5412 case RIL_E_NOT_PROVISIONED: return "E_NOT_PROVISIONED";
Ajay Nambi10345892016-03-19 09:02:28 -07005413 case RIL_E_NO_SUBSCRIPTION: return "E_NO_SUBSCRIPTION";
5414 case RIL_E_NO_NETWORK_FOUND: return "E_NO_NETWORK_FOUND";
5415 case RIL_E_DEVICE_IN_USE: return "E_DEVICE_IN_USE";
5416 case RIL_E_ABORTED: return "E_ABORTED";
Sanket Padawe0106aed2016-02-09 09:56:31 -08005417 case RIL_E_OEM_ERROR_1: return "E_OEM_ERROR_1";
5418 case RIL_E_OEM_ERROR_2: return "E_OEM_ERROR_2";
5419 case RIL_E_OEM_ERROR_3: return "E_OEM_ERROR_3";
5420 case RIL_E_OEM_ERROR_4: return "E_OEM_ERROR_4";
5421 case RIL_E_OEM_ERROR_5: return "E_OEM_ERROR_5";
5422 case RIL_E_OEM_ERROR_6: return "E_OEM_ERROR_6";
5423 case RIL_E_OEM_ERROR_7: return "E_OEM_ERROR_7";
5424 case RIL_E_OEM_ERROR_8: return "E_OEM_ERROR_8";
5425 case RIL_E_OEM_ERROR_9: return "E_OEM_ERROR_9";
5426 case RIL_E_OEM_ERROR_10: return "E_OEM_ERROR_10";
5427 case RIL_E_OEM_ERROR_11: return "E_OEM_ERROR_11";
5428 case RIL_E_OEM_ERROR_12: return "E_OEM_ERROR_12";
5429 case RIL_E_OEM_ERROR_13: return "E_OEM_ERROR_13";
5430 case RIL_E_OEM_ERROR_14: return "E_OEM_ERROR_14";
5431 case RIL_E_OEM_ERROR_15: return "E_OEM_ERROR_15";
5432 case RIL_E_OEM_ERROR_16: return "E_OEM_ERROR_16";
5433 case RIL_E_OEM_ERROR_17: return "E_OEM_ERROR_17";
5434 case RIL_E_OEM_ERROR_18: return "E_OEM_ERROR_18";
5435 case RIL_E_OEM_ERROR_19: return "E_OEM_ERROR_19";
5436 case RIL_E_OEM_ERROR_20: return "E_OEM_ERROR_20";
5437 case RIL_E_OEM_ERROR_21: return "E_OEM_ERROR_21";
5438 case RIL_E_OEM_ERROR_22: return "E_OEM_ERROR_22";
5439 case RIL_E_OEM_ERROR_23: return "E_OEM_ERROR_23";
5440 case RIL_E_OEM_ERROR_24: return "E_OEM_ERROR_24";
5441 case RIL_E_OEM_ERROR_25: return "E_OEM_ERROR_25";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005442 default: return "<unknown error>";
5443 }
5444}
5445
5446const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07005447radioStateToString(RIL_RadioState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005448 switch(s) {
5449 case RADIO_STATE_OFF: return "RADIO_OFF";
5450 case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005451 case RADIO_STATE_ON:return"RADIO_ON";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005452 default: return "<unknown state>";
5453 }
5454}
5455
5456const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07005457callStateToString(RIL_CallState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005458 switch(s) {
5459 case RIL_CALL_ACTIVE : return "ACTIVE";
5460 case RIL_CALL_HOLDING: return "HOLDING";
5461 case RIL_CALL_DIALING: return "DIALING";
5462 case RIL_CALL_ALERTING: return "ALERTING";
5463 case RIL_CALL_INCOMING: return "INCOMING";
5464 case RIL_CALL_WAITING: return "WAITING";
5465 default: return "<unknown state>";
5466 }
5467}
5468
5469const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07005470requestToString(int request) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005471/*
5472 cat libs/telephony/ril_commands.h \
5473 | egrep "^ *{RIL_" \
5474 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
5475
5476
5477 cat libs/telephony/ril_unsol_commands.h \
5478 | egrep "^ *{RIL_" \
5479 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
5480
5481*/
5482 switch(request) {
5483 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
5484 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
5485 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
5486 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
5487 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
5488 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
5489 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
5490 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
5491 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
5492 case RIL_REQUEST_DIAL: return "DIAL";
5493 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
5494 case RIL_REQUEST_HANGUP: return "HANGUP";
5495 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
5496 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
5497 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
5498 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
5499 case RIL_REQUEST_UDUB: return "UDUB";
5500 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
5501 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
Wink Savillec0114b32011-02-18 10:14:07 -08005502 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
5503 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005504 case RIL_REQUEST_OPERATOR: return "OPERATOR";
5505 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
5506 case RIL_REQUEST_DTMF: return "DTMF";
5507 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
5508 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
Wink Savillef4c4d362009-04-02 01:37:03 -07005509 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005510 case RIL_REQUEST_SIM_IO: return "SIM_IO";
5511 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
5512 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
5513 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
5514 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
5515 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
5516 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
5517 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
5518 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
5519 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
5520 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
5521 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
5522 case RIL_REQUEST_ANSWER: return "ANSWER";
Wink Savillef4c4d362009-04-02 01:37:03 -07005523 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005524 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
5525 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
5526 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
5527 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
5528 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
5529 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
Matt Mower897915e2015-04-08 23:16:03 -05005530 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS: return "QUERY_AVAILABLE_NETWORKS";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005531 case RIL_REQUEST_DTMF_START: return "DTMF_START";
5532 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
5533 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
5534 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005535 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
5536 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
5537 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
Wink Savillef4c4d362009-04-02 01:37:03 -07005538 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
5539 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005540 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
5541 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
5542 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
Matt Mower897915e2015-04-08 23:16:03 -05005543 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
5544 case RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION: return "SET_SUPP_SVC_NOTIFICATION";
5545 case RIL_REQUEST_WRITE_SMS_TO_SIM: return "WRITE_SMS_TO_SIM";
5546 case RIL_REQUEST_DELETE_SMS_ON_SIM: return "DELETE_SMS_ON_SIM";
Wink Savillef4c4d362009-04-02 01:37:03 -07005547 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
5548 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005549 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
5550 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
5551 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
5552 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
5553 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005554 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
Matt Mower897915e2015-04-08 23:16:03 -05005555 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
5556 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
5557 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005558 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
Matt Mower897915e2015-04-08 23:16:03 -05005559 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE: return "CDMA_SET_SUBSCRIPTION_SOURCE";
5560 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE: return "CDMA_SET_ROAMING_PREFERENCE";
5561 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE: return "CDMA_QUERY_ROAMING_PREFERENCE";
5562 case RIL_REQUEST_SET_TTY_MODE: return "SET_TTY_MODE";
5563 case RIL_REQUEST_QUERY_TTY_MODE: return "QUERY_TTY_MODE";
5564 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE: return "CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
5565 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE: return "CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
5566 case RIL_REQUEST_CDMA_FLASH: return "CDMA_FLASH";
5567 case RIL_REQUEST_CDMA_BURST_DTMF: return "CDMA_BURST_DTMF";
5568 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return "CDMA_VALIDATE_AND_WRITE_AKEY";
5569 case RIL_REQUEST_CDMA_SEND_SMS: return "CDMA_SEND_SMS";
5570 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE: return "CDMA_SMS_ACKNOWLEDGE";
5571 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG: return "GSM_GET_BROADCAST_SMS_CONFIG";
5572 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG: return "GSM_SET_BROADCAST_SMS_CONFIG";
5573 case RIL_REQUEST_GSM_SMS_BROADCAST_ACTIVATION: return "GSM_SMS_BROADCAST_ACTIVATION";
5574 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG: return "CDMA_GET_BROADCAST_SMS_CONFIG";
5575 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG: return "CDMA_SET_BROADCAST_SMS_CONFIG";
5576 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION: return "CDMA_SMS_BROADCAST_ACTIVATION";
5577 case RIL_REQUEST_CDMA_SUBSCRIPTION: return "CDMA_SUBSCRIPTION";
Wink Savillef4c4d362009-04-02 01:37:03 -07005578 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
5579 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
5580 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
jsh000a9fe2009-05-11 14:52:35 -07005581 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
5582 case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
5583 case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
jsh09a68ba2009-06-10 11:56:38 -07005584 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
jsh563fd722010-06-08 16:52:24 -07005585 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
Wink Savillec0114b32011-02-18 10:14:07 -08005586 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
Jake Hambyfa8d5842011-08-19 16:22:18 -07005587 case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
Matt Mower897915e2015-04-08 23:16:03 -05005588 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
5589 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "STK_SEND_ENVELOPE_WITH_STATUS";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005590 case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
Matt Mower897915e2015-04-08 23:16:03 -05005591 case RIL_REQUEST_GET_CELL_INFO_LIST: return "GET_CELL_INFO_LIST";
5592 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return "SET_UNSOL_CELL_INFO_LIST_RATE";
5593 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "SET_INITIAL_ATTACH_APN";
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07005594 case RIL_REQUEST_IMS_REGISTRATION_STATE: return "IMS_REGISTRATION_STATE";
5595 case RIL_REQUEST_IMS_SEND_SMS: return "IMS_SEND_SMS";
Shishir Agrawal2458d8d2013-11-27 14:53:05 -08005596 case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "SIM_TRANSMIT_APDU_BASIC";
5597 case RIL_REQUEST_SIM_OPEN_CHANNEL: return "SIM_OPEN_CHANNEL";
5598 case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "SIM_CLOSE_CHANNEL";
5599 case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "SIM_TRANSMIT_APDU_CHANNEL";
Matt Mower897915e2015-04-08 23:16:03 -05005600 case RIL_REQUEST_NV_READ_ITEM: return "NV_READ_ITEM";
5601 case RIL_REQUEST_NV_WRITE_ITEM: return "NV_WRITE_ITEM";
5602 case RIL_REQUEST_NV_WRITE_CDMA_PRL: return "NV_WRITE_CDMA_PRL";
5603 case RIL_REQUEST_NV_RESET_CONFIG: return "NV_RESET_CONFIG";
Etan Cohend3652192014-06-20 08:28:44 -07005604 case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "SET_UICC_SUBSCRIPTION";
5605 case RIL_REQUEST_ALLOW_DATA: return "ALLOW_DATA";
Amit Mahajan2b772032014-06-26 14:20:11 -07005606 case RIL_REQUEST_GET_HARDWARE_CONFIG: return "GET_HARDWARE_CONFIG";
5607 case RIL_REQUEST_SIM_AUTHENTICATION: return "SIM_AUTHENTICATION";
Wink Savillec29360a2014-07-13 05:17:28 -07005608 case RIL_REQUEST_GET_DC_RT_INFO: return "GET_DC_RT_INFO";
5609 case RIL_REQUEST_SET_DC_RT_INFO_RATE: return "SET_DC_RT_INFO_RATE";
Amit Mahajanc796e222014-08-13 16:54:01 +00005610 case RIL_REQUEST_SET_DATA_PROFILE: return "SET_DATA_PROFILE";
Matt Mower897915e2015-04-08 23:16:03 -05005611 case RIL_REQUEST_SHUTDOWN: return "SHUTDOWN";
5612 case RIL_REQUEST_GET_RADIO_CAPABILITY: return "GET_RADIO_CAPABILITY";
5613 case RIL_REQUEST_SET_RADIO_CAPABILITY: return "SET_RADIO_CAPABILITY";
5614 case RIL_REQUEST_START_LCE: return "START_LCE";
5615 case RIL_REQUEST_STOP_LCE: return "STOP_LCE";
5616 case RIL_REQUEST_PULL_LCEDATA: return "PULL_LCEDATA";
5617 case RIL_REQUEST_GET_ACTIVITY_INFO: return "GET_ACTIVITY_INFO";
Meng Wangb4e34312016-05-12 14:54:36 -07005618 case RIL_REQUEST_SET_CARRIER_RESTRICTIONS: return "SET_CARRIER_RESTRICTIONS";
5619 case RIL_REQUEST_GET_CARRIER_RESTRICTIONS: return "GET_CARRIER_RESTRICTIONS";
Matt Mower897915e2015-04-08 23:16:03 -05005620 case RIL_RESPONSE_ACKNOWLEDGEMENT: return "RESPONSE_ACKNOWLEDGEMENT";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005621 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
5622 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08005623 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 -08005624 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
5625 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
5626 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
5627 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
Matt Mower897915e2015-04-08 23:16:03 -05005628 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005629 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
5630 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
Matt Mower897915e2015-04-08 23:16:03 -05005631 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
Sanket Padawe0eb4fba2016-01-26 17:28:38 -08005632 case RIL_UNSOL_SUPP_SVC_NOTIFICATION: return "UNSOL_SUPP_SVC_NOTIFICATION";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005633 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
5634 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
5635 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
5636 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
Matt Mower897915e2015-04-08 23:16:03 -05005637 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FULL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005638 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005639 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
Wink Savillef4c4d362009-04-02 01:37:03 -07005640 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
Matt Mower897915e2015-04-08 23:16:03 -05005641 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_RESPONSE_CDMA_NEW_SMS";
5642 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_RESPONSE_NEW_BROADCAST_SMS";
Wink Savillef4c4d362009-04-02 01:37:03 -07005643 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
Wink Saville3d54e742009-05-18 18:00:44 -07005644 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
5645 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
5646 case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
5647 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
5648 case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
Jaikumar Ganeshaf6ecbf2009-04-29 13:27:51 -07005649 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
John Wang5d621da2009-09-18 17:17:48 -07005650 case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
John Wang5909cf82010-01-29 00:18:54 -08005651 case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
Wink Savilleee274582011-04-16 15:05:49 -07005652 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08005653 case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
5654 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
Wink Saville5b9df332011-04-06 16:24:21 -07005655 case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005656 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
Wink Saville8a9e0212013-04-09 12:11:38 -07005657 case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
Matt Mower897915e2015-04-08 23:16:03 -05005658 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED";
Etan Cohend3652192014-06-20 08:28:44 -07005659 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return "UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED";
5660 case RIL_UNSOL_SRVCC_STATE_NOTIFY: return "UNSOL_SRVCC_STATE_NOTIFY";
Matt Mower897915e2015-04-08 23:16:03 -05005661 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return "UNSOL_HARDWARE_CONFIG_CHANGED";
Wink Savillec29360a2014-07-13 05:17:28 -07005662 case RIL_UNSOL_DC_RT_INFO_CHANGED: return "UNSOL_DC_RT_INFO_CHANGED";
Matt Mower897915e2015-04-08 23:16:03 -05005663 case RIL_UNSOL_RADIO_CAPABILITY: return "UNSOL_RADIO_CAPABILITY";
Mark Salyzyn0078c8d2016-12-12 14:41:47 -08005664 case RIL_UNSOL_MODEM_RESTART: return "UNSOL_MODEM_RESTART";
Matt Mower897915e2015-04-08 23:16:03 -05005665 case RIL_UNSOL_ON_SS: return "UNSOL_ON_SS";
5666 case RIL_UNSOL_STK_CC_ALPHA_NOTIFY: return "UNSOL_STK_CC_ALPHA_NOTIFY";
5667 case RIL_UNSOL_LCEDATA_RECV: return "UNSOL_LCEDATA_RECV";
5668 case RIL_UNSOL_PCO_DATA: return "UNSOL_PCO_DATA";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005669 default: return "<unknown request>";
5670 }
5671}
5672
Etan Cohend3652192014-06-20 08:28:44 -07005673const char *
5674rilSocketIdToString(RIL_SOCKET_ID socket_id)
5675{
5676 switch(socket_id) {
5677 case RIL_SOCKET_1:
5678 return "RIL_SOCKET_1";
5679#if (SIM_COUNT >= 2)
5680 case RIL_SOCKET_2:
5681 return "RIL_SOCKET_2";
5682#endif
5683#if (SIM_COUNT >= 3)
5684 case RIL_SOCKET_3:
5685 return "RIL_SOCKET_3";
5686#endif
5687#if (SIM_COUNT >= 4)
5688 case RIL_SOCKET_4:
5689 return "RIL_SOCKET_4";
5690#endif
5691 default:
5692 return "not a valid RIL";
5693 }
5694}
5695
Sanket Padawe4c05f352016-01-26 16:19:00 -08005696/*
5697 * Returns true for a debuggable build.
5698 */
5699static bool isDebuggable() {
5700 char debuggable[PROP_VALUE_MAX];
5701 property_get("ro.debuggable", debuggable, "0");
5702 if (strcmp(debuggable, "1") == 0) {
5703 return true;
5704 }
5705 return false;
5706}
5707
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005708} /* namespace android */
Dheeraj Shetty27976c42014-07-02 21:27:57 +02005709
5710void rilEventAddWakeup_helper(struct ril_event *ev) {
5711 android::rilEventAddWakeup(ev);
5712}
5713
5714void listenCallback_helper(int fd, short flags, void *param) {
5715 android::listenCallback(fd, flags, param);
5716}
5717
5718int blockingWrite_helper(int fd, void *buffer, size_t len) {
5719 return android::blockingWrite(fd, buffer, len);
5720}