blob: d5c0222718ed3a58dc4ad3da87e18da5e78ae935 [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>
Amit Mahajanc2c71852016-11-29 16:48:54 -080050#include <sap_service.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080051
Dheeraj Shetty27976c42014-07-02 21:27:57 +020052extern "C" void
53RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen);
Sanket Padawe6ff9a872016-01-27 15:09:12 -080054
55extern "C" void
56RIL_onRequestAck(RIL_Token t);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080057namespace android {
58
59#define PHONE_PROCESS "radio"
Dheeraj Shetty27976c42014-07-02 21:27:57 +020060#define BLUETOOTH_PROCESS "bluetooth"
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080061
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080062#define SOCKET_NAME_RIL_DEBUG "rild-debug"
63
64#define ANDROID_WAKE_LOCK_NAME "radio-interface"
65
Nathan Harolda0153392015-07-28 14:54:58 -070066#define ANDROID_WAKE_LOCK_SECS 0
67#define ANDROID_WAKE_LOCK_USECS 200000
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080068
69#define PROPERTY_RIL_IMPL "gsm.version.ril-impl"
70
71// match with constant in RIL.java
72#define MAX_COMMAND_BYTES (8 * 1024)
73
74// Basically: memset buffers that the client library
75// shouldn't be using anymore in an attempt to find
76// memory usage issues sooner.
77#define MEMSET_FREED 1
78
79#define NUM_ELEMS(a) (sizeof (a) / sizeof (a)[0])
80
Wink Savillef4c4d362009-04-02 01:37:03 -070081#define MIN(a,b) ((a)<(b) ? (a) : (b))
82
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080083/* Negative values for private RIL errno's */
Chih-Hung Hsieh434554c2016-05-12 10:01:16 -070084#define RIL_ERRNO_INVALID_RESPONSE (-1)
Robert Greenwalt78e2c9c2016-05-16 12:36:42 -070085#define RIL_ERRNO_NO_MEMORY (-12)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080086
87// request, response, and unsolicited msg print macro
88#define PRINTBUF_SIZE 8096
89
Robert Greenwalt191e4dc2015-04-29 16:57:39 -070090// Enable verbose logging
91#define VDBG 0
92
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080093// Enable RILC log
94#define RILC_LOG 0
95
96#if RILC_LOG
97 #define startRequest sprintf(printBuf, "(")
98 #define closeRequest sprintf(printBuf, "%s)", printBuf)
99 #define printRequest(token, req) \
Wink Saville8eb2a122012-11-19 16:05:13 -0800100 RLOGD("[%04d]> %s %s", token, requestToString(req), printBuf)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800101
102 #define startResponse sprintf(printBuf, "%s {", printBuf)
103 #define closeResponse sprintf(printBuf, "%s}", printBuf)
Wink Saville8eb2a122012-11-19 16:05:13 -0800104 #define printResponse RLOGD("%s", printBuf)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800105
106 #define clearPrintBuf printBuf[0] = 0
107 #define removeLastChar printBuf[strlen(printBuf)-1] = 0
Ajay Nambifa49a7f2015-08-05 14:53:50 +0530108 #define appendPrintBuf(x...) snprintf(printBuf, PRINTBUF_SIZE, x)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800109#else
110 #define startRequest
111 #define closeRequest
112 #define printRequest(token, req)
113 #define startResponse
114 #define closeResponse
115 #define printResponse
116 #define clearPrintBuf
117 #define removeLastChar
118 #define appendPrintBuf(x...)
119#endif
120
121enum WakeType {DONT_WAKE, WAKE_PARTIAL};
122
123typedef struct {
124 int requestNumber;
Amit Mahajan18fe36b2016-08-25 11:19:21 -0700125 int (*responseFunction) (Parcel &p, int slotId, int requestNumber, int responseType, int token,
126 RIL_Errno e, void *response, size_t responselen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800127 WakeType wakeType;
128} UnsolResponseInfo;
129
Wink Saville3d54e742009-05-18 18:00:44 -0700130typedef struct UserCallbackInfo {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800131 RIL_TimedCallback p_callback;
132 void *userParam;
133 struct ril_event event;
134 struct UserCallbackInfo *p_next;
135} UserCallbackInfo;
136
Etan Cohend3652192014-06-20 08:28:44 -0700137extern "C" const char * failCauseToString(RIL_Errno);
138extern "C" const char * callStateToString(RIL_CallState);
139extern "C" const char * radioStateToString(RIL_RadioState);
140extern "C" const char * rilSocketIdToString(RIL_SOCKET_ID socket_id);
141
142extern "C"
143char rild[MAX_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800144/*******************************************************************/
145
146RIL_RadioFunctions s_callbacks = {0, NULL, NULL, NULL, NULL, NULL};
147static int s_registerCalled = 0;
148
149static pthread_t s_tid_dispatch;
150static pthread_t s_tid_reader;
151static int s_started = 0;
152
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800153static int s_fdDebug = -1;
Etan Cohend3652192014-06-20 08:28:44 -0700154static int s_fdDebug_socket2 = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800155
156static int s_fdWakeupRead;
157static int s_fdWakeupWrite;
158
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800159int s_wakelock_count = 0;
160
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800161static struct ril_event s_commands_event;
162static struct ril_event s_wakeupfd_event;
163static struct ril_event s_listen_event;
Etan Cohend3652192014-06-20 08:28:44 -0700164static SocketListenParam s_ril_param_socket;
165
166static pthread_mutex_t s_pendingRequestsMutex = PTHREAD_MUTEX_INITIALIZER;
167static pthread_mutex_t s_writeMutex = PTHREAD_MUTEX_INITIALIZER;
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800168static pthread_mutex_t s_wakeLockCountMutex = PTHREAD_MUTEX_INITIALIZER;
Etan Cohend3652192014-06-20 08:28:44 -0700169static RequestInfo *s_pendingRequests = NULL;
170
171#if (SIM_COUNT >= 2)
172static struct ril_event s_commands_event_socket2;
173static struct ril_event s_listen_event_socket2;
174static SocketListenParam s_ril_param_socket2;
175
176static pthread_mutex_t s_pendingRequestsMutex_socket2 = PTHREAD_MUTEX_INITIALIZER;
177static pthread_mutex_t s_writeMutex_socket2 = PTHREAD_MUTEX_INITIALIZER;
178static RequestInfo *s_pendingRequests_socket2 = NULL;
179#endif
180
181#if (SIM_COUNT >= 3)
182static struct ril_event s_commands_event_socket3;
183static struct ril_event s_listen_event_socket3;
184static SocketListenParam s_ril_param_socket3;
185
186static pthread_mutex_t s_pendingRequestsMutex_socket3 = PTHREAD_MUTEX_INITIALIZER;
187static pthread_mutex_t s_writeMutex_socket3 = PTHREAD_MUTEX_INITIALIZER;
188static RequestInfo *s_pendingRequests_socket3 = NULL;
189#endif
190
191#if (SIM_COUNT >= 4)
192static struct ril_event s_commands_event_socket4;
193static struct ril_event s_listen_event_socket4;
194static SocketListenParam s_ril_param_socket4;
195
196static pthread_mutex_t s_pendingRequestsMutex_socket4 = PTHREAD_MUTEX_INITIALIZER;
197static pthread_mutex_t s_writeMutex_socket4 = PTHREAD_MUTEX_INITIALIZER;
198static RequestInfo *s_pendingRequests_socket4 = NULL;
199#endif
200
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800201static struct ril_event s_wake_timeout_event;
202static struct ril_event s_debug_event;
203
204
Nathan Harolda0153392015-07-28 14:54:58 -0700205static const struct timeval TIMEVAL_WAKE_TIMEOUT = {ANDROID_WAKE_LOCK_SECS,ANDROID_WAKE_LOCK_USECS};
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800206
Etan Cohend3652192014-06-20 08:28:44 -0700207
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800208static pthread_mutex_t s_startupMutex = PTHREAD_MUTEX_INITIALIZER;
209static pthread_cond_t s_startupCond = PTHREAD_COND_INITIALIZER;
210
211static pthread_mutex_t s_dispatchMutex = PTHREAD_MUTEX_INITIALIZER;
212static pthread_cond_t s_dispatchCond = PTHREAD_COND_INITIALIZER;
213
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800214static RequestInfo *s_toDispatchHead = NULL;
215static RequestInfo *s_toDispatchTail = NULL;
216
217static UserCallbackInfo *s_last_wake_timeout_info = NULL;
218
219static void *s_lastNITZTimeData = NULL;
220static size_t s_lastNITZTimeDataSize;
221
222#if RILC_LOG
223 static char printBuf[PRINTBUF_SIZE];
224#endif
225
226/*******************************************************************/
Etan Cohend3652192014-06-20 08:28:44 -0700227static int sendResponse (Parcel &p, RIL_SOCKET_ID socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800228
229static void dispatchVoid (Parcel& p, RequestInfo *pRI);
230static void dispatchString (Parcel& p, RequestInfo *pRI);
231static void dispatchStrings (Parcel& p, RequestInfo *pRI);
232static void dispatchInts (Parcel& p, RequestInfo *pRI);
233static void dispatchDial (Parcel& p, RequestInfo *pRI);
234static void dispatchSIM_IO (Parcel& p, RequestInfo *pRI);
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800235static void dispatchSIM_APDU (Parcel& p, RequestInfo *pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800236static void dispatchCallForward(Parcel& p, RequestInfo *pRI);
237static void dispatchRaw(Parcel& p, RequestInfo *pRI);
238static void dispatchSmsWrite (Parcel &p, RequestInfo *pRI);
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -0700239static void dispatchDataCall (Parcel& p, RequestInfo *pRI);
Sungmin Choi75697532013-04-26 15:04:45 -0700240static void dispatchSetInitialAttachApn (Parcel& p, RequestInfo *pRI);
Wink Savillef4c4d362009-04-02 01:37:03 -0700241static void dispatchCdmaSms(Parcel &p, RequestInfo *pRI);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -0700242static void dispatchImsSms(Parcel &p, RequestInfo *pRI);
243static void dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
244static void dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
Wink Savillef4c4d362009-04-02 01:37:03 -0700245static void dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI);
Wink Savillea592eeb2009-05-22 13:26:36 -0700246static void dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI);
Wink Savillef4c4d362009-04-02 01:37:03 -0700247static void dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI);
248static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI);
Jake Hamby8a4a2332014-01-15 13:12:05 -0800249static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI);
250static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI);
Etan Cohend3652192014-06-20 08:28:44 -0700251static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI);
Amit Mahajan90530a62014-07-01 15:54:08 -0700252static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI);
Amit Mahajanc796e222014-08-13 16:54:01 +0000253static void dispatchDataProfile(Parcel &p, RequestInfo *pRI);
Wink Saville8b4e4f72014-10-17 15:01:45 -0700254static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI);
Meng Wangb4e34312016-05-12 14:54:36 -0700255static void dispatchCarrierRestrictions(Parcel &p, RequestInfo *pRI);
Amit Mahajan18fe36b2016-08-25 11:19:21 -0700256static int responseInts(Parcel &p, int slotId, int requestNumber, int responseType, int token,
257 RIL_Errno e, void *response, size_t responselen);
258static int responseFailCause(Parcel &p, int slotId, int requestNumber, int responseType, int token,
259 RIL_Errno e, void *response, size_t responselen);
260static int responseStrings(Parcel &p, int slotId, int requestNumber, int responseType, int token,
261 RIL_Errno e, void *response, size_t responselen);
262static int responseString(Parcel &p, int slotId, int requestNumber, int responseType, int token,
263 RIL_Errno e, void *response, size_t responselen);
264static int responseVoid(Parcel &p, int slotId, int requestNumber, int responseType, int token,
265 RIL_Errno e, void *response, size_t responselen);
266static int responseCallList(Parcel &p, int slotId, int requestNumber, int responseType, int token,
267 RIL_Errno e, void *response, size_t responselen);
268static int responseSMS(Parcel &p, int slotId, int requestNumber, int responseType, int token,
269 RIL_Errno e, void *response, size_t responselen);
270static int responseSIM_IO(Parcel &p, int slotId, int requestNumber, int responseType, int token,
271 RIL_Errno e, void *response, size_t responselen);
272static int responseCallForwards(Parcel &p, int slotId, int requestNumber, int responseType,
273 int token, RIL_Errno e, void *response, size_t responselen);
274static int responseDataCallList(Parcel &p, int slotId, int requestNumber, int responseType,
275 int token, RIL_Errno e, void *response, size_t responselen);
276static int responseSetupDataCall(Parcel &p, int slotId, int requestNumber, int responseType,
277 int token, RIL_Errno e, void *response, size_t responselen);
278static int responseRaw(Parcel &p, int slotId, int requestNumber, int responseType, int token,
279 RIL_Errno e, void *response, size_t responselen);
280static int responseSsn(Parcel &p, int slotId, int requestNumber, int responseType, int token,
281 RIL_Errno e, void *response, size_t responselen);
282static int responseGsmBrSmsCnf(Parcel &p, int slotId, int requestNumber, int responseType,
283 int token, RIL_Errno e, void *response, size_t responselen);
284static int responseCdmaBrSmsCnf(Parcel &p, int slotId, int requestNumber, int responseType,
285 int token, RIL_Errno e, void *response, size_t responselen);
286static int responseCdmaSms(Parcel &p, int slotId, int requestNumber, int responseType, int token,
287 RIL_Errno e, void *response, size_t responselen);
288static int responseCellList(Parcel &p, int slotId, int requestNumber, int responseType, int token,
289 RIL_Errno e, void *response, size_t responselen);
290static int responseCdmaInformationRecords(Parcel &p, int slotId, int requestNumber,
291 int responseType, int token, RIL_Errno e,void *response, size_t responselen);
292static int responseRilSignalStrength(Parcel &p, int slotId, int requestNumber, int responseType,
293 int token, RIL_Errno e,void *response, size_t responselen);
294static int responseCallRing(Parcel &p, int slotId, int requestNumber, int responseType, int token,
295 RIL_Errno e, void *response, size_t responselen);
296static int responseCdmaSignalInfoRecord(Parcel &p, int slotId, int requestNumber, int responseType,
297 int token, RIL_Errno e,void *response, size_t responselen);
298static int responseCdmaCallWaiting(Parcel &p, int slotId, int requestNumber, int responseType,
299 int token, RIL_Errno e,void *response, size_t responselen);
300static int responseSimRefresh(Parcel &p, int slotId, int requestNumber, int responseType, int token,
301 RIL_Errno e, void *response, size_t responselen);
302static int responseCellInfoList(Parcel &p, int slotId, int requestNumber, int responseType,
303 int token, RIL_Errno e, void *response, size_t responselen);
304static int responseHardwareConfig(Parcel &p, int slotId, int requestNumber, int responseType,
305 int token, RIL_Errno e, void *response, size_t responselen);
306static int responseDcRtInfo(Parcel &p, int slotId, int requestNumber, int responseType, int token,
307 RIL_Errno e, void *response, size_t responselen);
308static int responseRadioCapability(Parcel &p, int slotId, int requestNumber, int responseType,
309 int token, RIL_Errno e, void *response, size_t responselen);
310static int responseSSData(Parcel &p, int slotId, int requestNumber, int responseType, int token,
311 RIL_Errno e, void *response, size_t responselen);
312static int responseLceStatus(Parcel &p, int slotId, int requestNumber, int responseType, int token,
313 RIL_Errno e, void *response, size_t responselen);
314static int responseLceData(Parcel &p, int slotId, int requestNumber, int responseType, int token,
315 RIL_Errno e, void *response, size_t responselen);
316static int responseActivityData(Parcel &p, int slotId, int requestNumber, int responseType,
317 int token, RIL_Errno e, void *response, size_t responselen);
318static int responseCarrierRestrictions(Parcel &p, int slotId, int requestNumber, int responseType,
319 int token, RIL_Errno e, void *response, size_t responselen);
320static int responsePcoData(Parcel &p, int slotId, int requestNumber, int responseType, int token,
321 RIL_Errno e, void *response, size_t responselen);
Amit Mahajan54563d32014-11-22 00:54:49 +0000322
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800323static void grabPartialWakeLock();
324static void releaseWakeLock();
325static void wakeTimeoutCallback(void *);
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800326
Amit Mahajan54563d32014-11-22 00:54:49 +0000327static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType);
328
Sanket Padawe4c05f352016-01-26 16:19:00 -0800329static bool isDebuggable();
330
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800331#ifdef RIL_SHLIB
Etan Cohend3652192014-06-20 08:28:44 -0700332#if defined(ANDROID_MULTI_SIM)
Vinit Deshpande1b1ec2d2015-04-15 13:31:05 -0700333extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Etan Cohend3652192014-06-20 08:28:44 -0700334 size_t datalen, RIL_SOCKET_ID socket_id);
335#else
Vinit Deshpande1b1ec2d2015-04-15 13:31:05 -0700336extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800337 size_t datalen);
338#endif
Etan Cohend3652192014-06-20 08:28:44 -0700339#endif
340
341#if defined(ANDROID_MULTI_SIM)
342#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c), (d))
343#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d), (e))
344#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest(a)
345#else
346#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c))
347#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d))
348#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest()
349#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800350
Wink Saville7f856802009-06-09 10:23:37 -0700351static UserCallbackInfo * internalRequestTimedCallback
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -0700352 (RIL_TimedCallback callback, void *param,
353 const struct timeval *relativeTime);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800354
355/** Index == requestNumber */
356static CommandInfo s_commands[] = {
357#include "ril_commands.h"
358};
359
360static UnsolResponseInfo s_unsolResponses[] = {
361#include "ril_unsol_commands.h"
362};
363
Amit Mahajan18fe36b2016-08-25 11:19:21 -0700364char * RIL_getRilSocketName() {
Etan Cohend3652192014-06-20 08:28:44 -0700365 return rild;
366}
367
368extern "C"
Dheeraj Shetty27976c42014-07-02 21:27:57 +0200369void RIL_setRilSocketName(const char * s) {
Etan Cohend3652192014-06-20 08:28:44 -0700370 strncpy(rild, s, MAX_SOCKET_NAME_LENGTH);
371}
372
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800373static char *
Wink Savillef4c4d362009-04-02 01:37:03 -0700374strdupReadString(Parcel &p) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800375 size_t stringlen;
376 const char16_t *s16;
Wink Saville7f856802009-06-09 10:23:37 -0700377
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800378 s16 = p.readString16Inplace(&stringlen);
Wink Saville7f856802009-06-09 10:23:37 -0700379
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800380 return strndup16to8(s16, stringlen);
381}
382
Wink Saville8b4e4f72014-10-17 15:01:45 -0700383static status_t
384readStringFromParcelInplace(Parcel &p, char *str, size_t maxLen) {
385 size_t s16Len;
386 const char16_t *s16;
387
388 s16 = p.readString16Inplace(&s16Len);
389 if (s16 == NULL) {
390 return NO_MEMORY;
391 }
392 size_t strLen = strnlen16to8(s16, s16Len);
393 if ((strLen + 1) > maxLen) {
394 return NO_MEMORY;
395 }
396 if (strncpy16to8(str, s16, strLen) == NULL) {
397 return NO_MEMORY;
398 } else {
399 return NO_ERROR;
400 }
401}
402
Wink Savillef4c4d362009-04-02 01:37:03 -0700403static void writeStringToParcel(Parcel &p, const char *s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800404 char16_t *s16;
405 size_t s16_len;
406 s16 = strdup8to16(s, &s16_len);
407 p.writeString16(s16, s16_len);
408 free(s16);
409}
410
411
412static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700413memsetString (char *s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800414 if (s != NULL) {
415 memset (s, 0, strlen(s));
416 }
417}
418
419void nullParcelReleaseFunction (const uint8_t* data, size_t dataSize,
420 const size_t* objects, size_t objectsSize,
Wink Savillef4c4d362009-04-02 01:37:03 -0700421 void* cookie) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800422 // do nothing -- the data reference lives longer than the Parcel object
423}
424
Wink Saville7f856802009-06-09 10:23:37 -0700425/**
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800426 * To be called from dispatch thread
427 * Issue a single local request, ensuring that the response
Wink Saville7f856802009-06-09 10:23:37 -0700428 * is not sent back up to the command process
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800429 */
430static void
Etan Cohend3652192014-06-20 08:28:44 -0700431issueLocalRequest(int request, void *data, int len, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800432 RequestInfo *pRI;
433 int ret;
Etan Cohend3652192014-06-20 08:28:44 -0700434 /* Hook for current context */
435 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
436 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
437 /* pendingRequestsHook refer to &s_pendingRequests */
438 RequestInfo** pendingRequestsHook = &s_pendingRequests;
439
440#if (SIM_COUNT == 2)
441 if (socket_id == RIL_SOCKET_2) {
442 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
443 pendingRequestsHook = &s_pendingRequests_socket2;
444 }
445#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800446
447 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
Sanket Padawe55227b52016-02-29 10:09:26 -0800448 if (pRI == NULL) {
449 RLOGE("Memory allocation failed for request %s", requestToString(request));
450 return;
451 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800452
453 pRI->local = 1;
454 pRI->token = 0xffffffff; // token is not used in this context
455 pRI->pCI = &(s_commands[request]);
Etan Cohend3652192014-06-20 08:28:44 -0700456 pRI->socket_id = socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800457
Etan Cohend3652192014-06-20 08:28:44 -0700458 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800459 assert (ret == 0);
460
Etan Cohend3652192014-06-20 08:28:44 -0700461 pRI->p_next = *pendingRequestsHook;
462 *pendingRequestsHook = pRI;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800463
Etan Cohend3652192014-06-20 08:28:44 -0700464 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800465 assert (ret == 0);
466
Wink Saville8eb2a122012-11-19 16:05:13 -0800467 RLOGD("C[locl]> %s", requestToString(request));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800468
Etan Cohend3652192014-06-20 08:28:44 -0700469 CALL_ONREQUEST(request, data, len, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800470}
471
472
473
474static int
Etan Cohend3652192014-06-20 08:28:44 -0700475processCommandBuffer(void *buffer, size_t buflen, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800476 Parcel p;
477 status_t status;
478 int32_t request;
479 int32_t token;
480 RequestInfo *pRI;
481 int ret;
Etan Cohend3652192014-06-20 08:28:44 -0700482 /* Hook for current context */
483 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
484 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
485 /* pendingRequestsHook refer to &s_pendingRequests */
486 RequestInfo** pendingRequestsHook = &s_pendingRequests;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800487
488 p.setData((uint8_t *) buffer, buflen);
489
490 // status checked at end
491 status = p.readInt32(&request);
492 status = p.readInt32 (&token);
493
Etan Cohend3652192014-06-20 08:28:44 -0700494#if (SIM_COUNT >= 2)
495 if (socket_id == RIL_SOCKET_2) {
496 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
497 pendingRequestsHook = &s_pendingRequests_socket2;
498 }
499#if (SIM_COUNT >= 3)
500 else if (socket_id == RIL_SOCKET_3) {
501 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
502 pendingRequestsHook = &s_pendingRequests_socket3;
503 }
504#endif
505#if (SIM_COUNT >= 4)
506 else if (socket_id == RIL_SOCKET_4) {
507 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
508 pendingRequestsHook = &s_pendingRequests_socket4;
509 }
510#endif
511#endif
512
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800513 if (status != NO_ERROR) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800514 RLOGE("invalid request block");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800515 return 0;
516 }
517
Sooraj Sasindran405313f2016-05-06 16:19:56 -0700518 // Received an Ack for the previous result sent to RIL.java,
519 // so release wakelock and exit
520 if (request == RIL_RESPONSE_ACKNOWLEDGEMENT) {
521 releaseWakeLock();
522 return 0;
523 }
524
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800525 if (request < 1 || request >= (int32_t)NUM_ELEMS(s_commands)) {
Etan Cohend3652192014-06-20 08:28:44 -0700526 Parcel pErr;
Wink Saville8eb2a122012-11-19 16:05:13 -0800527 RLOGE("unsupported request code %d token %d", request, token);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800528 // FIXME this should perhaps return a response
Etan Cohend3652192014-06-20 08:28:44 -0700529 pErr.writeInt32 (RESPONSE_SOLICITED);
530 pErr.writeInt32 (token);
531 pErr.writeInt32 (RIL_E_GENERIC_FAILURE);
532
533 sendResponse(pErr, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800534 return 0;
535 }
536
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800537 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
Sanket Padawe55227b52016-02-29 10:09:26 -0800538 if (pRI == NULL) {
539 RLOGE("Memory allocation failed for request %s", requestToString(request));
540 return 0;
541 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800542
543 pRI->token = token;
544 pRI->pCI = &(s_commands[request]);
Etan Cohend3652192014-06-20 08:28:44 -0700545 pRI->socket_id = socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800546
Etan Cohend3652192014-06-20 08:28:44 -0700547 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800548 assert (ret == 0);
549
Etan Cohend3652192014-06-20 08:28:44 -0700550 pRI->p_next = *pendingRequestsHook;
551 *pendingRequestsHook = pRI;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800552
Etan Cohend3652192014-06-20 08:28:44 -0700553 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800554 assert (ret == 0);
555
Wink Saville7f856802009-06-09 10:23:37 -0700556 pRI->pCI->dispatchFunction(p, pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800557
558 return 0;
559}
560
Amit Mahajan18fe36b2016-08-25 11:19:21 -0700561int
562addRequestToList(RequestInfo *pRI, int request, int token, RIL_SOCKET_ID socket_id) {
563 status_t status;
564 int ret;
565 /* Hook for current context */
566 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
567 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
568 /* pendingRequestsHook refer to &s_pendingRequests */
569 RequestInfo** pendingRequestsHook = &s_pendingRequests;
570
571#if (SIM_COUNT >= 2)
572 if (socket_id == RIL_SOCKET_2) {
573 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
574 pendingRequestsHook = &s_pendingRequests_socket2;
575 }
576#if (SIM_COUNT >= 3)
577 else if (socket_id == RIL_SOCKET_3) {
578 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
579 pendingRequestsHook = &s_pendingRequests_socket3;
580 }
581#endif
582#if (SIM_COUNT >= 4)
583 else if (socket_id == RIL_SOCKET_4) {
584 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
585 pendingRequestsHook = &s_pendingRequests_socket4;
586 }
587#endif
588#endif
589
590 // Received an Ack for the previous result sent to RIL.java,
591 // so release wakelock and exit
592 if (request == RIL_RESPONSE_ACKNOWLEDGEMENT) {
593 releaseWakeLock();
594 return 0;
595 }
596
597 ret = pthread_mutex_lock(pendingRequestsMutexHook);
598 assert (ret == 0);
599
600 pRI->p_next = *pendingRequestsHook;
601 *pendingRequestsHook = pRI;
602
603 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
604 assert (ret == 0);
605
606 return 0;
607}
608
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800609static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700610invalidCommandBlock (RequestInfo *pRI) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800611 RLOGE("invalid command block for token %d request %s",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800612 pRI->token, requestToString(pRI->pCI->requestNumber));
613}
614
615/** Callee expects NULL */
Wink Saville7f856802009-06-09 10:23:37 -0700616static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700617dispatchVoid (Parcel& p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800618 clearPrintBuf;
619 printRequest(pRI->token, pRI->pCI->requestNumber);
Etan Cohend3652192014-06-20 08:28:44 -0700620 CALL_ONREQUEST(pRI->pCI->requestNumber, NULL, 0, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800621}
622
623/** Callee expects const char * */
624static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700625dispatchString (Parcel& p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800626 status_t status;
627 size_t datalen;
628 size_t stringlen;
629 char *string8 = NULL;
630
631 string8 = strdupReadString(p);
632
633 startRequest;
634 appendPrintBuf("%s%s", printBuf, string8);
635 closeRequest;
636 printRequest(pRI->token, pRI->pCI->requestNumber);
637
Etan Cohend3652192014-06-20 08:28:44 -0700638 CALL_ONREQUEST(pRI->pCI->requestNumber, string8,
639 sizeof(char *), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800640
641#ifdef MEMSET_FREED
642 memsetString(string8);
643#endif
644
645 free(string8);
646 return;
647invalid:
648 invalidCommandBlock(pRI);
649 return;
650}
651
652/** Callee expects const char ** */
653static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700654dispatchStrings (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800655 int32_t countStrings;
656 status_t status;
657 size_t datalen;
658 char **pStrings;
659
660 status = p.readInt32 (&countStrings);
661
662 if (status != NO_ERROR) {
663 goto invalid;
664 }
665
666 startRequest;
667 if (countStrings == 0) {
668 // just some non-null pointer
Sanket Padawe0cfc5532016-03-07 17:12:19 -0800669 pStrings = (char **)calloc(1, sizeof(char *));
Sanket Padawe55227b52016-02-29 10:09:26 -0800670 if (pStrings == NULL) {
671 RLOGE("Memory allocation failed for request %s",
672 requestToString(pRI->pCI->requestNumber));
673 closeRequest;
674 return;
675 }
676
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800677 datalen = 0;
Sanket Padawe0cfc5532016-03-07 17:12:19 -0800678 } else if (countStrings < 0) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800679 pStrings = NULL;
680 datalen = 0;
681 } else {
682 datalen = sizeof(char *) * countStrings;
Wink Saville7f856802009-06-09 10:23:37 -0700683
Sanket Padawe0cfc5532016-03-07 17:12:19 -0800684 pStrings = (char **)calloc(countStrings, sizeof(char *));
Sanket Padawe55227b52016-02-29 10:09:26 -0800685 if (pStrings == NULL) {
686 RLOGE("Memory allocation failed for request %s",
687 requestToString(pRI->pCI->requestNumber));
688 closeRequest;
689 return;
690 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800691
692 for (int i = 0 ; i < countStrings ; i++) {
693 pStrings[i] = strdupReadString(p);
694 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
695 }
696 }
697 removeLastChar;
698 closeRequest;
699 printRequest(pRI->token, pRI->pCI->requestNumber);
700
Etan Cohend3652192014-06-20 08:28:44 -0700701 CALL_ONREQUEST(pRI->pCI->requestNumber, pStrings, datalen, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800702
703 if (pStrings != NULL) {
704 for (int i = 0 ; i < countStrings ; i++) {
705#ifdef MEMSET_FREED
706 memsetString (pStrings[i]);
707#endif
708 free(pStrings[i]);
709 }
710
711#ifdef MEMSET_FREED
712 memset(pStrings, 0, datalen);
713#endif
Sanket Padawe0cfc5532016-03-07 17:12:19 -0800714 free(pStrings);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800715 }
Wink Saville7f856802009-06-09 10:23:37 -0700716
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800717 return;
718invalid:
719 invalidCommandBlock(pRI);
720 return;
721}
722
723/** Callee expects const int * */
724static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700725dispatchInts (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800726 int32_t count;
727 status_t status;
728 size_t datalen;
729 int *pInts;
730
731 status = p.readInt32 (&count);
732
Sanket Padawe0cfc5532016-03-07 17:12:19 -0800733 if (status != NO_ERROR || count <= 0) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800734 goto invalid;
735 }
736
737 datalen = sizeof(int) * count;
Sanket Padawe0cfc5532016-03-07 17:12:19 -0800738 pInts = (int *)calloc(count, sizeof(int));
Sanket Padawe55227b52016-02-29 10:09:26 -0800739 if (pInts == NULL) {
740 RLOGE("Memory allocation failed for request %s", requestToString(pRI->pCI->requestNumber));
741 return;
742 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800743
744 startRequest;
745 for (int i = 0 ; i < count ; i++) {
746 int32_t t;
747
748 status = p.readInt32(&t);
749 pInts[i] = (int)t;
750 appendPrintBuf("%s%d,", printBuf, t);
751
752 if (status != NO_ERROR) {
Sanket Padawe0cfc5532016-03-07 17:12:19 -0800753 free(pInts);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800754 goto invalid;
755 }
756 }
757 removeLastChar;
758 closeRequest;
759 printRequest(pRI->token, pRI->pCI->requestNumber);
760
Etan Cohend3652192014-06-20 08:28:44 -0700761 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<int *>(pInts),
762 datalen, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800763
764#ifdef MEMSET_FREED
765 memset(pInts, 0, datalen);
766#endif
Sanket Padawe0cfc5532016-03-07 17:12:19 -0800767 free(pInts);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800768 return;
769invalid:
770 invalidCommandBlock(pRI);
771 return;
772}
773
774
Wink Saville7f856802009-06-09 10:23:37 -0700775/**
776 * Callee expects const RIL_SMS_WriteArgs *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800777 * Payload is:
778 * int32_t status
779 * String pdu
780 */
781static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700782dispatchSmsWrite (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800783 RIL_SMS_WriteArgs args;
784 int32_t t;
785 status_t status;
786
Mark Salyzyndba25612015-04-09 07:18:35 -0700787 RLOGD("dispatchSmsWrite");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800788 memset (&args, 0, sizeof(args));
789
790 status = p.readInt32(&t);
791 args.status = (int)t;
792
793 args.pdu = strdupReadString(p);
794
795 if (status != NO_ERROR || args.pdu == NULL) {
796 goto invalid;
797 }
798
799 args.smsc = strdupReadString(p);
800
801 startRequest;
802 appendPrintBuf("%s%d,%s,smsc=%s", printBuf, args.status,
803 (char*)args.pdu, (char*)args.smsc);
804 closeRequest;
805 printRequest(pRI->token, pRI->pCI->requestNumber);
Wink Saville7f856802009-06-09 10:23:37 -0700806
Etan Cohend3652192014-06-20 08:28:44 -0700807 CALL_ONREQUEST(pRI->pCI->requestNumber, &args, sizeof(args), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800808
809#ifdef MEMSET_FREED
810 memsetString (args.pdu);
811#endif
812
813 free (args.pdu);
Wink Saville7f856802009-06-09 10:23:37 -0700814
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800815#ifdef MEMSET_FREED
816 memset(&args, 0, sizeof(args));
817#endif
818
819 return;
820invalid:
821 invalidCommandBlock(pRI);
822 return;
823}
824
Wink Saville7f856802009-06-09 10:23:37 -0700825/**
826 * Callee expects const RIL_Dial *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800827 * Payload is:
828 * String address
829 * int32_t clir
830 */
831static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700832dispatchDial (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800833 RIL_Dial dial;
Wink Saville74fa3882009-12-22 15:35:41 -0800834 RIL_UUS_Info uusInfo;
Wink Saville7bce0822010-01-08 15:20:12 -0800835 int32_t sizeOfDial;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800836 int32_t t;
Wink Saville74fa3882009-12-22 15:35:41 -0800837 int32_t uusPresent;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800838 status_t status;
839
Mark Salyzyndba25612015-04-09 07:18:35 -0700840 RLOGD("dispatchDial");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800841 memset (&dial, 0, sizeof(dial));
842
843 dial.address = strdupReadString(p);
844
845 status = p.readInt32(&t);
846 dial.clir = (int)t;
847
848 if (status != NO_ERROR || dial.address == NULL) {
849 goto invalid;
850 }
851
Wink Saville3a4840b2010-04-07 13:29:58 -0700852 if (s_callbacks.version < 3) { // Remove when partners upgrade to version 3
Wink Saville74fa3882009-12-22 15:35:41 -0800853 uusPresent = 0;
Wink Saville7bce0822010-01-08 15:20:12 -0800854 sizeOfDial = sizeof(dial) - sizeof(RIL_UUS_Info *);
Wink Saville74fa3882009-12-22 15:35:41 -0800855 } else {
856 status = p.readInt32(&uusPresent);
857
858 if (status != NO_ERROR) {
859 goto invalid;
860 }
861
862 if (uusPresent == 0) {
863 dial.uusInfo = NULL;
864 } else {
865 int32_t len;
866
867 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
868
869 status = p.readInt32(&t);
870 uusInfo.uusType = (RIL_UUS_Type) t;
871
872 status = p.readInt32(&t);
873 uusInfo.uusDcs = (RIL_UUS_DCS) t;
874
875 status = p.readInt32(&len);
876 if (status != NO_ERROR) {
877 goto invalid;
878 }
879
880 // The java code writes -1 for null arrays
881 if (((int) len) == -1) {
882 uusInfo.uusData = NULL;
883 len = 0;
884 } else {
885 uusInfo.uusData = (char*) p.readInplace(len);
Sooraj Sasindrane0491222016-09-23 11:20:39 -0700886 // check if the length is invalid
887 if (uusInfo.uusData == NULL) {
888 goto invalid;
889 }
Wink Saville74fa3882009-12-22 15:35:41 -0800890 }
891
892 uusInfo.uusLength = len;
893 dial.uusInfo = &uusInfo;
894 }
Wink Saville7bce0822010-01-08 15:20:12 -0800895 sizeOfDial = sizeof(dial);
Wink Saville74fa3882009-12-22 15:35:41 -0800896 }
897
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800898 startRequest;
899 appendPrintBuf("%snum=%s,clir=%d", printBuf, dial.address, dial.clir);
Wink Saville74fa3882009-12-22 15:35:41 -0800900 if (uusPresent) {
901 appendPrintBuf("%s,uusType=%d,uusDcs=%d,uusLen=%d", printBuf,
902 dial.uusInfo->uusType, dial.uusInfo->uusDcs,
903 dial.uusInfo->uusLength);
904 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800905 closeRequest;
906 printRequest(pRI->token, pRI->pCI->requestNumber);
907
Etan Cohend3652192014-06-20 08:28:44 -0700908 CALL_ONREQUEST(pRI->pCI->requestNumber, &dial, sizeOfDial, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800909
910#ifdef MEMSET_FREED
911 memsetString (dial.address);
912#endif
913
914 free (dial.address);
Wink Saville7f856802009-06-09 10:23:37 -0700915
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800916#ifdef MEMSET_FREED
Wink Saville74fa3882009-12-22 15:35:41 -0800917 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800918 memset(&dial, 0, sizeof(dial));
919#endif
920
921 return;
922invalid:
923 invalidCommandBlock(pRI);
924 return;
925}
926
Wink Saville7f856802009-06-09 10:23:37 -0700927/**
928 * Callee expects const RIL_SIM_IO *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800929 * Payload is:
930 * int32_t command
931 * int32_t fileid
932 * String path
933 * int32_t p1, p2, p3
Wink Saville7f856802009-06-09 10:23:37 -0700934 * String data
935 * String pin2
Wink Savillec0114b32011-02-18 10:14:07 -0800936 * String aidPtr
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800937 */
938static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700939dispatchSIM_IO (Parcel &p, RequestInfo *pRI) {
Wink Savillec0114b32011-02-18 10:14:07 -0800940 union RIL_SIM_IO {
941 RIL_SIM_IO_v6 v6;
942 RIL_SIM_IO_v5 v5;
943 } simIO;
944
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800945 int32_t t;
Wink Savillec0114b32011-02-18 10:14:07 -0800946 int size;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800947 status_t status;
948
Robert Greenwalt191e4dc2015-04-29 16:57:39 -0700949#if VDBG
Mark Salyzyndba25612015-04-09 07:18:35 -0700950 RLOGD("dispatchSIM_IO");
Robert Greenwalt191e4dc2015-04-29 16:57:39 -0700951#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800952 memset (&simIO, 0, sizeof(simIO));
953
Wink Saville7f856802009-06-09 10:23:37 -0700954 // note we only check status at the end
955
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800956 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800957 simIO.v6.command = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800958
959 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800960 simIO.v6.fileid = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800961
Wink Savillec0114b32011-02-18 10:14:07 -0800962 simIO.v6.path = strdupReadString(p);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800963
964 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800965 simIO.v6.p1 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800966
967 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800968 simIO.v6.p2 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800969
970 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800971 simIO.v6.p3 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800972
Wink Savillec0114b32011-02-18 10:14:07 -0800973 simIO.v6.data = strdupReadString(p);
974 simIO.v6.pin2 = strdupReadString(p);
975 simIO.v6.aidPtr = strdupReadString(p);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800976
977 startRequest;
Wink Savillec0114b32011-02-18 10:14:07 -0800978 appendPrintBuf("%scmd=0x%X,efid=0x%X,path=%s,%d,%d,%d,%s,pin2=%s,aid=%s", printBuf,
979 simIO.v6.command, simIO.v6.fileid, (char*)simIO.v6.path,
980 simIO.v6.p1, simIO.v6.p2, simIO.v6.p3,
981 (char*)simIO.v6.data, (char*)simIO.v6.pin2, simIO.v6.aidPtr);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800982 closeRequest;
983 printRequest(pRI->token, pRI->pCI->requestNumber);
Wink Saville7f856802009-06-09 10:23:37 -0700984
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800985 if (status != NO_ERROR) {
986 goto invalid;
987 }
988
Wink Savillec0114b32011-02-18 10:14:07 -0800989 size = (s_callbacks.version < 6) ? sizeof(simIO.v5) : sizeof(simIO.v6);
Etan Cohend3652192014-06-20 08:28:44 -0700990 CALL_ONREQUEST(pRI->pCI->requestNumber, &simIO, size, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800991
992#ifdef MEMSET_FREED
Wink Savillec0114b32011-02-18 10:14:07 -0800993 memsetString (simIO.v6.path);
994 memsetString (simIO.v6.data);
995 memsetString (simIO.v6.pin2);
996 memsetString (simIO.v6.aidPtr);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800997#endif
998
Wink Savillec0114b32011-02-18 10:14:07 -0800999 free (simIO.v6.path);
1000 free (simIO.v6.data);
1001 free (simIO.v6.pin2);
1002 free (simIO.v6.aidPtr);
Wink Saville7f856802009-06-09 10:23:37 -07001003
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001004#ifdef MEMSET_FREED
1005 memset(&simIO, 0, sizeof(simIO));
1006#endif
1007
1008 return;
1009invalid:
1010 invalidCommandBlock(pRI);
1011 return;
1012}
1013
1014/**
Shishir Agrawal2458d8d2013-11-27 14:53:05 -08001015 * Callee expects const RIL_SIM_APDU *
1016 * Payload is:
1017 * int32_t sessionid
1018 * int32_t cla
1019 * int32_t instruction
1020 * int32_t p1, p2, p3
1021 * String data
1022 */
1023static void
1024dispatchSIM_APDU (Parcel &p, RequestInfo *pRI) {
1025 int32_t t;
1026 status_t status;
1027 RIL_SIM_APDU apdu;
1028
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07001029#if VDBG
Mark Salyzyndba25612015-04-09 07:18:35 -07001030 RLOGD("dispatchSIM_APDU");
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07001031#endif
Shishir Agrawal2458d8d2013-11-27 14:53:05 -08001032 memset (&apdu, 0, sizeof(RIL_SIM_APDU));
1033
1034 // Note we only check status at the end. Any single failure leads to
1035 // subsequent reads filing.
1036 status = p.readInt32(&t);
1037 apdu.sessionid = (int)t;
1038
1039 status = p.readInt32(&t);
1040 apdu.cla = (int)t;
1041
1042 status = p.readInt32(&t);
1043 apdu.instruction = (int)t;
1044
1045 status = p.readInt32(&t);
1046 apdu.p1 = (int)t;
1047
1048 status = p.readInt32(&t);
1049 apdu.p2 = (int)t;
1050
1051 status = p.readInt32(&t);
1052 apdu.p3 = (int)t;
1053
1054 apdu.data = strdupReadString(p);
1055
1056 startRequest;
1057 appendPrintBuf("%ssessionid=%d,cla=%d,ins=%d,p1=%d,p2=%d,p3=%d,data=%s",
1058 printBuf, apdu.sessionid, apdu.cla, apdu.instruction, apdu.p1, apdu.p2,
1059 apdu.p3, (char*)apdu.data);
1060 closeRequest;
1061 printRequest(pRI->token, pRI->pCI->requestNumber);
1062
1063 if (status != NO_ERROR) {
1064 goto invalid;
1065 }
1066
Etan Cohend3652192014-06-20 08:28:44 -07001067 CALL_ONREQUEST(pRI->pCI->requestNumber, &apdu, sizeof(RIL_SIM_APDU), pRI, pRI->socket_id);
Shishir Agrawal2458d8d2013-11-27 14:53:05 -08001068
1069#ifdef MEMSET_FREED
1070 memsetString(apdu.data);
1071#endif
1072 free(apdu.data);
1073
1074#ifdef MEMSET_FREED
1075 memset(&apdu, 0, sizeof(RIL_SIM_APDU));
1076#endif
1077
1078 return;
1079invalid:
1080 invalidCommandBlock(pRI);
1081 return;
1082}
1083
1084
1085/**
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001086 * Callee expects const RIL_CallForwardInfo *
1087 * Payload is:
1088 * int32_t status/action
1089 * int32_t reason
1090 * int32_t serviceCode
1091 * int32_t toa
1092 * String number (0 length -> null)
1093 * int32_t timeSeconds
1094 */
Wink Saville7f856802009-06-09 10:23:37 -07001095static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001096dispatchCallForward(Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001097 RIL_CallForwardInfo cff;
1098 int32_t t;
1099 status_t status;
1100
Mark Salyzyndba25612015-04-09 07:18:35 -07001101 RLOGD("dispatchCallForward");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001102 memset (&cff, 0, sizeof(cff));
1103
Wink Saville7f856802009-06-09 10:23:37 -07001104 // note we only check status at the end
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001105
1106 status = p.readInt32(&t);
1107 cff.status = (int)t;
Wink Saville7f856802009-06-09 10:23:37 -07001108
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001109 status = p.readInt32(&t);
1110 cff.reason = (int)t;
1111
1112 status = p.readInt32(&t);
1113 cff.serviceClass = (int)t;
1114
1115 status = p.readInt32(&t);
1116 cff.toa = (int)t;
1117
1118 cff.number = strdupReadString(p);
1119
1120 status = p.readInt32(&t);
1121 cff.timeSeconds = (int)t;
1122
1123 if (status != NO_ERROR) {
1124 goto invalid;
1125 }
1126
1127 // special case: number 0-length fields is null
1128
1129 if (cff.number != NULL && strlen (cff.number) == 0) {
1130 cff.number = NULL;
1131 }
1132
1133 startRequest;
1134 appendPrintBuf("%sstat=%d,reason=%d,serv=%d,toa=%d,%s,tout=%d", printBuf,
1135 cff.status, cff.reason, cff.serviceClass, cff.toa,
1136 (char*)cff.number, cff.timeSeconds);
1137 closeRequest;
1138 printRequest(pRI->token, pRI->pCI->requestNumber);
1139
Etan Cohend3652192014-06-20 08:28:44 -07001140 CALL_ONREQUEST(pRI->pCI->requestNumber, &cff, sizeof(cff), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001141
1142#ifdef MEMSET_FREED
1143 memsetString(cff.number);
1144#endif
1145
1146 free (cff.number);
1147
1148#ifdef MEMSET_FREED
1149 memset(&cff, 0, sizeof(cff));
1150#endif
1151
1152 return;
1153invalid:
1154 invalidCommandBlock(pRI);
1155 return;
1156}
1157
1158
Wink Saville7f856802009-06-09 10:23:37 -07001159static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001160dispatchRaw(Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001161 int32_t len;
1162 status_t status;
1163 const void *data;
1164
1165 status = p.readInt32(&len);
1166
1167 if (status != NO_ERROR) {
1168 goto invalid;
1169 }
1170
1171 // The java code writes -1 for null arrays
1172 if (((int)len) == -1) {
1173 data = NULL;
1174 len = 0;
Wink Saville7f856802009-06-09 10:23:37 -07001175 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001176
1177 data = p.readInplace(len);
1178
1179 startRequest;
1180 appendPrintBuf("%sraw_size=%d", printBuf, len);
1181 closeRequest;
1182 printRequest(pRI->token, pRI->pCI->requestNumber);
1183
Etan Cohend3652192014-06-20 08:28:44 -07001184 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<void *>(data), len, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001185
1186 return;
1187invalid:
1188 invalidCommandBlock(pRI);
1189 return;
1190}
1191
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001192static status_t
1193constructCdmaSms(Parcel &p, RequestInfo *pRI, RIL_CDMA_SMS_Message& rcsm) {
Wink Savillef4c4d362009-04-02 01:37:03 -07001194 int32_t t;
1195 uint8_t ut;
1196 status_t status;
1197 int32_t digitCount;
1198 int digitLimit;
Wink Saville7f856802009-06-09 10:23:37 -07001199
Wink Savillef4c4d362009-04-02 01:37:03 -07001200 memset(&rcsm, 0, sizeof(rcsm));
1201
1202 status = p.readInt32(&t);
1203 rcsm.uTeleserviceID = (int) t;
1204
1205 status = p.read(&ut,sizeof(ut));
1206 rcsm.bIsServicePresent = (uint8_t) ut;
1207
1208 status = p.readInt32(&t);
1209 rcsm.uServicecategory = (int) t;
1210
1211 status = p.readInt32(&t);
1212 rcsm.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1213
1214 status = p.readInt32(&t);
1215 rcsm.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1216
1217 status = p.readInt32(&t);
1218 rcsm.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1219
1220 status = p.readInt32(&t);
1221 rcsm.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1222
1223 status = p.read(&ut,sizeof(ut));
1224 rcsm.sAddress.number_of_digits= (uint8_t) ut;
1225
1226 digitLimit= MIN((rcsm.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
1227 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1228 status = p.read(&ut,sizeof(ut));
1229 rcsm.sAddress.digits[digitCount] = (uint8_t) ut;
1230 }
1231
Wink Saville7f856802009-06-09 10:23:37 -07001232 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001233 rcsm.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1234
Wink Saville7f856802009-06-09 10:23:37 -07001235 status = p.read(&ut,sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001236 rcsm.sSubAddress.odd = (uint8_t) ut;
1237
1238 status = p.read(&ut,sizeof(ut));
1239 rcsm.sSubAddress.number_of_digits = (uint8_t) ut;
1240
1241 digitLimit= MIN((rcsm.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
Wink Saville7f856802009-06-09 10:23:37 -07001242 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1243 status = p.read(&ut,sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001244 rcsm.sSubAddress.digits[digitCount] = (uint8_t) ut;
1245 }
1246
Wink Saville7f856802009-06-09 10:23:37 -07001247 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001248 rcsm.uBearerDataLen = (int) t;
1249
1250 digitLimit= MIN((rcsm.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
Wink Saville7f856802009-06-09 10:23:37 -07001251 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1252 status = p.read(&ut, sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001253 rcsm.aBearerData[digitCount] = (uint8_t) ut;
1254 }
1255
1256 if (status != NO_ERROR) {
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001257 return status;
Wink Savillef4c4d362009-04-02 01:37:03 -07001258 }
1259
1260 startRequest;
1261 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
Wink Saville1b5fd232009-04-22 14:50:00 -07001262 sAddress.digit_mode=%d, sAddress.Number_mode=%d, sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07001263 printBuf, rcsm.uTeleserviceID,rcsm.bIsServicePresent,rcsm.uServicecategory,
Wink Saville1b5fd232009-04-22 14:50:00 -07001264 rcsm.sAddress.digit_mode, rcsm.sAddress.number_mode,rcsm.sAddress.number_type);
Wink Savillef4c4d362009-04-02 01:37:03 -07001265 closeRequest;
Wink Saville7f856802009-06-09 10:23:37 -07001266
Wink Savillef4c4d362009-04-02 01:37:03 -07001267 printRequest(pRI->token, pRI->pCI->requestNumber);
1268
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001269 return status;
1270}
1271
1272static void
1273dispatchCdmaSms(Parcel &p, RequestInfo *pRI) {
1274 RIL_CDMA_SMS_Message rcsm;
1275
Mark Salyzyndba25612015-04-09 07:18:35 -07001276 RLOGD("dispatchCdmaSms");
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001277 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1278 goto invalid;
1279 }
1280
Etan Cohend3652192014-06-20 08:28:44 -07001281 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001282
1283#ifdef MEMSET_FREED
1284 memset(&rcsm, 0, sizeof(rcsm));
1285#endif
1286
1287 return;
1288
1289invalid:
1290 invalidCommandBlock(pRI);
1291 return;
1292}
1293
Wink Saville7f856802009-06-09 10:23:37 -07001294static void
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001295dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1296 RIL_IMS_SMS_Message rism;
1297 RIL_CDMA_SMS_Message rcsm;
1298
Mark Salyzyndba25612015-04-09 07:18:35 -07001299 RLOGD("dispatchImsCdmaSms: retry=%d, messageRef=%d", retry, messageRef);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001300
1301 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1302 goto invalid;
1303 }
1304 memset(&rism, 0, sizeof(rism));
1305 rism.tech = RADIO_TECH_3GPP2;
1306 rism.retry = retry;
1307 rism.messageRef = messageRef;
1308 rism.message.cdmaMessage = &rcsm;
1309
Etan Cohend3652192014-06-20 08:28:44 -07001310 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001311 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Etan Cohend3652192014-06-20 08:28:44 -07001312 +sizeof(rcsm),pRI, pRI->socket_id);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001313
1314#ifdef MEMSET_FREED
1315 memset(&rcsm, 0, sizeof(rcsm));
1316 memset(&rism, 0, sizeof(rism));
1317#endif
1318
1319 return;
1320
1321invalid:
1322 invalidCommandBlock(pRI);
1323 return;
1324}
1325
1326static void
1327dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1328 RIL_IMS_SMS_Message rism;
1329 int32_t countStrings;
1330 status_t status;
1331 size_t datalen;
1332 char **pStrings;
Mark Salyzyndba25612015-04-09 07:18:35 -07001333 RLOGD("dispatchImsGsmSms: retry=%d, messageRef=%d", retry, messageRef);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001334
1335 status = p.readInt32 (&countStrings);
1336
1337 if (status != NO_ERROR) {
1338 goto invalid;
1339 }
1340
1341 memset(&rism, 0, sizeof(rism));
1342 rism.tech = RADIO_TECH_3GPP;
1343 rism.retry = retry;
1344 rism.messageRef = messageRef;
1345
1346 startRequest;
Etan Cohen5d891b72014-02-27 17:25:17 -08001347 appendPrintBuf("%stech=%d, retry=%d, messageRef=%d, ", printBuf,
1348 (int)rism.tech, (int)rism.retry, rism.messageRef);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001349 if (countStrings == 0) {
1350 // just some non-null pointer
Sanket Padawe0cfc5532016-03-07 17:12:19 -08001351 pStrings = (char **)calloc(1, sizeof(char *));
Sanket Padawe55227b52016-02-29 10:09:26 -08001352 if (pStrings == NULL) {
1353 RLOGE("Memory allocation failed for request %s",
1354 requestToString(pRI->pCI->requestNumber));
1355 closeRequest;
1356 return;
1357 }
1358
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001359 datalen = 0;
Sanket Padawe0cfc5532016-03-07 17:12:19 -08001360 } else if (countStrings < 0) {
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001361 pStrings = NULL;
1362 datalen = 0;
1363 } else {
Meng Wangef966a32016-06-20 17:38:18 -07001364 if ((size_t)countStrings > (INT_MAX/sizeof(char *))) {
Sanket Padawe0cfc5532016-03-07 17:12:19 -08001365 RLOGE("Invalid value of countStrings: \n");
1366 closeRequest;
1367 return;
1368 }
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001369 datalen = sizeof(char *) * countStrings;
1370
Sanket Padawe0cfc5532016-03-07 17:12:19 -08001371 pStrings = (char **)calloc(countStrings, sizeof(char *));
Sanket Padawe55227b52016-02-29 10:09:26 -08001372 if (pStrings == NULL) {
1373 RLOGE("Memory allocation failed for request %s",
1374 requestToString(pRI->pCI->requestNumber));
1375 closeRequest;
1376 return;
1377 }
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001378
1379 for (int i = 0 ; i < countStrings ; i++) {
1380 pStrings[i] = strdupReadString(p);
1381 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
1382 }
1383 }
1384 removeLastChar;
1385 closeRequest;
1386 printRequest(pRI->token, pRI->pCI->requestNumber);
1387
1388 rism.message.gsmMessage = pStrings;
Etan Cohend3652192014-06-20 08:28:44 -07001389 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001390 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Etan Cohend3652192014-06-20 08:28:44 -07001391 +datalen, pRI, pRI->socket_id);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001392
1393 if (pStrings != NULL) {
1394 for (int i = 0 ; i < countStrings ; i++) {
1395#ifdef MEMSET_FREED
1396 memsetString (pStrings[i]);
1397#endif
1398 free(pStrings[i]);
1399 }
1400
1401#ifdef MEMSET_FREED
1402 memset(pStrings, 0, datalen);
1403#endif
Sanket Padawe0cfc5532016-03-07 17:12:19 -08001404 free(pStrings);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001405 }
1406
1407#ifdef MEMSET_FREED
1408 memset(&rism, 0, sizeof(rism));
1409#endif
1410 return;
1411invalid:
1412 ALOGE("dispatchImsGsmSms invalid block");
1413 invalidCommandBlock(pRI);
1414 return;
1415}
1416
1417static void
1418dispatchImsSms(Parcel &p, RequestInfo *pRI) {
1419 int32_t t;
1420 status_t status = p.readInt32(&t);
1421 RIL_RadioTechnologyFamily format;
1422 uint8_t retry;
1423 int32_t messageRef;
1424
Mark Salyzyndba25612015-04-09 07:18:35 -07001425 RLOGD("dispatchImsSms");
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001426 if (status != NO_ERROR) {
1427 goto invalid;
1428 }
1429 format = (RIL_RadioTechnologyFamily) t;
1430
1431 // read retry field
1432 status = p.read(&retry,sizeof(retry));
1433 if (status != NO_ERROR) {
1434 goto invalid;
1435 }
1436 // read messageRef field
1437 status = p.read(&messageRef,sizeof(messageRef));
1438 if (status != NO_ERROR) {
1439 goto invalid;
1440 }
1441
1442 if (RADIO_TECH_3GPP == format) {
1443 dispatchImsGsmSms(p, pRI, retry, messageRef);
1444 } else if (RADIO_TECH_3GPP2 == format) {
1445 dispatchImsCdmaSms(p, pRI, retry, messageRef);
1446 } else {
1447 ALOGE("requestImsSendSMS invalid format value =%d", format);
1448 }
1449
1450 return;
1451
1452invalid:
1453 invalidCommandBlock(pRI);
1454 return;
1455}
1456
1457static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001458dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI) {
1459 RIL_CDMA_SMS_Ack rcsa;
1460 int32_t t;
1461 status_t status;
1462 int32_t digitCount;
1463
Mark Salyzyndba25612015-04-09 07:18:35 -07001464 RLOGD("dispatchCdmaSmsAck");
Wink Savillef4c4d362009-04-02 01:37:03 -07001465 memset(&rcsa, 0, sizeof(rcsa));
1466
1467 status = p.readInt32(&t);
1468 rcsa.uErrorClass = (RIL_CDMA_SMS_ErrorClass) t;
1469
1470 status = p.readInt32(&t);
1471 rcsa.uSMSCauseCode = (int) t;
1472
1473 if (status != NO_ERROR) {
1474 goto invalid;
1475 }
1476
1477 startRequest;
Wink Saville1b5fd232009-04-22 14:50:00 -07001478 appendPrintBuf("%suErrorClass=%d, uTLStatus=%d, ",
1479 printBuf, rcsa.uErrorClass, rcsa.uSMSCauseCode);
Wink Savillef4c4d362009-04-02 01:37:03 -07001480 closeRequest;
1481
1482 printRequest(pRI->token, pRI->pCI->requestNumber);
1483
Etan Cohend3652192014-06-20 08:28:44 -07001484 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsa, sizeof(rcsa),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001485
1486#ifdef MEMSET_FREED
1487 memset(&rcsa, 0, sizeof(rcsa));
1488#endif
1489
1490 return;
1491
1492invalid:
1493 invalidCommandBlock(pRI);
1494 return;
1495}
1496
Wink Savillea592eeb2009-05-22 13:26:36 -07001497static void
1498dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1499 int32_t t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001500 status_t status;
Wink Savillea592eeb2009-05-22 13:26:36 -07001501 int32_t num;
Wink Savillef4c4d362009-04-02 01:37:03 -07001502
Wink Savillea592eeb2009-05-22 13:26:36 -07001503 status = p.readInt32(&num);
Wink Savillef4c4d362009-04-02 01:37:03 -07001504 if (status != NO_ERROR) {
1505 goto invalid;
1506 }
1507
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001508 {
1509 RIL_GSM_BroadcastSmsConfigInfo gsmBci[num];
1510 RIL_GSM_BroadcastSmsConfigInfo *gsmBciPtrs[num];
Wink Savillea592eeb2009-05-22 13:26:36 -07001511
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001512 startRequest;
1513 for (int i = 0 ; i < num ; i++ ) {
1514 gsmBciPtrs[i] = &gsmBci[i];
Wink Savillef4c4d362009-04-02 01:37:03 -07001515
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001516 status = p.readInt32(&t);
1517 gsmBci[i].fromServiceId = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001518
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001519 status = p.readInt32(&t);
1520 gsmBci[i].toServiceId = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001521
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001522 status = p.readInt32(&t);
1523 gsmBci[i].fromCodeScheme = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001524
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001525 status = p.readInt32(&t);
1526 gsmBci[i].toCodeScheme = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001527
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001528 status = p.readInt32(&t);
1529 gsmBci[i].selected = (uint8_t) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001530
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001531 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId =%d, \
1532 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]", printBuf, i,
1533 gsmBci[i].fromServiceId, gsmBci[i].toServiceId,
1534 gsmBci[i].fromCodeScheme, gsmBci[i].toCodeScheme,
1535 gsmBci[i].selected);
1536 }
1537 closeRequest;
Wink Savillef4c4d362009-04-02 01:37:03 -07001538
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001539 if (status != NO_ERROR) {
1540 goto invalid;
1541 }
Wink Savillef4c4d362009-04-02 01:37:03 -07001542
Etan Cohend3652192014-06-20 08:28:44 -07001543 CALL_ONREQUEST(pRI->pCI->requestNumber,
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001544 gsmBciPtrs,
1545 num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *),
Etan Cohend3652192014-06-20 08:28:44 -07001546 pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001547
1548#ifdef MEMSET_FREED
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001549 memset(gsmBci, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo));
1550 memset(gsmBciPtrs, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *));
Wink Savillef4c4d362009-04-02 01:37:03 -07001551#endif
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001552 }
Wink Savillef4c4d362009-04-02 01:37:03 -07001553
1554 return;
1555
1556invalid:
1557 invalidCommandBlock(pRI);
1558 return;
Wink Savillea592eeb2009-05-22 13:26:36 -07001559}
Wink Savillef4c4d362009-04-02 01:37:03 -07001560
Wink Savillea592eeb2009-05-22 13:26:36 -07001561static void
1562dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1563 int32_t t;
1564 status_t status;
1565 int32_t num;
1566
1567 status = p.readInt32(&num);
1568 if (status != NO_ERROR) {
1569 goto invalid;
1570 }
1571
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001572 {
1573 RIL_CDMA_BroadcastSmsConfigInfo cdmaBci[num];
1574 RIL_CDMA_BroadcastSmsConfigInfo *cdmaBciPtrs[num];
Wink Savillea592eeb2009-05-22 13:26:36 -07001575
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001576 startRequest;
1577 for (int i = 0 ; i < num ; i++ ) {
1578 cdmaBciPtrs[i] = &cdmaBci[i];
Wink Savillea592eeb2009-05-22 13:26:36 -07001579
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001580 status = p.readInt32(&t);
1581 cdmaBci[i].service_category = (int) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001582
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001583 status = p.readInt32(&t);
1584 cdmaBci[i].language = (int) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001585
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001586 status = p.readInt32(&t);
1587 cdmaBci[i].selected = (uint8_t) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001588
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001589 appendPrintBuf("%s [%d: service_category=%d, language =%d, \
1590 entries.bSelected =%d]", printBuf, i, cdmaBci[i].service_category,
1591 cdmaBci[i].language, cdmaBci[i].selected);
1592 }
1593 closeRequest;
Wink Savillea592eeb2009-05-22 13:26:36 -07001594
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001595 if (status != NO_ERROR) {
1596 goto invalid;
1597 }
Wink Savillea592eeb2009-05-22 13:26:36 -07001598
Etan Cohend3652192014-06-20 08:28:44 -07001599 CALL_ONREQUEST(pRI->pCI->requestNumber,
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001600 cdmaBciPtrs,
1601 num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *),
Etan Cohend3652192014-06-20 08:28:44 -07001602 pRI, pRI->socket_id);
Wink Savillea592eeb2009-05-22 13:26:36 -07001603
1604#ifdef MEMSET_FREED
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001605 memset(cdmaBci, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo));
1606 memset(cdmaBciPtrs, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *));
Wink Savillea592eeb2009-05-22 13:26:36 -07001607#endif
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001608 }
Wink Savillea592eeb2009-05-22 13:26:36 -07001609
1610 return;
1611
1612invalid:
1613 invalidCommandBlock(pRI);
1614 return;
Wink Savillef4c4d362009-04-02 01:37:03 -07001615}
1616
1617static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI) {
1618 RIL_CDMA_SMS_WriteArgs rcsw;
1619 int32_t t;
1620 uint32_t ut;
1621 uint8_t uct;
1622 status_t status;
1623 int32_t digitCount;
Sukanya Rajkhowa605c7842013-10-29 14:55:30 +08001624 int32_t digitLimit;
Wink Savillef4c4d362009-04-02 01:37:03 -07001625
1626 memset(&rcsw, 0, sizeof(rcsw));
1627
1628 status = p.readInt32(&t);
1629 rcsw.status = t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001630
Wink Savillef4c4d362009-04-02 01:37:03 -07001631 status = p.readInt32(&t);
1632 rcsw.message.uTeleserviceID = (int) t;
1633
1634 status = p.read(&uct,sizeof(uct));
1635 rcsw.message.bIsServicePresent = (uint8_t) uct;
1636
1637 status = p.readInt32(&t);
1638 rcsw.message.uServicecategory = (int) t;
1639
1640 status = p.readInt32(&t);
1641 rcsw.message.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1642
1643 status = p.readInt32(&t);
1644 rcsw.message.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1645
1646 status = p.readInt32(&t);
1647 rcsw.message.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1648
1649 status = p.readInt32(&t);
1650 rcsw.message.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1651
1652 status = p.read(&uct,sizeof(uct));
1653 rcsw.message.sAddress.number_of_digits = (uint8_t) uct;
1654
Sukanya Rajkhowa605c7842013-10-29 14:55:30 +08001655 digitLimit = MIN((rcsw.message.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
1656
1657 for(digitCount = 0 ; digitCount < digitLimit; digitCount ++) {
Wink Savillef4c4d362009-04-02 01:37:03 -07001658 status = p.read(&uct,sizeof(uct));
1659 rcsw.message.sAddress.digits[digitCount] = (uint8_t) uct;
1660 }
1661
Wink Savillea592eeb2009-05-22 13:26:36 -07001662 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001663 rcsw.message.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1664
Wink Savillea592eeb2009-05-22 13:26:36 -07001665 status = p.read(&uct,sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001666 rcsw.message.sSubAddress.odd = (uint8_t) uct;
1667
1668 status = p.read(&uct,sizeof(uct));
1669 rcsw.message.sSubAddress.number_of_digits = (uint8_t) uct;
1670
Sukanya Rajkhowa605c7842013-10-29 14:55:30 +08001671 digitLimit = MIN((rcsw.message.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
1672
1673 for(digitCount = 0 ; digitCount < digitLimit; digitCount ++) {
Wink Savillea592eeb2009-05-22 13:26:36 -07001674 status = p.read(&uct,sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001675 rcsw.message.sSubAddress.digits[digitCount] = (uint8_t) uct;
1676 }
1677
Wink Savillea592eeb2009-05-22 13:26:36 -07001678 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001679 rcsw.message.uBearerDataLen = (int) t;
1680
Sukanya Rajkhowa605c7842013-10-29 14:55:30 +08001681 digitLimit = MIN((rcsw.message.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
1682
1683 for(digitCount = 0 ; digitCount < digitLimit; digitCount ++) {
Wink Savillea592eeb2009-05-22 13:26:36 -07001684 status = p.read(&uct, sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001685 rcsw.message.aBearerData[digitCount] = (uint8_t) uct;
1686 }
1687
1688 if (status != NO_ERROR) {
1689 goto invalid;
1690 }
1691
1692 startRequest;
Wink Saville1b5fd232009-04-22 14:50:00 -07001693 appendPrintBuf("%sstatus=%d, message.uTeleserviceID=%d, message.bIsServicePresent=%d, \
1694 message.uServicecategory=%d, message.sAddress.digit_mode=%d, \
1695 message.sAddress.number_mode=%d, \
1696 message.sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07001697 printBuf, rcsw.status, rcsw.message.uTeleserviceID, rcsw.message.bIsServicePresent,
Wink Saville1b5fd232009-04-22 14:50:00 -07001698 rcsw.message.uServicecategory, rcsw.message.sAddress.digit_mode,
1699 rcsw.message.sAddress.number_mode,
1700 rcsw.message.sAddress.number_type);
Wink Savillef4c4d362009-04-02 01:37:03 -07001701 closeRequest;
1702
1703 printRequest(pRI->token, pRI->pCI->requestNumber);
1704
Etan Cohend3652192014-06-20 08:28:44 -07001705 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsw, sizeof(rcsw),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001706
1707#ifdef MEMSET_FREED
1708 memset(&rcsw, 0, sizeof(rcsw));
1709#endif
1710
1711 return;
1712
1713invalid:
1714 invalidCommandBlock(pRI);
1715 return;
1716
1717}
1718
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -07001719// For backwards compatibility in RIL_REQUEST_SETUP_DATA_CALL.
1720// Version 4 of the RIL interface adds a new PDP type parameter to support
1721// IPv6 and dual-stack PDP contexts. When dealing with a previous version of
1722// RIL, remove the parameter from the request.
1723static void dispatchDataCall(Parcel& p, RequestInfo *pRI) {
1724 // In RIL v3, REQUEST_SETUP_DATA_CALL takes 6 parameters.
1725 const int numParamsRilV3 = 6;
1726
1727 // The first bytes of the RIL parcel contain the request number and the
1728 // serial number - see processCommandBuffer(). Copy them over too.
1729 int pos = p.dataPosition();
1730
1731 int numParams = p.readInt32();
1732 if (s_callbacks.version < 4 && numParams > numParamsRilV3) {
1733 Parcel p2;
1734 p2.appendFrom(&p, 0, pos);
1735 p2.writeInt32(numParamsRilV3);
1736 for(int i = 0; i < numParamsRilV3; i++) {
1737 p2.writeString16(p.readString16());
1738 }
1739 p2.setDataPosition(pos);
1740 dispatchStrings(p2, pRI);
1741 } else {
Lorenzo Colitti57ce1f22010-09-13 12:23:50 -07001742 p.setDataPosition(pos);
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -07001743 dispatchStrings(p, pRI);
1744 }
1745}
1746
Sungmin Choi75697532013-04-26 15:04:45 -07001747static void dispatchSetInitialAttachApn(Parcel &p, RequestInfo *pRI)
1748{
1749 RIL_InitialAttachApn pf;
1750 int32_t t;
1751 status_t status;
1752
1753 memset(&pf, 0, sizeof(pf));
1754
1755 pf.apn = strdupReadString(p);
1756 pf.protocol = strdupReadString(p);
1757
1758 status = p.readInt32(&t);
1759 pf.authtype = (int) t;
1760
1761 pf.username = strdupReadString(p);
1762 pf.password = strdupReadString(p);
1763
1764 startRequest;
Etan Cohen5d891b72014-02-27 17:25:17 -08001765 appendPrintBuf("%sapn=%s, protocol=%s, authtype=%d, username=%s, password=%s",
1766 printBuf, pf.apn, pf.protocol, pf.authtype, pf.username, pf.password);
Sungmin Choi75697532013-04-26 15:04:45 -07001767 closeRequest;
1768 printRequest(pRI->token, pRI->pCI->requestNumber);
1769
1770 if (status != NO_ERROR) {
1771 goto invalid;
1772 }
Etan Cohend3652192014-06-20 08:28:44 -07001773 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
Sungmin Choi75697532013-04-26 15:04:45 -07001774
1775#ifdef MEMSET_FREED
1776 memsetString(pf.apn);
1777 memsetString(pf.protocol);
1778 memsetString(pf.username);
1779 memsetString(pf.password);
1780#endif
1781
1782 free(pf.apn);
1783 free(pf.protocol);
1784 free(pf.username);
1785 free(pf.password);
1786
1787#ifdef MEMSET_FREED
1788 memset(&pf, 0, sizeof(pf));
1789#endif
1790
1791 return;
1792invalid:
1793 invalidCommandBlock(pRI);
1794 return;
1795}
1796
Jake Hamby8a4a2332014-01-15 13:12:05 -08001797static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI) {
1798 RIL_NV_ReadItem nvri;
1799 int32_t t;
1800 status_t status;
1801
1802 memset(&nvri, 0, sizeof(nvri));
1803
1804 status = p.readInt32(&t);
1805 nvri.itemID = (RIL_NV_Item) t;
1806
1807 if (status != NO_ERROR) {
1808 goto invalid;
1809 }
1810
1811 startRequest;
1812 appendPrintBuf("%snvri.itemID=%d, ", printBuf, nvri.itemID);
1813 closeRequest;
1814
1815 printRequest(pRI->token, pRI->pCI->requestNumber);
1816
Etan Cohend3652192014-06-20 08:28:44 -07001817 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvri, sizeof(nvri), pRI, pRI->socket_id);
Jake Hamby8a4a2332014-01-15 13:12:05 -08001818
1819#ifdef MEMSET_FREED
1820 memset(&nvri, 0, sizeof(nvri));
1821#endif
1822
1823 return;
1824
1825invalid:
1826 invalidCommandBlock(pRI);
1827 return;
1828}
1829
1830static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI) {
1831 RIL_NV_WriteItem nvwi;
1832 int32_t t;
1833 status_t status;
1834
1835 memset(&nvwi, 0, sizeof(nvwi));
1836
1837 status = p.readInt32(&t);
1838 nvwi.itemID = (RIL_NV_Item) t;
1839
1840 nvwi.value = strdupReadString(p);
1841
1842 if (status != NO_ERROR || nvwi.value == NULL) {
1843 goto invalid;
1844 }
1845
1846 startRequest;
1847 appendPrintBuf("%snvwi.itemID=%d, value=%s, ", printBuf, nvwi.itemID,
1848 nvwi.value);
1849 closeRequest;
1850
1851 printRequest(pRI->token, pRI->pCI->requestNumber);
1852
Etan Cohend3652192014-06-20 08:28:44 -07001853 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvwi, sizeof(nvwi), pRI, pRI->socket_id);
Jake Hamby8a4a2332014-01-15 13:12:05 -08001854
1855#ifdef MEMSET_FREED
1856 memsetString(nvwi.value);
1857#endif
1858
1859 free(nvwi.value);
1860
1861#ifdef MEMSET_FREED
1862 memset(&nvwi, 0, sizeof(nvwi));
1863#endif
1864
1865 return;
1866
1867invalid:
1868 invalidCommandBlock(pRI);
1869 return;
1870}
1871
1872
Etan Cohend3652192014-06-20 08:28:44 -07001873static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI) {
1874 RIL_SelectUiccSub uicc_sub;
1875 status_t status;
1876 int32_t t;
1877 memset(&uicc_sub, 0, sizeof(uicc_sub));
1878
1879 status = p.readInt32(&t);
1880 if (status != NO_ERROR) {
1881 goto invalid;
1882 }
1883 uicc_sub.slot = (int) t;
1884
1885 status = p.readInt32(&t);
1886 if (status != NO_ERROR) {
1887 goto invalid;
1888 }
1889 uicc_sub.app_index = (int) t;
1890
1891 status = p.readInt32(&t);
1892 if (status != NO_ERROR) {
1893 goto invalid;
1894 }
1895 uicc_sub.sub_type = (RIL_SubscriptionType) t;
1896
1897 status = p.readInt32(&t);
1898 if (status != NO_ERROR) {
1899 goto invalid;
1900 }
1901 uicc_sub.act_status = (RIL_UiccSubActStatus) t;
1902
1903 startRequest;
1904 appendPrintBuf("slot=%d, app_index=%d, act_status = %d", uicc_sub.slot, uicc_sub.app_index,
1905 uicc_sub.act_status);
1906 RLOGD("dispatchUiccSubscription, slot=%d, app_index=%d, act_status = %d", uicc_sub.slot,
1907 uicc_sub.app_index, uicc_sub.act_status);
1908 closeRequest;
1909 printRequest(pRI->token, pRI->pCI->requestNumber);
1910
1911 CALL_ONREQUEST(pRI->pCI->requestNumber, &uicc_sub, sizeof(uicc_sub), pRI, pRI->socket_id);
1912
1913#ifdef MEMSET_FREED
1914 memset(&uicc_sub, 0, sizeof(uicc_sub));
1915#endif
1916 return;
1917
1918invalid:
1919 invalidCommandBlock(pRI);
1920 return;
1921}
1922
Amit Mahajan90530a62014-07-01 15:54:08 -07001923static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI)
1924{
1925 RIL_SimAuthentication pf;
1926 int32_t t;
1927 status_t status;
1928
1929 memset(&pf, 0, sizeof(pf));
1930
1931 status = p.readInt32(&t);
1932 pf.authContext = (int) t;
1933 pf.authData = strdupReadString(p);
1934 pf.aid = strdupReadString(p);
1935
1936 startRequest;
1937 appendPrintBuf("authContext=%s, authData=%s, aid=%s", pf.authContext, pf.authData, pf.aid);
1938 closeRequest;
1939 printRequest(pRI->token, pRI->pCI->requestNumber);
1940
1941 if (status != NO_ERROR) {
1942 goto invalid;
1943 }
1944 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
1945
1946#ifdef MEMSET_FREED
1947 memsetString(pf.authData);
1948 memsetString(pf.aid);
1949#endif
1950
1951 free(pf.authData);
1952 free(pf.aid);
1953
1954#ifdef MEMSET_FREED
1955 memset(&pf, 0, sizeof(pf));
1956#endif
1957
1958 return;
1959invalid:
1960 invalidCommandBlock(pRI);
1961 return;
1962}
1963
Amit Mahajanc796e222014-08-13 16:54:01 +00001964static void dispatchDataProfile(Parcel &p, RequestInfo *pRI) {
1965 int32_t t;
1966 status_t status;
1967 int32_t num;
1968
1969 status = p.readInt32(&num);
Sanket Padawe0cfc5532016-03-07 17:12:19 -08001970 if (status != NO_ERROR || num < 0) {
Amit Mahajanc796e222014-08-13 16:54:01 +00001971 goto invalid;
1972 }
1973
1974 {
Sanket Padawe55227b52016-02-29 10:09:26 -08001975 RIL_DataProfileInfo *dataProfiles =
Sanket Padawe0cfc5532016-03-07 17:12:19 -08001976 (RIL_DataProfileInfo *)calloc(num, sizeof(RIL_DataProfileInfo));
Sanket Padawe55227b52016-02-29 10:09:26 -08001977 if (dataProfiles == NULL) {
1978 RLOGE("Memory allocation failed for request %s",
1979 requestToString(pRI->pCI->requestNumber));
1980 return;
1981 }
1982 RIL_DataProfileInfo **dataProfilePtrs =
Sanket Padawe0cfc5532016-03-07 17:12:19 -08001983 (RIL_DataProfileInfo **)calloc(num, sizeof(RIL_DataProfileInfo *));
Sanket Padawe55227b52016-02-29 10:09:26 -08001984 if (dataProfilePtrs == NULL) {
1985 RLOGE("Memory allocation failed for request %s",
1986 requestToString(pRI->pCI->requestNumber));
1987 free(dataProfiles);
1988 return;
1989 }
Amit Mahajanc796e222014-08-13 16:54:01 +00001990
1991 startRequest;
1992 for (int i = 0 ; i < num ; i++ ) {
1993 dataProfilePtrs[i] = &dataProfiles[i];
1994
1995 status = p.readInt32(&t);
1996 dataProfiles[i].profileId = (int) t;
1997
1998 dataProfiles[i].apn = strdupReadString(p);
1999 dataProfiles[i].protocol = strdupReadString(p);
2000 status = p.readInt32(&t);
2001 dataProfiles[i].authType = (int) t;
2002
2003 dataProfiles[i].user = strdupReadString(p);
2004 dataProfiles[i].password = strdupReadString(p);
2005
2006 status = p.readInt32(&t);
2007 dataProfiles[i].type = (int) t;
2008
2009 status = p.readInt32(&t);
2010 dataProfiles[i].maxConnsTime = (int) t;
2011 status = p.readInt32(&t);
2012 dataProfiles[i].maxConns = (int) t;
2013 status = p.readInt32(&t);
2014 dataProfiles[i].waitTime = (int) t;
2015
2016 status = p.readInt32(&t);
2017 dataProfiles[i].enabled = (int) t;
2018
2019 appendPrintBuf("%s [%d: profileId=%d, apn =%s, protocol =%s, authType =%d, \
2020 user =%s, password =%s, type =%d, maxConnsTime =%d, maxConns =%d, \
2021 waitTime =%d, enabled =%d]", printBuf, i, dataProfiles[i].profileId,
2022 dataProfiles[i].apn, dataProfiles[i].protocol, dataProfiles[i].authType,
2023 dataProfiles[i].user, dataProfiles[i].password, dataProfiles[i].type,
2024 dataProfiles[i].maxConnsTime, dataProfiles[i].maxConns,
2025 dataProfiles[i].waitTime, dataProfiles[i].enabled);
2026 }
2027 closeRequest;
2028 printRequest(pRI->token, pRI->pCI->requestNumber);
2029
2030 if (status != NO_ERROR) {
Sanket Padawe55227b52016-02-29 10:09:26 -08002031 free(dataProfiles);
2032 free(dataProfilePtrs);
Amit Mahajanc796e222014-08-13 16:54:01 +00002033 goto invalid;
2034 }
2035 CALL_ONREQUEST(pRI->pCI->requestNumber,
2036 dataProfilePtrs,
2037 num * sizeof(RIL_DataProfileInfo *),
2038 pRI, pRI->socket_id);
2039
2040#ifdef MEMSET_FREED
2041 memset(dataProfiles, 0, num * sizeof(RIL_DataProfileInfo));
2042 memset(dataProfilePtrs, 0, num * sizeof(RIL_DataProfileInfo *));
2043#endif
Sanket Padawe55227b52016-02-29 10:09:26 -08002044 free(dataProfiles);
2045 free(dataProfilePtrs);
Amit Mahajanc796e222014-08-13 16:54:01 +00002046 }
2047
2048 return;
2049
2050invalid:
2051 invalidCommandBlock(pRI);
2052 return;
2053}
2054
Wink Saville8b4e4f72014-10-17 15:01:45 -07002055static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI){
2056 RIL_RadioCapability rc;
2057 int32_t t;
2058 status_t status;
2059
2060 memset (&rc, 0, sizeof(RIL_RadioCapability));
2061
2062 status = p.readInt32(&t);
2063 rc.version = (int)t;
2064 if (status != NO_ERROR) {
2065 goto invalid;
2066 }
2067
2068 status = p.readInt32(&t);
2069 rc.session= (int)t;
2070 if (status != NO_ERROR) {
2071 goto invalid;
2072 }
2073
2074 status = p.readInt32(&t);
2075 rc.phase= (int)t;
2076 if (status != NO_ERROR) {
2077 goto invalid;
2078 }
2079
2080 status = p.readInt32(&t);
2081 rc.rat = (int)t;
2082 if (status != NO_ERROR) {
2083 goto invalid;
2084 }
2085
2086 status = readStringFromParcelInplace(p, rc.logicalModemUuid, sizeof(rc.logicalModemUuid));
2087 if (status != NO_ERROR) {
2088 goto invalid;
2089 }
2090
2091 status = p.readInt32(&t);
2092 rc.status = (int)t;
2093
2094 if (status != NO_ERROR) {
2095 goto invalid;
2096 }
2097
2098 startRequest;
2099 appendPrintBuf("%s [version:%d, session:%d, phase:%d, rat:%d, \
Chih-Wei Huang8593f262015-10-02 15:09:52 +08002100 logicalModemUuid:%s, status:%d", printBuf, rc.version, rc.session,
Legler Wu8caf06f2014-10-29 14:02:14 +08002101 rc.phase, rc.rat, rc.logicalModemUuid, rc.session);
Wink Saville8b4e4f72014-10-17 15:01:45 -07002102
2103 closeRequest;
2104 printRequest(pRI->token, pRI->pCI->requestNumber);
2105
2106 CALL_ONREQUEST(pRI->pCI->requestNumber,
2107 &rc,
2108 sizeof(RIL_RadioCapability),
2109 pRI, pRI->socket_id);
2110 return;
2111invalid:
2112 invalidCommandBlock(pRI);
2113 return;
2114}
2115
Meng Wangb4e34312016-05-12 14:54:36 -07002116/**
2117 * Callee expects const RIL_CarrierRestrictions *
2118 */
2119static void dispatchCarrierRestrictions(Parcel &p, RequestInfo *pRI) {
2120 RIL_CarrierRestrictions cr;
2121 RIL_Carrier * allowed_carriers = NULL;
2122 RIL_Carrier * excluded_carriers = NULL;
2123 int32_t t;
2124 status_t status;
2125
2126 memset(&cr, 0, sizeof(RIL_CarrierRestrictions));
2127
Robert Greenwalt27e99c52016-06-01 16:31:38 -07002128 if (s_callbacks.version < 14) {
Meng Wangb4e34312016-05-12 14:54:36 -07002129 RLOGE("Unsuppoted RIL version %d, min version expected %d",
Robert Greenwalt27e99c52016-06-01 16:31:38 -07002130 s_callbacks.version, 14);
Meng Wangdf8398c2016-05-25 12:59:15 -07002131 RIL_onRequestComplete(pRI, RIL_E_REQUEST_NOT_SUPPORTED, NULL, 0);
2132 return;
Meng Wangb4e34312016-05-12 14:54:36 -07002133 }
2134
2135 status = p.readInt32(&t);
2136 if (status != NO_ERROR) {
2137 goto invalid;
2138 }
2139 allowed_carriers = (RIL_Carrier *)calloc(t, sizeof(RIL_Carrier));
2140 if (allowed_carriers == NULL) {
2141 RLOGE("Memory allocation failed for request %s", requestToString(pRI->pCI->requestNumber));
2142 goto exit;
2143 }
2144 cr.len_allowed_carriers = t;
2145 cr.allowed_carriers = allowed_carriers;
2146
2147 status = p.readInt32(&t);
2148 if (status != NO_ERROR) {
2149 goto invalid;
2150 }
2151 excluded_carriers = (RIL_Carrier *)calloc(t, sizeof(RIL_Carrier));
2152 if (excluded_carriers == NULL) {
2153 RLOGE("Memory allocation failed for request %s", requestToString(pRI->pCI->requestNumber));
2154 goto exit;
2155 }
2156 cr.len_excluded_carriers = t;
2157 cr.excluded_carriers = excluded_carriers;
2158
Meng Wang5d703cb2016-06-08 11:53:25 -07002159 startRequest;
2160 appendPrintBuf("%s len_allowed_carriers:%d, len_excluded_carriers:%d,",
2161 printBuf, cr.len_allowed_carriers, cr.len_excluded_carriers);
2162
2163 appendPrintBuf("%s allowed_carriers:", printBuf);
Meng Wangb4e34312016-05-12 14:54:36 -07002164 for (int32_t i = 0; i < cr.len_allowed_carriers; i++) {
2165 RIL_Carrier *p_cr = allowed_carriers + i;
Meng Wang5d703cb2016-06-08 11:53:25 -07002166 p_cr->mcc = strdupReadString(p);
2167 p_cr->mnc = strdupReadString(p);
Meng Wangb4e34312016-05-12 14:54:36 -07002168 status = p.readInt32(&t);
2169 p_cr->match_type = static_cast<RIL_CarrierMatchType>(t);
2170 if (status != NO_ERROR) {
2171 goto invalid;
2172 }
Meng Wang5d703cb2016-06-08 11:53:25 -07002173 p_cr->match_data = strdupReadString(p);
2174 appendPrintBuf("%s [%d mcc:%s, mnc:%s, match_type:%d, match_data:%s],",
2175 printBuf, i, p_cr->mcc, p_cr->mnc, p_cr->match_type, p_cr->match_data);
Meng Wangb4e34312016-05-12 14:54:36 -07002176 }
2177
2178 for (int32_t i = 0; i < cr.len_excluded_carriers; i++) {
2179 RIL_Carrier *p_cr = excluded_carriers + i;
Meng Wang5d703cb2016-06-08 11:53:25 -07002180 p_cr->mcc = strdupReadString(p);
2181 p_cr->mnc = strdupReadString(p);
Meng Wangb4e34312016-05-12 14:54:36 -07002182 status = p.readInt32(&t);
2183 p_cr->match_type = static_cast<RIL_CarrierMatchType>(t);
2184 if (status != NO_ERROR) {
2185 goto invalid;
2186 }
Meng Wang5d703cb2016-06-08 11:53:25 -07002187 p_cr->match_data = strdupReadString(p);
2188 appendPrintBuf("%s [%d mcc:%s, mnc:%s, match_type:%d, match_data:%s],",
2189 printBuf, i, p_cr->mcc, p_cr->mnc, p_cr->match_type, p_cr->match_data);
Meng Wangb4e34312016-05-12 14:54:36 -07002190 }
2191
Meng Wangb4e34312016-05-12 14:54:36 -07002192 closeRequest;
2193 printRequest(pRI->token, pRI->pCI->requestNumber);
2194
2195 CALL_ONREQUEST(pRI->pCI->requestNumber,
2196 &cr,
2197 sizeof(RIL_CarrierRestrictions),
2198 pRI, pRI->socket_id);
2199
2200 goto exit;
2201
2202invalid:
2203 invalidCommandBlock(pRI);
Meng Wangdf8398c2016-05-25 12:59:15 -07002204 RIL_onRequestComplete(pRI, RIL_E_INVALID_ARGUMENTS, NULL, 0);
Meng Wangb4e34312016-05-12 14:54:36 -07002205exit:
2206 if (allowed_carriers != NULL) {
2207 free(allowed_carriers);
2208 }
2209 if (excluded_carriers != NULL) {
2210 free(excluded_carriers);
2211 }
2212 return;
2213}
2214
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002215static int
Wink Savillef4c4d362009-04-02 01:37:03 -07002216blockingWrite(int fd, const void *buffer, size_t len) {
Wink Saville7f856802009-06-09 10:23:37 -07002217 size_t writeOffset = 0;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002218 const uint8_t *toWrite;
2219
2220 toWrite = (const uint8_t *)buffer;
2221
2222 while (writeOffset < len) {
2223 ssize_t written;
2224 do {
2225 written = write (fd, toWrite + writeOffset,
2226 len - writeOffset);
Banavathu, Srinivas Naik38884902011-07-05 20:04:25 +05302227 } while (written < 0 && ((errno == EINTR) || (errno == EAGAIN)));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002228
2229 if (written >= 0) {
2230 writeOffset += written;
2231 } else { // written < 0
Wink Saville8eb2a122012-11-19 16:05:13 -08002232 RLOGE ("RIL Response: unexpected error on write errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002233 close(fd);
2234 return -1;
2235 }
2236 }
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07002237#if VDBG
Dheeraj Shetty27976c42014-07-02 21:27:57 +02002238 RLOGE("RIL Response bytes written:%d", writeOffset);
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07002239#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002240 return 0;
2241}
2242
2243static int
Etan Cohend3652192014-06-20 08:28:44 -07002244sendResponseRaw (const void *data, size_t dataSize, RIL_SOCKET_ID socket_id) {
2245 int fd = s_ril_param_socket.fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002246 int ret;
2247 uint32_t header;
Etan Cohend3652192014-06-20 08:28:44 -07002248 pthread_mutex_t * writeMutexHook = &s_writeMutex;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002249
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07002250#if VDBG
Etan Cohend3652192014-06-20 08:28:44 -07002251 RLOGE("Send Response to %s", rilSocketIdToString(socket_id));
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07002252#endif
Etan Cohend3652192014-06-20 08:28:44 -07002253
2254#if (SIM_COUNT >= 2)
2255 if (socket_id == RIL_SOCKET_2) {
2256 fd = s_ril_param_socket2.fdCommand;
2257 writeMutexHook = &s_writeMutex_socket2;
2258 }
2259#if (SIM_COUNT >= 3)
2260 else if (socket_id == RIL_SOCKET_3) {
2261 fd = s_ril_param_socket3.fdCommand;
2262 writeMutexHook = &s_writeMutex_socket3;
2263 }
2264#endif
2265#if (SIM_COUNT >= 4)
2266 else if (socket_id == RIL_SOCKET_4) {
2267 fd = s_ril_param_socket4.fdCommand;
2268 writeMutexHook = &s_writeMutex_socket4;
2269 }
2270#endif
2271#endif
2272 if (fd < 0) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002273 return -1;
2274 }
2275
2276 if (dataSize > MAX_COMMAND_BYTES) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002277 RLOGE("RIL: packet larger than %u (%u)",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002278 MAX_COMMAND_BYTES, (unsigned int )dataSize);
2279
2280 return -1;
2281 }
Wink Saville7f856802009-06-09 10:23:37 -07002282
Etan Cohend3652192014-06-20 08:28:44 -07002283 pthread_mutex_lock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002284
2285 header = htonl(dataSize);
2286
2287 ret = blockingWrite(fd, (void *)&header, sizeof(header));
2288
2289 if (ret < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002290 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002291 return ret;
2292 }
2293
Kennyee1fadc2009-08-13 00:45:53 +08002294 ret = blockingWrite(fd, data, dataSize);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002295
2296 if (ret < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002297 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002298 return ret;
2299 }
2300
Etan Cohend3652192014-06-20 08:28:44 -07002301 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002302
2303 return 0;
2304}
2305
2306static int
Etan Cohend3652192014-06-20 08:28:44 -07002307sendResponse (Parcel &p, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002308 printResponse;
Etan Cohend3652192014-06-20 08:28:44 -07002309 return sendResponseRaw(p.data(), p.dataSize(), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002310}
2311
Mohamad Ayyash74f7e662014-04-18 11:43:28 -07002312/** response is an int* pointing to an array of ints */
Wink Saville7f856802009-06-09 10:23:37 -07002313
2314static int
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002315responseInts(Parcel &p, int slotId, int requestNumber, int responseType, int token, RIL_Errno e,
2316 void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002317 int numInts;
2318
2319 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002320 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002321 return RIL_ERRNO_INVALID_RESPONSE;
2322 }
2323 if (responselen % sizeof(int) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002324 RLOGE("responseInts: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002325 (int)responselen, (int)sizeof(int));
2326 return RIL_ERRNO_INVALID_RESPONSE;
2327 }
2328
2329 int *p_int = (int *) response;
2330
Mohamad Ayyash74f7e662014-04-18 11:43:28 -07002331 numInts = responselen / sizeof(int);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002332 p.writeInt32 (numInts);
2333
2334 /* each int*/
2335 startResponse;
2336 for (int i = 0 ; i < numInts ; i++) {
2337 appendPrintBuf("%s%d,", printBuf, p_int[i]);
2338 p.writeInt32(p_int[i]);
2339 }
2340 removeLastChar;
2341 closeResponse;
2342
2343 return 0;
2344}
2345
Chao Liu548a81e2015-05-14 16:13:46 -07002346// Response is an int or RIL_LastCallFailCauseInfo.
2347// Currently, only Shamu plans to use RIL_LastCallFailCauseInfo.
2348// TODO(yjl): Let all implementations use RIL_LastCallFailCauseInfo.
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002349static int responseFailCause(Parcel &p, int slotId, int requestNumber, int responseType, int token,
2350 RIL_Errno e, void *response, size_t responselen) {
Chao Liu548a81e2015-05-14 16:13:46 -07002351 if (response == NULL && responselen != 0) {
2352 RLOGE("invalid response: NULL");
2353 return RIL_ERRNO_INVALID_RESPONSE;
2354 }
2355
2356 if (responselen == sizeof(int)) {
Sungmin Choia408c252015-07-01 16:22:46 +09002357 startResponse;
2358 int *p_int = (int *) response;
2359 appendPrintBuf("%s%d,", printBuf, p_int[0]);
2360 p.writeInt32(p_int[0]);
2361 removeLastChar;
2362 closeResponse;
Chao Liu548a81e2015-05-14 16:13:46 -07002363 } else if (responselen == sizeof(RIL_LastCallFailCauseInfo)) {
2364 startResponse;
2365 RIL_LastCallFailCauseInfo *p_fail_cause_info = (RIL_LastCallFailCauseInfo *) response;
2366 appendPrintBuf("%s[cause_code=%d,vendor_cause=%s]", printBuf, p_fail_cause_info->cause_code,
2367 p_fail_cause_info->vendor_cause);
2368 p.writeInt32(p_fail_cause_info->cause_code);
2369 writeStringToParcel(p, p_fail_cause_info->vendor_cause);
2370 removeLastChar;
2371 closeResponse;
2372 } else {
2373 RLOGE("responseFailCause: invalid response length %d expected an int or "
2374 "RIL_LastCallFailCauseInfo", (int)responselen);
2375 return RIL_ERRNO_INVALID_RESPONSE;
2376 }
2377
2378 return 0;
2379}
2380
Wink Saville43808972011-01-13 17:39:51 -08002381/** response is a char **, pointing to an array of char *'s
2382 The parcel will begin with the version */
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002383static int responseStringsWithVersion(int version, Parcel &p, int slotId, int requestNumber,
2384 int responseType, int token, RIL_Errno e, void *response, size_t responselen) {
Wink Saville43808972011-01-13 17:39:51 -08002385 p.writeInt32(version);
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002386 return responseStrings(p, slotId, requestNumber, responseType, token, e, response, responselen);
Wink Saville43808972011-01-13 17:39:51 -08002387}
2388
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002389/** response is a char **, pointing to an array of char *'s */
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002390static int responseStrings(Parcel &p, int slotId, int requestNumber, int responseType, int token,
2391 RIL_Errno e, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002392 int numStrings;
Wink Saville7f856802009-06-09 10:23:37 -07002393
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002394 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002395 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002396 return RIL_ERRNO_INVALID_RESPONSE;
2397 }
2398 if (responselen % sizeof(char *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002399 RLOGE("responseStrings: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002400 (int)responselen, (int)sizeof(char *));
2401 return RIL_ERRNO_INVALID_RESPONSE;
2402 }
2403
2404 if (response == NULL) {
2405 p.writeInt32 (0);
2406 } else {
2407 char **p_cur = (char **) response;
2408
2409 numStrings = responselen / sizeof(char *);
2410 p.writeInt32 (numStrings);
2411
2412 /* each string*/
2413 startResponse;
2414 for (int i = 0 ; i < numStrings ; i++) {
2415 appendPrintBuf("%s%s,", printBuf, (char*)p_cur[i]);
2416 writeStringToParcel (p, p_cur[i]);
2417 }
2418 removeLastChar;
2419 closeResponse;
2420 }
2421 return 0;
2422}
2423
2424
2425/**
Wink Saville7f856802009-06-09 10:23:37 -07002426 * NULL strings are accepted
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002427 * FIXME currently ignores responselen
2428 */
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002429static int responseString(Parcel &p, int slotId, int requestNumber, int responseType, int token,
2430 RIL_Errno e, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002431 /* one string only */
2432 startResponse;
2433 appendPrintBuf("%s%s", printBuf, (char*)response);
2434 closeResponse;
2435
2436 writeStringToParcel(p, (const char *)response);
2437
2438 return 0;
2439}
2440
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002441static int responseVoid(Parcel &p, int slotId, int requestNumber, int responseType, int token,
2442 RIL_Errno e, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002443 startResponse;
2444 removeLastChar;
2445 return 0;
2446}
2447
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002448static int responseCallList(Parcel &p, int slotId, int requestNumber, int responseType, int token,
2449 RIL_Errno e, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002450 int num;
2451
2452 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002453 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002454 return RIL_ERRNO_INVALID_RESPONSE;
2455 }
2456
2457 if (responselen % sizeof (RIL_Call *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002458 RLOGE("responseCallList: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002459 (int)responselen, (int)sizeof (RIL_Call *));
2460 return RIL_ERRNO_INVALID_RESPONSE;
2461 }
2462
2463 startResponse;
2464 /* number of call info's */
2465 num = responselen / sizeof(RIL_Call *);
2466 p.writeInt32(num);
2467
2468 for (int i = 0 ; i < num ; i++) {
2469 RIL_Call *p_cur = ((RIL_Call **) response)[i];
2470 /* each call info */
2471 p.writeInt32(p_cur->state);
2472 p.writeInt32(p_cur->index);
2473 p.writeInt32(p_cur->toa);
2474 p.writeInt32(p_cur->isMpty);
2475 p.writeInt32(p_cur->isMT);
2476 p.writeInt32(p_cur->als);
2477 p.writeInt32(p_cur->isVoice);
Wink Saville1b5fd232009-04-22 14:50:00 -07002478 p.writeInt32(p_cur->isVoicePrivacy);
2479 writeStringToParcel(p, p_cur->number);
John Wangff368742009-03-24 17:56:29 -07002480 p.writeInt32(p_cur->numberPresentation);
Wink Saville1b5fd232009-04-22 14:50:00 -07002481 writeStringToParcel(p, p_cur->name);
2482 p.writeInt32(p_cur->namePresentation);
Wink Saville3a4840b2010-04-07 13:29:58 -07002483 // Remove when partners upgrade to version 3
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002484 if (s_callbacks.version < 3 || p_cur->uusInfo == NULL || p_cur->uusInfo->uusData == NULL) {
Wink Saville74fa3882009-12-22 15:35:41 -08002485 p.writeInt32(0); /* UUS Information is absent */
2486 } else {
2487 RIL_UUS_Info *uusInfo = p_cur->uusInfo;
2488 p.writeInt32(1); /* UUS Information is present */
2489 p.writeInt32(uusInfo->uusType);
2490 p.writeInt32(uusInfo->uusDcs);
2491 p.writeInt32(uusInfo->uusLength);
2492 p.write(uusInfo->uusData, uusInfo->uusLength);
2493 }
Wink Saville3d54e742009-05-18 18:00:44 -07002494 appendPrintBuf("%s[id=%d,%s,toa=%d,",
John Wangff368742009-03-24 17:56:29 -07002495 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002496 p_cur->index,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002497 callStateToString(p_cur->state),
Wink Saville3d54e742009-05-18 18:00:44 -07002498 p_cur->toa);
2499 appendPrintBuf("%s%s,%s,als=%d,%s,%s,",
2500 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002501 (p_cur->isMpty)?"conf":"norm",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002502 (p_cur->isMT)?"mt":"mo",
2503 p_cur->als,
2504 (p_cur->isVoice)?"voc":"nonvoc",
Wink Saville3d54e742009-05-18 18:00:44 -07002505 (p_cur->isVoicePrivacy)?"evp":"noevp");
2506 appendPrintBuf("%s%s,cli=%d,name='%s',%d]",
2507 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002508 p_cur->number,
2509 p_cur->numberPresentation,
2510 p_cur->name,
2511 p_cur->namePresentation);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002512 }
2513 removeLastChar;
2514 closeResponse;
2515
2516 return 0;
2517}
2518
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002519static int responseSMS(Parcel &p, int slotId, int requestNumber, int responseType, int token,
2520 RIL_Errno e, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002521 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002522 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002523 return RIL_ERRNO_INVALID_RESPONSE;
2524 }
2525
2526 if (responselen != sizeof (RIL_SMS_Response) ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002527 RLOGE("invalid response length %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002528 (int)responselen, (int)sizeof (RIL_SMS_Response));
2529 return RIL_ERRNO_INVALID_RESPONSE;
2530 }
2531
2532 RIL_SMS_Response *p_cur = (RIL_SMS_Response *) response;
2533
2534 p.writeInt32(p_cur->messageRef);
2535 writeStringToParcel(p, p_cur->ackPDU);
Jaikumar Ganesh920c78f2009-06-04 10:53:15 -07002536 p.writeInt32(p_cur->errorCode);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002537
2538 startResponse;
Jaikumar Ganesh920c78f2009-06-04 10:53:15 -07002539 appendPrintBuf("%s%d,%s,%d", printBuf, p_cur->messageRef,
2540 (char*)p_cur->ackPDU, p_cur->errorCode);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002541 closeResponse;
2542
2543 return 0;
2544}
2545
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002546static int responseDataCallListV4(Parcel &p, int slotId, int requestNumber, int responseType,
2547 int token, RIL_Errno e, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002548 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002549 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002550 return RIL_ERRNO_INVALID_RESPONSE;
2551 }
2552
Wink Savillec0114b32011-02-18 10:14:07 -08002553 if (responselen % sizeof(RIL_Data_Call_Response_v4) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002554 RLOGE("responseDataCallListV4: invalid response length %d expected multiple of %d",
Wink Savillec0114b32011-02-18 10:14:07 -08002555 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v4));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002556 return RIL_ERRNO_INVALID_RESPONSE;
2557 }
2558
Amit Mahajan52500162014-07-29 17:36:48 -07002559 // Write version
2560 p.writeInt32(4);
2561
Wink Savillec0114b32011-02-18 10:14:07 -08002562 int num = responselen / sizeof(RIL_Data_Call_Response_v4);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002563 p.writeInt32(num);
2564
Wink Savillec0114b32011-02-18 10:14:07 -08002565 RIL_Data_Call_Response_v4 *p_cur = (RIL_Data_Call_Response_v4 *) response;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002566 startResponse;
2567 int i;
2568 for (i = 0; i < num; i++) {
2569 p.writeInt32(p_cur[i].cid);
2570 p.writeInt32(p_cur[i].active);
2571 writeStringToParcel(p, p_cur[i].type);
Wink Savillec0114b32011-02-18 10:14:07 -08002572 // apn is not used, so don't send.
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002573 writeStringToParcel(p, p_cur[i].address);
Wink Savillec0114b32011-02-18 10:14:07 -08002574 appendPrintBuf("%s[cid=%d,%s,%s,%s],", printBuf,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002575 p_cur[i].cid,
2576 (p_cur[i].active==0)?"down":"up",
2577 (char*)p_cur[i].type,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002578 (char*)p_cur[i].address);
2579 }
2580 removeLastChar;
2581 closeResponse;
2582
2583 return 0;
2584}
2585
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002586static int responseDataCallListV6(Parcel &p, int slotId, int requestNumber, int responseType,
2587 int token, RIL_Errno e, void *response, size_t responselen) {
Amit Mahajan52500162014-07-29 17:36:48 -07002588 if (response == NULL && responselen != 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002589 RLOGE("invalid response: NULL");
2590 return RIL_ERRNO_INVALID_RESPONSE;
2591 }
2592
2593 if (responselen % sizeof(RIL_Data_Call_Response_v6) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002594 RLOGE("responseDataCallListV6: invalid response length %d expected multiple of %d",
Etan Cohend3652192014-06-20 08:28:44 -07002595 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v6));
2596 return RIL_ERRNO_INVALID_RESPONSE;
2597 }
2598
Amit Mahajan52500162014-07-29 17:36:48 -07002599 // Write version
2600 p.writeInt32(6);
2601
Etan Cohend3652192014-06-20 08:28:44 -07002602 int num = responselen / sizeof(RIL_Data_Call_Response_v6);
2603 p.writeInt32(num);
2604
2605 RIL_Data_Call_Response_v6 *p_cur = (RIL_Data_Call_Response_v6 *) response;
2606 startResponse;
2607 int i;
2608 for (i = 0; i < num; i++) {
2609 p.writeInt32((int)p_cur[i].status);
2610 p.writeInt32(p_cur[i].suggestedRetryTime);
2611 p.writeInt32(p_cur[i].cid);
2612 p.writeInt32(p_cur[i].active);
2613 writeStringToParcel(p, p_cur[i].type);
2614 writeStringToParcel(p, p_cur[i].ifname);
2615 writeStringToParcel(p, p_cur[i].addresses);
2616 writeStringToParcel(p, p_cur[i].dnses);
2617 writeStringToParcel(p, p_cur[i].gateways);
2618 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s],", printBuf,
2619 p_cur[i].status,
2620 p_cur[i].suggestedRetryTime,
2621 p_cur[i].cid,
2622 (p_cur[i].active==0)?"down":"up",
2623 (char*)p_cur[i].type,
2624 (char*)p_cur[i].ifname,
2625 (char*)p_cur[i].addresses,
2626 (char*)p_cur[i].dnses,
2627 (char*)p_cur[i].gateways);
2628 }
2629 removeLastChar;
2630 closeResponse;
2631
2632 return 0;
2633}
2634
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002635static int responseDataCallListV9(Parcel &p, int slotId, int requestNumber, int responseType,
2636 int token, RIL_Errno e, void *response, size_t responselen) {
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002637 if (response == NULL && responselen != 0) {
2638 RLOGE("invalid response: NULL");
2639 return RIL_ERRNO_INVALID_RESPONSE;
2640 }
2641
2642 if (responselen % sizeof(RIL_Data_Call_Response_v9) != 0) {
2643 RLOGE("responseDataCallListV9: invalid response length %d expected multiple of %d",
2644 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v9));
2645 return RIL_ERRNO_INVALID_RESPONSE;
2646 }
2647
2648 // Write version
2649 p.writeInt32(10);
2650
2651 int num = responselen / sizeof(RIL_Data_Call_Response_v9);
2652 p.writeInt32(num);
2653
2654 RIL_Data_Call_Response_v9 *p_cur = (RIL_Data_Call_Response_v9 *) response;
2655 startResponse;
2656 int i;
2657 for (i = 0; i < num; i++) {
2658 p.writeInt32((int)p_cur[i].status);
2659 p.writeInt32(p_cur[i].suggestedRetryTime);
2660 p.writeInt32(p_cur[i].cid);
2661 p.writeInt32(p_cur[i].active);
2662 writeStringToParcel(p, p_cur[i].type);
2663 writeStringToParcel(p, p_cur[i].ifname);
2664 writeStringToParcel(p, p_cur[i].addresses);
2665 writeStringToParcel(p, p_cur[i].dnses);
2666 writeStringToParcel(p, p_cur[i].gateways);
2667 writeStringToParcel(p, p_cur[i].pcscf);
2668 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s],", printBuf,
2669 p_cur[i].status,
2670 p_cur[i].suggestedRetryTime,
2671 p_cur[i].cid,
2672 (p_cur[i].active==0)?"down":"up",
2673 (char*)p_cur[i].type,
2674 (char*)p_cur[i].ifname,
2675 (char*)p_cur[i].addresses,
2676 (char*)p_cur[i].dnses,
2677 (char*)p_cur[i].gateways,
2678 (char*)p_cur[i].pcscf);
2679 }
2680 removeLastChar;
2681 closeResponse;
2682
2683 return 0;
2684}
2685
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002686static int responseDataCallListV11(Parcel &p, int slotId, int requestNumber, int responseType,
2687 int token, RIL_Errno e, void *response, size_t responselen) {
Sanket Padawe4c05f352016-01-26 16:19:00 -08002688 if (response == NULL && responselen != 0) {
2689 RLOGE("invalid response: NULL");
2690 return RIL_ERRNO_INVALID_RESPONSE;
2691 }
2692
2693 if (responselen % sizeof(RIL_Data_Call_Response_v11) != 0) {
2694 RLOGE("invalid response length %d expected multiple of %d",
2695 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v11));
2696 return RIL_ERRNO_INVALID_RESPONSE;
2697 }
2698
2699 // Write version
2700 p.writeInt32(11);
2701
2702 int num = responselen / sizeof(RIL_Data_Call_Response_v11);
2703 p.writeInt32(num);
2704
2705 RIL_Data_Call_Response_v11 *p_cur = (RIL_Data_Call_Response_v11 *) response;
2706 startResponse;
2707 int i;
2708 for (i = 0; i < num; i++) {
2709 p.writeInt32((int)p_cur[i].status);
2710 p.writeInt32(p_cur[i].suggestedRetryTime);
2711 p.writeInt32(p_cur[i].cid);
2712 p.writeInt32(p_cur[i].active);
2713 writeStringToParcel(p, p_cur[i].type);
2714 writeStringToParcel(p, p_cur[i].ifname);
2715 writeStringToParcel(p, p_cur[i].addresses);
2716 writeStringToParcel(p, p_cur[i].dnses);
2717 writeStringToParcel(p, p_cur[i].gateways);
2718 writeStringToParcel(p, p_cur[i].pcscf);
2719 p.writeInt32(p_cur[i].mtu);
2720 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s,mtu=%d],", printBuf,
2721 p_cur[i].status,
2722 p_cur[i].suggestedRetryTime,
2723 p_cur[i].cid,
2724 (p_cur[i].active==0)?"down":"up",
2725 (char*)p_cur[i].type,
2726 (char*)p_cur[i].ifname,
2727 (char*)p_cur[i].addresses,
2728 (char*)p_cur[i].dnses,
2729 (char*)p_cur[i].gateways,
2730 (char*)p_cur[i].pcscf,
2731 p_cur[i].mtu);
2732 }
2733 removeLastChar;
2734 closeResponse;
2735
2736 return 0;
2737}
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002738
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002739static int responseDataCallList(Parcel &p, int slotId, int requestNumber, int responseType,
2740 int token, RIL_Errno e, void *response, size_t responselen) {
Sanket Padawe4c05f352016-01-26 16:19:00 -08002741 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
2742 if (s_callbacks.version < 5) {
2743 RLOGD("responseDataCallList: v4");
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002744 return responseDataCallListV4(p, slotId, requestNumber, responseType, token, e,
2745 response, responselen);
Sanket Padawe4c05f352016-01-26 16:19:00 -08002746 } else if (responselen % sizeof(RIL_Data_Call_Response_v6) == 0) {
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002747 return responseDataCallListV6(p, slotId, requestNumber, responseType, token, e,
2748 response, responselen);
Sanket Padawe4c05f352016-01-26 16:19:00 -08002749 } else if (responselen % sizeof(RIL_Data_Call_Response_v9) == 0) {
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002750 return responseDataCallListV9(p, slotId, requestNumber, responseType, token, e,
2751 response, responselen);
Sanket Padawe4c05f352016-01-26 16:19:00 -08002752 } else {
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002753 return responseDataCallListV11(p, slotId, requestNumber, responseType, token, e,
2754 response, responselen);
Wink Saville43808972011-01-13 17:39:51 -08002755 }
Sanket Padawe00909612016-01-26 18:44:01 -08002756 } else { // RIL version >= 13
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002757 if (responselen % sizeof(RIL_Data_Call_Response_v11) != 0) {
Sanket Padawe4c05f352016-01-26 16:19:00 -08002758 RLOGE("Data structure expected is RIL_Data_Call_Response_v11");
2759 if (!isDebuggable()) {
2760 return RIL_ERRNO_INVALID_RESPONSE;
2761 } else {
2762 assert(0);
2763 }
Wink Saville43808972011-01-13 17:39:51 -08002764 }
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002765 return responseDataCallListV11(p, slotId, requestNumber, responseType, token, e, response,
2766 responselen);
Wink Saville43808972011-01-13 17:39:51 -08002767 }
Wink Saville43808972011-01-13 17:39:51 -08002768}
2769
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002770static int responseSetupDataCall(Parcel &p, int slotId, int requestNumber, int responseType,
2771 int token, RIL_Errno e, void *response, size_t responselen) {
Wink Saville43808972011-01-13 17:39:51 -08002772 if (s_callbacks.version < 5) {
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002773 return responseStringsWithVersion(s_callbacks.version, p, slotId, requestNumber,
2774 responseType, token, e, response, responselen);
Wink Saville43808972011-01-13 17:39:51 -08002775 } else {
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002776 return responseDataCallList(p, slotId, requestNumber, responseType, token, e, response,
2777 responselen);
Wink Saville43808972011-01-13 17:39:51 -08002778 }
2779}
2780
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002781static int responseRaw(Parcel &p, int slotId, int requestNumber, int responseType, int token,
2782 RIL_Errno e, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002783 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002784 RLOGE("invalid response: NULL with responselen != 0");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002785 return RIL_ERRNO_INVALID_RESPONSE;
2786 }
2787
2788 // The java code reads -1 size as null byte array
2789 if (response == NULL) {
Wink Saville7f856802009-06-09 10:23:37 -07002790 p.writeInt32(-1);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002791 } else {
2792 p.writeInt32(responselen);
2793 p.write(response, responselen);
2794 }
2795
2796 return 0;
2797}
2798
2799
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002800static int responseSIM_IO(Parcel &p, int slotId, int requestNumber, int responseType, int token,
2801 RIL_Errno e, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002802 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002803 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002804 return RIL_ERRNO_INVALID_RESPONSE;
2805 }
2806
2807 if (responselen != sizeof (RIL_SIM_IO_Response) ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002808 RLOGE("invalid response length was %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002809 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
2810 return RIL_ERRNO_INVALID_RESPONSE;
2811 }
2812
2813 RIL_SIM_IO_Response *p_cur = (RIL_SIM_IO_Response *) response;
2814 p.writeInt32(p_cur->sw1);
2815 p.writeInt32(p_cur->sw2);
2816 writeStringToParcel(p, p_cur->simResponse);
2817
2818 startResponse;
2819 appendPrintBuf("%ssw1=0x%X,sw2=0x%X,%s", printBuf, p_cur->sw1, p_cur->sw2,
2820 (char*)p_cur->simResponse);
2821 closeResponse;
2822
2823
2824 return 0;
2825}
2826
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002827static int responseCallForwards(Parcel &p, int slotId, int requestNumber, int responseType,
2828 int token, RIL_Errno e, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002829 int num;
Wink Saville7f856802009-06-09 10:23:37 -07002830
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002831 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002832 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002833 return RIL_ERRNO_INVALID_RESPONSE;
2834 }
2835
2836 if (responselen % sizeof(RIL_CallForwardInfo *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002837 RLOGE("responseCallForwards: invalid response length %d expected multiple of %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002838 (int)responselen, (int)sizeof(RIL_CallForwardInfo *));
2839 return RIL_ERRNO_INVALID_RESPONSE;
2840 }
2841
2842 /* number of call info's */
2843 num = responselen / sizeof(RIL_CallForwardInfo *);
2844 p.writeInt32(num);
2845
2846 startResponse;
2847 for (int i = 0 ; i < num ; i++) {
2848 RIL_CallForwardInfo *p_cur = ((RIL_CallForwardInfo **) response)[i];
2849
2850 p.writeInt32(p_cur->status);
2851 p.writeInt32(p_cur->reason);
2852 p.writeInt32(p_cur->serviceClass);
2853 p.writeInt32(p_cur->toa);
2854 writeStringToParcel(p, p_cur->number);
2855 p.writeInt32(p_cur->timeSeconds);
2856 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
2857 (p_cur->status==1)?"enable":"disable",
2858 p_cur->reason, p_cur->serviceClass, p_cur->toa,
2859 (char*)p_cur->number,
2860 p_cur->timeSeconds);
2861 }
2862 removeLastChar;
2863 closeResponse;
Wink Saville7f856802009-06-09 10:23:37 -07002864
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002865 return 0;
2866}
2867
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002868static int responseSsn(Parcel &p, int slotId, int requestNumber, int responseType, int token,
2869 RIL_Errno e, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002870 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002871 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002872 return RIL_ERRNO_INVALID_RESPONSE;
2873 }
2874
2875 if (responselen != sizeof(RIL_SuppSvcNotification)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002876 RLOGE("invalid response length was %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002877 (int)responselen, (int)sizeof (RIL_SuppSvcNotification));
2878 return RIL_ERRNO_INVALID_RESPONSE;
2879 }
2880
2881 RIL_SuppSvcNotification *p_cur = (RIL_SuppSvcNotification *) response;
2882 p.writeInt32(p_cur->notificationType);
2883 p.writeInt32(p_cur->code);
2884 p.writeInt32(p_cur->index);
2885 p.writeInt32(p_cur->type);
2886 writeStringToParcel(p, p_cur->number);
2887
2888 startResponse;
2889 appendPrintBuf("%s%s,code=%d,id=%d,type=%d,%s", printBuf,
2890 (p_cur->notificationType==0)?"mo":"mt",
2891 p_cur->code, p_cur->index, p_cur->type,
2892 (char*)p_cur->number);
2893 closeResponse;
2894
2895 return 0;
2896}
2897
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002898static int responseCellList(Parcel &p, int slotId, int requestNumber, int responseType, int token,
2899 RIL_Errno e, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002900 int num;
2901
2902 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002903 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002904 return RIL_ERRNO_INVALID_RESPONSE;
2905 }
2906
2907 if (responselen % sizeof (RIL_NeighboringCell *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002908 RLOGE("responseCellList: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002909 (int)responselen, (int)sizeof (RIL_NeighboringCell *));
2910 return RIL_ERRNO_INVALID_RESPONSE;
2911 }
2912
2913 startResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002914 /* number of records */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002915 num = responselen / sizeof(RIL_NeighboringCell *);
2916 p.writeInt32(num);
2917
2918 for (int i = 0 ; i < num ; i++) {
2919 RIL_NeighboringCell *p_cur = ((RIL_NeighboringCell **) response)[i];
2920
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002921 p.writeInt32(p_cur->rssi);
2922 writeStringToParcel (p, p_cur->cid);
2923
2924 appendPrintBuf("%s[cid=%s,rssi=%d],", printBuf,
2925 p_cur->cid, p_cur->rssi);
2926 }
2927 removeLastChar;
2928 closeResponse;
2929
2930 return 0;
2931}
2932
Wink Saville3d54e742009-05-18 18:00:44 -07002933/**
2934 * Marshall the signalInfoRecord into the parcel if it exists.
2935 */
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002936static void marshallSignalInfoRecord(Parcel &p, RIL_CDMA_SignalInfoRecord &p_signalInfoRecord) {
Wink Saville3d54e742009-05-18 18:00:44 -07002937 p.writeInt32(p_signalInfoRecord.isPresent);
2938 p.writeInt32(p_signalInfoRecord.signalType);
2939 p.writeInt32(p_signalInfoRecord.alertPitch);
2940 p.writeInt32(p_signalInfoRecord.signal);
2941}
2942
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002943static int responseCdmaInformationRecords(Parcel &p, int slotId, int requestNumber,
2944 int responseType, int token, RIL_Errno e, void *response, size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07002945 int num;
Wink Savillea592eeb2009-05-22 13:26:36 -07002946 char* string8 = NULL;
2947 int buffer_lenght;
2948 RIL_CDMA_InformationRecord *infoRec;
Wink Saville3d54e742009-05-18 18:00:44 -07002949
2950 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002951 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002952 return RIL_ERRNO_INVALID_RESPONSE;
2953 }
2954
Wink Savillea592eeb2009-05-22 13:26:36 -07002955 if (responselen != sizeof (RIL_CDMA_InformationRecords)) {
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002956 RLOGE("responseCdmaInformationRecords: invalid response length %d expected multiple of \
2957 %d\n", (int)responselen, (int)sizeof (RIL_CDMA_InformationRecords *));
Wink Saville3d54e742009-05-18 18:00:44 -07002958 return RIL_ERRNO_INVALID_RESPONSE;
2959 }
2960
Wink Savillea592eeb2009-05-22 13:26:36 -07002961 RIL_CDMA_InformationRecords *p_cur =
2962 (RIL_CDMA_InformationRecords *) response;
2963 num = MIN(p_cur->numberOfInfoRecs, RIL_CDMA_MAX_NUMBER_OF_INFO_RECS);
Wink Saville3d54e742009-05-18 18:00:44 -07002964
2965 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07002966 p.writeInt32(num);
Wink Saville3d54e742009-05-18 18:00:44 -07002967
Wink Savillea592eeb2009-05-22 13:26:36 -07002968 for (int i = 0 ; i < num ; i++) {
2969 infoRec = &p_cur->infoRec[i];
2970 p.writeInt32(infoRec->name);
2971 switch (infoRec->name) {
Wink Saville3d54e742009-05-18 18:00:44 -07002972 case RIL_CDMA_DISPLAY_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002973 case RIL_CDMA_EXTENDED_DISPLAY_INFO_REC:
2974 if (infoRec->rec.display.alpha_len >
2975 CDMA_ALPHA_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002976 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002977 expected not more than %d\n",
2978 (int)infoRec->rec.display.alpha_len,
2979 CDMA_ALPHA_INFO_BUFFER_LENGTH);
2980 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002981 }
Sanket Padawe0cfc5532016-03-07 17:12:19 -08002982 string8 = (char*) calloc(infoRec->rec.display.alpha_len + 1, sizeof(char));
Sanket Padawe55227b52016-02-29 10:09:26 -08002983 if (string8 == NULL) {
2984 RLOGE("Memory allocation failed for responseCdmaInformationRecords");
2985 closeRequest;
2986 return RIL_ERRNO_NO_MEMORY;
2987 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002988 for (int i = 0 ; i < infoRec->rec.display.alpha_len ; i++) {
2989 string8[i] = infoRec->rec.display.alpha_buf[i];
2990 }
Wink Saville43808972011-01-13 17:39:51 -08002991 string8[(int)infoRec->rec.display.alpha_len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002992 writeStringToParcel(p, (const char*)string8);
2993 free(string8);
2994 string8 = NULL;
Wink Saville3d54e742009-05-18 18:00:44 -07002995 break;
2996 case RIL_CDMA_CALLED_PARTY_NUMBER_INFO_REC:
Wink Saville3d54e742009-05-18 18:00:44 -07002997 case RIL_CDMA_CALLING_PARTY_NUMBER_INFO_REC:
Wink Saville3d54e742009-05-18 18:00:44 -07002998 case RIL_CDMA_CONNECTED_NUMBER_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002999 if (infoRec->rec.number.len > CDMA_NUMBER_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003000 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07003001 expected not more than %d\n",
3002 (int)infoRec->rec.number.len,
3003 CDMA_NUMBER_INFO_BUFFER_LENGTH);
3004 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07003005 }
Sanket Padawe0cfc5532016-03-07 17:12:19 -08003006 string8 = (char*) calloc(infoRec->rec.number.len + 1, sizeof(char));
Sanket Padawe55227b52016-02-29 10:09:26 -08003007 if (string8 == NULL) {
3008 RLOGE("Memory allocation failed for responseCdmaInformationRecords");
3009 closeRequest;
3010 return RIL_ERRNO_NO_MEMORY;
3011 }
Wink Savillea592eeb2009-05-22 13:26:36 -07003012 for (int i = 0 ; i < infoRec->rec.number.len; i++) {
3013 string8[i] = infoRec->rec.number.buf[i];
3014 }
Wink Saville43808972011-01-13 17:39:51 -08003015 string8[(int)infoRec->rec.number.len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07003016 writeStringToParcel(p, (const char*)string8);
3017 free(string8);
3018 string8 = NULL;
3019 p.writeInt32(infoRec->rec.number.number_type);
3020 p.writeInt32(infoRec->rec.number.number_plan);
3021 p.writeInt32(infoRec->rec.number.pi);
3022 p.writeInt32(infoRec->rec.number.si);
Wink Saville3d54e742009-05-18 18:00:44 -07003023 break;
3024 case RIL_CDMA_SIGNAL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07003025 p.writeInt32(infoRec->rec.signal.isPresent);
3026 p.writeInt32(infoRec->rec.signal.signalType);
3027 p.writeInt32(infoRec->rec.signal.alertPitch);
3028 p.writeInt32(infoRec->rec.signal.signal);
3029
3030 appendPrintBuf("%sisPresent=%X, signalType=%X, \
3031 alertPitch=%X, signal=%X, ",
3032 printBuf, (int)infoRec->rec.signal.isPresent,
3033 (int)infoRec->rec.signal.signalType,
3034 (int)infoRec->rec.signal.alertPitch,
3035 (int)infoRec->rec.signal.signal);
3036 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07003037 break;
3038 case RIL_CDMA_REDIRECTING_NUMBER_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07003039 if (infoRec->rec.redir.redirectingNumber.len >
3040 CDMA_NUMBER_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003041 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07003042 expected not more than %d\n",
3043 (int)infoRec->rec.redir.redirectingNumber.len,
3044 CDMA_NUMBER_INFO_BUFFER_LENGTH);
3045 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07003046 }
Sanket Padawe0cfc5532016-03-07 17:12:19 -08003047 string8 = (char*) calloc(infoRec->rec.redir.redirectingNumber.len + 1,
3048 sizeof(char));
Sanket Padawe55227b52016-02-29 10:09:26 -08003049 if (string8 == NULL) {
3050 RLOGE("Memory allocation failed for responseCdmaInformationRecords");
3051 closeRequest;
3052 return RIL_ERRNO_NO_MEMORY;
3053 }
Wink Savillea592eeb2009-05-22 13:26:36 -07003054 for (int i = 0;
3055 i < infoRec->rec.redir.redirectingNumber.len;
3056 i++) {
3057 string8[i] = infoRec->rec.redir.redirectingNumber.buf[i];
3058 }
Wink Saville43808972011-01-13 17:39:51 -08003059 string8[(int)infoRec->rec.redir.redirectingNumber.len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07003060 writeStringToParcel(p, (const char*)string8);
3061 free(string8);
3062 string8 = NULL;
3063 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_type);
3064 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_plan);
3065 p.writeInt32(infoRec->rec.redir.redirectingNumber.pi);
3066 p.writeInt32(infoRec->rec.redir.redirectingNumber.si);
3067 p.writeInt32(infoRec->rec.redir.redirectingReason);
Wink Saville3d54e742009-05-18 18:00:44 -07003068 break;
3069 case RIL_CDMA_LINE_CONTROL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07003070 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPolarityIncluded);
3071 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlToggle);
3072 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlReverse);
3073 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPowerDenial);
3074
3075 appendPrintBuf("%slineCtrlPolarityIncluded=%d, \
3076 lineCtrlToggle=%d, lineCtrlReverse=%d, \
3077 lineCtrlPowerDenial=%d, ", printBuf,
3078 (int)infoRec->rec.lineCtrl.lineCtrlPolarityIncluded,
3079 (int)infoRec->rec.lineCtrl.lineCtrlToggle,
3080 (int)infoRec->rec.lineCtrl.lineCtrlReverse,
3081 (int)infoRec->rec.lineCtrl.lineCtrlPowerDenial);
3082 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07003083 break;
3084 case RIL_CDMA_T53_CLIR_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07003085 p.writeInt32((int)(infoRec->rec.clir.cause));
Wink Saville3d54e742009-05-18 18:00:44 -07003086
Wink Savillea592eeb2009-05-22 13:26:36 -07003087 appendPrintBuf("%scause%d", printBuf, infoRec->rec.clir.cause);
3088 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07003089 break;
3090 case RIL_CDMA_T53_AUDIO_CONTROL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07003091 p.writeInt32(infoRec->rec.audioCtrl.upLink);
3092 p.writeInt32(infoRec->rec.audioCtrl.downLink);
3093
3094 appendPrintBuf("%supLink=%d, downLink=%d, ", printBuf,
3095 infoRec->rec.audioCtrl.upLink,
3096 infoRec->rec.audioCtrl.downLink);
3097 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07003098 break;
Wink Savillea592eeb2009-05-22 13:26:36 -07003099 case RIL_CDMA_T53_RELEASE_INFO_REC:
3100 // TODO(Moto): See David Krause, he has the answer:)
Wink Saville8eb2a122012-11-19 16:05:13 -08003101 RLOGE("RIL_CDMA_T53_RELEASE_INFO_REC: return INVALID_RESPONSE");
Wink Savillea592eeb2009-05-22 13:26:36 -07003102 return RIL_ERRNO_INVALID_RESPONSE;
3103 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08003104 RLOGE("Incorrect name value");
Wink Savillea592eeb2009-05-22 13:26:36 -07003105 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07003106 }
3107 }
Wink Savillea592eeb2009-05-22 13:26:36 -07003108 closeResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07003109
Wink Savillea592eeb2009-05-22 13:26:36 -07003110 return 0;
Wink Saville3d54e742009-05-18 18:00:44 -07003111}
3112
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003113static void responseRilSignalStrengthV5(Parcel &p, int slotId, int requestNumber, int responseType,
3114 int token, RIL_Errno e, RIL_SignalStrength_v10 *p_cur) {
Sanket Padawe4c05f352016-01-26 16:19:00 -08003115 p.writeInt32(p_cur->GW_SignalStrength.signalStrength);
3116 p.writeInt32(p_cur->GW_SignalStrength.bitErrorRate);
3117 p.writeInt32(p_cur->CDMA_SignalStrength.dbm);
3118 p.writeInt32(p_cur->CDMA_SignalStrength.ecio);
3119 p.writeInt32(p_cur->EVDO_SignalStrength.dbm);
3120 p.writeInt32(p_cur->EVDO_SignalStrength.ecio);
3121 p.writeInt32(p_cur->EVDO_SignalStrength.signalNoiseRatio);
3122}
3123
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003124static void responseRilSignalStrengthV6Extra(Parcel &p, int slotId, int requestNumber,
3125 int responseType, int token, RIL_Errno e, RIL_SignalStrength_v10 *p_cur) {
Sanket Padawe4c05f352016-01-26 16:19:00 -08003126 /*
3127 * Fixup LTE for backwards compatibility
3128 */
3129 // signalStrength: -1 -> 99
3130 if (p_cur->LTE_SignalStrength.signalStrength == -1) {
3131 p_cur->LTE_SignalStrength.signalStrength = 99;
3132 }
3133 // rsrp: -1 -> INT_MAX all other negative value to positive.
3134 // So remap here
3135 if (p_cur->LTE_SignalStrength.rsrp == -1) {
3136 p_cur->LTE_SignalStrength.rsrp = INT_MAX;
3137 } else if (p_cur->LTE_SignalStrength.rsrp < -1) {
3138 p_cur->LTE_SignalStrength.rsrp = -p_cur->LTE_SignalStrength.rsrp;
3139 }
3140 // rsrq: -1 -> INT_MAX
3141 if (p_cur->LTE_SignalStrength.rsrq == -1) {
3142 p_cur->LTE_SignalStrength.rsrq = INT_MAX;
3143 }
3144 // Not remapping rssnr is already using INT_MAX
3145
3146 // cqi: -1 -> INT_MAX
3147 if (p_cur->LTE_SignalStrength.cqi == -1) {
3148 p_cur->LTE_SignalStrength.cqi = INT_MAX;
3149 }
3150
3151 p.writeInt32(p_cur->LTE_SignalStrength.signalStrength);
3152 p.writeInt32(p_cur->LTE_SignalStrength.rsrp);
3153 p.writeInt32(p_cur->LTE_SignalStrength.rsrq);
3154 p.writeInt32(p_cur->LTE_SignalStrength.rssnr);
3155 p.writeInt32(p_cur->LTE_SignalStrength.cqi);
3156}
3157
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003158static void responseRilSignalStrengthV10(Parcel &p, int slotId, int requestNumber, int responseType,
3159 int token, RIL_Errno e, RIL_SignalStrength_v10 *p_cur) {
3160 responseRilSignalStrengthV5(p, slotId, requestNumber, responseType, token, e, p_cur);
3161 responseRilSignalStrengthV6Extra(p, slotId, requestNumber, responseType, token, e, p_cur);
Sanket Padawe4c05f352016-01-26 16:19:00 -08003162 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
3163}
3164
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003165static int responseRilSignalStrength(Parcel &p, int slotId, int requestNumber, int responseType,
3166 int token, RIL_Errno e, void *response, size_t responselen) {
Wink Savillea592eeb2009-05-22 13:26:36 -07003167 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003168 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07003169 return RIL_ERRNO_INVALID_RESPONSE;
3170 }
3171
Sanket Padawe626099e2016-06-08 14:09:26 -07003172 RIL_SignalStrength_v10 *p_cur;
Sanket Padawe4c05f352016-01-26 16:19:00 -08003173 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
3174 if (responselen >= sizeof (RIL_SignalStrength_v5)) {
Sanket Padawe626099e2016-06-08 14:09:26 -07003175 p_cur = ((RIL_SignalStrength_v10 *) response);
Wink Saville3d54e742009-05-18 18:00:44 -07003176
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003177 responseRilSignalStrengthV5(p, slotId, requestNumber, responseType, token, e, p_cur);
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07003178
Sanket Padawe4c05f352016-01-26 16:19:00 -08003179 if (responselen >= sizeof (RIL_SignalStrength_v6)) {
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003180 responseRilSignalStrengthV6Extra(p, slotId, requestNumber, responseType, token, e,
3181 p_cur);
Sanket Padawe4c05f352016-01-26 16:19:00 -08003182 if (responselen >= sizeof (RIL_SignalStrength_v10)) {
3183 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
3184 } else {
3185 p.writeInt32(INT_MAX);
Wink Saville18e4ab12013-04-07 17:31:04 -07003186 }
Etan Cohend3652192014-06-20 08:28:44 -07003187 } else {
Sanket Padawe4c05f352016-01-26 16:19:00 -08003188 p.writeInt32(99);
3189 p.writeInt32(INT_MAX);
3190 p.writeInt32(INT_MAX);
3191 p.writeInt32(INT_MAX);
3192 p.writeInt32(INT_MAX);
Etan Cohend3652192014-06-20 08:28:44 -07003193 p.writeInt32(INT_MAX);
3194 }
Wink Savillec0114b32011-02-18 10:14:07 -08003195 } else {
Sanket Padawe4c05f352016-01-26 16:19:00 -08003196 RLOGE("invalid response length");
3197 return RIL_ERRNO_INVALID_RESPONSE;
Wink Savillec0114b32011-02-18 10:14:07 -08003198 }
Sanket Padawe00909612016-01-26 18:44:01 -08003199 } else { // RIL version >= 13
Sanket Padawe4c05f352016-01-26 16:19:00 -08003200 if (responselen % sizeof(RIL_SignalStrength_v10) != 0) {
3201 RLOGE("Data structure expected is RIL_SignalStrength_v10");
3202 if (!isDebuggable()) {
3203 return RIL_ERRNO_INVALID_RESPONSE;
3204 } else {
3205 assert(0);
3206 }
3207 }
Sanket Padawe626099e2016-06-08 14:09:26 -07003208 p_cur = ((RIL_SignalStrength_v10 *) response);
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003209 responseRilSignalStrengthV10(p, slotId, requestNumber, responseType, token, e, p_cur);
Wink Saville3d54e742009-05-18 18:00:44 -07003210 }
Sanket Padawe4c05f352016-01-26 16:19:00 -08003211 startResponse;
3212 appendPrintBuf("%s[signalStrength=%d,bitErrorRate=%d,\
3213 CDMA_SS.dbm=%d,CDMA_SSecio=%d,\
3214 EVDO_SS.dbm=%d,EVDO_SS.ecio=%d,\
3215 EVDO_SS.signalNoiseRatio=%d,\
3216 LTE_SS.signalStrength=%d,LTE_SS.rsrp=%d,LTE_SS.rsrq=%d,\
3217 LTE_SS.rssnr=%d,LTE_SS.cqi=%d,TDSCDMA_SS.rscp=%d]",
3218 printBuf,
3219 p_cur->GW_SignalStrength.signalStrength,
3220 p_cur->GW_SignalStrength.bitErrorRate,
3221 p_cur->CDMA_SignalStrength.dbm,
3222 p_cur->CDMA_SignalStrength.ecio,
3223 p_cur->EVDO_SignalStrength.dbm,
3224 p_cur->EVDO_SignalStrength.ecio,
3225 p_cur->EVDO_SignalStrength.signalNoiseRatio,
3226 p_cur->LTE_SignalStrength.signalStrength,
3227 p_cur->LTE_SignalStrength.rsrp,
3228 p_cur->LTE_SignalStrength.rsrq,
3229 p_cur->LTE_SignalStrength.rssnr,
3230 p_cur->LTE_SignalStrength.cqi,
3231 p_cur->TD_SCDMA_SignalStrength.rscp);
3232 closeResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07003233 return 0;
3234}
3235
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003236static int responseCallRing(Parcel &p, int slotId, int requestNumber, int responseType, int token,
3237 RIL_Errno e, void *response, size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07003238 if ((response == NULL) || (responselen == 0)) {
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003239 return responseVoid(p, slotId, requestNumber, responseType, token, e, response,
3240 responselen);
Wink Saville3d54e742009-05-18 18:00:44 -07003241 } else {
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003242 return responseCdmaSignalInfoRecord(p, slotId, requestNumber, responseType, token, e,
3243 response, responselen);
Wink Saville3d54e742009-05-18 18:00:44 -07003244 }
3245}
3246
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003247static int responseCdmaSignalInfoRecord(Parcel &p, int slotId, int requestNumber, int responseType,
3248 int token, RIL_Errno e, void *response, size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07003249 if (response == NULL || responselen == 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003250 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07003251 return RIL_ERRNO_INVALID_RESPONSE;
3252 }
3253
3254 if (responselen != sizeof (RIL_CDMA_SignalInfoRecord)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003255 RLOGE("invalid response length %d expected sizeof (RIL_CDMA_SignalInfoRecord) of %d\n",
Wink Saville3d54e742009-05-18 18:00:44 -07003256 (int)responselen, (int)sizeof (RIL_CDMA_SignalInfoRecord));
3257 return RIL_ERRNO_INVALID_RESPONSE;
3258 }
3259
3260 startResponse;
3261
3262 RIL_CDMA_SignalInfoRecord *p_cur = ((RIL_CDMA_SignalInfoRecord *) response);
3263 marshallSignalInfoRecord(p, *p_cur);
3264
3265 appendPrintBuf("%s[isPresent=%d,signalType=%d,alertPitch=%d\
3266 signal=%d]",
3267 printBuf,
3268 p_cur->isPresent,
3269 p_cur->signalType,
3270 p_cur->alertPitch,
3271 p_cur->signal);
3272
3273 closeResponse;
3274 return 0;
3275}
3276
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003277static int responseCdmaCallWaiting(Parcel &p, int slotId, int requestNumber, int responseType,
3278 int token, RIL_Errno e, void *response, size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07003279 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003280 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07003281 return RIL_ERRNO_INVALID_RESPONSE;
3282 }
3283
Wink Savillec0114b32011-02-18 10:14:07 -08003284 if (responselen < sizeof(RIL_CDMA_CallWaiting_v6)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003285 RLOGW("Upgrade to ril version %d\n", RIL_VERSION);
Wink Savillec0114b32011-02-18 10:14:07 -08003286 }
3287
3288 RIL_CDMA_CallWaiting_v6 *p_cur = ((RIL_CDMA_CallWaiting_v6 *) response);
3289
3290 writeStringToParcel(p, p_cur->number);
3291 p.writeInt32(p_cur->numberPresentation);
3292 writeStringToParcel(p, p_cur->name);
3293 marshallSignalInfoRecord(p, p_cur->signalInfoRecord);
3294
Sanket Padawe4c05f352016-01-26 16:19:00 -08003295 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
3296 if (responselen >= sizeof(RIL_CDMA_CallWaiting_v6)) {
3297 p.writeInt32(p_cur->number_type);
3298 p.writeInt32(p_cur->number_plan);
3299 } else {
3300 p.writeInt32(0);
3301 p.writeInt32(0);
3302 }
Sanket Padawe00909612016-01-26 18:44:01 -08003303 } else { // RIL version >= 13
Sanket Padawe4c05f352016-01-26 16:19:00 -08003304 if (responselen % sizeof(RIL_CDMA_CallWaiting_v6) != 0) {
3305 RLOGE("Data structure expected is RIL_CDMA_CallWaiting_v6");
3306 if (!isDebuggable()) {
3307 return RIL_ERRNO_INVALID_RESPONSE;
3308 } else {
3309 assert(0);
3310 }
3311 }
Wink Savillec0114b32011-02-18 10:14:07 -08003312 p.writeInt32(p_cur->number_type);
3313 p.writeInt32(p_cur->number_plan);
Wink Saville3d54e742009-05-18 18:00:44 -07003314 }
3315
3316 startResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07003317 appendPrintBuf("%snumber=%s,numberPresentation=%d, name=%s,\
3318 signalInfoRecord[isPresent=%d,signalType=%d,alertPitch=%d\
Wink Savillec0114b32011-02-18 10:14:07 -08003319 signal=%d,number_type=%d,number_plan=%d]",
Wink Saville3d54e742009-05-18 18:00:44 -07003320 printBuf,
3321 p_cur->number,
3322 p_cur->numberPresentation,
3323 p_cur->name,
3324 p_cur->signalInfoRecord.isPresent,
3325 p_cur->signalInfoRecord.signalType,
3326 p_cur->signalInfoRecord.alertPitch,
Wink Savillec0114b32011-02-18 10:14:07 -08003327 p_cur->signalInfoRecord.signal,
3328 p_cur->number_type,
3329 p_cur->number_plan);
Wink Saville3d54e742009-05-18 18:00:44 -07003330 closeResponse;
3331
3332 return 0;
3333}
3334
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003335static void responseSimRefreshV7(Parcel &p, int slotId, int requestNumber, int responseType,
3336 int token, RIL_Errno e, void *response) {
Sanket Padawe4c05f352016-01-26 16:19:00 -08003337 RIL_SimRefreshResponse_v7 *p_cur = ((RIL_SimRefreshResponse_v7 *) response);
3338 p.writeInt32(p_cur->result);
3339 p.writeInt32(p_cur->ef_id);
3340 writeStringToParcel(p, p_cur->aid);
3341
3342 appendPrintBuf("%sresult=%d, ef_id=%d, aid=%s",
3343 printBuf,
3344 p_cur->result,
3345 p_cur->ef_id,
3346 p_cur->aid);
3347
3348}
3349
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003350static int responseSimRefresh(Parcel &p, int slotId, int requestNumber, int responseType, int token,
3351 RIL_Errno e, void *response, size_t responselen) {
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003352 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003353 RLOGE("responseSimRefresh: invalid response: NULL");
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003354 return RIL_ERRNO_INVALID_RESPONSE;
3355 }
3356
3357 startResponse;
Sanket Padawe4c05f352016-01-26 16:19:00 -08003358 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
Sanket Padawe66701c52016-01-26 17:44:34 -08003359 if (s_callbacks.version >= 7) {
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003360 responseSimRefreshV7(p, slotId, requestNumber, responseType, token, e, response);
Sanket Padawe4c05f352016-01-26 16:19:00 -08003361 } else {
3362 int *p_cur = ((int *) response);
3363 p.writeInt32(p_cur[0]);
3364 p.writeInt32(p_cur[1]);
3365 writeStringToParcel(p, NULL);
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003366
Sanket Padawe4c05f352016-01-26 16:19:00 -08003367 appendPrintBuf("%sresult=%d, ef_id=%d",
3368 printBuf,
3369 p_cur[0],
3370 p_cur[1]);
3371 }
Sanket Padawe00909612016-01-26 18:44:01 -08003372 } else { // RIL version >= 13
Sanket Padawe4c05f352016-01-26 16:19:00 -08003373 if (responselen % sizeof(RIL_SimRefreshResponse_v7) != 0) {
3374 RLOGE("Data structure expected is RIL_SimRefreshResponse_v7");
3375 if (!isDebuggable()) {
3376 return RIL_ERRNO_INVALID_RESPONSE;
3377 } else {
3378 assert(0);
3379 }
3380 }
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003381 responseSimRefreshV7(p, slotId, requestNumber, responseType, token, e, response);
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003382
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003383 }
3384 closeResponse;
3385
3386 return 0;
3387}
3388
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003389static int responseCellInfoListV6(Parcel &p, int slotId, int requestNumber, int responseType,
3390 int token, RIL_Errno e, void *response, size_t responselen) {
Wink Saville8a9e0212013-04-09 12:11:38 -07003391 if (response == NULL && responselen != 0) {
3392 RLOGE("invalid response: NULL");
3393 return RIL_ERRNO_INVALID_RESPONSE;
3394 }
3395
3396 if (responselen % sizeof(RIL_CellInfo) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07003397 RLOGE("responseCellInfoList: invalid response length %d expected multiple of %d",
Wink Saville8a9e0212013-04-09 12:11:38 -07003398 (int)responselen, (int)sizeof(RIL_CellInfo));
3399 return RIL_ERRNO_INVALID_RESPONSE;
3400 }
3401
3402 int num = responselen / sizeof(RIL_CellInfo);
3403 p.writeInt32(num);
3404
3405 RIL_CellInfo *p_cur = (RIL_CellInfo *) response;
3406 startResponse;
3407 int i;
3408 for (i = 0; i < num; i++) {
Wink Saville8a9e0212013-04-09 12:11:38 -07003409 p.writeInt32((int)p_cur->cellInfoType);
3410 p.writeInt32(p_cur->registered);
3411 p.writeInt32(p_cur->timeStampType);
3412 p.writeInt64(p_cur->timeStamp);
3413 switch(p_cur->cellInfoType) {
3414 case RIL_CELL_INFO_TYPE_GSM: {
Wink Saville8a9e0212013-04-09 12:11:38 -07003415 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
3416 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
3417 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
3418 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
Wink Saville8a9e0212013-04-09 12:11:38 -07003419 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
3420 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3421 break;
3422 }
Wink Savillec57b3eb2013-04-17 12:51:41 -07003423 case RIL_CELL_INFO_TYPE_WCDMA: {
Wink Savillec57b3eb2013-04-17 12:51:41 -07003424 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
3425 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
3426 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
3427 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
3428 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3429 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
3430 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3431 break;
3432 }
Wink Saville8a9e0212013-04-09 12:11:38 -07003433 case RIL_CELL_INFO_TYPE_CDMA: {
Wink Saville8a9e0212013-04-09 12:11:38 -07003434 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
3435 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
3436 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
3437 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
3438 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3439
Wink Saville8a9e0212013-04-09 12:11:38 -07003440 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
3441 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
3442 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
3443 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
3444 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3445 break;
3446 }
3447 case RIL_CELL_INFO_TYPE_LTE: {
Wink Saville8a9e0212013-04-09 12:11:38 -07003448 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
3449 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
3450 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
3451 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
3452 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
3453
Wink Saville8a9e0212013-04-09 12:11:38 -07003454 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
3455 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
3456 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
3457 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
3458 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
3459 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3460 break;
3461 }
Etan Cohend3652192014-06-20 08:28:44 -07003462 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
Etan Cohend3652192014-06-20 08:28:44 -07003463 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
3464 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
3465 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
3466 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
3467 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3468 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3469 break;
3470 }
Wink Saville8a9e0212013-04-09 12:11:38 -07003471 }
3472 p_cur += 1;
3473 }
3474 removeLastChar;
3475 closeResponse;
3476
3477 return 0;
3478}
3479
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003480static int responseCellInfoListV12(Parcel &p, int slotId, int requestNumber, int responseType,
3481 int token, RIL_Errno e, void *response, size_t responselen) {
Sanket Padawe00909612016-01-26 18:44:01 -08003482 if (response == NULL && responselen != 0) {
3483 RLOGE("invalid response: NULL");
3484 return RIL_ERRNO_INVALID_RESPONSE;
3485 }
3486
3487 if (responselen % sizeof(RIL_CellInfo_v12) != 0) {
3488 RLOGE("responseCellInfoList: invalid response length %d expected multiple of %d",
3489 (int)responselen, (int)sizeof(RIL_CellInfo_v12));
3490 return RIL_ERRNO_INVALID_RESPONSE;
3491 }
3492
3493 int num = responselen / sizeof(RIL_CellInfo_v12);
3494 p.writeInt32(num);
3495
3496 RIL_CellInfo_v12 *p_cur = (RIL_CellInfo_v12 *) response;
3497 startResponse;
3498 int i;
3499 for (i = 0; i < num; i++) {
Sanket Padawe00909612016-01-26 18:44:01 -08003500 p.writeInt32((int)p_cur->cellInfoType);
3501 p.writeInt32(p_cur->registered);
3502 p.writeInt32(p_cur->timeStampType);
3503 p.writeInt64(p_cur->timeStamp);
3504 switch(p_cur->cellInfoType) {
3505 case RIL_CELL_INFO_TYPE_GSM: {
Sanket Padawe00909612016-01-26 18:44:01 -08003506 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
3507 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
3508 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
3509 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3510 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.arfcn);
3511 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.bsic);
3512 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
3513 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3514 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.timingAdvance);
3515 break;
3516 }
3517 case RIL_CELL_INFO_TYPE_WCDMA: {
Sanket Padawe00909612016-01-26 18:44:01 -08003518 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
3519 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
3520 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
3521 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
3522 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3523 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.uarfcn);
3524 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
3525 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3526 break;
3527 }
3528 case RIL_CELL_INFO_TYPE_CDMA: {
Sanket Padawe00909612016-01-26 18:44:01 -08003529 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
3530 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
3531 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
3532 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
3533 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3534
Sanket Padawe00909612016-01-26 18:44:01 -08003535 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
3536 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
3537 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
3538 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
3539 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3540 break;
3541 }
3542 case RIL_CELL_INFO_TYPE_LTE: {
Sanket Padawe00909612016-01-26 18:44:01 -08003543 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
3544 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
3545 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
3546 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
3547 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
3548 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.earfcn);
3549
Sanket Padawe00909612016-01-26 18:44:01 -08003550 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
3551 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
3552 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
3553 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
3554 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
3555 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3556 break;
3557 }
3558 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
Sanket Padawe00909612016-01-26 18:44:01 -08003559 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
3560 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
3561 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
3562 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
3563 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3564 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3565 break;
3566 }
3567 }
3568 p_cur += 1;
3569 }
3570 removeLastChar;
3571 closeResponse;
3572 return 0;
3573}
3574
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003575static int responseCellInfoList(Parcel &p, int slotId, int requestNumber, int responseType,
3576 int token, RIL_Errno e, void *response, size_t responselen) {
Sanket Padawe00909612016-01-26 18:44:01 -08003577 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
3578 if (s_callbacks.version < 12) {
3579 RLOGD("responseCellInfoList: v6");
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003580 return responseCellInfoListV6(p, slotId, requestNumber, responseType, token, e,
3581 response, responselen);
Sanket Padawe00909612016-01-26 18:44:01 -08003582 } else {
3583 RLOGD("responseCellInfoList: v12");
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003584 return responseCellInfoListV12(p, slotId, requestNumber, responseType, token, e,
3585 response, responselen);
Sanket Padawe00909612016-01-26 18:44:01 -08003586 }
3587 } else { // RIL version >= 13
3588 if (responselen % sizeof(RIL_CellInfo_v12) != 0) {
3589 RLOGE("Data structure expected is RIL_CellInfo_v12");
3590 if (!isDebuggable()) {
3591 return RIL_ERRNO_INVALID_RESPONSE;
3592 } else {
3593 assert(0);
3594 }
3595 }
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003596 return responseCellInfoListV12(p, slotId, requestNumber, responseType, token, e, response,
3597 responselen);
Sanket Padawe00909612016-01-26 18:44:01 -08003598 }
3599
3600 return 0;
3601}
3602
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003603static int responseHardwareConfig(Parcel &p, int slotId, int requestNumber, int responseType,
3604 int token, RIL_Errno e, void *response, size_t responselen) {
Etan Cohend3652192014-06-20 08:28:44 -07003605 if (response == NULL && responselen != 0) {
3606 RLOGE("invalid response: NULL");
3607 return RIL_ERRNO_INVALID_RESPONSE;
3608 }
3609
3610 if (responselen % sizeof(RIL_HardwareConfig) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07003611 RLOGE("responseHardwareConfig: invalid response length %d expected multiple of %d",
Etan Cohend3652192014-06-20 08:28:44 -07003612 (int)responselen, (int)sizeof(RIL_HardwareConfig));
3613 return RIL_ERRNO_INVALID_RESPONSE;
3614 }
3615
3616 int num = responselen / sizeof(RIL_HardwareConfig);
3617 int i;
3618 RIL_HardwareConfig *p_cur = (RIL_HardwareConfig *) response;
3619
3620 p.writeInt32(num);
3621
3622 startResponse;
3623 for (i = 0; i < num; i++) {
3624 switch (p_cur[i].type) {
3625 case RIL_HARDWARE_CONFIG_MODEM: {
3626 writeStringToParcel(p, p_cur[i].uuid);
3627 p.writeInt32((int)p_cur[i].state);
3628 p.writeInt32(p_cur[i].cfg.modem.rat);
3629 p.writeInt32(p_cur[i].cfg.modem.maxVoice);
3630 p.writeInt32(p_cur[i].cfg.modem.maxData);
3631 p.writeInt32(p_cur[i].cfg.modem.maxStandby);
3632
3633 appendPrintBuf("%s modem: uuid=%s,state=%d,rat=%08x,maxV=%d,maxD=%d,maxS=%d", printBuf,
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003634 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.modem.rat,
3635 p_cur[i].cfg.modem.maxVoice, p_cur[i].cfg.modem.maxData,
3636 p_cur[i].cfg.modem.maxStandby);
Etan Cohend3652192014-06-20 08:28:44 -07003637 break;
3638 }
3639 case RIL_HARDWARE_CONFIG_SIM: {
3640 writeStringToParcel(p, p_cur[i].uuid);
3641 p.writeInt32((int)p_cur[i].state);
3642 writeStringToParcel(p, p_cur[i].cfg.sim.modemUuid);
3643
3644 appendPrintBuf("%s sim: uuid=%s,state=%d,modem-uuid=%s", printBuf,
3645 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.sim.modemUuid);
3646 break;
3647 }
3648 }
3649 }
3650 removeLastChar;
3651 closeResponse;
3652 return 0;
3653}
3654
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003655static int responseRadioCapability(Parcel &p, int slotId, int requestNumber, int responseType,
3656 int token, RIL_Errno e, void *response, size_t responselen) {
Wink Saville8b4e4f72014-10-17 15:01:45 -07003657 if (response == NULL) {
3658 RLOGE("invalid response: NULL");
3659 return RIL_ERRNO_INVALID_RESPONSE;
3660 }
3661
3662 if (responselen != sizeof (RIL_RadioCapability) ) {
3663 RLOGE("invalid response length was %d expected %d",
3664 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3665 return RIL_ERRNO_INVALID_RESPONSE;
3666 }
3667
3668 RIL_RadioCapability *p_cur = (RIL_RadioCapability *) response;
3669 p.writeInt32(p_cur->version);
3670 p.writeInt32(p_cur->session);
3671 p.writeInt32(p_cur->phase);
3672 p.writeInt32(p_cur->rat);
3673 writeStringToParcel(p, p_cur->logicalModemUuid);
3674 p.writeInt32(p_cur->status);
3675
3676 startResponse;
3677 appendPrintBuf("%s[version=%d,session=%d,phase=%d,\
Legler Wu8caf06f2014-10-29 14:02:14 +08003678 rat=%s,logicalModemUuid=%s,status=%d]",
Wink Saville8b4e4f72014-10-17 15:01:45 -07003679 printBuf,
3680 p_cur->version,
3681 p_cur->session,
3682 p_cur->phase,
3683 p_cur->rat,
Legler Wu8caf06f2014-10-29 14:02:14 +08003684 p_cur->logicalModemUuid,
Wink Saville8b4e4f72014-10-17 15:01:45 -07003685 p_cur->status);
3686 closeResponse;
3687 return 0;
3688}
3689
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003690static int responseSSData(Parcel &p, int slotId, int requestNumber, int responseType, int token,
3691 RIL_Errno e, void *response, size_t responselen) {
Amit Mahajan54563d32014-11-22 00:54:49 +00003692 RLOGD("In responseSSData");
3693 int num;
3694
3695 if (response == NULL && responselen != 0) {
3696 RLOGE("invalid response length was %d expected %d",
3697 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3698 return RIL_ERRNO_INVALID_RESPONSE;
3699 }
3700
3701 if (responselen != sizeof(RIL_StkCcUnsolSsResponse)) {
3702 RLOGE("invalid response length %d, expected %d",
3703 (int)responselen, (int)sizeof(RIL_StkCcUnsolSsResponse));
3704 return RIL_ERRNO_INVALID_RESPONSE;
3705 }
3706
3707 startResponse;
3708 RIL_StkCcUnsolSsResponse *p_cur = (RIL_StkCcUnsolSsResponse *) response;
3709 p.writeInt32(p_cur->serviceType);
3710 p.writeInt32(p_cur->requestType);
3711 p.writeInt32(p_cur->teleserviceType);
3712 p.writeInt32(p_cur->serviceClass);
3713 p.writeInt32(p_cur->result);
3714
3715 if (isServiceTypeCfQuery(p_cur->serviceType, p_cur->requestType)) {
3716 RLOGD("responseSSData CF type, num of Cf elements %d", p_cur->cfData.numValidIndexes);
3717 if (p_cur->cfData.numValidIndexes > NUM_SERVICE_CLASSES) {
3718 RLOGE("numValidIndexes is greater than max value %d, "
3719 "truncating it to max value", NUM_SERVICE_CLASSES);
3720 p_cur->cfData.numValidIndexes = NUM_SERVICE_CLASSES;
3721 }
3722 /* number of call info's */
3723 p.writeInt32(p_cur->cfData.numValidIndexes);
3724
3725 for (int i = 0; i < p_cur->cfData.numValidIndexes; i++) {
3726 RIL_CallForwardInfo cf = p_cur->cfData.cfInfo[i];
3727
3728 p.writeInt32(cf.status);
3729 p.writeInt32(cf.reason);
3730 p.writeInt32(cf.serviceClass);
3731 p.writeInt32(cf.toa);
3732 writeStringToParcel(p, cf.number);
3733 p.writeInt32(cf.timeSeconds);
3734 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
3735 (cf.status==1)?"enable":"disable", cf.reason, cf.serviceClass, cf.toa,
3736 (char*)cf.number, cf.timeSeconds);
3737 RLOGD("Data: %d,reason=%d,cls=%d,toa=%d,num=%s,tout=%d],", cf.status,
3738 cf.reason, cf.serviceClass, cf.toa, (char*)cf.number, cf.timeSeconds);
3739 }
3740 } else {
3741 p.writeInt32 (SS_INFO_MAX);
3742
3743 /* each int*/
3744 for (int i = 0; i < SS_INFO_MAX; i++) {
3745 appendPrintBuf("%s%d,", printBuf, p_cur->ssInfo[i]);
3746 RLOGD("Data: %d",p_cur->ssInfo[i]);
3747 p.writeInt32(p_cur->ssInfo[i]);
3748 }
3749 }
3750 removeLastChar;
3751 closeResponse;
3752
3753 return 0;
3754}
3755
3756static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType) {
3757 if ((reqType == SS_INTERROGATION) &&
3758 (serType == SS_CFU ||
3759 serType == SS_CF_BUSY ||
3760 serType == SS_CF_NO_REPLY ||
3761 serType == SS_CF_NOT_REACHABLE ||
3762 serType == SS_CF_ALL ||
3763 serType == SS_CF_ALL_CONDITIONAL)) {
3764 return true;
3765 }
3766 return false;
3767}
3768
Wink Saville3d54e742009-05-18 18:00:44 -07003769static void triggerEvLoop() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003770 int ret;
3771 if (!pthread_equal(pthread_self(), s_tid_dispatch)) {
3772 /* trigger event loop to wakeup. No reason to do this,
3773 * if we're in the event loop thread */
3774 do {
3775 ret = write (s_fdWakeupWrite, " ", 1);
3776 } while (ret < 0 && errno == EINTR);
3777 }
3778}
3779
Wink Saville3d54e742009-05-18 18:00:44 -07003780static void rilEventAddWakeup(struct ril_event *ev) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003781 ril_event_add(ev);
3782 triggerEvLoop();
3783}
3784
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003785static int responseGsmBrSmsCnf(Parcel &p, int slotId, int requestNumber, int responseType,
3786 int token, RIL_Errno e, void *response, size_t responselen) {
Wink Savillea592eeb2009-05-22 13:26:36 -07003787 int num = responselen / sizeof(RIL_GSM_BroadcastSmsConfigInfo *);
Wink Savillef4c4d362009-04-02 01:37:03 -07003788 p.writeInt32(num);
3789
Wink Savillef4c4d362009-04-02 01:37:03 -07003790 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07003791 RIL_GSM_BroadcastSmsConfigInfo **p_cur =
3792 (RIL_GSM_BroadcastSmsConfigInfo **) response;
3793 for (int i = 0; i < num; i++) {
3794 p.writeInt32(p_cur[i]->fromServiceId);
3795 p.writeInt32(p_cur[i]->toServiceId);
3796 p.writeInt32(p_cur[i]->fromCodeScheme);
3797 p.writeInt32(p_cur[i]->toCodeScheme);
3798 p.writeInt32(p_cur[i]->selected);
3799
3800 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId=%d, \
3801 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]",
3802 printBuf, i, p_cur[i]->fromServiceId, p_cur[i]->toServiceId,
3803 p_cur[i]->fromCodeScheme, p_cur[i]->toCodeScheme,
3804 p_cur[i]->selected);
3805 }
Wink Savillef4c4d362009-04-02 01:37:03 -07003806 closeResponse;
3807
3808 return 0;
3809}
3810
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003811static int responseCdmaBrSmsCnf(Parcel &p, int slotId, int requestNumber, int responseType,
3812 int token, RIL_Errno e, void *response, size_t responselen) {
Wink Savillea592eeb2009-05-22 13:26:36 -07003813 RIL_CDMA_BroadcastSmsConfigInfo **p_cur =
3814 (RIL_CDMA_BroadcastSmsConfigInfo **) response;
Wink Savillef4c4d362009-04-02 01:37:03 -07003815
Wink Savillea592eeb2009-05-22 13:26:36 -07003816 int num = responselen / sizeof (RIL_CDMA_BroadcastSmsConfigInfo *);
3817 p.writeInt32(num);
Wink Savillef4c4d362009-04-02 01:37:03 -07003818
3819 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07003820 for (int i = 0 ; i < num ; i++ ) {
3821 p.writeInt32(p_cur[i]->service_category);
3822 p.writeInt32(p_cur[i]->language);
3823 p.writeInt32(p_cur[i]->selected);
Wink Savillef4c4d362009-04-02 01:37:03 -07003824
Wink Savillea592eeb2009-05-22 13:26:36 -07003825 appendPrintBuf("%s [%d: srvice_category=%d, language =%d, \
3826 selected =%d], ",
3827 printBuf, i, p_cur[i]->service_category, p_cur[i]->language,
3828 p_cur[i]->selected);
Wink Savillef5903df2009-04-24 11:54:14 -07003829 }
Wink Savillea592eeb2009-05-22 13:26:36 -07003830 closeResponse;
Wink Savillef5903df2009-04-24 11:54:14 -07003831
Wink Savillef4c4d362009-04-02 01:37:03 -07003832 return 0;
3833}
3834
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003835static int responseCdmaSms(Parcel &p, int slotId, int requestNumber, int responseType, int token,
3836 RIL_Errno e, void *response, size_t responselen) {
Wink Savillef4c4d362009-04-02 01:37:03 -07003837 int num;
3838 int digitCount;
3839 int digitLimit;
3840 uint8_t uct;
3841 void* dest;
3842
Wink Saville8eb2a122012-11-19 16:05:13 -08003843 RLOGD("Inside responseCdmaSms");
Wink Savillef5903df2009-04-24 11:54:14 -07003844
Wink Savillef4c4d362009-04-02 01:37:03 -07003845 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003846 RLOGE("invalid response: NULL");
Wink Savillef4c4d362009-04-02 01:37:03 -07003847 return RIL_ERRNO_INVALID_RESPONSE;
3848 }
3849
Wink Savillef5903df2009-04-24 11:54:14 -07003850 if (responselen != sizeof(RIL_CDMA_SMS_Message)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003851 RLOGE("invalid response length was %d expected %d",
Wink Savillef5903df2009-04-24 11:54:14 -07003852 (int)responselen, (int)sizeof(RIL_CDMA_SMS_Message));
Wink Savillef4c4d362009-04-02 01:37:03 -07003853 return RIL_ERRNO_INVALID_RESPONSE;
3854 }
3855
3856 RIL_CDMA_SMS_Message *p_cur = (RIL_CDMA_SMS_Message *) response;
3857 p.writeInt32(p_cur->uTeleserviceID);
3858 p.write(&(p_cur->bIsServicePresent),sizeof(uct));
3859 p.writeInt32(p_cur->uServicecategory);
3860 p.writeInt32(p_cur->sAddress.digit_mode);
3861 p.writeInt32(p_cur->sAddress.number_mode);
3862 p.writeInt32(p_cur->sAddress.number_type);
3863 p.writeInt32(p_cur->sAddress.number_plan);
3864 p.write(&(p_cur->sAddress.number_of_digits), sizeof(uct));
3865 digitLimit= MIN((p_cur->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
3866 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3867 p.write(&(p_cur->sAddress.digits[digitCount]),sizeof(uct));
3868 }
3869
3870 p.writeInt32(p_cur->sSubAddress.subaddressType);
3871 p.write(&(p_cur->sSubAddress.odd),sizeof(uct));
3872 p.write(&(p_cur->sSubAddress.number_of_digits),sizeof(uct));
3873 digitLimit= MIN((p_cur->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
3874 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3875 p.write(&(p_cur->sSubAddress.digits[digitCount]),sizeof(uct));
3876 }
3877
3878 digitLimit= MIN((p_cur->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
3879 p.writeInt32(p_cur->uBearerDataLen);
3880 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3881 p.write(&(p_cur->aBearerData[digitCount]), sizeof(uct));
3882 }
3883
3884 startResponse;
3885 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
Wink Saville1b5fd232009-04-22 14:50:00 -07003886 sAddress.digit_mode=%d, sAddress.number_mode=%d, sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07003887 printBuf, p_cur->uTeleserviceID,p_cur->bIsServicePresent,p_cur->uServicecategory,
3888 p_cur->sAddress.digit_mode, p_cur->sAddress.number_mode,p_cur->sAddress.number_type);
3889 closeResponse;
3890
3891 return 0;
3892}
3893
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003894static int responseDcRtInfo(Parcel &p, int slotId, int requestNumber, int responseType, int token,
3895 RIL_Errno e, void *response, size_t responselen)
Wink Savillec29360a2014-07-13 05:17:28 -07003896{
3897 int num = responselen / sizeof(RIL_DcRtInfo);
3898 if ((responselen % sizeof(RIL_DcRtInfo) != 0) || (num != 1)) {
Amit Mahajan52500162014-07-29 17:36:48 -07003899 RLOGE("responseDcRtInfo: invalid response length %d expected multiple of %d",
Wink Savillec29360a2014-07-13 05:17:28 -07003900 (int)responselen, (int)sizeof(RIL_DcRtInfo));
3901 return RIL_ERRNO_INVALID_RESPONSE;
3902 }
3903
3904 startResponse;
3905 RIL_DcRtInfo *pDcRtInfo = (RIL_DcRtInfo *)response;
3906 p.writeInt64(pDcRtInfo->time);
3907 p.writeInt32(pDcRtInfo->powerState);
3908 appendPrintBuf("%s[time=%d,powerState=%d]", printBuf,
3909 pDcRtInfo->time,
3910 pDcRtInfo->powerState);
3911 closeResponse;
3912
3913 return 0;
3914}
3915
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003916static int responseLceStatus(Parcel &p, int slotId, int requestNumber, int responseType, int token,
3917 RIL_Errno e, void *response, size_t responselen) {
fengluf7408292015-04-14 14:53:55 -07003918 if (response == NULL || responselen != sizeof(RIL_LceStatusInfo)) {
3919 if (response == NULL) {
3920 RLOGE("invalid response: NULL");
3921 }
3922 else {
Meng Wangef966a32016-06-20 17:38:18 -07003923 RLOGE("responseLceStatus: invalid response length %u expecting len: %u",
3924 (unsigned)sizeof(RIL_LceStatusInfo), (unsigned)responselen);
fengluf7408292015-04-14 14:53:55 -07003925 }
3926 return RIL_ERRNO_INVALID_RESPONSE;
3927 }
3928
3929 RIL_LceStatusInfo *p_cur = (RIL_LceStatusInfo *)response;
3930 p.write((void *)p_cur, 1); // p_cur->lce_status takes one byte.
3931 p.writeInt32(p_cur->actual_interval_ms);
3932
3933 startResponse;
3934 appendPrintBuf("LCE Status: %d, actual_interval_ms: %d",
3935 p_cur->lce_status, p_cur->actual_interval_ms);
3936 closeResponse;
3937
3938 return 0;
3939}
3940
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003941static int responseLceData(Parcel &p, int slotId, int requestNumber, int responseType, int token,
3942 RIL_Errno e, void *response, size_t responselen) {
fengluf7408292015-04-14 14:53:55 -07003943 if (response == NULL || responselen != sizeof(RIL_LceDataInfo)) {
3944 if (response == NULL) {
3945 RLOGE("invalid response: NULL");
3946 }
3947 else {
Meng Wangef966a32016-06-20 17:38:18 -07003948 RLOGE("responseLceData: invalid response length %u expecting len: %u",
3949 (unsigned)sizeof(RIL_LceDataInfo), (unsigned)responselen);
fengluf7408292015-04-14 14:53:55 -07003950 }
3951 return RIL_ERRNO_INVALID_RESPONSE;
3952 }
3953
3954 RIL_LceDataInfo *p_cur = (RIL_LceDataInfo *)response;
3955 p.writeInt32(p_cur->last_hop_capacity_kbps);
3956
3957 /* p_cur->confidence_level and p_cur->lce_suspended take 1 byte each.*/
3958 p.write((void *)&(p_cur->confidence_level), 1);
3959 p.write((void *)&(p_cur->lce_suspended), 1);
3960
3961 startResponse;
Hyejin606dd672015-09-14 16:27:28 -07003962 appendPrintBuf("LCE info received: capacity %d confidence level %d \
fengluf7408292015-04-14 14:53:55 -07003963 and suspended %d",
3964 p_cur->last_hop_capacity_kbps, p_cur->confidence_level,
3965 p_cur->lce_suspended);
3966 closeResponse;
3967
3968 return 0;
3969}
3970
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003971static int responseActivityData(Parcel &p, int slotId, int requestNumber, int responseType,
3972 int token, RIL_Errno e, void *response, size_t responselen) {
Prerepa Viswanadham73157492015-05-28 00:37:32 -07003973 if (response == NULL || responselen != sizeof(RIL_ActivityStatsInfo)) {
3974 if (response == NULL) {
3975 RLOGE("invalid response: NULL");
3976 }
3977 else {
Meng Wangef966a32016-06-20 17:38:18 -07003978 RLOGE("responseActivityData: invalid response length %u expecting len: %u",
3979 (unsigned)sizeof(RIL_ActivityStatsInfo), (unsigned)responselen);
Prerepa Viswanadham73157492015-05-28 00:37:32 -07003980 }
3981 return RIL_ERRNO_INVALID_RESPONSE;
3982 }
3983
3984 RIL_ActivityStatsInfo *p_cur = (RIL_ActivityStatsInfo *)response;
3985 p.writeInt32(p_cur->sleep_mode_time_ms);
3986 p.writeInt32(p_cur->idle_mode_time_ms);
3987 for(int i = 0; i < RIL_NUM_TX_POWER_LEVELS; i++) {
3988 p.writeInt32(p_cur->tx_mode_time_ms[i]);
3989 }
3990 p.writeInt32(p_cur->rx_mode_time_ms);
3991
3992 startResponse;
Hyejin606dd672015-09-14 16:27:28 -07003993 appendPrintBuf("Modem activity info received: sleep_mode_time_ms %d idle_mode_time_ms %d \
Prerepa Viswanadham73157492015-05-28 00:37:32 -07003994 tx_mode_time_ms %d %d %d %d %d and rx_mode_time_ms %d",
3995 p_cur->sleep_mode_time_ms, p_cur->idle_mode_time_ms, p_cur->tx_mode_time_ms[0],
3996 p_cur->tx_mode_time_ms[1], p_cur->tx_mode_time_ms[2], p_cur->tx_mode_time_ms[3],
3997 p_cur->tx_mode_time_ms[4], p_cur->rx_mode_time_ms);
3998 closeResponse;
3999
4000 return 0;
4001}
4002
Amit Mahajan18fe36b2016-08-25 11:19:21 -07004003static int responseCarrierRestrictions(Parcel &p, int slotId, int requestNumber, int responseType,
4004 int token, RIL_Errno e, void *response, size_t responselen) {
Meng Wangb4e34312016-05-12 14:54:36 -07004005 if (response == NULL) {
4006 RLOGE("invalid response: NULL");
4007 return RIL_ERRNO_INVALID_RESPONSE;
4008 }
4009 if (responselen != sizeof(RIL_CarrierRestrictions)) {
Meng Wangef966a32016-06-20 17:38:18 -07004010 RLOGE("responseCarrierRestrictions: invalid response length %u expecting len: %u",
4011 (unsigned)responselen, (unsigned)sizeof(RIL_CarrierRestrictions));
Meng Wangb4e34312016-05-12 14:54:36 -07004012 return RIL_ERRNO_INVALID_RESPONSE;
4013 }
4014
4015 RIL_CarrierRestrictions *p_cr = (RIL_CarrierRestrictions *)response;
Meng Wangb460ba82016-06-09 09:21:26 -07004016 startResponse;
4017
4018 p.writeInt32(p_cr->len_allowed_carriers);
4019 p.writeInt32(p_cr->len_excluded_carriers);
4020 appendPrintBuf(" %s len_allowed_carriers: %d, len_excluded_carriers: %d,", printBuf,
4021 p_cr->len_allowed_carriers,p_cr->len_excluded_carriers);
4022
4023 appendPrintBuf(" %s allowed_carriers:", printBuf);
4024 for(int32_t i = 0; i < p_cr->len_allowed_carriers; i++) {
Meng Wangb4e34312016-05-12 14:54:36 -07004025 RIL_Carrier *carrier = p_cr->allowed_carriers + i;
Meng Wangb460ba82016-06-09 09:21:26 -07004026 writeStringToParcel(p, carrier->mcc);
4027 writeStringToParcel(p, carrier->mnc);
Meng Wangb4e34312016-05-12 14:54:36 -07004028 p.writeInt32(carrier->match_type);
Meng Wangb460ba82016-06-09 09:21:26 -07004029 writeStringToParcel(p, carrier->match_data);
4030 appendPrintBuf(" %s [%d mcc: %s, mnc: %s, match_type: %d, match_data: %s],", printBuf,
4031 i, carrier->mcc, carrier->mnc, carrier->match_type, carrier->match_data);
Meng Wangb4e34312016-05-12 14:54:36 -07004032 }
4033
Meng Wangb460ba82016-06-09 09:21:26 -07004034 appendPrintBuf(" %s excluded_carriers:", printBuf);
4035 for(int32_t i = 0; i < p_cr->len_excluded_carriers; i++) {
4036 RIL_Carrier *carrier = p_cr->excluded_carriers + i;
4037 writeStringToParcel(p, carrier->mcc);
4038 writeStringToParcel(p, carrier->mnc);
4039 p.writeInt32(carrier->match_type);
4040 writeStringToParcel(p, carrier->match_data);
4041 appendPrintBuf(" %s [%d mcc: %s, mnc: %s, match_type: %d, match_data: %s],", printBuf,
4042 i, carrier->mcc, carrier->mnc, carrier->match_type, carrier->match_data);
4043 }
4044
Meng Wangb4e34312016-05-12 14:54:36 -07004045 closeResponse;
4046
4047 return 0;
4048}
4049
Amit Mahajan18fe36b2016-08-25 11:19:21 -07004050static int responsePcoData(Parcel &p, int slotId, int requestNumber, int responseType, int token,
4051 RIL_Errno e, void *response, size_t responselen) {
Robert Greenwalt27e99c52016-06-01 16:31:38 -07004052 if (response == NULL) {
4053 RLOGE("responsePcoData: invalid NULL response");
4054 return RIL_ERRNO_INVALID_RESPONSE;
4055 }
4056 if (responselen != sizeof(RIL_PCO_Data)) {
Meng Wangef966a32016-06-20 17:38:18 -07004057 RLOGE("responsePcoData: invalid response length %u, expecting %u",
4058 (unsigned)responselen, (unsigned)sizeof(RIL_PCO_Data));
Robert Greenwalt27e99c52016-06-01 16:31:38 -07004059 return RIL_ERRNO_INVALID_RESPONSE;
4060 }
4061
4062 RIL_PCO_Data *p_cur = (RIL_PCO_Data *)response;
4063 p.writeInt32(p_cur->cid);
4064 writeStringToParcel(p, p_cur->bearer_proto);
4065 p.writeInt32(p_cur->pco_id);
4066 p.writeInt32(p_cur->contents_length);
4067 p.write(p_cur->contents, p_cur->contents_length);
4068
4069 startResponse;
4070 appendPrintBuf("PCO data received: cid %d, id %d, length %d",
4071 p_cur->cid, p_cur->pco_id, p_cur->contents_length);
4072 closeResponse;
4073
4074 return 0;
4075}
4076
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004077/**
4078 * A write on the wakeup fd is done just to pop us out of select()
4079 * We empty the buffer here and then ril_event will reset the timers on the
4080 * way back down
4081 */
Wink Savillef4c4d362009-04-02 01:37:03 -07004082static void processWakeupCallback(int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004083 char buff[16];
4084 int ret;
4085
Wink Saville8eb2a122012-11-19 16:05:13 -08004086 RLOGV("processWakeupCallback");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004087
4088 /* empty our wakeup socket out */
4089 do {
4090 ret = read(s_fdWakeupRead, &buff, sizeof(buff));
Wink Saville7f856802009-06-09 10:23:37 -07004091 } while (ret > 0 || (ret < 0 && errno == EINTR));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004092}
4093
Etan Cohend3652192014-06-20 08:28:44 -07004094static void onCommandsSocketClosed(RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004095 int ret;
4096 RequestInfo *p_cur;
Etan Cohend3652192014-06-20 08:28:44 -07004097 /* Hook for current context
4098 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
4099 pthread_mutex_t * pendingRequestsMutexHook = &s_pendingRequestsMutex;
4100 /* pendingRequestsHook refer to &s_pendingRequests */
4101 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004102
Etan Cohend3652192014-06-20 08:28:44 -07004103#if (SIM_COUNT >= 2)
4104 if (socket_id == RIL_SOCKET_2) {
4105 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
4106 pendingRequestsHook = &s_pendingRequests_socket2;
4107 }
4108#if (SIM_COUNT >= 3)
4109 else if (socket_id == RIL_SOCKET_3) {
4110 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
4111 pendingRequestsHook = &s_pendingRequests_socket3;
4112 }
4113#endif
4114#if (SIM_COUNT >= 4)
4115 else if (socket_id == RIL_SOCKET_4) {
4116 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
4117 pendingRequestsHook = &s_pendingRequests_socket4;
4118 }
4119#endif
4120#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004121 /* mark pending requests as "cancelled" so we dont report responses */
Etan Cohend3652192014-06-20 08:28:44 -07004122 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004123 assert (ret == 0);
4124
Etan Cohend3652192014-06-20 08:28:44 -07004125 p_cur = *pendingRequestsHook;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004126
Etan Cohend3652192014-06-20 08:28:44 -07004127 for (p_cur = *pendingRequestsHook
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004128 ; p_cur != NULL
4129 ; p_cur = p_cur->p_next
4130 ) {
4131 p_cur->cancelled = 1;
4132 }
4133
Etan Cohend3652192014-06-20 08:28:44 -07004134 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004135 assert (ret == 0);
4136}
4137
Wink Savillef4c4d362009-04-02 01:37:03 -07004138static void processCommandsCallback(int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004139 RecordStream *p_rs;
4140 void *p_record;
4141 size_t recordlen;
4142 int ret;
Etan Cohend3652192014-06-20 08:28:44 -07004143 SocketListenParam *p_info = (SocketListenParam *)param;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004144
Etan Cohend3652192014-06-20 08:28:44 -07004145 assert(fd == p_info->fdCommand);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004146
Etan Cohend3652192014-06-20 08:28:44 -07004147 p_rs = p_info->p_rs;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004148
4149 for (;;) {
4150 /* loop until EAGAIN/EINTR, end of stream, or other error */
4151 ret = record_stream_get_next(p_rs, &p_record, &recordlen);
4152
4153 if (ret == 0 && p_record == NULL) {
4154 /* end-of-stream */
4155 break;
4156 } else if (ret < 0) {
4157 break;
4158 } else if (ret == 0) { /* && p_record != NULL */
Etan Cohend3652192014-06-20 08:28:44 -07004159 processCommandBuffer(p_record, recordlen, p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004160 }
4161 }
4162
4163 if (ret == 0 || !(errno == EAGAIN || errno == EINTR)) {
4164 /* fatal error or end-of-stream */
4165 if (ret != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004166 RLOGE("error on reading command socket errno:%d\n", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004167 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08004168 RLOGW("EOS. Closing command socket.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004169 }
Wink Saville7f856802009-06-09 10:23:37 -07004170
Etan Cohend3652192014-06-20 08:28:44 -07004171 close(fd);
4172 p_info->fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004173
Etan Cohend3652192014-06-20 08:28:44 -07004174 ril_event_del(p_info->commands_event);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004175
4176 record_stream_free(p_rs);
4177
4178 /* start listening for new connections again */
4179 rilEventAddWakeup(&s_listen_event);
4180
Etan Cohend3652192014-06-20 08:28:44 -07004181 onCommandsSocketClosed(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004182 }
4183}
4184
4185
Etan Cohend3652192014-06-20 08:28:44 -07004186static void onNewCommandConnect(RIL_SOCKET_ID socket_id) {
Wink Saville5b9df332011-04-06 16:24:21 -07004187 // Inform we are connected and the ril version
Jake Hambya9c18d12011-04-12 23:32:08 -07004188 int rilVer = s_callbacks.version;
Etan Cohend3652192014-06-20 08:28:44 -07004189 RIL_UNSOL_RESPONSE(RIL_UNSOL_RIL_CONNECTED,
4190 &rilVer, sizeof(rilVer), socket_id);
Wink Saville5b9df332011-04-06 16:24:21 -07004191
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004192 // implicit radio state changed
Etan Cohend3652192014-06-20 08:28:44 -07004193 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
4194 NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004195
4196 // Send last NITZ time data, in case it was missed
4197 if (s_lastNITZTimeData != NULL) {
Etan Cohend3652192014-06-20 08:28:44 -07004198 sendResponseRaw(s_lastNITZTimeData, s_lastNITZTimeDataSize, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004199
4200 free(s_lastNITZTimeData);
4201 s_lastNITZTimeData = NULL;
4202 }
4203
4204 // Get version string
4205 if (s_callbacks.getVersion != NULL) {
4206 const char *version;
4207 version = s_callbacks.getVersion();
Wink Saville8eb2a122012-11-19 16:05:13 -08004208 RLOGI("RIL Daemon version: %s\n", version);
Wink Saville7f856802009-06-09 10:23:37 -07004209
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004210 property_set(PROPERTY_RIL_IMPL, version);
4211 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08004212 RLOGI("RIL Daemon version: unavailable\n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004213 property_set(PROPERTY_RIL_IMPL, "unavailable");
4214 }
4215
4216}
4217
Wink Savillef4c4d362009-04-02 01:37:03 -07004218static void listenCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004219 int ret;
4220 int err;
4221 int is_phone_socket;
Etan Cohend3652192014-06-20 08:28:44 -07004222 int fdCommand = -1;
Meng Wangef966a32016-06-20 17:38:18 -07004223 const char* processName;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004224 RecordStream *p_rs;
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004225 MySocketListenParam* listenParam;
4226 RilSocket *sapSocket = NULL;
4227 socketClient *sClient = NULL;
4228
Etan Cohend3652192014-06-20 08:28:44 -07004229 SocketListenParam *p_info = (SocketListenParam *)param;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004230
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004231 if(RIL_SAP_SOCKET == p_info->type) {
4232 listenParam = (MySocketListenParam *)param;
4233 sapSocket = listenParam->socket;
4234 }
4235
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004236 struct sockaddr_un peeraddr;
4237 socklen_t socklen = sizeof (peeraddr);
4238
4239 struct ucred creds;
4240 socklen_t szCreds = sizeof(creds);
4241
4242 struct passwd *pwd = NULL;
4243
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004244 if(NULL == sapSocket) {
George Burgess IVd9cee0a2016-10-27 22:51:30 -07004245 assert (p_info->fdCommand < 0);
4246 assert (fd == p_info->fdListen);
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004247 processName = PHONE_PROCESS;
4248 } else {
George Burgess IVd9cee0a2016-10-27 22:51:30 -07004249 assert (sapSocket->getCommandFd() < 0);
4250 assert (fd == sapSocket->getListenFd());
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004251 processName = BLUETOOTH_PROCESS;
4252 }
4253
Wink Saville7f856802009-06-09 10:23:37 -07004254
Etan Cohend3652192014-06-20 08:28:44 -07004255 fdCommand = accept(fd, (sockaddr *) &peeraddr, &socklen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004256
Etan Cohend3652192014-06-20 08:28:44 -07004257 if (fdCommand < 0 ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004258 RLOGE("Error on accept() errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004259 /* start listening for new connections again */
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004260 if(NULL == sapSocket) {
4261 rilEventAddWakeup(p_info->listen_event);
4262 } else {
4263 rilEventAddWakeup(sapSocket->getListenEvent());
4264 }
Etan Cohend3652192014-06-20 08:28:44 -07004265 return;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004266 }
4267
4268 /* check the credential of the other side and only accept socket from
4269 * phone process
Wink Saville7f856802009-06-09 10:23:37 -07004270 */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004271 errno = 0;
4272 is_phone_socket = 0;
Wink Savillef4c4d362009-04-02 01:37:03 -07004273
Etan Cohend3652192014-06-20 08:28:44 -07004274 err = getsockopt(fdCommand, SOL_SOCKET, SO_PEERCRED, &creds, &szCreds);
Wink Savillef4c4d362009-04-02 01:37:03 -07004275
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004276 if (err == 0 && szCreds > 0) {
Wink Savillef4c4d362009-04-02 01:37:03 -07004277 errno = 0;
4278 pwd = getpwuid(creds.uid);
4279 if (pwd != NULL) {
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004280 if (strcmp(pwd->pw_name, processName) == 0) {
Wink Savillef4c4d362009-04-02 01:37:03 -07004281 is_phone_socket = 1;
4282 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08004283 RLOGE("RILD can't accept socket from process %s", pwd->pw_name);
Wink Savillef4c4d362009-04-02 01:37:03 -07004284 }
4285 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08004286 RLOGE("Error on getpwuid() errno: %d", errno);
Wink Savillef4c4d362009-04-02 01:37:03 -07004287 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004288 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08004289 RLOGD("Error on getsockopt() errno: %d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004290 }
4291
Etan Cohend3652192014-06-20 08:28:44 -07004292 if (!is_phone_socket) {
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004293 RLOGE("RILD must accept socket from %s", processName);
Wink Saville7f856802009-06-09 10:23:37 -07004294
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004295 close(fdCommand);
4296 fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004297
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004298 if(NULL == sapSocket) {
4299 onCommandsSocketClosed(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004300
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004301 /* start listening for new connections again */
4302 rilEventAddWakeup(p_info->listen_event);
4303 } else {
4304 sapSocket->onCommandsSocketClosed();
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004305
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004306 /* start listening for new connections again */
4307 rilEventAddWakeup(sapSocket->getListenEvent());
4308 }
4309
4310 return;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004311 }
4312
Etan Cohend3652192014-06-20 08:28:44 -07004313 ret = fcntl(fdCommand, F_SETFL, O_NONBLOCK);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004314
4315 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004316 RLOGE ("Error setting O_NONBLOCK errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004317 }
4318
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004319 if(NULL == sapSocket) {
4320 RLOGI("libril: new connection to %s", rilSocketIdToString(p_info->socket_id));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004321
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004322 p_info->fdCommand = fdCommand;
4323 p_rs = record_stream_new(p_info->fdCommand, MAX_COMMAND_BYTES);
4324 p_info->p_rs = p_rs;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004325
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004326 ril_event_set (p_info->commands_event, p_info->fdCommand, 1,
Etan Cohend3652192014-06-20 08:28:44 -07004327 p_info->processCommandsCallback, p_info);
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004328 rilEventAddWakeup (p_info->commands_event);
Etan Cohend3652192014-06-20 08:28:44 -07004329
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004330 onNewCommandConnect(p_info->socket_id);
4331 } else {
4332 RLOGI("libril: new connection");
Etan Cohend3652192014-06-20 08:28:44 -07004333
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004334 sapSocket->setCommandFd(fdCommand);
4335 p_rs = record_stream_new(sapSocket->getCommandFd(), MAX_COMMAND_BYTES);
4336 sClient = new socketClient(sapSocket,p_rs);
4337 ril_event_set (sapSocket->getCallbackEvent(), sapSocket->getCommandFd(), 1,
4338 sapSocket->getCommandCb(), sClient);
4339
4340 rilEventAddWakeup(sapSocket->getCallbackEvent());
4341 sapSocket->onNewCommandConnect();
4342 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004343}
4344
4345static void freeDebugCallbackArgs(int number, char **args) {
4346 for (int i = 0; i < number; i++) {
4347 if (args[i] != NULL) {
4348 free(args[i]);
4349 }
4350 }
4351 free(args);
4352}
4353
Wink Savillef4c4d362009-04-02 01:37:03 -07004354static void debugCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004355 int acceptFD, option;
4356 struct sockaddr_un peeraddr;
4357 socklen_t socklen = sizeof (peeraddr);
4358 int data;
4359 unsigned int qxdm_data[6];
4360 const char *deactData[1] = {"1"};
4361 char *actData[1];
4362 RIL_Dial dialData;
4363 int hangupData[1] = {1};
4364 int number;
4365 char **args;
Etan Cohend3652192014-06-20 08:28:44 -07004366 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
4367 int sim_id = 0;
4368
4369 RLOGI("debugCallback for socket %s", rilSocketIdToString(socket_id));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004370
4371 acceptFD = accept (fd, (sockaddr *) &peeraddr, &socklen);
4372
4373 if (acceptFD < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004374 RLOGE ("error accepting on debug port: %d\n", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004375 return;
4376 }
4377
4378 if (recv(acceptFD, &number, sizeof(int), 0) != sizeof(int)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004379 RLOGE ("error reading on socket: number of Args: \n");
Sanket Padawe55227b52016-02-29 10:09:26 -08004380 close(acceptFD);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004381 return;
4382 }
Sanket Padawe55227b52016-02-29 10:09:26 -08004383
Sanket Padawe0cfc5532016-03-07 17:12:19 -08004384 if (number < 0) {
4385 RLOGE ("Invalid number of arguments: \n");
4386 close(acceptFD);
4387 return;
4388 }
4389
4390 args = (char **) calloc(number, sizeof(char*));
Sanket Padawe55227b52016-02-29 10:09:26 -08004391 if (args == NULL) {
4392 RLOGE("Memory allocation failed for debug args");
4393 close(acceptFD);
4394 return;
4395 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004396
4397 for (int i = 0; i < number; i++) {
4398 int len;
4399 if (recv(acceptFD, &len, sizeof(int), 0) != sizeof(int)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004400 RLOGE ("error reading on socket: Len of Args: \n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004401 freeDebugCallbackArgs(i, args);
Sanket Padawe55227b52016-02-29 10:09:26 -08004402 close(acceptFD);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004403 return;
4404 }
Sanket Padawe0cfc5532016-03-07 17:12:19 -08004405 if (len == INT_MAX || len < 0) {
4406 RLOGE("Invalid value of len: \n");
4407 freeDebugCallbackArgs(i, args);
4408 close(acceptFD);
4409 return;
4410 }
Sanket Padawe55227b52016-02-29 10:09:26 -08004411
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004412 // +1 for null-term
Sanket Padawe0cfc5532016-03-07 17:12:19 -08004413 args[i] = (char *) calloc(len + 1, sizeof(char));
Sanket Padawe55227b52016-02-29 10:09:26 -08004414 if (args[i] == NULL) {
4415 RLOGE("Memory allocation failed for debug args");
4416 freeDebugCallbackArgs(i, args);
4417 close(acceptFD);
4418 return;
4419 }
Wink Saville7f856802009-06-09 10:23:37 -07004420 if (recv(acceptFD, args[i], sizeof(char) * len, 0)
Wink Saville1b5fd232009-04-22 14:50:00 -07004421 != (int)sizeof(char) * len) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004422 RLOGE ("error reading on socket: Args[%d] \n", i);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004423 freeDebugCallbackArgs(i, args);
Sanket Padawe55227b52016-02-29 10:09:26 -08004424 close(acceptFD);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004425 return;
4426 }
4427 char * buf = args[i];
4428 buf[len] = 0;
Etan Cohend3652192014-06-20 08:28:44 -07004429 if ((i+1) == number) {
4430 /* The last argument should be sim id 0(SIM1)~3(SIM4) */
4431 sim_id = atoi(args[i]);
4432 switch (sim_id) {
4433 case 0:
4434 socket_id = RIL_SOCKET_1;
4435 break;
4436 #if (SIM_COUNT >= 2)
4437 case 1:
4438 socket_id = RIL_SOCKET_2;
4439 break;
4440 #endif
4441 #if (SIM_COUNT >= 3)
4442 case 2:
4443 socket_id = RIL_SOCKET_3;
4444 break;
4445 #endif
4446 #if (SIM_COUNT >= 4)
4447 case 3:
4448 socket_id = RIL_SOCKET_4;
4449 break;
4450 #endif
4451 default:
4452 socket_id = RIL_SOCKET_1;
4453 break;
4454 }
4455 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004456 }
4457
4458 switch (atoi(args[0])) {
4459 case 0:
Wink Saville8eb2a122012-11-19 16:05:13 -08004460 RLOGI ("Connection on debug port: issuing reset.");
Etan Cohend3652192014-06-20 08:28:44 -07004461 issueLocalRequest(RIL_REQUEST_RESET_RADIO, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004462 break;
4463 case 1:
Wink Saville8eb2a122012-11-19 16:05:13 -08004464 RLOGI ("Connection on debug port: issuing radio power off.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004465 data = 0;
Etan Cohend3652192014-06-20 08:28:44 -07004466 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004467 // Close the socket
Etan Cohend3652192014-06-20 08:28:44 -07004468 if (socket_id == RIL_SOCKET_1 && s_ril_param_socket.fdCommand > 0) {
4469 close(s_ril_param_socket.fdCommand);
4470 s_ril_param_socket.fdCommand = -1;
4471 }
4472 #if (SIM_COUNT == 2)
4473 else if (socket_id == RIL_SOCKET_2 && s_ril_param_socket2.fdCommand > 0) {
4474 close(s_ril_param_socket2.fdCommand);
4475 s_ril_param_socket2.fdCommand = -1;
4476 }
4477 #endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004478 break;
4479 case 2:
Wink Saville8eb2a122012-11-19 16:05:13 -08004480 RLOGI ("Debug port: issuing unsolicited voice network change.");
Etan Cohend3652192014-06-20 08:28:44 -07004481 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004482 break;
4483 case 3:
Wink Saville8eb2a122012-11-19 16:05:13 -08004484 RLOGI ("Debug port: QXDM log enable.");
Xia Wangd855ef42010-07-27 17:26:55 -07004485 qxdm_data[0] = 65536; // head.func_tag
4486 qxdm_data[1] = 16; // head.len
4487 qxdm_data[2] = 1; // mode: 1 for 'start logging'
4488 qxdm_data[3] = 32; // log_file_size: 32megabytes
4489 qxdm_data[4] = 0; // log_mask
4490 qxdm_data[5] = 8; // log_max_fileindex
Wink Saville7f856802009-06-09 10:23:37 -07004491 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Etan Cohend3652192014-06-20 08:28:44 -07004492 6 * sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004493 break;
4494 case 4:
Wink Saville8eb2a122012-11-19 16:05:13 -08004495 RLOGI ("Debug port: QXDM log disable.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004496 qxdm_data[0] = 65536;
4497 qxdm_data[1] = 16;
Xia Wangd855ef42010-07-27 17:26:55 -07004498 qxdm_data[2] = 0; // mode: 0 for 'stop logging'
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004499 qxdm_data[3] = 32;
4500 qxdm_data[4] = 0;
Xia Wangd855ef42010-07-27 17:26:55 -07004501 qxdm_data[5] = 8;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004502 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Etan Cohend3652192014-06-20 08:28:44 -07004503 6 * sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004504 break;
4505 case 5:
Wink Saville8eb2a122012-11-19 16:05:13 -08004506 RLOGI("Debug port: Radio On");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004507 data = 1;
Etan Cohend3652192014-06-20 08:28:44 -07004508 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004509 sleep(2);
4510 // Set network selection automatic.
Etan Cohend3652192014-06-20 08:28:44 -07004511 issueLocalRequest(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004512 break;
4513 case 6:
Wink Saville8eb2a122012-11-19 16:05:13 -08004514 RLOGI("Debug port: Setup Data Call, Apn :%s\n", args[1]);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004515 actData[0] = args[1];
Wink Saville7f856802009-06-09 10:23:37 -07004516 issueLocalRequest(RIL_REQUEST_SETUP_DATA_CALL, &actData,
Etan Cohend3652192014-06-20 08:28:44 -07004517 sizeof(actData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004518 break;
4519 case 7:
Wink Saville8eb2a122012-11-19 16:05:13 -08004520 RLOGI("Debug port: Deactivate Data Call");
Wink Saville7f856802009-06-09 10:23:37 -07004521 issueLocalRequest(RIL_REQUEST_DEACTIVATE_DATA_CALL, &deactData,
Etan Cohend3652192014-06-20 08:28:44 -07004522 sizeof(deactData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004523 break;
4524 case 8:
Wink Saville8eb2a122012-11-19 16:05:13 -08004525 RLOGI("Debug port: Dial Call");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004526 dialData.clir = 0;
4527 dialData.address = args[1];
Etan Cohend3652192014-06-20 08:28:44 -07004528 issueLocalRequest(RIL_REQUEST_DIAL, &dialData, sizeof(dialData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004529 break;
4530 case 9:
Wink Saville8eb2a122012-11-19 16:05:13 -08004531 RLOGI("Debug port: Answer Call");
Etan Cohend3652192014-06-20 08:28:44 -07004532 issueLocalRequest(RIL_REQUEST_ANSWER, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004533 break;
4534 case 10:
Wink Saville8eb2a122012-11-19 16:05:13 -08004535 RLOGI("Debug port: End Call");
Wink Saville7f856802009-06-09 10:23:37 -07004536 issueLocalRequest(RIL_REQUEST_HANGUP, &hangupData,
Etan Cohend3652192014-06-20 08:28:44 -07004537 sizeof(hangupData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004538 break;
4539 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004540 RLOGE ("Invalid request");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004541 break;
4542 }
4543 freeDebugCallbackArgs(number, args);
4544 close(acceptFD);
4545}
4546
4547
Wink Savillef4c4d362009-04-02 01:37:03 -07004548static void userTimerCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004549 UserCallbackInfo *p_info;
4550
4551 p_info = (UserCallbackInfo *)param;
4552
4553 p_info->p_callback(p_info->userParam);
4554
4555
4556 // FIXME generalize this...there should be a cancel mechanism
4557 if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) {
4558 s_last_wake_timeout_info = NULL;
4559 }
4560
4561 free(p_info);
4562}
4563
4564
4565static void *
Wink Savillef4c4d362009-04-02 01:37:03 -07004566eventLoop(void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004567 int ret;
4568 int filedes[2];
4569
4570 ril_event_init();
4571
4572 pthread_mutex_lock(&s_startupMutex);
4573
4574 s_started = 1;
4575 pthread_cond_broadcast(&s_startupCond);
4576
4577 pthread_mutex_unlock(&s_startupMutex);
4578
4579 ret = pipe(filedes);
4580
4581 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004582 RLOGE("Error in pipe() errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004583 return NULL;
4584 }
4585
4586 s_fdWakeupRead = filedes[0];
4587 s_fdWakeupWrite = filedes[1];
4588
4589 fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK);
4590
4591 ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,
4592 processWakeupCallback, NULL);
4593
4594 rilEventAddWakeup (&s_wakeupfd_event);
4595
4596 // Only returns on error
4597 ril_event_loop();
Wink Saville8eb2a122012-11-19 16:05:13 -08004598 RLOGE ("error in event_loop_base errno:%d", errno);
Kazuhiro Ondo5cdc1352011-10-14 17:50:58 -05004599 // kill self to restart on error
4600 kill(0, SIGKILL);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004601
4602 return NULL;
4603}
4604
Wink Saville7f856802009-06-09 10:23:37 -07004605extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07004606RIL_startEventLoop(void) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004607 /* spin up eventLoop thread and wait for it to get started */
4608 s_started = 0;
4609 pthread_mutex_lock(&s_startupMutex);
4610
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004611 pthread_attr_t attr;
4612 pthread_attr_init(&attr);
Wink Saville7f856802009-06-09 10:23:37 -07004613 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004614
Elliott Hughesfd81e712014-01-06 12:46:02 -08004615 int result = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
4616 if (result != 0) {
4617 RLOGE("Failed to create dispatch thread: %s", strerror(result));
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004618 goto done;
4619 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004620
4621 while (s_started == 0) {
4622 pthread_cond_wait(&s_startupCond, &s_startupMutex);
4623 }
4624
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004625done:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004626 pthread_mutex_unlock(&s_startupMutex);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004627}
4628
4629// Used for testing purpose only.
4630extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) {
4631 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4632}
4633
Etan Cohend3652192014-06-20 08:28:44 -07004634static void startListen(RIL_SOCKET_ID socket_id, SocketListenParam* socket_listen_p) {
4635 int fdListen = -1;
4636 int ret;
4637 char socket_name[10];
4638
4639 memset(socket_name, 0, sizeof(char)*10);
4640
4641 switch(socket_id) {
4642 case RIL_SOCKET_1:
4643 strncpy(socket_name, RIL_getRilSocketName(), 9);
4644 break;
4645 #if (SIM_COUNT >= 2)
4646 case RIL_SOCKET_2:
4647 strncpy(socket_name, SOCKET2_NAME_RIL, 9);
4648 break;
4649 #endif
4650 #if (SIM_COUNT >= 3)
4651 case RIL_SOCKET_3:
4652 strncpy(socket_name, SOCKET3_NAME_RIL, 9);
4653 break;
4654 #endif
4655 #if (SIM_COUNT >= 4)
4656 case RIL_SOCKET_4:
4657 strncpy(socket_name, SOCKET4_NAME_RIL, 9);
4658 break;
4659 #endif
4660 default:
4661 RLOGE("Socket id is wrong!!");
4662 return;
4663 }
4664
4665 RLOGI("Start to listen %s", rilSocketIdToString(socket_id));
4666
4667 fdListen = android_get_control_socket(socket_name);
4668 if (fdListen < 0) {
4669 RLOGE("Failed to get socket %s", socket_name);
4670 exit(-1);
4671 }
4672
4673 ret = listen(fdListen, 4);
4674
4675 if (ret < 0) {
4676 RLOGE("Failed to listen on control socket '%d': %s",
4677 fdListen, strerror(errno));
4678 exit(-1);
4679 }
4680 socket_listen_p->fdListen = fdListen;
4681
4682 /* note: non-persistent so we can accept only one connection at a time */
4683 ril_event_set (socket_listen_p->listen_event, fdListen, false,
4684 listenCallback, socket_listen_p);
4685
4686 rilEventAddWakeup (socket_listen_p->listen_event);
4687}
4688
Wink Saville7f856802009-06-09 10:23:37 -07004689extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07004690RIL_register (const RIL_RadioFunctions *callbacks) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004691 int ret;
4692 int flags;
4693
Etan Cohend3652192014-06-20 08:28:44 -07004694 RLOGI("SIM_COUNT: %d", SIM_COUNT);
4695
Wink Saville43808972011-01-13 17:39:51 -08004696 if (callbacks == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004697 RLOGE("RIL_register: RIL_RadioFunctions * null");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004698 return;
4699 }
Wink Saville43808972011-01-13 17:39:51 -08004700 if (callbacks->version < RIL_VERSION_MIN) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004701 RLOGE("RIL_register: version %d is to old, min version is %d",
Wink Saville43808972011-01-13 17:39:51 -08004702 callbacks->version, RIL_VERSION_MIN);
4703 return;
Wink Saville3a4840b2010-04-07 13:29:58 -07004704 }
Sanket Padawe4c05f352016-01-26 16:19:00 -08004705
Wink Saville8eb2a122012-11-19 16:05:13 -08004706 RLOGE("RIL_register: RIL version %d", callbacks->version);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004707
4708 if (s_registerCalled > 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004709 RLOGE("RIL_register has been called more than once. "
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004710 "Subsequent call ignored");
4711 return;
4712 }
4713
4714 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4715
Etan Cohend3652192014-06-20 08:28:44 -07004716 /* Initialize socket1 parameters */
4717 s_ril_param_socket = {
4718 RIL_SOCKET_1, /* socket_id */
4719 -1, /* fdListen */
4720 -1, /* fdCommand */
4721 PHONE_PROCESS, /* processName */
4722 &s_commands_event, /* commands_event */
4723 &s_listen_event, /* listen_event */
4724 processCommandsCallback, /* processCommandsCallback */
Meng Wangef966a32016-06-20 17:38:18 -07004725 NULL, /* p_rs */
4726 RIL_TELEPHONY_SOCKET /* type */
Etan Cohend3652192014-06-20 08:28:44 -07004727 };
4728
4729#if (SIM_COUNT >= 2)
4730 s_ril_param_socket2 = {
4731 RIL_SOCKET_2, /* socket_id */
4732 -1, /* fdListen */
4733 -1, /* fdCommand */
4734 PHONE_PROCESS, /* processName */
4735 &s_commands_event_socket2, /* commands_event */
4736 &s_listen_event_socket2, /* listen_event */
4737 processCommandsCallback, /* processCommandsCallback */
Meng Wangef966a32016-06-20 17:38:18 -07004738 NULL, /* p_rs */
4739 RIL_TELEPHONY_SOCKET /* type */
Etan Cohend3652192014-06-20 08:28:44 -07004740 };
4741#endif
4742
4743#if (SIM_COUNT >= 3)
4744 s_ril_param_socket3 = {
4745 RIL_SOCKET_3, /* socket_id */
4746 -1, /* fdListen */
4747 -1, /* fdCommand */
4748 PHONE_PROCESS, /* processName */
4749 &s_commands_event_socket3, /* commands_event */
4750 &s_listen_event_socket3, /* listen_event */
4751 processCommandsCallback, /* processCommandsCallback */
Meng Wangef966a32016-06-20 17:38:18 -07004752 NULL, /* p_rs */
4753 RIL_TELEPHONY_SOCKET /* type */
Etan Cohend3652192014-06-20 08:28:44 -07004754 };
4755#endif
4756
4757#if (SIM_COUNT >= 4)
4758 s_ril_param_socket4 = {
4759 RIL_SOCKET_4, /* socket_id */
4760 -1, /* fdListen */
4761 -1, /* fdCommand */
4762 PHONE_PROCESS, /* processName */
4763 &s_commands_event_socket4, /* commands_event */
4764 &s_listen_event_socket4, /* listen_event */
4765 processCommandsCallback, /* processCommandsCallback */
Meng Wangef966a32016-06-20 17:38:18 -07004766 NULL, /* p_rs */
4767 RIL_TELEPHONY_SOCKET /* type */
Etan Cohend3652192014-06-20 08:28:44 -07004768 };
4769#endif
4770
4771
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004772 s_registerCalled = 1;
4773
Etan Cohend3652192014-06-20 08:28:44 -07004774 RLOGI("s_registerCalled flag set, %d", s_started);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004775 // Little self-check
4776
Wink Savillef4c4d362009-04-02 01:37:03 -07004777 for (int i = 0; i < (int)NUM_ELEMS(s_commands); i++) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004778 assert(i == s_commands[i].requestNumber);
4779 }
4780
Wink Savillef4c4d362009-04-02 01:37:03 -07004781 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses); i++) {
Wink Saville7f856802009-06-09 10:23:37 -07004782 assert(i + RIL_UNSOL_RESPONSE_BASE
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004783 == s_unsolResponses[i].requestNumber);
4784 }
4785
4786 // New rild impl calls RIL_startEventLoop() first
4787 // old standalone impl wants it here.
4788
4789 if (s_started == 0) {
4790 RIL_startEventLoop();
4791 }
4792
Etan Cohend3652192014-06-20 08:28:44 -07004793 // start listen socket1
4794 startListen(RIL_SOCKET_1, &s_ril_param_socket);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004795
Etan Cohend3652192014-06-20 08:28:44 -07004796#if (SIM_COUNT >= 2)
4797 // start listen socket2
4798 startListen(RIL_SOCKET_2, &s_ril_param_socket2);
4799#endif /* (SIM_COUNT == 2) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004800
Etan Cohend3652192014-06-20 08:28:44 -07004801#if (SIM_COUNT >= 3)
4802 // start listen socket3
4803 startListen(RIL_SOCKET_3, &s_ril_param_socket3);
4804#endif /* (SIM_COUNT == 3) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004805
Etan Cohend3652192014-06-20 08:28:44 -07004806#if (SIM_COUNT >= 4)
4807 // start listen socket4
4808 startListen(RIL_SOCKET_4, &s_ril_param_socket4);
4809#endif /* (SIM_COUNT == 4) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004810
Amit Mahajan18fe36b2016-08-25 11:19:21 -07004811 RLOGI("RILHIDL calling registerService");
4812 radio::registerService(&s_callbacks, s_commands);
4813 RLOGI("RILHIDL called registerService");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004814
4815#if 1
4816 // start debug interface socket
4817
Etan Cohend3652192014-06-20 08:28:44 -07004818 char *inst = NULL;
4819 if (strlen(RIL_getRilSocketName()) >= strlen(SOCKET_NAME_RIL)) {
4820 inst = RIL_getRilSocketName() + strlen(SOCKET_NAME_RIL);
4821 }
4822
4823 char rildebug[MAX_DEBUG_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL_DEBUG;
4824 if (inst != NULL) {
Nick Kralevichc52e45e2015-02-08 07:54:16 -08004825 strlcat(rildebug, inst, MAX_DEBUG_SOCKET_NAME_LENGTH);
Etan Cohend3652192014-06-20 08:28:44 -07004826 }
4827
4828 s_fdDebug = android_get_control_socket(rildebug);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004829 if (s_fdDebug < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07004830 RLOGE("Failed to get socket : %s errno:%d", rildebug, errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004831 exit(-1);
4832 }
4833
4834 ret = listen(s_fdDebug, 4);
4835
4836 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004837 RLOGE("Failed to listen on ril debug socket '%d': %s",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004838 s_fdDebug, strerror(errno));
4839 exit(-1);
4840 }
4841
4842 ril_event_set (&s_debug_event, s_fdDebug, true,
4843 debugCallback, NULL);
4844
4845 rilEventAddWakeup (&s_debug_event);
4846#endif
4847
4848}
4849
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004850extern "C" void
Amit Mahajan18fe36b2016-08-25 11:19:21 -07004851RIL_register_socket (RIL_RadioFunctions *(*Init)(const struct RIL_Env *, int, char **),
4852 RIL_SOCKET_TYPE socketType, int argc, char **argv) {
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004853
4854 RIL_RadioFunctions* UimFuncs = NULL;
4855
4856 if(Init) {
4857 UimFuncs = Init(&RilSapSocket::uimRilEnv, argc, argv);
4858
4859 switch(socketType) {
4860 case RIL_SAP_SOCKET:
4861 RilSapSocket::initSapSocket("sap_uim_socket1", UimFuncs);
4862
4863#if (SIM_COUNT >= 2)
4864 RilSapSocket::initSapSocket("sap_uim_socket2", UimFuncs);
4865#endif
4866
4867#if (SIM_COUNT >= 3)
4868 RilSapSocket::initSapSocket("sap_uim_socket3", UimFuncs);
4869#endif
4870
4871#if (SIM_COUNT >= 4)
4872 RilSapSocket::initSapSocket("sap_uim_socket4", UimFuncs);
4873#endif
Meng Wangef966a32016-06-20 17:38:18 -07004874 break;
4875 default:;
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004876 }
Amit Mahajanc2c71852016-11-29 16:48:54 -08004877
4878 RLOGI("RIL_register_socket: calling registerService");
4879 sap::registerService(UimFuncs);
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004880 }
4881}
4882
Sanket Padawe6ff9a872016-01-27 15:09:12 -08004883// Check and remove RequestInfo if its a response and not just ack sent back
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004884static int
Sanket Padawe6ff9a872016-01-27 15:09:12 -08004885checkAndDequeueRequestInfoIfAck(struct RequestInfo *pRI, bool isAck) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004886 int ret = 0;
Etan Cohend3652192014-06-20 08:28:44 -07004887 /* Hook for current context
4888 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
4889 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
4890 /* pendingRequestsHook refer to &s_pendingRequests */
4891 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
Wink Saville7f856802009-06-09 10:23:37 -07004892
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004893 if (pRI == NULL) {
4894 return 0;
4895 }
4896
Etan Cohend3652192014-06-20 08:28:44 -07004897#if (SIM_COUNT >= 2)
4898 if (pRI->socket_id == RIL_SOCKET_2) {
4899 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
4900 pendingRequestsHook = &s_pendingRequests_socket2;
4901 }
4902#if (SIM_COUNT >= 3)
4903 if (pRI->socket_id == RIL_SOCKET_3) {
4904 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
4905 pendingRequestsHook = &s_pendingRequests_socket3;
4906 }
4907#endif
4908#if (SIM_COUNT >= 4)
4909 if (pRI->socket_id == RIL_SOCKET_4) {
4910 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
4911 pendingRequestsHook = &s_pendingRequests_socket4;
4912 }
4913#endif
4914#endif
4915 pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004916
Etan Cohend3652192014-06-20 08:28:44 -07004917 for(RequestInfo **ppCur = pendingRequestsHook
Wink Saville7f856802009-06-09 10:23:37 -07004918 ; *ppCur != NULL
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004919 ; ppCur = &((*ppCur)->p_next)
4920 ) {
4921 if (pRI == *ppCur) {
4922 ret = 1;
Sanket Padawe6ff9a872016-01-27 15:09:12 -08004923 if (isAck) { // Async ack
4924 if (pRI->wasAckSent == 1) {
4925 RLOGD("Ack was already sent for %s", requestToString(pRI->pCI->requestNumber));
4926 } else {
4927 pRI->wasAckSent = 1;
4928 }
4929 } else {
4930 *ppCur = (*ppCur)->p_next;
4931 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004932 break;
4933 }
4934 }
4935
Etan Cohend3652192014-06-20 08:28:44 -07004936 pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004937
4938 return ret;
4939}
4940
Sanket Padawe6ff9a872016-01-27 15:09:12 -08004941static int findFd(int socket_id) {
Etan Cohend3652192014-06-20 08:28:44 -07004942 int fd = s_ril_param_socket.fdCommand;
Etan Cohend3652192014-06-20 08:28:44 -07004943#if (SIM_COUNT >= 2)
4944 if (socket_id == RIL_SOCKET_2) {
4945 fd = s_ril_param_socket2.fdCommand;
4946 }
4947#if (SIM_COUNT >= 3)
Sanket Padawe6ff9a872016-01-27 15:09:12 -08004948 if (socket_id == RIL_SOCKET_3) {
4949 fd = s_ril_param_socket3.fdCommand;
4950 }
Etan Cohend3652192014-06-20 08:28:44 -07004951#endif
4952#if (SIM_COUNT >= 4)
4953 if (socket_id == RIL_SOCKET_4) {
4954 fd = s_ril_param_socket4.fdCommand;
4955 }
4956#endif
4957#endif
Sanket Padawe6ff9a872016-01-27 15:09:12 -08004958 return fd;
4959}
4960
4961extern "C" void
4962RIL_onRequestAck(RIL_Token t) {
4963 RequestInfo *pRI;
4964 int ret, fd;
4965
4966 size_t errorOffset;
4967 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
4968
4969 pRI = (RequestInfo *)t;
4970
4971 if (!checkAndDequeueRequestInfoIfAck(pRI, true)) {
4972 RLOGE ("RIL_onRequestAck: invalid RIL_Token");
4973 return;
4974 }
4975
4976 socket_id = pRI->socket_id;
4977 fd = findFd(socket_id);
4978
4979#if VDBG
4980 RLOGD("Request Ack, %s", rilSocketIdToString(socket_id));
4981#endif
4982
4983 appendPrintBuf("Ack [%04d]< %s", pRI->token, requestToString(pRI->pCI->requestNumber));
4984
4985 if (pRI->cancelled == 0) {
4986 Parcel p;
4987
4988 p.writeInt32 (RESPONSE_SOLICITED_ACK);
4989 p.writeInt32 (pRI->token);
4990
4991 if (fd < 0) {
4992 RLOGD ("RIL onRequestComplete: Command channel closed");
4993 }
4994
4995 sendResponse(p, socket_id);
4996 }
4997}
Sanket Padawe6ff9a872016-01-27 15:09:12 -08004998extern "C" void
4999RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) {
5000 RequestInfo *pRI;
5001 int ret;
5002 int fd;
5003 size_t errorOffset;
5004 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
5005
5006 pRI = (RequestInfo *)t;
5007
5008 if (!checkAndDequeueRequestInfoIfAck(pRI, false)) {
5009 RLOGE ("RIL_onRequestComplete: invalid RIL_Token");
5010 return;
5011 }
5012
5013 socket_id = pRI->socket_id;
5014 fd = findFd(socket_id);
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07005015#if VDBG
Etan Cohend3652192014-06-20 08:28:44 -07005016 RLOGD("RequestComplete, %s", rilSocketIdToString(socket_id));
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07005017#endif
Etan Cohend3652192014-06-20 08:28:44 -07005018
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005019 if (pRI->local > 0) {
5020 // Locally issued command...void only!
5021 // response does not go back up the command socket
Wink Saville8eb2a122012-11-19 16:05:13 -08005022 RLOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005023
5024 goto done;
5025 }
5026
5027 appendPrintBuf("[%04d]< %s",
5028 pRI->token, requestToString(pRI->pCI->requestNumber));
5029
5030 if (pRI->cancelled == 0) {
5031 Parcel p;
5032
Amit Mahajan18fe36b2016-08-25 11:19:21 -07005033 int responseType;
Sanket Padawe6ff9a872016-01-27 15:09:12 -08005034 if (s_callbacks.version >= 13 && pRI->wasAckSent == 1) {
5035 // If ack was already sent, then this call is an asynchronous response. So we need to
5036 // send id indicating that we expect an ack from RIL.java as we acquire wakelock here.
Amit Mahajan18fe36b2016-08-25 11:19:21 -07005037 responseType = RESPONSE_SOLICITED_ACK_EXP;
Sanket Padawe6ff9a872016-01-27 15:09:12 -08005038 grabPartialWakeLock();
5039 } else {
Amit Mahajan18fe36b2016-08-25 11:19:21 -07005040 responseType = RESPONSE_SOLICITED;
Sanket Padawe6ff9a872016-01-27 15:09:12 -08005041 }
Amit Mahajan18fe36b2016-08-25 11:19:21 -07005042 p.writeInt32 (responseType);
5043
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005044 p.writeInt32 (pRI->token);
5045 errorOffset = p.dataPosition();
5046
5047 p.writeInt32 (e);
5048
johnwangb2a61842009-06-02 14:55:45 -07005049 if (response != NULL) {
5050 // there is a response payload, no matter success or not.
Amit Mahajan18fe36b2016-08-25 11:19:21 -07005051 RLOGE ("Calling responseFunction() for token %d", pRI->token);
5052 ret = pRI->pCI->responseFunction(p, (int) socket_id, pRI->pCI->requestNumber,
5053 responseType, pRI->token, e, response, responselen);
5054
5055 if (pRI->pCI->requestNumber == RIL_REQUEST_GET_SIM_STATUS) {
5056 return;
5057 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005058
5059 /* if an error occurred, rewind and mark it */
5060 if (ret != 0) {
Etan Cohend3652192014-06-20 08:28:44 -07005061 RLOGE ("responseFunction error, ret %d", ret);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005062 p.setDataPosition(errorOffset);
5063 p.writeInt32 (ret);
5064 }
johnwangb2a61842009-06-02 14:55:45 -07005065 }
5066
5067 if (e != RIL_E_SUCCESS) {
5068 appendPrintBuf("%s fails by %s", printBuf, failCauseToString(e));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005069 }
5070
Etan Cohend3652192014-06-20 08:28:44 -07005071 if (fd < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08005072 RLOGD ("RIL onRequestComplete: Command channel closed");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005073 }
Etan Cohend3652192014-06-20 08:28:44 -07005074 sendResponse(p, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005075 }
5076
5077done:
5078 free(pRI);
5079}
5080
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005081static void
Wink Savillef4c4d362009-04-02 01:37:03 -07005082grabPartialWakeLock() {
Sanket Padawe6ff9a872016-01-27 15:09:12 -08005083 if (s_callbacks.version >= 13) {
5084 int ret;
5085 ret = pthread_mutex_lock(&s_wakeLockCountMutex);
5086 assert(ret == 0);
5087 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
Sanket Padawe55227b52016-02-29 10:09:26 -08005088
5089 UserCallbackInfo *p_info =
5090 internalRequestTimedCallback(wakeTimeoutCallback, NULL, &TIMEVAL_WAKE_TIMEOUT);
5091 if (p_info == NULL) {
5092 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
5093 } else {
5094 s_wakelock_count++;
5095 if (s_last_wake_timeout_info != NULL) {
5096 s_last_wake_timeout_info->userParam = (void *)1;
5097 }
5098 s_last_wake_timeout_info = p_info;
Sanket Padawe6ff9a872016-01-27 15:09:12 -08005099 }
Sanket Padawe6ff9a872016-01-27 15:09:12 -08005100 ret = pthread_mutex_unlock(&s_wakeLockCountMutex);
5101 assert(ret == 0);
5102 } else {
5103 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
5104 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005105}
5106
5107static void
Wink Savillef4c4d362009-04-02 01:37:03 -07005108releaseWakeLock() {
Sanket Padawe6ff9a872016-01-27 15:09:12 -08005109 if (s_callbacks.version >= 13) {
5110 int ret;
5111 ret = pthread_mutex_lock(&s_wakeLockCountMutex);
5112 assert(ret == 0);
5113
5114 if (s_wakelock_count > 1) {
5115 s_wakelock_count--;
5116 } else {
5117 s_wakelock_count = 0;
5118 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
5119 if (s_last_wake_timeout_info != NULL) {
5120 s_last_wake_timeout_info->userParam = (void *)1;
5121 }
5122 }
5123
5124 ret = pthread_mutex_unlock(&s_wakeLockCountMutex);
5125 assert(ret == 0);
5126 } else {
5127 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
5128 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005129}
5130
5131/**
5132 * Timer callback to put us back to sleep before the default timeout
5133 */
5134static void
Wink Savillef4c4d362009-04-02 01:37:03 -07005135wakeTimeoutCallback (void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005136 // We're using "param != NULL" as a cancellation mechanism
Sanket Padawe6ff9a872016-01-27 15:09:12 -08005137 if (s_callbacks.version >= 13) {
5138 if (param == NULL) {
5139 int ret;
5140 ret = pthread_mutex_lock(&s_wakeLockCountMutex);
5141 assert(ret == 0);
5142 s_wakelock_count = 0;
5143 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
5144 ret = pthread_mutex_unlock(&s_wakeLockCountMutex);
5145 assert(ret == 0);
5146 }
5147 } else {
5148 if (param == NULL) {
5149 releaseWakeLock();
5150 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005151 }
5152}
5153
Etan Cohend3652192014-06-20 08:28:44 -07005154#if defined(ANDROID_MULTI_SIM)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005155extern "C"
Bernhard Rosenkränzerd613b962014-11-17 20:52:09 +01005156void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Etan Cohend3652192014-06-20 08:28:44 -07005157 size_t datalen, RIL_SOCKET_ID socket_id)
5158#else
5159extern "C"
Bernhard Rosenkränzerd613b962014-11-17 20:52:09 +01005160void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005161 size_t datalen)
Etan Cohend3652192014-06-20 08:28:44 -07005162#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005163{
5164 int unsolResponseIndex;
5165 int ret;
5166 int64_t timeReceived = 0;
5167 bool shouldScheduleTimeout = false;
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005168 RIL_RadioState newState;
Etan Cohend3652192014-06-20 08:28:44 -07005169 RIL_SOCKET_ID soc_id = RIL_SOCKET_1;
5170
5171#if defined(ANDROID_MULTI_SIM)
5172 soc_id = socket_id;
5173#endif
5174
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005175
5176 if (s_registerCalled == 0) {
5177 // Ignore RIL_onUnsolicitedResponse before RIL_register
Wink Saville8eb2a122012-11-19 16:05:13 -08005178 RLOGW("RIL_onUnsolicitedResponse called before RIL_register");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005179 return;
5180 }
Wink Saville7f856802009-06-09 10:23:37 -07005181
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005182 unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
5183
5184 if ((unsolResponseIndex < 0)
5185 || (unsolResponseIndex >= (int32_t)NUM_ELEMS(s_unsolResponses))) {
Wink Saville8eb2a122012-11-19 16:05:13 -08005186 RLOGE("unsupported unsolicited response code %d", unsolResponse);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005187 return;
5188 }
5189
5190 // Grab a wake lock if needed for this reponse,
5191 // as we exit we'll either release it immediately
5192 // or set a timer to release it later.
5193 switch (s_unsolResponses[unsolResponseIndex].wakeType) {
5194 case WAKE_PARTIAL:
5195 grabPartialWakeLock();
5196 shouldScheduleTimeout = true;
5197 break;
5198
5199 case DONT_WAKE:
5200 default:
5201 // No wake lock is grabed so don't set timeout
5202 shouldScheduleTimeout = false;
5203 break;
5204 }
5205
5206 // Mark the time this was received, doing this
5207 // after grabing the wakelock incase getting
5208 // the elapsedRealTime might cause us to goto
5209 // sleep.
5210 if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
5211 timeReceived = elapsedRealtime();
5212 }
5213
5214 appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
5215
5216 Parcel p;
Amit Mahajan18fe36b2016-08-25 11:19:21 -07005217 int responseType;
Sanket Padawed8c0b462016-02-03 11:46:02 -08005218 if (s_callbacks.version >= 13
5219 && s_unsolResponses[unsolResponseIndex].wakeType == WAKE_PARTIAL) {
Amit Mahajan18fe36b2016-08-25 11:19:21 -07005220 responseType = RESPONSE_UNSOLICITED_ACK_EXP;
Sanket Padawed8c0b462016-02-03 11:46:02 -08005221 } else {
Amit Mahajan18fe36b2016-08-25 11:19:21 -07005222 responseType = RESPONSE_UNSOLICITED;
Sanket Padawed8c0b462016-02-03 11:46:02 -08005223 }
Amit Mahajan18fe36b2016-08-25 11:19:21 -07005224 p.writeInt32 (responseType);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005225 p.writeInt32 (unsolResponse);
5226
Amit Mahajan18fe36b2016-08-25 11:19:21 -07005227 ret = s_unsolResponses[unsolResponseIndex].responseFunction(
5228 p, (int) soc_id, unsolResponse, responseType, 0, RIL_E_SUCCESS, const_cast<void*>(data),
5229 datalen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005230 if (ret != 0) {
5231 // Problem with the response. Don't continue;
5232 goto error_exit;
5233 }
5234
5235 // some things get more payload
5236 switch(unsolResponse) {
5237 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
Naveen Kalla2baf7232016-10-11 13:49:20 -07005238 newState = CALL_ONSTATEREQUEST(soc_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005239 p.writeInt32(newState);
Naveen Kalla2baf7232016-10-11 13:49:20 -07005240 appendPrintBuf("%s {%s}", printBuf, radioStateToString(newState));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005241 break;
5242
5243
5244 case RIL_UNSOL_NITZ_TIME_RECEIVED:
5245 // Store the time that this was received so the
5246 // handler of this message can account for
5247 // the time it takes to arrive and process. In
5248 // particular the system has been known to sleep
5249 // before this message can be processed.
5250 p.writeInt64(timeReceived);
5251 break;
5252 }
5253
Sanket Padawe55227b52016-02-29 10:09:26 -08005254 if (s_callbacks.version < 13) {
5255 if (shouldScheduleTimeout) {
5256 UserCallbackInfo *p_info = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
5257 &TIMEVAL_WAKE_TIMEOUT);
5258
5259 if (p_info == NULL) {
5260 goto error_exit;
5261 } else {
5262 // Cancel the previous request
5263 if (s_last_wake_timeout_info != NULL) {
5264 s_last_wake_timeout_info->userParam = (void *)1;
5265 }
5266 s_last_wake_timeout_info = p_info;
5267 }
5268 }
5269 }
5270
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07005271#if VDBG
Amit Mahajan18fe36b2016-08-25 11:19:21 -07005272 RLOGI("%s UNSOLICITED: %s length:%d", rilSocketIdToString(soc_id),
5273 requestToString(unsolResponse), p.dataSize());
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07005274#endif
Amit Mahajan18fe36b2016-08-25 11:19:21 -07005275 ret = 0;
5276 switch (unsolResponse) {
5277 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
5278 radio::radioStateChanged(soc_id, responseType, newState);
5279 break;
5280 default:
5281 ret = sendResponse(p, soc_id);
5282 break;
5283 }
5284
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005285 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
5286
5287 // Unfortunately, NITZ time is not poll/update like everything
5288 // else in the system. So, if the upstream client isn't connected,
5289 // keep a copy of the last NITZ response (with receive time noted
5290 // above) around so we can deliver it when it is connected
5291
5292 if (s_lastNITZTimeData != NULL) {
5293 free (s_lastNITZTimeData);
5294 s_lastNITZTimeData = NULL;
5295 }
5296
Sanket Padawe0cfc5532016-03-07 17:12:19 -08005297 s_lastNITZTimeData = calloc(p.dataSize(), 1);
Sanket Padawe55227b52016-02-29 10:09:26 -08005298 if (s_lastNITZTimeData == NULL) {
5299 RLOGE("Memory allocation failed in RIL_onUnsolicitedResponse");
5300 goto error_exit;
5301 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005302 s_lastNITZTimeDataSize = p.dataSize();
5303 memcpy(s_lastNITZTimeData, p.data(), p.dataSize());
5304 }
5305
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005306 // Normal exit
5307 return;
5308
5309error_exit:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005310 if (shouldScheduleTimeout) {
5311 releaseWakeLock();
5312 }
5313}
5314
Wink Saville7f856802009-06-09 10:23:37 -07005315/** FIXME generalize this if you track UserCAllbackInfo, clear it
5316 when the callback occurs
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005317*/
5318static UserCallbackInfo *
Wink Saville7f856802009-06-09 10:23:37 -07005319internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07005320 const struct timeval *relativeTime)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005321{
5322 struct timeval myRelativeTime;
5323 UserCallbackInfo *p_info;
5324
Sanket Padawe0cfc5532016-03-07 17:12:19 -08005325 p_info = (UserCallbackInfo *) calloc(1, sizeof(UserCallbackInfo));
Sanket Padawe55227b52016-02-29 10:09:26 -08005326 if (p_info == NULL) {
5327 RLOGE("Memory allocation failed in internalRequestTimedCallback");
5328 return p_info;
5329
5330 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005331
Wink Saville7f856802009-06-09 10:23:37 -07005332 p_info->p_callback = callback;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005333 p_info->userParam = param;
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07005334
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005335 if (relativeTime == NULL) {
5336 /* treat null parameter as a 0 relative time */
5337 memset (&myRelativeTime, 0, sizeof(myRelativeTime));
5338 } else {
5339 /* FIXME I think event_add's tv param is really const anyway */
5340 memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
5341 }
5342
5343 ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
5344
5345 ril_timer_add(&(p_info->event), &myRelativeTime);
5346
5347 triggerEvLoop();
5348 return p_info;
5349}
5350
Naveen Kalla7edd07c2010-06-21 18:54:47 -07005351
5352extern "C" void
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07005353RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
5354 const struct timeval *relativeTime) {
5355 internalRequestTimedCallback (callback, param, relativeTime);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005356}
5357
5358const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07005359failCauseToString(RIL_Errno e) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005360 switch(e) {
5361 case RIL_E_SUCCESS: return "E_SUCCESS";
Robert Greenwalt2126ab22013-04-09 12:20:45 -07005362 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RADIO_NOT_AVAILABLE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005363 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
5364 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
5365 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
5366 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
5367 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
5368 case RIL_E_CANCELLED: return "E_CANCELLED";
5369 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
5370 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
5371 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
Wink Savillef4c4d362009-04-02 01:37:03 -07005372 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
John Wang75534472010-04-20 15:11:42 -07005373 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
Wink Saville7f856802009-06-09 10:23:37 -07005374#ifdef FEATURE_MULTIMODE_ANDROID
Wink Savillef4c4d362009-04-02 01:37:03 -07005375 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
5376 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
5377#endif
Sanket Padaweb39e5c92016-02-08 14:28:59 -08005378 case RIL_E_FDN_CHECK_FAILURE: return "E_FDN_CHECK_FAILURE";
5379 case RIL_E_MISSING_RESOURCE: return "E_MISSING_RESOURCE";
5380 case RIL_E_NO_SUCH_ELEMENT: return "E_NO_SUCH_ELEMENT";
5381 case RIL_E_DIAL_MODIFIED_TO_USSD: return "E_DIAL_MODIFIED_TO_USSD";
5382 case RIL_E_DIAL_MODIFIED_TO_SS: return "E_DIAL_MODIFIED_TO_SS";
5383 case RIL_E_DIAL_MODIFIED_TO_DIAL: return "E_DIAL_MODIFIED_TO_DIAL";
5384 case RIL_E_USSD_MODIFIED_TO_DIAL: return "E_USSD_MODIFIED_TO_DIAL";
5385 case RIL_E_USSD_MODIFIED_TO_SS: return "E_USSD_MODIFIED_TO_SS";
5386 case RIL_E_USSD_MODIFIED_TO_USSD: return "E_USSD_MODIFIED_TO_USSD";
5387 case RIL_E_SS_MODIFIED_TO_DIAL: return "E_SS_MODIFIED_TO_DIAL";
5388 case RIL_E_SS_MODIFIED_TO_USSD: return "E_SS_MODIFIED_TO_USSD";
5389 case RIL_E_SUBSCRIPTION_NOT_SUPPORTED: return "E_SUBSCRIPTION_NOT_SUPPORTED";
5390 case RIL_E_SS_MODIFIED_TO_SS: return "E_SS_MODIFIED_TO_SS";
5391 case RIL_E_LCE_NOT_SUPPORTED: return "E_LCE_NOT_SUPPORTED";
5392 case RIL_E_NO_MEMORY: return "E_NO_MEMORY";
5393 case RIL_E_INTERNAL_ERR: return "E_INTERNAL_ERR";
5394 case RIL_E_SYSTEM_ERR: return "E_SYSTEM_ERR";
5395 case RIL_E_MODEM_ERR: return "E_MODEM_ERR";
5396 case RIL_E_INVALID_STATE: return "E_INVALID_STATE";
5397 case RIL_E_NO_RESOURCES: return "E_NO_RESOURCES";
5398 case RIL_E_SIM_ERR: return "E_SIM_ERR";
5399 case RIL_E_INVALID_ARGUMENTS: return "E_INVALID_ARGUMENTS";
5400 case RIL_E_INVALID_SIM_STATE: return "E_INVALID_SIM_STATE";
5401 case RIL_E_INVALID_MODEM_STATE: return "E_INVALID_MODEM_STATE";
5402 case RIL_E_INVALID_CALL_ID: return "E_INVALID_CALL_ID";
5403 case RIL_E_NO_SMS_TO_ACK: return "E_NO_SMS_TO_ACK";
5404 case RIL_E_NETWORK_ERR: return "E_NETWORK_ERR";
5405 case RIL_E_REQUEST_RATE_LIMITED: return "E_REQUEST_RATE_LIMITED";
twen.changdf7add02016-03-04 18:27:48 +08005406 case RIL_E_SIM_BUSY: return "E_SIM_BUSY";
5407 case RIL_E_SIM_FULL: return "E_SIM_FULL";
5408 case RIL_E_NETWORK_REJECT: return "E_NETWORK_REJECT";
5409 case RIL_E_OPERATION_NOT_ALLOWED: return "E_OPERATION_NOT_ALLOWED";
5410 case RIL_E_EMPTY_RECORD: "E_EMPTY_RECORD";
Ajay Nambi68900f52016-03-11 12:02:55 -08005411 case RIL_E_INVALID_SMS_FORMAT: return "E_INVALID_SMS_FORMAT";
5412 case RIL_E_ENCODING_ERR: return "E_ENCODING_ERR";
5413 case RIL_E_INVALID_SMSC_ADDRESS: return "E_INVALID_SMSC_ADDRESS";
5414 case RIL_E_NO_SUCH_ENTRY: return "E_NO_SUCH_ENTRY";
5415 case RIL_E_NETWORK_NOT_READY: return "E_NETWORK_NOT_READY";
5416 case RIL_E_NOT_PROVISIONED: return "E_NOT_PROVISIONED";
Ajay Nambi10345892016-03-19 09:02:28 -07005417 case RIL_E_NO_SUBSCRIPTION: return "E_NO_SUBSCRIPTION";
5418 case RIL_E_NO_NETWORK_FOUND: return "E_NO_NETWORK_FOUND";
5419 case RIL_E_DEVICE_IN_USE: return "E_DEVICE_IN_USE";
5420 case RIL_E_ABORTED: return "E_ABORTED";
Sanket Padawe0106aed2016-02-09 09:56:31 -08005421 case RIL_E_OEM_ERROR_1: return "E_OEM_ERROR_1";
5422 case RIL_E_OEM_ERROR_2: return "E_OEM_ERROR_2";
5423 case RIL_E_OEM_ERROR_3: return "E_OEM_ERROR_3";
5424 case RIL_E_OEM_ERROR_4: return "E_OEM_ERROR_4";
5425 case RIL_E_OEM_ERROR_5: return "E_OEM_ERROR_5";
5426 case RIL_E_OEM_ERROR_6: return "E_OEM_ERROR_6";
5427 case RIL_E_OEM_ERROR_7: return "E_OEM_ERROR_7";
5428 case RIL_E_OEM_ERROR_8: return "E_OEM_ERROR_8";
5429 case RIL_E_OEM_ERROR_9: return "E_OEM_ERROR_9";
5430 case RIL_E_OEM_ERROR_10: return "E_OEM_ERROR_10";
5431 case RIL_E_OEM_ERROR_11: return "E_OEM_ERROR_11";
5432 case RIL_E_OEM_ERROR_12: return "E_OEM_ERROR_12";
5433 case RIL_E_OEM_ERROR_13: return "E_OEM_ERROR_13";
5434 case RIL_E_OEM_ERROR_14: return "E_OEM_ERROR_14";
5435 case RIL_E_OEM_ERROR_15: return "E_OEM_ERROR_15";
5436 case RIL_E_OEM_ERROR_16: return "E_OEM_ERROR_16";
5437 case RIL_E_OEM_ERROR_17: return "E_OEM_ERROR_17";
5438 case RIL_E_OEM_ERROR_18: return "E_OEM_ERROR_18";
5439 case RIL_E_OEM_ERROR_19: return "E_OEM_ERROR_19";
5440 case RIL_E_OEM_ERROR_20: return "E_OEM_ERROR_20";
5441 case RIL_E_OEM_ERROR_21: return "E_OEM_ERROR_21";
5442 case RIL_E_OEM_ERROR_22: return "E_OEM_ERROR_22";
5443 case RIL_E_OEM_ERROR_23: return "E_OEM_ERROR_23";
5444 case RIL_E_OEM_ERROR_24: return "E_OEM_ERROR_24";
5445 case RIL_E_OEM_ERROR_25: return "E_OEM_ERROR_25";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005446 default: return "<unknown error>";
5447 }
5448}
5449
5450const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07005451radioStateToString(RIL_RadioState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005452 switch(s) {
5453 case RADIO_STATE_OFF: return "RADIO_OFF";
5454 case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005455 case RADIO_STATE_ON:return"RADIO_ON";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005456 default: return "<unknown state>";
5457 }
5458}
5459
5460const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07005461callStateToString(RIL_CallState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005462 switch(s) {
5463 case RIL_CALL_ACTIVE : return "ACTIVE";
5464 case RIL_CALL_HOLDING: return "HOLDING";
5465 case RIL_CALL_DIALING: return "DIALING";
5466 case RIL_CALL_ALERTING: return "ALERTING";
5467 case RIL_CALL_INCOMING: return "INCOMING";
5468 case RIL_CALL_WAITING: return "WAITING";
5469 default: return "<unknown state>";
5470 }
5471}
5472
5473const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07005474requestToString(int request) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005475/*
5476 cat libs/telephony/ril_commands.h \
5477 | egrep "^ *{RIL_" \
5478 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
5479
5480
5481 cat libs/telephony/ril_unsol_commands.h \
5482 | egrep "^ *{RIL_" \
5483 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
5484
5485*/
5486 switch(request) {
5487 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
5488 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
5489 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
5490 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
5491 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
5492 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
5493 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
5494 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
5495 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
5496 case RIL_REQUEST_DIAL: return "DIAL";
5497 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
5498 case RIL_REQUEST_HANGUP: return "HANGUP";
5499 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
5500 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
5501 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
5502 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
5503 case RIL_REQUEST_UDUB: return "UDUB";
5504 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
5505 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
Wink Savillec0114b32011-02-18 10:14:07 -08005506 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
5507 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005508 case RIL_REQUEST_OPERATOR: return "OPERATOR";
5509 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
5510 case RIL_REQUEST_DTMF: return "DTMF";
5511 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
5512 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
Wink Savillef4c4d362009-04-02 01:37:03 -07005513 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005514 case RIL_REQUEST_SIM_IO: return "SIM_IO";
5515 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
5516 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
5517 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
5518 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
5519 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
5520 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
5521 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
5522 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
5523 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
5524 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
5525 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
5526 case RIL_REQUEST_ANSWER: return "ANSWER";
Wink Savillef4c4d362009-04-02 01:37:03 -07005527 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005528 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
5529 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
5530 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
5531 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
5532 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
5533 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
Matt Mower897915e2015-04-08 23:16:03 -05005534 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS: return "QUERY_AVAILABLE_NETWORKS";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005535 case RIL_REQUEST_DTMF_START: return "DTMF_START";
5536 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
5537 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
5538 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005539 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
5540 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
5541 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
Wink Savillef4c4d362009-04-02 01:37:03 -07005542 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
5543 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005544 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
5545 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
5546 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
Matt Mower897915e2015-04-08 23:16:03 -05005547 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
5548 case RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION: return "SET_SUPP_SVC_NOTIFICATION";
5549 case RIL_REQUEST_WRITE_SMS_TO_SIM: return "WRITE_SMS_TO_SIM";
5550 case RIL_REQUEST_DELETE_SMS_ON_SIM: return "DELETE_SMS_ON_SIM";
Wink Savillef4c4d362009-04-02 01:37:03 -07005551 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
5552 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005553 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
5554 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
5555 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
5556 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
5557 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 -08005558 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
Matt Mower897915e2015-04-08 23:16:03 -05005559 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
5560 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
5561 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005562 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
Matt Mower897915e2015-04-08 23:16:03 -05005563 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE: return "CDMA_SET_SUBSCRIPTION_SOURCE";
5564 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE: return "CDMA_SET_ROAMING_PREFERENCE";
5565 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE: return "CDMA_QUERY_ROAMING_PREFERENCE";
5566 case RIL_REQUEST_SET_TTY_MODE: return "SET_TTY_MODE";
5567 case RIL_REQUEST_QUERY_TTY_MODE: return "QUERY_TTY_MODE";
5568 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE: return "CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
5569 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE: return "CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
5570 case RIL_REQUEST_CDMA_FLASH: return "CDMA_FLASH";
5571 case RIL_REQUEST_CDMA_BURST_DTMF: return "CDMA_BURST_DTMF";
5572 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return "CDMA_VALIDATE_AND_WRITE_AKEY";
5573 case RIL_REQUEST_CDMA_SEND_SMS: return "CDMA_SEND_SMS";
5574 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE: return "CDMA_SMS_ACKNOWLEDGE";
5575 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG: return "GSM_GET_BROADCAST_SMS_CONFIG";
5576 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG: return "GSM_SET_BROADCAST_SMS_CONFIG";
5577 case RIL_REQUEST_GSM_SMS_BROADCAST_ACTIVATION: return "GSM_SMS_BROADCAST_ACTIVATION";
5578 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG: return "CDMA_GET_BROADCAST_SMS_CONFIG";
5579 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG: return "CDMA_SET_BROADCAST_SMS_CONFIG";
5580 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION: return "CDMA_SMS_BROADCAST_ACTIVATION";
5581 case RIL_REQUEST_CDMA_SUBSCRIPTION: return "CDMA_SUBSCRIPTION";
Wink Savillef4c4d362009-04-02 01:37:03 -07005582 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
5583 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
5584 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
jsh000a9fe2009-05-11 14:52:35 -07005585 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
5586 case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
5587 case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
jsh09a68ba2009-06-10 11:56:38 -07005588 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
jsh563fd722010-06-08 16:52:24 -07005589 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
Wink Savillec0114b32011-02-18 10:14:07 -08005590 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
Jake Hambyfa8d5842011-08-19 16:22:18 -07005591 case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
Matt Mower897915e2015-04-08 23:16:03 -05005592 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
5593 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "STK_SEND_ENVELOPE_WITH_STATUS";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005594 case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
Matt Mower897915e2015-04-08 23:16:03 -05005595 case RIL_REQUEST_GET_CELL_INFO_LIST: return "GET_CELL_INFO_LIST";
5596 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return "SET_UNSOL_CELL_INFO_LIST_RATE";
5597 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "SET_INITIAL_ATTACH_APN";
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07005598 case RIL_REQUEST_IMS_REGISTRATION_STATE: return "IMS_REGISTRATION_STATE";
5599 case RIL_REQUEST_IMS_SEND_SMS: return "IMS_SEND_SMS";
Shishir Agrawal2458d8d2013-11-27 14:53:05 -08005600 case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "SIM_TRANSMIT_APDU_BASIC";
5601 case RIL_REQUEST_SIM_OPEN_CHANNEL: return "SIM_OPEN_CHANNEL";
5602 case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "SIM_CLOSE_CHANNEL";
5603 case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "SIM_TRANSMIT_APDU_CHANNEL";
Matt Mower897915e2015-04-08 23:16:03 -05005604 case RIL_REQUEST_NV_READ_ITEM: return "NV_READ_ITEM";
5605 case RIL_REQUEST_NV_WRITE_ITEM: return "NV_WRITE_ITEM";
5606 case RIL_REQUEST_NV_WRITE_CDMA_PRL: return "NV_WRITE_CDMA_PRL";
5607 case RIL_REQUEST_NV_RESET_CONFIG: return "NV_RESET_CONFIG";
Etan Cohend3652192014-06-20 08:28:44 -07005608 case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "SET_UICC_SUBSCRIPTION";
5609 case RIL_REQUEST_ALLOW_DATA: return "ALLOW_DATA";
Amit Mahajan2b772032014-06-26 14:20:11 -07005610 case RIL_REQUEST_GET_HARDWARE_CONFIG: return "GET_HARDWARE_CONFIG";
5611 case RIL_REQUEST_SIM_AUTHENTICATION: return "SIM_AUTHENTICATION";
Wink Savillec29360a2014-07-13 05:17:28 -07005612 case RIL_REQUEST_GET_DC_RT_INFO: return "GET_DC_RT_INFO";
5613 case RIL_REQUEST_SET_DC_RT_INFO_RATE: return "SET_DC_RT_INFO_RATE";
Amit Mahajanc796e222014-08-13 16:54:01 +00005614 case RIL_REQUEST_SET_DATA_PROFILE: return "SET_DATA_PROFILE";
Matt Mower897915e2015-04-08 23:16:03 -05005615 case RIL_REQUEST_SHUTDOWN: return "SHUTDOWN";
5616 case RIL_REQUEST_GET_RADIO_CAPABILITY: return "GET_RADIO_CAPABILITY";
5617 case RIL_REQUEST_SET_RADIO_CAPABILITY: return "SET_RADIO_CAPABILITY";
5618 case RIL_REQUEST_START_LCE: return "START_LCE";
5619 case RIL_REQUEST_STOP_LCE: return "STOP_LCE";
5620 case RIL_REQUEST_PULL_LCEDATA: return "PULL_LCEDATA";
5621 case RIL_REQUEST_GET_ACTIVITY_INFO: return "GET_ACTIVITY_INFO";
Meng Wangb4e34312016-05-12 14:54:36 -07005622 case RIL_REQUEST_SET_CARRIER_RESTRICTIONS: return "SET_CARRIER_RESTRICTIONS";
5623 case RIL_REQUEST_GET_CARRIER_RESTRICTIONS: return "GET_CARRIER_RESTRICTIONS";
Matt Mower897915e2015-04-08 23:16:03 -05005624 case RIL_RESPONSE_ACKNOWLEDGEMENT: return "RESPONSE_ACKNOWLEDGEMENT";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005625 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
5626 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08005627 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 -08005628 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
5629 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
5630 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
5631 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
Matt Mower897915e2015-04-08 23:16:03 -05005632 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005633 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
5634 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
Matt Mower897915e2015-04-08 23:16:03 -05005635 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
Sanket Padawe0eb4fba2016-01-26 17:28:38 -08005636 case RIL_UNSOL_SUPP_SVC_NOTIFICATION: return "UNSOL_SUPP_SVC_NOTIFICATION";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005637 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
5638 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
5639 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
5640 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
Matt Mower897915e2015-04-08 23:16:03 -05005641 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FULL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005642 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005643 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
Wink Savillef4c4d362009-04-02 01:37:03 -07005644 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
Matt Mower897915e2015-04-08 23:16:03 -05005645 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_RESPONSE_CDMA_NEW_SMS";
5646 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_RESPONSE_NEW_BROADCAST_SMS";
Wink Savillef4c4d362009-04-02 01:37:03 -07005647 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
Wink Saville3d54e742009-05-18 18:00:44 -07005648 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
5649 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
5650 case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
5651 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
5652 case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
Jaikumar Ganeshaf6ecbf2009-04-29 13:27:51 -07005653 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
John Wang5d621da2009-09-18 17:17:48 -07005654 case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
John Wang5909cf82010-01-29 00:18:54 -08005655 case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
Wink Savilleee274582011-04-16 15:05:49 -07005656 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08005657 case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
5658 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
Wink Saville5b9df332011-04-06 16:24:21 -07005659 case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005660 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
Wink Saville8a9e0212013-04-09 12:11:38 -07005661 case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
Matt Mower897915e2015-04-08 23:16:03 -05005662 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED";
Etan Cohend3652192014-06-20 08:28:44 -07005663 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return "UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED";
5664 case RIL_UNSOL_SRVCC_STATE_NOTIFY: return "UNSOL_SRVCC_STATE_NOTIFY";
Matt Mower897915e2015-04-08 23:16:03 -05005665 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return "UNSOL_HARDWARE_CONFIG_CHANGED";
Wink Savillec29360a2014-07-13 05:17:28 -07005666 case RIL_UNSOL_DC_RT_INFO_CHANGED: return "UNSOL_DC_RT_INFO_CHANGED";
Matt Mower897915e2015-04-08 23:16:03 -05005667 case RIL_UNSOL_RADIO_CAPABILITY: return "UNSOL_RADIO_CAPABILITY";
Mark Salyzyn0078c8d2016-12-12 14:41:47 -08005668 case RIL_UNSOL_MODEM_RESTART: return "UNSOL_MODEM_RESTART";
Matt Mower897915e2015-04-08 23:16:03 -05005669 case RIL_UNSOL_ON_SS: return "UNSOL_ON_SS";
5670 case RIL_UNSOL_STK_CC_ALPHA_NOTIFY: return "UNSOL_STK_CC_ALPHA_NOTIFY";
5671 case RIL_UNSOL_LCEDATA_RECV: return "UNSOL_LCEDATA_RECV";
5672 case RIL_UNSOL_PCO_DATA: return "UNSOL_PCO_DATA";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005673 default: return "<unknown request>";
5674 }
5675}
5676
Etan Cohend3652192014-06-20 08:28:44 -07005677const char *
5678rilSocketIdToString(RIL_SOCKET_ID socket_id)
5679{
5680 switch(socket_id) {
5681 case RIL_SOCKET_1:
5682 return "RIL_SOCKET_1";
5683#if (SIM_COUNT >= 2)
5684 case RIL_SOCKET_2:
5685 return "RIL_SOCKET_2";
5686#endif
5687#if (SIM_COUNT >= 3)
5688 case RIL_SOCKET_3:
5689 return "RIL_SOCKET_3";
5690#endif
5691#if (SIM_COUNT >= 4)
5692 case RIL_SOCKET_4:
5693 return "RIL_SOCKET_4";
5694#endif
5695 default:
5696 return "not a valid RIL";
5697 }
5698}
5699
Sanket Padawe4c05f352016-01-26 16:19:00 -08005700/*
5701 * Returns true for a debuggable build.
5702 */
5703static bool isDebuggable() {
5704 char debuggable[PROP_VALUE_MAX];
5705 property_get("ro.debuggable", debuggable, "0");
5706 if (strcmp(debuggable, "1") == 0) {
5707 return true;
5708 }
5709 return false;
5710}
5711
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005712} /* namespace android */
Dheeraj Shetty27976c42014-07-02 21:27:57 +02005713
5714void rilEventAddWakeup_helper(struct ril_event *ev) {
5715 android::rilEventAddWakeup(ev);
5716}
5717
5718void listenCallback_helper(int fd, short flags, void *param) {
5719 android::listenCallback(fd, flags, param);
5720}
5721
5722int blockingWrite_helper(int fd, void *buffer, size_t len) {
5723 return android::blockingWrite(fd, buffer, len);
5724}