blob: b571ed2776b62b630828af76f896672594e40ec2 [file] [log] [blame]
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001/* //device/libs/telephony/ril.cpp
2**
3** Copyright 2006, The Android Open Source Project
4**
5** 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
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** 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
15** limitations under the License.
16*/
17
18#define LOG_TAG "RILC"
19
20#include <hardware_legacy/power.h>
Daniel Hillenbrand601dc852013-07-07 10:06:59 +020021#include <telephony/ril.h>
22#include <telephony/ril_cdma_sms.h>
23#include <cutils/sockets.h>
24#include <cutils/jstring.h>
Andrew Jiangca4a9a02014-01-18 18:04:08 -050025#include <telephony/record_stream.h>
Daniel Hillenbrand601dc852013-07-07 10:06:59 +020026#include <utils/Log.h>
27#include <utils/SystemClock.h>
28#include <pthread.h>
29#include <binder/Parcel.h>
30#include <cutils/jstring.h>
Daniel Hillenbrand601dc852013-07-07 10:06:59 +020031#include <sys/types.h>
XpLoDWilDba5c6a32013-07-27 21:12:19 +020032#include <sys/limits.h>
Sanket Padawe9343e872016-01-11 12:45:43 -080033#include <sys/system_properties.h>
Daniel Hillenbrand601dc852013-07-07 10:06:59 +020034#include <pwd.h>
Daniel Hillenbrand601dc852013-07-07 10:06:59 +020035#include <stdio.h>
36#include <stdlib.h>
37#include <stdarg.h>
38#include <string.h>
39#include <unistd.h>
40#include <fcntl.h>
41#include <time.h>
42#include <errno.h>
43#include <assert.h>
44#include <ctype.h>
45#include <alloca.h>
46#include <sys/un.h>
47#include <assert.h>
48#include <netinet/in.h>
49#include <cutils/properties.h>
Dheeraj Shettycc231012014-07-02 21:27:57 +020050#include <RilSapSocket.h>
Daniel Hillenbrand601dc852013-07-07 10:06:59 +020051
Dheeraj Shettycc231012014-07-02 21:27:57 +020052extern "C" void
53RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen);
Sanket Padawea7c043d2016-01-27 15:09:12 -080054
55extern "C" void
56RIL_onRequestAck(RIL_Token t);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +020057namespace android {
58
59#define PHONE_PROCESS "radio"
Dheeraj Shettycc231012014-07-02 21:27:57 +020060#define BLUETOOTH_PROCESS "bluetooth"
Daniel Hillenbrand601dc852013-07-07 10:06:59 +020061
62#define SOCKET_NAME_RIL "rild"
Howard Sue32dbfd2015-01-07 15:55:57 +080063#define SOCKET2_NAME_RIL "rild2"
64#define SOCKET3_NAME_RIL "rild3"
65#define SOCKET4_NAME_RIL "rild4"
66
Daniel Hillenbrand601dc852013-07-07 10:06:59 +020067#define SOCKET_NAME_RIL_DEBUG "rild-debug"
68
69#define ANDROID_WAKE_LOCK_NAME "radio-interface"
70
Nathan Haroldd6306fa2015-07-28 14:54:58 -070071#define ANDROID_WAKE_LOCK_SECS 0
72#define ANDROID_WAKE_LOCK_USECS 200000
Daniel Hillenbrand601dc852013-07-07 10:06:59 +020073
74#define PROPERTY_RIL_IMPL "gsm.version.ril-impl"
75
76// match with constant in RIL.java
77#define MAX_COMMAND_BYTES (8 * 1024)
78
79// Basically: memset buffers that the client library
80// shouldn't be using anymore in an attempt to find
81// memory usage issues sooner.
82#define MEMSET_FREED 1
83
84#define NUM_ELEMS(a) (sizeof (a) / sizeof (a)[0])
85
86#define MIN(a,b) ((a)<(b) ? (a) : (b))
87
88/* Constants for response types */
89#define RESPONSE_SOLICITED 0
90#define RESPONSE_UNSOLICITED 1
Sanket Padawea7c043d2016-01-27 15:09:12 -080091#define RESPONSE_SOLICITED_ACK 2
92#define RESPONSE_SOLICITED_ACK_EXP 3
Sanket Padawe9f972082016-02-03 11:46:02 -080093#define RESPONSE_UNSOLICITED_ACK_EXP 4
Daniel Hillenbrand601dc852013-07-07 10:06:59 +020094
95/* Negative values for private RIL errno's */
96#define RIL_ERRNO_INVALID_RESPONSE -1
Sanket Padawedf3dabe2016-02-29 10:09:26 -080097#define RIL_ERRNO_NO_MEMORY -12
Daniel Hillenbrand601dc852013-07-07 10:06:59 +020098
99// request, response, and unsolicited msg print macro
100#define PRINTBUF_SIZE 8096
101
Robert Greenwaltbc29c432015-04-29 16:57:39 -0700102// Enable verbose logging
103#define VDBG 0
104
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200105// Enable RILC log
106#define RILC_LOG 0
107
108#if RILC_LOG
109 #define startRequest sprintf(printBuf, "(")
110 #define closeRequest sprintf(printBuf, "%s)", printBuf)
forkbombe0568e12015-11-23 18:37:37 +1100111 #define printRequest(token, req) \
112 RLOGD("[%04d]> %s %s", token, requestToString(req), printBuf)
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200113
114 #define startResponse sprintf(printBuf, "%s {", printBuf)
115 #define closeResponse sprintf(printBuf, "%s}", printBuf)
XpLoDWilDba5c6a32013-07-27 21:12:19 +0200116 #define printResponse RLOGD("%s", printBuf)
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200117
118 #define clearPrintBuf printBuf[0] = 0
119 #define removeLastChar printBuf[strlen(printBuf)-1] = 0
Ajay Nambi323c8822015-08-05 14:53:50 +0530120 #define appendPrintBuf(x...) snprintf(printBuf, PRINTBUF_SIZE, x)
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200121#else
122 #define startRequest
123 #define closeRequest
124 #define printRequest(token, req)
125 #define startResponse
126 #define closeResponse
127 #define printResponse
128 #define clearPrintBuf
129 #define removeLastChar
130 #define appendPrintBuf(x...)
131#endif
132
133enum WakeType {DONT_WAKE, WAKE_PARTIAL};
134
135typedef struct {
136 int requestNumber;
137 void (*dispatchFunction) (Parcel &p, struct RequestInfo *pRI);
138 int(*responseFunction) (Parcel &p, void *response, size_t responselen);
139} CommandInfo;
140
141typedef struct {
142 int requestNumber;
143 int (*responseFunction) (Parcel &p, void *response, size_t responselen);
144 WakeType wakeType;
145} UnsolResponseInfo;
146
147typedef struct RequestInfo {
148 int32_t token; //this is not RIL_Token
149 CommandInfo *pCI;
150 struct RequestInfo *p_next;
151 char cancelled;
152 char local; // responses to local commands do not go back to command process
Howard Sue32dbfd2015-01-07 15:55:57 +0800153 RIL_SOCKET_ID socket_id;
Sanket Padawea7c043d2016-01-27 15:09:12 -0800154 int wasAckSent; // Indicates whether an ack was sent earlier
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200155} RequestInfo;
156
157typedef struct UserCallbackInfo {
158 RIL_TimedCallback p_callback;
159 void *userParam;
160 struct ril_event event;
161 struct UserCallbackInfo *p_next;
162} UserCallbackInfo;
163
Howard Sue32dbfd2015-01-07 15:55:57 +0800164extern "C" const char * requestToString(int request);
165extern "C" const char * failCauseToString(RIL_Errno);
166extern "C" const char * callStateToString(RIL_CallState);
167extern "C" const char * radioStateToString(RIL_RadioState);
168extern "C" const char * rilSocketIdToString(RIL_SOCKET_ID socket_id);
169
170extern "C"
171char rild[MAX_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200172
Howard Subd82ef12015-04-12 10:25:05 +0200173#define RIL_VENDOR_COMMANDS_OFFSET 10000
174
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200175/*******************************************************************/
176
177RIL_RadioFunctions s_callbacks = {0, NULL, NULL, NULL, NULL, NULL};
178static int s_registerCalled = 0;
179
180static pthread_t s_tid_dispatch;
181static pthread_t s_tid_reader;
182static int s_started = 0;
183
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200184static int s_fdDebug = -1;
Howard Sue32dbfd2015-01-07 15:55:57 +0800185static int s_fdDebug_socket2 = -1;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200186
187static int s_fdWakeupRead;
188static int s_fdWakeupWrite;
189
Sanket Padawea7c043d2016-01-27 15:09:12 -0800190int s_wakelock_count = 0;
191
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200192static struct ril_event s_commands_event;
193static struct ril_event s_wakeupfd_event;
194static struct ril_event s_listen_event;
Howard Sue32dbfd2015-01-07 15:55:57 +0800195static SocketListenParam s_ril_param_socket;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200196
197static pthread_mutex_t s_pendingRequestsMutex = PTHREAD_MUTEX_INITIALIZER;
198static pthread_mutex_t s_writeMutex = PTHREAD_MUTEX_INITIALIZER;
Sanket Padawea7c043d2016-01-27 15:09:12 -0800199static pthread_mutex_t s_wakeLockCountMutex = PTHREAD_MUTEX_INITIALIZER;
Howard Sue32dbfd2015-01-07 15:55:57 +0800200static RequestInfo *s_pendingRequests = NULL;
201
202#if (SIM_COUNT >= 2)
203static struct ril_event s_commands_event_socket2;
204static struct ril_event s_listen_event_socket2;
205static SocketListenParam s_ril_param_socket2;
206
207static pthread_mutex_t s_pendingRequestsMutex_socket2 = PTHREAD_MUTEX_INITIALIZER;
208static pthread_mutex_t s_writeMutex_socket2 = PTHREAD_MUTEX_INITIALIZER;
209static RequestInfo *s_pendingRequests_socket2 = NULL;
210#endif
211
212#if (SIM_COUNT >= 3)
213static struct ril_event s_commands_event_socket3;
214static struct ril_event s_listen_event_socket3;
215static SocketListenParam s_ril_param_socket3;
216
217static pthread_mutex_t s_pendingRequestsMutex_socket3 = PTHREAD_MUTEX_INITIALIZER;
218static pthread_mutex_t s_writeMutex_socket3 = PTHREAD_MUTEX_INITIALIZER;
219static RequestInfo *s_pendingRequests_socket3 = NULL;
220#endif
221
222#if (SIM_COUNT >= 4)
223static struct ril_event s_commands_event_socket4;
224static struct ril_event s_listen_event_socket4;
225static SocketListenParam s_ril_param_socket4;
226
227static pthread_mutex_t s_pendingRequestsMutex_socket4 = PTHREAD_MUTEX_INITIALIZER;
228static pthread_mutex_t s_writeMutex_socket4 = PTHREAD_MUTEX_INITIALIZER;
229static RequestInfo *s_pendingRequests_socket4 = NULL;
230#endif
231
232static struct ril_event s_wake_timeout_event;
233static struct ril_event s_debug_event;
234
Howard Subd82ef12015-04-12 10:25:05 +0200235
Nathan Haroldd6306fa2015-07-28 14:54:58 -0700236static const struct timeval TIMEVAL_WAKE_TIMEOUT = {ANDROID_WAKE_LOCK_SECS,ANDROID_WAKE_LOCK_USECS};
Howard Sue32dbfd2015-01-07 15:55:57 +0800237
Howard Subd82ef12015-04-12 10:25:05 +0200238
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200239static pthread_mutex_t s_startupMutex = PTHREAD_MUTEX_INITIALIZER;
240static pthread_cond_t s_startupCond = PTHREAD_COND_INITIALIZER;
241
242static pthread_mutex_t s_dispatchMutex = PTHREAD_MUTEX_INITIALIZER;
243static pthread_cond_t s_dispatchCond = PTHREAD_COND_INITIALIZER;
244
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200245static RequestInfo *s_toDispatchHead = NULL;
246static RequestInfo *s_toDispatchTail = NULL;
247
248static UserCallbackInfo *s_last_wake_timeout_info = NULL;
249
250static void *s_lastNITZTimeData = NULL;
251static size_t s_lastNITZTimeDataSize;
252
253#if RILC_LOG
254 static char printBuf[PRINTBUF_SIZE];
255#endif
256
257/*******************************************************************/
Howard Sue32dbfd2015-01-07 15:55:57 +0800258static int sendResponse (Parcel &p, RIL_SOCKET_ID socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200259
260static void dispatchVoid (Parcel& p, RequestInfo *pRI);
261static void dispatchString (Parcel& p, RequestInfo *pRI);
262static void dispatchStrings (Parcel& p, RequestInfo *pRI);
263static void dispatchInts (Parcel& p, RequestInfo *pRI);
264static void dispatchDial (Parcel& p, RequestInfo *pRI);
265static void dispatchSIM_IO (Parcel& p, RequestInfo *pRI);
Howard Sue32dbfd2015-01-07 15:55:57 +0800266static void dispatchSIM_APDU (Parcel& p, RequestInfo *pRI);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200267static void dispatchCallForward(Parcel& p, RequestInfo *pRI);
268static void dispatchRaw(Parcel& p, RequestInfo *pRI);
269static void dispatchSmsWrite (Parcel &p, RequestInfo *pRI);
270static void dispatchDataCall (Parcel& p, RequestInfo *pRI);
271static void dispatchVoiceRadioTech (Parcel& p, RequestInfo *pRI);
Andrew Jiangca4a9a02014-01-18 18:04:08 -0500272static void dispatchSetInitialAttachApn (Parcel& p, RequestInfo *pRI);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200273static void dispatchCdmaSubscriptionSource (Parcel& p, RequestInfo *pRI);
274
275static void dispatchCdmaSms(Parcel &p, RequestInfo *pRI);
Andrew Jiangca4a9a02014-01-18 18:04:08 -0500276static void dispatchImsSms(Parcel &p, RequestInfo *pRI);
277static void dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
278static void dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200279static void dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI);
280static void dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI);
281static void dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI);
282static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI);
Howard Sue32dbfd2015-01-07 15:55:57 +0800283static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI);
284static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI);
285static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI);
286static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI);
287static void dispatchDataProfile(Parcel &p, RequestInfo *pRI);
Howard Subd82ef12015-04-12 10:25:05 +0200288static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200289static int responseInts(Parcel &p, void *response, size_t responselen);
Daniel Hillenbrandd0b84162015-04-12 11:53:23 +0200290static int responseIntsGetPreferredNetworkType(Parcel &p, void *response, size_t responselen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200291static int responseStrings(Parcel &p, void *response, size_t responselen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200292static int responseString(Parcel &p, void *response, size_t responselen);
293static int responseVoid(Parcel &p, void *response, size_t responselen);
294static int responseCallList(Parcel &p, void *response, size_t responselen);
295static int responseSMS(Parcel &p, void *response, size_t responselen);
296static int responseSIM_IO(Parcel &p, void *response, size_t responselen);
297static int responseCallForwards(Parcel &p, void *response, size_t responselen);
298static int responseDataCallList(Parcel &p, void *response, size_t responselen);
299static int responseSetupDataCall(Parcel &p, void *response, size_t responselen);
300static int responseRaw(Parcel &p, void *response, size_t responselen);
301static int responseSsn(Parcel &p, void *response, size_t responselen);
302static int responseSimStatus(Parcel &p, void *response, size_t responselen);
303static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen);
304static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen);
305static int responseCdmaSms(Parcel &p, void *response, size_t responselen);
306static int responseCellList(Parcel &p, void *response, size_t responselen);
307static int responseCdmaInformationRecords(Parcel &p,void *response, size_t responselen);
308static int responseRilSignalStrength(Parcel &p,void *response, size_t responselen);
309static int responseCallRing(Parcel &p, void *response, size_t responselen);
310static int responseCdmaSignalInfoRecord(Parcel &p,void *response, size_t responselen);
311static int responseCdmaCallWaiting(Parcel &p,void *response, size_t responselen);
312static int responseSimRefresh(Parcel &p, void *response, size_t responselen);
XpLoDWilDba5c6a32013-07-27 21:12:19 +0200313static int responseCellInfoList(Parcel &p, void *response, size_t responselen);
Howard Sue32dbfd2015-01-07 15:55:57 +0800314static int responseHardwareConfig(Parcel &p, void *response, size_t responselen);
315static int responseDcRtInfo(Parcel &p, void *response, size_t responselen);
Howard Subd82ef12015-04-12 10:25:05 +0200316static int responseRadioCapability(Parcel &p, void *response, size_t responselen);
317static int responseSSData(Parcel &p, void *response, size_t responselen);
fenglu9bdede02015-04-14 14:53:55 -0700318static int responseLceStatus(Parcel &p, void *response, size_t responselen);
319static int responseLceData(Parcel &p, void *response, size_t responselen);
Prerepa Viswanadham8e755592015-05-28 00:37:32 -0700320static int responseActivityData(Parcel &p, void *response, size_t responselen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200321
322static int decodeVoiceRadioTechnology (RIL_RadioState radioState);
323static int decodeCdmaSubscriptionSource (RIL_RadioState radioState);
Howard Subd82ef12015-04-12 10:25:05 +0200324static RIL_RadioState processRadioState(RIL_RadioState newRadioState);
Sanket Padawea7c043d2016-01-27 15:09:12 -0800325static void grabPartialWakeLock();
326static void releaseWakeLock();
327static void wakeTimeoutCallback(void *);
Howard Subd82ef12015-04-12 10:25:05 +0200328
329static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200330
Sanket Padawe9343e872016-01-11 12:45:43 -0800331static bool isDebuggable();
332
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200333#ifdef RIL_SHLIB
Howard Sue32dbfd2015-01-07 15:55:57 +0800334#if defined(ANDROID_MULTI_SIM)
Andreas Schneider47b2d962015-04-13 22:54:49 +0200335extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Howard Sue32dbfd2015-01-07 15:55:57 +0800336 size_t datalen, RIL_SOCKET_ID socket_id);
337#else
Andreas Schneider47b2d962015-04-13 22:54:49 +0200338extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200339 size_t datalen);
340#endif
Howard Sue32dbfd2015-01-07 15:55:57 +0800341#endif
342
343#if defined(ANDROID_MULTI_SIM)
344#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c), (d))
345#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d), (e))
346#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest(a)
347#else
348#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c))
349#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d))
350#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest()
351#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200352
353static UserCallbackInfo * internalRequestTimedCallback
354 (RIL_TimedCallback callback, void *param,
355 const struct timeval *relativeTime);
356
357/** Index == requestNumber */
358static CommandInfo s_commands[] = {
359#include "ril_commands.h"
360};
361
362static UnsolResponseInfo s_unsolResponses[] = {
363#include "ril_unsol_commands.h"
364};
365
Christopher N. Hessec694ff02016-03-27 21:04:38 +0200366static CommandInfo s_commands_v[] = {
367#include <telephony/ril_commands_vendor.h>
368};
369
Howard Subd82ef12015-04-12 10:25:05 +0200370static UnsolResponseInfo s_unsolResponses_v[] = {
Christopher N. Hessec694ff02016-03-27 21:04:38 +0200371#include <telephony/ril_unsol_commands_vendor.h>
Howard Subd82ef12015-04-12 10:25:05 +0200372};
373
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200374/* For older RILs that do not support new commands RIL_REQUEST_VOICE_RADIO_TECH and
375 RIL_UNSOL_VOICE_RADIO_TECH_CHANGED messages, decode the voice radio tech from
376 radio state message and store it. Every time there is a change in Radio State
377 check to see if voice radio tech changes and notify telephony
378 */
379int voiceRadioTech = -1;
380
381/* For older RILs that do not support new commands RIL_REQUEST_GET_CDMA_SUBSCRIPTION_SOURCE
382 and RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED messages, decode the subscription
383 source from radio state and store it. Every time there is a change in Radio State
384 check to see if subscription source changed and notify telephony
385 */
386int cdmaSubscriptionSource = -1;
387
388/* For older RILs that do not send RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, decode the
389 SIM/RUIM state from radio state and store it. Every time there is a change in Radio State,
390 check to see if SIM/RUIM status changed and notify telephony
391 */
392int simRuimStatus = -1;
393
Howard Sue32dbfd2015-01-07 15:55:57 +0800394static char * RIL_getRilSocketName() {
395 return rild;
396}
397
398extern "C"
Dheeraj Shettycc231012014-07-02 21:27:57 +0200399void RIL_setRilSocketName(const char * s) {
Howard Sue32dbfd2015-01-07 15:55:57 +0800400 strncpy(rild, s, MAX_SOCKET_NAME_LENGTH);
401}
402
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200403static char *
404strdupReadString(Parcel &p) {
405 size_t stringlen;
406 const char16_t *s16;
407
408 s16 = p.readString16Inplace(&stringlen);
409
410 return strndup16to8(s16, stringlen);
411}
412
Howard Subd82ef12015-04-12 10:25:05 +0200413static status_t
414readStringFromParcelInplace(Parcel &p, char *str, size_t maxLen) {
415 size_t s16Len;
416 const char16_t *s16;
417
418 s16 = p.readString16Inplace(&s16Len);
419 if (s16 == NULL) {
420 return NO_MEMORY;
421 }
422 size_t strLen = strnlen16to8(s16, s16Len);
423 if ((strLen + 1) > maxLen) {
424 return NO_MEMORY;
425 }
426 if (strncpy16to8(str, s16, strLen) == NULL) {
427 return NO_MEMORY;
428 } else {
429 return NO_ERROR;
430 }
431}
432
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200433static void writeStringToParcel(Parcel &p, const char *s) {
434 char16_t *s16;
435 size_t s16_len;
436 s16 = strdup8to16(s, &s16_len);
437 p.writeString16(s16, s16_len);
438 free(s16);
439}
440
441
442static void
443memsetString (char *s) {
444 if (s != NULL) {
445 memset (s, 0, strlen(s));
446 }
447}
448
449void nullParcelReleaseFunction (const uint8_t* data, size_t dataSize,
450 const size_t* objects, size_t objectsSize,
451 void* cookie) {
452 // do nothing -- the data reference lives longer than the Parcel object
453}
454
455/**
456 * To be called from dispatch thread
457 * Issue a single local request, ensuring that the response
458 * is not sent back up to the command process
459 */
460static void
Howard Sue32dbfd2015-01-07 15:55:57 +0800461issueLocalRequest(int request, void *data, int len, RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200462 RequestInfo *pRI;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200463 int ret;
Howard Sue32dbfd2015-01-07 15:55:57 +0800464 /* Hook for current context */
465 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
466 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
467 /* pendingRequestsHook refer to &s_pendingRequests */
468 RequestInfo** pendingRequestsHook = &s_pendingRequests;
469
470#if (SIM_COUNT == 2)
471 if (socket_id == RIL_SOCKET_2) {
472 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
473 pendingRequestsHook = &s_pendingRequests_socket2;
474 }
475#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200476
477 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
Sanket Padawedf3dabe2016-02-29 10:09:26 -0800478 if (pRI == NULL) {
479 RLOGE("Memory allocation failed for request %s", requestToString(request));
480 return;
481 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200482
483 pRI->local = 1;
484 pRI->token = 0xffffffff; // token is not used in this context
485
Howard Subd82ef12015-04-12 10:25:05 +0200486 /* Check vendor commands */
487 if (request > RIL_VENDOR_COMMANDS_OFFSET) {
488 pRI->pCI = &(s_commands_v[request - RIL_VENDOR_COMMANDS_OFFSET]);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200489 } else {
490 pRI->pCI = &(s_commands[request]);
491 }
Howard Sue32dbfd2015-01-07 15:55:57 +0800492 pRI->socket_id = socket_id;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200493
Howard Sue32dbfd2015-01-07 15:55:57 +0800494 ret = pthread_mutex_lock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200495 assert (ret == 0);
496
Howard Sue32dbfd2015-01-07 15:55:57 +0800497 pRI->p_next = *pendingRequestsHook;
498 *pendingRequestsHook = pRI;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200499
Howard Sue32dbfd2015-01-07 15:55:57 +0800500 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200501 assert (ret == 0);
502
XpLoDWilDba5c6a32013-07-27 21:12:19 +0200503 RLOGD("C[locl]> %s", requestToString(request));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200504
Howard Sue32dbfd2015-01-07 15:55:57 +0800505 CALL_ONREQUEST(request, data, len, pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200506}
507
Howard Subd82ef12015-04-12 10:25:05 +0200508
509
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200510static int
Howard Sue32dbfd2015-01-07 15:55:57 +0800511processCommandBuffer(void *buffer, size_t buflen, RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200512 Parcel p;
513 status_t status;
514 int32_t request;
515 int32_t token;
516 RequestInfo *pRI;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200517 int ret;
Howard Sue32dbfd2015-01-07 15:55:57 +0800518 /* Hook for current context */
519 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
520 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
521 /* pendingRequestsHook refer to &s_pendingRequests */
522 RequestInfo** pendingRequestsHook = &s_pendingRequests;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200523
524 p.setData((uint8_t *) buffer, buflen);
525
526 // status checked at end
527 status = p.readInt32(&request);
528 status = p.readInt32 (&token);
529
Howard Sue32dbfd2015-01-07 15:55:57 +0800530#if (SIM_COUNT >= 2)
531 if (socket_id == RIL_SOCKET_2) {
532 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
533 pendingRequestsHook = &s_pendingRequests_socket2;
534 }
535#if (SIM_COUNT >= 3)
536 else if (socket_id == RIL_SOCKET_3) {
537 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
538 pendingRequestsHook = &s_pendingRequests_socket3;
539 }
540#endif
541#if (SIM_COUNT >= 4)
542 else if (socket_id == RIL_SOCKET_4) {
543 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
544 pendingRequestsHook = &s_pendingRequests_socket4;
545 }
546#endif
547#endif
548
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200549 if (status != NO_ERROR) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +0200550 RLOGE("invalid request block");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200551 return 0;
552 }
553
Howard Subd82ef12015-04-12 10:25:05 +0200554 CommandInfo *pCI = NULL;
555 if (request > RIL_VENDOR_COMMANDS_OFFSET) {
556 int index = request - RIL_VENDOR_COMMANDS_OFFSET;
557 RLOGD("processCommandBuffer: samsung request=%d, index=%d",
558 request, index);
559 if (index < (int32_t)NUM_ELEMS(s_commands_v))
560 pCI = &(s_commands_v[index]);
561 } else {
562 if (request < (int32_t)NUM_ELEMS(s_commands))
563 pCI = &(s_commands[request]);
564 }
Howard Sue32dbfd2015-01-07 15:55:57 +0800565
Sooraj Sasindrancfef9bd2016-05-06 16:19:56 -0700566 // Received an Ack for the previous result sent to RIL.java,
567 // so release wakelock and exit
568 if (request == RIL_RESPONSE_ACKNOWLEDGEMENT) {
569 releaseWakeLock();
570 return 0;
571 }
572
Howard Subd82ef12015-04-12 10:25:05 +0200573 if (pCI == NULL) {
574 Parcel pErr;
XpLoDWilDba5c6a32013-07-27 21:12:19 +0200575 RLOGE("unsupported request code %d token %d", request, token);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200576 // FIXME this should perhaps return a response
Howard Sue32dbfd2015-01-07 15:55:57 +0800577 pErr.writeInt32 (RESPONSE_SOLICITED);
578 pErr.writeInt32 (token);
579 pErr.writeInt32 (RIL_E_GENERIC_FAILURE);
580
581 sendResponse(pErr, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200582 return 0;
583 }
584
Sooraj Sasindrancfef9bd2016-05-06 16:19:56 -0700585 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
Sanket Padawedf3dabe2016-02-29 10:09:26 -0800586 if (pRI == NULL) {
587 RLOGE("Memory allocation failed for request %s", requestToString(request));
588 return 0;
589 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200590
591 pRI->token = token;
Howard Subd82ef12015-04-12 10:25:05 +0200592 pRI->pCI = pCI;
Howard Sue32dbfd2015-01-07 15:55:57 +0800593 pRI->socket_id = socket_id;
594
595 ret = pthread_mutex_lock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200596 assert (ret == 0);
597
Howard Sue32dbfd2015-01-07 15:55:57 +0800598 pRI->p_next = *pendingRequestsHook;
599 *pendingRequestsHook = pRI;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200600
Howard Sue32dbfd2015-01-07 15:55:57 +0800601 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200602 assert (ret == 0);
603
604/* sLastDispatchedToken = token; */
605
606 pRI->pCI->dispatchFunction(p, pRI);
607
608 return 0;
609}
610
611static void
612invalidCommandBlock (RequestInfo *pRI) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +0200613 RLOGE("invalid command block for token %d request %s",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200614 pRI->token, requestToString(pRI->pCI->requestNumber));
615}
616
617/** Callee expects NULL */
618static void
619dispatchVoid (Parcel& p, RequestInfo *pRI) {
620 clearPrintBuf;
621 printRequest(pRI->token, pRI->pCI->requestNumber);
Howard Sue32dbfd2015-01-07 15:55:57 +0800622 CALL_ONREQUEST(pRI->pCI->requestNumber, NULL, 0, pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200623}
624
625/** Callee expects const char * */
626static void
627dispatchString (Parcel& p, RequestInfo *pRI) {
628 status_t status;
629 size_t datalen;
630 size_t stringlen;
631 char *string8 = NULL;
632
633 string8 = strdupReadString(p);
634
635 startRequest;
636 appendPrintBuf("%s%s", printBuf, string8);
637 closeRequest;
638 printRequest(pRI->token, pRI->pCI->requestNumber);
639
Howard Sue32dbfd2015-01-07 15:55:57 +0800640 CALL_ONREQUEST(pRI->pCI->requestNumber, string8,
641 sizeof(char *), pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200642
643#ifdef MEMSET_FREED
644 memsetString(string8);
645#endif
646
647 free(string8);
648 return;
649invalid:
650 invalidCommandBlock(pRI);
651 return;
652}
653
654/** Callee expects const char ** */
655static void
656dispatchStrings (Parcel &p, RequestInfo *pRI) {
657 int32_t countStrings;
658 status_t status;
659 size_t datalen;
660 char **pStrings;
661
662 status = p.readInt32 (&countStrings);
663
664 if (status != NO_ERROR) {
665 goto invalid;
666 }
667
668 startRequest;
669 if (countStrings == 0) {
670 // just some non-null pointer
671 pStrings = (char **)alloca(sizeof(char *));
Sanket Padawedf3dabe2016-02-29 10:09:26 -0800672 if (pStrings == NULL) {
673 RLOGE("Memory allocation failed for request %s",
674 requestToString(pRI->pCI->requestNumber));
675 closeRequest;
676 return;
677 }
678
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200679 datalen = 0;
680 } else if (((int)countStrings) == -1) {
681 pStrings = NULL;
682 datalen = 0;
683 } else {
684 datalen = sizeof(char *) * countStrings;
685
686 pStrings = (char **)alloca(datalen);
Sanket Padawedf3dabe2016-02-29 10:09:26 -0800687 if (pStrings == NULL) {
688 RLOGE("Memory allocation failed for request %s",
689 requestToString(pRI->pCI->requestNumber));
690 closeRequest;
691 return;
692 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200693
694 for (int i = 0 ; i < countStrings ; i++) {
695 pStrings[i] = strdupReadString(p);
696 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
697 }
698 }
699 removeLastChar;
700 closeRequest;
701 printRequest(pRI->token, pRI->pCI->requestNumber);
702
Howard Sue32dbfd2015-01-07 15:55:57 +0800703 CALL_ONREQUEST(pRI->pCI->requestNumber, pStrings, datalen, pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200704
705 if (pStrings != NULL) {
706 for (int i = 0 ; i < countStrings ; i++) {
707#ifdef MEMSET_FREED
708 memsetString (pStrings[i]);
709#endif
710 free(pStrings[i]);
711 }
712
713#ifdef MEMSET_FREED
714 memset(pStrings, 0, datalen);
715#endif
716 }
717
718 return;
719invalid:
720 invalidCommandBlock(pRI);
721 return;
722}
723
724/** Callee expects const int * */
725static void
726dispatchInts (Parcel &p, RequestInfo *pRI) {
727 int32_t count;
728 status_t status;
729 size_t datalen;
730 int *pInts;
731
732 status = p.readInt32 (&count);
733
734 if (status != NO_ERROR || count == 0) {
735 goto invalid;
736 }
737
738 datalen = sizeof(int) * count;
739 pInts = (int *)alloca(datalen);
Sanket Padawedf3dabe2016-02-29 10:09:26 -0800740 if (pInts == NULL) {
741 RLOGE("Memory allocation failed for request %s", requestToString(pRI->pCI->requestNumber));
742 return;
743 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200744
745 startRequest;
746 for (int i = 0 ; i < count ; i++) {
747 int32_t t;
748
749 status = p.readInt32(&t);
750 pInts[i] = (int)t;
751 appendPrintBuf("%s%d,", printBuf, t);
752
753 if (status != NO_ERROR) {
754 goto invalid;
755 }
756 }
757 removeLastChar;
758 closeRequest;
759 printRequest(pRI->token, pRI->pCI->requestNumber);
760
Howard Sue32dbfd2015-01-07 15:55:57 +0800761 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<int *>(pInts),
762 datalen, pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200763
764#ifdef MEMSET_FREED
765 memset(pInts, 0, datalen);
766#endif
767
768 return;
769invalid:
770 invalidCommandBlock(pRI);
771 return;
772}
773
774
775/**
776 * Callee expects const RIL_SMS_WriteArgs *
777 * Payload is:
778 * int32_t status
779 * String pdu
780 */
781static void
782dispatchSmsWrite (Parcel &p, RequestInfo *pRI) {
783 RIL_SMS_WriteArgs args;
784 int32_t t;
785 status_t status;
786
Mark Salyzyn961fd022015-04-09 07:18:35 -0700787 RLOGD("dispatchSmsWrite");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200788 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);
806
Howard Sue32dbfd2015-01-07 15:55:57 +0800807 CALL_ONREQUEST(pRI->pCI->requestNumber, &args, sizeof(args), pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200808
809#ifdef MEMSET_FREED
810 memsetString (args.pdu);
811#endif
812
813 free (args.pdu);
814
815#ifdef MEMSET_FREED
816 memset(&args, 0, sizeof(args));
817#endif
818
819 return;
820invalid:
821 invalidCommandBlock(pRI);
822 return;
823}
824
825/**
826 * Callee expects const RIL_Dial *
827 * Payload is:
828 * String address
829 * int32_t clir
830 */
831static void
832dispatchDial (Parcel &p, RequestInfo *pRI) {
833 RIL_Dial dial;
834 RIL_UUS_Info uusInfo;
835 int32_t sizeOfDial;
836 int32_t t;
837 int32_t uusPresent;
Christopher N. Hesse621e63e2016-02-22 21:57:39 +0100838#ifdef SAMSUNG_NEXT_GEN_MODEM
Andreas Schneider29472682015-01-01 19:00:04 +0100839 char *csv;
840#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200841 status_t status;
842
Mark Salyzyn961fd022015-04-09 07:18:35 -0700843 RLOGD("dispatchDial");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200844 memset (&dial, 0, sizeof(dial));
845
846 dial.address = strdupReadString(p);
847
848 status = p.readInt32(&t);
849 dial.clir = (int)t;
850
851 if (status != NO_ERROR || dial.address == NULL) {
852 goto invalid;
853 }
854
Christopher N. Hesse621e63e2016-02-22 21:57:39 +0100855#ifdef SAMSUNG_NEXT_GEN_MODEM
Andreas Schneider29472682015-01-01 19:00:04 +0100856 /* CallDetails.call_type */
857 status = p.readInt32(&t);
858 if (status != NO_ERROR) {
859 goto invalid;
860 }
861 /* CallDetails.call_domain */
862 p.readInt32(&t);
863 if (status != NO_ERROR) {
864 goto invalid;
865 }
866 /* CallDetails.getCsvFromExtra */
867 csv = strdupReadString(p);
868 if (csv == NULL) {
869 goto invalid;
870 }
871 free(csv);
872#endif
873
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200874 if (s_callbacks.version < 3) { // Remove when partners upgrade to version 3
875 uusPresent = 0;
876 sizeOfDial = sizeof(dial) - sizeof(RIL_UUS_Info *);
877 } else {
878 status = p.readInt32(&uusPresent);
879
880 if (status != NO_ERROR) {
881 goto invalid;
882 }
883
884 if (uusPresent == 0) {
Christopher N. Hesse621e63e2016-02-22 21:57:39 +0100885#if defined(MODEM_TYPE_XMM6262) || defined(SAMSUNG_NEXT_GEN_MODEM)
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200886 dial.uusInfo = NULL;
Andreas Schneiderf68609b2015-04-07 19:01:34 +0200887#elif defined(MODEM_TYPE_XMM6260)
Howard Sue32dbfd2015-01-07 15:55:57 +0800888 /* Samsung hack */
889 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
890 uusInfo.uusType = (RIL_UUS_Type) 0;
891 uusInfo.uusDcs = (RIL_UUS_DCS) 0;
892 uusInfo.uusData = NULL;
893 uusInfo.uusLength = 0;
894 dial.uusInfo = &uusInfo;
895#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200896 } else {
897 int32_t len;
898
899 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
900
901 status = p.readInt32(&t);
902 uusInfo.uusType = (RIL_UUS_Type) t;
903
904 status = p.readInt32(&t);
905 uusInfo.uusDcs = (RIL_UUS_DCS) t;
906
907 status = p.readInt32(&len);
908 if (status != NO_ERROR) {
909 goto invalid;
910 }
911
912 // The java code writes -1 for null arrays
913 if (((int) len) == -1) {
914 uusInfo.uusData = NULL;
915 len = 0;
916 } else {
917 uusInfo.uusData = (char*) p.readInplace(len);
918 }
919
920 uusInfo.uusLength = len;
921 dial.uusInfo = &uusInfo;
922 }
923 sizeOfDial = sizeof(dial);
924 }
925
926 startRequest;
927 appendPrintBuf("%snum=%s,clir=%d", printBuf, dial.address, dial.clir);
928 if (uusPresent) {
929 appendPrintBuf("%s,uusType=%d,uusDcs=%d,uusLen=%d", printBuf,
930 dial.uusInfo->uusType, dial.uusInfo->uusDcs,
931 dial.uusInfo->uusLength);
932 }
933 closeRequest;
934 printRequest(pRI->token, pRI->pCI->requestNumber);
935
Howard Sue32dbfd2015-01-07 15:55:57 +0800936 CALL_ONREQUEST(pRI->pCI->requestNumber, &dial, sizeOfDial, pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200937
938#ifdef MEMSET_FREED
939 memsetString (dial.address);
940#endif
941
942 free (dial.address);
943
944#ifdef MEMSET_FREED
945 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
946 memset(&dial, 0, sizeof(dial));
947#endif
948
949 return;
950invalid:
951 invalidCommandBlock(pRI);
952 return;
953}
954
955/**
956 * Callee expects const RIL_SIM_IO *
957 * Payload is:
958 * int32_t command
959 * int32_t fileid
960 * String path
961 * int32_t p1, p2, p3
962 * String data
963 * String pin2
964 * String aidPtr
965 */
966static void
967dispatchSIM_IO (Parcel &p, RequestInfo *pRI) {
968 union RIL_SIM_IO {
969 RIL_SIM_IO_v6 v6;
970 RIL_SIM_IO_v5 v5;
971 } simIO;
972
973 int32_t t;
974 int size;
975 status_t status;
976
Robert Greenwaltbc29c432015-04-29 16:57:39 -0700977#if VDBG
Mark Salyzyn961fd022015-04-09 07:18:35 -0700978 RLOGD("dispatchSIM_IO");
Robert Greenwaltbc29c432015-04-29 16:57:39 -0700979#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200980 memset (&simIO, 0, sizeof(simIO));
981
982 // note we only check status at the end
983
984 status = p.readInt32(&t);
985 simIO.v6.command = (int)t;
986
987 status = p.readInt32(&t);
988 simIO.v6.fileid = (int)t;
989
990 simIO.v6.path = strdupReadString(p);
991
992 status = p.readInt32(&t);
993 simIO.v6.p1 = (int)t;
994
995 status = p.readInt32(&t);
996 simIO.v6.p2 = (int)t;
997
998 status = p.readInt32(&t);
999 simIO.v6.p3 = (int)t;
1000
1001 simIO.v6.data = strdupReadString(p);
1002 simIO.v6.pin2 = strdupReadString(p);
1003 simIO.v6.aidPtr = strdupReadString(p);
1004
1005 startRequest;
1006 appendPrintBuf("%scmd=0x%X,efid=0x%X,path=%s,%d,%d,%d,%s,pin2=%s,aid=%s", printBuf,
1007 simIO.v6.command, simIO.v6.fileid, (char*)simIO.v6.path,
1008 simIO.v6.p1, simIO.v6.p2, simIO.v6.p3,
1009 (char*)simIO.v6.data, (char*)simIO.v6.pin2, simIO.v6.aidPtr);
1010 closeRequest;
1011 printRequest(pRI->token, pRI->pCI->requestNumber);
1012
1013 if (status != NO_ERROR) {
1014 goto invalid;
1015 }
1016
1017 size = (s_callbacks.version < 6) ? sizeof(simIO.v5) : sizeof(simIO.v6);
Howard Sue32dbfd2015-01-07 15:55:57 +08001018 CALL_ONREQUEST(pRI->pCI->requestNumber, &simIO, size, pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001019
1020#ifdef MEMSET_FREED
1021 memsetString (simIO.v6.path);
1022 memsetString (simIO.v6.data);
1023 memsetString (simIO.v6.pin2);
1024 memsetString (simIO.v6.aidPtr);
1025#endif
1026
1027 free (simIO.v6.path);
1028 free (simIO.v6.data);
1029 free (simIO.v6.pin2);
1030 free (simIO.v6.aidPtr);
1031
1032#ifdef MEMSET_FREED
1033 memset(&simIO, 0, sizeof(simIO));
1034#endif
1035
1036 return;
1037invalid:
1038 invalidCommandBlock(pRI);
1039 return;
1040}
1041
1042/**
Howard Sue32dbfd2015-01-07 15:55:57 +08001043 * Callee expects const RIL_SIM_APDU *
1044 * Payload is:
1045 * int32_t sessionid
1046 * int32_t cla
1047 * int32_t instruction
1048 * int32_t p1, p2, p3
1049 * String data
1050 */
1051static void
1052dispatchSIM_APDU (Parcel &p, RequestInfo *pRI) {
1053 int32_t t;
1054 status_t status;
1055 RIL_SIM_APDU apdu;
1056
Robert Greenwaltbc29c432015-04-29 16:57:39 -07001057#if VDBG
Mark Salyzyn961fd022015-04-09 07:18:35 -07001058 RLOGD("dispatchSIM_APDU");
Robert Greenwaltbc29c432015-04-29 16:57:39 -07001059#endif
Howard Sue32dbfd2015-01-07 15:55:57 +08001060 memset (&apdu, 0, sizeof(RIL_SIM_APDU));
1061
1062 // Note we only check status at the end. Any single failure leads to
1063 // subsequent reads filing.
1064 status = p.readInt32(&t);
1065 apdu.sessionid = (int)t;
1066
1067 status = p.readInt32(&t);
1068 apdu.cla = (int)t;
1069
1070 status = p.readInt32(&t);
1071 apdu.instruction = (int)t;
1072
1073 status = p.readInt32(&t);
1074 apdu.p1 = (int)t;
1075
1076 status = p.readInt32(&t);
1077 apdu.p2 = (int)t;
1078
1079 status = p.readInt32(&t);
1080 apdu.p3 = (int)t;
1081
1082 apdu.data = strdupReadString(p);
1083
1084 startRequest;
1085 appendPrintBuf("%ssessionid=%d,cla=%d,ins=%d,p1=%d,p2=%d,p3=%d,data=%s",
1086 printBuf, apdu.sessionid, apdu.cla, apdu.instruction, apdu.p1, apdu.p2,
1087 apdu.p3, (char*)apdu.data);
1088 closeRequest;
1089 printRequest(pRI->token, pRI->pCI->requestNumber);
1090
1091 if (status != NO_ERROR) {
1092 goto invalid;
1093 }
1094
1095 CALL_ONREQUEST(pRI->pCI->requestNumber, &apdu, sizeof(RIL_SIM_APDU), pRI, pRI->socket_id);
1096
1097#ifdef MEMSET_FREED
1098 memsetString(apdu.data);
1099#endif
1100 free(apdu.data);
1101
1102#ifdef MEMSET_FREED
1103 memset(&apdu, 0, sizeof(RIL_SIM_APDU));
1104#endif
1105
1106 return;
1107invalid:
1108 invalidCommandBlock(pRI);
1109 return;
1110}
1111
Howard Subd82ef12015-04-12 10:25:05 +02001112
Howard Sue32dbfd2015-01-07 15:55:57 +08001113/**
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001114 * Callee expects const RIL_CallForwardInfo *
1115 * Payload is:
1116 * int32_t status/action
1117 * int32_t reason
1118 * int32_t serviceCode
1119 * int32_t toa
1120 * String number (0 length -> null)
1121 * int32_t timeSeconds
1122 */
1123static void
1124dispatchCallForward(Parcel &p, RequestInfo *pRI) {
1125 RIL_CallForwardInfo cff;
1126 int32_t t;
1127 status_t status;
1128
Mark Salyzyn961fd022015-04-09 07:18:35 -07001129 RLOGD("dispatchCallForward");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001130 memset (&cff, 0, sizeof(cff));
1131
1132 // note we only check status at the end
1133
1134 status = p.readInt32(&t);
1135 cff.status = (int)t;
1136
1137 status = p.readInt32(&t);
1138 cff.reason = (int)t;
1139
1140 status = p.readInt32(&t);
1141 cff.serviceClass = (int)t;
1142
1143 status = p.readInt32(&t);
1144 cff.toa = (int)t;
1145
1146 cff.number = strdupReadString(p);
1147
1148 status = p.readInt32(&t);
1149 cff.timeSeconds = (int)t;
1150
1151 if (status != NO_ERROR) {
1152 goto invalid;
1153 }
1154
1155 // special case: number 0-length fields is null
1156
1157 if (cff.number != NULL && strlen (cff.number) == 0) {
1158 cff.number = NULL;
1159 }
1160
1161 startRequest;
1162 appendPrintBuf("%sstat=%d,reason=%d,serv=%d,toa=%d,%s,tout=%d", printBuf,
1163 cff.status, cff.reason, cff.serviceClass, cff.toa,
1164 (char*)cff.number, cff.timeSeconds);
1165 closeRequest;
1166 printRequest(pRI->token, pRI->pCI->requestNumber);
1167
Howard Sue32dbfd2015-01-07 15:55:57 +08001168 CALL_ONREQUEST(pRI->pCI->requestNumber, &cff, sizeof(cff), pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001169
1170#ifdef MEMSET_FREED
1171 memsetString(cff.number);
1172#endif
1173
1174 free (cff.number);
1175
1176#ifdef MEMSET_FREED
1177 memset(&cff, 0, sizeof(cff));
1178#endif
1179
1180 return;
1181invalid:
1182 invalidCommandBlock(pRI);
1183 return;
1184}
1185
1186
1187static void
1188dispatchRaw(Parcel &p, RequestInfo *pRI) {
1189 int32_t len;
1190 status_t status;
1191 const void *data;
1192
1193 status = p.readInt32(&len);
1194
1195 if (status != NO_ERROR) {
1196 goto invalid;
1197 }
1198
1199 // The java code writes -1 for null arrays
1200 if (((int)len) == -1) {
1201 data = NULL;
1202 len = 0;
1203 }
1204
1205 data = p.readInplace(len);
1206
1207 startRequest;
1208 appendPrintBuf("%sraw_size=%d", printBuf, len);
1209 closeRequest;
1210 printRequest(pRI->token, pRI->pCI->requestNumber);
1211
Howard Sue32dbfd2015-01-07 15:55:57 +08001212 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<void *>(data), len, pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001213
1214 return;
1215invalid:
1216 invalidCommandBlock(pRI);
1217 return;
1218}
1219
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001220static status_t
1221constructCdmaSms(Parcel &p, RequestInfo *pRI, RIL_CDMA_SMS_Message& rcsm) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001222 int32_t t;
1223 uint8_t ut;
1224 status_t status;
1225 int32_t digitCount;
1226 int digitLimit;
1227
1228 memset(&rcsm, 0, sizeof(rcsm));
1229
1230 status = p.readInt32(&t);
1231 rcsm.uTeleserviceID = (int) t;
1232
1233 status = p.read(&ut,sizeof(ut));
1234 rcsm.bIsServicePresent = (uint8_t) ut;
1235
1236 status = p.readInt32(&t);
1237 rcsm.uServicecategory = (int) t;
1238
1239 status = p.readInt32(&t);
1240 rcsm.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1241
1242 status = p.readInt32(&t);
1243 rcsm.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1244
1245 status = p.readInt32(&t);
1246 rcsm.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1247
1248 status = p.readInt32(&t);
1249 rcsm.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1250
1251 status = p.read(&ut,sizeof(ut));
1252 rcsm.sAddress.number_of_digits= (uint8_t) ut;
1253
1254 digitLimit= MIN((rcsm.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
1255 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1256 status = p.read(&ut,sizeof(ut));
1257 rcsm.sAddress.digits[digitCount] = (uint8_t) ut;
1258 }
1259
1260 status = p.readInt32(&t);
1261 rcsm.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1262
1263 status = p.read(&ut,sizeof(ut));
1264 rcsm.sSubAddress.odd = (uint8_t) ut;
1265
1266 status = p.read(&ut,sizeof(ut));
1267 rcsm.sSubAddress.number_of_digits = (uint8_t) ut;
1268
1269 digitLimit= MIN((rcsm.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
1270 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1271 status = p.read(&ut,sizeof(ut));
1272 rcsm.sSubAddress.digits[digitCount] = (uint8_t) ut;
1273 }
1274
1275 status = p.readInt32(&t);
1276 rcsm.uBearerDataLen = (int) t;
1277
1278 digitLimit= MIN((rcsm.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
1279 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1280 status = p.read(&ut, sizeof(ut));
1281 rcsm.aBearerData[digitCount] = (uint8_t) ut;
1282 }
1283
1284 if (status != NO_ERROR) {
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001285 return status;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001286 }
1287
1288 startRequest;
1289 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
1290 sAddress.digit_mode=%d, sAddress.Number_mode=%d, sAddress.number_type=%d, ",
1291 printBuf, rcsm.uTeleserviceID,rcsm.bIsServicePresent,rcsm.uServicecategory,
1292 rcsm.sAddress.digit_mode, rcsm.sAddress.number_mode,rcsm.sAddress.number_type);
1293 closeRequest;
1294
1295 printRequest(pRI->token, pRI->pCI->requestNumber);
1296
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001297 return status;
1298}
1299
1300static void
1301dispatchCdmaSms(Parcel &p, RequestInfo *pRI) {
1302 RIL_CDMA_SMS_Message rcsm;
1303
Mark Salyzyn961fd022015-04-09 07:18:35 -07001304 RLOGD("dispatchCdmaSms");
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001305 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1306 goto invalid;
1307 }
1308
Howard Sue32dbfd2015-01-07 15:55:57 +08001309 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm),pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001310
1311#ifdef MEMSET_FREED
1312 memset(&rcsm, 0, sizeof(rcsm));
1313#endif
1314
1315 return;
1316
1317invalid:
1318 invalidCommandBlock(pRI);
1319 return;
1320}
1321
1322static void
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001323dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1324 RIL_IMS_SMS_Message rism;
1325 RIL_CDMA_SMS_Message rcsm;
1326
Mark Salyzyn961fd022015-04-09 07:18:35 -07001327 RLOGD("dispatchImsCdmaSms: retry=%d, messageRef=%d", retry, messageRef);
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001328
1329 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1330 goto invalid;
1331 }
1332 memset(&rism, 0, sizeof(rism));
1333 rism.tech = RADIO_TECH_3GPP2;
1334 rism.retry = retry;
1335 rism.messageRef = messageRef;
1336 rism.message.cdmaMessage = &rcsm;
1337
Howard Sue32dbfd2015-01-07 15:55:57 +08001338 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001339 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Howard Sue32dbfd2015-01-07 15:55:57 +08001340 +sizeof(rcsm),pRI, pRI->socket_id);
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001341
1342#ifdef MEMSET_FREED
1343 memset(&rcsm, 0, sizeof(rcsm));
1344 memset(&rism, 0, sizeof(rism));
1345#endif
1346
1347 return;
1348
1349invalid:
1350 invalidCommandBlock(pRI);
1351 return;
1352}
1353
1354static void
1355dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1356 RIL_IMS_SMS_Message rism;
1357 int32_t countStrings;
1358 status_t status;
1359 size_t datalen;
1360 char **pStrings;
Mark Salyzyn961fd022015-04-09 07:18:35 -07001361 RLOGD("dispatchImsGsmSms: retry=%d, messageRef=%d", retry, messageRef);
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001362
1363 status = p.readInt32 (&countStrings);
1364
1365 if (status != NO_ERROR) {
1366 goto invalid;
1367 }
1368
1369 memset(&rism, 0, sizeof(rism));
1370 rism.tech = RADIO_TECH_3GPP;
1371 rism.retry = retry;
1372 rism.messageRef = messageRef;
1373
1374 startRequest;
Howard Sue32dbfd2015-01-07 15:55:57 +08001375 appendPrintBuf("%stech=%d, retry=%d, messageRef=%d, ", printBuf,
1376 (int)rism.tech, (int)rism.retry, rism.messageRef);
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001377 if (countStrings == 0) {
1378 // just some non-null pointer
1379 pStrings = (char **)alloca(sizeof(char *));
Sanket Padawedf3dabe2016-02-29 10:09:26 -08001380 if (pStrings == NULL) {
1381 RLOGE("Memory allocation failed for request %s",
1382 requestToString(pRI->pCI->requestNumber));
1383 closeRequest;
1384 return;
1385 }
1386
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001387 datalen = 0;
1388 } else if (((int)countStrings) == -1) {
1389 pStrings = NULL;
1390 datalen = 0;
1391 } else {
1392 datalen = sizeof(char *) * countStrings;
1393
1394 pStrings = (char **)alloca(datalen);
Sanket Padawedf3dabe2016-02-29 10:09:26 -08001395 if (pStrings == NULL) {
1396 RLOGE("Memory allocation failed for request %s",
1397 requestToString(pRI->pCI->requestNumber));
1398 closeRequest;
1399 return;
1400 }
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001401
1402 for (int i = 0 ; i < countStrings ; i++) {
1403 pStrings[i] = strdupReadString(p);
1404 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
1405 }
1406 }
1407 removeLastChar;
1408 closeRequest;
1409 printRequest(pRI->token, pRI->pCI->requestNumber);
1410
1411 rism.message.gsmMessage = pStrings;
Howard Sue32dbfd2015-01-07 15:55:57 +08001412 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001413 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Howard Sue32dbfd2015-01-07 15:55:57 +08001414 +datalen, pRI, pRI->socket_id);
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001415
1416 if (pStrings != NULL) {
1417 for (int i = 0 ; i < countStrings ; i++) {
1418#ifdef MEMSET_FREED
1419 memsetString (pStrings[i]);
1420#endif
1421 free(pStrings[i]);
1422 }
1423
1424#ifdef MEMSET_FREED
1425 memset(pStrings, 0, datalen);
1426#endif
1427 }
1428
1429#ifdef MEMSET_FREED
1430 memset(&rism, 0, sizeof(rism));
1431#endif
1432 return;
1433invalid:
1434 ALOGE("dispatchImsGsmSms invalid block");
1435 invalidCommandBlock(pRI);
1436 return;
1437}
1438
1439static void
1440dispatchImsSms(Parcel &p, RequestInfo *pRI) {
1441 int32_t t;
1442 status_t status = p.readInt32(&t);
1443 RIL_RadioTechnologyFamily format;
1444 uint8_t retry;
1445 int32_t messageRef;
1446
Mark Salyzyn961fd022015-04-09 07:18:35 -07001447 RLOGD("dispatchImsSms");
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001448 if (status != NO_ERROR) {
1449 goto invalid;
1450 }
1451 format = (RIL_RadioTechnologyFamily) t;
1452
1453 // read retry field
1454 status = p.read(&retry,sizeof(retry));
1455 if (status != NO_ERROR) {
1456 goto invalid;
1457 }
1458 // read messageRef field
1459 status = p.read(&messageRef,sizeof(messageRef));
1460 if (status != NO_ERROR) {
1461 goto invalid;
1462 }
1463
1464 if (RADIO_TECH_3GPP == format) {
1465 dispatchImsGsmSms(p, pRI, retry, messageRef);
1466 } else if (RADIO_TECH_3GPP2 == format) {
1467 dispatchImsCdmaSms(p, pRI, retry, messageRef);
1468 } else {
1469 ALOGE("requestImsSendSMS invalid format value =%d", format);
1470 }
1471
1472 return;
1473
1474invalid:
1475 invalidCommandBlock(pRI);
1476 return;
1477}
1478
1479static void
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001480dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI) {
1481 RIL_CDMA_SMS_Ack rcsa;
1482 int32_t t;
1483 status_t status;
1484 int32_t digitCount;
1485
Mark Salyzyn961fd022015-04-09 07:18:35 -07001486 RLOGD("dispatchCdmaSmsAck");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001487 memset(&rcsa, 0, sizeof(rcsa));
1488
1489 status = p.readInt32(&t);
1490 rcsa.uErrorClass = (RIL_CDMA_SMS_ErrorClass) t;
1491
1492 status = p.readInt32(&t);
1493 rcsa.uSMSCauseCode = (int) t;
1494
1495 if (status != NO_ERROR) {
1496 goto invalid;
1497 }
1498
1499 startRequest;
1500 appendPrintBuf("%suErrorClass=%d, uTLStatus=%d, ",
1501 printBuf, rcsa.uErrorClass, rcsa.uSMSCauseCode);
1502 closeRequest;
1503
1504 printRequest(pRI->token, pRI->pCI->requestNumber);
1505
Howard Sue32dbfd2015-01-07 15:55:57 +08001506 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsa, sizeof(rcsa),pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001507
1508#ifdef MEMSET_FREED
1509 memset(&rcsa, 0, sizeof(rcsa));
1510#endif
1511
1512 return;
1513
1514invalid:
1515 invalidCommandBlock(pRI);
1516 return;
1517}
1518
1519static void
1520dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1521 int32_t t;
1522 status_t status;
1523 int32_t num;
1524
1525 status = p.readInt32(&num);
1526 if (status != NO_ERROR) {
1527 goto invalid;
1528 }
1529
Ethan Chend6e30652013-08-04 22:49:56 -07001530 {
1531 RIL_GSM_BroadcastSmsConfigInfo gsmBci[num];
1532 RIL_GSM_BroadcastSmsConfigInfo *gsmBciPtrs[num];
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001533
Ethan Chend6e30652013-08-04 22:49:56 -07001534 startRequest;
1535 for (int i = 0 ; i < num ; i++ ) {
1536 gsmBciPtrs[i] = &gsmBci[i];
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001537
Ethan Chend6e30652013-08-04 22:49:56 -07001538 status = p.readInt32(&t);
1539 gsmBci[i].fromServiceId = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001540
Ethan Chend6e30652013-08-04 22:49:56 -07001541 status = p.readInt32(&t);
1542 gsmBci[i].toServiceId = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001543
Ethan Chend6e30652013-08-04 22:49:56 -07001544 status = p.readInt32(&t);
1545 gsmBci[i].fromCodeScheme = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001546
Ethan Chend6e30652013-08-04 22:49:56 -07001547 status = p.readInt32(&t);
1548 gsmBci[i].toCodeScheme = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001549
Ethan Chend6e30652013-08-04 22:49:56 -07001550 status = p.readInt32(&t);
1551 gsmBci[i].selected = (uint8_t) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001552
Ethan Chend6e30652013-08-04 22:49:56 -07001553 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId =%d, \
1554 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]", printBuf, i,
1555 gsmBci[i].fromServiceId, gsmBci[i].toServiceId,
1556 gsmBci[i].fromCodeScheme, gsmBci[i].toCodeScheme,
1557 gsmBci[i].selected);
1558 }
1559 closeRequest;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001560
Ethan Chend6e30652013-08-04 22:49:56 -07001561 if (status != NO_ERROR) {
1562 goto invalid;
1563 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001564
Howard Sue32dbfd2015-01-07 15:55:57 +08001565 CALL_ONREQUEST(pRI->pCI->requestNumber,
Ethan Chend6e30652013-08-04 22:49:56 -07001566 gsmBciPtrs,
1567 num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *),
Howard Sue32dbfd2015-01-07 15:55:57 +08001568 pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001569
1570#ifdef MEMSET_FREED
Ethan Chend6e30652013-08-04 22:49:56 -07001571 memset(gsmBci, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo));
1572 memset(gsmBciPtrs, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001573#endif
Ethan Chend6e30652013-08-04 22:49:56 -07001574 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001575
1576 return;
1577
1578invalid:
1579 invalidCommandBlock(pRI);
1580 return;
1581}
1582
1583static void
1584dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1585 int32_t t;
1586 status_t status;
1587 int32_t num;
1588
1589 status = p.readInt32(&num);
1590 if (status != NO_ERROR) {
1591 goto invalid;
1592 }
1593
Ethan Chend6e30652013-08-04 22:49:56 -07001594 {
1595 RIL_CDMA_BroadcastSmsConfigInfo cdmaBci[num];
1596 RIL_CDMA_BroadcastSmsConfigInfo *cdmaBciPtrs[num];
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001597
Ethan Chend6e30652013-08-04 22:49:56 -07001598 startRequest;
1599 for (int i = 0 ; i < num ; i++ ) {
1600 cdmaBciPtrs[i] = &cdmaBci[i];
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001601
Ethan Chend6e30652013-08-04 22:49:56 -07001602 status = p.readInt32(&t);
1603 cdmaBci[i].service_category = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001604
Ethan Chend6e30652013-08-04 22:49:56 -07001605 status = p.readInt32(&t);
1606 cdmaBci[i].language = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001607
Ethan Chend6e30652013-08-04 22:49:56 -07001608 status = p.readInt32(&t);
1609 cdmaBci[i].selected = (uint8_t) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001610
Ethan Chend6e30652013-08-04 22:49:56 -07001611 appendPrintBuf("%s [%d: service_category=%d, language =%d, \
1612 entries.bSelected =%d]", printBuf, i, cdmaBci[i].service_category,
1613 cdmaBci[i].language, cdmaBci[i].selected);
1614 }
1615 closeRequest;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001616
Ethan Chend6e30652013-08-04 22:49:56 -07001617 if (status != NO_ERROR) {
1618 goto invalid;
1619 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001620
Howard Sue32dbfd2015-01-07 15:55:57 +08001621 CALL_ONREQUEST(pRI->pCI->requestNumber,
Ethan Chend6e30652013-08-04 22:49:56 -07001622 cdmaBciPtrs,
1623 num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *),
Howard Sue32dbfd2015-01-07 15:55:57 +08001624 pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001625
1626#ifdef MEMSET_FREED
Ethan Chend6e30652013-08-04 22:49:56 -07001627 memset(cdmaBci, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo));
1628 memset(cdmaBciPtrs, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001629#endif
Ethan Chend6e30652013-08-04 22:49:56 -07001630 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001631
1632 return;
1633
1634invalid:
1635 invalidCommandBlock(pRI);
1636 return;
1637}
1638
1639static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI) {
1640 RIL_CDMA_SMS_WriteArgs rcsw;
1641 int32_t t;
1642 uint32_t ut;
1643 uint8_t uct;
1644 status_t status;
1645 int32_t digitCount;
Sukanya Rajkhowa70ecc092013-10-29 14:55:30 +08001646 int32_t digitLimit;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001647
1648 memset(&rcsw, 0, sizeof(rcsw));
1649
1650 status = p.readInt32(&t);
1651 rcsw.status = t;
1652
1653 status = p.readInt32(&t);
1654 rcsw.message.uTeleserviceID = (int) t;
1655
1656 status = p.read(&uct,sizeof(uct));
1657 rcsw.message.bIsServicePresent = (uint8_t) uct;
1658
1659 status = p.readInt32(&t);
1660 rcsw.message.uServicecategory = (int) t;
1661
1662 status = p.readInt32(&t);
1663 rcsw.message.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1664
1665 status = p.readInt32(&t);
1666 rcsw.message.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1667
1668 status = p.readInt32(&t);
1669 rcsw.message.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1670
1671 status = p.readInt32(&t);
1672 rcsw.message.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1673
1674 status = p.read(&uct,sizeof(uct));
1675 rcsw.message.sAddress.number_of_digits = (uint8_t) uct;
1676
Sukanya Rajkhowa70ecc092013-10-29 14:55:30 +08001677 digitLimit = MIN((rcsw.message.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
1678
1679 for(digitCount = 0 ; digitCount < digitLimit; digitCount ++) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001680 status = p.read(&uct,sizeof(uct));
1681 rcsw.message.sAddress.digits[digitCount] = (uint8_t) uct;
1682 }
1683
1684 status = p.readInt32(&t);
1685 rcsw.message.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1686
1687 status = p.read(&uct,sizeof(uct));
1688 rcsw.message.sSubAddress.odd = (uint8_t) uct;
1689
1690 status = p.read(&uct,sizeof(uct));
1691 rcsw.message.sSubAddress.number_of_digits = (uint8_t) uct;
1692
Sukanya Rajkhowa70ecc092013-10-29 14:55:30 +08001693 digitLimit = MIN((rcsw.message.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
1694
1695 for(digitCount = 0 ; digitCount < digitLimit; digitCount ++) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001696 status = p.read(&uct,sizeof(uct));
1697 rcsw.message.sSubAddress.digits[digitCount] = (uint8_t) uct;
1698 }
1699
1700 status = p.readInt32(&t);
1701 rcsw.message.uBearerDataLen = (int) t;
1702
Sukanya Rajkhowa70ecc092013-10-29 14:55:30 +08001703 digitLimit = MIN((rcsw.message.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
1704
1705 for(digitCount = 0 ; digitCount < digitLimit; digitCount ++) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001706 status = p.read(&uct, sizeof(uct));
1707 rcsw.message.aBearerData[digitCount] = (uint8_t) uct;
1708 }
1709
1710 if (status != NO_ERROR) {
1711 goto invalid;
1712 }
1713
1714 startRequest;
1715 appendPrintBuf("%sstatus=%d, message.uTeleserviceID=%d, message.bIsServicePresent=%d, \
1716 message.uServicecategory=%d, message.sAddress.digit_mode=%d, \
1717 message.sAddress.number_mode=%d, \
1718 message.sAddress.number_type=%d, ",
1719 printBuf, rcsw.status, rcsw.message.uTeleserviceID, rcsw.message.bIsServicePresent,
1720 rcsw.message.uServicecategory, rcsw.message.sAddress.digit_mode,
1721 rcsw.message.sAddress.number_mode,
1722 rcsw.message.sAddress.number_type);
1723 closeRequest;
1724
1725 printRequest(pRI->token, pRI->pCI->requestNumber);
1726
Howard Sue32dbfd2015-01-07 15:55:57 +08001727 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsw, sizeof(rcsw),pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001728
1729#ifdef MEMSET_FREED
1730 memset(&rcsw, 0, sizeof(rcsw));
1731#endif
1732
1733 return;
1734
1735invalid:
1736 invalidCommandBlock(pRI);
1737 return;
1738
1739}
1740
Ethan Chend6e30652013-08-04 22:49:56 -07001741// For backwards compatibility in RIL_REQUEST_SETUP_DATA_CALL.
1742// Version 4 of the RIL interface adds a new PDP type parameter to support
1743// IPv6 and dual-stack PDP contexts. When dealing with a previous version of
1744// RIL, remove the parameter from the request.
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001745static void dispatchDataCall(Parcel& p, RequestInfo *pRI) {
Ethan Chend6e30652013-08-04 22:49:56 -07001746 // In RIL v3, REQUEST_SETUP_DATA_CALL takes 6 parameters.
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001747 const int numParamsRilV3 = 6;
1748
Ethan Chend6e30652013-08-04 22:49:56 -07001749 // The first bytes of the RIL parcel contain the request number and the
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001750 // serial number - see processCommandBuffer(). Copy them over too.
1751 int pos = p.dataPosition();
1752
1753 int numParams = p.readInt32();
1754 if (s_callbacks.version < 4 && numParams > numParamsRilV3) {
1755 Parcel p2;
1756 p2.appendFrom(&p, 0, pos);
1757 p2.writeInt32(numParamsRilV3);
1758 for(int i = 0; i < numParamsRilV3; i++) {
1759 p2.writeString16(p.readString16());
1760 }
1761 p2.setDataPosition(pos);
1762 dispatchStrings(p2, pRI);
1763 } else {
1764 p.setDataPosition(pos);
1765 dispatchStrings(p, pRI);
1766 }
1767}
1768
1769// For backwards compatibility with RILs that dont support RIL_REQUEST_VOICE_RADIO_TECH.
Ethan Chend6e30652013-08-04 22:49:56 -07001770// When all RILs handle this request, this function can be removed and
1771// the request can be sent directly to the RIL using dispatchVoid.
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001772static void dispatchVoiceRadioTech(Parcel& p, RequestInfo *pRI) {
Howard Sue32dbfd2015-01-07 15:55:57 +08001773 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001774
1775 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1776 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1777 }
1778
Ethan Chend6e30652013-08-04 22:49:56 -07001779 // RILs that support RADIO_STATE_ON should support this request.
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001780 if (RADIO_STATE_ON == state) {
1781 dispatchVoid(p, pRI);
1782 return;
1783 }
1784
Ethan Chend6e30652013-08-04 22:49:56 -07001785 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1786 // will not support this new request either and decode Voice Radio Technology
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001787 // from Radio State
1788 voiceRadioTech = decodeVoiceRadioTechnology(state);
1789
1790 if (voiceRadioTech < 0)
1791 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1792 else
1793 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &voiceRadioTech, sizeof(int));
1794}
1795
Ethan Chend6e30652013-08-04 22:49:56 -07001796// For backwards compatibility in RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE:.
1797// When all RILs handle this request, this function can be removed and
1798// the request can be sent directly to the RIL using dispatchVoid.
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001799static void dispatchCdmaSubscriptionSource(Parcel& p, RequestInfo *pRI) {
Howard Sue32dbfd2015-01-07 15:55:57 +08001800 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001801
1802 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1803 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1804 }
1805
1806 // RILs that support RADIO_STATE_ON should support this request.
1807 if (RADIO_STATE_ON == state) {
1808 dispatchVoid(p, pRI);
1809 return;
1810 }
1811
Ethan Chend6e30652013-08-04 22:49:56 -07001812 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001813 // will not support this new request either and decode CDMA Subscription Source
Ethan Chend6e30652013-08-04 22:49:56 -07001814 // from Radio State
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001815 cdmaSubscriptionSource = decodeCdmaSubscriptionSource(state);
1816
1817 if (cdmaSubscriptionSource < 0)
1818 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1819 else
1820 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &cdmaSubscriptionSource, sizeof(int));
1821}
1822
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001823static void dispatchSetInitialAttachApn(Parcel &p, RequestInfo *pRI)
1824{
1825 RIL_InitialAttachApn pf;
1826 int32_t t;
1827 status_t status;
1828
1829 memset(&pf, 0, sizeof(pf));
1830
1831 pf.apn = strdupReadString(p);
1832 pf.protocol = strdupReadString(p);
1833
1834 status = p.readInt32(&t);
1835 pf.authtype = (int) t;
1836
1837 pf.username = strdupReadString(p);
1838 pf.password = strdupReadString(p);
1839
1840 startRequest;
1841 appendPrintBuf("%sapn=%s, protocol=%s, auth_type=%d, username=%s, password=%s",
Andreas Schneidera8d09502015-06-23 18:41:38 +02001842 printBuf, pf.apn, pf.protocol, pf.authtype, pf.username, pf.password);
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001843 closeRequest;
1844 printRequest(pRI->token, pRI->pCI->requestNumber);
1845
1846 if (status != NO_ERROR) {
1847 goto invalid;
1848 }
Howard Sue32dbfd2015-01-07 15:55:57 +08001849 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001850
1851#ifdef MEMSET_FREED
1852 memsetString(pf.apn);
1853 memsetString(pf.protocol);
1854 memsetString(pf.username);
1855 memsetString(pf.password);
1856#endif
1857
1858 free(pf.apn);
1859 free(pf.protocol);
1860 free(pf.username);
1861 free(pf.password);
1862
1863#ifdef MEMSET_FREED
1864 memset(&pf, 0, sizeof(pf));
1865#endif
1866
1867 return;
1868invalid:
1869 invalidCommandBlock(pRI);
1870 return;
1871}
1872
Howard Sue32dbfd2015-01-07 15:55:57 +08001873static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI) {
1874 RIL_NV_ReadItem nvri;
1875 int32_t t;
1876 status_t status;
1877
1878 memset(&nvri, 0, sizeof(nvri));
1879
1880 status = p.readInt32(&t);
1881 nvri.itemID = (RIL_NV_Item) t;
1882
1883 if (status != NO_ERROR) {
1884 goto invalid;
1885 }
1886
1887 startRequest;
1888 appendPrintBuf("%snvri.itemID=%d, ", printBuf, nvri.itemID);
1889 closeRequest;
1890
1891 printRequest(pRI->token, pRI->pCI->requestNumber);
1892
1893 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvri, sizeof(nvri), pRI, pRI->socket_id);
1894
1895#ifdef MEMSET_FREED
1896 memset(&nvri, 0, sizeof(nvri));
1897#endif
1898
1899 return;
1900
1901invalid:
1902 invalidCommandBlock(pRI);
1903 return;
1904}
1905
1906static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI) {
1907 RIL_NV_WriteItem nvwi;
1908 int32_t t;
1909 status_t status;
1910
1911 memset(&nvwi, 0, sizeof(nvwi));
1912
1913 status = p.readInt32(&t);
1914 nvwi.itemID = (RIL_NV_Item) t;
1915
1916 nvwi.value = strdupReadString(p);
1917
1918 if (status != NO_ERROR || nvwi.value == NULL) {
1919 goto invalid;
1920 }
1921
1922 startRequest;
1923 appendPrintBuf("%snvwi.itemID=%d, value=%s, ", printBuf, nvwi.itemID,
1924 nvwi.value);
1925 closeRequest;
1926
1927 printRequest(pRI->token, pRI->pCI->requestNumber);
1928
1929 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvwi, sizeof(nvwi), pRI, pRI->socket_id);
1930
1931#ifdef MEMSET_FREED
1932 memsetString(nvwi.value);
1933#endif
1934
1935 free(nvwi.value);
1936
1937#ifdef MEMSET_FREED
1938 memset(&nvwi, 0, sizeof(nvwi));
1939#endif
1940
1941 return;
1942
1943invalid:
1944 invalidCommandBlock(pRI);
1945 return;
1946}
1947
1948
1949static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI) {
1950 RIL_SelectUiccSub uicc_sub;
1951 status_t status;
1952 int32_t t;
1953 memset(&uicc_sub, 0, sizeof(uicc_sub));
1954
1955 status = p.readInt32(&t);
1956 if (status != NO_ERROR) {
1957 goto invalid;
1958 }
1959 uicc_sub.slot = (int) t;
1960
1961 status = p.readInt32(&t);
1962 if (status != NO_ERROR) {
1963 goto invalid;
1964 }
1965 uicc_sub.app_index = (int) t;
1966
1967 status = p.readInt32(&t);
1968 if (status != NO_ERROR) {
1969 goto invalid;
1970 }
1971 uicc_sub.sub_type = (RIL_SubscriptionType) t;
1972
1973 status = p.readInt32(&t);
1974 if (status != NO_ERROR) {
1975 goto invalid;
1976 }
1977 uicc_sub.act_status = (RIL_UiccSubActStatus) t;
1978
1979 startRequest;
1980 appendPrintBuf("slot=%d, app_index=%d, act_status = %d", uicc_sub.slot, uicc_sub.app_index,
1981 uicc_sub.act_status);
1982 RLOGD("dispatchUiccSubscription, slot=%d, app_index=%d, act_status = %d", uicc_sub.slot,
1983 uicc_sub.app_index, uicc_sub.act_status);
1984 closeRequest;
1985 printRequest(pRI->token, pRI->pCI->requestNumber);
1986
1987 CALL_ONREQUEST(pRI->pCI->requestNumber, &uicc_sub, sizeof(uicc_sub), pRI, pRI->socket_id);
1988
1989#ifdef MEMSET_FREED
1990 memset(&uicc_sub, 0, sizeof(uicc_sub));
1991#endif
1992 return;
1993
1994invalid:
1995 invalidCommandBlock(pRI);
1996 return;
1997}
1998
1999static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI)
2000{
2001 RIL_SimAuthentication pf;
2002 int32_t t;
2003 status_t status;
2004
2005 memset(&pf, 0, sizeof(pf));
2006
2007 status = p.readInt32(&t);
2008 pf.authContext = (int) t;
2009 pf.authData = strdupReadString(p);
2010 pf.aid = strdupReadString(p);
2011
2012 startRequest;
Andreas Schneidera8d09502015-06-23 18:41:38 +02002013 appendPrintBuf("authContext=%d, authData=%s, aid=%s", pf.authContext, pf.authData, pf.aid);
Howard Sue32dbfd2015-01-07 15:55:57 +08002014 closeRequest;
2015 printRequest(pRI->token, pRI->pCI->requestNumber);
2016
2017 if (status != NO_ERROR) {
2018 goto invalid;
2019 }
2020 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
2021
2022#ifdef MEMSET_FREED
2023 memsetString(pf.authData);
2024 memsetString(pf.aid);
2025#endif
2026
2027 free(pf.authData);
2028 free(pf.aid);
2029
2030#ifdef MEMSET_FREED
2031 memset(&pf, 0, sizeof(pf));
2032#endif
2033
2034 return;
2035invalid:
2036 invalidCommandBlock(pRI);
2037 return;
2038}
2039
2040static void dispatchDataProfile(Parcel &p, RequestInfo *pRI) {
2041 int32_t t;
2042 status_t status;
2043 int32_t num;
2044
2045 status = p.readInt32(&num);
2046 if (status != NO_ERROR) {
2047 goto invalid;
2048 }
2049
2050 {
Sanket Padawedf3dabe2016-02-29 10:09:26 -08002051 RIL_DataProfileInfo *dataProfiles =
2052 (RIL_DataProfileInfo *)malloc(num * sizeof(RIL_DataProfileInfo));
2053 if (dataProfiles == NULL) {
2054 RLOGE("Memory allocation failed for request %s",
2055 requestToString(pRI->pCI->requestNumber));
2056 return;
2057 }
2058 RIL_DataProfileInfo **dataProfilePtrs =
2059 (RIL_DataProfileInfo **)malloc(num * sizeof(RIL_DataProfileInfo *));
2060 if (dataProfilePtrs == NULL) {
2061 RLOGE("Memory allocation failed for request %s",
2062 requestToString(pRI->pCI->requestNumber));
2063 free(dataProfiles);
2064 return;
2065 }
Howard Sue32dbfd2015-01-07 15:55:57 +08002066
2067 startRequest;
2068 for (int i = 0 ; i < num ; i++ ) {
2069 dataProfilePtrs[i] = &dataProfiles[i];
2070
2071 status = p.readInt32(&t);
2072 dataProfiles[i].profileId = (int) t;
2073
2074 dataProfiles[i].apn = strdupReadString(p);
2075 dataProfiles[i].protocol = strdupReadString(p);
2076 status = p.readInt32(&t);
2077 dataProfiles[i].authType = (int) t;
2078
2079 dataProfiles[i].user = strdupReadString(p);
2080 dataProfiles[i].password = strdupReadString(p);
2081
2082 status = p.readInt32(&t);
2083 dataProfiles[i].type = (int) t;
2084
2085 status = p.readInt32(&t);
2086 dataProfiles[i].maxConnsTime = (int) t;
2087 status = p.readInt32(&t);
2088 dataProfiles[i].maxConns = (int) t;
2089 status = p.readInt32(&t);
2090 dataProfiles[i].waitTime = (int) t;
2091
2092 status = p.readInt32(&t);
2093 dataProfiles[i].enabled = (int) t;
2094
2095 appendPrintBuf("%s [%d: profileId=%d, apn =%s, protocol =%s, authType =%d, \
2096 user =%s, password =%s, type =%d, maxConnsTime =%d, maxConns =%d, \
2097 waitTime =%d, enabled =%d]", printBuf, i, dataProfiles[i].profileId,
2098 dataProfiles[i].apn, dataProfiles[i].protocol, dataProfiles[i].authType,
2099 dataProfiles[i].user, dataProfiles[i].password, dataProfiles[i].type,
2100 dataProfiles[i].maxConnsTime, dataProfiles[i].maxConns,
2101 dataProfiles[i].waitTime, dataProfiles[i].enabled);
2102 }
2103 closeRequest;
2104 printRequest(pRI->token, pRI->pCI->requestNumber);
2105
2106 if (status != NO_ERROR) {
Sanket Padawedf3dabe2016-02-29 10:09:26 -08002107 free(dataProfiles);
2108 free(dataProfilePtrs);
Howard Sue32dbfd2015-01-07 15:55:57 +08002109 goto invalid;
2110 }
2111 CALL_ONREQUEST(pRI->pCI->requestNumber,
2112 dataProfilePtrs,
2113 num * sizeof(RIL_DataProfileInfo *),
2114 pRI, pRI->socket_id);
2115
2116#ifdef MEMSET_FREED
2117 memset(dataProfiles, 0, num * sizeof(RIL_DataProfileInfo));
2118 memset(dataProfilePtrs, 0, num * sizeof(RIL_DataProfileInfo *));
2119#endif
Sanket Padawedf3dabe2016-02-29 10:09:26 -08002120 free(dataProfiles);
2121 free(dataProfilePtrs);
Howard Sue32dbfd2015-01-07 15:55:57 +08002122 }
2123
2124 return;
2125
2126invalid:
2127 invalidCommandBlock(pRI);
2128 return;
2129}
2130
Howard Subd82ef12015-04-12 10:25:05 +02002131static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI){
2132 RIL_RadioCapability rc;
2133 int32_t t;
2134 status_t status;
2135
2136 memset (&rc, 0, sizeof(RIL_RadioCapability));
2137
2138 status = p.readInt32(&t);
2139 rc.version = (int)t;
2140 if (status != NO_ERROR) {
2141 goto invalid;
2142 }
2143
2144 status = p.readInt32(&t);
2145 rc.session= (int)t;
2146 if (status != NO_ERROR) {
2147 goto invalid;
2148 }
2149
2150 status = p.readInt32(&t);
2151 rc.phase= (int)t;
2152 if (status != NO_ERROR) {
2153 goto invalid;
2154 }
2155
2156 status = p.readInt32(&t);
2157 rc.rat = (int)t;
2158 if (status != NO_ERROR) {
2159 goto invalid;
2160 }
2161
2162 status = readStringFromParcelInplace(p, rc.logicalModemUuid, sizeof(rc.logicalModemUuid));
2163 if (status != NO_ERROR) {
2164 goto invalid;
2165 }
2166
2167 status = p.readInt32(&t);
2168 rc.status = (int)t;
2169
2170 if (status != NO_ERROR) {
2171 goto invalid;
2172 }
2173
2174 startRequest;
2175 appendPrintBuf("%s [version:%d, session:%d, phase:%d, rat:%d, \
Andreas Schneidera8d09502015-06-23 18:41:38 +02002176 logicalModemUuid:%s, status:%d", printBuf, rc.version, rc.session,
2177 rc.phase, rc.rat, rc.logicalModemUuid, rc.status);
Howard Subd82ef12015-04-12 10:25:05 +02002178
2179 closeRequest;
2180 printRequest(pRI->token, pRI->pCI->requestNumber);
2181
2182 CALL_ONREQUEST(pRI->pCI->requestNumber,
2183 &rc,
2184 sizeof(RIL_RadioCapability),
2185 pRI, pRI->socket_id);
2186 return;
2187invalid:
2188 invalidCommandBlock(pRI);
2189 return;
2190}
2191
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002192static int
2193blockingWrite(int fd, const void *buffer, size_t len) {
2194 size_t writeOffset = 0;
2195 const uint8_t *toWrite;
2196
2197 toWrite = (const uint8_t *)buffer;
2198
2199 while (writeOffset < len) {
2200 ssize_t written;
2201 do {
2202 written = write (fd, toWrite + writeOffset,
2203 len - writeOffset);
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002204 } while (written < 0 && ((errno == EINTR) || (errno == EAGAIN)));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002205
2206 if (written >= 0) {
2207 writeOffset += written;
2208 } else { // written < 0
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002209 RLOGE ("RIL Response: unexpected error on write errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002210 close(fd);
2211 return -1;
2212 }
2213 }
Robert Greenwaltbc29c432015-04-29 16:57:39 -07002214#if VDBG
Dheeraj Shettycc231012014-07-02 21:27:57 +02002215 RLOGE("RIL Response bytes written:%d", writeOffset);
Robert Greenwaltbc29c432015-04-29 16:57:39 -07002216#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002217 return 0;
2218}
2219
2220static int
Howard Sue32dbfd2015-01-07 15:55:57 +08002221sendResponseRaw (const void *data, size_t dataSize, RIL_SOCKET_ID socket_id) {
2222 int fd = s_ril_param_socket.fdCommand;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002223 int ret;
2224 uint32_t header;
Howard Sue32dbfd2015-01-07 15:55:57 +08002225 pthread_mutex_t * writeMutexHook = &s_writeMutex;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002226
Robert Greenwaltbc29c432015-04-29 16:57:39 -07002227#if VDBG
Andreas Schneider822b70b2015-10-23 08:36:26 +02002228 RLOGD("Send Response to %s", rilSocketIdToString(socket_id));
Robert Greenwaltbc29c432015-04-29 16:57:39 -07002229#endif
Howard Sue32dbfd2015-01-07 15:55:57 +08002230
2231#if (SIM_COUNT >= 2)
2232 if (socket_id == RIL_SOCKET_2) {
2233 fd = s_ril_param_socket2.fdCommand;
2234 writeMutexHook = &s_writeMutex_socket2;
2235 }
2236#if (SIM_COUNT >= 3)
2237 else if (socket_id == RIL_SOCKET_3) {
2238 fd = s_ril_param_socket3.fdCommand;
2239 writeMutexHook = &s_writeMutex_socket3;
2240 }
2241#endif
2242#if (SIM_COUNT >= 4)
2243 else if (socket_id == RIL_SOCKET_4) {
2244 fd = s_ril_param_socket4.fdCommand;
2245 writeMutexHook = &s_writeMutex_socket4;
2246 }
2247#endif
2248#endif
2249 if (fd < 0) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002250 return -1;
2251 }
2252
Howard Subd82ef12015-04-12 10:25:05 +02002253 if (dataSize > MAX_COMMAND_BYTES) {
2254 RLOGE("RIL: packet larger than %u (%u)",
2255 MAX_COMMAND_BYTES, (unsigned int )dataSize);
2256
2257 return -1;
2258 }
2259
Howard Sue32dbfd2015-01-07 15:55:57 +08002260 pthread_mutex_lock(writeMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002261
2262 header = htonl(dataSize);
2263
2264 ret = blockingWrite(fd, (void *)&header, sizeof(header));
2265
2266 if (ret < 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002267 pthread_mutex_unlock(writeMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002268 return ret;
2269 }
2270
2271 ret = blockingWrite(fd, data, dataSize);
2272
2273 if (ret < 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002274 pthread_mutex_unlock(writeMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002275 return ret;
2276 }
2277
Howard Sue32dbfd2015-01-07 15:55:57 +08002278 pthread_mutex_unlock(writeMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002279
2280 return 0;
2281}
2282
2283static int
Howard Sue32dbfd2015-01-07 15:55:57 +08002284sendResponse (Parcel &p, RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002285 printResponse;
Howard Sue32dbfd2015-01-07 15:55:57 +08002286 return sendResponseRaw(p.data(), p.dataSize(), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002287}
2288
Howard Sue32dbfd2015-01-07 15:55:57 +08002289/** response is an int* pointing to an array of ints */
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002290
2291static int
2292responseInts(Parcel &p, void *response, size_t responselen) {
2293 int numInts;
2294
2295 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002296 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002297 return RIL_ERRNO_INVALID_RESPONSE;
2298 }
2299 if (responselen % sizeof(int) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002300 RLOGE("responseInts: invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002301 (int)responselen, (int)sizeof(int));
2302 return RIL_ERRNO_INVALID_RESPONSE;
2303 }
2304
2305 int *p_int = (int *) response;
2306
Howard Sue32dbfd2015-01-07 15:55:57 +08002307 numInts = responselen / sizeof(int);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002308 p.writeInt32 (numInts);
2309
2310 /* each int*/
2311 startResponse;
2312 for (int i = 0 ; i < numInts ; i++) {
2313 appendPrintBuf("%s%d,", printBuf, p_int[i]);
2314 p.writeInt32(p_int[i]);
2315 }
2316 removeLastChar;
2317 closeResponse;
2318
2319 return 0;
2320}
2321
Daniel Hillenbrandd0b84162015-04-12 11:53:23 +02002322static int
2323responseIntsGetPreferredNetworkType(Parcel &p, void *response, size_t responselen) {
2324 int numInts;
2325
2326 if (response == NULL && responselen != 0) {
2327 RLOGE("invalid response: NULL");
2328 return RIL_ERRNO_INVALID_RESPONSE;
2329 }
2330 if (responselen % sizeof(int) != 0) {
2331 RLOGE("responseInts: invalid response length %d expected multiple of %d\n",
2332 (int)responselen, (int)sizeof(int));
2333 return RIL_ERRNO_INVALID_RESPONSE;
2334 }
2335
2336 int *p_int = (int *) response;
2337
2338 numInts = responselen / sizeof(int);
2339 p.writeInt32 (numInts);
2340
2341 /* each int*/
2342 startResponse;
2343 for (int i = 0 ; i < numInts ; i++) {
2344 if (i == 0 && p_int[0] == 7) {
2345 RLOGD("REQUEST_GET_PREFERRED_NETWORK_TYPE: NETWORK_MODE_GLOBAL => NETWORK_MODE_WCDMA_PREF");
2346 p_int[0] = 0;
2347 }
2348 appendPrintBuf("%s%d,", printBuf, p_int[i]);
2349 p.writeInt32(p_int[i]);
2350 }
2351 removeLastChar;
2352 closeResponse;
2353
2354 return 0;
2355}
2356
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002357/** response is a char **, pointing to an array of char *'s
2358 The parcel will begin with the version */
2359static int responseStringsWithVersion(int version, Parcel &p, void *response, size_t responselen) {
2360 p.writeInt32(version);
2361 return responseStrings(p, response, responselen);
2362}
2363
2364/** response is a char **, pointing to an array of char *'s */
2365static int responseStrings(Parcel &p, void *response, size_t responselen) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002366 int numStrings;
2367
2368 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002369 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002370 return RIL_ERRNO_INVALID_RESPONSE;
2371 }
2372 if (responselen % sizeof(char *) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002373 RLOGE("responseStrings: invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002374 (int)responselen, (int)sizeof(char *));
2375 return RIL_ERRNO_INVALID_RESPONSE;
2376 }
2377
2378 if (response == NULL) {
2379 p.writeInt32 (0);
2380 } else {
2381 char **p_cur = (char **) response;
2382
2383 numStrings = responselen / sizeof(char *);
Dheeraj CVR48d3f722016-10-04 11:10:55 +04002384 p.writeInt32 (numStrings);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002385
2386 /* each string*/
2387 startResponse;
2388 for (int i = 0 ; i < numStrings ; i++) {
2389 appendPrintBuf("%s%s,", printBuf, (char*)p_cur[i]);
2390 writeStringToParcel (p, p_cur[i]);
2391 }
2392 removeLastChar;
2393 closeResponse;
2394 }
2395 return 0;
2396}
2397
Howard Subd82ef12015-04-12 10:25:05 +02002398
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002399/**
2400 * NULL strings are accepted
2401 * FIXME currently ignores responselen
2402 */
2403static int responseString(Parcel &p, void *response, size_t responselen) {
2404 /* one string only */
2405 startResponse;
2406 appendPrintBuf("%s%s", printBuf, (char*)response);
2407 closeResponse;
2408
2409 writeStringToParcel(p, (const char *)response);
2410
2411 return 0;
2412}
2413
2414static int responseVoid(Parcel &p, void *response, size_t responselen) {
2415 startResponse;
2416 removeLastChar;
2417 return 0;
2418}
2419
2420static int responseCallList(Parcel &p, void *response, size_t responselen) {
2421 int num;
2422
2423 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002424 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002425 return RIL_ERRNO_INVALID_RESPONSE;
2426 }
2427
2428 if (responselen % sizeof (RIL_Call *) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002429 RLOGE("responseCallList: invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002430 (int)responselen, (int)sizeof (RIL_Call *));
2431 return RIL_ERRNO_INVALID_RESPONSE;
2432 }
2433
2434 startResponse;
2435 /* number of call info's */
2436 num = responselen / sizeof(RIL_Call *);
2437 p.writeInt32(num);
2438
2439 for (int i = 0 ; i < num ; i++) {
2440 RIL_Call *p_cur = ((RIL_Call **) response)[i];
2441 /* each call info */
2442 p.writeInt32(p_cur->state);
2443 p.writeInt32(p_cur->index);
2444 p.writeInt32(p_cur->toa);
2445 p.writeInt32(p_cur->isMpty);
2446 p.writeInt32(p_cur->isMT);
2447 p.writeInt32(p_cur->als);
2448 p.writeInt32(p_cur->isVoice);
Andreas Schneider29472682015-01-01 19:00:04 +01002449
Christopher N. Hesse621e63e2016-02-22 21:57:39 +01002450#ifdef NEEDS_VIDEO_CALL_FIELD
Andreas Schneider29472682015-01-01 19:00:04 +01002451 p.writeInt32(p_cur->isVideo);
Sayd1052772015-12-13 17:25:01 +09002452#endif
Andreas Schneider29472682015-01-01 19:00:04 +01002453
Christopher N. Hesse621e63e2016-02-22 21:57:39 +01002454#ifdef SAMSUNG_NEXT_GEN_MODEM
Andreas Schneider29472682015-01-01 19:00:04 +01002455 /* Pass CallDetails */
2456 p.writeInt32(0);
2457 p.writeInt32(0);
2458 writeStringToParcel(p, "");
2459#endif
2460
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002461 p.writeInt32(p_cur->isVoicePrivacy);
2462 writeStringToParcel(p, p_cur->number);
2463 p.writeInt32(p_cur->numberPresentation);
2464 writeStringToParcel(p, p_cur->name);
2465 p.writeInt32(p_cur->namePresentation);
2466 // Remove when partners upgrade to version 3
2467 if ((s_callbacks.version < 3) || (p_cur->uusInfo == NULL || p_cur->uusInfo->uusData == NULL)) {
2468 p.writeInt32(0); /* UUS Information is absent */
2469 } else {
2470 RIL_UUS_Info *uusInfo = p_cur->uusInfo;
2471 p.writeInt32(1); /* UUS Information is present */
2472 p.writeInt32(uusInfo->uusType);
2473 p.writeInt32(uusInfo->uusDcs);
2474 p.writeInt32(uusInfo->uusLength);
2475 p.write(uusInfo->uusData, uusInfo->uusLength);
2476 }
2477 appendPrintBuf("%s[id=%d,%s,toa=%d,",
2478 printBuf,
2479 p_cur->index,
2480 callStateToString(p_cur->state),
2481 p_cur->toa);
2482 appendPrintBuf("%s%s,%s,als=%d,%s,%s,",
2483 printBuf,
2484 (p_cur->isMpty)?"conf":"norm",
2485 (p_cur->isMT)?"mt":"mo",
2486 p_cur->als,
2487 (p_cur->isVoice)?"voc":"nonvoc",
2488 (p_cur->isVoicePrivacy)?"evp":"noevp");
Christopher N. Hesse621e63e2016-02-22 21:57:39 +01002489#ifdef SAMSUNG_NEXT_GEN_MODEM
Andreas Schneider29472682015-01-01 19:00:04 +01002490 appendPrintBuf("%s,%s,",
2491 printBuf,
2492 (p_cur->isVideo) ? "vid" : "novid");
2493#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002494 appendPrintBuf("%s%s,cli=%d,name='%s',%d]",
2495 printBuf,
2496 p_cur->number,
2497 p_cur->numberPresentation,
2498 p_cur->name,
2499 p_cur->namePresentation);
2500 }
2501 removeLastChar;
2502 closeResponse;
2503
2504 return 0;
2505}
2506
2507static int responseSMS(Parcel &p, void *response, size_t responselen) {
2508 if (response == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002509 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002510 return RIL_ERRNO_INVALID_RESPONSE;
2511 }
2512
2513 if (responselen != sizeof (RIL_SMS_Response) ) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002514 RLOGE("invalid response length %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002515 (int)responselen, (int)sizeof (RIL_SMS_Response));
2516 return RIL_ERRNO_INVALID_RESPONSE;
2517 }
2518
2519 RIL_SMS_Response *p_cur = (RIL_SMS_Response *) response;
2520
2521 p.writeInt32(p_cur->messageRef);
2522 writeStringToParcel(p, p_cur->ackPDU);
2523 p.writeInt32(p_cur->errorCode);
2524
2525 startResponse;
2526 appendPrintBuf("%s%d,%s,%d", printBuf, p_cur->messageRef,
2527 (char*)p_cur->ackPDU, p_cur->errorCode);
2528 closeResponse;
2529
2530 return 0;
2531}
2532
2533static int responseDataCallListV4(Parcel &p, void *response, size_t responselen)
2534{
2535 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002536 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002537 return RIL_ERRNO_INVALID_RESPONSE;
2538 }
2539
2540 if (responselen % sizeof(RIL_Data_Call_Response_v4) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002541 RLOGE("responseDataCallListV4: invalid response length %d expected multiple of %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002542 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v4));
2543 return RIL_ERRNO_INVALID_RESPONSE;
2544 }
2545
Howard Sue32dbfd2015-01-07 15:55:57 +08002546 // Write version
2547 p.writeInt32(4);
2548
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002549 int num = responselen / sizeof(RIL_Data_Call_Response_v4);
2550 p.writeInt32(num);
2551
2552 RIL_Data_Call_Response_v4 *p_cur = (RIL_Data_Call_Response_v4 *) response;
2553 startResponse;
2554 int i;
2555 for (i = 0; i < num; i++) {
2556 p.writeInt32(p_cur[i].cid);
2557 p.writeInt32(p_cur[i].active);
2558 writeStringToParcel(p, p_cur[i].type);
2559 // apn is not used, so don't send.
2560 writeStringToParcel(p, p_cur[i].address);
2561 appendPrintBuf("%s[cid=%d,%s,%s,%s],", printBuf,
2562 p_cur[i].cid,
2563 (p_cur[i].active==0)?"down":"up",
2564 (char*)p_cur[i].type,
2565 (char*)p_cur[i].address);
2566 }
2567 removeLastChar;
2568 closeResponse;
2569
2570 return 0;
2571}
2572
Howard Sue32dbfd2015-01-07 15:55:57 +08002573static int responseDataCallListV6(Parcel &p, void *response, size_t responselen)
2574{
2575 if (response == NULL && responselen != 0) {
2576 RLOGE("invalid response: NULL");
2577 return RIL_ERRNO_INVALID_RESPONSE;
2578 }
2579
2580 if (responselen % sizeof(RIL_Data_Call_Response_v6) != 0) {
2581 RLOGE("responseDataCallListV6: invalid response length %d expected multiple of %d",
2582 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v6));
2583 return RIL_ERRNO_INVALID_RESPONSE;
2584 }
2585
2586 // Write version
2587 p.writeInt32(6);
2588
2589 int num = responselen / sizeof(RIL_Data_Call_Response_v6);
2590 p.writeInt32(num);
2591
2592 RIL_Data_Call_Response_v6 *p_cur = (RIL_Data_Call_Response_v6 *) response;
2593 startResponse;
2594 int i;
2595 for (i = 0; i < num; i++) {
2596 p.writeInt32((int)p_cur[i].status);
2597 p.writeInt32(p_cur[i].suggestedRetryTime);
2598 p.writeInt32(p_cur[i].cid);
2599 p.writeInt32(p_cur[i].active);
2600 writeStringToParcel(p, p_cur[i].type);
2601 writeStringToParcel(p, p_cur[i].ifname);
2602 writeStringToParcel(p, p_cur[i].addresses);
2603 writeStringToParcel(p, p_cur[i].dnses);
2604 writeStringToParcel(p, p_cur[i].addresses);
2605 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s],", printBuf,
2606 p_cur[i].status,
2607 p_cur[i].suggestedRetryTime,
2608 p_cur[i].cid,
2609 (p_cur[i].active==0)?"down":"up",
2610 (char*)p_cur[i].type,
2611 (char*)p_cur[i].ifname,
2612 (char*)p_cur[i].addresses,
2613 (char*)p_cur[i].dnses,
2614 (char*)p_cur[i].addresses);
2615 }
2616 removeLastChar;
2617 closeResponse;
2618
2619 return 0;
2620}
2621
Howard Subd82ef12015-04-12 10:25:05 +02002622static int responseDataCallListV9(Parcel &p, void *response, size_t responselen)
2623{
2624 if (response == NULL && responselen != 0) {
2625 RLOGE("invalid response: NULL");
2626 return RIL_ERRNO_INVALID_RESPONSE;
2627 }
2628
2629 if (responselen % sizeof(RIL_Data_Call_Response_v9) != 0) {
2630 RLOGE("responseDataCallListV9: invalid response length %d expected multiple of %d",
2631 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v9));
2632 return RIL_ERRNO_INVALID_RESPONSE;
2633 }
2634
2635 // Write version
2636 p.writeInt32(10);
2637
2638 int num = responselen / sizeof(RIL_Data_Call_Response_v9);
2639 p.writeInt32(num);
2640
2641 RIL_Data_Call_Response_v9 *p_cur = (RIL_Data_Call_Response_v9 *) response;
2642 startResponse;
2643 int i;
2644 for (i = 0; i < num; i++) {
2645 p.writeInt32((int)p_cur[i].status);
2646 p.writeInt32(p_cur[i].suggestedRetryTime);
2647 p.writeInt32(p_cur[i].cid);
2648 p.writeInt32(p_cur[i].active);
2649 writeStringToParcel(p, p_cur[i].type);
2650 writeStringToParcel(p, p_cur[i].ifname);
2651 writeStringToParcel(p, p_cur[i].addresses);
2652 writeStringToParcel(p, p_cur[i].dnses);
2653 writeStringToParcel(p, p_cur[i].gateways);
2654 writeStringToParcel(p, p_cur[i].pcscf);
2655 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s],", printBuf,
2656 p_cur[i].status,
2657 p_cur[i].suggestedRetryTime,
2658 p_cur[i].cid,
2659 (p_cur[i].active==0)?"down":"up",
2660 (char*)p_cur[i].type,
2661 (char*)p_cur[i].ifname,
2662 (char*)p_cur[i].addresses,
2663 (char*)p_cur[i].dnses,
2664 (char*)p_cur[i].gateways,
2665 (char*)p_cur[i].pcscf);
2666 }
2667 removeLastChar;
2668 closeResponse;
2669
2670 return 0;
2671}
2672
Sanket Padawe9343e872016-01-11 12:45:43 -08002673static int responseDataCallListV11(Parcel &p, void *response, size_t responselen) {
2674 if (response == NULL && responselen != 0) {
2675 RLOGE("invalid response: NULL");
2676 return RIL_ERRNO_INVALID_RESPONSE;
2677 }
2678
2679 if (responselen % sizeof(RIL_Data_Call_Response_v11) != 0) {
2680 RLOGE("invalid response length %d expected multiple of %d",
2681 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v11));
2682 return RIL_ERRNO_INVALID_RESPONSE;
2683 }
2684
2685 // Write version
2686 p.writeInt32(11);
2687
2688 int num = responselen / sizeof(RIL_Data_Call_Response_v11);
2689 p.writeInt32(num);
2690
2691 RIL_Data_Call_Response_v11 *p_cur = (RIL_Data_Call_Response_v11 *) response;
2692 startResponse;
2693 int i;
2694 for (i = 0; i < num; i++) {
2695 p.writeInt32((int)p_cur[i].status);
2696 p.writeInt32(p_cur[i].suggestedRetryTime);
2697 p.writeInt32(p_cur[i].cid);
2698 p.writeInt32(p_cur[i].active);
2699 writeStringToParcel(p, p_cur[i].type);
2700 writeStringToParcel(p, p_cur[i].ifname);
2701 writeStringToParcel(p, p_cur[i].addresses);
2702 writeStringToParcel(p, p_cur[i].dnses);
2703 writeStringToParcel(p, p_cur[i].gateways);
2704 writeStringToParcel(p, p_cur[i].pcscf);
2705 p.writeInt32(p_cur[i].mtu);
2706 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s,mtu=%d],", printBuf,
2707 p_cur[i].status,
2708 p_cur[i].suggestedRetryTime,
2709 p_cur[i].cid,
2710 (p_cur[i].active==0)?"down":"up",
2711 (char*)p_cur[i].type,
2712 (char*)p_cur[i].ifname,
2713 (char*)p_cur[i].addresses,
2714 (char*)p_cur[i].dnses,
2715 (char*)p_cur[i].gateways,
2716 (char*)p_cur[i].pcscf,
2717 p_cur[i].mtu);
2718 }
2719 removeLastChar;
2720 closeResponse;
2721
2722 return 0;
2723}
Howard Subd82ef12015-04-12 10:25:05 +02002724
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002725static int responseDataCallList(Parcel &p, void *response, size_t responselen)
2726{
Sanket Padawe9343e872016-01-11 12:45:43 -08002727 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
2728 if (s_callbacks.version < 5) {
2729 RLOGD("responseDataCallList: v4");
2730 return responseDataCallListV4(p, response, responselen);
2731 } else if (responselen % sizeof(RIL_Data_Call_Response_v6) == 0) {
2732 return responseDataCallListV6(p, response, responselen);
2733 } else if (responselen % sizeof(RIL_Data_Call_Response_v9) == 0) {
2734 return responseDataCallListV9(p, response, responselen);
2735 } else {
2736 return responseDataCallListV11(p, response, responselen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002737 }
Sanket Padawea79128a2016-01-26 18:44:01 -08002738 } else { // RIL version >= 13
Howard Subd82ef12015-04-12 10:25:05 +02002739 if (responselen % sizeof(RIL_Data_Call_Response_v11) != 0) {
Sanket Padawe9343e872016-01-11 12:45:43 -08002740 RLOGE("Data structure expected is RIL_Data_Call_Response_v11");
2741 if (!isDebuggable()) {
2742 return RIL_ERRNO_INVALID_RESPONSE;
2743 } else {
2744 assert(0);
2745 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002746 }
Sanket Padawe9343e872016-01-11 12:45:43 -08002747 return responseDataCallListV11(p, response, responselen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002748 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002749}
2750
2751static int responseSetupDataCall(Parcel &p, void *response, size_t responselen)
2752{
2753 if (s_callbacks.version < 5) {
2754 return responseStringsWithVersion(s_callbacks.version, p, response, responselen);
2755 } else {
2756 return responseDataCallList(p, response, responselen);
2757 }
2758}
2759
2760static int responseRaw(Parcel &p, void *response, size_t responselen) {
2761 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002762 RLOGE("invalid response: NULL with responselen != 0");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002763 return RIL_ERRNO_INVALID_RESPONSE;
2764 }
2765
2766 // The java code reads -1 size as null byte array
2767 if (response == NULL) {
2768 p.writeInt32(-1);
2769 } else {
2770 p.writeInt32(responselen);
2771 p.write(response, responselen);
2772 }
2773
2774 return 0;
2775}
2776
2777
2778static int responseSIM_IO(Parcel &p, void *response, size_t responselen) {
2779 if (response == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002780 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002781 return RIL_ERRNO_INVALID_RESPONSE;
2782 }
2783
2784 if (responselen != sizeof (RIL_SIM_IO_Response) ) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002785 RLOGE("invalid response length was %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002786 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
2787 return RIL_ERRNO_INVALID_RESPONSE;
2788 }
2789
2790 RIL_SIM_IO_Response *p_cur = (RIL_SIM_IO_Response *) response;
2791 p.writeInt32(p_cur->sw1);
2792 p.writeInt32(p_cur->sw2);
2793 writeStringToParcel(p, p_cur->simResponse);
2794
2795 startResponse;
2796 appendPrintBuf("%ssw1=0x%X,sw2=0x%X,%s", printBuf, p_cur->sw1, p_cur->sw2,
2797 (char*)p_cur->simResponse);
2798 closeResponse;
2799
2800
2801 return 0;
2802}
2803
2804static int responseCallForwards(Parcel &p, void *response, size_t responselen) {
2805 int num;
2806
2807 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002808 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002809 return RIL_ERRNO_INVALID_RESPONSE;
2810 }
2811
2812 if (responselen % sizeof(RIL_CallForwardInfo *) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002813 RLOGE("responseCallForwards: invalid response length %d expected multiple of %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002814 (int)responselen, (int)sizeof(RIL_CallForwardInfo *));
2815 return RIL_ERRNO_INVALID_RESPONSE;
2816 }
2817
2818 /* number of call info's */
2819 num = responselen / sizeof(RIL_CallForwardInfo *);
2820 p.writeInt32(num);
2821
2822 startResponse;
2823 for (int i = 0 ; i < num ; i++) {
2824 RIL_CallForwardInfo *p_cur = ((RIL_CallForwardInfo **) response)[i];
2825
2826 p.writeInt32(p_cur->status);
2827 p.writeInt32(p_cur->reason);
2828 p.writeInt32(p_cur->serviceClass);
2829 p.writeInt32(p_cur->toa);
2830 writeStringToParcel(p, p_cur->number);
2831 p.writeInt32(p_cur->timeSeconds);
2832 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
2833 (p_cur->status==1)?"enable":"disable",
2834 p_cur->reason, p_cur->serviceClass, p_cur->toa,
2835 (char*)p_cur->number,
2836 p_cur->timeSeconds);
2837 }
2838 removeLastChar;
2839 closeResponse;
2840
2841 return 0;
2842}
2843
2844static int responseSsn(Parcel &p, void *response, size_t responselen) {
2845 if (response == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002846 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002847 return RIL_ERRNO_INVALID_RESPONSE;
2848 }
2849
2850 if (responselen != sizeof(RIL_SuppSvcNotification)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002851 RLOGE("invalid response length was %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002852 (int)responselen, (int)sizeof (RIL_SuppSvcNotification));
2853 return RIL_ERRNO_INVALID_RESPONSE;
2854 }
2855
2856 RIL_SuppSvcNotification *p_cur = (RIL_SuppSvcNotification *) response;
2857 p.writeInt32(p_cur->notificationType);
2858 p.writeInt32(p_cur->code);
2859 p.writeInt32(p_cur->index);
2860 p.writeInt32(p_cur->type);
2861 writeStringToParcel(p, p_cur->number);
2862
2863 startResponse;
2864 appendPrintBuf("%s%s,code=%d,id=%d,type=%d,%s", printBuf,
2865 (p_cur->notificationType==0)?"mo":"mt",
2866 p_cur->code, p_cur->index, p_cur->type,
2867 (char*)p_cur->number);
2868 closeResponse;
2869
2870 return 0;
2871}
2872
2873static int responseCellList(Parcel &p, void *response, size_t responselen) {
2874 int num;
2875
2876 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002877 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002878 return RIL_ERRNO_INVALID_RESPONSE;
2879 }
2880
2881 if (responselen % sizeof (RIL_NeighboringCell *) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002882 RLOGE("responseCellList: invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002883 (int)responselen, (int)sizeof (RIL_NeighboringCell *));
2884 return RIL_ERRNO_INVALID_RESPONSE;
2885 }
2886
2887 startResponse;
2888 /* number of records */
2889 num = responselen / sizeof(RIL_NeighboringCell *);
2890 p.writeInt32(num);
2891
2892 for (int i = 0 ; i < num ; i++) {
2893 RIL_NeighboringCell *p_cur = ((RIL_NeighboringCell **) response)[i];
2894
2895 p.writeInt32(p_cur->rssi);
2896 writeStringToParcel (p, p_cur->cid);
2897
2898 appendPrintBuf("%s[cid=%s,rssi=%d],", printBuf,
2899 p_cur->cid, p_cur->rssi);
2900 }
2901 removeLastChar;
2902 closeResponse;
2903
2904 return 0;
2905}
2906
2907/**
2908 * Marshall the signalInfoRecord into the parcel if it exists.
2909 */
2910static void marshallSignalInfoRecord(Parcel &p,
2911 RIL_CDMA_SignalInfoRecord &p_signalInfoRecord) {
2912 p.writeInt32(p_signalInfoRecord.isPresent);
2913 p.writeInt32(p_signalInfoRecord.signalType);
2914 p.writeInt32(p_signalInfoRecord.alertPitch);
2915 p.writeInt32(p_signalInfoRecord.signal);
2916}
2917
2918static int responseCdmaInformationRecords(Parcel &p,
2919 void *response, size_t responselen) {
2920 int num;
2921 char* string8 = NULL;
2922 int buffer_lenght;
2923 RIL_CDMA_InformationRecord *infoRec;
2924
2925 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002926 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002927 return RIL_ERRNO_INVALID_RESPONSE;
2928 }
2929
2930 if (responselen != sizeof (RIL_CDMA_InformationRecords)) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002931 RLOGE("responseCdmaInformationRecords: invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002932 (int)responselen, (int)sizeof (RIL_CDMA_InformationRecords *));
2933 return RIL_ERRNO_INVALID_RESPONSE;
2934 }
2935
2936 RIL_CDMA_InformationRecords *p_cur =
2937 (RIL_CDMA_InformationRecords *) response;
2938 num = MIN(p_cur->numberOfInfoRecs, RIL_CDMA_MAX_NUMBER_OF_INFO_RECS);
2939
2940 startResponse;
2941 p.writeInt32(num);
2942
2943 for (int i = 0 ; i < num ; i++) {
2944 infoRec = &p_cur->infoRec[i];
2945 p.writeInt32(infoRec->name);
2946 switch (infoRec->name) {
2947 case RIL_CDMA_DISPLAY_INFO_REC:
2948 case RIL_CDMA_EXTENDED_DISPLAY_INFO_REC:
2949 if (infoRec->rec.display.alpha_len >
2950 CDMA_ALPHA_INFO_BUFFER_LENGTH) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002951 RLOGE("invalid display info response length %d \
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002952 expected not more than %d\n",
2953 (int)infoRec->rec.display.alpha_len,
2954 CDMA_ALPHA_INFO_BUFFER_LENGTH);
2955 return RIL_ERRNO_INVALID_RESPONSE;
2956 }
2957 string8 = (char*) malloc((infoRec->rec.display.alpha_len + 1)
2958 * sizeof(char) );
Sanket Padawedf3dabe2016-02-29 10:09:26 -08002959 if (string8 == NULL) {
2960 RLOGE("Memory allocation failed for responseCdmaInformationRecords");
2961 closeRequest;
2962 return RIL_ERRNO_NO_MEMORY;
2963 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002964 for (int i = 0 ; i < infoRec->rec.display.alpha_len ; i++) {
2965 string8[i] = infoRec->rec.display.alpha_buf[i];
2966 }
2967 string8[(int)infoRec->rec.display.alpha_len] = '\0';
2968 writeStringToParcel(p, (const char*)string8);
2969 free(string8);
2970 string8 = NULL;
2971 break;
2972 case RIL_CDMA_CALLED_PARTY_NUMBER_INFO_REC:
2973 case RIL_CDMA_CALLING_PARTY_NUMBER_INFO_REC:
2974 case RIL_CDMA_CONNECTED_NUMBER_INFO_REC:
2975 if (infoRec->rec.number.len > CDMA_NUMBER_INFO_BUFFER_LENGTH) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002976 RLOGE("invalid display info response length %d \
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002977 expected not more than %d\n",
2978 (int)infoRec->rec.number.len,
2979 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2980 return RIL_ERRNO_INVALID_RESPONSE;
2981 }
2982 string8 = (char*) malloc((infoRec->rec.number.len + 1)
2983 * sizeof(char) );
Sanket Padawedf3dabe2016-02-29 10:09:26 -08002984 if (string8 == NULL) {
2985 RLOGE("Memory allocation failed for responseCdmaInformationRecords");
2986 closeRequest;
2987 return RIL_ERRNO_NO_MEMORY;
2988 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002989 for (int i = 0 ; i < infoRec->rec.number.len; i++) {
2990 string8[i] = infoRec->rec.number.buf[i];
2991 }
2992 string8[(int)infoRec->rec.number.len] = '\0';
2993 writeStringToParcel(p, (const char*)string8);
2994 free(string8);
2995 string8 = NULL;
2996 p.writeInt32(infoRec->rec.number.number_type);
2997 p.writeInt32(infoRec->rec.number.number_plan);
2998 p.writeInt32(infoRec->rec.number.pi);
2999 p.writeInt32(infoRec->rec.number.si);
3000 break;
3001 case RIL_CDMA_SIGNAL_INFO_REC:
3002 p.writeInt32(infoRec->rec.signal.isPresent);
3003 p.writeInt32(infoRec->rec.signal.signalType);
3004 p.writeInt32(infoRec->rec.signal.alertPitch);
3005 p.writeInt32(infoRec->rec.signal.signal);
3006
3007 appendPrintBuf("%sisPresent=%X, signalType=%X, \
3008 alertPitch=%X, signal=%X, ",
3009 printBuf, (int)infoRec->rec.signal.isPresent,
3010 (int)infoRec->rec.signal.signalType,
3011 (int)infoRec->rec.signal.alertPitch,
3012 (int)infoRec->rec.signal.signal);
3013 removeLastChar;
3014 break;
3015 case RIL_CDMA_REDIRECTING_NUMBER_INFO_REC:
3016 if (infoRec->rec.redir.redirectingNumber.len >
3017 CDMA_NUMBER_INFO_BUFFER_LENGTH) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003018 RLOGE("invalid display info response length %d \
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003019 expected not more than %d\n",
3020 (int)infoRec->rec.redir.redirectingNumber.len,
3021 CDMA_NUMBER_INFO_BUFFER_LENGTH);
3022 return RIL_ERRNO_INVALID_RESPONSE;
3023 }
3024 string8 = (char*) malloc((infoRec->rec.redir.redirectingNumber
3025 .len + 1) * sizeof(char) );
Sanket Padawedf3dabe2016-02-29 10:09:26 -08003026 if (string8 == NULL) {
3027 RLOGE("Memory allocation failed for responseCdmaInformationRecords");
3028 closeRequest;
3029 return RIL_ERRNO_NO_MEMORY;
3030 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003031 for (int i = 0;
3032 i < infoRec->rec.redir.redirectingNumber.len;
3033 i++) {
3034 string8[i] = infoRec->rec.redir.redirectingNumber.buf[i];
3035 }
3036 string8[(int)infoRec->rec.redir.redirectingNumber.len] = '\0';
3037 writeStringToParcel(p, (const char*)string8);
3038 free(string8);
3039 string8 = NULL;
3040 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_type);
3041 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_plan);
3042 p.writeInt32(infoRec->rec.redir.redirectingNumber.pi);
3043 p.writeInt32(infoRec->rec.redir.redirectingNumber.si);
3044 p.writeInt32(infoRec->rec.redir.redirectingReason);
3045 break;
3046 case RIL_CDMA_LINE_CONTROL_INFO_REC:
3047 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPolarityIncluded);
3048 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlToggle);
3049 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlReverse);
3050 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPowerDenial);
3051
3052 appendPrintBuf("%slineCtrlPolarityIncluded=%d, \
3053 lineCtrlToggle=%d, lineCtrlReverse=%d, \
3054 lineCtrlPowerDenial=%d, ", printBuf,
3055 (int)infoRec->rec.lineCtrl.lineCtrlPolarityIncluded,
3056 (int)infoRec->rec.lineCtrl.lineCtrlToggle,
3057 (int)infoRec->rec.lineCtrl.lineCtrlReverse,
3058 (int)infoRec->rec.lineCtrl.lineCtrlPowerDenial);
3059 removeLastChar;
3060 break;
3061 case RIL_CDMA_T53_CLIR_INFO_REC:
3062 p.writeInt32((int)(infoRec->rec.clir.cause));
3063
3064 appendPrintBuf("%scause%d", printBuf, infoRec->rec.clir.cause);
3065 removeLastChar;
3066 break;
3067 case RIL_CDMA_T53_AUDIO_CONTROL_INFO_REC:
3068 p.writeInt32(infoRec->rec.audioCtrl.upLink);
3069 p.writeInt32(infoRec->rec.audioCtrl.downLink);
3070
3071 appendPrintBuf("%supLink=%d, downLink=%d, ", printBuf,
3072 infoRec->rec.audioCtrl.upLink,
3073 infoRec->rec.audioCtrl.downLink);
3074 removeLastChar;
3075 break;
3076 case RIL_CDMA_T53_RELEASE_INFO_REC:
3077 // TODO(Moto): See David Krause, he has the answer:)
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003078 RLOGE("RIL_CDMA_T53_RELEASE_INFO_REC: return INVALID_RESPONSE");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003079 return RIL_ERRNO_INVALID_RESPONSE;
3080 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003081 RLOGE("Incorrect name value");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003082 return RIL_ERRNO_INVALID_RESPONSE;
3083 }
3084 }
3085 closeResponse;
3086
3087 return 0;
3088}
3089
Sanket Padawe9343e872016-01-11 12:45:43 -08003090static void responseRilSignalStrengthV5(Parcel &p, RIL_SignalStrength_v10 *p_cur) {
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303091 int gsmSignalStrength;
3092 int cdmaDbm;
3093 int evdoDbm;
3094
Sanket Padawe9343e872016-01-11 12:45:43 -08003095 gsmSignalStrength = p_cur->GW_SignalStrength.signalStrength & 0xFF;
Utkarsh Gupta8ede9fa2015-04-23 13:21:49 +05303096
3097#ifdef MODEM_TYPE_XMM6260
3098 if (gsmSignalStrength < 0 ||
3099 (gsmSignalStrength > 31 && p_cur->GW_SignalStrength.signalStrength != 99)) {
3100 gsmSignalStrength = p_cur->CDMA_SignalStrength.dbm;
3101 }
3102#else
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303103 if (gsmSignalStrength < 0) {
3104 gsmSignalStrength = 99;
3105 } else if (gsmSignalStrength > 31 && gsmSignalStrength != 99) {
3106 gsmSignalStrength = 31;
3107 }
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303108#endif
3109 p.writeInt32(gsmSignalStrength);
3110
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003111 p.writeInt32(p_cur->GW_SignalStrength.bitErrorRate);
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303112
Christopher N. Hesse621e63e2016-02-22 21:57:39 +01003113#if defined(MODEM_TYPE_XMM6262) || defined(SAMSUNG_NEXT_GEN_MODEM)
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303114 cdmaDbm = p_cur->CDMA_SignalStrength.dbm & 0xFF;
3115 if (cdmaDbm < 0) {
3116 cdmaDbm = 99;
3117 } else if (cdmaDbm > 31 && cdmaDbm != 99) {
3118 cdmaDbm = 31;
3119 }
3120#else
Caio Schnepperec042542015-04-14 08:03:43 -03003121 cdmaDbm = p_cur->CDMA_SignalStrength.dbm;
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303122#endif
3123 p.writeInt32(cdmaDbm);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003124 p.writeInt32(p_cur->CDMA_SignalStrength.ecio);
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303125
Christopher N. Hesse621e63e2016-02-22 21:57:39 +01003126#if defined(MODEM_TYPE_XMM6262) || defined(SAMSUNG_NEXT_GEN_MODEM)
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303127 evdoDbm = p_cur->EVDO_SignalStrength.dbm & 0xFF;
3128 if (evdoDbm < 0) {
3129 evdoDbm = 99;
3130 } else if (evdoDbm > 31 && evdoDbm != 99) {
3131 evdoDbm = 31;
3132 }
3133#else
3134 evdoDbm = p_cur->EVDO_SignalStrength.dbm;
3135#endif
3136 p.writeInt32(evdoDbm);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003137 p.writeInt32(p_cur->EVDO_SignalStrength.ecio);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003138 p.writeInt32(p_cur->EVDO_SignalStrength.signalNoiseRatio);
Sanket Padawe9343e872016-01-11 12:45:43 -08003139}
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003140
Sanket Padawe9343e872016-01-11 12:45:43 -08003141static void responseRilSignalStrengthV6Extra(Parcel &p, RIL_SignalStrength_v10 *p_cur) {
3142 /*
3143 * Fixup LTE for backwards compatibility
3144 */
3145 // signalStrength: -1 -> 99
3146 if (p_cur->LTE_SignalStrength.signalStrength == -1) {
3147 p_cur->LTE_SignalStrength.signalStrength = 99;
3148 }
3149 // rsrp: -1 -> INT_MAX all other negative value to positive.
3150 // So remap here
3151 if (p_cur->LTE_SignalStrength.rsrp == -1) {
3152 p_cur->LTE_SignalStrength.rsrp = INT_MAX;
3153 } else if (p_cur->LTE_SignalStrength.rsrp < -1) {
3154 p_cur->LTE_SignalStrength.rsrp = -p_cur->LTE_SignalStrength.rsrp;
3155 }
3156 // rsrq: -1 -> INT_MAX
3157 if (p_cur->LTE_SignalStrength.rsrq == -1) {
3158 p_cur->LTE_SignalStrength.rsrq = INT_MAX;
3159 }
3160 // Not remapping rssnr is already using INT_MAX
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003161
Sanket Padawe9343e872016-01-11 12:45:43 -08003162 // cqi: -1 -> INT_MAX
3163 if (p_cur->LTE_SignalStrength.cqi == -1) {
3164 p_cur->LTE_SignalStrength.cqi = INT_MAX;
3165 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003166
Sanket Padawe9343e872016-01-11 12:45:43 -08003167 p.writeInt32(p_cur->LTE_SignalStrength.signalStrength);
3168 p.writeInt32(p_cur->LTE_SignalStrength.rsrp);
3169 p.writeInt32(p_cur->LTE_SignalStrength.rsrq);
3170 p.writeInt32(p_cur->LTE_SignalStrength.rssnr);
3171 p.writeInt32(p_cur->LTE_SignalStrength.cqi);
3172}
3173
3174static void responseRilSignalStrengthV10(Parcel &p, RIL_SignalStrength_v10 *p_cur) {
3175 responseRilSignalStrengthV5(p, p_cur);
3176 responseRilSignalStrengthV6Extra(p, p_cur);
3177 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
3178}
3179
3180
3181static int responseRilSignalStrength(Parcel &p,
3182 void *response, size_t responselen) {
3183 if (response == NULL && responselen != 0) {
3184 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003185 return RIL_ERRNO_INVALID_RESPONSE;
3186 }
3187
Sanket Padawe6daeeef2016-06-08 14:09:26 -07003188 RIL_SignalStrength_v10 *p_cur;
Sanket Padawe9343e872016-01-11 12:45:43 -08003189 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
3190 if (responselen >= sizeof (RIL_SignalStrength_v5)) {
Sanket Padawe6daeeef2016-06-08 14:09:26 -07003191 p_cur = ((RIL_SignalStrength_v10 *) response);
Sanket Padawe9343e872016-01-11 12:45:43 -08003192
3193 responseRilSignalStrengthV5(p, p_cur);
3194
3195 if (responselen >= sizeof (RIL_SignalStrength_v6)) {
3196 responseRilSignalStrengthV6Extra(p, p_cur);
3197 if (responselen >= sizeof (RIL_SignalStrength_v10)) {
3198 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
3199 } else {
3200 p.writeInt32(INT_MAX);
3201 }
3202 } else {
3203 p.writeInt32(99);
3204 p.writeInt32(INT_MAX);
3205 p.writeInt32(INT_MAX);
3206 p.writeInt32(INT_MAX);
3207 p.writeInt32(INT_MAX);
3208 p.writeInt32(INT_MAX);
3209 }
3210 } else {
3211 RLOGE("invalid response length");
3212 return RIL_ERRNO_INVALID_RESPONSE;
3213 }
Sanket Padawea79128a2016-01-26 18:44:01 -08003214 } else { // RIL version >= 13
Sanket Padawe9343e872016-01-11 12:45:43 -08003215 if (responselen % sizeof(RIL_SignalStrength_v10) != 0) {
3216 RLOGE("Data structure expected is RIL_SignalStrength_v10");
3217 if (!isDebuggable()) {
3218 return RIL_ERRNO_INVALID_RESPONSE;
3219 } else {
3220 assert(0);
3221 }
3222 }
Sanket Padawe6daeeef2016-06-08 14:09:26 -07003223 p_cur = ((RIL_SignalStrength_v10 *) response);
Sanket Padawe9343e872016-01-11 12:45:43 -08003224 responseRilSignalStrengthV10(p, p_cur);
3225 }
3226
3227 startResponse;
3228 appendPrintBuf("%s[signalStrength=%d,bitErrorRate=%d,\
3229 CDMA_SS.dbm=%d,CDMA_SSecio=%d,\
3230 EVDO_SS.dbm=%d,EVDO_SS.ecio=%d,\
3231 EVDO_SS.signalNoiseRatio=%d,\
3232 LTE_SS.signalStrength=%d,LTE_SS.rsrp=%d,LTE_SS.rsrq=%d,\
3233 LTE_SS.rssnr=%d,LTE_SS.cqi=%d,TDSCDMA_SS.rscp=%d]",
3234 printBuf,
3235 gsmSignalStrength,
3236 p_cur->GW_SignalStrength.bitErrorRate,
3237 cdmaDbm,
3238 p_cur->CDMA_SignalStrength.ecio,
3239 evdoDbm,
3240 p_cur->EVDO_SignalStrength.ecio,
3241 p_cur->EVDO_SignalStrength.signalNoiseRatio,
3242 p_cur->LTE_SignalStrength.signalStrength,
3243 p_cur->LTE_SignalStrength.rsrp,
3244 p_cur->LTE_SignalStrength.rsrq,
3245 p_cur->LTE_SignalStrength.rssnr,
3246 p_cur->LTE_SignalStrength.cqi,
3247 p_cur->TD_SCDMA_SignalStrength.rscp);
3248 closeResponse;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003249 return 0;
3250}
3251
3252static int responseCallRing(Parcel &p, void *response, size_t responselen) {
3253 if ((response == NULL) || (responselen == 0)) {
3254 return responseVoid(p, response, responselen);
3255 } else {
3256 return responseCdmaSignalInfoRecord(p, response, responselen);
3257 }
3258}
3259
3260static int responseCdmaSignalInfoRecord(Parcel &p, void *response, size_t responselen) {
3261 if (response == NULL || responselen == 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003262 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003263 return RIL_ERRNO_INVALID_RESPONSE;
3264 }
3265
3266 if (responselen != sizeof (RIL_CDMA_SignalInfoRecord)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003267 RLOGE("invalid response length %d expected sizeof (RIL_CDMA_SignalInfoRecord) of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003268 (int)responselen, (int)sizeof (RIL_CDMA_SignalInfoRecord));
3269 return RIL_ERRNO_INVALID_RESPONSE;
3270 }
3271
3272 startResponse;
3273
3274 RIL_CDMA_SignalInfoRecord *p_cur = ((RIL_CDMA_SignalInfoRecord *) response);
3275 marshallSignalInfoRecord(p, *p_cur);
3276
3277 appendPrintBuf("%s[isPresent=%d,signalType=%d,alertPitch=%d\
3278 signal=%d]",
3279 printBuf,
3280 p_cur->isPresent,
3281 p_cur->signalType,
3282 p_cur->alertPitch,
3283 p_cur->signal);
3284
3285 closeResponse;
3286 return 0;
3287}
3288
3289static int responseCdmaCallWaiting(Parcel &p, void *response,
3290 size_t responselen) {
3291 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003292 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003293 return RIL_ERRNO_INVALID_RESPONSE;
3294 }
3295
3296 if (responselen < sizeof(RIL_CDMA_CallWaiting_v6)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003297 RLOGW("Upgrade to ril version %d\n", RIL_VERSION);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003298 }
3299
3300 RIL_CDMA_CallWaiting_v6 *p_cur = ((RIL_CDMA_CallWaiting_v6 *) response);
3301
3302 writeStringToParcel(p, p_cur->number);
3303 p.writeInt32(p_cur->numberPresentation);
3304 writeStringToParcel(p, p_cur->name);
3305 marshallSignalInfoRecord(p, p_cur->signalInfoRecord);
3306
Sanket Padawe9343e872016-01-11 12:45:43 -08003307 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
3308 if (responselen >= sizeof(RIL_CDMA_CallWaiting_v6)) {
3309 p.writeInt32(p_cur->number_type);
3310 p.writeInt32(p_cur->number_plan);
3311 } else {
3312 p.writeInt32(0);
3313 p.writeInt32(0);
3314 }
Sanket Padawea79128a2016-01-26 18:44:01 -08003315 } else { // RIL version >= 13
Sanket Padawe9343e872016-01-11 12:45:43 -08003316 if (responselen % sizeof(RIL_CDMA_CallWaiting_v6) != 0) {
3317 RLOGE("Data structure expected is RIL_CDMA_CallWaiting_v6");
3318 if (!isDebuggable()) {
3319 return RIL_ERRNO_INVALID_RESPONSE;
3320 } else {
3321 assert(0);
3322 }
3323 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003324 p.writeInt32(p_cur->number_type);
3325 p.writeInt32(p_cur->number_plan);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003326 }
3327
3328 startResponse;
3329 appendPrintBuf("%snumber=%s,numberPresentation=%d, name=%s,\
3330 signalInfoRecord[isPresent=%d,signalType=%d,alertPitch=%d\
3331 signal=%d,number_type=%d,number_plan=%d]",
3332 printBuf,
3333 p_cur->number,
3334 p_cur->numberPresentation,
3335 p_cur->name,
3336 p_cur->signalInfoRecord.isPresent,
3337 p_cur->signalInfoRecord.signalType,
3338 p_cur->signalInfoRecord.alertPitch,
3339 p_cur->signalInfoRecord.signal,
3340 p_cur->number_type,
3341 p_cur->number_plan);
3342 closeResponse;
3343
3344 return 0;
3345}
3346
Sanket Padawe9343e872016-01-11 12:45:43 -08003347static void responseSimRefreshV7(Parcel &p, void *response) {
3348 RIL_SimRefreshResponse_v7 *p_cur = ((RIL_SimRefreshResponse_v7 *) response);
3349 p.writeInt32(p_cur->result);
3350 p.writeInt32(p_cur->ef_id);
3351 writeStringToParcel(p, p_cur->aid);
3352
3353 appendPrintBuf("%sresult=%d, ef_id=%d, aid=%s",
3354 printBuf,
3355 p_cur->result,
3356 p_cur->ef_id,
3357 p_cur->aid);
3358
3359}
3360
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003361static int responseSimRefresh(Parcel &p, void *response, size_t responselen) {
3362 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003363 RLOGE("responseSimRefresh: invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003364 return RIL_ERRNO_INVALID_RESPONSE;
3365 }
3366
3367 startResponse;
Sanket Padawe9343e872016-01-11 12:45:43 -08003368 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
Sanket Padawe201aca32016-01-21 15:49:33 -08003369 if (s_callbacks.version >= 7) {
Sanket Padawe9343e872016-01-11 12:45:43 -08003370 responseSimRefreshV7(p, response);
3371 } else {
3372 int *p_cur = ((int *) response);
3373 p.writeInt32(p_cur[0]);
3374 p.writeInt32(p_cur[1]);
3375 writeStringToParcel(p, NULL);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003376
Sanket Padawe9343e872016-01-11 12:45:43 -08003377 appendPrintBuf("%sresult=%d, ef_id=%d",
3378 printBuf,
3379 p_cur[0],
3380 p_cur[1]);
3381 }
Sanket Padawea79128a2016-01-26 18:44:01 -08003382 } else { // RIL version >= 13
Sanket Padawe9343e872016-01-11 12:45:43 -08003383 if (responselen % sizeof(RIL_SimRefreshResponse_v7) != 0) {
3384 RLOGE("Data structure expected is RIL_SimRefreshResponse_v7");
3385 if (!isDebuggable()) {
3386 return RIL_ERRNO_INVALID_RESPONSE;
3387 } else {
3388 assert(0);
3389 }
3390 }
3391 responseSimRefreshV7(p, response);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003392
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003393 }
3394 closeResponse;
3395
3396 return 0;
3397}
3398
Sanket Padawea79128a2016-01-26 18:44:01 -08003399static int responseCellInfoListV6(Parcel &p, void *response, size_t responselen) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003400 if (response == NULL && responselen != 0) {
3401 RLOGE("invalid response: NULL");
3402 return RIL_ERRNO_INVALID_RESPONSE;
3403 }
3404
3405 if (responselen % sizeof(RIL_CellInfo) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08003406 RLOGE("responseCellInfoList: invalid response length %d expected multiple of %d",
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003407 (int)responselen, (int)sizeof(RIL_CellInfo));
3408 return RIL_ERRNO_INVALID_RESPONSE;
3409 }
3410
3411 int num = responselen / sizeof(RIL_CellInfo);
3412 p.writeInt32(num);
3413
3414 RIL_CellInfo *p_cur = (RIL_CellInfo *) response;
3415 startResponse;
3416 int i;
3417 for (i = 0; i < num; i++) {
3418 appendPrintBuf("%s[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", printBuf, i,
3419 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
3420 p.writeInt32((int)p_cur->cellInfoType);
3421 p.writeInt32(p_cur->registered);
3422 p.writeInt32(p_cur->timeStampType);
3423 p.writeInt64(p_cur->timeStamp);
3424 switch(p_cur->cellInfoType) {
3425 case RIL_CELL_INFO_TYPE_GSM: {
3426 appendPrintBuf("%s GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,", printBuf,
3427 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
3428 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
3429 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
3430 p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3431 appendPrintBuf("%s gsmSS: ss=%d,ber=%d],", printBuf,
3432 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
3433 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3434
3435 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
3436 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
3437 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
3438 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3439 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
3440 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3441 break;
3442 }
3443 case RIL_CELL_INFO_TYPE_WCDMA: {
3444 appendPrintBuf("%s WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,", printBuf,
3445 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
3446 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
3447 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
3448 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
3449 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3450 appendPrintBuf("%s wcdmaSS: ss=%d,ber=%d],", printBuf,
3451 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
3452 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3453
3454 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
3455 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
3456 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
3457 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
3458 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3459 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
3460 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3461 break;
3462 }
3463 case RIL_CELL_INFO_TYPE_CDMA: {
3464 appendPrintBuf("%s CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d", printBuf,
3465 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
3466 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
3467 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
3468 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
3469 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3470
3471 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
3472 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
3473 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
3474 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
3475 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3476
3477 appendPrintBuf("%s cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d", printBuf,
3478 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
3479 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
3480 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
3481 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
3482 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3483
3484 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
3485 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
3486 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
3487 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
3488 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3489 break;
3490 }
3491 case RIL_CELL_INFO_TYPE_LTE: {
3492 appendPrintBuf("%s LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d", printBuf,
3493 p_cur->CellInfo.lte.cellIdentityLte.mcc,
3494 p_cur->CellInfo.lte.cellIdentityLte.mnc,
3495 p_cur->CellInfo.lte.cellIdentityLte.ci,
3496 p_cur->CellInfo.lte.cellIdentityLte.pci,
3497 p_cur->CellInfo.lte.cellIdentityLte.tac);
3498
3499 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
3500 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
3501 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
3502 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
3503 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
3504
3505 appendPrintBuf("%s lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d", printBuf,
3506 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
3507 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
3508 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
3509 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
3510 p_cur->CellInfo.lte.signalStrengthLte.cqi,
3511 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3512 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
3513 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
3514 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
3515 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
3516 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
3517 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3518 break;
3519 }
Howard Sue32dbfd2015-01-07 15:55:57 +08003520 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
3521 appendPrintBuf("%s TDSCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,cpid=%d,", printBuf,
3522 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc,
3523 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc,
3524 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac,
3525 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid,
3526 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3527 appendPrintBuf("%s tdscdmaSS: rscp=%d],", printBuf,
3528 p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3529
3530 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
3531 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
3532 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
3533 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
3534 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3535 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3536 break;
3537 }
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003538 }
3539 p_cur += 1;
3540 }
3541 removeLastChar;
3542 closeResponse;
3543
3544 return 0;
3545}
3546
Sanket Padawea79128a2016-01-26 18:44:01 -08003547static int responseCellInfoListV12(Parcel &p, void *response, size_t responselen) {
3548 if (response == NULL && responselen != 0) {
3549 RLOGE("invalid response: NULL");
3550 return RIL_ERRNO_INVALID_RESPONSE;
3551 }
3552
3553 if (responselen % sizeof(RIL_CellInfo_v12) != 0) {
3554 RLOGE("responseCellInfoList: invalid response length %d expected multiple of %d",
3555 (int)responselen, (int)sizeof(RIL_CellInfo_v12));
3556 return RIL_ERRNO_INVALID_RESPONSE;
3557 }
3558
3559 int num = responselen / sizeof(RIL_CellInfo_v12);
3560 p.writeInt32(num);
3561
3562 RIL_CellInfo_v12 *p_cur = (RIL_CellInfo_v12 *) response;
3563 startResponse;
3564 int i;
3565 for (i = 0; i < num; i++) {
3566 appendPrintBuf("%s[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", printBuf, i,
3567 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
3568 RLOGE("[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", i,
3569 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
3570 p.writeInt32((int)p_cur->cellInfoType);
3571 p.writeInt32(p_cur->registered);
3572 p.writeInt32(p_cur->timeStampType);
3573 p.writeInt64(p_cur->timeStamp);
3574 switch(p_cur->cellInfoType) {
3575 case RIL_CELL_INFO_TYPE_GSM: {
3576 appendPrintBuf("%s GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,arfcn=%d,bsic=%x", printBuf,
3577 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
3578 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
3579 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
3580 p_cur->CellInfo.gsm.cellIdentityGsm.cid,
3581 p_cur->CellInfo.gsm.cellIdentityGsm.arfcn,
3582 p_cur->CellInfo.gsm.cellIdentityGsm.bsic);
3583 RLOGE("GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,arfcn=%d,bsic=%x",
3584 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
3585 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
3586 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
3587 p_cur->CellInfo.gsm.cellIdentityGsm.cid,
3588 p_cur->CellInfo.gsm.cellIdentityGsm.arfcn,
3589 p_cur->CellInfo.gsm.cellIdentityGsm.bsic);
3590 RLOGE("gsmSS: ss=%d,ber=%d, ta=%d],",
3591 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
3592 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate,
3593 p_cur->CellInfo.gsm.signalStrengthGsm.timingAdvance);
3594 appendPrintBuf("%s gsmSS: ss=%d,ber=%d, ta=%d],", printBuf,
3595 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
3596 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate,
3597 p_cur->CellInfo.gsm.signalStrengthGsm.timingAdvance);
3598
3599 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
3600 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
3601 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
3602 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3603 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.arfcn);
3604 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.bsic);
3605 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
3606 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3607 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.timingAdvance);
3608 break;
3609 }
3610 case RIL_CELL_INFO_TYPE_WCDMA: {
3611 RLOGE("WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,uarfcn=%d",
3612 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
3613 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
3614 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
3615 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
3616 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc,
3617 p_cur->CellInfo.wcdma.cellIdentityWcdma.uarfcn);
3618 RLOGE("wcdmaSS: ss=%d,ber=%d],",
3619 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
3620 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3621 appendPrintBuf("%s WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,uarfcn=%d", printBuf,
3622 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
3623 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
3624 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
3625 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
3626 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc,
3627 p_cur->CellInfo.wcdma.cellIdentityWcdma.uarfcn);
3628 appendPrintBuf("%s wcdmaSS: ss=%d,ber=%d],", printBuf,
3629 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
3630 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3631
3632 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
3633 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
3634 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
3635 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
3636 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3637 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.uarfcn);
3638 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
3639 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3640 break;
3641 }
3642 case RIL_CELL_INFO_TYPE_CDMA: {
3643 RLOGE("CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d",
3644 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
3645 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
3646 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
3647 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
3648 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3649
3650 appendPrintBuf("%s CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d", printBuf,
3651 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
3652 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
3653 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
3654 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
3655 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3656
3657 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
3658 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
3659 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
3660 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
3661 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3662
3663 RLOGE("cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d",
3664 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
3665 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
3666 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
3667 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
3668 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3669
3670 appendPrintBuf("%s cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d", printBuf,
3671 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
3672 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
3673 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
3674 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
3675 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3676
3677 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
3678 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
3679 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
3680 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
3681 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3682 break;
3683 }
3684 case RIL_CELL_INFO_TYPE_LTE: {
3685 RLOGE("LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d,earfcn=%d",
3686 p_cur->CellInfo.lte.cellIdentityLte.mcc,
3687 p_cur->CellInfo.lte.cellIdentityLte.mnc,
3688 p_cur->CellInfo.lte.cellIdentityLte.ci,
3689 p_cur->CellInfo.lte.cellIdentityLte.pci,
3690 p_cur->CellInfo.lte.cellIdentityLte.tac,
3691 p_cur->CellInfo.lte.cellIdentityLte.earfcn);
3692
3693 appendPrintBuf("%s LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d,earfcn=%d", printBuf,
3694 p_cur->CellInfo.lte.cellIdentityLte.mcc,
3695 p_cur->CellInfo.lte.cellIdentityLte.mnc,
3696 p_cur->CellInfo.lte.cellIdentityLte.ci,
3697 p_cur->CellInfo.lte.cellIdentityLte.pci,
3698 p_cur->CellInfo.lte.cellIdentityLte.tac,
3699 p_cur->CellInfo.lte.cellIdentityLte.earfcn);
3700
3701 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
3702 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
3703 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
3704 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
3705 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
3706 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.earfcn);
3707
3708 RLOGE("lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d",
3709 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
3710 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
3711 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
3712 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
3713 p_cur->CellInfo.lte.signalStrengthLte.cqi,
3714 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3715 appendPrintBuf("%s lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d", printBuf,
3716 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
3717 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
3718 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
3719 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
3720 p_cur->CellInfo.lte.signalStrengthLte.cqi,
3721 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3722 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
3723 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
3724 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
3725 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
3726 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
3727 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3728 break;
3729 }
3730 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
3731 appendPrintBuf("%s TDSCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,cpid=%d,", printBuf,
3732 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc,
3733 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc,
3734 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac,
3735 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid,
3736 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3737 appendPrintBuf("%s tdscdmaSS: rscp=%d],", printBuf,
3738 p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3739
3740 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
3741 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
3742 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
3743 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
3744 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3745 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3746 break;
3747 }
3748 }
3749 p_cur += 1;
3750 }
3751 removeLastChar;
3752 closeResponse;
3753 return 0;
3754}
3755
3756static int responseCellInfoList(Parcel &p, void *response, size_t responselen)
3757{
3758 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
3759 if (s_callbacks.version < 12) {
3760 RLOGD("responseCellInfoList: v6");
3761 return responseCellInfoListV6(p, response, responselen);
3762 } else {
3763 RLOGD("responseCellInfoList: v12");
3764 return responseCellInfoListV12(p, response, responselen);
3765 }
3766 } else { // RIL version >= 13
3767 if (responselen % sizeof(RIL_CellInfo_v12) != 0) {
3768 RLOGE("Data structure expected is RIL_CellInfo_v12");
3769 if (!isDebuggable()) {
3770 return RIL_ERRNO_INVALID_RESPONSE;
3771 } else {
3772 assert(0);
3773 }
3774 }
3775 return responseCellInfoListV12(p, response, responselen);
3776 }
3777
3778 return 0;
3779}
3780
Howard Sue32dbfd2015-01-07 15:55:57 +08003781static int responseHardwareConfig(Parcel &p, void *response, size_t responselen)
3782{
3783 if (response == NULL && responselen != 0) {
3784 RLOGE("invalid response: NULL");
3785 return RIL_ERRNO_INVALID_RESPONSE;
3786 }
3787
3788 if (responselen % sizeof(RIL_HardwareConfig) != 0) {
3789 RLOGE("responseHardwareConfig: invalid response length %d expected multiple of %d",
3790 (int)responselen, (int)sizeof(RIL_HardwareConfig));
3791 return RIL_ERRNO_INVALID_RESPONSE;
3792 }
3793
3794 int num = responselen / sizeof(RIL_HardwareConfig);
3795 int i;
3796 RIL_HardwareConfig *p_cur = (RIL_HardwareConfig *) response;
3797
3798 p.writeInt32(num);
3799
3800 startResponse;
3801 for (i = 0; i < num; i++) {
3802 switch (p_cur[i].type) {
3803 case RIL_HARDWARE_CONFIG_MODEM: {
3804 writeStringToParcel(p, p_cur[i].uuid);
3805 p.writeInt32((int)p_cur[i].state);
3806 p.writeInt32(p_cur[i].cfg.modem.rat);
3807 p.writeInt32(p_cur[i].cfg.modem.maxVoice);
3808 p.writeInt32(p_cur[i].cfg.modem.maxData);
3809 p.writeInt32(p_cur[i].cfg.modem.maxStandby);
3810
3811 appendPrintBuf("%s modem: uuid=%s,state=%d,rat=%08x,maxV=%d,maxD=%d,maxS=%d", printBuf,
3812 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.modem.rat,
3813 p_cur[i].cfg.modem.maxVoice, p_cur[i].cfg.modem.maxData, p_cur[i].cfg.modem.maxStandby);
3814 break;
3815 }
3816 case RIL_HARDWARE_CONFIG_SIM: {
3817 writeStringToParcel(p, p_cur[i].uuid);
3818 p.writeInt32((int)p_cur[i].state);
3819 writeStringToParcel(p, p_cur[i].cfg.sim.modemUuid);
3820
3821 appendPrintBuf("%s sim: uuid=%s,state=%d,modem-uuid=%s", printBuf,
3822 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.sim.modemUuid);
3823 break;
3824 }
3825 }
3826 }
3827 removeLastChar;
3828 closeResponse;
3829 return 0;
3830}
3831
Howard Subd82ef12015-04-12 10:25:05 +02003832static int responseRadioCapability(Parcel &p, void *response, size_t responselen) {
3833 if (response == NULL) {
3834 RLOGE("invalid response: NULL");
3835 return RIL_ERRNO_INVALID_RESPONSE;
3836 }
3837
3838 if (responselen != sizeof (RIL_RadioCapability) ) {
3839 RLOGE("invalid response length was %d expected %d",
3840 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3841 return RIL_ERRNO_INVALID_RESPONSE;
3842 }
3843
3844 RIL_RadioCapability *p_cur = (RIL_RadioCapability *) response;
3845 p.writeInt32(p_cur->version);
3846 p.writeInt32(p_cur->session);
3847 p.writeInt32(p_cur->phase);
3848 p.writeInt32(p_cur->rat);
3849 writeStringToParcel(p, p_cur->logicalModemUuid);
3850 p.writeInt32(p_cur->status);
3851
3852 startResponse;
3853 appendPrintBuf("%s[version=%d,session=%d,phase=%d,\
Andreas Schneidera8d09502015-06-23 18:41:38 +02003854 rat=%d,logicalModemUuid=%s,status=%d]",
Howard Subd82ef12015-04-12 10:25:05 +02003855 printBuf,
3856 p_cur->version,
3857 p_cur->session,
3858 p_cur->phase,
3859 p_cur->rat,
3860 p_cur->logicalModemUuid,
3861 p_cur->status);
3862 closeResponse;
3863 return 0;
3864}
3865
3866static int responseSSData(Parcel &p, void *response, size_t responselen) {
3867 RLOGD("In responseSSData");
3868 int num;
3869
3870 if (response == NULL && responselen != 0) {
3871 RLOGE("invalid response length was %d expected %d",
3872 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3873 return RIL_ERRNO_INVALID_RESPONSE;
3874 }
3875
3876 if (responselen != sizeof(RIL_StkCcUnsolSsResponse)) {
3877 RLOGE("invalid response length %d, expected %d",
3878 (int)responselen, (int)sizeof(RIL_StkCcUnsolSsResponse));
3879 return RIL_ERRNO_INVALID_RESPONSE;
3880 }
3881
3882 startResponse;
3883 RIL_StkCcUnsolSsResponse *p_cur = (RIL_StkCcUnsolSsResponse *) response;
3884 p.writeInt32(p_cur->serviceType);
3885 p.writeInt32(p_cur->requestType);
3886 p.writeInt32(p_cur->teleserviceType);
3887 p.writeInt32(p_cur->serviceClass);
3888 p.writeInt32(p_cur->result);
3889
3890 if (isServiceTypeCfQuery(p_cur->serviceType, p_cur->requestType)) {
3891 RLOGD("responseSSData CF type, num of Cf elements %d", p_cur->cfData.numValidIndexes);
3892 if (p_cur->cfData.numValidIndexes > NUM_SERVICE_CLASSES) {
3893 RLOGE("numValidIndexes is greater than max value %d, "
3894 "truncating it to max value", NUM_SERVICE_CLASSES);
3895 p_cur->cfData.numValidIndexes = NUM_SERVICE_CLASSES;
3896 }
3897 /* number of call info's */
3898 p.writeInt32(p_cur->cfData.numValidIndexes);
3899
3900 for (int i = 0; i < p_cur->cfData.numValidIndexes; i++) {
3901 RIL_CallForwardInfo cf = p_cur->cfData.cfInfo[i];
3902
3903 p.writeInt32(cf.status);
3904 p.writeInt32(cf.reason);
3905 p.writeInt32(cf.serviceClass);
3906 p.writeInt32(cf.toa);
3907 writeStringToParcel(p, cf.number);
3908 p.writeInt32(cf.timeSeconds);
3909 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
3910 (cf.status==1)?"enable":"disable", cf.reason, cf.serviceClass, cf.toa,
3911 (char*)cf.number, cf.timeSeconds);
3912 RLOGD("Data: %d,reason=%d,cls=%d,toa=%d,num=%s,tout=%d],", cf.status,
3913 cf.reason, cf.serviceClass, cf.toa, (char*)cf.number, cf.timeSeconds);
3914 }
3915 } else {
3916 p.writeInt32 (SS_INFO_MAX);
3917
3918 /* each int*/
3919 for (int i = 0; i < SS_INFO_MAX; i++) {
3920 appendPrintBuf("%s%d,", printBuf, p_cur->ssInfo[i]);
3921 RLOGD("Data: %d",p_cur->ssInfo[i]);
3922 p.writeInt32(p_cur->ssInfo[i]);
3923 }
3924 }
3925 removeLastChar;
3926 closeResponse;
3927
3928 return 0;
3929}
3930
3931static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType) {
3932 if ((reqType == SS_INTERROGATION) &&
3933 (serType == SS_CFU ||
3934 serType == SS_CF_BUSY ||
3935 serType == SS_CF_NO_REPLY ||
3936 serType == SS_CF_NOT_REACHABLE ||
3937 serType == SS_CF_ALL ||
3938 serType == SS_CF_ALL_CONDITIONAL)) {
3939 return true;
3940 }
3941 return false;
3942}
3943
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003944static void triggerEvLoop() {
3945 int ret;
3946 if (!pthread_equal(pthread_self(), s_tid_dispatch)) {
3947 /* trigger event loop to wakeup. No reason to do this,
3948 * if we're in the event loop thread */
3949 do {
3950 ret = write (s_fdWakeupWrite, " ", 1);
3951 } while (ret < 0 && errno == EINTR);
3952 }
3953}
3954
3955static void rilEventAddWakeup(struct ril_event *ev) {
3956 ril_event_add(ev);
3957 triggerEvLoop();
3958}
3959
3960static void sendSimStatusAppInfo(Parcel &p, int num_apps, RIL_AppStatus appStatus[]) {
3961 p.writeInt32(num_apps);
3962 startResponse;
3963 for (int i = 0; i < num_apps; i++) {
3964 p.writeInt32(appStatus[i].app_type);
3965 p.writeInt32(appStatus[i].app_state);
3966 p.writeInt32(appStatus[i].perso_substate);
3967 writeStringToParcel(p, (const char*)(appStatus[i].aid_ptr));
3968 writeStringToParcel(p, (const char*)
3969 (appStatus[i].app_label_ptr));
3970 p.writeInt32(appStatus[i].pin1_replaced);
3971 p.writeInt32(appStatus[i].pin1);
3972 p.writeInt32(appStatus[i].pin2);
3973 appendPrintBuf("%s[app_type=%d,app_state=%d,perso_substate=%d,\
3974 aid_ptr=%s,app_label_ptr=%s,pin1_replaced=%d,pin1=%d,pin2=%d],",
3975 printBuf,
3976 appStatus[i].app_type,
3977 appStatus[i].app_state,
3978 appStatus[i].perso_substate,
3979 appStatus[i].aid_ptr,
3980 appStatus[i].app_label_ptr,
3981 appStatus[i].pin1_replaced,
3982 appStatus[i].pin1,
3983 appStatus[i].pin2);
3984 }
3985 closeResponse;
3986}
3987
Sanket Padawe9343e872016-01-11 12:45:43 -08003988static void responseSimStatusV5(Parcel &p, void *response) {
3989 RIL_CardStatus_v5 *p_cur = ((RIL_CardStatus_v5 *) response);
3990
3991 p.writeInt32(p_cur->card_state);
3992 p.writeInt32(p_cur->universal_pin_state);
3993 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3994 p.writeInt32(p_cur->cdma_subscription_app_index);
Kyle Repinski5a2cc4e2016-08-31 01:04:02 -05003995 p.writeInt32(-1);
Sanket Padawe9343e872016-01-11 12:45:43 -08003996
3997 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
3998}
3999
4000static void responseSimStatusV6(Parcel &p, void *response) {
4001 RIL_CardStatus_v6 *p_cur = ((RIL_CardStatus_v6 *) response);
4002
4003 p.writeInt32(p_cur->card_state);
4004 p.writeInt32(p_cur->universal_pin_state);
4005 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
4006 p.writeInt32(p_cur->cdma_subscription_app_index);
4007 p.writeInt32(p_cur->ims_subscription_app_index);
4008
4009 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
4010}
4011
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004012static int responseSimStatus(Parcel &p, void *response, size_t responselen) {
Howard Sue32dbfd2015-01-07 15:55:57 +08004013 int i;
4014
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004015 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004016 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004017 return RIL_ERRNO_INVALID_RESPONSE;
4018 }
4019
Sanket Padawe9343e872016-01-11 12:45:43 -08004020 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
4021 if (responselen == sizeof (RIL_CardStatus_v6)) {
4022 responseSimStatusV6(p, response);
4023 } else if (responselen == sizeof (RIL_CardStatus_v5)) {
4024 responseSimStatusV5(p, response);
4025 } else {
4026 RLOGE("responseSimStatus: A RilCardStatus_v6 or _v5 expected\n");
4027 return RIL_ERRNO_INVALID_RESPONSE;
4028 }
Sanket Padawea79128a2016-01-26 18:44:01 -08004029 } else { // RIL version >= 13
Sanket Padawe9343e872016-01-11 12:45:43 -08004030 if (responselen % sizeof(RIL_CardStatus_v6) != 0) {
4031 RLOGE("Data structure expected is RIL_CardStatus_v6");
4032 if (!isDebuggable()) {
4033 return RIL_ERRNO_INVALID_RESPONSE;
4034 } else {
4035 assert(0);
4036 }
4037 }
4038 responseSimStatusV6(p, response);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004039 }
4040
4041 return 0;
4042}
4043
4044static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen) {
4045 int num = responselen / sizeof(RIL_GSM_BroadcastSmsConfigInfo *);
4046 p.writeInt32(num);
4047
4048 startResponse;
4049 RIL_GSM_BroadcastSmsConfigInfo **p_cur =
4050 (RIL_GSM_BroadcastSmsConfigInfo **) response;
4051 for (int i = 0; i < num; i++) {
4052 p.writeInt32(p_cur[i]->fromServiceId);
4053 p.writeInt32(p_cur[i]->toServiceId);
4054 p.writeInt32(p_cur[i]->fromCodeScheme);
4055 p.writeInt32(p_cur[i]->toCodeScheme);
4056 p.writeInt32(p_cur[i]->selected);
4057
4058 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId=%d, \
4059 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]",
4060 printBuf, i, p_cur[i]->fromServiceId, p_cur[i]->toServiceId,
4061 p_cur[i]->fromCodeScheme, p_cur[i]->toCodeScheme,
4062 p_cur[i]->selected);
4063 }
4064 closeResponse;
4065
4066 return 0;
4067}
4068
4069static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen) {
4070 RIL_CDMA_BroadcastSmsConfigInfo **p_cur =
4071 (RIL_CDMA_BroadcastSmsConfigInfo **) response;
4072
4073 int num = responselen / sizeof (RIL_CDMA_BroadcastSmsConfigInfo *);
4074 p.writeInt32(num);
4075
4076 startResponse;
4077 for (int i = 0 ; i < num ; i++ ) {
4078 p.writeInt32(p_cur[i]->service_category);
4079 p.writeInt32(p_cur[i]->language);
4080 p.writeInt32(p_cur[i]->selected);
4081
4082 appendPrintBuf("%s [%d: srvice_category=%d, language =%d, \
4083 selected =%d], ",
4084 printBuf, i, p_cur[i]->service_category, p_cur[i]->language,
4085 p_cur[i]->selected);
4086 }
4087 closeResponse;
4088
4089 return 0;
4090}
4091
4092static int responseCdmaSms(Parcel &p, void *response, size_t responselen) {
4093 int num;
4094 int digitCount;
4095 int digitLimit;
4096 uint8_t uct;
4097 void* dest;
4098
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004099 RLOGD("Inside responseCdmaSms");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004100
4101 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004102 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004103 return RIL_ERRNO_INVALID_RESPONSE;
4104 }
4105
4106 if (responselen != sizeof(RIL_CDMA_SMS_Message)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004107 RLOGE("invalid response length was %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004108 (int)responselen, (int)sizeof(RIL_CDMA_SMS_Message));
4109 return RIL_ERRNO_INVALID_RESPONSE;
4110 }
4111
4112 RIL_CDMA_SMS_Message *p_cur = (RIL_CDMA_SMS_Message *) response;
4113 p.writeInt32(p_cur->uTeleserviceID);
4114 p.write(&(p_cur->bIsServicePresent),sizeof(uct));
4115 p.writeInt32(p_cur->uServicecategory);
4116 p.writeInt32(p_cur->sAddress.digit_mode);
4117 p.writeInt32(p_cur->sAddress.number_mode);
4118 p.writeInt32(p_cur->sAddress.number_type);
4119 p.writeInt32(p_cur->sAddress.number_plan);
4120 p.write(&(p_cur->sAddress.number_of_digits), sizeof(uct));
4121 digitLimit= MIN((p_cur->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
4122 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
4123 p.write(&(p_cur->sAddress.digits[digitCount]),sizeof(uct));
4124 }
4125
4126 p.writeInt32(p_cur->sSubAddress.subaddressType);
4127 p.write(&(p_cur->sSubAddress.odd),sizeof(uct));
4128 p.write(&(p_cur->sSubAddress.number_of_digits),sizeof(uct));
4129 digitLimit= MIN((p_cur->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
4130 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
4131 p.write(&(p_cur->sSubAddress.digits[digitCount]),sizeof(uct));
4132 }
4133
4134 digitLimit= MIN((p_cur->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
4135 p.writeInt32(p_cur->uBearerDataLen);
4136 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
4137 p.write(&(p_cur->aBearerData[digitCount]), sizeof(uct));
4138 }
4139
4140 startResponse;
4141 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
4142 sAddress.digit_mode=%d, sAddress.number_mode=%d, sAddress.number_type=%d, ",
4143 printBuf, p_cur->uTeleserviceID,p_cur->bIsServicePresent,p_cur->uServicecategory,
4144 p_cur->sAddress.digit_mode, p_cur->sAddress.number_mode,p_cur->sAddress.number_type);
4145 closeResponse;
4146
4147 return 0;
4148}
4149
Howard Sue32dbfd2015-01-07 15:55:57 +08004150static int responseDcRtInfo(Parcel &p, void *response, size_t responselen)
4151{
4152 int num = responselen / sizeof(RIL_DcRtInfo);
4153 if ((responselen % sizeof(RIL_DcRtInfo) != 0) || (num != 1)) {
4154 RLOGE("responseDcRtInfo: invalid response length %d expected multiple of %d",
4155 (int)responselen, (int)sizeof(RIL_DcRtInfo));
4156 return RIL_ERRNO_INVALID_RESPONSE;
4157 }
4158
4159 startResponse;
4160 RIL_DcRtInfo *pDcRtInfo = (RIL_DcRtInfo *)response;
4161 p.writeInt64(pDcRtInfo->time);
4162 p.writeInt32(pDcRtInfo->powerState);
4163 appendPrintBuf("%s[time=%d,powerState=%d]", printBuf,
4164 pDcRtInfo->time,
Andreas Schneidera8d09502015-06-23 18:41:38 +02004165 (int)pDcRtInfo->powerState);
Howard Sue32dbfd2015-01-07 15:55:57 +08004166 closeResponse;
4167
4168 return 0;
4169}
4170
fenglu9bdede02015-04-14 14:53:55 -07004171static int responseLceStatus(Parcel &p, void *response, size_t responselen) {
4172 if (response == NULL || responselen != sizeof(RIL_LceStatusInfo)) {
4173 if (response == NULL) {
4174 RLOGE("invalid response: NULL");
4175 }
4176 else {
4177 RLOGE("responseLceStatus: invalid response length %d expecting len: d%",
4178 sizeof(RIL_LceStatusInfo), responselen);
4179 }
4180 return RIL_ERRNO_INVALID_RESPONSE;
4181 }
4182
4183 RIL_LceStatusInfo *p_cur = (RIL_LceStatusInfo *)response;
4184 p.write((void *)p_cur, 1); // p_cur->lce_status takes one byte.
4185 p.writeInt32(p_cur->actual_interval_ms);
4186
4187 startResponse;
4188 appendPrintBuf("LCE Status: %d, actual_interval_ms: %d",
4189 p_cur->lce_status, p_cur->actual_interval_ms);
4190 closeResponse;
4191
4192 return 0;
4193}
4194
4195static int responseLceData(Parcel &p, void *response, size_t responselen) {
4196 if (response == NULL || responselen != sizeof(RIL_LceDataInfo)) {
4197 if (response == NULL) {
4198 RLOGE("invalid response: NULL");
4199 }
4200 else {
4201 RLOGE("responseLceData: invalid response length %d expecting len: d%",
4202 sizeof(RIL_LceDataInfo), responselen);
4203 }
4204 return RIL_ERRNO_INVALID_RESPONSE;
4205 }
4206
4207 RIL_LceDataInfo *p_cur = (RIL_LceDataInfo *)response;
4208 p.writeInt32(p_cur->last_hop_capacity_kbps);
4209
4210 /* p_cur->confidence_level and p_cur->lce_suspended take 1 byte each.*/
4211 p.write((void *)&(p_cur->confidence_level), 1);
4212 p.write((void *)&(p_cur->lce_suspended), 1);
4213
4214 startResponse;
Hyejine942c332015-09-14 16:27:28 -07004215 appendPrintBuf("LCE info received: capacity %d confidence level %d \
4216 and suspended %d",
fenglu9bdede02015-04-14 14:53:55 -07004217 p_cur->last_hop_capacity_kbps, p_cur->confidence_level,
4218 p_cur->lce_suspended);
4219 closeResponse;
4220
4221 return 0;
4222}
4223
Prerepa Viswanadham8e755592015-05-28 00:37:32 -07004224static int responseActivityData(Parcel &p, void *response, size_t responselen) {
4225 if (response == NULL || responselen != sizeof(RIL_ActivityStatsInfo)) {
4226 if (response == NULL) {
4227 RLOGE("invalid response: NULL");
4228 }
4229 else {
4230 RLOGE("responseActivityData: invalid response length %d expecting len: d%",
4231 sizeof(RIL_ActivityStatsInfo), responselen);
4232 }
4233 return RIL_ERRNO_INVALID_RESPONSE;
4234 }
4235
4236 RIL_ActivityStatsInfo *p_cur = (RIL_ActivityStatsInfo *)response;
4237 p.writeInt32(p_cur->sleep_mode_time_ms);
4238 p.writeInt32(p_cur->idle_mode_time_ms);
4239 for(int i = 0; i < RIL_NUM_TX_POWER_LEVELS; i++) {
4240 p.writeInt32(p_cur->tx_mode_time_ms[i]);
4241 }
4242 p.writeInt32(p_cur->rx_mode_time_ms);
4243
4244 startResponse;
Hyejine942c332015-09-14 16:27:28 -07004245 appendPrintBuf("Modem activity info received: sleep_mode_time_ms %d idle_mode_time_ms %d \
4246 tx_mode_time_ms %d %d %d %d %d and rx_mode_time_ms %d",
Prerepa Viswanadham8e755592015-05-28 00:37:32 -07004247 p_cur->sleep_mode_time_ms, p_cur->idle_mode_time_ms, p_cur->tx_mode_time_ms[0],
4248 p_cur->tx_mode_time_ms[1], p_cur->tx_mode_time_ms[2], p_cur->tx_mode_time_ms[3],
4249 p_cur->tx_mode_time_ms[4], p_cur->rx_mode_time_ms);
4250 closeResponse;
4251
4252 return 0;
4253}
4254
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004255/**
4256 * A write on the wakeup fd is done just to pop us out of select()
4257 * We empty the buffer here and then ril_event will reset the timers on the
4258 * way back down
4259 */
4260static void processWakeupCallback(int fd, short flags, void *param) {
4261 char buff[16];
4262 int ret;
4263
Ethan Chend6e30652013-08-04 22:49:56 -07004264 RLOGV("processWakeupCallback");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004265
4266 /* empty our wakeup socket out */
4267 do {
4268 ret = read(s_fdWakeupRead, &buff, sizeof(buff));
4269 } while (ret > 0 || (ret < 0 && errno == EINTR));
4270}
4271
Howard Sue32dbfd2015-01-07 15:55:57 +08004272static void onCommandsSocketClosed(RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004273 int ret;
4274 RequestInfo *p_cur;
Howard Sue32dbfd2015-01-07 15:55:57 +08004275 /* Hook for current context
4276 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
4277 pthread_mutex_t * pendingRequestsMutexHook = &s_pendingRequestsMutex;
4278 /* pendingRequestsHook refer to &s_pendingRequests */
4279 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004280
Howard Sue32dbfd2015-01-07 15:55:57 +08004281#if (SIM_COUNT >= 2)
4282 if (socket_id == RIL_SOCKET_2) {
4283 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
4284 pendingRequestsHook = &s_pendingRequests_socket2;
4285 }
4286#if (SIM_COUNT >= 3)
4287 else if (socket_id == RIL_SOCKET_3) {
4288 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
4289 pendingRequestsHook = &s_pendingRequests_socket3;
4290 }
4291#endif
4292#if (SIM_COUNT >= 4)
4293 else if (socket_id == RIL_SOCKET_4) {
4294 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
4295 pendingRequestsHook = &s_pendingRequests_socket4;
4296 }
4297#endif
4298#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004299 /* mark pending requests as "cancelled" so we dont report responses */
Howard Sue32dbfd2015-01-07 15:55:57 +08004300 ret = pthread_mutex_lock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004301 assert (ret == 0);
4302
Howard Sue32dbfd2015-01-07 15:55:57 +08004303 p_cur = *pendingRequestsHook;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004304
Howard Sue32dbfd2015-01-07 15:55:57 +08004305 for (p_cur = *pendingRequestsHook
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004306 ; p_cur != NULL
4307 ; p_cur = p_cur->p_next
4308 ) {
4309 p_cur->cancelled = 1;
4310 }
4311
Howard Sue32dbfd2015-01-07 15:55:57 +08004312 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004313 assert (ret == 0);
4314}
4315
4316static void processCommandsCallback(int fd, short flags, void *param) {
4317 RecordStream *p_rs;
4318 void *p_record;
4319 size_t recordlen;
4320 int ret;
Howard Sue32dbfd2015-01-07 15:55:57 +08004321 SocketListenParam *p_info = (SocketListenParam *)param;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004322
Howard Sue32dbfd2015-01-07 15:55:57 +08004323 assert(fd == p_info->fdCommand);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004324
Howard Sue32dbfd2015-01-07 15:55:57 +08004325 p_rs = p_info->p_rs;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004326
4327 for (;;) {
4328 /* loop until EAGAIN/EINTR, end of stream, or other error */
4329 ret = record_stream_get_next(p_rs, &p_record, &recordlen);
4330
4331 if (ret == 0 && p_record == NULL) {
4332 /* end-of-stream */
4333 break;
4334 } else if (ret < 0) {
4335 break;
4336 } else if (ret == 0) { /* && p_record != NULL */
Howard Sue32dbfd2015-01-07 15:55:57 +08004337 processCommandBuffer(p_record, recordlen, p_info->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004338 }
4339 }
4340
4341 if (ret == 0 || !(errno == EAGAIN || errno == EINTR)) {
4342 /* fatal error or end-of-stream */
4343 if (ret != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004344 RLOGE("error on reading command socket errno:%d\n", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004345 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004346 RLOGW("EOS. Closing command socket.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004347 }
4348
Howard Sue32dbfd2015-01-07 15:55:57 +08004349 close(fd);
4350 p_info->fdCommand = -1;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004351
Howard Sue32dbfd2015-01-07 15:55:57 +08004352 ril_event_del(p_info->commands_event);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004353
4354 record_stream_free(p_rs);
4355
4356 /* start listening for new connections again */
4357 rilEventAddWakeup(&s_listen_event);
4358
Howard Sue32dbfd2015-01-07 15:55:57 +08004359 onCommandsSocketClosed(p_info->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004360 }
4361}
4362
Howard Subd82ef12015-04-12 10:25:05 +02004363
Howard Sue32dbfd2015-01-07 15:55:57 +08004364static void onNewCommandConnect(RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004365 // Inform we are connected and the ril version
4366 int rilVer = s_callbacks.version;
Howard Sue32dbfd2015-01-07 15:55:57 +08004367 RIL_UNSOL_RESPONSE(RIL_UNSOL_RIL_CONNECTED,
4368 &rilVer, sizeof(rilVer), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004369
4370 // implicit radio state changed
Howard Sue32dbfd2015-01-07 15:55:57 +08004371 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
4372 NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004373
4374 // Send last NITZ time data, in case it was missed
4375 if (s_lastNITZTimeData != NULL) {
Howard Sue32dbfd2015-01-07 15:55:57 +08004376 sendResponseRaw(s_lastNITZTimeData, s_lastNITZTimeDataSize, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004377
4378 free(s_lastNITZTimeData);
4379 s_lastNITZTimeData = NULL;
4380 }
4381
4382 // Get version string
4383 if (s_callbacks.getVersion != NULL) {
4384 const char *version;
4385 version = s_callbacks.getVersion();
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004386 RLOGI("RIL Daemon version: %s\n", version);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004387
4388 property_set(PROPERTY_RIL_IMPL, version);
4389 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004390 RLOGI("RIL Daemon version: unavailable\n");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004391 property_set(PROPERTY_RIL_IMPL, "unavailable");
4392 }
4393
4394}
4395
4396static void listenCallback (int fd, short flags, void *param) {
4397 int ret;
4398 int err;
4399 int is_phone_socket;
Howard Sue32dbfd2015-01-07 15:55:57 +08004400 int fdCommand = -1;
Dheeraj Shettycc231012014-07-02 21:27:57 +02004401 char* processName;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004402 RecordStream *p_rs;
Dheeraj Shettycc231012014-07-02 21:27:57 +02004403 MySocketListenParam* listenParam;
4404 RilSocket *sapSocket = NULL;
4405 socketClient *sClient = NULL;
4406
Howard Sue32dbfd2015-01-07 15:55:57 +08004407 SocketListenParam *p_info = (SocketListenParam *)param;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004408
Dheeraj Shettycc231012014-07-02 21:27:57 +02004409 if(RIL_SAP_SOCKET == p_info->type) {
4410 listenParam = (MySocketListenParam *)param;
4411 sapSocket = listenParam->socket;
4412 }
4413
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004414 struct sockaddr_un peeraddr;
4415 socklen_t socklen = sizeof (peeraddr);
4416
4417 struct ucred creds;
4418 socklen_t szCreds = sizeof(creds);
4419
4420 struct passwd *pwd = NULL;
4421
Dheeraj Shettycc231012014-07-02 21:27:57 +02004422 if(NULL == sapSocket) {
4423 assert (*p_info->fdCommand < 0);
4424 assert (fd == *p_info->fdListen);
4425 processName = PHONE_PROCESS;
4426 } else {
4427 assert (sapSocket->commandFd < 0);
4428 assert (fd == sapSocket->listenFd);
4429 processName = BLUETOOTH_PROCESS;
4430 }
4431
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004432
Howard Sue32dbfd2015-01-07 15:55:57 +08004433 fdCommand = accept(fd, (sockaddr *) &peeraddr, &socklen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004434
Howard Sue32dbfd2015-01-07 15:55:57 +08004435 if (fdCommand < 0 ) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004436 RLOGE("Error on accept() errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004437 /* start listening for new connections again */
Dheeraj Shettycc231012014-07-02 21:27:57 +02004438 if(NULL == sapSocket) {
4439 rilEventAddWakeup(p_info->listen_event);
4440 } else {
4441 rilEventAddWakeup(sapSocket->getListenEvent());
4442 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004443 return;
4444 }
4445
4446 /* check the credential of the other side and only accept socket from
4447 * phone process
4448 */
4449 errno = 0;
4450 is_phone_socket = 0;
4451
Howard Sue32dbfd2015-01-07 15:55:57 +08004452 err = getsockopt(fdCommand, SOL_SOCKET, SO_PEERCRED, &creds, &szCreds);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004453
4454 if (err == 0 && szCreds > 0) {
4455 errno = 0;
4456 pwd = getpwuid(creds.uid);
4457 if (pwd != NULL) {
Dheeraj Shettycc231012014-07-02 21:27:57 +02004458 if (strcmp(pwd->pw_name, processName) == 0) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004459 is_phone_socket = 1;
4460 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004461 RLOGE("RILD can't accept socket from process %s", pwd->pw_name);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004462 }
4463 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004464 RLOGE("Error on getpwuid() errno: %d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004465 }
4466 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004467 RLOGD("Error on getsockopt() errno: %d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004468 }
4469
Howard Subd82ef12015-04-12 10:25:05 +02004470 if (!is_phone_socket) {
Dheeraj Shettycc231012014-07-02 21:27:57 +02004471 RLOGE("RILD must accept socket from %s", processName);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004472
Dheeraj Shettycc231012014-07-02 21:27:57 +02004473 close(fdCommand);
4474 fdCommand = -1;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004475
Dheeraj Shettycc231012014-07-02 21:27:57 +02004476 if(NULL == sapSocket) {
4477 onCommandsSocketClosed(p_info->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004478
Dheeraj Shettycc231012014-07-02 21:27:57 +02004479 /* start listening for new connections again */
4480 rilEventAddWakeup(p_info->listen_event);
4481 } else {
4482 sapSocket->onCommandsSocketClosed();
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004483
Dheeraj Shettycc231012014-07-02 21:27:57 +02004484 /* start listening for new connections again */
4485 rilEventAddWakeup(sapSocket->getListenEvent());
4486 }
4487
4488 return;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004489 }
4490
Howard Sue32dbfd2015-01-07 15:55:57 +08004491 ret = fcntl(fdCommand, F_SETFL, O_NONBLOCK);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004492
4493 if (ret < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004494 RLOGE ("Error setting O_NONBLOCK errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004495 }
4496
Dheeraj Shettycc231012014-07-02 21:27:57 +02004497 if(NULL == sapSocket) {
4498 RLOGI("libril: new connection to %s", rilSocketIdToString(p_info->socket_id));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004499
Dheeraj Shettycc231012014-07-02 21:27:57 +02004500 p_info->fdCommand = fdCommand;
4501 p_rs = record_stream_new(p_info->fdCommand, MAX_COMMAND_BYTES);
4502 p_info->p_rs = p_rs;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004503
Dheeraj Shettycc231012014-07-02 21:27:57 +02004504 ril_event_set (p_info->commands_event, p_info->fdCommand, 1,
Howard Sue32dbfd2015-01-07 15:55:57 +08004505 p_info->processCommandsCallback, p_info);
Dheeraj Shettycc231012014-07-02 21:27:57 +02004506 rilEventAddWakeup (p_info->commands_event);
Howard Sue32dbfd2015-01-07 15:55:57 +08004507
Dheeraj Shettycc231012014-07-02 21:27:57 +02004508 onNewCommandConnect(p_info->socket_id);
4509 } else {
4510 RLOGI("libril: new connection");
Howard Sue32dbfd2015-01-07 15:55:57 +08004511
Dheeraj Shettycc231012014-07-02 21:27:57 +02004512 sapSocket->setCommandFd(fdCommand);
4513 p_rs = record_stream_new(sapSocket->getCommandFd(), MAX_COMMAND_BYTES);
4514 sClient = new socketClient(sapSocket,p_rs);
4515 ril_event_set (sapSocket->getCallbackEvent(), sapSocket->getCommandFd(), 1,
4516 sapSocket->getCommandCb(), sClient);
4517
4518 rilEventAddWakeup(sapSocket->getCallbackEvent());
4519 sapSocket->onNewCommandConnect();
4520 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004521}
4522
4523static void freeDebugCallbackArgs(int number, char **args) {
4524 for (int i = 0; i < number; i++) {
4525 if (args[i] != NULL) {
4526 free(args[i]);
4527 }
4528 }
4529 free(args);
4530}
4531
4532static void debugCallback (int fd, short flags, void *param) {
4533 int acceptFD, option;
4534 struct sockaddr_un peeraddr;
4535 socklen_t socklen = sizeof (peeraddr);
4536 int data;
4537 unsigned int qxdm_data[6];
4538 const char *deactData[1] = {"1"};
4539 char *actData[1];
4540 RIL_Dial dialData;
4541 int hangupData[1] = {1};
4542 int number;
4543 char **args;
Howard Sue32dbfd2015-01-07 15:55:57 +08004544 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
4545 int sim_id = 0;
4546
4547 RLOGI("debugCallback for socket %s", rilSocketIdToString(socket_id));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004548
4549 acceptFD = accept (fd, (sockaddr *) &peeraddr, &socklen);
4550
4551 if (acceptFD < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004552 RLOGE ("error accepting on debug port: %d\n", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004553 return;
4554 }
4555
4556 if (recv(acceptFD, &number, sizeof(int), 0) != sizeof(int)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004557 RLOGE ("error reading on socket: number of Args: \n");
Sanket Padawedf3dabe2016-02-29 10:09:26 -08004558 close(acceptFD);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004559 return;
4560 }
Sanket Padawedf3dabe2016-02-29 10:09:26 -08004561
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004562 args = (char **) malloc(sizeof(char*) * number);
Sanket Padawedf3dabe2016-02-29 10:09:26 -08004563 if (args == NULL) {
4564 RLOGE("Memory allocation failed for debug args");
4565 close(acceptFD);
4566 return;
4567 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004568
4569 for (int i = 0; i < number; i++) {
4570 int len;
4571 if (recv(acceptFD, &len, sizeof(int), 0) != sizeof(int)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004572 RLOGE ("error reading on socket: Len of Args: \n");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004573 freeDebugCallbackArgs(i, args);
Sanket Padawedf3dabe2016-02-29 10:09:26 -08004574 close(acceptFD);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004575 return;
4576 }
Sanket Padawedf3dabe2016-02-29 10:09:26 -08004577
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004578 // +1 for null-term
4579 args[i] = (char *) malloc((sizeof(char) * len) + 1);
Sanket Padawedf3dabe2016-02-29 10:09:26 -08004580 if (args[i] == NULL) {
4581 RLOGE("Memory allocation failed for debug args");
4582 freeDebugCallbackArgs(i, args);
4583 close(acceptFD);
4584 return;
4585 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004586 if (recv(acceptFD, args[i], sizeof(char) * len, 0)
4587 != (int)sizeof(char) * len) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004588 RLOGE ("error reading on socket: Args[%d] \n", i);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004589 freeDebugCallbackArgs(i, args);
Sanket Padawedf3dabe2016-02-29 10:09:26 -08004590 close(acceptFD);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004591 return;
4592 }
4593 char * buf = args[i];
4594 buf[len] = 0;
Howard Sue32dbfd2015-01-07 15:55:57 +08004595 if ((i+1) == number) {
4596 /* The last argument should be sim id 0(SIM1)~3(SIM4) */
4597 sim_id = atoi(args[i]);
4598 switch (sim_id) {
4599 case 0:
4600 socket_id = RIL_SOCKET_1;
4601 break;
4602 #if (SIM_COUNT >= 2)
4603 case 1:
4604 socket_id = RIL_SOCKET_2;
4605 break;
4606 #endif
4607 #if (SIM_COUNT >= 3)
4608 case 2:
4609 socket_id = RIL_SOCKET_3;
4610 break;
4611 #endif
4612 #if (SIM_COUNT >= 4)
4613 case 3:
4614 socket_id = RIL_SOCKET_4;
4615 break;
4616 #endif
4617 default:
4618 socket_id = RIL_SOCKET_1;
4619 break;
4620 }
4621 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004622 }
4623
4624 switch (atoi(args[0])) {
4625 case 0:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004626 RLOGI ("Connection on debug port: issuing reset.");
Howard Sue32dbfd2015-01-07 15:55:57 +08004627 issueLocalRequest(RIL_REQUEST_RESET_RADIO, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004628 break;
4629 case 1:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004630 RLOGI ("Connection on debug port: issuing radio power off.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004631 data = 0;
Howard Sue32dbfd2015-01-07 15:55:57 +08004632 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004633 // Close the socket
Howard Subd82ef12015-04-12 10:25:05 +02004634 if (socket_id == RIL_SOCKET_1 && s_ril_param_socket.fdCommand > 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08004635 close(s_ril_param_socket.fdCommand);
4636 s_ril_param_socket.fdCommand = -1;
4637 }
4638 #if (SIM_COUNT == 2)
4639 else if (socket_id == RIL_SOCKET_2 && s_ril_param_socket2.fdCommand > 0) {
4640 close(s_ril_param_socket2.fdCommand);
4641 s_ril_param_socket2.fdCommand = -1;
4642 }
4643 #endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004644 break;
4645 case 2:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004646 RLOGI ("Debug port: issuing unsolicited voice network change.");
Howard Sue32dbfd2015-01-07 15:55:57 +08004647 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004648 break;
4649 case 3:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004650 RLOGI ("Debug port: QXDM log enable.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004651 qxdm_data[0] = 65536; // head.func_tag
4652 qxdm_data[1] = 16; // head.len
4653 qxdm_data[2] = 1; // mode: 1 for 'start logging'
4654 qxdm_data[3] = 32; // log_file_size: 32megabytes
4655 qxdm_data[4] = 0; // log_mask
4656 qxdm_data[5] = 8; // log_max_fileindex
4657 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Howard Sue32dbfd2015-01-07 15:55:57 +08004658 6 * sizeof(int), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004659 break;
4660 case 4:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004661 RLOGI ("Debug port: QXDM log disable.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004662 qxdm_data[0] = 65536;
4663 qxdm_data[1] = 16;
4664 qxdm_data[2] = 0; // mode: 0 for 'stop logging'
4665 qxdm_data[3] = 32;
4666 qxdm_data[4] = 0;
4667 qxdm_data[5] = 8;
4668 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Howard Sue32dbfd2015-01-07 15:55:57 +08004669 6 * sizeof(int), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004670 break;
4671 case 5:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004672 RLOGI("Debug port: Radio On");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004673 data = 1;
Howard Sue32dbfd2015-01-07 15:55:57 +08004674 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004675 sleep(2);
4676 // Set network selection automatic.
Howard Sue32dbfd2015-01-07 15:55:57 +08004677 issueLocalRequest(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004678 break;
4679 case 6:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004680 RLOGI("Debug port: Setup Data Call, Apn :%s\n", args[1]);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004681 actData[0] = args[1];
4682 issueLocalRequest(RIL_REQUEST_SETUP_DATA_CALL, &actData,
Howard Sue32dbfd2015-01-07 15:55:57 +08004683 sizeof(actData), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004684 break;
4685 case 7:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004686 RLOGI("Debug port: Deactivate Data Call");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004687 issueLocalRequest(RIL_REQUEST_DEACTIVATE_DATA_CALL, &deactData,
Howard Sue32dbfd2015-01-07 15:55:57 +08004688 sizeof(deactData), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004689 break;
4690 case 8:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004691 RLOGI("Debug port: Dial Call");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004692 dialData.clir = 0;
4693 dialData.address = args[1];
Howard Sue32dbfd2015-01-07 15:55:57 +08004694 issueLocalRequest(RIL_REQUEST_DIAL, &dialData, sizeof(dialData), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004695 break;
4696 case 9:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004697 RLOGI("Debug port: Answer Call");
Howard Sue32dbfd2015-01-07 15:55:57 +08004698 issueLocalRequest(RIL_REQUEST_ANSWER, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004699 break;
4700 case 10:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004701 RLOGI("Debug port: End Call");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004702 issueLocalRequest(RIL_REQUEST_HANGUP, &hangupData,
Howard Sue32dbfd2015-01-07 15:55:57 +08004703 sizeof(hangupData), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004704 break;
4705 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004706 RLOGE ("Invalid request");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004707 break;
4708 }
4709 freeDebugCallbackArgs(number, args);
4710 close(acceptFD);
4711}
4712
4713
4714static void userTimerCallback (int fd, short flags, void *param) {
4715 UserCallbackInfo *p_info;
4716
4717 p_info = (UserCallbackInfo *)param;
4718
4719 p_info->p_callback(p_info->userParam);
4720
4721
4722 // FIXME generalize this...there should be a cancel mechanism
4723 if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) {
4724 s_last_wake_timeout_info = NULL;
4725 }
4726
4727 free(p_info);
4728}
4729
4730
4731static void *
4732eventLoop(void *param) {
4733 int ret;
4734 int filedes[2];
4735
4736 ril_event_init();
4737
4738 pthread_mutex_lock(&s_startupMutex);
4739
4740 s_started = 1;
4741 pthread_cond_broadcast(&s_startupCond);
4742
4743 pthread_mutex_unlock(&s_startupMutex);
4744
4745 ret = pipe(filedes);
4746
4747 if (ret < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004748 RLOGE("Error in pipe() errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004749 return NULL;
4750 }
4751
4752 s_fdWakeupRead = filedes[0];
4753 s_fdWakeupWrite = filedes[1];
4754
4755 fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK);
4756
4757 ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,
4758 processWakeupCallback, NULL);
4759
4760 rilEventAddWakeup (&s_wakeupfd_event);
4761
4762 // Only returns on error
4763 ril_event_loop();
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004764 RLOGE ("error in event_loop_base errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004765 // kill self to restart on error
4766 kill(0, SIGKILL);
4767
4768 return NULL;
4769}
4770
4771extern "C" void
4772RIL_startEventLoop(void) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004773 /* spin up eventLoop thread and wait for it to get started */
4774 s_started = 0;
4775 pthread_mutex_lock(&s_startupMutex);
4776
Howard Sue32dbfd2015-01-07 15:55:57 +08004777 pthread_attr_t attr;
4778 pthread_attr_init(&attr);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004779 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
Howard Sue32dbfd2015-01-07 15:55:57 +08004780
4781 int result = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
4782 if (result != 0) {
4783 RLOGE("Failed to create dispatch thread: %s", strerror(result));
4784 goto done;
4785 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004786
4787 while (s_started == 0) {
4788 pthread_cond_wait(&s_startupCond, &s_startupMutex);
4789 }
4790
Howard Sue32dbfd2015-01-07 15:55:57 +08004791done:
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004792 pthread_mutex_unlock(&s_startupMutex);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004793}
4794
4795// Used for testing purpose only.
4796extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) {
4797 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4798}
4799
Howard Sue32dbfd2015-01-07 15:55:57 +08004800static void startListen(RIL_SOCKET_ID socket_id, SocketListenParam* socket_listen_p) {
4801 int fdListen = -1;
4802 int ret;
4803 char socket_name[10];
4804
4805 memset(socket_name, 0, sizeof(char)*10);
4806
4807 switch(socket_id) {
4808 case RIL_SOCKET_1:
4809 strncpy(socket_name, RIL_getRilSocketName(), 9);
4810 break;
4811 #if (SIM_COUNT >= 2)
4812 case RIL_SOCKET_2:
4813 strncpy(socket_name, SOCKET2_NAME_RIL, 9);
4814 break;
4815 #endif
4816 #if (SIM_COUNT >= 3)
4817 case RIL_SOCKET_3:
4818 strncpy(socket_name, SOCKET3_NAME_RIL, 9);
4819 break;
4820 #endif
4821 #if (SIM_COUNT >= 4)
4822 case RIL_SOCKET_4:
4823 strncpy(socket_name, SOCKET4_NAME_RIL, 9);
4824 break;
4825 #endif
4826 default:
4827 RLOGE("Socket id is wrong!!");
4828 return;
4829 }
4830
4831 RLOGI("Start to listen %s", rilSocketIdToString(socket_id));
4832
4833 fdListen = android_get_control_socket(socket_name);
4834 if (fdListen < 0) {
4835 RLOGE("Failed to get socket %s", socket_name);
4836 exit(-1);
4837 }
4838
4839 ret = listen(fdListen, 4);
4840
4841 if (ret < 0) {
4842 RLOGE("Failed to listen on control socket '%d': %s",
4843 fdListen, strerror(errno));
4844 exit(-1);
4845 }
4846 socket_listen_p->fdListen = fdListen;
4847
4848 /* note: non-persistent so we can accept only one connection at a time */
4849 ril_event_set (socket_listen_p->listen_event, fdListen, false,
4850 listenCallback, socket_listen_p);
4851
4852 rilEventAddWakeup (socket_listen_p->listen_event);
4853}
4854
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004855extern "C" void
4856RIL_register (const RIL_RadioFunctions *callbacks) {
4857 int ret;
4858 int flags;
4859
Howard Sue32dbfd2015-01-07 15:55:57 +08004860 RLOGI("SIM_COUNT: %d", SIM_COUNT);
4861
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004862 if (callbacks == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004863 RLOGE("RIL_register: RIL_RadioFunctions * null");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004864 return;
4865 }
4866 if (callbacks->version < RIL_VERSION_MIN) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004867 RLOGE("RIL_register: version %d is to old, min version is %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004868 callbacks->version, RIL_VERSION_MIN);
4869 return;
4870 }
Sanket Padawe9343e872016-01-11 12:45:43 -08004871
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004872 RLOGE("RIL_register: RIL version %d", callbacks->version);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004873
4874 if (s_registerCalled > 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004875 RLOGE("RIL_register has been called more than once. "
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004876 "Subsequent call ignored");
4877 return;
4878 }
4879
4880 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4881
Howard Sue32dbfd2015-01-07 15:55:57 +08004882 /* Initialize socket1 parameters */
4883 s_ril_param_socket = {
4884 RIL_SOCKET_1, /* socket_id */
4885 -1, /* fdListen */
4886 -1, /* fdCommand */
4887 PHONE_PROCESS, /* processName */
4888 &s_commands_event, /* commands_event */
4889 &s_listen_event, /* listen_event */
4890 processCommandsCallback, /* processCommandsCallback */
4891 NULL /* p_rs */
4892 };
4893
4894#if (SIM_COUNT >= 2)
4895 s_ril_param_socket2 = {
4896 RIL_SOCKET_2, /* socket_id */
4897 -1, /* fdListen */
4898 -1, /* fdCommand */
4899 PHONE_PROCESS, /* processName */
4900 &s_commands_event_socket2, /* commands_event */
4901 &s_listen_event_socket2, /* listen_event */
4902 processCommandsCallback, /* processCommandsCallback */
4903 NULL /* p_rs */
4904 };
4905#endif
4906
4907#if (SIM_COUNT >= 3)
4908 s_ril_param_socket3 = {
4909 RIL_SOCKET_3, /* socket_id */
4910 -1, /* fdListen */
4911 -1, /* fdCommand */
4912 PHONE_PROCESS, /* processName */
4913 &s_commands_event_socket3, /* commands_event */
4914 &s_listen_event_socket3, /* listen_event */
4915 processCommandsCallback, /* processCommandsCallback */
4916 NULL /* p_rs */
4917 };
4918#endif
4919
4920#if (SIM_COUNT >= 4)
4921 s_ril_param_socket4 = {
4922 RIL_SOCKET_4, /* socket_id */
4923 -1, /* fdListen */
4924 -1, /* fdCommand */
4925 PHONE_PROCESS, /* processName */
4926 &s_commands_event_socket4, /* commands_event */
4927 &s_listen_event_socket4, /* listen_event */
4928 processCommandsCallback, /* processCommandsCallback */
4929 NULL /* p_rs */
4930 };
4931#endif
4932
Howard Subd82ef12015-04-12 10:25:05 +02004933
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004934 s_registerCalled = 1;
4935
Howard Sue32dbfd2015-01-07 15:55:57 +08004936 RLOGI("s_registerCalled flag set, %d", s_started);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004937 // Little self-check
4938
4939 for (int i = 0; i < (int)NUM_ELEMS(s_commands); i++) {
4940 assert(i == s_commands[i].requestNumber);
4941 }
4942
Howard Subd82ef12015-04-12 10:25:05 +02004943 for (int i = 0; i < (int)NUM_ELEMS(s_commands_v); i++) {
4944 assert(i + RIL_VENDOR_COMMANDS_OFFSET == s_commands[i].requestNumber);
4945 }
4946
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004947 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses); i++) {
Howard Sue32dbfd2015-01-07 15:55:57 +08004948 assert(i + RIL_UNSOL_RESPONSE_BASE
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004949 == s_unsolResponses[i].requestNumber);
4950 }
4951
Howard Subd82ef12015-04-12 10:25:05 +02004952 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses_v); i++) {
4953 assert(i + RIL_UNSOL_RESPONSE_BASE + RIL_VENDOR_COMMANDS_OFFSET
4954 == s_unsolResponses[i].requestNumber);
4955 }
4956
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004957 // New rild impl calls RIL_startEventLoop() first
4958 // old standalone impl wants it here.
4959
4960 if (s_started == 0) {
4961 RIL_startEventLoop();
4962 }
4963
Howard Sue32dbfd2015-01-07 15:55:57 +08004964 // start listen socket1
4965 startListen(RIL_SOCKET_1, &s_ril_param_socket);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004966
Howard Sue32dbfd2015-01-07 15:55:57 +08004967#if (SIM_COUNT >= 2)
4968 // start listen socket2
4969 startListen(RIL_SOCKET_2, &s_ril_param_socket2);
4970#endif /* (SIM_COUNT == 2) */
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004971
Howard Sue32dbfd2015-01-07 15:55:57 +08004972#if (SIM_COUNT >= 3)
4973 // start listen socket3
4974 startListen(RIL_SOCKET_3, &s_ril_param_socket3);
4975#endif /* (SIM_COUNT == 3) */
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004976
Howard Sue32dbfd2015-01-07 15:55:57 +08004977#if (SIM_COUNT >= 4)
4978 // start listen socket4
4979 startListen(RIL_SOCKET_4, &s_ril_param_socket4);
4980#endif /* (SIM_COUNT == 4) */
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004981
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004982
4983#if 1
4984 // start debug interface socket
4985
Howard Sue32dbfd2015-01-07 15:55:57 +08004986 char *inst = NULL;
4987 if (strlen(RIL_getRilSocketName()) >= strlen(SOCKET_NAME_RIL)) {
4988 inst = RIL_getRilSocketName() + strlen(SOCKET_NAME_RIL);
4989 }
4990
4991 char rildebug[MAX_DEBUG_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL_DEBUG;
4992 if (inst != NULL) {
Andreas Schneider3063dc12015-04-13 23:04:05 +02004993 snprintf(rildebug, sizeof(rildebug), "%s%s", SOCKET_NAME_RIL_DEBUG, inst);
Howard Sue32dbfd2015-01-07 15:55:57 +08004994 }
4995
4996 s_fdDebug = android_get_control_socket(rildebug);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004997 if (s_fdDebug < 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08004998 RLOGE("Failed to get socket : %s errno:%d", rildebug, errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004999 exit(-1);
5000 }
5001
5002 ret = listen(s_fdDebug, 4);
5003
5004 if (ret < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005005 RLOGE("Failed to listen on ril debug socket '%d': %s",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005006 s_fdDebug, strerror(errno));
5007 exit(-1);
5008 }
5009
5010 ril_event_set (&s_debug_event, s_fdDebug, true,
5011 debugCallback, NULL);
5012
5013 rilEventAddWakeup (&s_debug_event);
5014#endif
5015
5016}
5017
Dheeraj Shettycc231012014-07-02 21:27:57 +02005018extern "C" void
5019RIL_register_socket (RIL_RadioFunctions *(*Init)(const struct RIL_Env *, int, char **),RIL_SOCKET_TYPE socketType, int argc, char **argv) {
5020
5021 RIL_RadioFunctions* UimFuncs = NULL;
5022
5023 if(Init) {
5024 UimFuncs = Init(&RilSapSocket::uimRilEnv, argc, argv);
5025
5026 switch(socketType) {
5027 case RIL_SAP_SOCKET:
5028 RilSapSocket::initSapSocket("sap_uim_socket1", UimFuncs);
5029
5030#if (SIM_COUNT >= 2)
5031 RilSapSocket::initSapSocket("sap_uim_socket2", UimFuncs);
5032#endif
5033
5034#if (SIM_COUNT >= 3)
5035 RilSapSocket::initSapSocket("sap_uim_socket3", UimFuncs);
5036#endif
5037
5038#if (SIM_COUNT >= 4)
5039 RilSapSocket::initSapSocket("sap_uim_socket4", UimFuncs);
5040#endif
5041 }
5042 }
5043}
5044
Sanket Padawea7c043d2016-01-27 15:09:12 -08005045// Check and remove RequestInfo if its a response and not just ack sent back
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005046static int
Sanket Padawea7c043d2016-01-27 15:09:12 -08005047checkAndDequeueRequestInfoIfAck(struct RequestInfo *pRI, bool isAck) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005048 int ret = 0;
Howard Sue32dbfd2015-01-07 15:55:57 +08005049 /* Hook for current context
5050 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
5051 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
5052 /* pendingRequestsHook refer to &s_pendingRequests */
5053 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005054
5055 if (pRI == NULL) {
5056 return 0;
5057 }
5058
Howard Sue32dbfd2015-01-07 15:55:57 +08005059#if (SIM_COUNT >= 2)
5060 if (pRI->socket_id == RIL_SOCKET_2) {
5061 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
5062 pendingRequestsHook = &s_pendingRequests_socket2;
5063 }
5064#if (SIM_COUNT >= 3)
5065 if (pRI->socket_id == RIL_SOCKET_3) {
5066 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
5067 pendingRequestsHook = &s_pendingRequests_socket3;
5068 }
5069#endif
5070#if (SIM_COUNT >= 4)
5071 if (pRI->socket_id == RIL_SOCKET_4) {
5072 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
5073 pendingRequestsHook = &s_pendingRequests_socket4;
5074 }
5075#endif
5076#endif
5077 pthread_mutex_lock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005078
Howard Sue32dbfd2015-01-07 15:55:57 +08005079 for(RequestInfo **ppCur = pendingRequestsHook
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005080 ; *ppCur != NULL
5081 ; ppCur = &((*ppCur)->p_next)
5082 ) {
5083 if (pRI == *ppCur) {
5084 ret = 1;
Sanket Padawea7c043d2016-01-27 15:09:12 -08005085 if (isAck) { // Async ack
5086 if (pRI->wasAckSent == 1) {
5087 RLOGD("Ack was already sent for %s", requestToString(pRI->pCI->requestNumber));
5088 } else {
5089 pRI->wasAckSent = 1;
5090 }
5091 } else {
5092 *ppCur = (*ppCur)->p_next;
5093 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005094 break;
5095 }
5096 }
5097
Howard Sue32dbfd2015-01-07 15:55:57 +08005098 pthread_mutex_unlock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005099
5100 return ret;
5101}
5102
Sanket Padawea7c043d2016-01-27 15:09:12 -08005103static int findFd(int socket_id) {
Howard Sue32dbfd2015-01-07 15:55:57 +08005104 int fd = s_ril_param_socket.fdCommand;
Howard Sue32dbfd2015-01-07 15:55:57 +08005105#if (SIM_COUNT >= 2)
5106 if (socket_id == RIL_SOCKET_2) {
5107 fd = s_ril_param_socket2.fdCommand;
5108 }
5109#if (SIM_COUNT >= 3)
Sanket Padawea7c043d2016-01-27 15:09:12 -08005110 if (socket_id == RIL_SOCKET_3) {
5111 fd = s_ril_param_socket3.fdCommand;
5112 }
Howard Sue32dbfd2015-01-07 15:55:57 +08005113#endif
5114#if (SIM_COUNT >= 4)
5115 if (socket_id == RIL_SOCKET_4) {
5116 fd = s_ril_param_socket4.fdCommand;
5117 }
5118#endif
5119#endif
Sanket Padawea7c043d2016-01-27 15:09:12 -08005120 return fd;
5121}
5122
5123extern "C" void
5124RIL_onRequestAck(RIL_Token t) {
5125 RequestInfo *pRI;
5126 int ret, fd;
5127
5128 size_t errorOffset;
5129 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
5130
5131 pRI = (RequestInfo *)t;
5132
5133 if (!checkAndDequeueRequestInfoIfAck(pRI, true)) {
5134 RLOGE ("RIL_onRequestAck: invalid RIL_Token");
5135 return;
5136 }
5137
5138 socket_id = pRI->socket_id;
5139 fd = findFd(socket_id);
5140
5141#if VDBG
5142 RLOGD("Request Ack, %s", rilSocketIdToString(socket_id));
5143#endif
5144
5145 appendPrintBuf("Ack [%04d]< %s", pRI->token, requestToString(pRI->pCI->requestNumber));
5146
5147 if (pRI->cancelled == 0) {
5148 Parcel p;
5149
5150 p.writeInt32 (RESPONSE_SOLICITED_ACK);
5151 p.writeInt32 (pRI->token);
5152
5153 if (fd < 0) {
5154 RLOGD ("RIL onRequestComplete: Command channel closed");
5155 }
5156
5157 sendResponse(p, socket_id);
5158 }
5159}
5160
5161extern "C" void
5162RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) {
5163 RequestInfo *pRI;
5164 int ret;
5165 int fd;
5166 size_t errorOffset;
5167 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
5168
5169 pRI = (RequestInfo *)t;
5170
5171 if (!checkAndDequeueRequestInfoIfAck(pRI, false)) {
5172 RLOGE ("RIL_onRequestComplete: invalid RIL_Token");
5173 return;
5174 }
5175
5176 socket_id = pRI->socket_id;
5177 fd = findFd(socket_id);
5178
Robert Greenwaltbc29c432015-04-29 16:57:39 -07005179#if VDBG
Howard Sue32dbfd2015-01-07 15:55:57 +08005180 RLOGD("RequestComplete, %s", rilSocketIdToString(socket_id));
Robert Greenwaltbc29c432015-04-29 16:57:39 -07005181#endif
Howard Sue32dbfd2015-01-07 15:55:57 +08005182
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005183 if (pRI->local > 0) {
5184 // Locally issued command...void only!
5185 // response does not go back up the command socket
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005186 RLOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005187
5188 goto done;
5189 }
5190
5191 appendPrintBuf("[%04d]< %s",
5192 pRI->token, requestToString(pRI->pCI->requestNumber));
5193
5194 if (pRI->cancelled == 0) {
5195 Parcel p;
5196
Sanket Padawea7c043d2016-01-27 15:09:12 -08005197 if (s_callbacks.version >= 13 && pRI->wasAckSent == 1) {
5198 // If ack was already sent, then this call is an asynchronous response. So we need to
5199 // send id indicating that we expect an ack from RIL.java as we acquire wakelock here.
5200 p.writeInt32 (RESPONSE_SOLICITED_ACK_EXP);
5201 grabPartialWakeLock();
5202 } else {
5203 p.writeInt32 (RESPONSE_SOLICITED);
5204 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005205 p.writeInt32 (pRI->token);
5206 errorOffset = p.dataPosition();
5207
5208 p.writeInt32 (e);
5209
5210 if (response != NULL) {
5211 // there is a response payload, no matter success or not.
5212 ret = pRI->pCI->responseFunction(p, response, responselen);
5213
5214 /* if an error occurred, rewind and mark it */
5215 if (ret != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08005216 RLOGE ("responseFunction error, ret %d", ret);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005217 p.setDataPosition(errorOffset);
5218 p.writeInt32 (ret);
5219 }
5220 }
5221
5222 if (e != RIL_E_SUCCESS) {
5223 appendPrintBuf("%s fails by %s", printBuf, failCauseToString(e));
5224 }
5225
Howard Sue32dbfd2015-01-07 15:55:57 +08005226 if (fd < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005227 RLOGD ("RIL onRequestComplete: Command channel closed");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005228 }
Howard Sue32dbfd2015-01-07 15:55:57 +08005229 sendResponse(p, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005230 }
5231
5232done:
5233 free(pRI);
5234}
5235
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005236static void
5237grabPartialWakeLock() {
Sanket Padawea7c043d2016-01-27 15:09:12 -08005238 if (s_callbacks.version >= 13) {
5239 int ret;
5240 ret = pthread_mutex_lock(&s_wakeLockCountMutex);
5241 assert(ret == 0);
5242 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
Sanket Padawedf3dabe2016-02-29 10:09:26 -08005243
5244 UserCallbackInfo *p_info =
5245 internalRequestTimedCallback(wakeTimeoutCallback, NULL, &TIMEVAL_WAKE_TIMEOUT);
5246 if (p_info == NULL) {
5247 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
5248 } else {
5249 s_wakelock_count++;
5250 if (s_last_wake_timeout_info != NULL) {
5251 s_last_wake_timeout_info->userParam = (void *)1;
5252 }
5253 s_last_wake_timeout_info = p_info;
Sanket Padawea7c043d2016-01-27 15:09:12 -08005254 }
Sanket Padawea7c043d2016-01-27 15:09:12 -08005255 ret = pthread_mutex_unlock(&s_wakeLockCountMutex);
5256 assert(ret == 0);
5257 } else {
5258 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
5259 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005260}
5261
5262static void
5263releaseWakeLock() {
Sanket Padawea7c043d2016-01-27 15:09:12 -08005264 if (s_callbacks.version >= 13) {
5265 int ret;
5266 ret = pthread_mutex_lock(&s_wakeLockCountMutex);
5267 assert(ret == 0);
5268
5269 if (s_wakelock_count > 1) {
5270 s_wakelock_count--;
5271 } else {
5272 s_wakelock_count = 0;
5273 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
5274 if (s_last_wake_timeout_info != NULL) {
5275 s_last_wake_timeout_info->userParam = (void *)1;
5276 }
5277 }
5278
5279 ret = pthread_mutex_unlock(&s_wakeLockCountMutex);
5280 assert(ret == 0);
5281 } else {
5282 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
5283 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005284}
5285
5286/**
5287 * Timer callback to put us back to sleep before the default timeout
5288 */
5289static void
5290wakeTimeoutCallback (void *param) {
5291 // We're using "param != NULL" as a cancellation mechanism
Sanket Padawea7c043d2016-01-27 15:09:12 -08005292 if (s_callbacks.version >= 13) {
5293 if (param == NULL) {
5294 int ret;
5295 ret = pthread_mutex_lock(&s_wakeLockCountMutex);
5296 assert(ret == 0);
5297 s_wakelock_count = 0;
5298 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
5299 ret = pthread_mutex_unlock(&s_wakeLockCountMutex);
5300 assert(ret == 0);
5301 }
5302 } else {
5303 if (param == NULL) {
5304 releaseWakeLock();
5305 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005306 }
5307}
5308
5309static int
5310decodeVoiceRadioTechnology (RIL_RadioState radioState) {
5311 switch (radioState) {
5312 case RADIO_STATE_SIM_NOT_READY:
5313 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
5314 case RADIO_STATE_SIM_READY:
5315 return RADIO_TECH_UMTS;
5316
5317 case RADIO_STATE_RUIM_NOT_READY:
5318 case RADIO_STATE_RUIM_READY:
5319 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
5320 case RADIO_STATE_NV_NOT_READY:
5321 case RADIO_STATE_NV_READY:
5322 return RADIO_TECH_1xRTT;
5323
5324 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005325 RLOGD("decodeVoiceRadioTechnology: Invoked with incorrect RadioState");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005326 return -1;
5327 }
5328}
5329
5330static int
5331decodeCdmaSubscriptionSource (RIL_RadioState radioState) {
5332 switch (radioState) {
5333 case RADIO_STATE_SIM_NOT_READY:
5334 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
5335 case RADIO_STATE_SIM_READY:
5336 case RADIO_STATE_RUIM_NOT_READY:
5337 case RADIO_STATE_RUIM_READY:
5338 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
5339 return CDMA_SUBSCRIPTION_SOURCE_RUIM_SIM;
5340
5341 case RADIO_STATE_NV_NOT_READY:
5342 case RADIO_STATE_NV_READY:
5343 return CDMA_SUBSCRIPTION_SOURCE_NV;
5344
5345 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005346 RLOGD("decodeCdmaSubscriptionSource: Invoked with incorrect RadioState");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005347 return -1;
5348 }
5349}
5350
5351static int
5352decodeSimStatus (RIL_RadioState radioState) {
5353 switch (radioState) {
5354 case RADIO_STATE_SIM_NOT_READY:
5355 case RADIO_STATE_RUIM_NOT_READY:
5356 case RADIO_STATE_NV_NOT_READY:
5357 case RADIO_STATE_NV_READY:
5358 return -1;
5359 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
5360 case RADIO_STATE_SIM_READY:
5361 case RADIO_STATE_RUIM_READY:
5362 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
5363 return radioState;
5364 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005365 RLOGD("decodeSimStatus: Invoked with incorrect RadioState");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005366 return -1;
5367 }
5368}
5369
5370static bool is3gpp2(int radioTech) {
5371 switch (radioTech) {
5372 case RADIO_TECH_IS95A:
5373 case RADIO_TECH_IS95B:
5374 case RADIO_TECH_1xRTT:
5375 case RADIO_TECH_EVDO_0:
5376 case RADIO_TECH_EVDO_A:
5377 case RADIO_TECH_EVDO_B:
5378 case RADIO_TECH_EHRPD:
5379 return true;
5380 default:
5381 return false;
5382 }
5383}
5384
5385/* If RIL sends SIM states or RUIM states, store the voice radio
5386 * technology and subscription source information so that they can be
5387 * returned when telephony framework requests them
5388 */
5389static RIL_RadioState
Howard Subd82ef12015-04-12 10:25:05 +02005390processRadioState(RIL_RadioState newRadioState, RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005391
5392 if((newRadioState > RADIO_STATE_UNAVAILABLE) && (newRadioState < RADIO_STATE_ON)) {
5393 int newVoiceRadioTech;
5394 int newCdmaSubscriptionSource;
5395 int newSimStatus;
5396
5397 /* This is old RIL. Decode Subscription source and Voice Radio Technology
5398 from Radio State and send change notifications if there has been a change */
5399 newVoiceRadioTech = decodeVoiceRadioTechnology(newRadioState);
5400 if(newVoiceRadioTech != voiceRadioTech) {
5401 voiceRadioTech = newVoiceRadioTech;
Howard Sue32dbfd2015-01-07 15:55:57 +08005402 RIL_UNSOL_RESPONSE(RIL_UNSOL_VOICE_RADIO_TECH_CHANGED,
5403 &voiceRadioTech, sizeof(voiceRadioTech), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005404 }
5405 if(is3gpp2(newVoiceRadioTech)) {
5406 newCdmaSubscriptionSource = decodeCdmaSubscriptionSource(newRadioState);
5407 if(newCdmaSubscriptionSource != cdmaSubscriptionSource) {
5408 cdmaSubscriptionSource = newCdmaSubscriptionSource;
Howard Sue32dbfd2015-01-07 15:55:57 +08005409 RIL_UNSOL_RESPONSE(RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED,
5410 &cdmaSubscriptionSource, sizeof(cdmaSubscriptionSource), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005411 }
5412 }
5413 newSimStatus = decodeSimStatus(newRadioState);
5414 if(newSimStatus != simRuimStatus) {
5415 simRuimStatus = newSimStatus;
Howard Sue32dbfd2015-01-07 15:55:57 +08005416 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005417 }
5418
5419 /* Send RADIO_ON to telephony */
5420 newRadioState = RADIO_STATE_ON;
5421 }
5422
5423 return newRadioState;
5424}
5425
Howard Subd82ef12015-04-12 10:25:05 +02005426
Howard Sue32dbfd2015-01-07 15:55:57 +08005427#if defined(ANDROID_MULTI_SIM)
5428extern "C"
Andreas Schneider47b2d962015-04-13 22:54:49 +02005429void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Howard Sue32dbfd2015-01-07 15:55:57 +08005430 size_t datalen, RIL_SOCKET_ID socket_id)
5431#else
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005432extern "C"
Andreas Schneider47b2d962015-04-13 22:54:49 +02005433void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005434 size_t datalen)
Howard Sue32dbfd2015-01-07 15:55:57 +08005435#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005436{
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005437 int ret;
5438 int64_t timeReceived = 0;
5439 bool shouldScheduleTimeout = false;
5440 RIL_RadioState newState;
Howard Sue32dbfd2015-01-07 15:55:57 +08005441 RIL_SOCKET_ID soc_id = RIL_SOCKET_1;
Howard Subd82ef12015-04-12 10:25:05 +02005442 UnsolResponseInfo *pRI = NULL;
Howard Sue32dbfd2015-01-07 15:55:57 +08005443
5444#if defined(ANDROID_MULTI_SIM)
5445 soc_id = socket_id;
5446#endif
5447
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005448
5449 if (s_registerCalled == 0) {
5450 // Ignore RIL_onUnsolicitedResponse before RIL_register
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005451 RLOGW("RIL_onUnsolicitedResponse called before RIL_register");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005452 return;
5453 }
Howard Sue32dbfd2015-01-07 15:55:57 +08005454
Howard Subd82ef12015-04-12 10:25:05 +02005455 /* Hack to include Samsung responses */
5456 if (unsolResponse > RIL_VENDOR_COMMANDS_OFFSET + RIL_UNSOL_RESPONSE_BASE) {
5457 int index = unsolResponse - RIL_VENDOR_COMMANDS_OFFSET - RIL_UNSOL_RESPONSE_BASE;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005458
Howard Subd82ef12015-04-12 10:25:05 +02005459 RLOGD("SAMSUNG: unsolResponse=%d, unsolResponseIndex=%d", unsolResponse, index);
5460
5461 if (index < (int32_t)NUM_ELEMS(s_unsolResponses_v))
5462 pRI = &s_unsolResponses_v[index];
5463 } else {
5464 int index = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
5465 if (index < (int32_t)NUM_ELEMS(s_unsolResponses))
5466 pRI = &s_unsolResponses[index];
5467 }
5468
5469 if (pRI == NULL || pRI->responseFunction == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005470 RLOGE("unsupported unsolicited response code %d", unsolResponse);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005471 return;
5472 }
5473
5474 // Grab a wake lock if needed for this reponse,
5475 // as we exit we'll either release it immediately
5476 // or set a timer to release it later.
Howard Subd82ef12015-04-12 10:25:05 +02005477 switch (pRI->wakeType) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005478 case WAKE_PARTIAL:
5479 grabPartialWakeLock();
5480 shouldScheduleTimeout = true;
5481 break;
5482
5483 case DONT_WAKE:
5484 default:
5485 // No wake lock is grabed so don't set timeout
5486 shouldScheduleTimeout = false;
5487 break;
5488 }
5489
5490 // Mark the time this was received, doing this
5491 // after grabing the wakelock incase getting
5492 // the elapsedRealTime might cause us to goto
5493 // sleep.
5494 if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
5495 timeReceived = elapsedRealtime();
5496 }
5497
5498 appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
5499
5500 Parcel p;
Sanket Padawe9f972082016-02-03 11:46:02 -08005501 if (s_callbacks.version >= 13
5502 && pRI->wakeType == WAKE_PARTIAL) {
5503 p.writeInt32 (RESPONSE_UNSOLICITED_ACK_EXP);
5504 } else {
5505 p.writeInt32 (RESPONSE_UNSOLICITED);
5506 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005507 p.writeInt32 (unsolResponse);
5508
Howard Subd82ef12015-04-12 10:25:05 +02005509 ret = pRI->responseFunction(p, const_cast<void*>(data), datalen);
5510
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005511 if (ret != 0) {
5512 // Problem with the response. Don't continue;
5513 goto error_exit;
5514 }
5515
5516 // some things get more payload
5517 switch(unsolResponse) {
5518 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
Howard Sue32dbfd2015-01-07 15:55:57 +08005519 newState = processRadioState(CALL_ONSTATEREQUEST(soc_id), soc_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005520 p.writeInt32(newState);
5521 appendPrintBuf("%s {%s}", printBuf,
Howard Sue32dbfd2015-01-07 15:55:57 +08005522 radioStateToString(CALL_ONSTATEREQUEST(soc_id)));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005523 break;
5524
5525
5526 case RIL_UNSOL_NITZ_TIME_RECEIVED:
5527 // Store the time that this was received so the
5528 // handler of this message can account for
5529 // the time it takes to arrive and process. In
5530 // particular the system has been known to sleep
5531 // before this message can be processed.
5532 p.writeInt64(timeReceived);
5533 break;
5534 }
5535
Sanket Padawedf3dabe2016-02-29 10:09:26 -08005536 if (s_callbacks.version < 13) {
5537 if (shouldScheduleTimeout) {
5538 UserCallbackInfo *p_info = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
5539 &TIMEVAL_WAKE_TIMEOUT);
5540
5541 if (p_info == NULL) {
5542 goto error_exit;
5543 } else {
5544 // Cancel the previous request
5545 if (s_last_wake_timeout_info != NULL) {
5546 s_last_wake_timeout_info->userParam = (void *)1;
5547 }
5548 s_last_wake_timeout_info = p_info;
5549 }
5550 }
5551 }
5552
Robert Greenwaltbc29c432015-04-29 16:57:39 -07005553#if VDBG
Howard Sue32dbfd2015-01-07 15:55:57 +08005554 RLOGI("%s UNSOLICITED: %s length:%d", rilSocketIdToString(soc_id), requestToString(unsolResponse), p.dataSize());
Robert Greenwaltbc29c432015-04-29 16:57:39 -07005555#endif
Howard Sue32dbfd2015-01-07 15:55:57 +08005556 ret = sendResponse(p, soc_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005557 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
5558
5559 // Unfortunately, NITZ time is not poll/update like everything
5560 // else in the system. So, if the upstream client isn't connected,
5561 // keep a copy of the last NITZ response (with receive time noted
5562 // above) around so we can deliver it when it is connected
5563
5564 if (s_lastNITZTimeData != NULL) {
5565 free (s_lastNITZTimeData);
5566 s_lastNITZTimeData = NULL;
5567 }
5568
5569 s_lastNITZTimeData = malloc(p.dataSize());
Sanket Padawedf3dabe2016-02-29 10:09:26 -08005570 if (s_lastNITZTimeData == NULL) {
5571 RLOGE("Memory allocation failed in RIL_onUnsolicitedResponse");
5572 goto error_exit;
5573 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005574 s_lastNITZTimeDataSize = p.dataSize();
5575 memcpy(s_lastNITZTimeData, p.data(), p.dataSize());
5576 }
5577
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005578 // Normal exit
5579 return;
5580
5581error_exit:
5582 if (shouldScheduleTimeout) {
5583 releaseWakeLock();
5584 }
5585}
5586
5587/** FIXME generalize this if you track UserCAllbackInfo, clear it
5588 when the callback occurs
5589*/
5590static UserCallbackInfo *
5591internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
5592 const struct timeval *relativeTime)
5593{
5594 struct timeval myRelativeTime;
5595 UserCallbackInfo *p_info;
5596
5597 p_info = (UserCallbackInfo *) malloc (sizeof(UserCallbackInfo));
Sanket Padawedf3dabe2016-02-29 10:09:26 -08005598 if (p_info == NULL) {
5599 RLOGE("Memory allocation failed in internalRequestTimedCallback");
5600 return p_info;
5601
5602 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005603
5604 p_info->p_callback = callback;
5605 p_info->userParam = param;
5606
5607 if (relativeTime == NULL) {
5608 /* treat null parameter as a 0 relative time */
5609 memset (&myRelativeTime, 0, sizeof(myRelativeTime));
5610 } else {
5611 /* FIXME I think event_add's tv param is really const anyway */
5612 memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
5613 }
5614
5615 ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
5616
5617 ril_timer_add(&(p_info->event), &myRelativeTime);
5618
5619 triggerEvLoop();
5620 return p_info;
5621}
5622
5623
5624extern "C" void
5625RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
5626 const struct timeval *relativeTime) {
5627 internalRequestTimedCallback (callback, param, relativeTime);
5628}
5629
5630const char *
5631failCauseToString(RIL_Errno e) {
5632 switch(e) {
5633 case RIL_E_SUCCESS: return "E_SUCCESS";
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005634 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RADIO_NOT_AVAILABLE";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005635 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
5636 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
5637 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
5638 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
5639 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
5640 case RIL_E_CANCELLED: return "E_CANCELLED";
5641 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
5642 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
5643 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
5644 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
5645 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
5646#ifdef FEATURE_MULTIMODE_ANDROID
5647 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
5648 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
5649#endif
Sanket Padawe6049dec2016-02-08 14:28:59 -08005650 case RIL_E_FDN_CHECK_FAILURE: return "E_FDN_CHECK_FAILURE";
5651 case RIL_E_MISSING_RESOURCE: return "E_MISSING_RESOURCE";
5652 case RIL_E_NO_SUCH_ELEMENT: return "E_NO_SUCH_ELEMENT";
5653 case RIL_E_DIAL_MODIFIED_TO_USSD: return "E_DIAL_MODIFIED_TO_USSD";
5654 case RIL_E_DIAL_MODIFIED_TO_SS: return "E_DIAL_MODIFIED_TO_SS";
5655 case RIL_E_DIAL_MODIFIED_TO_DIAL: return "E_DIAL_MODIFIED_TO_DIAL";
5656 case RIL_E_USSD_MODIFIED_TO_DIAL: return "E_USSD_MODIFIED_TO_DIAL";
5657 case RIL_E_USSD_MODIFIED_TO_SS: return "E_USSD_MODIFIED_TO_SS";
5658 case RIL_E_USSD_MODIFIED_TO_USSD: return "E_USSD_MODIFIED_TO_USSD";
5659 case RIL_E_SS_MODIFIED_TO_DIAL: return "E_SS_MODIFIED_TO_DIAL";
5660 case RIL_E_SS_MODIFIED_TO_USSD: return "E_SS_MODIFIED_TO_USSD";
5661 case RIL_E_SUBSCRIPTION_NOT_SUPPORTED: return "E_SUBSCRIPTION_NOT_SUPPORTED";
5662 case RIL_E_SS_MODIFIED_TO_SS: return "E_SS_MODIFIED_TO_SS";
5663 case RIL_E_LCE_NOT_SUPPORTED: return "E_LCE_NOT_SUPPORTED";
5664 case RIL_E_NO_MEMORY: return "E_NO_MEMORY";
5665 case RIL_E_INTERNAL_ERR: return "E_INTERNAL_ERR";
5666 case RIL_E_SYSTEM_ERR: return "E_SYSTEM_ERR";
5667 case RIL_E_MODEM_ERR: return "E_MODEM_ERR";
5668 case RIL_E_INVALID_STATE: return "E_INVALID_STATE";
5669 case RIL_E_NO_RESOURCES: return "E_NO_RESOURCES";
5670 case RIL_E_SIM_ERR: return "E_SIM_ERR";
5671 case RIL_E_INVALID_ARGUMENTS: return "E_INVALID_ARGUMENTS";
5672 case RIL_E_INVALID_SIM_STATE: return "E_INVALID_SIM_STATE";
5673 case RIL_E_INVALID_MODEM_STATE: return "E_INVALID_MODEM_STATE";
5674 case RIL_E_INVALID_CALL_ID: return "E_INVALID_CALL_ID";
5675 case RIL_E_NO_SMS_TO_ACK: return "E_NO_SMS_TO_ACK";
5676 case RIL_E_NETWORK_ERR: return "E_NETWORK_ERR";
5677 case RIL_E_REQUEST_RATE_LIMITED: return "E_REQUEST_RATE_LIMITED";
twen.chang7dd377c2016-03-04 18:27:48 +08005678 case RIL_E_SIM_BUSY: return "E_SIM_BUSY";
5679 case RIL_E_SIM_FULL: return "E_SIM_FULL";
5680 case RIL_E_NETWORK_REJECT: return "E_NETWORK_REJECT";
5681 case RIL_E_OPERATION_NOT_ALLOWED: return "E_OPERATION_NOT_ALLOWED";
5682 case RIL_E_EMPTY_RECORD: "E_EMPTY_RECORD";
Ajay Nambi69659752016-03-11 12:02:55 -08005683 case RIL_E_INVALID_SMS_FORMAT: return "E_INVALID_SMS_FORMAT";
5684 case RIL_E_ENCODING_ERR: return "E_ENCODING_ERR";
5685 case RIL_E_INVALID_SMSC_ADDRESS: return "E_INVALID_SMSC_ADDRESS";
5686 case RIL_E_NO_SUCH_ENTRY: return "E_NO_SUCH_ENTRY";
5687 case RIL_E_NETWORK_NOT_READY: return "E_NETWORK_NOT_READY";
5688 case RIL_E_NOT_PROVISIONED: return "E_NOT_PROVISIONED";
Ajay Nambi0af7d1c2016-03-19 09:02:28 -07005689 case RIL_E_NO_SUBSCRIPTION: return "E_NO_SUBSCRIPTION";
5690 case RIL_E_NO_NETWORK_FOUND: return "E_NO_NETWORK_FOUND";
5691 case RIL_E_DEVICE_IN_USE: return "E_DEVICE_IN_USE";
5692 case RIL_E_ABORTED: return "E_ABORTED";
Sanket Padawedb5d1e02016-02-09 09:56:31 -08005693 case RIL_E_OEM_ERROR_1: return "E_OEM_ERROR_1";
5694 case RIL_E_OEM_ERROR_2: return "E_OEM_ERROR_2";
5695 case RIL_E_OEM_ERROR_3: return "E_OEM_ERROR_3";
5696 case RIL_E_OEM_ERROR_4: return "E_OEM_ERROR_4";
5697 case RIL_E_OEM_ERROR_5: return "E_OEM_ERROR_5";
5698 case RIL_E_OEM_ERROR_6: return "E_OEM_ERROR_6";
5699 case RIL_E_OEM_ERROR_7: return "E_OEM_ERROR_7";
5700 case RIL_E_OEM_ERROR_8: return "E_OEM_ERROR_8";
5701 case RIL_E_OEM_ERROR_9: return "E_OEM_ERROR_9";
5702 case RIL_E_OEM_ERROR_10: return "E_OEM_ERROR_10";
5703 case RIL_E_OEM_ERROR_11: return "E_OEM_ERROR_11";
5704 case RIL_E_OEM_ERROR_12: return "E_OEM_ERROR_12";
5705 case RIL_E_OEM_ERROR_13: return "E_OEM_ERROR_13";
5706 case RIL_E_OEM_ERROR_14: return "E_OEM_ERROR_14";
5707 case RIL_E_OEM_ERROR_15: return "E_OEM_ERROR_15";
5708 case RIL_E_OEM_ERROR_16: return "E_OEM_ERROR_16";
5709 case RIL_E_OEM_ERROR_17: return "E_OEM_ERROR_17";
5710 case RIL_E_OEM_ERROR_18: return "E_OEM_ERROR_18";
5711 case RIL_E_OEM_ERROR_19: return "E_OEM_ERROR_19";
5712 case RIL_E_OEM_ERROR_20: return "E_OEM_ERROR_20";
5713 case RIL_E_OEM_ERROR_21: return "E_OEM_ERROR_21";
5714 case RIL_E_OEM_ERROR_22: return "E_OEM_ERROR_22";
5715 case RIL_E_OEM_ERROR_23: return "E_OEM_ERROR_23";
5716 case RIL_E_OEM_ERROR_24: return "E_OEM_ERROR_24";
5717 case RIL_E_OEM_ERROR_25: return "E_OEM_ERROR_25";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005718 default: return "<unknown error>";
5719 }
5720}
5721
5722const char *
5723radioStateToString(RIL_RadioState s) {
5724 switch(s) {
5725 case RADIO_STATE_OFF: return "RADIO_OFF";
5726 case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
5727 case RADIO_STATE_SIM_NOT_READY: return "RADIO_SIM_NOT_READY";
5728 case RADIO_STATE_SIM_LOCKED_OR_ABSENT: return "RADIO_SIM_LOCKED_OR_ABSENT";
5729 case RADIO_STATE_SIM_READY: return "RADIO_SIM_READY";
5730 case RADIO_STATE_RUIM_NOT_READY:return"RADIO_RUIM_NOT_READY";
5731 case RADIO_STATE_RUIM_READY:return"RADIO_RUIM_READY";
5732 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:return"RADIO_RUIM_LOCKED_OR_ABSENT";
5733 case RADIO_STATE_NV_NOT_READY:return"RADIO_NV_NOT_READY";
5734 case RADIO_STATE_NV_READY:return"RADIO_NV_READY";
5735 case RADIO_STATE_ON:return"RADIO_ON";
5736 default: return "<unknown state>";
5737 }
5738}
5739
5740const char *
5741callStateToString(RIL_CallState s) {
5742 switch(s) {
5743 case RIL_CALL_ACTIVE : return "ACTIVE";
5744 case RIL_CALL_HOLDING: return "HOLDING";
5745 case RIL_CALL_DIALING: return "DIALING";
5746 case RIL_CALL_ALERTING: return "ALERTING";
5747 case RIL_CALL_INCOMING: return "INCOMING";
5748 case RIL_CALL_WAITING: return "WAITING";
5749 default: return "<unknown state>";
5750 }
5751}
5752
5753const char *
5754requestToString(int request) {
5755/*
5756 cat libs/telephony/ril_commands.h \
5757 | egrep "^ *{RIL_" \
5758 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
5759
5760
5761 cat libs/telephony/ril_unsol_commands.h \
5762 | egrep "^ *{RIL_" \
5763 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
5764
5765*/
5766 switch(request) {
5767 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
5768 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
5769 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
5770 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
5771 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
5772 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
5773 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
5774 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
5775 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
5776 case RIL_REQUEST_DIAL: return "DIAL";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005777 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
5778 case RIL_REQUEST_HANGUP: return "HANGUP";
5779 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
5780 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
5781 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
5782 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
5783 case RIL_REQUEST_UDUB: return "UDUB";
5784 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
5785 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
5786 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
5787 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
5788 case RIL_REQUEST_OPERATOR: return "OPERATOR";
5789 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
5790 case RIL_REQUEST_DTMF: return "DTMF";
5791 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
5792 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
5793 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
5794 case RIL_REQUEST_SIM_IO: return "SIM_IO";
5795 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
5796 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
5797 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
5798 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
5799 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
5800 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
5801 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
5802 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
5803 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
5804 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
5805 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
5806 case RIL_REQUEST_ANSWER: return "ANSWER";
5807 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
5808 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
5809 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
5810 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
5811 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
5812 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
5813 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
5814 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";
5815 case RIL_REQUEST_DTMF_START: return "DTMF_START";
5816 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
5817 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
5818 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
5819 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
5820 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
5821 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
5822 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
5823 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
5824 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
5825 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
5826 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
5827 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
5828 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
5829 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
5830 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
5831 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
5832 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
5833 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
5834 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
5835 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
5836 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
5837 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
5838 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
5839 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005840 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE:return"CDMA_SET_SUBSCRIPTION_SOURCE";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005841 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"CDMA_SET_ROAMING_PREFERENCE";
5842 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"CDMA_QUERY_ROAMING_PREFERENCE";
5843 case RIL_REQUEST_SET_TTY_MODE:return"SET_TTY_MODE";
5844 case RIL_REQUEST_QUERY_TTY_MODE:return"QUERY_TTY_MODE";
5845 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
5846 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
5847 case RIL_REQUEST_CDMA_FLASH:return"CDMA_FLASH";
5848 case RIL_REQUEST_CDMA_BURST_DTMF:return"CDMA_BURST_DTMF";
5849 case RIL_REQUEST_CDMA_SEND_SMS:return"CDMA_SEND_SMS";
5850 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:return"CDMA_SMS_ACKNOWLEDGE";
5851 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG:return"GSM_GET_BROADCAST_SMS_CONFIG";
5852 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG:return"GSM_SET_BROADCAST_SMS_CONFIG";
5853 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG:return "CDMA_GET_BROADCAST_SMS_CONFIG";
5854 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG:return "CDMA_SET_BROADCAST_SMS_CONFIG";
5855 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION:return "CDMA_SMS_BROADCAST_ACTIVATION";
Ethan Chend6e30652013-08-04 22:49:56 -07005856 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return"CDMA_VALIDATE_AND_WRITE_AKEY";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005857 case RIL_REQUEST_CDMA_SUBSCRIPTION: return"CDMA_SUBSCRIPTION";
5858 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
5859 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
5860 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
5861 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
5862 case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
5863 case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
5864 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
5865 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
5866 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
5867 case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
5868 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
5869 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
5870 case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
Ajay Nambie63b4f62011-11-15 11:19:30 -08005871 case RIL_REQUEST_WRITE_SMS_TO_SIM: return "WRITE_SMS_TO_SIM";
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005872 case RIL_REQUEST_GET_CELL_INFO_LIST: return"GET_CELL_INFO_LIST";
5873 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return"SET_UNSOL_CELL_INFO_LIST_RATE";
Andrew Jiangca4a9a02014-01-18 18:04:08 -05005874 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "RIL_REQUEST_SET_INITIAL_ATTACH_APN";
5875 case RIL_REQUEST_IMS_REGISTRATION_STATE: return "IMS_REGISTRATION_STATE";
5876 case RIL_REQUEST_IMS_SEND_SMS: return "IMS_SEND_SMS";
Howard Sue32dbfd2015-01-07 15:55:57 +08005877 case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "SIM_TRANSMIT_APDU_BASIC";
5878 case RIL_REQUEST_SIM_OPEN_CHANNEL: return "SIM_OPEN_CHANNEL";
5879 case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "SIM_CLOSE_CHANNEL";
5880 case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "SIM_TRANSMIT_APDU_CHANNEL";
Howard Subd82ef12015-04-12 10:25:05 +02005881 case RIL_REQUEST_GET_RADIO_CAPABILITY: return "RIL_REQUEST_GET_RADIO_CAPABILITY";
5882 case RIL_REQUEST_SET_RADIO_CAPABILITY: return "RIL_REQUEST_SET_RADIO_CAPABILITY";
Howard Sue32dbfd2015-01-07 15:55:57 +08005883 case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "SET_UICC_SUBSCRIPTION";
5884 case RIL_REQUEST_ALLOW_DATA: return "ALLOW_DATA";
5885 case RIL_REQUEST_GET_HARDWARE_CONFIG: return "GET_HARDWARE_CONFIG";
5886 case RIL_REQUEST_SIM_AUTHENTICATION: return "SIM_AUTHENTICATION";
5887 case RIL_REQUEST_GET_DC_RT_INFO: return "GET_DC_RT_INFO";
5888 case RIL_REQUEST_SET_DC_RT_INFO_RATE: return "SET_DC_RT_INFO_RATE";
5889 case RIL_REQUEST_SET_DATA_PROFILE: return "SET_DATA_PROFILE";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005890 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
5891 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
5892 case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED";
5893 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
5894 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
5895 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
5896 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
5897 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)";
5898 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
5899 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
Howard Subd82ef12015-04-12 10:25:05 +02005900 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
5901 case RIL_UNSOL_SUPP_SVC_NOTIFICATION: return "UNSOL_SUPP_SVC_NOTIFICATION";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005902 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
5903 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
5904 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
5905 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
5906 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL";
5907 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005908 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
5909 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
5910 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_NEW_CDMA_SMS";
5911 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_NEW_BROADCAST_SMS";
5912 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
5913 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
5914 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
5915 case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
5916 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
5917 case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
5918 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
5919 case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
5920 case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
5921 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
5922 case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
5923 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
5924 case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
5925 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
Ethan Chend6e30652013-08-04 22:49:56 -07005926 case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
Andrew Jiangca4a9a02014-01-18 18:04:08 -05005927 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "RESPONSE_IMS_NETWORK_STATE_CHANGED";
Howard Sue32dbfd2015-01-07 15:55:57 +08005928 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return "UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED";
5929 case RIL_UNSOL_SRVCC_STATE_NOTIFY: return "UNSOL_SRVCC_STATE_NOTIFY";
5930 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return "HARDWARE_CONFIG_CHANGED";
5931 case RIL_UNSOL_DC_RT_INFO_CHANGED: return "UNSOL_DC_RT_INFO_CHANGED";
Howard Subd82ef12015-04-12 10:25:05 +02005932 case RIL_UNSOL_RADIO_CAPABILITY: return "UNSOL_RADIO_CAPABILITY";
5933 case RIL_UNSOL_ON_SS: return "UNSOL_ON_SS";
5934 case RIL_UNSOL_STK_CC_ALPHA_NOTIFY: return "UNSOL_STK_CC_ALPHA_NOTIFY";
Howard Sue32dbfd2015-01-07 15:55:57 +08005935 case RIL_REQUEST_SHUTDOWN: return "SHUTDOWN";
Sanket Padawea7c043d2016-01-27 15:09:12 -08005936 case RIL_RESPONSE_ACKNOWLEDGEMENT: return "RIL_RESPONSE_ACKNOWLEDGEMENT";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005937 default: return "<unknown request>";
5938 }
5939}
5940
Howard Sue32dbfd2015-01-07 15:55:57 +08005941const char *
5942rilSocketIdToString(RIL_SOCKET_ID socket_id)
5943{
5944 switch(socket_id) {
5945 case RIL_SOCKET_1:
5946 return "RIL_SOCKET_1";
5947#if (SIM_COUNT >= 2)
5948 case RIL_SOCKET_2:
5949 return "RIL_SOCKET_2";
5950#endif
5951#if (SIM_COUNT >= 3)
5952 case RIL_SOCKET_3:
5953 return "RIL_SOCKET_3";
5954#endif
5955#if (SIM_COUNT >= 4)
5956 case RIL_SOCKET_4:
5957 return "RIL_SOCKET_4";
5958#endif
5959 default:
5960 return "not a valid RIL";
5961 }
5962}
5963
Sanket Padawe9343e872016-01-11 12:45:43 -08005964/*
5965 * Returns true for a debuggable build.
5966 */
5967static bool isDebuggable() {
5968 char debuggable[PROP_VALUE_MAX];
5969 property_get("ro.debuggable", debuggable, "0");
5970 if (strcmp(debuggable, "1") == 0) {
5971 return true;
5972 }
5973 return false;
5974}
5975
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005976} /* namespace android */
Dheeraj Shettycc231012014-07-02 21:27:57 +02005977
5978void rilEventAddWakeup_helper(struct ril_event *ev) {
5979 android::rilEventAddWakeup(ev);
5980}
5981
5982void listenCallback_helper(int fd, short flags, void *param) {
5983 android::listenCallback(fd, flags, param);
5984}
5985
5986int blockingWrite_helper(int fd, void *buffer, size_t len) {
5987 return android::blockingWrite(fd, buffer, len);
5988}