blob: 7babdf61dce806e42b121189a8a0e58a7f9a77fc [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
Howard Subd82ef12015-04-12 10:25:05 +0200566 if (pCI == NULL) {
567 Parcel pErr;
XpLoDWilDba5c6a32013-07-27 21:12:19 +0200568 RLOGE("unsupported request code %d token %d", request, token);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200569 // FIXME this should perhaps return a response
Howard Sue32dbfd2015-01-07 15:55:57 +0800570 pErr.writeInt32 (RESPONSE_SOLICITED);
571 pErr.writeInt32 (token);
572 pErr.writeInt32 (RIL_E_GENERIC_FAILURE);
573
574 sendResponse(pErr, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200575 return 0;
576 }
577
Sanket Padawea7c043d2016-01-27 15:09:12 -0800578 // Received an Ack for the previous result sent to RIL.java,
579 // so release wakelock and exit
580 if (request == RIL_RESPONSE_ACKNOWLEDGEMENT) {
581 releaseWakeLock();
582 return 0;
583 }
584
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200585 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;
1646
1647 memset(&rcsw, 0, sizeof(rcsw));
1648
1649 status = p.readInt32(&t);
1650 rcsw.status = t;
1651
1652 status = p.readInt32(&t);
1653 rcsw.message.uTeleserviceID = (int) t;
1654
1655 status = p.read(&uct,sizeof(uct));
1656 rcsw.message.bIsServicePresent = (uint8_t) uct;
1657
1658 status = p.readInt32(&t);
1659 rcsw.message.uServicecategory = (int) t;
1660
1661 status = p.readInt32(&t);
1662 rcsw.message.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1663
1664 status = p.readInt32(&t);
1665 rcsw.message.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1666
1667 status = p.readInt32(&t);
1668 rcsw.message.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1669
1670 status = p.readInt32(&t);
1671 rcsw.message.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1672
1673 status = p.read(&uct,sizeof(uct));
1674 rcsw.message.sAddress.number_of_digits = (uint8_t) uct;
1675
1676 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_ADDRESS_MAX; digitCount ++) {
1677 status = p.read(&uct,sizeof(uct));
1678 rcsw.message.sAddress.digits[digitCount] = (uint8_t) uct;
1679 }
1680
1681 status = p.readInt32(&t);
1682 rcsw.message.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1683
1684 status = p.read(&uct,sizeof(uct));
1685 rcsw.message.sSubAddress.odd = (uint8_t) uct;
1686
1687 status = p.read(&uct,sizeof(uct));
1688 rcsw.message.sSubAddress.number_of_digits = (uint8_t) uct;
1689
1690 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_SUBADDRESS_MAX; digitCount ++) {
1691 status = p.read(&uct,sizeof(uct));
1692 rcsw.message.sSubAddress.digits[digitCount] = (uint8_t) uct;
1693 }
1694
1695 status = p.readInt32(&t);
1696 rcsw.message.uBearerDataLen = (int) t;
1697
1698 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_BEARER_DATA_MAX; digitCount ++) {
1699 status = p.read(&uct, sizeof(uct));
1700 rcsw.message.aBearerData[digitCount] = (uint8_t) uct;
1701 }
1702
1703 if (status != NO_ERROR) {
1704 goto invalid;
1705 }
1706
1707 startRequest;
1708 appendPrintBuf("%sstatus=%d, message.uTeleserviceID=%d, message.bIsServicePresent=%d, \
1709 message.uServicecategory=%d, message.sAddress.digit_mode=%d, \
1710 message.sAddress.number_mode=%d, \
1711 message.sAddress.number_type=%d, ",
1712 printBuf, rcsw.status, rcsw.message.uTeleserviceID, rcsw.message.bIsServicePresent,
1713 rcsw.message.uServicecategory, rcsw.message.sAddress.digit_mode,
1714 rcsw.message.sAddress.number_mode,
1715 rcsw.message.sAddress.number_type);
1716 closeRequest;
1717
1718 printRequest(pRI->token, pRI->pCI->requestNumber);
1719
Howard Sue32dbfd2015-01-07 15:55:57 +08001720 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsw, sizeof(rcsw),pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001721
1722#ifdef MEMSET_FREED
1723 memset(&rcsw, 0, sizeof(rcsw));
1724#endif
1725
1726 return;
1727
1728invalid:
1729 invalidCommandBlock(pRI);
1730 return;
1731
1732}
1733
Ethan Chend6e30652013-08-04 22:49:56 -07001734// For backwards compatibility in RIL_REQUEST_SETUP_DATA_CALL.
1735// Version 4 of the RIL interface adds a new PDP type parameter to support
1736// IPv6 and dual-stack PDP contexts. When dealing with a previous version of
1737// RIL, remove the parameter from the request.
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001738static void dispatchDataCall(Parcel& p, RequestInfo *pRI) {
Ethan Chend6e30652013-08-04 22:49:56 -07001739 // In RIL v3, REQUEST_SETUP_DATA_CALL takes 6 parameters.
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001740 const int numParamsRilV3 = 6;
1741
Ethan Chend6e30652013-08-04 22:49:56 -07001742 // The first bytes of the RIL parcel contain the request number and the
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001743 // serial number - see processCommandBuffer(). Copy them over too.
1744 int pos = p.dataPosition();
1745
1746 int numParams = p.readInt32();
1747 if (s_callbacks.version < 4 && numParams > numParamsRilV3) {
1748 Parcel p2;
1749 p2.appendFrom(&p, 0, pos);
1750 p2.writeInt32(numParamsRilV3);
1751 for(int i = 0; i < numParamsRilV3; i++) {
1752 p2.writeString16(p.readString16());
1753 }
1754 p2.setDataPosition(pos);
1755 dispatchStrings(p2, pRI);
1756 } else {
1757 p.setDataPosition(pos);
1758 dispatchStrings(p, pRI);
1759 }
1760}
1761
1762// For backwards compatibility with RILs that dont support RIL_REQUEST_VOICE_RADIO_TECH.
Ethan Chend6e30652013-08-04 22:49:56 -07001763// When all RILs handle this request, this function can be removed and
1764// the request can be sent directly to the RIL using dispatchVoid.
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001765static void dispatchVoiceRadioTech(Parcel& p, RequestInfo *pRI) {
Howard Sue32dbfd2015-01-07 15:55:57 +08001766 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001767
1768 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1769 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1770 }
1771
Ethan Chend6e30652013-08-04 22:49:56 -07001772 // RILs that support RADIO_STATE_ON should support this request.
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001773 if (RADIO_STATE_ON == state) {
1774 dispatchVoid(p, pRI);
1775 return;
1776 }
1777
Ethan Chend6e30652013-08-04 22:49:56 -07001778 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1779 // will not support this new request either and decode Voice Radio Technology
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001780 // from Radio State
1781 voiceRadioTech = decodeVoiceRadioTechnology(state);
1782
1783 if (voiceRadioTech < 0)
1784 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1785 else
1786 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &voiceRadioTech, sizeof(int));
1787}
1788
Ethan Chend6e30652013-08-04 22:49:56 -07001789// For backwards compatibility in RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE:.
1790// When all RILs handle this request, this function can be removed and
1791// the request can be sent directly to the RIL using dispatchVoid.
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001792static void dispatchCdmaSubscriptionSource(Parcel& p, RequestInfo *pRI) {
Howard Sue32dbfd2015-01-07 15:55:57 +08001793 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001794
1795 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1796 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1797 }
1798
1799 // RILs that support RADIO_STATE_ON should support this request.
1800 if (RADIO_STATE_ON == state) {
1801 dispatchVoid(p, pRI);
1802 return;
1803 }
1804
Ethan Chend6e30652013-08-04 22:49:56 -07001805 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001806 // will not support this new request either and decode CDMA Subscription Source
Ethan Chend6e30652013-08-04 22:49:56 -07001807 // from Radio State
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001808 cdmaSubscriptionSource = decodeCdmaSubscriptionSource(state);
1809
1810 if (cdmaSubscriptionSource < 0)
1811 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1812 else
1813 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &cdmaSubscriptionSource, sizeof(int));
1814}
1815
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001816static void dispatchSetInitialAttachApn(Parcel &p, RequestInfo *pRI)
1817{
1818 RIL_InitialAttachApn pf;
1819 int32_t t;
1820 status_t status;
1821
1822 memset(&pf, 0, sizeof(pf));
1823
1824 pf.apn = strdupReadString(p);
1825 pf.protocol = strdupReadString(p);
1826
1827 status = p.readInt32(&t);
1828 pf.authtype = (int) t;
1829
1830 pf.username = strdupReadString(p);
1831 pf.password = strdupReadString(p);
1832
1833 startRequest;
1834 appendPrintBuf("%sapn=%s, protocol=%s, auth_type=%d, username=%s, password=%s",
Andreas Schneidera8d09502015-06-23 18:41:38 +02001835 printBuf, pf.apn, pf.protocol, pf.authtype, pf.username, pf.password);
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001836 closeRequest;
1837 printRequest(pRI->token, pRI->pCI->requestNumber);
1838
1839 if (status != NO_ERROR) {
1840 goto invalid;
1841 }
Howard Sue32dbfd2015-01-07 15:55:57 +08001842 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001843
1844#ifdef MEMSET_FREED
1845 memsetString(pf.apn);
1846 memsetString(pf.protocol);
1847 memsetString(pf.username);
1848 memsetString(pf.password);
1849#endif
1850
1851 free(pf.apn);
1852 free(pf.protocol);
1853 free(pf.username);
1854 free(pf.password);
1855
1856#ifdef MEMSET_FREED
1857 memset(&pf, 0, sizeof(pf));
1858#endif
1859
1860 return;
1861invalid:
1862 invalidCommandBlock(pRI);
1863 return;
1864}
1865
Howard Sue32dbfd2015-01-07 15:55:57 +08001866static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI) {
1867 RIL_NV_ReadItem nvri;
1868 int32_t t;
1869 status_t status;
1870
1871 memset(&nvri, 0, sizeof(nvri));
1872
1873 status = p.readInt32(&t);
1874 nvri.itemID = (RIL_NV_Item) t;
1875
1876 if (status != NO_ERROR) {
1877 goto invalid;
1878 }
1879
1880 startRequest;
1881 appendPrintBuf("%snvri.itemID=%d, ", printBuf, nvri.itemID);
1882 closeRequest;
1883
1884 printRequest(pRI->token, pRI->pCI->requestNumber);
1885
1886 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvri, sizeof(nvri), pRI, pRI->socket_id);
1887
1888#ifdef MEMSET_FREED
1889 memset(&nvri, 0, sizeof(nvri));
1890#endif
1891
1892 return;
1893
1894invalid:
1895 invalidCommandBlock(pRI);
1896 return;
1897}
1898
1899static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI) {
1900 RIL_NV_WriteItem nvwi;
1901 int32_t t;
1902 status_t status;
1903
1904 memset(&nvwi, 0, sizeof(nvwi));
1905
1906 status = p.readInt32(&t);
1907 nvwi.itemID = (RIL_NV_Item) t;
1908
1909 nvwi.value = strdupReadString(p);
1910
1911 if (status != NO_ERROR || nvwi.value == NULL) {
1912 goto invalid;
1913 }
1914
1915 startRequest;
1916 appendPrintBuf("%snvwi.itemID=%d, value=%s, ", printBuf, nvwi.itemID,
1917 nvwi.value);
1918 closeRequest;
1919
1920 printRequest(pRI->token, pRI->pCI->requestNumber);
1921
1922 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvwi, sizeof(nvwi), pRI, pRI->socket_id);
1923
1924#ifdef MEMSET_FREED
1925 memsetString(nvwi.value);
1926#endif
1927
1928 free(nvwi.value);
1929
1930#ifdef MEMSET_FREED
1931 memset(&nvwi, 0, sizeof(nvwi));
1932#endif
1933
1934 return;
1935
1936invalid:
1937 invalidCommandBlock(pRI);
1938 return;
1939}
1940
1941
1942static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI) {
1943 RIL_SelectUiccSub uicc_sub;
1944 status_t status;
1945 int32_t t;
1946 memset(&uicc_sub, 0, sizeof(uicc_sub));
1947
1948 status = p.readInt32(&t);
1949 if (status != NO_ERROR) {
1950 goto invalid;
1951 }
1952 uicc_sub.slot = (int) t;
1953
1954 status = p.readInt32(&t);
1955 if (status != NO_ERROR) {
1956 goto invalid;
1957 }
1958 uicc_sub.app_index = (int) t;
1959
1960 status = p.readInt32(&t);
1961 if (status != NO_ERROR) {
1962 goto invalid;
1963 }
1964 uicc_sub.sub_type = (RIL_SubscriptionType) t;
1965
1966 status = p.readInt32(&t);
1967 if (status != NO_ERROR) {
1968 goto invalid;
1969 }
1970 uicc_sub.act_status = (RIL_UiccSubActStatus) t;
1971
1972 startRequest;
1973 appendPrintBuf("slot=%d, app_index=%d, act_status = %d", uicc_sub.slot, uicc_sub.app_index,
1974 uicc_sub.act_status);
1975 RLOGD("dispatchUiccSubscription, slot=%d, app_index=%d, act_status = %d", uicc_sub.slot,
1976 uicc_sub.app_index, uicc_sub.act_status);
1977 closeRequest;
1978 printRequest(pRI->token, pRI->pCI->requestNumber);
1979
1980 CALL_ONREQUEST(pRI->pCI->requestNumber, &uicc_sub, sizeof(uicc_sub), pRI, pRI->socket_id);
1981
1982#ifdef MEMSET_FREED
1983 memset(&uicc_sub, 0, sizeof(uicc_sub));
1984#endif
1985 return;
1986
1987invalid:
1988 invalidCommandBlock(pRI);
1989 return;
1990}
1991
1992static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI)
1993{
1994 RIL_SimAuthentication pf;
1995 int32_t t;
1996 status_t status;
1997
1998 memset(&pf, 0, sizeof(pf));
1999
2000 status = p.readInt32(&t);
2001 pf.authContext = (int) t;
2002 pf.authData = strdupReadString(p);
2003 pf.aid = strdupReadString(p);
2004
2005 startRequest;
Andreas Schneidera8d09502015-06-23 18:41:38 +02002006 appendPrintBuf("authContext=%d, authData=%s, aid=%s", pf.authContext, pf.authData, pf.aid);
Howard Sue32dbfd2015-01-07 15:55:57 +08002007 closeRequest;
2008 printRequest(pRI->token, pRI->pCI->requestNumber);
2009
2010 if (status != NO_ERROR) {
2011 goto invalid;
2012 }
2013 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
2014
2015#ifdef MEMSET_FREED
2016 memsetString(pf.authData);
2017 memsetString(pf.aid);
2018#endif
2019
2020 free(pf.authData);
2021 free(pf.aid);
2022
2023#ifdef MEMSET_FREED
2024 memset(&pf, 0, sizeof(pf));
2025#endif
2026
2027 return;
2028invalid:
2029 invalidCommandBlock(pRI);
2030 return;
2031}
2032
2033static void dispatchDataProfile(Parcel &p, RequestInfo *pRI) {
2034 int32_t t;
2035 status_t status;
2036 int32_t num;
2037
2038 status = p.readInt32(&num);
2039 if (status != NO_ERROR) {
2040 goto invalid;
2041 }
2042
2043 {
Sanket Padawedf3dabe2016-02-29 10:09:26 -08002044 RIL_DataProfileInfo *dataProfiles =
2045 (RIL_DataProfileInfo *)malloc(num * sizeof(RIL_DataProfileInfo));
2046 if (dataProfiles == NULL) {
2047 RLOGE("Memory allocation failed for request %s",
2048 requestToString(pRI->pCI->requestNumber));
2049 return;
2050 }
2051 RIL_DataProfileInfo **dataProfilePtrs =
2052 (RIL_DataProfileInfo **)malloc(num * sizeof(RIL_DataProfileInfo *));
2053 if (dataProfilePtrs == NULL) {
2054 RLOGE("Memory allocation failed for request %s",
2055 requestToString(pRI->pCI->requestNumber));
2056 free(dataProfiles);
2057 return;
2058 }
Howard Sue32dbfd2015-01-07 15:55:57 +08002059
2060 startRequest;
2061 for (int i = 0 ; i < num ; i++ ) {
2062 dataProfilePtrs[i] = &dataProfiles[i];
2063
2064 status = p.readInt32(&t);
2065 dataProfiles[i].profileId = (int) t;
2066
2067 dataProfiles[i].apn = strdupReadString(p);
2068 dataProfiles[i].protocol = strdupReadString(p);
2069 status = p.readInt32(&t);
2070 dataProfiles[i].authType = (int) t;
2071
2072 dataProfiles[i].user = strdupReadString(p);
2073 dataProfiles[i].password = strdupReadString(p);
2074
2075 status = p.readInt32(&t);
2076 dataProfiles[i].type = (int) t;
2077
2078 status = p.readInt32(&t);
2079 dataProfiles[i].maxConnsTime = (int) t;
2080 status = p.readInt32(&t);
2081 dataProfiles[i].maxConns = (int) t;
2082 status = p.readInt32(&t);
2083 dataProfiles[i].waitTime = (int) t;
2084
2085 status = p.readInt32(&t);
2086 dataProfiles[i].enabled = (int) t;
2087
2088 appendPrintBuf("%s [%d: profileId=%d, apn =%s, protocol =%s, authType =%d, \
2089 user =%s, password =%s, type =%d, maxConnsTime =%d, maxConns =%d, \
2090 waitTime =%d, enabled =%d]", printBuf, i, dataProfiles[i].profileId,
2091 dataProfiles[i].apn, dataProfiles[i].protocol, dataProfiles[i].authType,
2092 dataProfiles[i].user, dataProfiles[i].password, dataProfiles[i].type,
2093 dataProfiles[i].maxConnsTime, dataProfiles[i].maxConns,
2094 dataProfiles[i].waitTime, dataProfiles[i].enabled);
2095 }
2096 closeRequest;
2097 printRequest(pRI->token, pRI->pCI->requestNumber);
2098
2099 if (status != NO_ERROR) {
Sanket Padawedf3dabe2016-02-29 10:09:26 -08002100 free(dataProfiles);
2101 free(dataProfilePtrs);
Howard Sue32dbfd2015-01-07 15:55:57 +08002102 goto invalid;
2103 }
2104 CALL_ONREQUEST(pRI->pCI->requestNumber,
2105 dataProfilePtrs,
2106 num * sizeof(RIL_DataProfileInfo *),
2107 pRI, pRI->socket_id);
2108
2109#ifdef MEMSET_FREED
2110 memset(dataProfiles, 0, num * sizeof(RIL_DataProfileInfo));
2111 memset(dataProfilePtrs, 0, num * sizeof(RIL_DataProfileInfo *));
2112#endif
Sanket Padawedf3dabe2016-02-29 10:09:26 -08002113 free(dataProfiles);
2114 free(dataProfilePtrs);
Howard Sue32dbfd2015-01-07 15:55:57 +08002115 }
2116
2117 return;
2118
2119invalid:
2120 invalidCommandBlock(pRI);
2121 return;
2122}
2123
Howard Subd82ef12015-04-12 10:25:05 +02002124static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI){
2125 RIL_RadioCapability rc;
2126 int32_t t;
2127 status_t status;
2128
2129 memset (&rc, 0, sizeof(RIL_RadioCapability));
2130
2131 status = p.readInt32(&t);
2132 rc.version = (int)t;
2133 if (status != NO_ERROR) {
2134 goto invalid;
2135 }
2136
2137 status = p.readInt32(&t);
2138 rc.session= (int)t;
2139 if (status != NO_ERROR) {
2140 goto invalid;
2141 }
2142
2143 status = p.readInt32(&t);
2144 rc.phase= (int)t;
2145 if (status != NO_ERROR) {
2146 goto invalid;
2147 }
2148
2149 status = p.readInt32(&t);
2150 rc.rat = (int)t;
2151 if (status != NO_ERROR) {
2152 goto invalid;
2153 }
2154
2155 status = readStringFromParcelInplace(p, rc.logicalModemUuid, sizeof(rc.logicalModemUuid));
2156 if (status != NO_ERROR) {
2157 goto invalid;
2158 }
2159
2160 status = p.readInt32(&t);
2161 rc.status = (int)t;
2162
2163 if (status != NO_ERROR) {
2164 goto invalid;
2165 }
2166
2167 startRequest;
2168 appendPrintBuf("%s [version:%d, session:%d, phase:%d, rat:%d, \
Andreas Schneidera8d09502015-06-23 18:41:38 +02002169 logicalModemUuid:%s, status:%d", printBuf, rc.version, rc.session,
2170 rc.phase, rc.rat, rc.logicalModemUuid, rc.status);
Howard Subd82ef12015-04-12 10:25:05 +02002171
2172 closeRequest;
2173 printRequest(pRI->token, pRI->pCI->requestNumber);
2174
2175 CALL_ONREQUEST(pRI->pCI->requestNumber,
2176 &rc,
2177 sizeof(RIL_RadioCapability),
2178 pRI, pRI->socket_id);
2179 return;
2180invalid:
2181 invalidCommandBlock(pRI);
2182 return;
2183}
2184
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002185static int
2186blockingWrite(int fd, const void *buffer, size_t len) {
2187 size_t writeOffset = 0;
2188 const uint8_t *toWrite;
2189
2190 toWrite = (const uint8_t *)buffer;
2191
2192 while (writeOffset < len) {
2193 ssize_t written;
2194 do {
2195 written = write (fd, toWrite + writeOffset,
2196 len - writeOffset);
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002197 } while (written < 0 && ((errno == EINTR) || (errno == EAGAIN)));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002198
2199 if (written >= 0) {
2200 writeOffset += written;
2201 } else { // written < 0
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002202 RLOGE ("RIL Response: unexpected error on write errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002203 close(fd);
2204 return -1;
2205 }
2206 }
Robert Greenwaltbc29c432015-04-29 16:57:39 -07002207#if VDBG
Dheeraj Shettycc231012014-07-02 21:27:57 +02002208 RLOGE("RIL Response bytes written:%d", writeOffset);
Robert Greenwaltbc29c432015-04-29 16:57:39 -07002209#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002210 return 0;
2211}
2212
2213static int
Howard Sue32dbfd2015-01-07 15:55:57 +08002214sendResponseRaw (const void *data, size_t dataSize, RIL_SOCKET_ID socket_id) {
2215 int fd = s_ril_param_socket.fdCommand;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002216 int ret;
2217 uint32_t header;
Howard Sue32dbfd2015-01-07 15:55:57 +08002218 pthread_mutex_t * writeMutexHook = &s_writeMutex;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002219
Robert Greenwaltbc29c432015-04-29 16:57:39 -07002220#if VDBG
Andreas Schneider822b70b2015-10-23 08:36:26 +02002221 RLOGD("Send Response to %s", rilSocketIdToString(socket_id));
Robert Greenwaltbc29c432015-04-29 16:57:39 -07002222#endif
Howard Sue32dbfd2015-01-07 15:55:57 +08002223
2224#if (SIM_COUNT >= 2)
2225 if (socket_id == RIL_SOCKET_2) {
2226 fd = s_ril_param_socket2.fdCommand;
2227 writeMutexHook = &s_writeMutex_socket2;
2228 }
2229#if (SIM_COUNT >= 3)
2230 else if (socket_id == RIL_SOCKET_3) {
2231 fd = s_ril_param_socket3.fdCommand;
2232 writeMutexHook = &s_writeMutex_socket3;
2233 }
2234#endif
2235#if (SIM_COUNT >= 4)
2236 else if (socket_id == RIL_SOCKET_4) {
2237 fd = s_ril_param_socket4.fdCommand;
2238 writeMutexHook = &s_writeMutex_socket4;
2239 }
2240#endif
2241#endif
2242 if (fd < 0) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002243 return -1;
2244 }
2245
Howard Subd82ef12015-04-12 10:25:05 +02002246 if (dataSize > MAX_COMMAND_BYTES) {
2247 RLOGE("RIL: packet larger than %u (%u)",
2248 MAX_COMMAND_BYTES, (unsigned int )dataSize);
2249
2250 return -1;
2251 }
2252
Howard Sue32dbfd2015-01-07 15:55:57 +08002253 pthread_mutex_lock(writeMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002254
2255 header = htonl(dataSize);
2256
2257 ret = blockingWrite(fd, (void *)&header, sizeof(header));
2258
2259 if (ret < 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002260 pthread_mutex_unlock(writeMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002261 return ret;
2262 }
2263
2264 ret = blockingWrite(fd, data, dataSize);
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
Howard Sue32dbfd2015-01-07 15:55:57 +08002271 pthread_mutex_unlock(writeMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002272
2273 return 0;
2274}
2275
2276static int
Howard Sue32dbfd2015-01-07 15:55:57 +08002277sendResponse (Parcel &p, RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002278 printResponse;
Howard Sue32dbfd2015-01-07 15:55:57 +08002279 return sendResponseRaw(p.data(), p.dataSize(), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002280}
2281
Howard Sue32dbfd2015-01-07 15:55:57 +08002282/** response is an int* pointing to an array of ints */
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002283
2284static int
2285responseInts(Parcel &p, void *response, size_t responselen) {
2286 int numInts;
2287
2288 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002289 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002290 return RIL_ERRNO_INVALID_RESPONSE;
2291 }
2292 if (responselen % sizeof(int) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002293 RLOGE("responseInts: invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002294 (int)responselen, (int)sizeof(int));
2295 return RIL_ERRNO_INVALID_RESPONSE;
2296 }
2297
2298 int *p_int = (int *) response;
2299
Howard Sue32dbfd2015-01-07 15:55:57 +08002300 numInts = responselen / sizeof(int);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002301 p.writeInt32 (numInts);
2302
2303 /* each int*/
2304 startResponse;
2305 for (int i = 0 ; i < numInts ; i++) {
2306 appendPrintBuf("%s%d,", printBuf, p_int[i]);
2307 p.writeInt32(p_int[i]);
2308 }
2309 removeLastChar;
2310 closeResponse;
2311
2312 return 0;
2313}
2314
Daniel Hillenbrandd0b84162015-04-12 11:53:23 +02002315static int
2316responseIntsGetPreferredNetworkType(Parcel &p, void *response, size_t responselen) {
2317 int numInts;
2318
2319 if (response == NULL && responselen != 0) {
2320 RLOGE("invalid response: NULL");
2321 return RIL_ERRNO_INVALID_RESPONSE;
2322 }
2323 if (responselen % sizeof(int) != 0) {
2324 RLOGE("responseInts: invalid response length %d expected multiple of %d\n",
2325 (int)responselen, (int)sizeof(int));
2326 return RIL_ERRNO_INVALID_RESPONSE;
2327 }
2328
2329 int *p_int = (int *) response;
2330
2331 numInts = responselen / sizeof(int);
2332 p.writeInt32 (numInts);
2333
2334 /* each int*/
2335 startResponse;
2336 for (int i = 0 ; i < numInts ; i++) {
2337 if (i == 0 && p_int[0] == 7) {
2338 RLOGD("REQUEST_GET_PREFERRED_NETWORK_TYPE: NETWORK_MODE_GLOBAL => NETWORK_MODE_WCDMA_PREF");
2339 p_int[0] = 0;
2340 }
2341 appendPrintBuf("%s%d,", printBuf, p_int[i]);
2342 p.writeInt32(p_int[i]);
2343 }
2344 removeLastChar;
2345 closeResponse;
2346
2347 return 0;
2348}
2349
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002350/** response is a char **, pointing to an array of char *'s
2351 The parcel will begin with the version */
2352static int responseStringsWithVersion(int version, Parcel &p, void *response, size_t responselen) {
2353 p.writeInt32(version);
2354 return responseStrings(p, response, responselen);
2355}
2356
2357/** response is a char **, pointing to an array of char *'s */
2358static int responseStrings(Parcel &p, void *response, size_t responselen) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002359 int numStrings;
2360
2361 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002362 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002363 return RIL_ERRNO_INVALID_RESPONSE;
2364 }
2365 if (responselen % sizeof(char *) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002366 RLOGE("responseStrings: invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002367 (int)responselen, (int)sizeof(char *));
2368 return RIL_ERRNO_INVALID_RESPONSE;
2369 }
2370
2371 if (response == NULL) {
2372 p.writeInt32 (0);
2373 } else {
2374 char **p_cur = (char **) response;
2375
2376 numStrings = responselen / sizeof(char *);
Dheeraj CVR48d3f722016-10-04 11:10:55 +04002377 p.writeInt32 (numStrings);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002378
2379 /* each string*/
2380 startResponse;
2381 for (int i = 0 ; i < numStrings ; i++) {
2382 appendPrintBuf("%s%s,", printBuf, (char*)p_cur[i]);
2383 writeStringToParcel (p, p_cur[i]);
2384 }
2385 removeLastChar;
2386 closeResponse;
2387 }
2388 return 0;
2389}
2390
Howard Subd82ef12015-04-12 10:25:05 +02002391
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002392/**
2393 * NULL strings are accepted
2394 * FIXME currently ignores responselen
2395 */
2396static int responseString(Parcel &p, void *response, size_t responselen) {
2397 /* one string only */
2398 startResponse;
2399 appendPrintBuf("%s%s", printBuf, (char*)response);
2400 closeResponse;
2401
2402 writeStringToParcel(p, (const char *)response);
2403
2404 return 0;
2405}
2406
2407static int responseVoid(Parcel &p, void *response, size_t responselen) {
2408 startResponse;
2409 removeLastChar;
2410 return 0;
2411}
2412
2413static int responseCallList(Parcel &p, void *response, size_t responselen) {
2414 int num;
2415
2416 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002417 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002418 return RIL_ERRNO_INVALID_RESPONSE;
2419 }
2420
2421 if (responselen % sizeof (RIL_Call *) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002422 RLOGE("responseCallList: invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002423 (int)responselen, (int)sizeof (RIL_Call *));
2424 return RIL_ERRNO_INVALID_RESPONSE;
2425 }
2426
2427 startResponse;
2428 /* number of call info's */
2429 num = responselen / sizeof(RIL_Call *);
2430 p.writeInt32(num);
2431
2432 for (int i = 0 ; i < num ; i++) {
2433 RIL_Call *p_cur = ((RIL_Call **) response)[i];
2434 /* each call info */
2435 p.writeInt32(p_cur->state);
2436 p.writeInt32(p_cur->index);
2437 p.writeInt32(p_cur->toa);
2438 p.writeInt32(p_cur->isMpty);
2439 p.writeInt32(p_cur->isMT);
2440 p.writeInt32(p_cur->als);
2441 p.writeInt32(p_cur->isVoice);
Andreas Schneider29472682015-01-01 19:00:04 +01002442
Christopher N. Hesse621e63e2016-02-22 21:57:39 +01002443#ifdef NEEDS_VIDEO_CALL_FIELD
Andreas Schneider29472682015-01-01 19:00:04 +01002444 p.writeInt32(p_cur->isVideo);
Sayd1052772015-12-13 17:25:01 +09002445#endif
Andreas Schneider29472682015-01-01 19:00:04 +01002446
Christopher N. Hesse621e63e2016-02-22 21:57:39 +01002447#ifdef SAMSUNG_NEXT_GEN_MODEM
Andreas Schneider29472682015-01-01 19:00:04 +01002448 /* Pass CallDetails */
2449 p.writeInt32(0);
2450 p.writeInt32(0);
2451 writeStringToParcel(p, "");
2452#endif
2453
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002454 p.writeInt32(p_cur->isVoicePrivacy);
2455 writeStringToParcel(p, p_cur->number);
2456 p.writeInt32(p_cur->numberPresentation);
2457 writeStringToParcel(p, p_cur->name);
2458 p.writeInt32(p_cur->namePresentation);
2459 // Remove when partners upgrade to version 3
2460 if ((s_callbacks.version < 3) || (p_cur->uusInfo == NULL || p_cur->uusInfo->uusData == NULL)) {
2461 p.writeInt32(0); /* UUS Information is absent */
2462 } else {
2463 RIL_UUS_Info *uusInfo = p_cur->uusInfo;
2464 p.writeInt32(1); /* UUS Information is present */
2465 p.writeInt32(uusInfo->uusType);
2466 p.writeInt32(uusInfo->uusDcs);
2467 p.writeInt32(uusInfo->uusLength);
2468 p.write(uusInfo->uusData, uusInfo->uusLength);
2469 }
2470 appendPrintBuf("%s[id=%d,%s,toa=%d,",
2471 printBuf,
2472 p_cur->index,
2473 callStateToString(p_cur->state),
2474 p_cur->toa);
2475 appendPrintBuf("%s%s,%s,als=%d,%s,%s,",
2476 printBuf,
2477 (p_cur->isMpty)?"conf":"norm",
2478 (p_cur->isMT)?"mt":"mo",
2479 p_cur->als,
2480 (p_cur->isVoice)?"voc":"nonvoc",
2481 (p_cur->isVoicePrivacy)?"evp":"noevp");
Christopher N. Hesse621e63e2016-02-22 21:57:39 +01002482#ifdef SAMSUNG_NEXT_GEN_MODEM
Andreas Schneider29472682015-01-01 19:00:04 +01002483 appendPrintBuf("%s,%s,",
2484 printBuf,
2485 (p_cur->isVideo) ? "vid" : "novid");
2486#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002487 appendPrintBuf("%s%s,cli=%d,name='%s',%d]",
2488 printBuf,
2489 p_cur->number,
2490 p_cur->numberPresentation,
2491 p_cur->name,
2492 p_cur->namePresentation);
2493 }
2494 removeLastChar;
2495 closeResponse;
2496
2497 return 0;
2498}
2499
2500static int responseSMS(Parcel &p, void *response, size_t responselen) {
2501 if (response == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002502 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002503 return RIL_ERRNO_INVALID_RESPONSE;
2504 }
2505
2506 if (responselen != sizeof (RIL_SMS_Response) ) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002507 RLOGE("invalid response length %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002508 (int)responselen, (int)sizeof (RIL_SMS_Response));
2509 return RIL_ERRNO_INVALID_RESPONSE;
2510 }
2511
2512 RIL_SMS_Response *p_cur = (RIL_SMS_Response *) response;
2513
2514 p.writeInt32(p_cur->messageRef);
2515 writeStringToParcel(p, p_cur->ackPDU);
2516 p.writeInt32(p_cur->errorCode);
2517
2518 startResponse;
2519 appendPrintBuf("%s%d,%s,%d", printBuf, p_cur->messageRef,
2520 (char*)p_cur->ackPDU, p_cur->errorCode);
2521 closeResponse;
2522
2523 return 0;
2524}
2525
2526static int responseDataCallListV4(Parcel &p, void *response, size_t responselen)
2527{
2528 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002529 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002530 return RIL_ERRNO_INVALID_RESPONSE;
2531 }
2532
2533 if (responselen % sizeof(RIL_Data_Call_Response_v4) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002534 RLOGE("responseDataCallListV4: invalid response length %d expected multiple of %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002535 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v4));
2536 return RIL_ERRNO_INVALID_RESPONSE;
2537 }
2538
Howard Sue32dbfd2015-01-07 15:55:57 +08002539 // Write version
2540 p.writeInt32(4);
2541
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002542 int num = responselen / sizeof(RIL_Data_Call_Response_v4);
2543 p.writeInt32(num);
2544
2545 RIL_Data_Call_Response_v4 *p_cur = (RIL_Data_Call_Response_v4 *) response;
2546 startResponse;
2547 int i;
2548 for (i = 0; i < num; i++) {
2549 p.writeInt32(p_cur[i].cid);
2550 p.writeInt32(p_cur[i].active);
2551 writeStringToParcel(p, p_cur[i].type);
2552 // apn is not used, so don't send.
2553 writeStringToParcel(p, p_cur[i].address);
2554 appendPrintBuf("%s[cid=%d,%s,%s,%s],", printBuf,
2555 p_cur[i].cid,
2556 (p_cur[i].active==0)?"down":"up",
2557 (char*)p_cur[i].type,
2558 (char*)p_cur[i].address);
2559 }
2560 removeLastChar;
2561 closeResponse;
2562
2563 return 0;
2564}
2565
Howard Sue32dbfd2015-01-07 15:55:57 +08002566static int responseDataCallListV6(Parcel &p, void *response, size_t responselen)
2567{
2568 if (response == NULL && responselen != 0) {
2569 RLOGE("invalid response: NULL");
2570 return RIL_ERRNO_INVALID_RESPONSE;
2571 }
2572
2573 if (responselen % sizeof(RIL_Data_Call_Response_v6) != 0) {
2574 RLOGE("responseDataCallListV6: invalid response length %d expected multiple of %d",
2575 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v6));
2576 return RIL_ERRNO_INVALID_RESPONSE;
2577 }
2578
2579 // Write version
2580 p.writeInt32(6);
2581
2582 int num = responselen / sizeof(RIL_Data_Call_Response_v6);
2583 p.writeInt32(num);
2584
2585 RIL_Data_Call_Response_v6 *p_cur = (RIL_Data_Call_Response_v6 *) response;
2586 startResponse;
2587 int i;
2588 for (i = 0; i < num; i++) {
2589 p.writeInt32((int)p_cur[i].status);
2590 p.writeInt32(p_cur[i].suggestedRetryTime);
2591 p.writeInt32(p_cur[i].cid);
2592 p.writeInt32(p_cur[i].active);
2593 writeStringToParcel(p, p_cur[i].type);
2594 writeStringToParcel(p, p_cur[i].ifname);
2595 writeStringToParcel(p, p_cur[i].addresses);
2596 writeStringToParcel(p, p_cur[i].dnses);
2597 writeStringToParcel(p, p_cur[i].addresses);
2598 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s],", printBuf,
2599 p_cur[i].status,
2600 p_cur[i].suggestedRetryTime,
2601 p_cur[i].cid,
2602 (p_cur[i].active==0)?"down":"up",
2603 (char*)p_cur[i].type,
2604 (char*)p_cur[i].ifname,
2605 (char*)p_cur[i].addresses,
2606 (char*)p_cur[i].dnses,
2607 (char*)p_cur[i].addresses);
2608 }
2609 removeLastChar;
2610 closeResponse;
2611
2612 return 0;
2613}
2614
Howard Subd82ef12015-04-12 10:25:05 +02002615static int responseDataCallListV9(Parcel &p, void *response, size_t responselen)
2616{
2617 if (response == NULL && responselen != 0) {
2618 RLOGE("invalid response: NULL");
2619 return RIL_ERRNO_INVALID_RESPONSE;
2620 }
2621
2622 if (responselen % sizeof(RIL_Data_Call_Response_v9) != 0) {
2623 RLOGE("responseDataCallListV9: invalid response length %d expected multiple of %d",
2624 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v9));
2625 return RIL_ERRNO_INVALID_RESPONSE;
2626 }
2627
2628 // Write version
2629 p.writeInt32(10);
2630
2631 int num = responselen / sizeof(RIL_Data_Call_Response_v9);
2632 p.writeInt32(num);
2633
2634 RIL_Data_Call_Response_v9 *p_cur = (RIL_Data_Call_Response_v9 *) response;
2635 startResponse;
2636 int i;
2637 for (i = 0; i < num; i++) {
2638 p.writeInt32((int)p_cur[i].status);
2639 p.writeInt32(p_cur[i].suggestedRetryTime);
2640 p.writeInt32(p_cur[i].cid);
2641 p.writeInt32(p_cur[i].active);
2642 writeStringToParcel(p, p_cur[i].type);
2643 writeStringToParcel(p, p_cur[i].ifname);
2644 writeStringToParcel(p, p_cur[i].addresses);
2645 writeStringToParcel(p, p_cur[i].dnses);
2646 writeStringToParcel(p, p_cur[i].gateways);
2647 writeStringToParcel(p, p_cur[i].pcscf);
2648 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s],", printBuf,
2649 p_cur[i].status,
2650 p_cur[i].suggestedRetryTime,
2651 p_cur[i].cid,
2652 (p_cur[i].active==0)?"down":"up",
2653 (char*)p_cur[i].type,
2654 (char*)p_cur[i].ifname,
2655 (char*)p_cur[i].addresses,
2656 (char*)p_cur[i].dnses,
2657 (char*)p_cur[i].gateways,
2658 (char*)p_cur[i].pcscf);
2659 }
2660 removeLastChar;
2661 closeResponse;
2662
2663 return 0;
2664}
2665
Sanket Padawe9343e872016-01-11 12:45:43 -08002666static int responseDataCallListV11(Parcel &p, void *response, size_t responselen) {
2667 if (response == NULL && responselen != 0) {
2668 RLOGE("invalid response: NULL");
2669 return RIL_ERRNO_INVALID_RESPONSE;
2670 }
2671
2672 if (responselen % sizeof(RIL_Data_Call_Response_v11) != 0) {
2673 RLOGE("invalid response length %d expected multiple of %d",
2674 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v11));
2675 return RIL_ERRNO_INVALID_RESPONSE;
2676 }
2677
2678 // Write version
2679 p.writeInt32(11);
2680
2681 int num = responselen / sizeof(RIL_Data_Call_Response_v11);
2682 p.writeInt32(num);
2683
2684 RIL_Data_Call_Response_v11 *p_cur = (RIL_Data_Call_Response_v11 *) response;
2685 startResponse;
2686 int i;
2687 for (i = 0; i < num; i++) {
2688 p.writeInt32((int)p_cur[i].status);
2689 p.writeInt32(p_cur[i].suggestedRetryTime);
2690 p.writeInt32(p_cur[i].cid);
2691 p.writeInt32(p_cur[i].active);
2692 writeStringToParcel(p, p_cur[i].type);
2693 writeStringToParcel(p, p_cur[i].ifname);
2694 writeStringToParcel(p, p_cur[i].addresses);
2695 writeStringToParcel(p, p_cur[i].dnses);
2696 writeStringToParcel(p, p_cur[i].gateways);
2697 writeStringToParcel(p, p_cur[i].pcscf);
2698 p.writeInt32(p_cur[i].mtu);
2699 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s,mtu=%d],", printBuf,
2700 p_cur[i].status,
2701 p_cur[i].suggestedRetryTime,
2702 p_cur[i].cid,
2703 (p_cur[i].active==0)?"down":"up",
2704 (char*)p_cur[i].type,
2705 (char*)p_cur[i].ifname,
2706 (char*)p_cur[i].addresses,
2707 (char*)p_cur[i].dnses,
2708 (char*)p_cur[i].gateways,
2709 (char*)p_cur[i].pcscf,
2710 p_cur[i].mtu);
2711 }
2712 removeLastChar;
2713 closeResponse;
2714
2715 return 0;
2716}
Howard Subd82ef12015-04-12 10:25:05 +02002717
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002718static int responseDataCallList(Parcel &p, void *response, size_t responselen)
2719{
Sanket Padawe9343e872016-01-11 12:45:43 -08002720 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
2721 if (s_callbacks.version < 5) {
2722 RLOGD("responseDataCallList: v4");
2723 return responseDataCallListV4(p, response, responselen);
2724 } else if (responselen % sizeof(RIL_Data_Call_Response_v6) == 0) {
2725 return responseDataCallListV6(p, response, responselen);
2726 } else if (responselen % sizeof(RIL_Data_Call_Response_v9) == 0) {
2727 return responseDataCallListV9(p, response, responselen);
2728 } else {
2729 return responseDataCallListV11(p, response, responselen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002730 }
Sanket Padawea79128a2016-01-26 18:44:01 -08002731 } else { // RIL version >= 13
Howard Subd82ef12015-04-12 10:25:05 +02002732 if (responselen % sizeof(RIL_Data_Call_Response_v11) != 0) {
Sanket Padawe9343e872016-01-11 12:45:43 -08002733 RLOGE("Data structure expected is RIL_Data_Call_Response_v11");
2734 if (!isDebuggable()) {
2735 return RIL_ERRNO_INVALID_RESPONSE;
2736 } else {
2737 assert(0);
2738 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002739 }
Sanket Padawe9343e872016-01-11 12:45:43 -08002740 return responseDataCallListV11(p, response, responselen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002741 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002742}
2743
2744static int responseSetupDataCall(Parcel &p, void *response, size_t responselen)
2745{
2746 if (s_callbacks.version < 5) {
2747 return responseStringsWithVersion(s_callbacks.version, p, response, responselen);
2748 } else {
2749 return responseDataCallList(p, response, responselen);
2750 }
2751}
2752
2753static int responseRaw(Parcel &p, void *response, size_t responselen) {
2754 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002755 RLOGE("invalid response: NULL with responselen != 0");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002756 return RIL_ERRNO_INVALID_RESPONSE;
2757 }
2758
2759 // The java code reads -1 size as null byte array
2760 if (response == NULL) {
2761 p.writeInt32(-1);
2762 } else {
2763 p.writeInt32(responselen);
2764 p.write(response, responselen);
2765 }
2766
2767 return 0;
2768}
2769
2770
2771static int responseSIM_IO(Parcel &p, void *response, size_t responselen) {
2772 if (response == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002773 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002774 return RIL_ERRNO_INVALID_RESPONSE;
2775 }
2776
2777 if (responselen != sizeof (RIL_SIM_IO_Response) ) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002778 RLOGE("invalid response length was %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002779 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
2780 return RIL_ERRNO_INVALID_RESPONSE;
2781 }
2782
2783 RIL_SIM_IO_Response *p_cur = (RIL_SIM_IO_Response *) response;
2784 p.writeInt32(p_cur->sw1);
2785 p.writeInt32(p_cur->sw2);
2786 writeStringToParcel(p, p_cur->simResponse);
2787
2788 startResponse;
2789 appendPrintBuf("%ssw1=0x%X,sw2=0x%X,%s", printBuf, p_cur->sw1, p_cur->sw2,
2790 (char*)p_cur->simResponse);
2791 closeResponse;
2792
2793
2794 return 0;
2795}
2796
2797static int responseCallForwards(Parcel &p, void *response, size_t responselen) {
2798 int num;
2799
2800 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002801 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002802 return RIL_ERRNO_INVALID_RESPONSE;
2803 }
2804
2805 if (responselen % sizeof(RIL_CallForwardInfo *) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002806 RLOGE("responseCallForwards: invalid response length %d expected multiple of %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002807 (int)responselen, (int)sizeof(RIL_CallForwardInfo *));
2808 return RIL_ERRNO_INVALID_RESPONSE;
2809 }
2810
2811 /* number of call info's */
2812 num = responselen / sizeof(RIL_CallForwardInfo *);
2813 p.writeInt32(num);
2814
2815 startResponse;
2816 for (int i = 0 ; i < num ; i++) {
2817 RIL_CallForwardInfo *p_cur = ((RIL_CallForwardInfo **) response)[i];
2818
2819 p.writeInt32(p_cur->status);
2820 p.writeInt32(p_cur->reason);
2821 p.writeInt32(p_cur->serviceClass);
2822 p.writeInt32(p_cur->toa);
2823 writeStringToParcel(p, p_cur->number);
2824 p.writeInt32(p_cur->timeSeconds);
2825 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
2826 (p_cur->status==1)?"enable":"disable",
2827 p_cur->reason, p_cur->serviceClass, p_cur->toa,
2828 (char*)p_cur->number,
2829 p_cur->timeSeconds);
2830 }
2831 removeLastChar;
2832 closeResponse;
2833
2834 return 0;
2835}
2836
2837static int responseSsn(Parcel &p, void *response, size_t responselen) {
2838 if (response == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002839 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002840 return RIL_ERRNO_INVALID_RESPONSE;
2841 }
2842
2843 if (responselen != sizeof(RIL_SuppSvcNotification)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002844 RLOGE("invalid response length was %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002845 (int)responselen, (int)sizeof (RIL_SuppSvcNotification));
2846 return RIL_ERRNO_INVALID_RESPONSE;
2847 }
2848
2849 RIL_SuppSvcNotification *p_cur = (RIL_SuppSvcNotification *) response;
2850 p.writeInt32(p_cur->notificationType);
2851 p.writeInt32(p_cur->code);
2852 p.writeInt32(p_cur->index);
2853 p.writeInt32(p_cur->type);
2854 writeStringToParcel(p, p_cur->number);
2855
2856 startResponse;
2857 appendPrintBuf("%s%s,code=%d,id=%d,type=%d,%s", printBuf,
2858 (p_cur->notificationType==0)?"mo":"mt",
2859 p_cur->code, p_cur->index, p_cur->type,
2860 (char*)p_cur->number);
2861 closeResponse;
2862
2863 return 0;
2864}
2865
2866static int responseCellList(Parcel &p, void *response, size_t responselen) {
2867 int num;
2868
2869 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002870 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002871 return RIL_ERRNO_INVALID_RESPONSE;
2872 }
2873
2874 if (responselen % sizeof (RIL_NeighboringCell *) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002875 RLOGE("responseCellList: invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002876 (int)responselen, (int)sizeof (RIL_NeighboringCell *));
2877 return RIL_ERRNO_INVALID_RESPONSE;
2878 }
2879
2880 startResponse;
2881 /* number of records */
2882 num = responselen / sizeof(RIL_NeighboringCell *);
2883 p.writeInt32(num);
2884
2885 for (int i = 0 ; i < num ; i++) {
2886 RIL_NeighboringCell *p_cur = ((RIL_NeighboringCell **) response)[i];
2887
2888 p.writeInt32(p_cur->rssi);
2889 writeStringToParcel (p, p_cur->cid);
2890
2891 appendPrintBuf("%s[cid=%s,rssi=%d],", printBuf,
2892 p_cur->cid, p_cur->rssi);
2893 }
2894 removeLastChar;
2895 closeResponse;
2896
2897 return 0;
2898}
2899
2900/**
2901 * Marshall the signalInfoRecord into the parcel if it exists.
2902 */
2903static void marshallSignalInfoRecord(Parcel &p,
2904 RIL_CDMA_SignalInfoRecord &p_signalInfoRecord) {
2905 p.writeInt32(p_signalInfoRecord.isPresent);
2906 p.writeInt32(p_signalInfoRecord.signalType);
2907 p.writeInt32(p_signalInfoRecord.alertPitch);
2908 p.writeInt32(p_signalInfoRecord.signal);
2909}
2910
2911static int responseCdmaInformationRecords(Parcel &p,
2912 void *response, size_t responselen) {
2913 int num;
2914 char* string8 = NULL;
2915 int buffer_lenght;
2916 RIL_CDMA_InformationRecord *infoRec;
2917
2918 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002919 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002920 return RIL_ERRNO_INVALID_RESPONSE;
2921 }
2922
2923 if (responselen != sizeof (RIL_CDMA_InformationRecords)) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002924 RLOGE("responseCdmaInformationRecords: invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002925 (int)responselen, (int)sizeof (RIL_CDMA_InformationRecords *));
2926 return RIL_ERRNO_INVALID_RESPONSE;
2927 }
2928
2929 RIL_CDMA_InformationRecords *p_cur =
2930 (RIL_CDMA_InformationRecords *) response;
2931 num = MIN(p_cur->numberOfInfoRecs, RIL_CDMA_MAX_NUMBER_OF_INFO_RECS);
2932
2933 startResponse;
2934 p.writeInt32(num);
2935
2936 for (int i = 0 ; i < num ; i++) {
2937 infoRec = &p_cur->infoRec[i];
2938 p.writeInt32(infoRec->name);
2939 switch (infoRec->name) {
2940 case RIL_CDMA_DISPLAY_INFO_REC:
2941 case RIL_CDMA_EXTENDED_DISPLAY_INFO_REC:
2942 if (infoRec->rec.display.alpha_len >
2943 CDMA_ALPHA_INFO_BUFFER_LENGTH) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002944 RLOGE("invalid display info response length %d \
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002945 expected not more than %d\n",
2946 (int)infoRec->rec.display.alpha_len,
2947 CDMA_ALPHA_INFO_BUFFER_LENGTH);
2948 return RIL_ERRNO_INVALID_RESPONSE;
2949 }
2950 string8 = (char*) malloc((infoRec->rec.display.alpha_len + 1)
2951 * sizeof(char) );
Sanket Padawedf3dabe2016-02-29 10:09:26 -08002952 if (string8 == NULL) {
2953 RLOGE("Memory allocation failed for responseCdmaInformationRecords");
2954 closeRequest;
2955 return RIL_ERRNO_NO_MEMORY;
2956 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002957 for (int i = 0 ; i < infoRec->rec.display.alpha_len ; i++) {
2958 string8[i] = infoRec->rec.display.alpha_buf[i];
2959 }
2960 string8[(int)infoRec->rec.display.alpha_len] = '\0';
2961 writeStringToParcel(p, (const char*)string8);
2962 free(string8);
2963 string8 = NULL;
2964 break;
2965 case RIL_CDMA_CALLED_PARTY_NUMBER_INFO_REC:
2966 case RIL_CDMA_CALLING_PARTY_NUMBER_INFO_REC:
2967 case RIL_CDMA_CONNECTED_NUMBER_INFO_REC:
2968 if (infoRec->rec.number.len > CDMA_NUMBER_INFO_BUFFER_LENGTH) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002969 RLOGE("invalid display info response length %d \
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002970 expected not more than %d\n",
2971 (int)infoRec->rec.number.len,
2972 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2973 return RIL_ERRNO_INVALID_RESPONSE;
2974 }
2975 string8 = (char*) malloc((infoRec->rec.number.len + 1)
2976 * sizeof(char) );
Sanket Padawedf3dabe2016-02-29 10:09:26 -08002977 if (string8 == NULL) {
2978 RLOGE("Memory allocation failed for responseCdmaInformationRecords");
2979 closeRequest;
2980 return RIL_ERRNO_NO_MEMORY;
2981 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002982 for (int i = 0 ; i < infoRec->rec.number.len; i++) {
2983 string8[i] = infoRec->rec.number.buf[i];
2984 }
2985 string8[(int)infoRec->rec.number.len] = '\0';
2986 writeStringToParcel(p, (const char*)string8);
2987 free(string8);
2988 string8 = NULL;
2989 p.writeInt32(infoRec->rec.number.number_type);
2990 p.writeInt32(infoRec->rec.number.number_plan);
2991 p.writeInt32(infoRec->rec.number.pi);
2992 p.writeInt32(infoRec->rec.number.si);
2993 break;
2994 case RIL_CDMA_SIGNAL_INFO_REC:
2995 p.writeInt32(infoRec->rec.signal.isPresent);
2996 p.writeInt32(infoRec->rec.signal.signalType);
2997 p.writeInt32(infoRec->rec.signal.alertPitch);
2998 p.writeInt32(infoRec->rec.signal.signal);
2999
3000 appendPrintBuf("%sisPresent=%X, signalType=%X, \
3001 alertPitch=%X, signal=%X, ",
3002 printBuf, (int)infoRec->rec.signal.isPresent,
3003 (int)infoRec->rec.signal.signalType,
3004 (int)infoRec->rec.signal.alertPitch,
3005 (int)infoRec->rec.signal.signal);
3006 removeLastChar;
3007 break;
3008 case RIL_CDMA_REDIRECTING_NUMBER_INFO_REC:
3009 if (infoRec->rec.redir.redirectingNumber.len >
3010 CDMA_NUMBER_INFO_BUFFER_LENGTH) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003011 RLOGE("invalid display info response length %d \
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003012 expected not more than %d\n",
3013 (int)infoRec->rec.redir.redirectingNumber.len,
3014 CDMA_NUMBER_INFO_BUFFER_LENGTH);
3015 return RIL_ERRNO_INVALID_RESPONSE;
3016 }
3017 string8 = (char*) malloc((infoRec->rec.redir.redirectingNumber
3018 .len + 1) * sizeof(char) );
Sanket Padawedf3dabe2016-02-29 10:09:26 -08003019 if (string8 == NULL) {
3020 RLOGE("Memory allocation failed for responseCdmaInformationRecords");
3021 closeRequest;
3022 return RIL_ERRNO_NO_MEMORY;
3023 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003024 for (int i = 0;
3025 i < infoRec->rec.redir.redirectingNumber.len;
3026 i++) {
3027 string8[i] = infoRec->rec.redir.redirectingNumber.buf[i];
3028 }
3029 string8[(int)infoRec->rec.redir.redirectingNumber.len] = '\0';
3030 writeStringToParcel(p, (const char*)string8);
3031 free(string8);
3032 string8 = NULL;
3033 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_type);
3034 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_plan);
3035 p.writeInt32(infoRec->rec.redir.redirectingNumber.pi);
3036 p.writeInt32(infoRec->rec.redir.redirectingNumber.si);
3037 p.writeInt32(infoRec->rec.redir.redirectingReason);
3038 break;
3039 case RIL_CDMA_LINE_CONTROL_INFO_REC:
3040 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPolarityIncluded);
3041 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlToggle);
3042 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlReverse);
3043 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPowerDenial);
3044
3045 appendPrintBuf("%slineCtrlPolarityIncluded=%d, \
3046 lineCtrlToggle=%d, lineCtrlReverse=%d, \
3047 lineCtrlPowerDenial=%d, ", printBuf,
3048 (int)infoRec->rec.lineCtrl.lineCtrlPolarityIncluded,
3049 (int)infoRec->rec.lineCtrl.lineCtrlToggle,
3050 (int)infoRec->rec.lineCtrl.lineCtrlReverse,
3051 (int)infoRec->rec.lineCtrl.lineCtrlPowerDenial);
3052 removeLastChar;
3053 break;
3054 case RIL_CDMA_T53_CLIR_INFO_REC:
3055 p.writeInt32((int)(infoRec->rec.clir.cause));
3056
3057 appendPrintBuf("%scause%d", printBuf, infoRec->rec.clir.cause);
3058 removeLastChar;
3059 break;
3060 case RIL_CDMA_T53_AUDIO_CONTROL_INFO_REC:
3061 p.writeInt32(infoRec->rec.audioCtrl.upLink);
3062 p.writeInt32(infoRec->rec.audioCtrl.downLink);
3063
3064 appendPrintBuf("%supLink=%d, downLink=%d, ", printBuf,
3065 infoRec->rec.audioCtrl.upLink,
3066 infoRec->rec.audioCtrl.downLink);
3067 removeLastChar;
3068 break;
3069 case RIL_CDMA_T53_RELEASE_INFO_REC:
3070 // TODO(Moto): See David Krause, he has the answer:)
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003071 RLOGE("RIL_CDMA_T53_RELEASE_INFO_REC: return INVALID_RESPONSE");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003072 return RIL_ERRNO_INVALID_RESPONSE;
3073 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003074 RLOGE("Incorrect name value");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003075 return RIL_ERRNO_INVALID_RESPONSE;
3076 }
3077 }
3078 closeResponse;
3079
3080 return 0;
3081}
3082
Sanket Padawe9343e872016-01-11 12:45:43 -08003083static void responseRilSignalStrengthV5(Parcel &p, RIL_SignalStrength_v10 *p_cur) {
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303084 int gsmSignalStrength;
3085 int cdmaDbm;
3086 int evdoDbm;
3087
Sanket Padawe9343e872016-01-11 12:45:43 -08003088 gsmSignalStrength = p_cur->GW_SignalStrength.signalStrength & 0xFF;
Utkarsh Gupta8ede9fa2015-04-23 13:21:49 +05303089
3090#ifdef MODEM_TYPE_XMM6260
3091 if (gsmSignalStrength < 0 ||
3092 (gsmSignalStrength > 31 && p_cur->GW_SignalStrength.signalStrength != 99)) {
3093 gsmSignalStrength = p_cur->CDMA_SignalStrength.dbm;
3094 }
3095#else
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303096 if (gsmSignalStrength < 0) {
3097 gsmSignalStrength = 99;
3098 } else if (gsmSignalStrength > 31 && gsmSignalStrength != 99) {
3099 gsmSignalStrength = 31;
3100 }
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303101#endif
3102 p.writeInt32(gsmSignalStrength);
3103
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003104 p.writeInt32(p_cur->GW_SignalStrength.bitErrorRate);
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303105
Christopher N. Hesse621e63e2016-02-22 21:57:39 +01003106#if defined(MODEM_TYPE_XMM6262) || defined(SAMSUNG_NEXT_GEN_MODEM)
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303107 cdmaDbm = p_cur->CDMA_SignalStrength.dbm & 0xFF;
3108 if (cdmaDbm < 0) {
3109 cdmaDbm = 99;
3110 } else if (cdmaDbm > 31 && cdmaDbm != 99) {
3111 cdmaDbm = 31;
3112 }
3113#else
Caio Schnepperec042542015-04-14 08:03:43 -03003114 cdmaDbm = p_cur->CDMA_SignalStrength.dbm;
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303115#endif
3116 p.writeInt32(cdmaDbm);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003117 p.writeInt32(p_cur->CDMA_SignalStrength.ecio);
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303118
Christopher N. Hesse621e63e2016-02-22 21:57:39 +01003119#if defined(MODEM_TYPE_XMM6262) || defined(SAMSUNG_NEXT_GEN_MODEM)
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303120 evdoDbm = p_cur->EVDO_SignalStrength.dbm & 0xFF;
3121 if (evdoDbm < 0) {
3122 evdoDbm = 99;
3123 } else if (evdoDbm > 31 && evdoDbm != 99) {
3124 evdoDbm = 31;
3125 }
3126#else
3127 evdoDbm = p_cur->EVDO_SignalStrength.dbm;
3128#endif
3129 p.writeInt32(evdoDbm);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003130 p.writeInt32(p_cur->EVDO_SignalStrength.ecio);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003131 p.writeInt32(p_cur->EVDO_SignalStrength.signalNoiseRatio);
Sanket Padawe9343e872016-01-11 12:45:43 -08003132}
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003133
Sanket Padawe9343e872016-01-11 12:45:43 -08003134static void responseRilSignalStrengthV6Extra(Parcel &p, RIL_SignalStrength_v10 *p_cur) {
3135 /*
3136 * Fixup LTE for backwards compatibility
3137 */
3138 // signalStrength: -1 -> 99
3139 if (p_cur->LTE_SignalStrength.signalStrength == -1) {
3140 p_cur->LTE_SignalStrength.signalStrength = 99;
3141 }
3142 // rsrp: -1 -> INT_MAX all other negative value to positive.
3143 // So remap here
3144 if (p_cur->LTE_SignalStrength.rsrp == -1) {
3145 p_cur->LTE_SignalStrength.rsrp = INT_MAX;
3146 } else if (p_cur->LTE_SignalStrength.rsrp < -1) {
3147 p_cur->LTE_SignalStrength.rsrp = -p_cur->LTE_SignalStrength.rsrp;
3148 }
3149 // rsrq: -1 -> INT_MAX
3150 if (p_cur->LTE_SignalStrength.rsrq == -1) {
3151 p_cur->LTE_SignalStrength.rsrq = INT_MAX;
3152 }
3153 // Not remapping rssnr is already using INT_MAX
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003154
Sanket Padawe9343e872016-01-11 12:45:43 -08003155 // cqi: -1 -> INT_MAX
3156 if (p_cur->LTE_SignalStrength.cqi == -1) {
3157 p_cur->LTE_SignalStrength.cqi = INT_MAX;
3158 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003159
Sanket Padawe9343e872016-01-11 12:45:43 -08003160 p.writeInt32(p_cur->LTE_SignalStrength.signalStrength);
3161 p.writeInt32(p_cur->LTE_SignalStrength.rsrp);
3162 p.writeInt32(p_cur->LTE_SignalStrength.rsrq);
3163 p.writeInt32(p_cur->LTE_SignalStrength.rssnr);
3164 p.writeInt32(p_cur->LTE_SignalStrength.cqi);
3165}
3166
3167static void responseRilSignalStrengthV10(Parcel &p, RIL_SignalStrength_v10 *p_cur) {
3168 responseRilSignalStrengthV5(p, p_cur);
3169 responseRilSignalStrengthV6Extra(p, p_cur);
3170 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
3171}
3172
3173
3174static int responseRilSignalStrength(Parcel &p,
3175 void *response, size_t responselen) {
3176 if (response == NULL && responselen != 0) {
3177 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003178 return RIL_ERRNO_INVALID_RESPONSE;
3179 }
3180
Sanket Padawe9343e872016-01-11 12:45:43 -08003181 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
3182 if (responselen >= sizeof (RIL_SignalStrength_v5)) {
3183 RIL_SignalStrength_v10 *p_cur = ((RIL_SignalStrength_v10 *) response);
3184
3185 responseRilSignalStrengthV5(p, p_cur);
3186
3187 if (responselen >= sizeof (RIL_SignalStrength_v6)) {
3188 responseRilSignalStrengthV6Extra(p, p_cur);
3189 if (responselen >= sizeof (RIL_SignalStrength_v10)) {
3190 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
3191 } else {
3192 p.writeInt32(INT_MAX);
3193 }
3194 } else {
3195 p.writeInt32(99);
3196 p.writeInt32(INT_MAX);
3197 p.writeInt32(INT_MAX);
3198 p.writeInt32(INT_MAX);
3199 p.writeInt32(INT_MAX);
3200 p.writeInt32(INT_MAX);
3201 }
3202 } else {
3203 RLOGE("invalid response length");
3204 return RIL_ERRNO_INVALID_RESPONSE;
3205 }
Sanket Padawea79128a2016-01-26 18:44:01 -08003206 } else { // RIL version >= 13
Sanket Padawe9343e872016-01-11 12:45:43 -08003207 if (responselen % sizeof(RIL_SignalStrength_v10) != 0) {
3208 RLOGE("Data structure expected is RIL_SignalStrength_v10");
3209 if (!isDebuggable()) {
3210 return RIL_ERRNO_INVALID_RESPONSE;
3211 } else {
3212 assert(0);
3213 }
3214 }
3215 RIL_SignalStrength_v10 *p_cur = ((RIL_SignalStrength_v10 *) response);
3216 responseRilSignalStrengthV10(p, p_cur);
3217 }
3218
3219 startResponse;
3220 appendPrintBuf("%s[signalStrength=%d,bitErrorRate=%d,\
3221 CDMA_SS.dbm=%d,CDMA_SSecio=%d,\
3222 EVDO_SS.dbm=%d,EVDO_SS.ecio=%d,\
3223 EVDO_SS.signalNoiseRatio=%d,\
3224 LTE_SS.signalStrength=%d,LTE_SS.rsrp=%d,LTE_SS.rsrq=%d,\
3225 LTE_SS.rssnr=%d,LTE_SS.cqi=%d,TDSCDMA_SS.rscp=%d]",
3226 printBuf,
3227 gsmSignalStrength,
3228 p_cur->GW_SignalStrength.bitErrorRate,
3229 cdmaDbm,
3230 p_cur->CDMA_SignalStrength.ecio,
3231 evdoDbm,
3232 p_cur->EVDO_SignalStrength.ecio,
3233 p_cur->EVDO_SignalStrength.signalNoiseRatio,
3234 p_cur->LTE_SignalStrength.signalStrength,
3235 p_cur->LTE_SignalStrength.rsrp,
3236 p_cur->LTE_SignalStrength.rsrq,
3237 p_cur->LTE_SignalStrength.rssnr,
3238 p_cur->LTE_SignalStrength.cqi,
3239 p_cur->TD_SCDMA_SignalStrength.rscp);
3240 closeResponse;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003241 return 0;
3242}
3243
3244static int responseCallRing(Parcel &p, void *response, size_t responselen) {
3245 if ((response == NULL) || (responselen == 0)) {
3246 return responseVoid(p, response, responselen);
3247 } else {
3248 return responseCdmaSignalInfoRecord(p, response, responselen);
3249 }
3250}
3251
3252static int responseCdmaSignalInfoRecord(Parcel &p, void *response, size_t responselen) {
3253 if (response == NULL || responselen == 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003254 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003255 return RIL_ERRNO_INVALID_RESPONSE;
3256 }
3257
3258 if (responselen != sizeof (RIL_CDMA_SignalInfoRecord)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003259 RLOGE("invalid response length %d expected sizeof (RIL_CDMA_SignalInfoRecord) of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003260 (int)responselen, (int)sizeof (RIL_CDMA_SignalInfoRecord));
3261 return RIL_ERRNO_INVALID_RESPONSE;
3262 }
3263
3264 startResponse;
3265
3266 RIL_CDMA_SignalInfoRecord *p_cur = ((RIL_CDMA_SignalInfoRecord *) response);
3267 marshallSignalInfoRecord(p, *p_cur);
3268
3269 appendPrintBuf("%s[isPresent=%d,signalType=%d,alertPitch=%d\
3270 signal=%d]",
3271 printBuf,
3272 p_cur->isPresent,
3273 p_cur->signalType,
3274 p_cur->alertPitch,
3275 p_cur->signal);
3276
3277 closeResponse;
3278 return 0;
3279}
3280
3281static int responseCdmaCallWaiting(Parcel &p, void *response,
3282 size_t responselen) {
3283 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003284 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003285 return RIL_ERRNO_INVALID_RESPONSE;
3286 }
3287
3288 if (responselen < sizeof(RIL_CDMA_CallWaiting_v6)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003289 RLOGW("Upgrade to ril version %d\n", RIL_VERSION);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003290 }
3291
3292 RIL_CDMA_CallWaiting_v6 *p_cur = ((RIL_CDMA_CallWaiting_v6 *) response);
3293
3294 writeStringToParcel(p, p_cur->number);
3295 p.writeInt32(p_cur->numberPresentation);
3296 writeStringToParcel(p, p_cur->name);
3297 marshallSignalInfoRecord(p, p_cur->signalInfoRecord);
3298
Sanket Padawe9343e872016-01-11 12:45:43 -08003299 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
3300 if (responselen >= sizeof(RIL_CDMA_CallWaiting_v6)) {
3301 p.writeInt32(p_cur->number_type);
3302 p.writeInt32(p_cur->number_plan);
3303 } else {
3304 p.writeInt32(0);
3305 p.writeInt32(0);
3306 }
Sanket Padawea79128a2016-01-26 18:44:01 -08003307 } else { // RIL version >= 13
Sanket Padawe9343e872016-01-11 12:45:43 -08003308 if (responselen % sizeof(RIL_CDMA_CallWaiting_v6) != 0) {
3309 RLOGE("Data structure expected is RIL_CDMA_CallWaiting_v6");
3310 if (!isDebuggable()) {
3311 return RIL_ERRNO_INVALID_RESPONSE;
3312 } else {
3313 assert(0);
3314 }
3315 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003316 p.writeInt32(p_cur->number_type);
3317 p.writeInt32(p_cur->number_plan);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003318 }
3319
3320 startResponse;
3321 appendPrintBuf("%snumber=%s,numberPresentation=%d, name=%s,\
3322 signalInfoRecord[isPresent=%d,signalType=%d,alertPitch=%d\
3323 signal=%d,number_type=%d,number_plan=%d]",
3324 printBuf,
3325 p_cur->number,
3326 p_cur->numberPresentation,
3327 p_cur->name,
3328 p_cur->signalInfoRecord.isPresent,
3329 p_cur->signalInfoRecord.signalType,
3330 p_cur->signalInfoRecord.alertPitch,
3331 p_cur->signalInfoRecord.signal,
3332 p_cur->number_type,
3333 p_cur->number_plan);
3334 closeResponse;
3335
3336 return 0;
3337}
3338
Sanket Padawe9343e872016-01-11 12:45:43 -08003339static void responseSimRefreshV7(Parcel &p, void *response) {
3340 RIL_SimRefreshResponse_v7 *p_cur = ((RIL_SimRefreshResponse_v7 *) response);
3341 p.writeInt32(p_cur->result);
3342 p.writeInt32(p_cur->ef_id);
3343 writeStringToParcel(p, p_cur->aid);
3344
3345 appendPrintBuf("%sresult=%d, ef_id=%d, aid=%s",
3346 printBuf,
3347 p_cur->result,
3348 p_cur->ef_id,
3349 p_cur->aid);
3350
3351}
3352
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003353static int responseSimRefresh(Parcel &p, void *response, size_t responselen) {
3354 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003355 RLOGE("responseSimRefresh: invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003356 return RIL_ERRNO_INVALID_RESPONSE;
3357 }
3358
3359 startResponse;
Sanket Padawe9343e872016-01-11 12:45:43 -08003360 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
Sanket Padawe201aca32016-01-21 15:49:33 -08003361 if (s_callbacks.version >= 7) {
Sanket Padawe9343e872016-01-11 12:45:43 -08003362 responseSimRefreshV7(p, response);
3363 } else {
3364 int *p_cur = ((int *) response);
3365 p.writeInt32(p_cur[0]);
3366 p.writeInt32(p_cur[1]);
3367 writeStringToParcel(p, NULL);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003368
Sanket Padawe9343e872016-01-11 12:45:43 -08003369 appendPrintBuf("%sresult=%d, ef_id=%d",
3370 printBuf,
3371 p_cur[0],
3372 p_cur[1]);
3373 }
Sanket Padawea79128a2016-01-26 18:44:01 -08003374 } else { // RIL version >= 13
Sanket Padawe9343e872016-01-11 12:45:43 -08003375 if (responselen % sizeof(RIL_SimRefreshResponse_v7) != 0) {
3376 RLOGE("Data structure expected is RIL_SimRefreshResponse_v7");
3377 if (!isDebuggable()) {
3378 return RIL_ERRNO_INVALID_RESPONSE;
3379 } else {
3380 assert(0);
3381 }
3382 }
3383 responseSimRefreshV7(p, response);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003384
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003385 }
3386 closeResponse;
3387
3388 return 0;
3389}
3390
Sanket Padawea79128a2016-01-26 18:44:01 -08003391static int responseCellInfoListV6(Parcel &p, void *response, size_t responselen) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003392 if (response == NULL && responselen != 0) {
3393 RLOGE("invalid response: NULL");
3394 return RIL_ERRNO_INVALID_RESPONSE;
3395 }
3396
3397 if (responselen % sizeof(RIL_CellInfo) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08003398 RLOGE("responseCellInfoList: invalid response length %d expected multiple of %d",
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003399 (int)responselen, (int)sizeof(RIL_CellInfo));
3400 return RIL_ERRNO_INVALID_RESPONSE;
3401 }
3402
3403 int num = responselen / sizeof(RIL_CellInfo);
3404 p.writeInt32(num);
3405
3406 RIL_CellInfo *p_cur = (RIL_CellInfo *) response;
3407 startResponse;
3408 int i;
3409 for (i = 0; i < num; i++) {
3410 appendPrintBuf("%s[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", printBuf, i,
3411 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
3412 p.writeInt32((int)p_cur->cellInfoType);
3413 p.writeInt32(p_cur->registered);
3414 p.writeInt32(p_cur->timeStampType);
3415 p.writeInt64(p_cur->timeStamp);
3416 switch(p_cur->cellInfoType) {
3417 case RIL_CELL_INFO_TYPE_GSM: {
3418 appendPrintBuf("%s GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,", printBuf,
3419 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
3420 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
3421 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
3422 p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3423 appendPrintBuf("%s gsmSS: ss=%d,ber=%d],", printBuf,
3424 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
3425 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3426
3427 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
3428 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
3429 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
3430 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3431 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
3432 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3433 break;
3434 }
3435 case RIL_CELL_INFO_TYPE_WCDMA: {
3436 appendPrintBuf("%s WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,", printBuf,
3437 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
3438 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
3439 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
3440 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
3441 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3442 appendPrintBuf("%s wcdmaSS: ss=%d,ber=%d],", printBuf,
3443 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
3444 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3445
3446 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
3447 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
3448 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
3449 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
3450 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3451 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
3452 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3453 break;
3454 }
3455 case RIL_CELL_INFO_TYPE_CDMA: {
3456 appendPrintBuf("%s CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d", printBuf,
3457 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
3458 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
3459 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
3460 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
3461 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3462
3463 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
3464 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
3465 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
3466 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
3467 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3468
3469 appendPrintBuf("%s cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d", printBuf,
3470 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
3471 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
3472 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
3473 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
3474 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3475
3476 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
3477 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
3478 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
3479 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
3480 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3481 break;
3482 }
3483 case RIL_CELL_INFO_TYPE_LTE: {
3484 appendPrintBuf("%s LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d", printBuf,
3485 p_cur->CellInfo.lte.cellIdentityLte.mcc,
3486 p_cur->CellInfo.lte.cellIdentityLte.mnc,
3487 p_cur->CellInfo.lte.cellIdentityLte.ci,
3488 p_cur->CellInfo.lte.cellIdentityLte.pci,
3489 p_cur->CellInfo.lte.cellIdentityLte.tac);
3490
3491 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
3492 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
3493 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
3494 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
3495 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
3496
3497 appendPrintBuf("%s lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d", printBuf,
3498 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
3499 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
3500 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
3501 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
3502 p_cur->CellInfo.lte.signalStrengthLte.cqi,
3503 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3504 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
3505 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
3506 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
3507 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
3508 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
3509 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3510 break;
3511 }
Howard Sue32dbfd2015-01-07 15:55:57 +08003512 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
3513 appendPrintBuf("%s TDSCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,cpid=%d,", printBuf,
3514 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc,
3515 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc,
3516 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac,
3517 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid,
3518 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3519 appendPrintBuf("%s tdscdmaSS: rscp=%d],", printBuf,
3520 p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3521
3522 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
3523 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
3524 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
3525 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
3526 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3527 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3528 break;
3529 }
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003530 }
3531 p_cur += 1;
3532 }
3533 removeLastChar;
3534 closeResponse;
3535
3536 return 0;
3537}
3538
Sanket Padawea79128a2016-01-26 18:44:01 -08003539static int responseCellInfoListV12(Parcel &p, void *response, size_t responselen) {
3540 if (response == NULL && responselen != 0) {
3541 RLOGE("invalid response: NULL");
3542 return RIL_ERRNO_INVALID_RESPONSE;
3543 }
3544
3545 if (responselen % sizeof(RIL_CellInfo_v12) != 0) {
3546 RLOGE("responseCellInfoList: invalid response length %d expected multiple of %d",
3547 (int)responselen, (int)sizeof(RIL_CellInfo_v12));
3548 return RIL_ERRNO_INVALID_RESPONSE;
3549 }
3550
3551 int num = responselen / sizeof(RIL_CellInfo_v12);
3552 p.writeInt32(num);
3553
3554 RIL_CellInfo_v12 *p_cur = (RIL_CellInfo_v12 *) response;
3555 startResponse;
3556 int i;
3557 for (i = 0; i < num; i++) {
3558 appendPrintBuf("%s[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", printBuf, i,
3559 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
3560 RLOGE("[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", i,
3561 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
3562 p.writeInt32((int)p_cur->cellInfoType);
3563 p.writeInt32(p_cur->registered);
3564 p.writeInt32(p_cur->timeStampType);
3565 p.writeInt64(p_cur->timeStamp);
3566 switch(p_cur->cellInfoType) {
3567 case RIL_CELL_INFO_TYPE_GSM: {
3568 appendPrintBuf("%s GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,arfcn=%d,bsic=%x", printBuf,
3569 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
3570 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
3571 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
3572 p_cur->CellInfo.gsm.cellIdentityGsm.cid,
3573 p_cur->CellInfo.gsm.cellIdentityGsm.arfcn,
3574 p_cur->CellInfo.gsm.cellIdentityGsm.bsic);
3575 RLOGE("GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,arfcn=%d,bsic=%x",
3576 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
3577 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
3578 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
3579 p_cur->CellInfo.gsm.cellIdentityGsm.cid,
3580 p_cur->CellInfo.gsm.cellIdentityGsm.arfcn,
3581 p_cur->CellInfo.gsm.cellIdentityGsm.bsic);
3582 RLOGE("gsmSS: ss=%d,ber=%d, ta=%d],",
3583 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
3584 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate,
3585 p_cur->CellInfo.gsm.signalStrengthGsm.timingAdvance);
3586 appendPrintBuf("%s gsmSS: ss=%d,ber=%d, ta=%d],", printBuf,
3587 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
3588 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate,
3589 p_cur->CellInfo.gsm.signalStrengthGsm.timingAdvance);
3590
3591 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
3592 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
3593 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
3594 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3595 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.arfcn);
3596 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.bsic);
3597 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
3598 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3599 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.timingAdvance);
3600 break;
3601 }
3602 case RIL_CELL_INFO_TYPE_WCDMA: {
3603 RLOGE("WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,uarfcn=%d",
3604 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
3605 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
3606 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
3607 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
3608 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc,
3609 p_cur->CellInfo.wcdma.cellIdentityWcdma.uarfcn);
3610 RLOGE("wcdmaSS: ss=%d,ber=%d],",
3611 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
3612 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3613 appendPrintBuf("%s WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,uarfcn=%d", printBuf,
3614 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
3615 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
3616 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
3617 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
3618 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc,
3619 p_cur->CellInfo.wcdma.cellIdentityWcdma.uarfcn);
3620 appendPrintBuf("%s wcdmaSS: ss=%d,ber=%d],", printBuf,
3621 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
3622 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3623
3624 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
3625 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
3626 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
3627 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
3628 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3629 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.uarfcn);
3630 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
3631 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3632 break;
3633 }
3634 case RIL_CELL_INFO_TYPE_CDMA: {
3635 RLOGE("CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d",
3636 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
3637 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
3638 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
3639 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
3640 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3641
3642 appendPrintBuf("%s CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d", printBuf,
3643 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
3644 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
3645 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
3646 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
3647 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3648
3649 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
3650 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
3651 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
3652 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
3653 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3654
3655 RLOGE("cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d",
3656 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
3657 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
3658 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
3659 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
3660 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3661
3662 appendPrintBuf("%s cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d", printBuf,
3663 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
3664 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
3665 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
3666 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
3667 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3668
3669 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
3670 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
3671 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
3672 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
3673 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3674 break;
3675 }
3676 case RIL_CELL_INFO_TYPE_LTE: {
3677 RLOGE("LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d,earfcn=%d",
3678 p_cur->CellInfo.lte.cellIdentityLte.mcc,
3679 p_cur->CellInfo.lte.cellIdentityLte.mnc,
3680 p_cur->CellInfo.lte.cellIdentityLte.ci,
3681 p_cur->CellInfo.lte.cellIdentityLte.pci,
3682 p_cur->CellInfo.lte.cellIdentityLte.tac,
3683 p_cur->CellInfo.lte.cellIdentityLte.earfcn);
3684
3685 appendPrintBuf("%s LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d,earfcn=%d", printBuf,
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 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
3694 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
3695 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
3696 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
3697 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
3698 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.earfcn);
3699
3700 RLOGE("lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d",
3701 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
3702 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
3703 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
3704 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
3705 p_cur->CellInfo.lte.signalStrengthLte.cqi,
3706 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3707 appendPrintBuf("%s lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d", printBuf,
3708 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
3709 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
3710 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
3711 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
3712 p_cur->CellInfo.lte.signalStrengthLte.cqi,
3713 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3714 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
3715 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
3716 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
3717 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
3718 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
3719 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3720 break;
3721 }
3722 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
3723 appendPrintBuf("%s TDSCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,cpid=%d,", printBuf,
3724 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc,
3725 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc,
3726 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac,
3727 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid,
3728 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3729 appendPrintBuf("%s tdscdmaSS: rscp=%d],", printBuf,
3730 p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3731
3732 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
3733 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
3734 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
3735 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
3736 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3737 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3738 break;
3739 }
3740 }
3741 p_cur += 1;
3742 }
3743 removeLastChar;
3744 closeResponse;
3745 return 0;
3746}
3747
3748static int responseCellInfoList(Parcel &p, void *response, size_t responselen)
3749{
3750 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
3751 if (s_callbacks.version < 12) {
3752 RLOGD("responseCellInfoList: v6");
3753 return responseCellInfoListV6(p, response, responselen);
3754 } else {
3755 RLOGD("responseCellInfoList: v12");
3756 return responseCellInfoListV12(p, response, responselen);
3757 }
3758 } else { // RIL version >= 13
3759 if (responselen % sizeof(RIL_CellInfo_v12) != 0) {
3760 RLOGE("Data structure expected is RIL_CellInfo_v12");
3761 if (!isDebuggable()) {
3762 return RIL_ERRNO_INVALID_RESPONSE;
3763 } else {
3764 assert(0);
3765 }
3766 }
3767 return responseCellInfoListV12(p, response, responselen);
3768 }
3769
3770 return 0;
3771}
3772
Howard Sue32dbfd2015-01-07 15:55:57 +08003773static int responseHardwareConfig(Parcel &p, void *response, size_t responselen)
3774{
3775 if (response == NULL && responselen != 0) {
3776 RLOGE("invalid response: NULL");
3777 return RIL_ERRNO_INVALID_RESPONSE;
3778 }
3779
3780 if (responselen % sizeof(RIL_HardwareConfig) != 0) {
3781 RLOGE("responseHardwareConfig: invalid response length %d expected multiple of %d",
3782 (int)responselen, (int)sizeof(RIL_HardwareConfig));
3783 return RIL_ERRNO_INVALID_RESPONSE;
3784 }
3785
3786 int num = responselen / sizeof(RIL_HardwareConfig);
3787 int i;
3788 RIL_HardwareConfig *p_cur = (RIL_HardwareConfig *) response;
3789
3790 p.writeInt32(num);
3791
3792 startResponse;
3793 for (i = 0; i < num; i++) {
3794 switch (p_cur[i].type) {
3795 case RIL_HARDWARE_CONFIG_MODEM: {
3796 writeStringToParcel(p, p_cur[i].uuid);
3797 p.writeInt32((int)p_cur[i].state);
3798 p.writeInt32(p_cur[i].cfg.modem.rat);
3799 p.writeInt32(p_cur[i].cfg.modem.maxVoice);
3800 p.writeInt32(p_cur[i].cfg.modem.maxData);
3801 p.writeInt32(p_cur[i].cfg.modem.maxStandby);
3802
3803 appendPrintBuf("%s modem: uuid=%s,state=%d,rat=%08x,maxV=%d,maxD=%d,maxS=%d", printBuf,
3804 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.modem.rat,
3805 p_cur[i].cfg.modem.maxVoice, p_cur[i].cfg.modem.maxData, p_cur[i].cfg.modem.maxStandby);
3806 break;
3807 }
3808 case RIL_HARDWARE_CONFIG_SIM: {
3809 writeStringToParcel(p, p_cur[i].uuid);
3810 p.writeInt32((int)p_cur[i].state);
3811 writeStringToParcel(p, p_cur[i].cfg.sim.modemUuid);
3812
3813 appendPrintBuf("%s sim: uuid=%s,state=%d,modem-uuid=%s", printBuf,
3814 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.sim.modemUuid);
3815 break;
3816 }
3817 }
3818 }
3819 removeLastChar;
3820 closeResponse;
3821 return 0;
3822}
3823
Howard Subd82ef12015-04-12 10:25:05 +02003824static int responseRadioCapability(Parcel &p, void *response, size_t responselen) {
3825 if (response == NULL) {
3826 RLOGE("invalid response: NULL");
3827 return RIL_ERRNO_INVALID_RESPONSE;
3828 }
3829
3830 if (responselen != sizeof (RIL_RadioCapability) ) {
3831 RLOGE("invalid response length was %d expected %d",
3832 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3833 return RIL_ERRNO_INVALID_RESPONSE;
3834 }
3835
3836 RIL_RadioCapability *p_cur = (RIL_RadioCapability *) response;
3837 p.writeInt32(p_cur->version);
3838 p.writeInt32(p_cur->session);
3839 p.writeInt32(p_cur->phase);
3840 p.writeInt32(p_cur->rat);
3841 writeStringToParcel(p, p_cur->logicalModemUuid);
3842 p.writeInt32(p_cur->status);
3843
3844 startResponse;
3845 appendPrintBuf("%s[version=%d,session=%d,phase=%d,\
Andreas Schneidera8d09502015-06-23 18:41:38 +02003846 rat=%d,logicalModemUuid=%s,status=%d]",
Howard Subd82ef12015-04-12 10:25:05 +02003847 printBuf,
3848 p_cur->version,
3849 p_cur->session,
3850 p_cur->phase,
3851 p_cur->rat,
3852 p_cur->logicalModemUuid,
3853 p_cur->status);
3854 closeResponse;
3855 return 0;
3856}
3857
3858static int responseSSData(Parcel &p, void *response, size_t responselen) {
3859 RLOGD("In responseSSData");
3860 int num;
3861
3862 if (response == NULL && responselen != 0) {
3863 RLOGE("invalid response length was %d expected %d",
3864 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3865 return RIL_ERRNO_INVALID_RESPONSE;
3866 }
3867
3868 if (responselen != sizeof(RIL_StkCcUnsolSsResponse)) {
3869 RLOGE("invalid response length %d, expected %d",
3870 (int)responselen, (int)sizeof(RIL_StkCcUnsolSsResponse));
3871 return RIL_ERRNO_INVALID_RESPONSE;
3872 }
3873
3874 startResponse;
3875 RIL_StkCcUnsolSsResponse *p_cur = (RIL_StkCcUnsolSsResponse *) response;
3876 p.writeInt32(p_cur->serviceType);
3877 p.writeInt32(p_cur->requestType);
3878 p.writeInt32(p_cur->teleserviceType);
3879 p.writeInt32(p_cur->serviceClass);
3880 p.writeInt32(p_cur->result);
3881
3882 if (isServiceTypeCfQuery(p_cur->serviceType, p_cur->requestType)) {
3883 RLOGD("responseSSData CF type, num of Cf elements %d", p_cur->cfData.numValidIndexes);
3884 if (p_cur->cfData.numValidIndexes > NUM_SERVICE_CLASSES) {
3885 RLOGE("numValidIndexes is greater than max value %d, "
3886 "truncating it to max value", NUM_SERVICE_CLASSES);
3887 p_cur->cfData.numValidIndexes = NUM_SERVICE_CLASSES;
3888 }
3889 /* number of call info's */
3890 p.writeInt32(p_cur->cfData.numValidIndexes);
3891
3892 for (int i = 0; i < p_cur->cfData.numValidIndexes; i++) {
3893 RIL_CallForwardInfo cf = p_cur->cfData.cfInfo[i];
3894
3895 p.writeInt32(cf.status);
3896 p.writeInt32(cf.reason);
3897 p.writeInt32(cf.serviceClass);
3898 p.writeInt32(cf.toa);
3899 writeStringToParcel(p, cf.number);
3900 p.writeInt32(cf.timeSeconds);
3901 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
3902 (cf.status==1)?"enable":"disable", cf.reason, cf.serviceClass, cf.toa,
3903 (char*)cf.number, cf.timeSeconds);
3904 RLOGD("Data: %d,reason=%d,cls=%d,toa=%d,num=%s,tout=%d],", cf.status,
3905 cf.reason, cf.serviceClass, cf.toa, (char*)cf.number, cf.timeSeconds);
3906 }
3907 } else {
3908 p.writeInt32 (SS_INFO_MAX);
3909
3910 /* each int*/
3911 for (int i = 0; i < SS_INFO_MAX; i++) {
3912 appendPrintBuf("%s%d,", printBuf, p_cur->ssInfo[i]);
3913 RLOGD("Data: %d",p_cur->ssInfo[i]);
3914 p.writeInt32(p_cur->ssInfo[i]);
3915 }
3916 }
3917 removeLastChar;
3918 closeResponse;
3919
3920 return 0;
3921}
3922
3923static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType) {
3924 if ((reqType == SS_INTERROGATION) &&
3925 (serType == SS_CFU ||
3926 serType == SS_CF_BUSY ||
3927 serType == SS_CF_NO_REPLY ||
3928 serType == SS_CF_NOT_REACHABLE ||
3929 serType == SS_CF_ALL ||
3930 serType == SS_CF_ALL_CONDITIONAL)) {
3931 return true;
3932 }
3933 return false;
3934}
3935
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003936static void triggerEvLoop() {
3937 int ret;
3938 if (!pthread_equal(pthread_self(), s_tid_dispatch)) {
3939 /* trigger event loop to wakeup. No reason to do this,
3940 * if we're in the event loop thread */
3941 do {
3942 ret = write (s_fdWakeupWrite, " ", 1);
3943 } while (ret < 0 && errno == EINTR);
3944 }
3945}
3946
3947static void rilEventAddWakeup(struct ril_event *ev) {
3948 ril_event_add(ev);
3949 triggerEvLoop();
3950}
3951
3952static void sendSimStatusAppInfo(Parcel &p, int num_apps, RIL_AppStatus appStatus[]) {
3953 p.writeInt32(num_apps);
3954 startResponse;
3955 for (int i = 0; i < num_apps; i++) {
3956 p.writeInt32(appStatus[i].app_type);
3957 p.writeInt32(appStatus[i].app_state);
3958 p.writeInt32(appStatus[i].perso_substate);
3959 writeStringToParcel(p, (const char*)(appStatus[i].aid_ptr));
3960 writeStringToParcel(p, (const char*)
3961 (appStatus[i].app_label_ptr));
3962 p.writeInt32(appStatus[i].pin1_replaced);
3963 p.writeInt32(appStatus[i].pin1);
3964 p.writeInt32(appStatus[i].pin2);
3965 appendPrintBuf("%s[app_type=%d,app_state=%d,perso_substate=%d,\
3966 aid_ptr=%s,app_label_ptr=%s,pin1_replaced=%d,pin1=%d,pin2=%d],",
3967 printBuf,
3968 appStatus[i].app_type,
3969 appStatus[i].app_state,
3970 appStatus[i].perso_substate,
3971 appStatus[i].aid_ptr,
3972 appStatus[i].app_label_ptr,
3973 appStatus[i].pin1_replaced,
3974 appStatus[i].pin1,
3975 appStatus[i].pin2);
3976 }
3977 closeResponse;
3978}
3979
Sanket Padawe9343e872016-01-11 12:45:43 -08003980static void responseSimStatusV5(Parcel &p, void *response) {
3981 RIL_CardStatus_v5 *p_cur = ((RIL_CardStatus_v5 *) response);
3982
3983 p.writeInt32(p_cur->card_state);
3984 p.writeInt32(p_cur->universal_pin_state);
3985 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3986 p.writeInt32(p_cur->cdma_subscription_app_index);
3987
3988 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
3989}
3990
3991static void responseSimStatusV6(Parcel &p, void *response) {
3992 RIL_CardStatus_v6 *p_cur = ((RIL_CardStatus_v6 *) response);
3993
3994 p.writeInt32(p_cur->card_state);
3995 p.writeInt32(p_cur->universal_pin_state);
3996 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3997 p.writeInt32(p_cur->cdma_subscription_app_index);
3998 p.writeInt32(p_cur->ims_subscription_app_index);
3999
4000 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
4001}
4002
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004003static int responseSimStatus(Parcel &p, void *response, size_t responselen) {
Howard Sue32dbfd2015-01-07 15:55:57 +08004004 int i;
4005
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004006 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004007 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004008 return RIL_ERRNO_INVALID_RESPONSE;
4009 }
4010
Sanket Padawe9343e872016-01-11 12:45:43 -08004011 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
4012 if (responselen == sizeof (RIL_CardStatus_v6)) {
4013 responseSimStatusV6(p, response);
4014 } else if (responselen == sizeof (RIL_CardStatus_v5)) {
4015 responseSimStatusV5(p, response);
4016 } else {
4017 RLOGE("responseSimStatus: A RilCardStatus_v6 or _v5 expected\n");
4018 return RIL_ERRNO_INVALID_RESPONSE;
4019 }
Sanket Padawea79128a2016-01-26 18:44:01 -08004020 } else { // RIL version >= 13
Sanket Padawe9343e872016-01-11 12:45:43 -08004021 if (responselen % sizeof(RIL_CardStatus_v6) != 0) {
4022 RLOGE("Data structure expected is RIL_CardStatus_v6");
4023 if (!isDebuggable()) {
4024 return RIL_ERRNO_INVALID_RESPONSE;
4025 } else {
4026 assert(0);
4027 }
4028 }
4029 responseSimStatusV6(p, response);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004030 }
4031
4032 return 0;
4033}
4034
4035static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen) {
4036 int num = responselen / sizeof(RIL_GSM_BroadcastSmsConfigInfo *);
4037 p.writeInt32(num);
4038
4039 startResponse;
4040 RIL_GSM_BroadcastSmsConfigInfo **p_cur =
4041 (RIL_GSM_BroadcastSmsConfigInfo **) response;
4042 for (int i = 0; i < num; i++) {
4043 p.writeInt32(p_cur[i]->fromServiceId);
4044 p.writeInt32(p_cur[i]->toServiceId);
4045 p.writeInt32(p_cur[i]->fromCodeScheme);
4046 p.writeInt32(p_cur[i]->toCodeScheme);
4047 p.writeInt32(p_cur[i]->selected);
4048
4049 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId=%d, \
4050 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]",
4051 printBuf, i, p_cur[i]->fromServiceId, p_cur[i]->toServiceId,
4052 p_cur[i]->fromCodeScheme, p_cur[i]->toCodeScheme,
4053 p_cur[i]->selected);
4054 }
4055 closeResponse;
4056
4057 return 0;
4058}
4059
4060static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen) {
4061 RIL_CDMA_BroadcastSmsConfigInfo **p_cur =
4062 (RIL_CDMA_BroadcastSmsConfigInfo **) response;
4063
4064 int num = responselen / sizeof (RIL_CDMA_BroadcastSmsConfigInfo *);
4065 p.writeInt32(num);
4066
4067 startResponse;
4068 for (int i = 0 ; i < num ; i++ ) {
4069 p.writeInt32(p_cur[i]->service_category);
4070 p.writeInt32(p_cur[i]->language);
4071 p.writeInt32(p_cur[i]->selected);
4072
4073 appendPrintBuf("%s [%d: srvice_category=%d, language =%d, \
4074 selected =%d], ",
4075 printBuf, i, p_cur[i]->service_category, p_cur[i]->language,
4076 p_cur[i]->selected);
4077 }
4078 closeResponse;
4079
4080 return 0;
4081}
4082
4083static int responseCdmaSms(Parcel &p, void *response, size_t responselen) {
4084 int num;
4085 int digitCount;
4086 int digitLimit;
4087 uint8_t uct;
4088 void* dest;
4089
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004090 RLOGD("Inside responseCdmaSms");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004091
4092 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004093 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004094 return RIL_ERRNO_INVALID_RESPONSE;
4095 }
4096
4097 if (responselen != sizeof(RIL_CDMA_SMS_Message)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004098 RLOGE("invalid response length was %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004099 (int)responselen, (int)sizeof(RIL_CDMA_SMS_Message));
4100 return RIL_ERRNO_INVALID_RESPONSE;
4101 }
4102
4103 RIL_CDMA_SMS_Message *p_cur = (RIL_CDMA_SMS_Message *) response;
4104 p.writeInt32(p_cur->uTeleserviceID);
4105 p.write(&(p_cur->bIsServicePresent),sizeof(uct));
4106 p.writeInt32(p_cur->uServicecategory);
4107 p.writeInt32(p_cur->sAddress.digit_mode);
4108 p.writeInt32(p_cur->sAddress.number_mode);
4109 p.writeInt32(p_cur->sAddress.number_type);
4110 p.writeInt32(p_cur->sAddress.number_plan);
4111 p.write(&(p_cur->sAddress.number_of_digits), sizeof(uct));
4112 digitLimit= MIN((p_cur->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
4113 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
4114 p.write(&(p_cur->sAddress.digits[digitCount]),sizeof(uct));
4115 }
4116
4117 p.writeInt32(p_cur->sSubAddress.subaddressType);
4118 p.write(&(p_cur->sSubAddress.odd),sizeof(uct));
4119 p.write(&(p_cur->sSubAddress.number_of_digits),sizeof(uct));
4120 digitLimit= MIN((p_cur->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
4121 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
4122 p.write(&(p_cur->sSubAddress.digits[digitCount]),sizeof(uct));
4123 }
4124
4125 digitLimit= MIN((p_cur->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
4126 p.writeInt32(p_cur->uBearerDataLen);
4127 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
4128 p.write(&(p_cur->aBearerData[digitCount]), sizeof(uct));
4129 }
4130
4131 startResponse;
4132 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
4133 sAddress.digit_mode=%d, sAddress.number_mode=%d, sAddress.number_type=%d, ",
4134 printBuf, p_cur->uTeleserviceID,p_cur->bIsServicePresent,p_cur->uServicecategory,
4135 p_cur->sAddress.digit_mode, p_cur->sAddress.number_mode,p_cur->sAddress.number_type);
4136 closeResponse;
4137
4138 return 0;
4139}
4140
Howard Sue32dbfd2015-01-07 15:55:57 +08004141static int responseDcRtInfo(Parcel &p, void *response, size_t responselen)
4142{
4143 int num = responselen / sizeof(RIL_DcRtInfo);
4144 if ((responselen % sizeof(RIL_DcRtInfo) != 0) || (num != 1)) {
4145 RLOGE("responseDcRtInfo: invalid response length %d expected multiple of %d",
4146 (int)responselen, (int)sizeof(RIL_DcRtInfo));
4147 return RIL_ERRNO_INVALID_RESPONSE;
4148 }
4149
4150 startResponse;
4151 RIL_DcRtInfo *pDcRtInfo = (RIL_DcRtInfo *)response;
4152 p.writeInt64(pDcRtInfo->time);
4153 p.writeInt32(pDcRtInfo->powerState);
4154 appendPrintBuf("%s[time=%d,powerState=%d]", printBuf,
4155 pDcRtInfo->time,
Andreas Schneidera8d09502015-06-23 18:41:38 +02004156 (int)pDcRtInfo->powerState);
Howard Sue32dbfd2015-01-07 15:55:57 +08004157 closeResponse;
4158
4159 return 0;
4160}
4161
fenglu9bdede02015-04-14 14:53:55 -07004162static int responseLceStatus(Parcel &p, void *response, size_t responselen) {
4163 if (response == NULL || responselen != sizeof(RIL_LceStatusInfo)) {
4164 if (response == NULL) {
4165 RLOGE("invalid response: NULL");
4166 }
4167 else {
4168 RLOGE("responseLceStatus: invalid response length %d expecting len: d%",
4169 sizeof(RIL_LceStatusInfo), responselen);
4170 }
4171 return RIL_ERRNO_INVALID_RESPONSE;
4172 }
4173
4174 RIL_LceStatusInfo *p_cur = (RIL_LceStatusInfo *)response;
4175 p.write((void *)p_cur, 1); // p_cur->lce_status takes one byte.
4176 p.writeInt32(p_cur->actual_interval_ms);
4177
4178 startResponse;
4179 appendPrintBuf("LCE Status: %d, actual_interval_ms: %d",
4180 p_cur->lce_status, p_cur->actual_interval_ms);
4181 closeResponse;
4182
4183 return 0;
4184}
4185
4186static int responseLceData(Parcel &p, void *response, size_t responselen) {
4187 if (response == NULL || responselen != sizeof(RIL_LceDataInfo)) {
4188 if (response == NULL) {
4189 RLOGE("invalid response: NULL");
4190 }
4191 else {
4192 RLOGE("responseLceData: invalid response length %d expecting len: d%",
4193 sizeof(RIL_LceDataInfo), responselen);
4194 }
4195 return RIL_ERRNO_INVALID_RESPONSE;
4196 }
4197
4198 RIL_LceDataInfo *p_cur = (RIL_LceDataInfo *)response;
4199 p.writeInt32(p_cur->last_hop_capacity_kbps);
4200
4201 /* p_cur->confidence_level and p_cur->lce_suspended take 1 byte each.*/
4202 p.write((void *)&(p_cur->confidence_level), 1);
4203 p.write((void *)&(p_cur->lce_suspended), 1);
4204
4205 startResponse;
Hyejine942c332015-09-14 16:27:28 -07004206 appendPrintBuf("LCE info received: capacity %d confidence level %d \
4207 and suspended %d",
fenglu9bdede02015-04-14 14:53:55 -07004208 p_cur->last_hop_capacity_kbps, p_cur->confidence_level,
4209 p_cur->lce_suspended);
4210 closeResponse;
4211
4212 return 0;
4213}
4214
Prerepa Viswanadham8e755592015-05-28 00:37:32 -07004215static int responseActivityData(Parcel &p, void *response, size_t responselen) {
4216 if (response == NULL || responselen != sizeof(RIL_ActivityStatsInfo)) {
4217 if (response == NULL) {
4218 RLOGE("invalid response: NULL");
4219 }
4220 else {
4221 RLOGE("responseActivityData: invalid response length %d expecting len: d%",
4222 sizeof(RIL_ActivityStatsInfo), responselen);
4223 }
4224 return RIL_ERRNO_INVALID_RESPONSE;
4225 }
4226
4227 RIL_ActivityStatsInfo *p_cur = (RIL_ActivityStatsInfo *)response;
4228 p.writeInt32(p_cur->sleep_mode_time_ms);
4229 p.writeInt32(p_cur->idle_mode_time_ms);
4230 for(int i = 0; i < RIL_NUM_TX_POWER_LEVELS; i++) {
4231 p.writeInt32(p_cur->tx_mode_time_ms[i]);
4232 }
4233 p.writeInt32(p_cur->rx_mode_time_ms);
4234
4235 startResponse;
Hyejine942c332015-09-14 16:27:28 -07004236 appendPrintBuf("Modem activity info received: sleep_mode_time_ms %d idle_mode_time_ms %d \
4237 tx_mode_time_ms %d %d %d %d %d and rx_mode_time_ms %d",
Prerepa Viswanadham8e755592015-05-28 00:37:32 -07004238 p_cur->sleep_mode_time_ms, p_cur->idle_mode_time_ms, p_cur->tx_mode_time_ms[0],
4239 p_cur->tx_mode_time_ms[1], p_cur->tx_mode_time_ms[2], p_cur->tx_mode_time_ms[3],
4240 p_cur->tx_mode_time_ms[4], p_cur->rx_mode_time_ms);
4241 closeResponse;
4242
4243 return 0;
4244}
4245
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004246/**
4247 * A write on the wakeup fd is done just to pop us out of select()
4248 * We empty the buffer here and then ril_event will reset the timers on the
4249 * way back down
4250 */
4251static void processWakeupCallback(int fd, short flags, void *param) {
4252 char buff[16];
4253 int ret;
4254
Ethan Chend6e30652013-08-04 22:49:56 -07004255 RLOGV("processWakeupCallback");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004256
4257 /* empty our wakeup socket out */
4258 do {
4259 ret = read(s_fdWakeupRead, &buff, sizeof(buff));
4260 } while (ret > 0 || (ret < 0 && errno == EINTR));
4261}
4262
Howard Sue32dbfd2015-01-07 15:55:57 +08004263static void onCommandsSocketClosed(RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004264 int ret;
4265 RequestInfo *p_cur;
Howard Sue32dbfd2015-01-07 15:55:57 +08004266 /* Hook for current context
4267 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
4268 pthread_mutex_t * pendingRequestsMutexHook = &s_pendingRequestsMutex;
4269 /* pendingRequestsHook refer to &s_pendingRequests */
4270 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004271
Howard Sue32dbfd2015-01-07 15:55:57 +08004272#if (SIM_COUNT >= 2)
4273 if (socket_id == RIL_SOCKET_2) {
4274 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
4275 pendingRequestsHook = &s_pendingRequests_socket2;
4276 }
4277#if (SIM_COUNT >= 3)
4278 else if (socket_id == RIL_SOCKET_3) {
4279 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
4280 pendingRequestsHook = &s_pendingRequests_socket3;
4281 }
4282#endif
4283#if (SIM_COUNT >= 4)
4284 else if (socket_id == RIL_SOCKET_4) {
4285 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
4286 pendingRequestsHook = &s_pendingRequests_socket4;
4287 }
4288#endif
4289#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004290 /* mark pending requests as "cancelled" so we dont report responses */
Howard Sue32dbfd2015-01-07 15:55:57 +08004291 ret = pthread_mutex_lock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004292 assert (ret == 0);
4293
Howard Sue32dbfd2015-01-07 15:55:57 +08004294 p_cur = *pendingRequestsHook;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004295
Howard Sue32dbfd2015-01-07 15:55:57 +08004296 for (p_cur = *pendingRequestsHook
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004297 ; p_cur != NULL
4298 ; p_cur = p_cur->p_next
4299 ) {
4300 p_cur->cancelled = 1;
4301 }
4302
Howard Sue32dbfd2015-01-07 15:55:57 +08004303 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004304 assert (ret == 0);
4305}
4306
4307static void processCommandsCallback(int fd, short flags, void *param) {
4308 RecordStream *p_rs;
4309 void *p_record;
4310 size_t recordlen;
4311 int ret;
Howard Sue32dbfd2015-01-07 15:55:57 +08004312 SocketListenParam *p_info = (SocketListenParam *)param;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004313
Howard Sue32dbfd2015-01-07 15:55:57 +08004314 assert(fd == p_info->fdCommand);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004315
Howard Sue32dbfd2015-01-07 15:55:57 +08004316 p_rs = p_info->p_rs;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004317
4318 for (;;) {
4319 /* loop until EAGAIN/EINTR, end of stream, or other error */
4320 ret = record_stream_get_next(p_rs, &p_record, &recordlen);
4321
4322 if (ret == 0 && p_record == NULL) {
4323 /* end-of-stream */
4324 break;
4325 } else if (ret < 0) {
4326 break;
4327 } else if (ret == 0) { /* && p_record != NULL */
Howard Sue32dbfd2015-01-07 15:55:57 +08004328 processCommandBuffer(p_record, recordlen, p_info->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004329 }
4330 }
4331
4332 if (ret == 0 || !(errno == EAGAIN || errno == EINTR)) {
4333 /* fatal error or end-of-stream */
4334 if (ret != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004335 RLOGE("error on reading command socket errno:%d\n", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004336 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004337 RLOGW("EOS. Closing command socket.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004338 }
4339
Howard Sue32dbfd2015-01-07 15:55:57 +08004340 close(fd);
4341 p_info->fdCommand = -1;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004342
Howard Sue32dbfd2015-01-07 15:55:57 +08004343 ril_event_del(p_info->commands_event);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004344
4345 record_stream_free(p_rs);
4346
4347 /* start listening for new connections again */
4348 rilEventAddWakeup(&s_listen_event);
4349
Howard Sue32dbfd2015-01-07 15:55:57 +08004350 onCommandsSocketClosed(p_info->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004351 }
4352}
4353
Howard Subd82ef12015-04-12 10:25:05 +02004354
Howard Sue32dbfd2015-01-07 15:55:57 +08004355static void onNewCommandConnect(RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004356 // Inform we are connected and the ril version
4357 int rilVer = s_callbacks.version;
Howard Sue32dbfd2015-01-07 15:55:57 +08004358 RIL_UNSOL_RESPONSE(RIL_UNSOL_RIL_CONNECTED,
4359 &rilVer, sizeof(rilVer), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004360
4361 // implicit radio state changed
Howard Sue32dbfd2015-01-07 15:55:57 +08004362 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
4363 NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004364
4365 // Send last NITZ time data, in case it was missed
4366 if (s_lastNITZTimeData != NULL) {
Howard Sue32dbfd2015-01-07 15:55:57 +08004367 sendResponseRaw(s_lastNITZTimeData, s_lastNITZTimeDataSize, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004368
4369 free(s_lastNITZTimeData);
4370 s_lastNITZTimeData = NULL;
4371 }
4372
4373 // Get version string
4374 if (s_callbacks.getVersion != NULL) {
4375 const char *version;
4376 version = s_callbacks.getVersion();
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004377 RLOGI("RIL Daemon version: %s\n", version);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004378
4379 property_set(PROPERTY_RIL_IMPL, version);
4380 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004381 RLOGI("RIL Daemon version: unavailable\n");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004382 property_set(PROPERTY_RIL_IMPL, "unavailable");
4383 }
4384
4385}
4386
4387static void listenCallback (int fd, short flags, void *param) {
4388 int ret;
4389 int err;
4390 int is_phone_socket;
Howard Sue32dbfd2015-01-07 15:55:57 +08004391 int fdCommand = -1;
Dheeraj Shettycc231012014-07-02 21:27:57 +02004392 char* processName;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004393 RecordStream *p_rs;
Dheeraj Shettycc231012014-07-02 21:27:57 +02004394 MySocketListenParam* listenParam;
4395 RilSocket *sapSocket = NULL;
4396 socketClient *sClient = NULL;
4397
Howard Sue32dbfd2015-01-07 15:55:57 +08004398 SocketListenParam *p_info = (SocketListenParam *)param;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004399
Dheeraj Shettycc231012014-07-02 21:27:57 +02004400 if(RIL_SAP_SOCKET == p_info->type) {
4401 listenParam = (MySocketListenParam *)param;
4402 sapSocket = listenParam->socket;
4403 }
4404
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004405 struct sockaddr_un peeraddr;
4406 socklen_t socklen = sizeof (peeraddr);
4407
4408 struct ucred creds;
4409 socklen_t szCreds = sizeof(creds);
4410
4411 struct passwd *pwd = NULL;
4412
Dheeraj Shettycc231012014-07-02 21:27:57 +02004413 if(NULL == sapSocket) {
4414 assert (*p_info->fdCommand < 0);
4415 assert (fd == *p_info->fdListen);
4416 processName = PHONE_PROCESS;
4417 } else {
4418 assert (sapSocket->commandFd < 0);
4419 assert (fd == sapSocket->listenFd);
4420 processName = BLUETOOTH_PROCESS;
4421 }
4422
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004423
Howard Sue32dbfd2015-01-07 15:55:57 +08004424 fdCommand = accept(fd, (sockaddr *) &peeraddr, &socklen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004425
Howard Sue32dbfd2015-01-07 15:55:57 +08004426 if (fdCommand < 0 ) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004427 RLOGE("Error on accept() errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004428 /* start listening for new connections again */
Dheeraj Shettycc231012014-07-02 21:27:57 +02004429 if(NULL == sapSocket) {
4430 rilEventAddWakeup(p_info->listen_event);
4431 } else {
4432 rilEventAddWakeup(sapSocket->getListenEvent());
4433 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004434 return;
4435 }
4436
4437 /* check the credential of the other side and only accept socket from
4438 * phone process
4439 */
4440 errno = 0;
4441 is_phone_socket = 0;
4442
Howard Sue32dbfd2015-01-07 15:55:57 +08004443 err = getsockopt(fdCommand, SOL_SOCKET, SO_PEERCRED, &creds, &szCreds);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004444
4445 if (err == 0 && szCreds > 0) {
4446 errno = 0;
4447 pwd = getpwuid(creds.uid);
4448 if (pwd != NULL) {
Dheeraj Shettycc231012014-07-02 21:27:57 +02004449 if (strcmp(pwd->pw_name, processName) == 0) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004450 is_phone_socket = 1;
4451 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004452 RLOGE("RILD can't accept socket from process %s", pwd->pw_name);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004453 }
4454 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004455 RLOGE("Error on getpwuid() errno: %d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004456 }
4457 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004458 RLOGD("Error on getsockopt() errno: %d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004459 }
4460
Howard Subd82ef12015-04-12 10:25:05 +02004461 if (!is_phone_socket) {
Dheeraj Shettycc231012014-07-02 21:27:57 +02004462 RLOGE("RILD must accept socket from %s", processName);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004463
Dheeraj Shettycc231012014-07-02 21:27:57 +02004464 close(fdCommand);
4465 fdCommand = -1;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004466
Dheeraj Shettycc231012014-07-02 21:27:57 +02004467 if(NULL == sapSocket) {
4468 onCommandsSocketClosed(p_info->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004469
Dheeraj Shettycc231012014-07-02 21:27:57 +02004470 /* start listening for new connections again */
4471 rilEventAddWakeup(p_info->listen_event);
4472 } else {
4473 sapSocket->onCommandsSocketClosed();
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004474
Dheeraj Shettycc231012014-07-02 21:27:57 +02004475 /* start listening for new connections again */
4476 rilEventAddWakeup(sapSocket->getListenEvent());
4477 }
4478
4479 return;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004480 }
4481
Howard Sue32dbfd2015-01-07 15:55:57 +08004482 ret = fcntl(fdCommand, F_SETFL, O_NONBLOCK);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004483
4484 if (ret < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004485 RLOGE ("Error setting O_NONBLOCK errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004486 }
4487
Dheeraj Shettycc231012014-07-02 21:27:57 +02004488 if(NULL == sapSocket) {
4489 RLOGI("libril: new connection to %s", rilSocketIdToString(p_info->socket_id));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004490
Dheeraj Shettycc231012014-07-02 21:27:57 +02004491 p_info->fdCommand = fdCommand;
4492 p_rs = record_stream_new(p_info->fdCommand, MAX_COMMAND_BYTES);
4493 p_info->p_rs = p_rs;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004494
Dheeraj Shettycc231012014-07-02 21:27:57 +02004495 ril_event_set (p_info->commands_event, p_info->fdCommand, 1,
Howard Sue32dbfd2015-01-07 15:55:57 +08004496 p_info->processCommandsCallback, p_info);
Dheeraj Shettycc231012014-07-02 21:27:57 +02004497 rilEventAddWakeup (p_info->commands_event);
Howard Sue32dbfd2015-01-07 15:55:57 +08004498
Dheeraj Shettycc231012014-07-02 21:27:57 +02004499 onNewCommandConnect(p_info->socket_id);
4500 } else {
4501 RLOGI("libril: new connection");
Howard Sue32dbfd2015-01-07 15:55:57 +08004502
Dheeraj Shettycc231012014-07-02 21:27:57 +02004503 sapSocket->setCommandFd(fdCommand);
4504 p_rs = record_stream_new(sapSocket->getCommandFd(), MAX_COMMAND_BYTES);
4505 sClient = new socketClient(sapSocket,p_rs);
4506 ril_event_set (sapSocket->getCallbackEvent(), sapSocket->getCommandFd(), 1,
4507 sapSocket->getCommandCb(), sClient);
4508
4509 rilEventAddWakeup(sapSocket->getCallbackEvent());
4510 sapSocket->onNewCommandConnect();
4511 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004512}
4513
4514static void freeDebugCallbackArgs(int number, char **args) {
4515 for (int i = 0; i < number; i++) {
4516 if (args[i] != NULL) {
4517 free(args[i]);
4518 }
4519 }
4520 free(args);
4521}
4522
4523static void debugCallback (int fd, short flags, void *param) {
4524 int acceptFD, option;
4525 struct sockaddr_un peeraddr;
4526 socklen_t socklen = sizeof (peeraddr);
4527 int data;
4528 unsigned int qxdm_data[6];
4529 const char *deactData[1] = {"1"};
4530 char *actData[1];
4531 RIL_Dial dialData;
4532 int hangupData[1] = {1};
4533 int number;
4534 char **args;
Howard Sue32dbfd2015-01-07 15:55:57 +08004535 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
4536 int sim_id = 0;
4537
4538 RLOGI("debugCallback for socket %s", rilSocketIdToString(socket_id));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004539
4540 acceptFD = accept (fd, (sockaddr *) &peeraddr, &socklen);
4541
4542 if (acceptFD < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004543 RLOGE ("error accepting on debug port: %d\n", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004544 return;
4545 }
4546
4547 if (recv(acceptFD, &number, sizeof(int), 0) != sizeof(int)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004548 RLOGE ("error reading on socket: number of Args: \n");
Sanket Padawedf3dabe2016-02-29 10:09:26 -08004549 close(acceptFD);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004550 return;
4551 }
Sanket Padawedf3dabe2016-02-29 10:09:26 -08004552
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004553 args = (char **) malloc(sizeof(char*) * number);
Sanket Padawedf3dabe2016-02-29 10:09:26 -08004554 if (args == NULL) {
4555 RLOGE("Memory allocation failed for debug args");
4556 close(acceptFD);
4557 return;
4558 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004559
4560 for (int i = 0; i < number; i++) {
4561 int len;
4562 if (recv(acceptFD, &len, sizeof(int), 0) != sizeof(int)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004563 RLOGE ("error reading on socket: Len of Args: \n");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004564 freeDebugCallbackArgs(i, args);
Sanket Padawedf3dabe2016-02-29 10:09:26 -08004565 close(acceptFD);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004566 return;
4567 }
Sanket Padawedf3dabe2016-02-29 10:09:26 -08004568
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004569 // +1 for null-term
4570 args[i] = (char *) malloc((sizeof(char) * len) + 1);
Sanket Padawedf3dabe2016-02-29 10:09:26 -08004571 if (args[i] == NULL) {
4572 RLOGE("Memory allocation failed for debug args");
4573 freeDebugCallbackArgs(i, args);
4574 close(acceptFD);
4575 return;
4576 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004577 if (recv(acceptFD, args[i], sizeof(char) * len, 0)
4578 != (int)sizeof(char) * len) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004579 RLOGE ("error reading on socket: Args[%d] \n", i);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004580 freeDebugCallbackArgs(i, args);
Sanket Padawedf3dabe2016-02-29 10:09:26 -08004581 close(acceptFD);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004582 return;
4583 }
4584 char * buf = args[i];
4585 buf[len] = 0;
Howard Sue32dbfd2015-01-07 15:55:57 +08004586 if ((i+1) == number) {
4587 /* The last argument should be sim id 0(SIM1)~3(SIM4) */
4588 sim_id = atoi(args[i]);
4589 switch (sim_id) {
4590 case 0:
4591 socket_id = RIL_SOCKET_1;
4592 break;
4593 #if (SIM_COUNT >= 2)
4594 case 1:
4595 socket_id = RIL_SOCKET_2;
4596 break;
4597 #endif
4598 #if (SIM_COUNT >= 3)
4599 case 2:
4600 socket_id = RIL_SOCKET_3;
4601 break;
4602 #endif
4603 #if (SIM_COUNT >= 4)
4604 case 3:
4605 socket_id = RIL_SOCKET_4;
4606 break;
4607 #endif
4608 default:
4609 socket_id = RIL_SOCKET_1;
4610 break;
4611 }
4612 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004613 }
4614
4615 switch (atoi(args[0])) {
4616 case 0:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004617 RLOGI ("Connection on debug port: issuing reset.");
Howard Sue32dbfd2015-01-07 15:55:57 +08004618 issueLocalRequest(RIL_REQUEST_RESET_RADIO, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004619 break;
4620 case 1:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004621 RLOGI ("Connection on debug port: issuing radio power off.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004622 data = 0;
Howard Sue32dbfd2015-01-07 15:55:57 +08004623 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004624 // Close the socket
Howard Subd82ef12015-04-12 10:25:05 +02004625 if (socket_id == RIL_SOCKET_1 && s_ril_param_socket.fdCommand > 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08004626 close(s_ril_param_socket.fdCommand);
4627 s_ril_param_socket.fdCommand = -1;
4628 }
4629 #if (SIM_COUNT == 2)
4630 else if (socket_id == RIL_SOCKET_2 && s_ril_param_socket2.fdCommand > 0) {
4631 close(s_ril_param_socket2.fdCommand);
4632 s_ril_param_socket2.fdCommand = -1;
4633 }
4634 #endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004635 break;
4636 case 2:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004637 RLOGI ("Debug port: issuing unsolicited voice network change.");
Howard Sue32dbfd2015-01-07 15:55:57 +08004638 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004639 break;
4640 case 3:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004641 RLOGI ("Debug port: QXDM log enable.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004642 qxdm_data[0] = 65536; // head.func_tag
4643 qxdm_data[1] = 16; // head.len
4644 qxdm_data[2] = 1; // mode: 1 for 'start logging'
4645 qxdm_data[3] = 32; // log_file_size: 32megabytes
4646 qxdm_data[4] = 0; // log_mask
4647 qxdm_data[5] = 8; // log_max_fileindex
4648 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Howard Sue32dbfd2015-01-07 15:55:57 +08004649 6 * sizeof(int), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004650 break;
4651 case 4:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004652 RLOGI ("Debug port: QXDM log disable.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004653 qxdm_data[0] = 65536;
4654 qxdm_data[1] = 16;
4655 qxdm_data[2] = 0; // mode: 0 for 'stop logging'
4656 qxdm_data[3] = 32;
4657 qxdm_data[4] = 0;
4658 qxdm_data[5] = 8;
4659 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Howard Sue32dbfd2015-01-07 15:55:57 +08004660 6 * sizeof(int), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004661 break;
4662 case 5:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004663 RLOGI("Debug port: Radio On");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004664 data = 1;
Howard Sue32dbfd2015-01-07 15:55:57 +08004665 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004666 sleep(2);
4667 // Set network selection automatic.
Howard Sue32dbfd2015-01-07 15:55:57 +08004668 issueLocalRequest(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004669 break;
4670 case 6:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004671 RLOGI("Debug port: Setup Data Call, Apn :%s\n", args[1]);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004672 actData[0] = args[1];
4673 issueLocalRequest(RIL_REQUEST_SETUP_DATA_CALL, &actData,
Howard Sue32dbfd2015-01-07 15:55:57 +08004674 sizeof(actData), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004675 break;
4676 case 7:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004677 RLOGI("Debug port: Deactivate Data Call");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004678 issueLocalRequest(RIL_REQUEST_DEACTIVATE_DATA_CALL, &deactData,
Howard Sue32dbfd2015-01-07 15:55:57 +08004679 sizeof(deactData), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004680 break;
4681 case 8:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004682 RLOGI("Debug port: Dial Call");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004683 dialData.clir = 0;
4684 dialData.address = args[1];
Howard Sue32dbfd2015-01-07 15:55:57 +08004685 issueLocalRequest(RIL_REQUEST_DIAL, &dialData, sizeof(dialData), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004686 break;
4687 case 9:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004688 RLOGI("Debug port: Answer Call");
Howard Sue32dbfd2015-01-07 15:55:57 +08004689 issueLocalRequest(RIL_REQUEST_ANSWER, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004690 break;
4691 case 10:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004692 RLOGI("Debug port: End Call");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004693 issueLocalRequest(RIL_REQUEST_HANGUP, &hangupData,
Howard Sue32dbfd2015-01-07 15:55:57 +08004694 sizeof(hangupData), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004695 break;
4696 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004697 RLOGE ("Invalid request");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004698 break;
4699 }
4700 freeDebugCallbackArgs(number, args);
4701 close(acceptFD);
4702}
4703
4704
4705static void userTimerCallback (int fd, short flags, void *param) {
4706 UserCallbackInfo *p_info;
4707
4708 p_info = (UserCallbackInfo *)param;
4709
4710 p_info->p_callback(p_info->userParam);
4711
4712
4713 // FIXME generalize this...there should be a cancel mechanism
4714 if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) {
4715 s_last_wake_timeout_info = NULL;
4716 }
4717
4718 free(p_info);
4719}
4720
4721
4722static void *
4723eventLoop(void *param) {
4724 int ret;
4725 int filedes[2];
4726
4727 ril_event_init();
4728
4729 pthread_mutex_lock(&s_startupMutex);
4730
4731 s_started = 1;
4732 pthread_cond_broadcast(&s_startupCond);
4733
4734 pthread_mutex_unlock(&s_startupMutex);
4735
4736 ret = pipe(filedes);
4737
4738 if (ret < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004739 RLOGE("Error in pipe() errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004740 return NULL;
4741 }
4742
4743 s_fdWakeupRead = filedes[0];
4744 s_fdWakeupWrite = filedes[1];
4745
4746 fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK);
4747
4748 ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,
4749 processWakeupCallback, NULL);
4750
4751 rilEventAddWakeup (&s_wakeupfd_event);
4752
4753 // Only returns on error
4754 ril_event_loop();
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004755 RLOGE ("error in event_loop_base errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004756 // kill self to restart on error
4757 kill(0, SIGKILL);
4758
4759 return NULL;
4760}
4761
4762extern "C" void
4763RIL_startEventLoop(void) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004764 /* spin up eventLoop thread and wait for it to get started */
4765 s_started = 0;
4766 pthread_mutex_lock(&s_startupMutex);
4767
Howard Sue32dbfd2015-01-07 15:55:57 +08004768 pthread_attr_t attr;
4769 pthread_attr_init(&attr);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004770 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
Howard Sue32dbfd2015-01-07 15:55:57 +08004771
4772 int result = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
4773 if (result != 0) {
4774 RLOGE("Failed to create dispatch thread: %s", strerror(result));
4775 goto done;
4776 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004777
4778 while (s_started == 0) {
4779 pthread_cond_wait(&s_startupCond, &s_startupMutex);
4780 }
4781
Howard Sue32dbfd2015-01-07 15:55:57 +08004782done:
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004783 pthread_mutex_unlock(&s_startupMutex);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004784}
4785
4786// Used for testing purpose only.
4787extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) {
4788 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4789}
4790
Howard Sue32dbfd2015-01-07 15:55:57 +08004791static void startListen(RIL_SOCKET_ID socket_id, SocketListenParam* socket_listen_p) {
4792 int fdListen = -1;
4793 int ret;
4794 char socket_name[10];
4795
4796 memset(socket_name, 0, sizeof(char)*10);
4797
4798 switch(socket_id) {
4799 case RIL_SOCKET_1:
4800 strncpy(socket_name, RIL_getRilSocketName(), 9);
4801 break;
4802 #if (SIM_COUNT >= 2)
4803 case RIL_SOCKET_2:
4804 strncpy(socket_name, SOCKET2_NAME_RIL, 9);
4805 break;
4806 #endif
4807 #if (SIM_COUNT >= 3)
4808 case RIL_SOCKET_3:
4809 strncpy(socket_name, SOCKET3_NAME_RIL, 9);
4810 break;
4811 #endif
4812 #if (SIM_COUNT >= 4)
4813 case RIL_SOCKET_4:
4814 strncpy(socket_name, SOCKET4_NAME_RIL, 9);
4815 break;
4816 #endif
4817 default:
4818 RLOGE("Socket id is wrong!!");
4819 return;
4820 }
4821
4822 RLOGI("Start to listen %s", rilSocketIdToString(socket_id));
4823
4824 fdListen = android_get_control_socket(socket_name);
4825 if (fdListen < 0) {
4826 RLOGE("Failed to get socket %s", socket_name);
4827 exit(-1);
4828 }
4829
4830 ret = listen(fdListen, 4);
4831
4832 if (ret < 0) {
4833 RLOGE("Failed to listen on control socket '%d': %s",
4834 fdListen, strerror(errno));
4835 exit(-1);
4836 }
4837 socket_listen_p->fdListen = fdListen;
4838
4839 /* note: non-persistent so we can accept only one connection at a time */
4840 ril_event_set (socket_listen_p->listen_event, fdListen, false,
4841 listenCallback, socket_listen_p);
4842
4843 rilEventAddWakeup (socket_listen_p->listen_event);
4844}
4845
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004846extern "C" void
4847RIL_register (const RIL_RadioFunctions *callbacks) {
4848 int ret;
4849 int flags;
4850
Howard Sue32dbfd2015-01-07 15:55:57 +08004851 RLOGI("SIM_COUNT: %d", SIM_COUNT);
4852
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004853 if (callbacks == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004854 RLOGE("RIL_register: RIL_RadioFunctions * null");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004855 return;
4856 }
4857 if (callbacks->version < RIL_VERSION_MIN) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004858 RLOGE("RIL_register: version %d is to old, min version is %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004859 callbacks->version, RIL_VERSION_MIN);
4860 return;
4861 }
Sanket Padawe9343e872016-01-11 12:45:43 -08004862
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004863 RLOGE("RIL_register: RIL version %d", callbacks->version);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004864
4865 if (s_registerCalled > 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004866 RLOGE("RIL_register has been called more than once. "
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004867 "Subsequent call ignored");
4868 return;
4869 }
4870
4871 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4872
Howard Sue32dbfd2015-01-07 15:55:57 +08004873 /* Initialize socket1 parameters */
4874 s_ril_param_socket = {
4875 RIL_SOCKET_1, /* socket_id */
4876 -1, /* fdListen */
4877 -1, /* fdCommand */
4878 PHONE_PROCESS, /* processName */
4879 &s_commands_event, /* commands_event */
4880 &s_listen_event, /* listen_event */
4881 processCommandsCallback, /* processCommandsCallback */
4882 NULL /* p_rs */
4883 };
4884
4885#if (SIM_COUNT >= 2)
4886 s_ril_param_socket2 = {
4887 RIL_SOCKET_2, /* socket_id */
4888 -1, /* fdListen */
4889 -1, /* fdCommand */
4890 PHONE_PROCESS, /* processName */
4891 &s_commands_event_socket2, /* commands_event */
4892 &s_listen_event_socket2, /* listen_event */
4893 processCommandsCallback, /* processCommandsCallback */
4894 NULL /* p_rs */
4895 };
4896#endif
4897
4898#if (SIM_COUNT >= 3)
4899 s_ril_param_socket3 = {
4900 RIL_SOCKET_3, /* socket_id */
4901 -1, /* fdListen */
4902 -1, /* fdCommand */
4903 PHONE_PROCESS, /* processName */
4904 &s_commands_event_socket3, /* commands_event */
4905 &s_listen_event_socket3, /* listen_event */
4906 processCommandsCallback, /* processCommandsCallback */
4907 NULL /* p_rs */
4908 };
4909#endif
4910
4911#if (SIM_COUNT >= 4)
4912 s_ril_param_socket4 = {
4913 RIL_SOCKET_4, /* socket_id */
4914 -1, /* fdListen */
4915 -1, /* fdCommand */
4916 PHONE_PROCESS, /* processName */
4917 &s_commands_event_socket4, /* commands_event */
4918 &s_listen_event_socket4, /* listen_event */
4919 processCommandsCallback, /* processCommandsCallback */
4920 NULL /* p_rs */
4921 };
4922#endif
4923
Howard Subd82ef12015-04-12 10:25:05 +02004924
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004925 s_registerCalled = 1;
4926
Howard Sue32dbfd2015-01-07 15:55:57 +08004927 RLOGI("s_registerCalled flag set, %d", s_started);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004928 // Little self-check
4929
4930 for (int i = 0; i < (int)NUM_ELEMS(s_commands); i++) {
4931 assert(i == s_commands[i].requestNumber);
4932 }
4933
Howard Subd82ef12015-04-12 10:25:05 +02004934 for (int i = 0; i < (int)NUM_ELEMS(s_commands_v); i++) {
4935 assert(i + RIL_VENDOR_COMMANDS_OFFSET == s_commands[i].requestNumber);
4936 }
4937
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004938 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses); i++) {
Howard Sue32dbfd2015-01-07 15:55:57 +08004939 assert(i + RIL_UNSOL_RESPONSE_BASE
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004940 == s_unsolResponses[i].requestNumber);
4941 }
4942
Howard Subd82ef12015-04-12 10:25:05 +02004943 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses_v); i++) {
4944 assert(i + RIL_UNSOL_RESPONSE_BASE + RIL_VENDOR_COMMANDS_OFFSET
4945 == s_unsolResponses[i].requestNumber);
4946 }
4947
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004948 // New rild impl calls RIL_startEventLoop() first
4949 // old standalone impl wants it here.
4950
4951 if (s_started == 0) {
4952 RIL_startEventLoop();
4953 }
4954
Howard Sue32dbfd2015-01-07 15:55:57 +08004955 // start listen socket1
4956 startListen(RIL_SOCKET_1, &s_ril_param_socket);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004957
Howard Sue32dbfd2015-01-07 15:55:57 +08004958#if (SIM_COUNT >= 2)
4959 // start listen socket2
4960 startListen(RIL_SOCKET_2, &s_ril_param_socket2);
4961#endif /* (SIM_COUNT == 2) */
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004962
Howard Sue32dbfd2015-01-07 15:55:57 +08004963#if (SIM_COUNT >= 3)
4964 // start listen socket3
4965 startListen(RIL_SOCKET_3, &s_ril_param_socket3);
4966#endif /* (SIM_COUNT == 3) */
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004967
Howard Sue32dbfd2015-01-07 15:55:57 +08004968#if (SIM_COUNT >= 4)
4969 // start listen socket4
4970 startListen(RIL_SOCKET_4, &s_ril_param_socket4);
4971#endif /* (SIM_COUNT == 4) */
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004972
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004973
4974#if 1
4975 // start debug interface socket
4976
Howard Sue32dbfd2015-01-07 15:55:57 +08004977 char *inst = NULL;
4978 if (strlen(RIL_getRilSocketName()) >= strlen(SOCKET_NAME_RIL)) {
4979 inst = RIL_getRilSocketName() + strlen(SOCKET_NAME_RIL);
4980 }
4981
4982 char rildebug[MAX_DEBUG_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL_DEBUG;
4983 if (inst != NULL) {
Andreas Schneider3063dc12015-04-13 23:04:05 +02004984 snprintf(rildebug, sizeof(rildebug), "%s%s", SOCKET_NAME_RIL_DEBUG, inst);
Howard Sue32dbfd2015-01-07 15:55:57 +08004985 }
4986
4987 s_fdDebug = android_get_control_socket(rildebug);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004988 if (s_fdDebug < 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08004989 RLOGE("Failed to get socket : %s errno:%d", rildebug, errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004990 exit(-1);
4991 }
4992
4993 ret = listen(s_fdDebug, 4);
4994
4995 if (ret < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004996 RLOGE("Failed to listen on ril debug socket '%d': %s",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004997 s_fdDebug, strerror(errno));
4998 exit(-1);
4999 }
5000
5001 ril_event_set (&s_debug_event, s_fdDebug, true,
5002 debugCallback, NULL);
5003
5004 rilEventAddWakeup (&s_debug_event);
5005#endif
5006
5007}
5008
Dheeraj Shettycc231012014-07-02 21:27:57 +02005009extern "C" void
5010RIL_register_socket (RIL_RadioFunctions *(*Init)(const struct RIL_Env *, int, char **),RIL_SOCKET_TYPE socketType, int argc, char **argv) {
5011
5012 RIL_RadioFunctions* UimFuncs = NULL;
5013
5014 if(Init) {
5015 UimFuncs = Init(&RilSapSocket::uimRilEnv, argc, argv);
5016
5017 switch(socketType) {
5018 case RIL_SAP_SOCKET:
5019 RilSapSocket::initSapSocket("sap_uim_socket1", UimFuncs);
5020
5021#if (SIM_COUNT >= 2)
5022 RilSapSocket::initSapSocket("sap_uim_socket2", UimFuncs);
5023#endif
5024
5025#if (SIM_COUNT >= 3)
5026 RilSapSocket::initSapSocket("sap_uim_socket3", UimFuncs);
5027#endif
5028
5029#if (SIM_COUNT >= 4)
5030 RilSapSocket::initSapSocket("sap_uim_socket4", UimFuncs);
5031#endif
5032 }
5033 }
5034}
5035
Sanket Padawea7c043d2016-01-27 15:09:12 -08005036// Check and remove RequestInfo if its a response and not just ack sent back
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005037static int
Sanket Padawea7c043d2016-01-27 15:09:12 -08005038checkAndDequeueRequestInfoIfAck(struct RequestInfo *pRI, bool isAck) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005039 int ret = 0;
Howard Sue32dbfd2015-01-07 15:55:57 +08005040 /* Hook for current context
5041 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
5042 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
5043 /* pendingRequestsHook refer to &s_pendingRequests */
5044 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005045
5046 if (pRI == NULL) {
5047 return 0;
5048 }
5049
Howard Sue32dbfd2015-01-07 15:55:57 +08005050#if (SIM_COUNT >= 2)
5051 if (pRI->socket_id == RIL_SOCKET_2) {
5052 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
5053 pendingRequestsHook = &s_pendingRequests_socket2;
5054 }
5055#if (SIM_COUNT >= 3)
5056 if (pRI->socket_id == RIL_SOCKET_3) {
5057 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
5058 pendingRequestsHook = &s_pendingRequests_socket3;
5059 }
5060#endif
5061#if (SIM_COUNT >= 4)
5062 if (pRI->socket_id == RIL_SOCKET_4) {
5063 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
5064 pendingRequestsHook = &s_pendingRequests_socket4;
5065 }
5066#endif
5067#endif
5068 pthread_mutex_lock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005069
Howard Sue32dbfd2015-01-07 15:55:57 +08005070 for(RequestInfo **ppCur = pendingRequestsHook
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005071 ; *ppCur != NULL
5072 ; ppCur = &((*ppCur)->p_next)
5073 ) {
5074 if (pRI == *ppCur) {
5075 ret = 1;
Sanket Padawea7c043d2016-01-27 15:09:12 -08005076 if (isAck) { // Async ack
5077 if (pRI->wasAckSent == 1) {
5078 RLOGD("Ack was already sent for %s", requestToString(pRI->pCI->requestNumber));
5079 } else {
5080 pRI->wasAckSent = 1;
5081 }
5082 } else {
5083 *ppCur = (*ppCur)->p_next;
5084 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005085 break;
5086 }
5087 }
5088
Howard Sue32dbfd2015-01-07 15:55:57 +08005089 pthread_mutex_unlock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005090
5091 return ret;
5092}
5093
Sanket Padawea7c043d2016-01-27 15:09:12 -08005094static int findFd(int socket_id) {
Howard Sue32dbfd2015-01-07 15:55:57 +08005095 int fd = s_ril_param_socket.fdCommand;
Howard Sue32dbfd2015-01-07 15:55:57 +08005096#if (SIM_COUNT >= 2)
5097 if (socket_id == RIL_SOCKET_2) {
5098 fd = s_ril_param_socket2.fdCommand;
5099 }
5100#if (SIM_COUNT >= 3)
Sanket Padawea7c043d2016-01-27 15:09:12 -08005101 if (socket_id == RIL_SOCKET_3) {
5102 fd = s_ril_param_socket3.fdCommand;
5103 }
Howard Sue32dbfd2015-01-07 15:55:57 +08005104#endif
5105#if (SIM_COUNT >= 4)
5106 if (socket_id == RIL_SOCKET_4) {
5107 fd = s_ril_param_socket4.fdCommand;
5108 }
5109#endif
5110#endif
Sanket Padawea7c043d2016-01-27 15:09:12 -08005111 return fd;
5112}
5113
5114extern "C" void
5115RIL_onRequestAck(RIL_Token t) {
5116 RequestInfo *pRI;
5117 int ret, fd;
5118
5119 size_t errorOffset;
5120 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
5121
5122 pRI = (RequestInfo *)t;
5123
5124 if (!checkAndDequeueRequestInfoIfAck(pRI, true)) {
5125 RLOGE ("RIL_onRequestAck: invalid RIL_Token");
5126 return;
5127 }
5128
5129 socket_id = pRI->socket_id;
5130 fd = findFd(socket_id);
5131
5132#if VDBG
5133 RLOGD("Request Ack, %s", rilSocketIdToString(socket_id));
5134#endif
5135
5136 appendPrintBuf("Ack [%04d]< %s", pRI->token, requestToString(pRI->pCI->requestNumber));
5137
5138 if (pRI->cancelled == 0) {
5139 Parcel p;
5140
5141 p.writeInt32 (RESPONSE_SOLICITED_ACK);
5142 p.writeInt32 (pRI->token);
5143
5144 if (fd < 0) {
5145 RLOGD ("RIL onRequestComplete: Command channel closed");
5146 }
5147
5148 sendResponse(p, socket_id);
5149 }
5150}
5151
5152extern "C" void
5153RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) {
5154 RequestInfo *pRI;
5155 int ret;
5156 int fd;
5157 size_t errorOffset;
5158 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
5159
5160 pRI = (RequestInfo *)t;
5161
5162 if (!checkAndDequeueRequestInfoIfAck(pRI, false)) {
5163 RLOGE ("RIL_onRequestComplete: invalid RIL_Token");
5164 return;
5165 }
5166
5167 socket_id = pRI->socket_id;
5168 fd = findFd(socket_id);
5169
Robert Greenwaltbc29c432015-04-29 16:57:39 -07005170#if VDBG
Howard Sue32dbfd2015-01-07 15:55:57 +08005171 RLOGD("RequestComplete, %s", rilSocketIdToString(socket_id));
Robert Greenwaltbc29c432015-04-29 16:57:39 -07005172#endif
Howard Sue32dbfd2015-01-07 15:55:57 +08005173
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005174 if (pRI->local > 0) {
5175 // Locally issued command...void only!
5176 // response does not go back up the command socket
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005177 RLOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005178
5179 goto done;
5180 }
5181
5182 appendPrintBuf("[%04d]< %s",
5183 pRI->token, requestToString(pRI->pCI->requestNumber));
5184
5185 if (pRI->cancelled == 0) {
5186 Parcel p;
5187
Sanket Padawea7c043d2016-01-27 15:09:12 -08005188 if (s_callbacks.version >= 13 && pRI->wasAckSent == 1) {
5189 // If ack was already sent, then this call is an asynchronous response. So we need to
5190 // send id indicating that we expect an ack from RIL.java as we acquire wakelock here.
5191 p.writeInt32 (RESPONSE_SOLICITED_ACK_EXP);
5192 grabPartialWakeLock();
5193 } else {
5194 p.writeInt32 (RESPONSE_SOLICITED);
5195 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005196 p.writeInt32 (pRI->token);
5197 errorOffset = p.dataPosition();
5198
5199 p.writeInt32 (e);
5200
5201 if (response != NULL) {
5202 // there is a response payload, no matter success or not.
5203 ret = pRI->pCI->responseFunction(p, response, responselen);
5204
5205 /* if an error occurred, rewind and mark it */
5206 if (ret != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08005207 RLOGE ("responseFunction error, ret %d", ret);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005208 p.setDataPosition(errorOffset);
5209 p.writeInt32 (ret);
5210 }
5211 }
5212
5213 if (e != RIL_E_SUCCESS) {
5214 appendPrintBuf("%s fails by %s", printBuf, failCauseToString(e));
5215 }
5216
Howard Sue32dbfd2015-01-07 15:55:57 +08005217 if (fd < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005218 RLOGD ("RIL onRequestComplete: Command channel closed");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005219 }
Howard Sue32dbfd2015-01-07 15:55:57 +08005220 sendResponse(p, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005221 }
5222
5223done:
5224 free(pRI);
5225}
5226
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005227static void
5228grabPartialWakeLock() {
Sanket Padawea7c043d2016-01-27 15:09:12 -08005229 if (s_callbacks.version >= 13) {
5230 int ret;
5231 ret = pthread_mutex_lock(&s_wakeLockCountMutex);
5232 assert(ret == 0);
5233 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
Sanket Padawedf3dabe2016-02-29 10:09:26 -08005234
5235 UserCallbackInfo *p_info =
5236 internalRequestTimedCallback(wakeTimeoutCallback, NULL, &TIMEVAL_WAKE_TIMEOUT);
5237 if (p_info == NULL) {
5238 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
5239 } else {
5240 s_wakelock_count++;
5241 if (s_last_wake_timeout_info != NULL) {
5242 s_last_wake_timeout_info->userParam = (void *)1;
5243 }
5244 s_last_wake_timeout_info = p_info;
Sanket Padawea7c043d2016-01-27 15:09:12 -08005245 }
Sanket Padawea7c043d2016-01-27 15:09:12 -08005246 ret = pthread_mutex_unlock(&s_wakeLockCountMutex);
5247 assert(ret == 0);
5248 } else {
5249 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
5250 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005251}
5252
5253static void
5254releaseWakeLock() {
Sanket Padawea7c043d2016-01-27 15:09:12 -08005255 if (s_callbacks.version >= 13) {
5256 int ret;
5257 ret = pthread_mutex_lock(&s_wakeLockCountMutex);
5258 assert(ret == 0);
5259
5260 if (s_wakelock_count > 1) {
5261 s_wakelock_count--;
5262 } else {
5263 s_wakelock_count = 0;
5264 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
5265 if (s_last_wake_timeout_info != NULL) {
5266 s_last_wake_timeout_info->userParam = (void *)1;
5267 }
5268 }
5269
5270 ret = pthread_mutex_unlock(&s_wakeLockCountMutex);
5271 assert(ret == 0);
5272 } else {
5273 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
5274 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005275}
5276
5277/**
5278 * Timer callback to put us back to sleep before the default timeout
5279 */
5280static void
5281wakeTimeoutCallback (void *param) {
5282 // We're using "param != NULL" as a cancellation mechanism
Sanket Padawea7c043d2016-01-27 15:09:12 -08005283 if (s_callbacks.version >= 13) {
5284 if (param == NULL) {
5285 int ret;
5286 ret = pthread_mutex_lock(&s_wakeLockCountMutex);
5287 assert(ret == 0);
5288 s_wakelock_count = 0;
5289 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
5290 ret = pthread_mutex_unlock(&s_wakeLockCountMutex);
5291 assert(ret == 0);
5292 }
5293 } else {
5294 if (param == NULL) {
5295 releaseWakeLock();
5296 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005297 }
5298}
5299
5300static int
5301decodeVoiceRadioTechnology (RIL_RadioState radioState) {
5302 switch (radioState) {
5303 case RADIO_STATE_SIM_NOT_READY:
5304 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
5305 case RADIO_STATE_SIM_READY:
5306 return RADIO_TECH_UMTS;
5307
5308 case RADIO_STATE_RUIM_NOT_READY:
5309 case RADIO_STATE_RUIM_READY:
5310 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
5311 case RADIO_STATE_NV_NOT_READY:
5312 case RADIO_STATE_NV_READY:
5313 return RADIO_TECH_1xRTT;
5314
5315 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005316 RLOGD("decodeVoiceRadioTechnology: Invoked with incorrect RadioState");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005317 return -1;
5318 }
5319}
5320
5321static int
5322decodeCdmaSubscriptionSource (RIL_RadioState radioState) {
5323 switch (radioState) {
5324 case RADIO_STATE_SIM_NOT_READY:
5325 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
5326 case RADIO_STATE_SIM_READY:
5327 case RADIO_STATE_RUIM_NOT_READY:
5328 case RADIO_STATE_RUIM_READY:
5329 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
5330 return CDMA_SUBSCRIPTION_SOURCE_RUIM_SIM;
5331
5332 case RADIO_STATE_NV_NOT_READY:
5333 case RADIO_STATE_NV_READY:
5334 return CDMA_SUBSCRIPTION_SOURCE_NV;
5335
5336 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005337 RLOGD("decodeCdmaSubscriptionSource: Invoked with incorrect RadioState");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005338 return -1;
5339 }
5340}
5341
5342static int
5343decodeSimStatus (RIL_RadioState radioState) {
5344 switch (radioState) {
5345 case RADIO_STATE_SIM_NOT_READY:
5346 case RADIO_STATE_RUIM_NOT_READY:
5347 case RADIO_STATE_NV_NOT_READY:
5348 case RADIO_STATE_NV_READY:
5349 return -1;
5350 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
5351 case RADIO_STATE_SIM_READY:
5352 case RADIO_STATE_RUIM_READY:
5353 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
5354 return radioState;
5355 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005356 RLOGD("decodeSimStatus: Invoked with incorrect RadioState");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005357 return -1;
5358 }
5359}
5360
5361static bool is3gpp2(int radioTech) {
5362 switch (radioTech) {
5363 case RADIO_TECH_IS95A:
5364 case RADIO_TECH_IS95B:
5365 case RADIO_TECH_1xRTT:
5366 case RADIO_TECH_EVDO_0:
5367 case RADIO_TECH_EVDO_A:
5368 case RADIO_TECH_EVDO_B:
5369 case RADIO_TECH_EHRPD:
5370 return true;
5371 default:
5372 return false;
5373 }
5374}
5375
5376/* If RIL sends SIM states or RUIM states, store the voice radio
5377 * technology and subscription source information so that they can be
5378 * returned when telephony framework requests them
5379 */
5380static RIL_RadioState
Howard Subd82ef12015-04-12 10:25:05 +02005381processRadioState(RIL_RadioState newRadioState, RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005382
5383 if((newRadioState > RADIO_STATE_UNAVAILABLE) && (newRadioState < RADIO_STATE_ON)) {
5384 int newVoiceRadioTech;
5385 int newCdmaSubscriptionSource;
5386 int newSimStatus;
5387
5388 /* This is old RIL. Decode Subscription source and Voice Radio Technology
5389 from Radio State and send change notifications if there has been a change */
5390 newVoiceRadioTech = decodeVoiceRadioTechnology(newRadioState);
5391 if(newVoiceRadioTech != voiceRadioTech) {
5392 voiceRadioTech = newVoiceRadioTech;
Howard Sue32dbfd2015-01-07 15:55:57 +08005393 RIL_UNSOL_RESPONSE(RIL_UNSOL_VOICE_RADIO_TECH_CHANGED,
5394 &voiceRadioTech, sizeof(voiceRadioTech), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005395 }
5396 if(is3gpp2(newVoiceRadioTech)) {
5397 newCdmaSubscriptionSource = decodeCdmaSubscriptionSource(newRadioState);
5398 if(newCdmaSubscriptionSource != cdmaSubscriptionSource) {
5399 cdmaSubscriptionSource = newCdmaSubscriptionSource;
Howard Sue32dbfd2015-01-07 15:55:57 +08005400 RIL_UNSOL_RESPONSE(RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED,
5401 &cdmaSubscriptionSource, sizeof(cdmaSubscriptionSource), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005402 }
5403 }
5404 newSimStatus = decodeSimStatus(newRadioState);
5405 if(newSimStatus != simRuimStatus) {
5406 simRuimStatus = newSimStatus;
Howard Sue32dbfd2015-01-07 15:55:57 +08005407 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005408 }
5409
5410 /* Send RADIO_ON to telephony */
5411 newRadioState = RADIO_STATE_ON;
5412 }
5413
5414 return newRadioState;
5415}
5416
Howard Subd82ef12015-04-12 10:25:05 +02005417
Howard Sue32dbfd2015-01-07 15:55:57 +08005418#if defined(ANDROID_MULTI_SIM)
5419extern "C"
Andreas Schneider47b2d962015-04-13 22:54:49 +02005420void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Howard Sue32dbfd2015-01-07 15:55:57 +08005421 size_t datalen, RIL_SOCKET_ID socket_id)
5422#else
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005423extern "C"
Andreas Schneider47b2d962015-04-13 22:54:49 +02005424void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005425 size_t datalen)
Howard Sue32dbfd2015-01-07 15:55:57 +08005426#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005427{
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005428 int ret;
5429 int64_t timeReceived = 0;
5430 bool shouldScheduleTimeout = false;
5431 RIL_RadioState newState;
Howard Sue32dbfd2015-01-07 15:55:57 +08005432 RIL_SOCKET_ID soc_id = RIL_SOCKET_1;
Howard Subd82ef12015-04-12 10:25:05 +02005433 UnsolResponseInfo *pRI = NULL;
Howard Sue32dbfd2015-01-07 15:55:57 +08005434
5435#if defined(ANDROID_MULTI_SIM)
5436 soc_id = socket_id;
5437#endif
5438
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005439
5440 if (s_registerCalled == 0) {
5441 // Ignore RIL_onUnsolicitedResponse before RIL_register
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005442 RLOGW("RIL_onUnsolicitedResponse called before RIL_register");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005443 return;
5444 }
Howard Sue32dbfd2015-01-07 15:55:57 +08005445
Howard Subd82ef12015-04-12 10:25:05 +02005446 /* Hack to include Samsung responses */
5447 if (unsolResponse > RIL_VENDOR_COMMANDS_OFFSET + RIL_UNSOL_RESPONSE_BASE) {
5448 int index = unsolResponse - RIL_VENDOR_COMMANDS_OFFSET - RIL_UNSOL_RESPONSE_BASE;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005449
Howard Subd82ef12015-04-12 10:25:05 +02005450 RLOGD("SAMSUNG: unsolResponse=%d, unsolResponseIndex=%d", unsolResponse, index);
5451
5452 if (index < (int32_t)NUM_ELEMS(s_unsolResponses_v))
5453 pRI = &s_unsolResponses_v[index];
5454 } else {
5455 int index = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
5456 if (index < (int32_t)NUM_ELEMS(s_unsolResponses))
5457 pRI = &s_unsolResponses[index];
5458 }
5459
5460 if (pRI == NULL || pRI->responseFunction == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005461 RLOGE("unsupported unsolicited response code %d", unsolResponse);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005462 return;
5463 }
5464
5465 // Grab a wake lock if needed for this reponse,
5466 // as we exit we'll either release it immediately
5467 // or set a timer to release it later.
Howard Subd82ef12015-04-12 10:25:05 +02005468 switch (pRI->wakeType) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005469 case WAKE_PARTIAL:
5470 grabPartialWakeLock();
5471 shouldScheduleTimeout = true;
5472 break;
5473
5474 case DONT_WAKE:
5475 default:
5476 // No wake lock is grabed so don't set timeout
5477 shouldScheduleTimeout = false;
5478 break;
5479 }
5480
5481 // Mark the time this was received, doing this
5482 // after grabing the wakelock incase getting
5483 // the elapsedRealTime might cause us to goto
5484 // sleep.
5485 if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
5486 timeReceived = elapsedRealtime();
5487 }
5488
5489 appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
5490
5491 Parcel p;
Sanket Padawe9f972082016-02-03 11:46:02 -08005492 if (s_callbacks.version >= 13
5493 && pRI->wakeType == WAKE_PARTIAL) {
5494 p.writeInt32 (RESPONSE_UNSOLICITED_ACK_EXP);
5495 } else {
5496 p.writeInt32 (RESPONSE_UNSOLICITED);
5497 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005498 p.writeInt32 (unsolResponse);
5499
Howard Subd82ef12015-04-12 10:25:05 +02005500 ret = pRI->responseFunction(p, const_cast<void*>(data), datalen);
5501
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005502 if (ret != 0) {
5503 // Problem with the response. Don't continue;
5504 goto error_exit;
5505 }
5506
5507 // some things get more payload
5508 switch(unsolResponse) {
5509 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
Howard Sue32dbfd2015-01-07 15:55:57 +08005510 newState = processRadioState(CALL_ONSTATEREQUEST(soc_id), soc_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005511 p.writeInt32(newState);
5512 appendPrintBuf("%s {%s}", printBuf,
Howard Sue32dbfd2015-01-07 15:55:57 +08005513 radioStateToString(CALL_ONSTATEREQUEST(soc_id)));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005514 break;
5515
5516
5517 case RIL_UNSOL_NITZ_TIME_RECEIVED:
5518 // Store the time that this was received so the
5519 // handler of this message can account for
5520 // the time it takes to arrive and process. In
5521 // particular the system has been known to sleep
5522 // before this message can be processed.
5523 p.writeInt64(timeReceived);
5524 break;
5525 }
5526
Sanket Padawedf3dabe2016-02-29 10:09:26 -08005527 if (s_callbacks.version < 13) {
5528 if (shouldScheduleTimeout) {
5529 UserCallbackInfo *p_info = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
5530 &TIMEVAL_WAKE_TIMEOUT);
5531
5532 if (p_info == NULL) {
5533 goto error_exit;
5534 } else {
5535 // Cancel the previous request
5536 if (s_last_wake_timeout_info != NULL) {
5537 s_last_wake_timeout_info->userParam = (void *)1;
5538 }
5539 s_last_wake_timeout_info = p_info;
5540 }
5541 }
5542 }
5543
Robert Greenwaltbc29c432015-04-29 16:57:39 -07005544#if VDBG
Howard Sue32dbfd2015-01-07 15:55:57 +08005545 RLOGI("%s UNSOLICITED: %s length:%d", rilSocketIdToString(soc_id), requestToString(unsolResponse), p.dataSize());
Robert Greenwaltbc29c432015-04-29 16:57:39 -07005546#endif
Howard Sue32dbfd2015-01-07 15:55:57 +08005547 ret = sendResponse(p, soc_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005548 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
5549
5550 // Unfortunately, NITZ time is not poll/update like everything
5551 // else in the system. So, if the upstream client isn't connected,
5552 // keep a copy of the last NITZ response (with receive time noted
5553 // above) around so we can deliver it when it is connected
5554
5555 if (s_lastNITZTimeData != NULL) {
5556 free (s_lastNITZTimeData);
5557 s_lastNITZTimeData = NULL;
5558 }
5559
5560 s_lastNITZTimeData = malloc(p.dataSize());
Sanket Padawedf3dabe2016-02-29 10:09:26 -08005561 if (s_lastNITZTimeData == NULL) {
5562 RLOGE("Memory allocation failed in RIL_onUnsolicitedResponse");
5563 goto error_exit;
5564 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005565 s_lastNITZTimeDataSize = p.dataSize();
5566 memcpy(s_lastNITZTimeData, p.data(), p.dataSize());
5567 }
5568
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005569 // Normal exit
5570 return;
5571
5572error_exit:
5573 if (shouldScheduleTimeout) {
5574 releaseWakeLock();
5575 }
5576}
5577
5578/** FIXME generalize this if you track UserCAllbackInfo, clear it
5579 when the callback occurs
5580*/
5581static UserCallbackInfo *
5582internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
5583 const struct timeval *relativeTime)
5584{
5585 struct timeval myRelativeTime;
5586 UserCallbackInfo *p_info;
5587
5588 p_info = (UserCallbackInfo *) malloc (sizeof(UserCallbackInfo));
Sanket Padawedf3dabe2016-02-29 10:09:26 -08005589 if (p_info == NULL) {
5590 RLOGE("Memory allocation failed in internalRequestTimedCallback");
5591 return p_info;
5592
5593 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005594
5595 p_info->p_callback = callback;
5596 p_info->userParam = param;
5597
5598 if (relativeTime == NULL) {
5599 /* treat null parameter as a 0 relative time */
5600 memset (&myRelativeTime, 0, sizeof(myRelativeTime));
5601 } else {
5602 /* FIXME I think event_add's tv param is really const anyway */
5603 memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
5604 }
5605
5606 ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
5607
5608 ril_timer_add(&(p_info->event), &myRelativeTime);
5609
5610 triggerEvLoop();
5611 return p_info;
5612}
5613
5614
5615extern "C" void
5616RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
5617 const struct timeval *relativeTime) {
5618 internalRequestTimedCallback (callback, param, relativeTime);
5619}
5620
5621const char *
5622failCauseToString(RIL_Errno e) {
5623 switch(e) {
5624 case RIL_E_SUCCESS: return "E_SUCCESS";
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005625 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RADIO_NOT_AVAILABLE";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005626 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
5627 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
5628 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
5629 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
5630 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
5631 case RIL_E_CANCELLED: return "E_CANCELLED";
5632 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
5633 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
5634 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
5635 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
5636 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
5637#ifdef FEATURE_MULTIMODE_ANDROID
5638 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
5639 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
5640#endif
Sanket Padawe6049dec2016-02-08 14:28:59 -08005641 case RIL_E_FDN_CHECK_FAILURE: return "E_FDN_CHECK_FAILURE";
5642 case RIL_E_MISSING_RESOURCE: return "E_MISSING_RESOURCE";
5643 case RIL_E_NO_SUCH_ELEMENT: return "E_NO_SUCH_ELEMENT";
5644 case RIL_E_DIAL_MODIFIED_TO_USSD: return "E_DIAL_MODIFIED_TO_USSD";
5645 case RIL_E_DIAL_MODIFIED_TO_SS: return "E_DIAL_MODIFIED_TO_SS";
5646 case RIL_E_DIAL_MODIFIED_TO_DIAL: return "E_DIAL_MODIFIED_TO_DIAL";
5647 case RIL_E_USSD_MODIFIED_TO_DIAL: return "E_USSD_MODIFIED_TO_DIAL";
5648 case RIL_E_USSD_MODIFIED_TO_SS: return "E_USSD_MODIFIED_TO_SS";
5649 case RIL_E_USSD_MODIFIED_TO_USSD: return "E_USSD_MODIFIED_TO_USSD";
5650 case RIL_E_SS_MODIFIED_TO_DIAL: return "E_SS_MODIFIED_TO_DIAL";
5651 case RIL_E_SS_MODIFIED_TO_USSD: return "E_SS_MODIFIED_TO_USSD";
5652 case RIL_E_SUBSCRIPTION_NOT_SUPPORTED: return "E_SUBSCRIPTION_NOT_SUPPORTED";
5653 case RIL_E_SS_MODIFIED_TO_SS: return "E_SS_MODIFIED_TO_SS";
5654 case RIL_E_LCE_NOT_SUPPORTED: return "E_LCE_NOT_SUPPORTED";
5655 case RIL_E_NO_MEMORY: return "E_NO_MEMORY";
5656 case RIL_E_INTERNAL_ERR: return "E_INTERNAL_ERR";
5657 case RIL_E_SYSTEM_ERR: return "E_SYSTEM_ERR";
5658 case RIL_E_MODEM_ERR: return "E_MODEM_ERR";
5659 case RIL_E_INVALID_STATE: return "E_INVALID_STATE";
5660 case RIL_E_NO_RESOURCES: return "E_NO_RESOURCES";
5661 case RIL_E_SIM_ERR: return "E_SIM_ERR";
5662 case RIL_E_INVALID_ARGUMENTS: return "E_INVALID_ARGUMENTS";
5663 case RIL_E_INVALID_SIM_STATE: return "E_INVALID_SIM_STATE";
5664 case RIL_E_INVALID_MODEM_STATE: return "E_INVALID_MODEM_STATE";
5665 case RIL_E_INVALID_CALL_ID: return "E_INVALID_CALL_ID";
5666 case RIL_E_NO_SMS_TO_ACK: return "E_NO_SMS_TO_ACK";
5667 case RIL_E_NETWORK_ERR: return "E_NETWORK_ERR";
5668 case RIL_E_REQUEST_RATE_LIMITED: return "E_REQUEST_RATE_LIMITED";
Sanket Padawedb5d1e02016-02-09 09:56:31 -08005669 case RIL_E_OEM_ERROR_1: return "E_OEM_ERROR_1";
5670 case RIL_E_OEM_ERROR_2: return "E_OEM_ERROR_2";
5671 case RIL_E_OEM_ERROR_3: return "E_OEM_ERROR_3";
5672 case RIL_E_OEM_ERROR_4: return "E_OEM_ERROR_4";
5673 case RIL_E_OEM_ERROR_5: return "E_OEM_ERROR_5";
5674 case RIL_E_OEM_ERROR_6: return "E_OEM_ERROR_6";
5675 case RIL_E_OEM_ERROR_7: return "E_OEM_ERROR_7";
5676 case RIL_E_OEM_ERROR_8: return "E_OEM_ERROR_8";
5677 case RIL_E_OEM_ERROR_9: return "E_OEM_ERROR_9";
5678 case RIL_E_OEM_ERROR_10: return "E_OEM_ERROR_10";
5679 case RIL_E_OEM_ERROR_11: return "E_OEM_ERROR_11";
5680 case RIL_E_OEM_ERROR_12: return "E_OEM_ERROR_12";
5681 case RIL_E_OEM_ERROR_13: return "E_OEM_ERROR_13";
5682 case RIL_E_OEM_ERROR_14: return "E_OEM_ERROR_14";
5683 case RIL_E_OEM_ERROR_15: return "E_OEM_ERROR_15";
5684 case RIL_E_OEM_ERROR_16: return "E_OEM_ERROR_16";
5685 case RIL_E_OEM_ERROR_17: return "E_OEM_ERROR_17";
5686 case RIL_E_OEM_ERROR_18: return "E_OEM_ERROR_18";
5687 case RIL_E_OEM_ERROR_19: return "E_OEM_ERROR_19";
5688 case RIL_E_OEM_ERROR_20: return "E_OEM_ERROR_20";
5689 case RIL_E_OEM_ERROR_21: return "E_OEM_ERROR_21";
5690 case RIL_E_OEM_ERROR_22: return "E_OEM_ERROR_22";
5691 case RIL_E_OEM_ERROR_23: return "E_OEM_ERROR_23";
5692 case RIL_E_OEM_ERROR_24: return "E_OEM_ERROR_24";
5693 case RIL_E_OEM_ERROR_25: return "E_OEM_ERROR_25";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005694 default: return "<unknown error>";
5695 }
5696}
5697
5698const char *
5699radioStateToString(RIL_RadioState s) {
5700 switch(s) {
5701 case RADIO_STATE_OFF: return "RADIO_OFF";
5702 case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
5703 case RADIO_STATE_SIM_NOT_READY: return "RADIO_SIM_NOT_READY";
5704 case RADIO_STATE_SIM_LOCKED_OR_ABSENT: return "RADIO_SIM_LOCKED_OR_ABSENT";
5705 case RADIO_STATE_SIM_READY: return "RADIO_SIM_READY";
5706 case RADIO_STATE_RUIM_NOT_READY:return"RADIO_RUIM_NOT_READY";
5707 case RADIO_STATE_RUIM_READY:return"RADIO_RUIM_READY";
5708 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:return"RADIO_RUIM_LOCKED_OR_ABSENT";
5709 case RADIO_STATE_NV_NOT_READY:return"RADIO_NV_NOT_READY";
5710 case RADIO_STATE_NV_READY:return"RADIO_NV_READY";
5711 case RADIO_STATE_ON:return"RADIO_ON";
5712 default: return "<unknown state>";
5713 }
5714}
5715
5716const char *
5717callStateToString(RIL_CallState s) {
5718 switch(s) {
5719 case RIL_CALL_ACTIVE : return "ACTIVE";
5720 case RIL_CALL_HOLDING: return "HOLDING";
5721 case RIL_CALL_DIALING: return "DIALING";
5722 case RIL_CALL_ALERTING: return "ALERTING";
5723 case RIL_CALL_INCOMING: return "INCOMING";
5724 case RIL_CALL_WAITING: return "WAITING";
5725 default: return "<unknown state>";
5726 }
5727}
5728
5729const char *
5730requestToString(int request) {
5731/*
5732 cat libs/telephony/ril_commands.h \
5733 | egrep "^ *{RIL_" \
5734 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
5735
5736
5737 cat libs/telephony/ril_unsol_commands.h \
5738 | egrep "^ *{RIL_" \
5739 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
5740
5741*/
5742 switch(request) {
5743 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
5744 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
5745 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
5746 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
5747 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
5748 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
5749 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
5750 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
5751 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
5752 case RIL_REQUEST_DIAL: return "DIAL";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005753 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
5754 case RIL_REQUEST_HANGUP: return "HANGUP";
5755 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
5756 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
5757 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
5758 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
5759 case RIL_REQUEST_UDUB: return "UDUB";
5760 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
5761 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
5762 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
5763 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
5764 case RIL_REQUEST_OPERATOR: return "OPERATOR";
5765 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
5766 case RIL_REQUEST_DTMF: return "DTMF";
5767 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
5768 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
5769 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
5770 case RIL_REQUEST_SIM_IO: return "SIM_IO";
5771 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
5772 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
5773 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
5774 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
5775 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
5776 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
5777 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
5778 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
5779 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
5780 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
5781 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
5782 case RIL_REQUEST_ANSWER: return "ANSWER";
5783 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
5784 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
5785 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
5786 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
5787 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
5788 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
5789 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
5790 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";
5791 case RIL_REQUEST_DTMF_START: return "DTMF_START";
5792 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
5793 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
5794 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
5795 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
5796 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
5797 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
5798 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
5799 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
5800 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
5801 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
5802 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
5803 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
5804 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
5805 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
5806 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
5807 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
5808 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
5809 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
5810 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
5811 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
5812 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
5813 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
5814 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
5815 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005816 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE:return"CDMA_SET_SUBSCRIPTION_SOURCE";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005817 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"CDMA_SET_ROAMING_PREFERENCE";
5818 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"CDMA_QUERY_ROAMING_PREFERENCE";
5819 case RIL_REQUEST_SET_TTY_MODE:return"SET_TTY_MODE";
5820 case RIL_REQUEST_QUERY_TTY_MODE:return"QUERY_TTY_MODE";
5821 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
5822 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
5823 case RIL_REQUEST_CDMA_FLASH:return"CDMA_FLASH";
5824 case RIL_REQUEST_CDMA_BURST_DTMF:return"CDMA_BURST_DTMF";
5825 case RIL_REQUEST_CDMA_SEND_SMS:return"CDMA_SEND_SMS";
5826 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:return"CDMA_SMS_ACKNOWLEDGE";
5827 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG:return"GSM_GET_BROADCAST_SMS_CONFIG";
5828 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG:return"GSM_SET_BROADCAST_SMS_CONFIG";
5829 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG:return "CDMA_GET_BROADCAST_SMS_CONFIG";
5830 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG:return "CDMA_SET_BROADCAST_SMS_CONFIG";
5831 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION:return "CDMA_SMS_BROADCAST_ACTIVATION";
Ethan Chend6e30652013-08-04 22:49:56 -07005832 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return"CDMA_VALIDATE_AND_WRITE_AKEY";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005833 case RIL_REQUEST_CDMA_SUBSCRIPTION: return"CDMA_SUBSCRIPTION";
5834 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
5835 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
5836 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
5837 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
5838 case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
5839 case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
5840 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
5841 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
5842 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
5843 case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
5844 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
5845 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
5846 case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
Ajay Nambie63b4f62011-11-15 11:19:30 -08005847 case RIL_REQUEST_WRITE_SMS_TO_SIM: return "WRITE_SMS_TO_SIM";
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005848 case RIL_REQUEST_GET_CELL_INFO_LIST: return"GET_CELL_INFO_LIST";
5849 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return"SET_UNSOL_CELL_INFO_LIST_RATE";
Andrew Jiangca4a9a02014-01-18 18:04:08 -05005850 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "RIL_REQUEST_SET_INITIAL_ATTACH_APN";
5851 case RIL_REQUEST_IMS_REGISTRATION_STATE: return "IMS_REGISTRATION_STATE";
5852 case RIL_REQUEST_IMS_SEND_SMS: return "IMS_SEND_SMS";
Howard Sue32dbfd2015-01-07 15:55:57 +08005853 case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "SIM_TRANSMIT_APDU_BASIC";
5854 case RIL_REQUEST_SIM_OPEN_CHANNEL: return "SIM_OPEN_CHANNEL";
5855 case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "SIM_CLOSE_CHANNEL";
5856 case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "SIM_TRANSMIT_APDU_CHANNEL";
Howard Subd82ef12015-04-12 10:25:05 +02005857 case RIL_REQUEST_GET_RADIO_CAPABILITY: return "RIL_REQUEST_GET_RADIO_CAPABILITY";
5858 case RIL_REQUEST_SET_RADIO_CAPABILITY: return "RIL_REQUEST_SET_RADIO_CAPABILITY";
Howard Sue32dbfd2015-01-07 15:55:57 +08005859 case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "SET_UICC_SUBSCRIPTION";
5860 case RIL_REQUEST_ALLOW_DATA: return "ALLOW_DATA";
5861 case RIL_REQUEST_GET_HARDWARE_CONFIG: return "GET_HARDWARE_CONFIG";
5862 case RIL_REQUEST_SIM_AUTHENTICATION: return "SIM_AUTHENTICATION";
5863 case RIL_REQUEST_GET_DC_RT_INFO: return "GET_DC_RT_INFO";
5864 case RIL_REQUEST_SET_DC_RT_INFO_RATE: return "SET_DC_RT_INFO_RATE";
5865 case RIL_REQUEST_SET_DATA_PROFILE: return "SET_DATA_PROFILE";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005866 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
5867 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
5868 case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED";
5869 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
5870 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
5871 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
5872 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
5873 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)";
5874 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
5875 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
Howard Subd82ef12015-04-12 10:25:05 +02005876 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
5877 case RIL_UNSOL_SUPP_SVC_NOTIFICATION: return "UNSOL_SUPP_SVC_NOTIFICATION";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005878 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
5879 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
5880 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
5881 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
5882 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL";
5883 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005884 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
5885 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
5886 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_NEW_CDMA_SMS";
5887 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_NEW_BROADCAST_SMS";
5888 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
5889 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
5890 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
5891 case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
5892 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
5893 case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
5894 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
5895 case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
5896 case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
5897 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
5898 case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
5899 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
5900 case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
5901 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
Ethan Chend6e30652013-08-04 22:49:56 -07005902 case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
Andrew Jiangca4a9a02014-01-18 18:04:08 -05005903 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "RESPONSE_IMS_NETWORK_STATE_CHANGED";
Howard Sue32dbfd2015-01-07 15:55:57 +08005904 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return "UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED";
5905 case RIL_UNSOL_SRVCC_STATE_NOTIFY: return "UNSOL_SRVCC_STATE_NOTIFY";
5906 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return "HARDWARE_CONFIG_CHANGED";
5907 case RIL_UNSOL_DC_RT_INFO_CHANGED: return "UNSOL_DC_RT_INFO_CHANGED";
Howard Subd82ef12015-04-12 10:25:05 +02005908 case RIL_UNSOL_RADIO_CAPABILITY: return "UNSOL_RADIO_CAPABILITY";
5909 case RIL_UNSOL_ON_SS: return "UNSOL_ON_SS";
5910 case RIL_UNSOL_STK_CC_ALPHA_NOTIFY: return "UNSOL_STK_CC_ALPHA_NOTIFY";
Howard Sue32dbfd2015-01-07 15:55:57 +08005911 case RIL_REQUEST_SHUTDOWN: return "SHUTDOWN";
Sanket Padawea7c043d2016-01-27 15:09:12 -08005912 case RIL_RESPONSE_ACKNOWLEDGEMENT: return "RIL_RESPONSE_ACKNOWLEDGEMENT";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005913 default: return "<unknown request>";
5914 }
5915}
5916
Howard Sue32dbfd2015-01-07 15:55:57 +08005917const char *
5918rilSocketIdToString(RIL_SOCKET_ID socket_id)
5919{
5920 switch(socket_id) {
5921 case RIL_SOCKET_1:
5922 return "RIL_SOCKET_1";
5923#if (SIM_COUNT >= 2)
5924 case RIL_SOCKET_2:
5925 return "RIL_SOCKET_2";
5926#endif
5927#if (SIM_COUNT >= 3)
5928 case RIL_SOCKET_3:
5929 return "RIL_SOCKET_3";
5930#endif
5931#if (SIM_COUNT >= 4)
5932 case RIL_SOCKET_4:
5933 return "RIL_SOCKET_4";
5934#endif
5935 default:
5936 return "not a valid RIL";
5937 }
5938}
5939
Sanket Padawe9343e872016-01-11 12:45:43 -08005940/*
5941 * Returns true for a debuggable build.
5942 */
5943static bool isDebuggable() {
5944 char debuggable[PROP_VALUE_MAX];
5945 property_get("ro.debuggable", debuggable, "0");
5946 if (strcmp(debuggable, "1") == 0) {
5947 return true;
5948 }
5949 return false;
5950}
5951
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005952} /* namespace android */
Dheeraj Shettycc231012014-07-02 21:27:57 +02005953
5954void rilEventAddWakeup_helper(struct ril_event *ev) {
5955 android::rilEventAddWakeup(ev);
5956}
5957
5958void listenCallback_helper(int fd, short flags, void *param) {
5959 android::listenCallback(fd, flags, param);
5960}
5961
5962int blockingWrite_helper(int fd, void *buffer, size_t len) {
5963 return android::blockingWrite(fd, buffer, len);
5964}