blob: a2d1e4e5390d15e3c8cfc11133030d7c282dae76 [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>
Daniel Hillenbrand601dc852013-07-07 10:06:59 +020045#include <sys/un.h>
46#include <assert.h>
47#include <netinet/in.h>
48#include <cutils/properties.h>
Dheeraj Shettycc231012014-07-02 21:27:57 +020049#include <RilSapSocket.h>
Daniel Hillenbrand601dc852013-07-07 10:06:59 +020050
Dheeraj Shettycc231012014-07-02 21:27:57 +020051extern "C" void
52RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen);
Sanket Padawea7c043d2016-01-27 15:09:12 -080053
54extern "C" void
55RIL_onRequestAck(RIL_Token t);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +020056namespace android {
57
58#define PHONE_PROCESS "radio"
Dheeraj Shettycc231012014-07-02 21:27:57 +020059#define BLUETOOTH_PROCESS "bluetooth"
Daniel Hillenbrand601dc852013-07-07 10:06:59 +020060
61#define SOCKET_NAME_RIL "rild"
Howard Sue32dbfd2015-01-07 15:55:57 +080062#define SOCKET2_NAME_RIL "rild2"
63#define SOCKET3_NAME_RIL "rild3"
64#define SOCKET4_NAME_RIL "rild4"
65
Daniel Hillenbrand601dc852013-07-07 10:06:59 +020066#define SOCKET_NAME_RIL_DEBUG "rild-debug"
67
68#define ANDROID_WAKE_LOCK_NAME "radio-interface"
69
Nathan Haroldd6306fa2015-07-28 14:54:58 -070070#define ANDROID_WAKE_LOCK_SECS 0
71#define ANDROID_WAKE_LOCK_USECS 200000
Daniel Hillenbrand601dc852013-07-07 10:06:59 +020072
73#define PROPERTY_RIL_IMPL "gsm.version.ril-impl"
74
75// match with constant in RIL.java
76#define MAX_COMMAND_BYTES (8 * 1024)
77
78// Basically: memset buffers that the client library
79// shouldn't be using anymore in an attempt to find
80// memory usage issues sooner.
81#define MEMSET_FREED 1
82
83#define NUM_ELEMS(a) (sizeof (a) / sizeof (a)[0])
84
85#define MIN(a,b) ((a)<(b) ? (a) : (b))
86
87/* Constants for response types */
88#define RESPONSE_SOLICITED 0
89#define RESPONSE_UNSOLICITED 1
Sanket Padawea7c043d2016-01-27 15:09:12 -080090#define RESPONSE_SOLICITED_ACK 2
91#define RESPONSE_SOLICITED_ACK_EXP 3
Sanket Padawe9f972082016-02-03 11:46:02 -080092#define RESPONSE_UNSOLICITED_ACK_EXP 4
Daniel Hillenbrand601dc852013-07-07 10:06:59 +020093
94/* Negative values for private RIL errno's */
95#define RIL_ERRNO_INVALID_RESPONSE -1
Sanket Padawedf3dabe2016-02-29 10:09:26 -080096#define RIL_ERRNO_NO_MEMORY -12
Daniel Hillenbrand601dc852013-07-07 10:06:59 +020097
98// request, response, and unsolicited msg print macro
99#define PRINTBUF_SIZE 8096
100
Robert Greenwaltbc29c432015-04-29 16:57:39 -0700101// Enable verbose logging
102#define VDBG 0
103
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200104// Enable RILC log
105#define RILC_LOG 0
106
107#if RILC_LOG
108 #define startRequest sprintf(printBuf, "(")
109 #define closeRequest sprintf(printBuf, "%s)", printBuf)
Christopher N. Hesse65084862017-02-07 22:21:27 +0100110 #define printRequest(token, req) \
111 RLOGD("[%04d]> %s %s", token, requestToString(req), printBuf)
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200112
113 #define startResponse sprintf(printBuf, "%s {", printBuf)
114 #define closeResponse sprintf(printBuf, "%s}", printBuf)
XpLoDWilDba5c6a32013-07-27 21:12:19 +0200115 #define printResponse RLOGD("%s", printBuf)
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200116
117 #define clearPrintBuf printBuf[0] = 0
118 #define removeLastChar printBuf[strlen(printBuf)-1] = 0
Ajay Nambi323c8822015-08-05 14:53:50 +0530119 #define appendPrintBuf(x...) snprintf(printBuf, PRINTBUF_SIZE, x)
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200120#else
121 #define startRequest
122 #define closeRequest
123 #define printRequest(token, req)
124 #define startResponse
125 #define closeResponse
126 #define printResponse
127 #define clearPrintBuf
128 #define removeLastChar
129 #define appendPrintBuf(x...)
130#endif
131
132enum WakeType {DONT_WAKE, WAKE_PARTIAL};
133
134typedef struct {
135 int requestNumber;
136 void (*dispatchFunction) (Parcel &p, struct RequestInfo *pRI);
137 int(*responseFunction) (Parcel &p, void *response, size_t responselen);
138} CommandInfo;
139
140typedef struct {
141 int requestNumber;
142 int (*responseFunction) (Parcel &p, void *response, size_t responselen);
143 WakeType wakeType;
144} UnsolResponseInfo;
145
146typedef struct RequestInfo {
147 int32_t token; //this is not RIL_Token
148 CommandInfo *pCI;
149 struct RequestInfo *p_next;
150 char cancelled;
151 char local; // responses to local commands do not go back to command process
Howard Sue32dbfd2015-01-07 15:55:57 +0800152 RIL_SOCKET_ID socket_id;
Sanket Padawea7c043d2016-01-27 15:09:12 -0800153 int wasAckSent; // Indicates whether an ack was sent earlier
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200154} RequestInfo;
155
156typedef struct UserCallbackInfo {
157 RIL_TimedCallback p_callback;
158 void *userParam;
159 struct ril_event event;
160 struct UserCallbackInfo *p_next;
161} UserCallbackInfo;
162
Howard Sue32dbfd2015-01-07 15:55:57 +0800163extern "C" const char * requestToString(int request);
164extern "C" const char * failCauseToString(RIL_Errno);
165extern "C" const char * callStateToString(RIL_CallState);
166extern "C" const char * radioStateToString(RIL_RadioState);
167extern "C" const char * rilSocketIdToString(RIL_SOCKET_ID socket_id);
168
169extern "C"
170char rild[MAX_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200171
Howard Subd82ef12015-04-12 10:25:05 +0200172#define RIL_VENDOR_COMMANDS_OFFSET 10000
173
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200174/*******************************************************************/
175
176RIL_RadioFunctions s_callbacks = {0, NULL, NULL, NULL, NULL, NULL};
177static int s_registerCalled = 0;
178
179static pthread_t s_tid_dispatch;
180static pthread_t s_tid_reader;
181static int s_started = 0;
182
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200183static int s_fdDebug = -1;
Howard Sue32dbfd2015-01-07 15:55:57 +0800184static int s_fdDebug_socket2 = -1;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200185
186static int s_fdWakeupRead;
187static int s_fdWakeupWrite;
188
Sanket Padawea7c043d2016-01-27 15:09:12 -0800189int s_wakelock_count = 0;
190
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200191static struct ril_event s_commands_event;
192static struct ril_event s_wakeupfd_event;
193static struct ril_event s_listen_event;
Howard Sue32dbfd2015-01-07 15:55:57 +0800194static SocketListenParam s_ril_param_socket;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200195
196static pthread_mutex_t s_pendingRequestsMutex = PTHREAD_MUTEX_INITIALIZER;
197static pthread_mutex_t s_writeMutex = PTHREAD_MUTEX_INITIALIZER;
Sanket Padawea7c043d2016-01-27 15:09:12 -0800198static pthread_mutex_t s_wakeLockCountMutex = PTHREAD_MUTEX_INITIALIZER;
Howard Sue32dbfd2015-01-07 15:55:57 +0800199static RequestInfo *s_pendingRequests = NULL;
200
201#if (SIM_COUNT >= 2)
202static struct ril_event s_commands_event_socket2;
203static struct ril_event s_listen_event_socket2;
204static SocketListenParam s_ril_param_socket2;
205
206static pthread_mutex_t s_pendingRequestsMutex_socket2 = PTHREAD_MUTEX_INITIALIZER;
207static pthread_mutex_t s_writeMutex_socket2 = PTHREAD_MUTEX_INITIALIZER;
208static RequestInfo *s_pendingRequests_socket2 = NULL;
209#endif
210
211#if (SIM_COUNT >= 3)
212static struct ril_event s_commands_event_socket3;
213static struct ril_event s_listen_event_socket3;
214static SocketListenParam s_ril_param_socket3;
215
216static pthread_mutex_t s_pendingRequestsMutex_socket3 = PTHREAD_MUTEX_INITIALIZER;
217static pthread_mutex_t s_writeMutex_socket3 = PTHREAD_MUTEX_INITIALIZER;
218static RequestInfo *s_pendingRequests_socket3 = NULL;
219#endif
220
221#if (SIM_COUNT >= 4)
222static struct ril_event s_commands_event_socket4;
223static struct ril_event s_listen_event_socket4;
224static SocketListenParam s_ril_param_socket4;
225
226static pthread_mutex_t s_pendingRequestsMutex_socket4 = PTHREAD_MUTEX_INITIALIZER;
227static pthread_mutex_t s_writeMutex_socket4 = PTHREAD_MUTEX_INITIALIZER;
228static RequestInfo *s_pendingRequests_socket4 = NULL;
229#endif
230
231static struct ril_event s_wake_timeout_event;
232static struct ril_event s_debug_event;
233
Howard Subd82ef12015-04-12 10:25:05 +0200234
Nathan Haroldd6306fa2015-07-28 14:54:58 -0700235static const struct timeval TIMEVAL_WAKE_TIMEOUT = {ANDROID_WAKE_LOCK_SECS,ANDROID_WAKE_LOCK_USECS};
Howard Sue32dbfd2015-01-07 15:55:57 +0800236
Howard Subd82ef12015-04-12 10:25:05 +0200237
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200238static pthread_mutex_t s_startupMutex = PTHREAD_MUTEX_INITIALIZER;
239static pthread_cond_t s_startupCond = PTHREAD_COND_INITIALIZER;
240
241static pthread_mutex_t s_dispatchMutex = PTHREAD_MUTEX_INITIALIZER;
242static pthread_cond_t s_dispatchCond = PTHREAD_COND_INITIALIZER;
243
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200244static RequestInfo *s_toDispatchHead = NULL;
245static RequestInfo *s_toDispatchTail = NULL;
246
247static UserCallbackInfo *s_last_wake_timeout_info = NULL;
248
249static void *s_lastNITZTimeData = NULL;
250static size_t s_lastNITZTimeDataSize;
251
252#if RILC_LOG
253 static char printBuf[PRINTBUF_SIZE];
254#endif
255
256/*******************************************************************/
Howard Sue32dbfd2015-01-07 15:55:57 +0800257static int sendResponse (Parcel &p, RIL_SOCKET_ID socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200258
259static void dispatchVoid (Parcel& p, RequestInfo *pRI);
260static void dispatchString (Parcel& p, RequestInfo *pRI);
261static void dispatchStrings (Parcel& p, RequestInfo *pRI);
262static void dispatchInts (Parcel& p, RequestInfo *pRI);
263static void dispatchDial (Parcel& p, RequestInfo *pRI);
264static void dispatchSIM_IO (Parcel& p, RequestInfo *pRI);
Howard Sue32dbfd2015-01-07 15:55:57 +0800265static void dispatchSIM_APDU (Parcel& p, RequestInfo *pRI);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200266static void dispatchCallForward(Parcel& p, RequestInfo *pRI);
267static void dispatchRaw(Parcel& p, RequestInfo *pRI);
268static void dispatchSmsWrite (Parcel &p, RequestInfo *pRI);
269static void dispatchDataCall (Parcel& p, RequestInfo *pRI);
270static void dispatchVoiceRadioTech (Parcel& p, RequestInfo *pRI);
Andrew Jiangca4a9a02014-01-18 18:04:08 -0500271static void dispatchSetInitialAttachApn (Parcel& p, RequestInfo *pRI);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200272static void dispatchCdmaSubscriptionSource (Parcel& p, RequestInfo *pRI);
273
274static void dispatchCdmaSms(Parcel &p, RequestInfo *pRI);
Andrew Jiangca4a9a02014-01-18 18:04:08 -0500275static void dispatchImsSms(Parcel &p, RequestInfo *pRI);
276static void dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
277static void dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200278static void dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI);
279static void dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI);
280static void dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI);
281static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI);
Howard Sue32dbfd2015-01-07 15:55:57 +0800282static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI);
283static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI);
284static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI);
285static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI);
286static void dispatchDataProfile(Parcel &p, RequestInfo *pRI);
Howard Subd82ef12015-04-12 10:25:05 +0200287static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI);
Christopher N. Hesse65084862017-02-07 22:21:27 +0100288static void dispatchCarrierRestrictions(Parcel &p, RequestInfo *pRI);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200289static int responseInts(Parcel &p, void *response, size_t responselen);
Christopher N. Hesse65084862017-02-07 22:21:27 +0100290static int responseFailCause(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
Christopher N. Hesse65084862017-02-07 22:21:27 +0100322static int responseCarrierRestrictions(Parcel &p, void *response, size_t responselen);
323static int responsePcoData(Parcel &p, void *response, size_t responselen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200324static int decodeVoiceRadioTechnology (RIL_RadioState radioState);
325static int decodeCdmaSubscriptionSource (RIL_RadioState radioState);
Howard Subd82ef12015-04-12 10:25:05 +0200326static RIL_RadioState processRadioState(RIL_RadioState newRadioState);
Sanket Padawea7c043d2016-01-27 15:09:12 -0800327static void grabPartialWakeLock();
328static void releaseWakeLock();
329static void wakeTimeoutCallback(void *);
Howard Subd82ef12015-04-12 10:25:05 +0200330
331static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200332
Sanket Padawe9343e872016-01-11 12:45:43 -0800333static bool isDebuggable();
334
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200335#ifdef RIL_SHLIB
Howard Sue32dbfd2015-01-07 15:55:57 +0800336#if defined(ANDROID_MULTI_SIM)
Andreas Schneider47b2d962015-04-13 22:54:49 +0200337extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Howard Sue32dbfd2015-01-07 15:55:57 +0800338 size_t datalen, RIL_SOCKET_ID socket_id);
339#else
Andreas Schneider47b2d962015-04-13 22:54:49 +0200340extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200341 size_t datalen);
342#endif
Howard Sue32dbfd2015-01-07 15:55:57 +0800343#endif
344
345#if defined(ANDROID_MULTI_SIM)
346#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c), (d))
347#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d), (e))
348#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest(a)
349#else
350#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c))
351#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d))
352#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest()
353#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200354
355static UserCallbackInfo * internalRequestTimedCallback
356 (RIL_TimedCallback callback, void *param,
357 const struct timeval *relativeTime);
358
359/** Index == requestNumber */
360static CommandInfo s_commands[] = {
361#include "ril_commands.h"
362};
363
364static UnsolResponseInfo s_unsolResponses[] = {
365#include "ril_unsol_commands.h"
366};
367
Christopher N. Hessec694ff02016-03-27 21:04:38 +0200368static CommandInfo s_commands_v[] = {
369#include <telephony/ril_commands_vendor.h>
370};
371
Howard Subd82ef12015-04-12 10:25:05 +0200372static UnsolResponseInfo s_unsolResponses_v[] = {
Christopher N. Hessec694ff02016-03-27 21:04:38 +0200373#include <telephony/ril_unsol_commands_vendor.h>
Howard Subd82ef12015-04-12 10:25:05 +0200374};
375
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200376/* For older RILs that do not support new commands RIL_REQUEST_VOICE_RADIO_TECH and
377 RIL_UNSOL_VOICE_RADIO_TECH_CHANGED messages, decode the voice radio tech from
378 radio state message and store it. Every time there is a change in Radio State
379 check to see if voice radio tech changes and notify telephony
380 */
381int voiceRadioTech = -1;
382
383/* For older RILs that do not support new commands RIL_REQUEST_GET_CDMA_SUBSCRIPTION_SOURCE
384 and RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED messages, decode the subscription
385 source from radio state and store it. Every time there is a change in Radio State
386 check to see if subscription source changed and notify telephony
387 */
388int cdmaSubscriptionSource = -1;
389
390/* For older RILs that do not send RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, decode the
391 SIM/RUIM state from radio state and store it. Every time there is a change in Radio State,
392 check to see if SIM/RUIM status changed and notify telephony
393 */
394int simRuimStatus = -1;
395
Howard Sue32dbfd2015-01-07 15:55:57 +0800396static char * RIL_getRilSocketName() {
397 return rild;
398}
399
400extern "C"
Dheeraj Shettycc231012014-07-02 21:27:57 +0200401void RIL_setRilSocketName(const char * s) {
Howard Sue32dbfd2015-01-07 15:55:57 +0800402 strncpy(rild, s, MAX_SOCKET_NAME_LENGTH);
403}
404
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200405static char *
406strdupReadString(Parcel &p) {
407 size_t stringlen;
408 const char16_t *s16;
409
410 s16 = p.readString16Inplace(&stringlen);
411
412 return strndup16to8(s16, stringlen);
413}
414
Howard Subd82ef12015-04-12 10:25:05 +0200415static status_t
416readStringFromParcelInplace(Parcel &p, char *str, size_t maxLen) {
417 size_t s16Len;
418 const char16_t *s16;
419
420 s16 = p.readString16Inplace(&s16Len);
421 if (s16 == NULL) {
422 return NO_MEMORY;
423 }
424 size_t strLen = strnlen16to8(s16, s16Len);
425 if ((strLen + 1) > maxLen) {
426 return NO_MEMORY;
427 }
428 if (strncpy16to8(str, s16, strLen) == NULL) {
429 return NO_MEMORY;
430 } else {
431 return NO_ERROR;
432 }
433}
434
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200435static void writeStringToParcel(Parcel &p, const char *s) {
436 char16_t *s16;
437 size_t s16_len;
438 s16 = strdup8to16(s, &s16_len);
439 p.writeString16(s16, s16_len);
440 free(s16);
441}
442
443
444static void
445memsetString (char *s) {
446 if (s != NULL) {
447 memset (s, 0, strlen(s));
448 }
449}
450
451void nullParcelReleaseFunction (const uint8_t* data, size_t dataSize,
452 const size_t* objects, size_t objectsSize,
453 void* cookie) {
454 // do nothing -- the data reference lives longer than the Parcel object
455}
456
457/**
458 * To be called from dispatch thread
459 * Issue a single local request, ensuring that the response
460 * is not sent back up to the command process
461 */
462static void
Howard Sue32dbfd2015-01-07 15:55:57 +0800463issueLocalRequest(int request, void *data, int len, RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200464 RequestInfo *pRI;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200465 int ret;
Howard Sue32dbfd2015-01-07 15:55:57 +0800466 /* Hook for current context */
467 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
468 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
469 /* pendingRequestsHook refer to &s_pendingRequests */
470 RequestInfo** pendingRequestsHook = &s_pendingRequests;
471
472#if (SIM_COUNT == 2)
473 if (socket_id == RIL_SOCKET_2) {
474 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
475 pendingRequestsHook = &s_pendingRequests_socket2;
476 }
477#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200478
479 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
Sanket Padawedf3dabe2016-02-29 10:09:26 -0800480 if (pRI == NULL) {
481 RLOGE("Memory allocation failed for request %s", requestToString(request));
482 return;
483 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200484
485 pRI->local = 1;
486 pRI->token = 0xffffffff; // token is not used in this context
487
Christopher N. Hesse65084862017-02-07 22:21:27 +0100488 pRI->pCI = &(s_commands[request]);
489 pRI->socket_id = socket_id;
490
491 /* Hack to include Samsung requests */
Howard Subd82ef12015-04-12 10:25:05 +0200492 if (request > RIL_VENDOR_COMMANDS_OFFSET) {
493 pRI->pCI = &(s_commands_v[request - RIL_VENDOR_COMMANDS_OFFSET]);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200494 }
495
Howard Sue32dbfd2015-01-07 15:55:57 +0800496 ret = pthread_mutex_lock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200497 assert (ret == 0);
498
Howard Sue32dbfd2015-01-07 15:55:57 +0800499 pRI->p_next = *pendingRequestsHook;
500 *pendingRequestsHook = pRI;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200501
Howard Sue32dbfd2015-01-07 15:55:57 +0800502 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200503 assert (ret == 0);
504
XpLoDWilDba5c6a32013-07-27 21:12:19 +0200505 RLOGD("C[locl]> %s", requestToString(request));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200506
Howard Sue32dbfd2015-01-07 15:55:57 +0800507 CALL_ONREQUEST(request, data, len, pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200508}
509
Howard Subd82ef12015-04-12 10:25:05 +0200510
511
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200512static int
Howard Sue32dbfd2015-01-07 15:55:57 +0800513processCommandBuffer(void *buffer, size_t buflen, RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200514 Parcel p;
515 status_t status;
516 int32_t request;
517 int32_t token;
518 RequestInfo *pRI;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200519 int ret;
Howard Sue32dbfd2015-01-07 15:55:57 +0800520 /* Hook for current context */
521 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
522 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
523 /* pendingRequestsHook refer to &s_pendingRequests */
524 RequestInfo** pendingRequestsHook = &s_pendingRequests;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200525
526 p.setData((uint8_t *) buffer, buflen);
527
528 // status checked at end
529 status = p.readInt32(&request);
530 status = p.readInt32 (&token);
531
Howard Sue32dbfd2015-01-07 15:55:57 +0800532#if (SIM_COUNT >= 2)
533 if (socket_id == RIL_SOCKET_2) {
534 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
535 pendingRequestsHook = &s_pendingRequests_socket2;
536 }
537#if (SIM_COUNT >= 3)
538 else if (socket_id == RIL_SOCKET_3) {
539 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
540 pendingRequestsHook = &s_pendingRequests_socket3;
541 }
542#endif
543#if (SIM_COUNT >= 4)
544 else if (socket_id == RIL_SOCKET_4) {
545 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
546 pendingRequestsHook = &s_pendingRequests_socket4;
547 }
548#endif
549#endif
550
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200551 if (status != NO_ERROR) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +0200552 RLOGE("invalid request block");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200553 return 0;
554 }
555
Howard Subd82ef12015-04-12 10:25:05 +0200556 CommandInfo *pCI = NULL;
557 if (request > RIL_VENDOR_COMMANDS_OFFSET) {
558 int index = request - RIL_VENDOR_COMMANDS_OFFSET;
559 RLOGD("processCommandBuffer: samsung request=%d, index=%d",
560 request, index);
561 if (index < (int32_t)NUM_ELEMS(s_commands_v))
562 pCI = &(s_commands_v[index]);
563 } else {
564 if (request < (int32_t)NUM_ELEMS(s_commands))
565 pCI = &(s_commands[request]);
566 }
Howard Sue32dbfd2015-01-07 15:55:57 +0800567
Sooraj Sasindrancfef9bd2016-05-06 16:19:56 -0700568 // Received an Ack for the previous result sent to RIL.java,
569 // so release wakelock and exit
570 if (request == RIL_RESPONSE_ACKNOWLEDGEMENT) {
571 releaseWakeLock();
572 return 0;
573 }
574
Howard Subd82ef12015-04-12 10:25:05 +0200575 if (pCI == NULL) {
576 Parcel pErr;
XpLoDWilDba5c6a32013-07-27 21:12:19 +0200577 RLOGE("unsupported request code %d token %d", request, token);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200578 // FIXME this should perhaps return a response
Howard Sue32dbfd2015-01-07 15:55:57 +0800579 pErr.writeInt32 (RESPONSE_SOLICITED);
580 pErr.writeInt32 (token);
581 pErr.writeInt32 (RIL_E_GENERIC_FAILURE);
582
583 sendResponse(pErr, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200584 return 0;
585 }
586
Christopher N. Hesse65084862017-02-07 22:21:27 +0100587 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
Sanket Padawedf3dabe2016-02-29 10:09:26 -0800588 if (pRI == NULL) {
589 RLOGE("Memory allocation failed for request %s", requestToString(request));
590 return 0;
591 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200592
593 pRI->token = token;
Howard Subd82ef12015-04-12 10:25:05 +0200594 pRI->pCI = pCI;
Howard Sue32dbfd2015-01-07 15:55:57 +0800595 pRI->socket_id = socket_id;
596
597 ret = pthread_mutex_lock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200598 assert (ret == 0);
599
Howard Sue32dbfd2015-01-07 15:55:57 +0800600 pRI->p_next = *pendingRequestsHook;
601 *pendingRequestsHook = pRI;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200602
Howard Sue32dbfd2015-01-07 15:55:57 +0800603 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200604 assert (ret == 0);
605
606/* sLastDispatchedToken = token; */
607
608 pRI->pCI->dispatchFunction(p, pRI);
609
610 return 0;
611}
612
613static void
614invalidCommandBlock (RequestInfo *pRI) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +0200615 RLOGE("invalid command block for token %d request %s",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200616 pRI->token, requestToString(pRI->pCI->requestNumber));
617}
618
619/** Callee expects NULL */
620static void
621dispatchVoid (Parcel& p, RequestInfo *pRI) {
622 clearPrintBuf;
623 printRequest(pRI->token, pRI->pCI->requestNumber);
Howard Sue32dbfd2015-01-07 15:55:57 +0800624 CALL_ONREQUEST(pRI->pCI->requestNumber, NULL, 0, pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200625}
626
627/** Callee expects const char * */
628static void
629dispatchString (Parcel& p, RequestInfo *pRI) {
630 status_t status;
631 size_t datalen;
632 size_t stringlen;
633 char *string8 = NULL;
634
635 string8 = strdupReadString(p);
636
637 startRequest;
638 appendPrintBuf("%s%s", printBuf, string8);
639 closeRequest;
640 printRequest(pRI->token, pRI->pCI->requestNumber);
641
Howard Sue32dbfd2015-01-07 15:55:57 +0800642 CALL_ONREQUEST(pRI->pCI->requestNumber, string8,
643 sizeof(char *), pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200644
645#ifdef MEMSET_FREED
646 memsetString(string8);
647#endif
648
649 free(string8);
650 return;
651invalid:
652 invalidCommandBlock(pRI);
653 return;
654}
655
656/** Callee expects const char ** */
657static void
658dispatchStrings (Parcel &p, RequestInfo *pRI) {
659 int32_t countStrings;
660 status_t status;
661 size_t datalen;
662 char **pStrings;
663
664 status = p.readInt32 (&countStrings);
665
666 if (status != NO_ERROR) {
667 goto invalid;
668 }
669
670 startRequest;
671 if (countStrings == 0) {
672 // just some non-null pointer
Christopher N. Hesse65084862017-02-07 22:21:27 +0100673 pStrings = (char **)calloc(1, sizeof(char *));
Sanket Padawedf3dabe2016-02-29 10:09:26 -0800674 if (pStrings == NULL) {
675 RLOGE("Memory allocation failed for request %s",
676 requestToString(pRI->pCI->requestNumber));
677 closeRequest;
678 return;
679 }
680
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200681 datalen = 0;
Christopher N. Hesse65084862017-02-07 22:21:27 +0100682 } else if (countStrings < 0) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200683 pStrings = NULL;
684 datalen = 0;
685 } else {
686 datalen = sizeof(char *) * countStrings;
687
Christopher N. Hesse65084862017-02-07 22:21:27 +0100688 pStrings = (char **)calloc(countStrings, sizeof(char *));
Sanket Padawedf3dabe2016-02-29 10:09:26 -0800689 if (pStrings == NULL) {
690 RLOGE("Memory allocation failed for request %s",
691 requestToString(pRI->pCI->requestNumber));
692 closeRequest;
693 return;
694 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200695
696 for (int i = 0 ; i < countStrings ; i++) {
697 pStrings[i] = strdupReadString(p);
698 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
699 }
700 }
701 removeLastChar;
702 closeRequest;
703 printRequest(pRI->token, pRI->pCI->requestNumber);
704
Howard Sue32dbfd2015-01-07 15:55:57 +0800705 CALL_ONREQUEST(pRI->pCI->requestNumber, pStrings, datalen, pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200706
707 if (pStrings != NULL) {
708 for (int i = 0 ; i < countStrings ; i++) {
709#ifdef MEMSET_FREED
710 memsetString (pStrings[i]);
711#endif
712 free(pStrings[i]);
713 }
714
715#ifdef MEMSET_FREED
716 memset(pStrings, 0, datalen);
717#endif
Christopher N. Hesse65084862017-02-07 22:21:27 +0100718 free(pStrings);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200719 }
720
721 return;
722invalid:
723 invalidCommandBlock(pRI);
724 return;
725}
726
727/** Callee expects const int * */
728static void
729dispatchInts (Parcel &p, RequestInfo *pRI) {
730 int32_t count;
731 status_t status;
732 size_t datalen;
733 int *pInts;
734
735 status = p.readInt32 (&count);
736
Christopher N. Hesse65084862017-02-07 22:21:27 +0100737 if (status != NO_ERROR || count <= 0) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200738 goto invalid;
739 }
740
741 datalen = sizeof(int) * count;
Christopher N. Hesse65084862017-02-07 22:21:27 +0100742 pInts = (int *)calloc(count, sizeof(int));
Sanket Padawedf3dabe2016-02-29 10:09:26 -0800743 if (pInts == NULL) {
744 RLOGE("Memory allocation failed for request %s", requestToString(pRI->pCI->requestNumber));
745 return;
746 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200747
748 startRequest;
749 for (int i = 0 ; i < count ; i++) {
750 int32_t t;
751
752 status = p.readInt32(&t);
753 pInts[i] = (int)t;
754 appendPrintBuf("%s%d,", printBuf, t);
755
756 if (status != NO_ERROR) {
Christopher N. Hesse65084862017-02-07 22:21:27 +0100757 free(pInts);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200758 goto invalid;
759 }
760 }
761 removeLastChar;
762 closeRequest;
763 printRequest(pRI->token, pRI->pCI->requestNumber);
764
Howard Sue32dbfd2015-01-07 15:55:57 +0800765 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<int *>(pInts),
766 datalen, pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200767
768#ifdef MEMSET_FREED
769 memset(pInts, 0, datalen);
770#endif
Christopher N. Hesse65084862017-02-07 22:21:27 +0100771 free(pInts);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200772 return;
773invalid:
774 invalidCommandBlock(pRI);
775 return;
776}
777
778
779/**
780 * Callee expects const RIL_SMS_WriteArgs *
781 * Payload is:
782 * int32_t status
783 * String pdu
784 */
785static void
786dispatchSmsWrite (Parcel &p, RequestInfo *pRI) {
787 RIL_SMS_WriteArgs args;
788 int32_t t;
789 status_t status;
790
Mark Salyzyn961fd022015-04-09 07:18:35 -0700791 RLOGD("dispatchSmsWrite");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200792 memset (&args, 0, sizeof(args));
793
794 status = p.readInt32(&t);
795 args.status = (int)t;
796
797 args.pdu = strdupReadString(p);
798
799 if (status != NO_ERROR || args.pdu == NULL) {
800 goto invalid;
801 }
802
803 args.smsc = strdupReadString(p);
804
805 startRequest;
806 appendPrintBuf("%s%d,%s,smsc=%s", printBuf, args.status,
807 (char*)args.pdu, (char*)args.smsc);
808 closeRequest;
809 printRequest(pRI->token, pRI->pCI->requestNumber);
810
Howard Sue32dbfd2015-01-07 15:55:57 +0800811 CALL_ONREQUEST(pRI->pCI->requestNumber, &args, sizeof(args), pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200812
813#ifdef MEMSET_FREED
814 memsetString (args.pdu);
815#endif
816
817 free (args.pdu);
818
819#ifdef MEMSET_FREED
820 memset(&args, 0, sizeof(args));
821#endif
822
823 return;
824invalid:
825 invalidCommandBlock(pRI);
826 return;
827}
828
829/**
830 * Callee expects const RIL_Dial *
831 * Payload is:
832 * String address
833 * int32_t clir
834 */
835static void
836dispatchDial (Parcel &p, RequestInfo *pRI) {
837 RIL_Dial dial;
838 RIL_UUS_Info uusInfo;
839 int32_t sizeOfDial;
840 int32_t t;
841 int32_t uusPresent;
Christopher N. Hesse621e63e2016-02-22 21:57:39 +0100842#ifdef SAMSUNG_NEXT_GEN_MODEM
Andreas Schneider29472682015-01-01 19:00:04 +0100843 char *csv;
844#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200845 status_t status;
846
Mark Salyzyn961fd022015-04-09 07:18:35 -0700847 RLOGD("dispatchDial");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200848 memset (&dial, 0, sizeof(dial));
849
850 dial.address = strdupReadString(p);
851
852 status = p.readInt32(&t);
853 dial.clir = (int)t;
854
855 if (status != NO_ERROR || dial.address == NULL) {
856 goto invalid;
857 }
858
Christopher N. Hesse621e63e2016-02-22 21:57:39 +0100859#ifdef SAMSUNG_NEXT_GEN_MODEM
Andreas Schneider29472682015-01-01 19:00:04 +0100860 /* CallDetails.call_type */
861 status = p.readInt32(&t);
862 if (status != NO_ERROR) {
863 goto invalid;
864 }
865 /* CallDetails.call_domain */
866 p.readInt32(&t);
867 if (status != NO_ERROR) {
868 goto invalid;
869 }
870 /* CallDetails.getCsvFromExtra */
871 csv = strdupReadString(p);
872 if (csv == NULL) {
873 goto invalid;
874 }
875 free(csv);
876#endif
877
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200878 if (s_callbacks.version < 3) { // Remove when partners upgrade to version 3
879 uusPresent = 0;
880 sizeOfDial = sizeof(dial) - sizeof(RIL_UUS_Info *);
881 } else {
882 status = p.readInt32(&uusPresent);
883
884 if (status != NO_ERROR) {
885 goto invalid;
886 }
887
888 if (uusPresent == 0) {
Christopher N. Hesse621e63e2016-02-22 21:57:39 +0100889#if defined(MODEM_TYPE_XMM6262) || defined(SAMSUNG_NEXT_GEN_MODEM)
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200890 dial.uusInfo = NULL;
Andreas Schneiderf68609b2015-04-07 19:01:34 +0200891#elif defined(MODEM_TYPE_XMM6260)
Howard Sue32dbfd2015-01-07 15:55:57 +0800892 /* Samsung hack */
893 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
894 uusInfo.uusType = (RIL_UUS_Type) 0;
895 uusInfo.uusDcs = (RIL_UUS_DCS) 0;
896 uusInfo.uusData = NULL;
897 uusInfo.uusLength = 0;
898 dial.uusInfo = &uusInfo;
899#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200900 } else {
901 int32_t len;
902
903 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
904
905 status = p.readInt32(&t);
906 uusInfo.uusType = (RIL_UUS_Type) t;
907
908 status = p.readInt32(&t);
909 uusInfo.uusDcs = (RIL_UUS_DCS) t;
910
911 status = p.readInt32(&len);
912 if (status != NO_ERROR) {
913 goto invalid;
914 }
915
916 // The java code writes -1 for null arrays
917 if (((int) len) == -1) {
918 uusInfo.uusData = NULL;
919 len = 0;
920 } else {
921 uusInfo.uusData = (char*) p.readInplace(len);
922 }
923
924 uusInfo.uusLength = len;
925 dial.uusInfo = &uusInfo;
926 }
927 sizeOfDial = sizeof(dial);
928 }
929
930 startRequest;
931 appendPrintBuf("%snum=%s,clir=%d", printBuf, dial.address, dial.clir);
932 if (uusPresent) {
933 appendPrintBuf("%s,uusType=%d,uusDcs=%d,uusLen=%d", printBuf,
934 dial.uusInfo->uusType, dial.uusInfo->uusDcs,
935 dial.uusInfo->uusLength);
936 }
937 closeRequest;
938 printRequest(pRI->token, pRI->pCI->requestNumber);
939
Howard Sue32dbfd2015-01-07 15:55:57 +0800940 CALL_ONREQUEST(pRI->pCI->requestNumber, &dial, sizeOfDial, pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200941
942#ifdef MEMSET_FREED
943 memsetString (dial.address);
944#endif
945
946 free (dial.address);
947
948#ifdef MEMSET_FREED
949 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
950 memset(&dial, 0, sizeof(dial));
951#endif
952
953 return;
954invalid:
955 invalidCommandBlock(pRI);
956 return;
957}
958
959/**
960 * Callee expects const RIL_SIM_IO *
961 * Payload is:
962 * int32_t command
963 * int32_t fileid
964 * String path
965 * int32_t p1, p2, p3
966 * String data
967 * String pin2
968 * String aidPtr
969 */
970static void
971dispatchSIM_IO (Parcel &p, RequestInfo *pRI) {
972 union RIL_SIM_IO {
973 RIL_SIM_IO_v6 v6;
974 RIL_SIM_IO_v5 v5;
975 } simIO;
976
977 int32_t t;
978 int size;
979 status_t status;
980
Robert Greenwaltbc29c432015-04-29 16:57:39 -0700981#if VDBG
Mark Salyzyn961fd022015-04-09 07:18:35 -0700982 RLOGD("dispatchSIM_IO");
Robert Greenwaltbc29c432015-04-29 16:57:39 -0700983#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200984 memset (&simIO, 0, sizeof(simIO));
985
986 // note we only check status at the end
987
988 status = p.readInt32(&t);
989 simIO.v6.command = (int)t;
990
991 status = p.readInt32(&t);
992 simIO.v6.fileid = (int)t;
993
994 simIO.v6.path = strdupReadString(p);
995
996 status = p.readInt32(&t);
997 simIO.v6.p1 = (int)t;
998
999 status = p.readInt32(&t);
1000 simIO.v6.p2 = (int)t;
1001
1002 status = p.readInt32(&t);
1003 simIO.v6.p3 = (int)t;
1004
1005 simIO.v6.data = strdupReadString(p);
1006 simIO.v6.pin2 = strdupReadString(p);
1007 simIO.v6.aidPtr = strdupReadString(p);
1008
1009 startRequest;
1010 appendPrintBuf("%scmd=0x%X,efid=0x%X,path=%s,%d,%d,%d,%s,pin2=%s,aid=%s", printBuf,
1011 simIO.v6.command, simIO.v6.fileid, (char*)simIO.v6.path,
1012 simIO.v6.p1, simIO.v6.p2, simIO.v6.p3,
1013 (char*)simIO.v6.data, (char*)simIO.v6.pin2, simIO.v6.aidPtr);
1014 closeRequest;
1015 printRequest(pRI->token, pRI->pCI->requestNumber);
1016
1017 if (status != NO_ERROR) {
1018 goto invalid;
1019 }
1020
1021 size = (s_callbacks.version < 6) ? sizeof(simIO.v5) : sizeof(simIO.v6);
Howard Sue32dbfd2015-01-07 15:55:57 +08001022 CALL_ONREQUEST(pRI->pCI->requestNumber, &simIO, size, pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001023
1024#ifdef MEMSET_FREED
1025 memsetString (simIO.v6.path);
1026 memsetString (simIO.v6.data);
1027 memsetString (simIO.v6.pin2);
1028 memsetString (simIO.v6.aidPtr);
1029#endif
1030
1031 free (simIO.v6.path);
1032 free (simIO.v6.data);
1033 free (simIO.v6.pin2);
1034 free (simIO.v6.aidPtr);
1035
1036#ifdef MEMSET_FREED
1037 memset(&simIO, 0, sizeof(simIO));
1038#endif
1039
1040 return;
1041invalid:
1042 invalidCommandBlock(pRI);
1043 return;
1044}
1045
1046/**
Howard Sue32dbfd2015-01-07 15:55:57 +08001047 * Callee expects const RIL_SIM_APDU *
1048 * Payload is:
1049 * int32_t sessionid
1050 * int32_t cla
1051 * int32_t instruction
1052 * int32_t p1, p2, p3
1053 * String data
1054 */
1055static void
1056dispatchSIM_APDU (Parcel &p, RequestInfo *pRI) {
1057 int32_t t;
1058 status_t status;
1059 RIL_SIM_APDU apdu;
1060
Robert Greenwaltbc29c432015-04-29 16:57:39 -07001061#if VDBG
Mark Salyzyn961fd022015-04-09 07:18:35 -07001062 RLOGD("dispatchSIM_APDU");
Robert Greenwaltbc29c432015-04-29 16:57:39 -07001063#endif
Howard Sue32dbfd2015-01-07 15:55:57 +08001064 memset (&apdu, 0, sizeof(RIL_SIM_APDU));
1065
1066 // Note we only check status at the end. Any single failure leads to
1067 // subsequent reads filing.
1068 status = p.readInt32(&t);
1069 apdu.sessionid = (int)t;
1070
1071 status = p.readInt32(&t);
1072 apdu.cla = (int)t;
1073
1074 status = p.readInt32(&t);
1075 apdu.instruction = (int)t;
1076
1077 status = p.readInt32(&t);
1078 apdu.p1 = (int)t;
1079
1080 status = p.readInt32(&t);
1081 apdu.p2 = (int)t;
1082
1083 status = p.readInt32(&t);
1084 apdu.p3 = (int)t;
1085
1086 apdu.data = strdupReadString(p);
1087
1088 startRequest;
1089 appendPrintBuf("%ssessionid=%d,cla=%d,ins=%d,p1=%d,p2=%d,p3=%d,data=%s",
1090 printBuf, apdu.sessionid, apdu.cla, apdu.instruction, apdu.p1, apdu.p2,
1091 apdu.p3, (char*)apdu.data);
1092 closeRequest;
1093 printRequest(pRI->token, pRI->pCI->requestNumber);
1094
1095 if (status != NO_ERROR) {
1096 goto invalid;
1097 }
1098
1099 CALL_ONREQUEST(pRI->pCI->requestNumber, &apdu, sizeof(RIL_SIM_APDU), pRI, pRI->socket_id);
1100
1101#ifdef MEMSET_FREED
1102 memsetString(apdu.data);
1103#endif
1104 free(apdu.data);
1105
1106#ifdef MEMSET_FREED
1107 memset(&apdu, 0, sizeof(RIL_SIM_APDU));
1108#endif
1109
1110 return;
1111invalid:
1112 invalidCommandBlock(pRI);
1113 return;
1114}
1115
Howard Subd82ef12015-04-12 10:25:05 +02001116
Howard Sue32dbfd2015-01-07 15:55:57 +08001117/**
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001118 * Callee expects const RIL_CallForwardInfo *
1119 * Payload is:
1120 * int32_t status/action
1121 * int32_t reason
1122 * int32_t serviceCode
1123 * int32_t toa
1124 * String number (0 length -> null)
1125 * int32_t timeSeconds
1126 */
1127static void
1128dispatchCallForward(Parcel &p, RequestInfo *pRI) {
1129 RIL_CallForwardInfo cff;
1130 int32_t t;
1131 status_t status;
1132
Mark Salyzyn961fd022015-04-09 07:18:35 -07001133 RLOGD("dispatchCallForward");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001134 memset (&cff, 0, sizeof(cff));
1135
1136 // note we only check status at the end
1137
1138 status = p.readInt32(&t);
1139 cff.status = (int)t;
1140
1141 status = p.readInt32(&t);
1142 cff.reason = (int)t;
1143
1144 status = p.readInt32(&t);
1145 cff.serviceClass = (int)t;
1146
1147 status = p.readInt32(&t);
1148 cff.toa = (int)t;
1149
1150 cff.number = strdupReadString(p);
1151
1152 status = p.readInt32(&t);
1153 cff.timeSeconds = (int)t;
1154
1155 if (status != NO_ERROR) {
1156 goto invalid;
1157 }
1158
1159 // special case: number 0-length fields is null
1160
1161 if (cff.number != NULL && strlen (cff.number) == 0) {
1162 cff.number = NULL;
1163 }
1164
1165 startRequest;
1166 appendPrintBuf("%sstat=%d,reason=%d,serv=%d,toa=%d,%s,tout=%d", printBuf,
1167 cff.status, cff.reason, cff.serviceClass, cff.toa,
1168 (char*)cff.number, cff.timeSeconds);
1169 closeRequest;
1170 printRequest(pRI->token, pRI->pCI->requestNumber);
1171
Howard Sue32dbfd2015-01-07 15:55:57 +08001172 CALL_ONREQUEST(pRI->pCI->requestNumber, &cff, sizeof(cff), pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001173
1174#ifdef MEMSET_FREED
1175 memsetString(cff.number);
1176#endif
1177
1178 free (cff.number);
1179
1180#ifdef MEMSET_FREED
1181 memset(&cff, 0, sizeof(cff));
1182#endif
1183
1184 return;
1185invalid:
1186 invalidCommandBlock(pRI);
1187 return;
1188}
1189
1190
1191static void
1192dispatchRaw(Parcel &p, RequestInfo *pRI) {
1193 int32_t len;
1194 status_t status;
1195 const void *data;
1196
1197 status = p.readInt32(&len);
1198
1199 if (status != NO_ERROR) {
1200 goto invalid;
1201 }
1202
1203 // The java code writes -1 for null arrays
1204 if (((int)len) == -1) {
1205 data = NULL;
1206 len = 0;
1207 }
1208
1209 data = p.readInplace(len);
1210
1211 startRequest;
1212 appendPrintBuf("%sraw_size=%d", printBuf, len);
1213 closeRequest;
1214 printRequest(pRI->token, pRI->pCI->requestNumber);
1215
Howard Sue32dbfd2015-01-07 15:55:57 +08001216 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<void *>(data), len, pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001217
1218 return;
1219invalid:
1220 invalidCommandBlock(pRI);
1221 return;
1222}
1223
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001224static status_t
1225constructCdmaSms(Parcel &p, RequestInfo *pRI, RIL_CDMA_SMS_Message& rcsm) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001226 int32_t t;
1227 uint8_t ut;
1228 status_t status;
1229 int32_t digitCount;
1230 int digitLimit;
1231
1232 memset(&rcsm, 0, sizeof(rcsm));
1233
1234 status = p.readInt32(&t);
1235 rcsm.uTeleserviceID = (int) t;
1236
1237 status = p.read(&ut,sizeof(ut));
1238 rcsm.bIsServicePresent = (uint8_t) ut;
1239
1240 status = p.readInt32(&t);
1241 rcsm.uServicecategory = (int) t;
1242
1243 status = p.readInt32(&t);
1244 rcsm.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1245
1246 status = p.readInt32(&t);
1247 rcsm.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1248
1249 status = p.readInt32(&t);
1250 rcsm.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1251
1252 status = p.readInt32(&t);
1253 rcsm.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1254
1255 status = p.read(&ut,sizeof(ut));
1256 rcsm.sAddress.number_of_digits= (uint8_t) ut;
1257
1258 digitLimit= MIN((rcsm.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
1259 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1260 status = p.read(&ut,sizeof(ut));
1261 rcsm.sAddress.digits[digitCount] = (uint8_t) ut;
1262 }
1263
1264 status = p.readInt32(&t);
1265 rcsm.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1266
1267 status = p.read(&ut,sizeof(ut));
1268 rcsm.sSubAddress.odd = (uint8_t) ut;
1269
1270 status = p.read(&ut,sizeof(ut));
1271 rcsm.sSubAddress.number_of_digits = (uint8_t) ut;
1272
1273 digitLimit= MIN((rcsm.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
1274 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1275 status = p.read(&ut,sizeof(ut));
1276 rcsm.sSubAddress.digits[digitCount] = (uint8_t) ut;
1277 }
1278
1279 status = p.readInt32(&t);
1280 rcsm.uBearerDataLen = (int) t;
1281
1282 digitLimit= MIN((rcsm.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
1283 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1284 status = p.read(&ut, sizeof(ut));
1285 rcsm.aBearerData[digitCount] = (uint8_t) ut;
1286 }
1287
1288 if (status != NO_ERROR) {
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001289 return status;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001290 }
1291
1292 startRequest;
1293 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
1294 sAddress.digit_mode=%d, sAddress.Number_mode=%d, sAddress.number_type=%d, ",
1295 printBuf, rcsm.uTeleserviceID,rcsm.bIsServicePresent,rcsm.uServicecategory,
1296 rcsm.sAddress.digit_mode, rcsm.sAddress.number_mode,rcsm.sAddress.number_type);
1297 closeRequest;
1298
1299 printRequest(pRI->token, pRI->pCI->requestNumber);
1300
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001301 return status;
1302}
1303
1304static void
1305dispatchCdmaSms(Parcel &p, RequestInfo *pRI) {
1306 RIL_CDMA_SMS_Message rcsm;
1307
Mark Salyzyn961fd022015-04-09 07:18:35 -07001308 RLOGD("dispatchCdmaSms");
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001309 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1310 goto invalid;
1311 }
1312
Howard Sue32dbfd2015-01-07 15:55:57 +08001313 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm),pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001314
1315#ifdef MEMSET_FREED
1316 memset(&rcsm, 0, sizeof(rcsm));
1317#endif
1318
1319 return;
1320
1321invalid:
1322 invalidCommandBlock(pRI);
1323 return;
1324}
1325
1326static void
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001327dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1328 RIL_IMS_SMS_Message rism;
1329 RIL_CDMA_SMS_Message rcsm;
1330
Mark Salyzyn961fd022015-04-09 07:18:35 -07001331 RLOGD("dispatchImsCdmaSms: retry=%d, messageRef=%d", retry, messageRef);
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001332
1333 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1334 goto invalid;
1335 }
1336 memset(&rism, 0, sizeof(rism));
1337 rism.tech = RADIO_TECH_3GPP2;
1338 rism.retry = retry;
1339 rism.messageRef = messageRef;
1340 rism.message.cdmaMessage = &rcsm;
1341
Howard Sue32dbfd2015-01-07 15:55:57 +08001342 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001343 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Howard Sue32dbfd2015-01-07 15:55:57 +08001344 +sizeof(rcsm),pRI, pRI->socket_id);
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001345
1346#ifdef MEMSET_FREED
1347 memset(&rcsm, 0, sizeof(rcsm));
1348 memset(&rism, 0, sizeof(rism));
1349#endif
1350
1351 return;
1352
1353invalid:
1354 invalidCommandBlock(pRI);
1355 return;
1356}
1357
1358static void
1359dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1360 RIL_IMS_SMS_Message rism;
1361 int32_t countStrings;
1362 status_t status;
1363 size_t datalen;
1364 char **pStrings;
Mark Salyzyn961fd022015-04-09 07:18:35 -07001365 RLOGD("dispatchImsGsmSms: retry=%d, messageRef=%d", retry, messageRef);
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001366
1367 status = p.readInt32 (&countStrings);
1368
1369 if (status != NO_ERROR) {
1370 goto invalid;
1371 }
1372
1373 memset(&rism, 0, sizeof(rism));
1374 rism.tech = RADIO_TECH_3GPP;
1375 rism.retry = retry;
1376 rism.messageRef = messageRef;
1377
1378 startRequest;
Howard Sue32dbfd2015-01-07 15:55:57 +08001379 appendPrintBuf("%stech=%d, retry=%d, messageRef=%d, ", printBuf,
1380 (int)rism.tech, (int)rism.retry, rism.messageRef);
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001381 if (countStrings == 0) {
1382 // just some non-null pointer
Christopher N. Hesse65084862017-02-07 22:21:27 +01001383 pStrings = (char **)calloc(1, sizeof(char *));
Sanket Padawedf3dabe2016-02-29 10:09:26 -08001384 if (pStrings == NULL) {
1385 RLOGE("Memory allocation failed for request %s",
1386 requestToString(pRI->pCI->requestNumber));
1387 closeRequest;
1388 return;
1389 }
1390
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001391 datalen = 0;
Christopher N. Hesse65084862017-02-07 22:21:27 +01001392 } else if (countStrings < 0) {
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001393 pStrings = NULL;
1394 datalen = 0;
1395 } else {
Christopher N. Hesse65084862017-02-07 22:21:27 +01001396 if ((size_t)countStrings > (INT_MAX/sizeof(char *))) {
1397 RLOGE("Invalid value of countStrings: \n");
1398 closeRequest;
1399 return;
1400 }
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001401 datalen = sizeof(char *) * countStrings;
1402
Christopher N. Hesse65084862017-02-07 22:21:27 +01001403 pStrings = (char **)calloc(countStrings, sizeof(char *));
Sanket Padawedf3dabe2016-02-29 10:09:26 -08001404 if (pStrings == NULL) {
1405 RLOGE("Memory allocation failed for request %s",
1406 requestToString(pRI->pCI->requestNumber));
1407 closeRequest;
1408 return;
1409 }
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001410
1411 for (int i = 0 ; i < countStrings ; i++) {
1412 pStrings[i] = strdupReadString(p);
1413 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
1414 }
1415 }
1416 removeLastChar;
1417 closeRequest;
1418 printRequest(pRI->token, pRI->pCI->requestNumber);
1419
1420 rism.message.gsmMessage = pStrings;
Howard Sue32dbfd2015-01-07 15:55:57 +08001421 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001422 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Howard Sue32dbfd2015-01-07 15:55:57 +08001423 +datalen, pRI, pRI->socket_id);
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001424
1425 if (pStrings != NULL) {
1426 for (int i = 0 ; i < countStrings ; i++) {
1427#ifdef MEMSET_FREED
1428 memsetString (pStrings[i]);
1429#endif
1430 free(pStrings[i]);
1431 }
1432
1433#ifdef MEMSET_FREED
1434 memset(pStrings, 0, datalen);
1435#endif
Christopher N. Hesse65084862017-02-07 22:21:27 +01001436 free(pStrings);
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001437 }
1438
1439#ifdef MEMSET_FREED
1440 memset(&rism, 0, sizeof(rism));
1441#endif
1442 return;
1443invalid:
Christopher N. Hesse65084862017-02-07 22:21:27 +01001444 ALOGE("dispatchImsGsmSms invalid block");
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001445 invalidCommandBlock(pRI);
1446 return;
1447}
1448
1449static void
1450dispatchImsSms(Parcel &p, RequestInfo *pRI) {
1451 int32_t t;
1452 status_t status = p.readInt32(&t);
1453 RIL_RadioTechnologyFamily format;
1454 uint8_t retry;
1455 int32_t messageRef;
1456
Mark Salyzyn961fd022015-04-09 07:18:35 -07001457 RLOGD("dispatchImsSms");
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001458 if (status != NO_ERROR) {
1459 goto invalid;
1460 }
1461 format = (RIL_RadioTechnologyFamily) t;
1462
1463 // read retry field
1464 status = p.read(&retry,sizeof(retry));
1465 if (status != NO_ERROR) {
1466 goto invalid;
1467 }
1468 // read messageRef field
1469 status = p.read(&messageRef,sizeof(messageRef));
1470 if (status != NO_ERROR) {
1471 goto invalid;
1472 }
1473
1474 if (RADIO_TECH_3GPP == format) {
1475 dispatchImsGsmSms(p, pRI, retry, messageRef);
1476 } else if (RADIO_TECH_3GPP2 == format) {
1477 dispatchImsCdmaSms(p, pRI, retry, messageRef);
1478 } else {
Christopher N. Hesse65084862017-02-07 22:21:27 +01001479 ALOGE("requestImsSendSMS invalid format value =%d", format);
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001480 }
1481
1482 return;
1483
1484invalid:
1485 invalidCommandBlock(pRI);
1486 return;
1487}
1488
1489static void
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001490dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI) {
1491 RIL_CDMA_SMS_Ack rcsa;
1492 int32_t t;
1493 status_t status;
1494 int32_t digitCount;
1495
Mark Salyzyn961fd022015-04-09 07:18:35 -07001496 RLOGD("dispatchCdmaSmsAck");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001497 memset(&rcsa, 0, sizeof(rcsa));
1498
1499 status = p.readInt32(&t);
1500 rcsa.uErrorClass = (RIL_CDMA_SMS_ErrorClass) t;
1501
1502 status = p.readInt32(&t);
1503 rcsa.uSMSCauseCode = (int) t;
1504
1505 if (status != NO_ERROR) {
1506 goto invalid;
1507 }
1508
1509 startRequest;
1510 appendPrintBuf("%suErrorClass=%d, uTLStatus=%d, ",
1511 printBuf, rcsa.uErrorClass, rcsa.uSMSCauseCode);
1512 closeRequest;
1513
1514 printRequest(pRI->token, pRI->pCI->requestNumber);
1515
Howard Sue32dbfd2015-01-07 15:55:57 +08001516 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsa, sizeof(rcsa),pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001517
1518#ifdef MEMSET_FREED
1519 memset(&rcsa, 0, sizeof(rcsa));
1520#endif
1521
1522 return;
1523
1524invalid:
1525 invalidCommandBlock(pRI);
1526 return;
1527}
1528
1529static void
1530dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1531 int32_t t;
1532 status_t status;
1533 int32_t num;
1534
1535 status = p.readInt32(&num);
1536 if (status != NO_ERROR) {
1537 goto invalid;
1538 }
1539
Ethan Chend6e30652013-08-04 22:49:56 -07001540 {
1541 RIL_GSM_BroadcastSmsConfigInfo gsmBci[num];
1542 RIL_GSM_BroadcastSmsConfigInfo *gsmBciPtrs[num];
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001543
Ethan Chend6e30652013-08-04 22:49:56 -07001544 startRequest;
1545 for (int i = 0 ; i < num ; i++ ) {
1546 gsmBciPtrs[i] = &gsmBci[i];
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001547
Ethan Chend6e30652013-08-04 22:49:56 -07001548 status = p.readInt32(&t);
1549 gsmBci[i].fromServiceId = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001550
Ethan Chend6e30652013-08-04 22:49:56 -07001551 status = p.readInt32(&t);
1552 gsmBci[i].toServiceId = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001553
Ethan Chend6e30652013-08-04 22:49:56 -07001554 status = p.readInt32(&t);
1555 gsmBci[i].fromCodeScheme = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001556
Ethan Chend6e30652013-08-04 22:49:56 -07001557 status = p.readInt32(&t);
1558 gsmBci[i].toCodeScheme = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001559
Ethan Chend6e30652013-08-04 22:49:56 -07001560 status = p.readInt32(&t);
1561 gsmBci[i].selected = (uint8_t) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001562
Ethan Chend6e30652013-08-04 22:49:56 -07001563 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId =%d, \
1564 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]", printBuf, i,
1565 gsmBci[i].fromServiceId, gsmBci[i].toServiceId,
1566 gsmBci[i].fromCodeScheme, gsmBci[i].toCodeScheme,
1567 gsmBci[i].selected);
1568 }
1569 closeRequest;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001570
Ethan Chend6e30652013-08-04 22:49:56 -07001571 if (status != NO_ERROR) {
1572 goto invalid;
1573 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001574
Howard Sue32dbfd2015-01-07 15:55:57 +08001575 CALL_ONREQUEST(pRI->pCI->requestNumber,
Ethan Chend6e30652013-08-04 22:49:56 -07001576 gsmBciPtrs,
1577 num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *),
Howard Sue32dbfd2015-01-07 15:55:57 +08001578 pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001579
1580#ifdef MEMSET_FREED
Ethan Chend6e30652013-08-04 22:49:56 -07001581 memset(gsmBci, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo));
1582 memset(gsmBciPtrs, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001583#endif
Ethan Chend6e30652013-08-04 22:49:56 -07001584 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001585
1586 return;
1587
1588invalid:
1589 invalidCommandBlock(pRI);
1590 return;
1591}
1592
1593static void
1594dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1595 int32_t t;
1596 status_t status;
1597 int32_t num;
1598
1599 status = p.readInt32(&num);
1600 if (status != NO_ERROR) {
1601 goto invalid;
1602 }
1603
Ethan Chend6e30652013-08-04 22:49:56 -07001604 {
1605 RIL_CDMA_BroadcastSmsConfigInfo cdmaBci[num];
1606 RIL_CDMA_BroadcastSmsConfigInfo *cdmaBciPtrs[num];
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001607
Ethan Chend6e30652013-08-04 22:49:56 -07001608 startRequest;
1609 for (int i = 0 ; i < num ; i++ ) {
1610 cdmaBciPtrs[i] = &cdmaBci[i];
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001611
Ethan Chend6e30652013-08-04 22:49:56 -07001612 status = p.readInt32(&t);
1613 cdmaBci[i].service_category = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001614
Ethan Chend6e30652013-08-04 22:49:56 -07001615 status = p.readInt32(&t);
1616 cdmaBci[i].language = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001617
Ethan Chend6e30652013-08-04 22:49:56 -07001618 status = p.readInt32(&t);
1619 cdmaBci[i].selected = (uint8_t) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001620
Ethan Chend6e30652013-08-04 22:49:56 -07001621 appendPrintBuf("%s [%d: service_category=%d, language =%d, \
1622 entries.bSelected =%d]", printBuf, i, cdmaBci[i].service_category,
1623 cdmaBci[i].language, cdmaBci[i].selected);
1624 }
1625 closeRequest;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001626
Ethan Chend6e30652013-08-04 22:49:56 -07001627 if (status != NO_ERROR) {
1628 goto invalid;
1629 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001630
Howard Sue32dbfd2015-01-07 15:55:57 +08001631 CALL_ONREQUEST(pRI->pCI->requestNumber,
Ethan Chend6e30652013-08-04 22:49:56 -07001632 cdmaBciPtrs,
1633 num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *),
Howard Sue32dbfd2015-01-07 15:55:57 +08001634 pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001635
1636#ifdef MEMSET_FREED
Ethan Chend6e30652013-08-04 22:49:56 -07001637 memset(cdmaBci, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo));
1638 memset(cdmaBciPtrs, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001639#endif
Ethan Chend6e30652013-08-04 22:49:56 -07001640 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001641
1642 return;
1643
1644invalid:
1645 invalidCommandBlock(pRI);
1646 return;
1647}
1648
1649static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI) {
1650 RIL_CDMA_SMS_WriteArgs rcsw;
1651 int32_t t;
1652 uint32_t ut;
1653 uint8_t uct;
1654 status_t status;
1655 int32_t digitCount;
Sukanya Rajkhowa70ecc092013-10-29 14:55:30 +08001656 int32_t digitLimit;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001657
1658 memset(&rcsw, 0, sizeof(rcsw));
1659
1660 status = p.readInt32(&t);
1661 rcsw.status = t;
1662
1663 status = p.readInt32(&t);
1664 rcsw.message.uTeleserviceID = (int) t;
1665
1666 status = p.read(&uct,sizeof(uct));
1667 rcsw.message.bIsServicePresent = (uint8_t) uct;
1668
1669 status = p.readInt32(&t);
1670 rcsw.message.uServicecategory = (int) t;
1671
1672 status = p.readInt32(&t);
1673 rcsw.message.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1674
1675 status = p.readInt32(&t);
1676 rcsw.message.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1677
1678 status = p.readInt32(&t);
1679 rcsw.message.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1680
1681 status = p.readInt32(&t);
1682 rcsw.message.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1683
1684 status = p.read(&uct,sizeof(uct));
1685 rcsw.message.sAddress.number_of_digits = (uint8_t) uct;
1686
Sukanya Rajkhowa70ecc092013-10-29 14:55:30 +08001687 digitLimit = MIN((rcsw.message.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
1688
1689 for(digitCount = 0 ; digitCount < digitLimit; digitCount ++) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001690 status = p.read(&uct,sizeof(uct));
1691 rcsw.message.sAddress.digits[digitCount] = (uint8_t) uct;
1692 }
1693
1694 status = p.readInt32(&t);
1695 rcsw.message.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1696
1697 status = p.read(&uct,sizeof(uct));
1698 rcsw.message.sSubAddress.odd = (uint8_t) uct;
1699
1700 status = p.read(&uct,sizeof(uct));
1701 rcsw.message.sSubAddress.number_of_digits = (uint8_t) uct;
1702
Sukanya Rajkhowa70ecc092013-10-29 14:55:30 +08001703 digitLimit = MIN((rcsw.message.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
1704
1705 for(digitCount = 0 ; digitCount < digitLimit; digitCount ++) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001706 status = p.read(&uct,sizeof(uct));
1707 rcsw.message.sSubAddress.digits[digitCount] = (uint8_t) uct;
1708 }
1709
1710 status = p.readInt32(&t);
1711 rcsw.message.uBearerDataLen = (int) t;
1712
Sukanya Rajkhowa70ecc092013-10-29 14:55:30 +08001713 digitLimit = MIN((rcsw.message.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
1714
1715 for(digitCount = 0 ; digitCount < digitLimit; digitCount ++) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001716 status = p.read(&uct, sizeof(uct));
1717 rcsw.message.aBearerData[digitCount] = (uint8_t) uct;
1718 }
1719
1720 if (status != NO_ERROR) {
1721 goto invalid;
1722 }
1723
1724 startRequest;
1725 appendPrintBuf("%sstatus=%d, message.uTeleserviceID=%d, message.bIsServicePresent=%d, \
1726 message.uServicecategory=%d, message.sAddress.digit_mode=%d, \
1727 message.sAddress.number_mode=%d, \
1728 message.sAddress.number_type=%d, ",
1729 printBuf, rcsw.status, rcsw.message.uTeleserviceID, rcsw.message.bIsServicePresent,
1730 rcsw.message.uServicecategory, rcsw.message.sAddress.digit_mode,
1731 rcsw.message.sAddress.number_mode,
1732 rcsw.message.sAddress.number_type);
1733 closeRequest;
1734
1735 printRequest(pRI->token, pRI->pCI->requestNumber);
1736
Howard Sue32dbfd2015-01-07 15:55:57 +08001737 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsw, sizeof(rcsw),pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001738
1739#ifdef MEMSET_FREED
1740 memset(&rcsw, 0, sizeof(rcsw));
1741#endif
1742
1743 return;
1744
1745invalid:
1746 invalidCommandBlock(pRI);
1747 return;
1748
1749}
1750
Ethan Chend6e30652013-08-04 22:49:56 -07001751// For backwards compatibility in RIL_REQUEST_SETUP_DATA_CALL.
1752// Version 4 of the RIL interface adds a new PDP type parameter to support
1753// IPv6 and dual-stack PDP contexts. When dealing with a previous version of
1754// RIL, remove the parameter from the request.
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001755static void dispatchDataCall(Parcel& p, RequestInfo *pRI) {
Ethan Chend6e30652013-08-04 22:49:56 -07001756 // In RIL v3, REQUEST_SETUP_DATA_CALL takes 6 parameters.
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001757 const int numParamsRilV3 = 6;
1758
Ethan Chend6e30652013-08-04 22:49:56 -07001759 // The first bytes of the RIL parcel contain the request number and the
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001760 // serial number - see processCommandBuffer(). Copy them over too.
1761 int pos = p.dataPosition();
1762
1763 int numParams = p.readInt32();
1764 if (s_callbacks.version < 4 && numParams > numParamsRilV3) {
1765 Parcel p2;
1766 p2.appendFrom(&p, 0, pos);
1767 p2.writeInt32(numParamsRilV3);
1768 for(int i = 0; i < numParamsRilV3; i++) {
1769 p2.writeString16(p.readString16());
1770 }
1771 p2.setDataPosition(pos);
1772 dispatchStrings(p2, pRI);
1773 } else {
1774 p.setDataPosition(pos);
1775 dispatchStrings(p, pRI);
1776 }
1777}
1778
1779// For backwards compatibility with RILs that dont support RIL_REQUEST_VOICE_RADIO_TECH.
Ethan Chend6e30652013-08-04 22:49:56 -07001780// When all RILs handle this request, this function can be removed and
1781// the request can be sent directly to the RIL using dispatchVoid.
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001782static void dispatchVoiceRadioTech(Parcel& p, RequestInfo *pRI) {
Howard Sue32dbfd2015-01-07 15:55:57 +08001783 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001784
1785 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1786 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1787 }
1788
Ethan Chend6e30652013-08-04 22:49:56 -07001789 // RILs that support RADIO_STATE_ON should support this request.
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001790 if (RADIO_STATE_ON == state) {
1791 dispatchVoid(p, pRI);
1792 return;
1793 }
1794
Ethan Chend6e30652013-08-04 22:49:56 -07001795 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1796 // will not support this new request either and decode Voice Radio Technology
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001797 // from Radio State
1798 voiceRadioTech = decodeVoiceRadioTechnology(state);
1799
1800 if (voiceRadioTech < 0)
1801 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1802 else
1803 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &voiceRadioTech, sizeof(int));
1804}
1805
Ethan Chend6e30652013-08-04 22:49:56 -07001806// For backwards compatibility in RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE:.
1807// When all RILs handle this request, this function can be removed and
1808// the request can be sent directly to the RIL using dispatchVoid.
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001809static void dispatchCdmaSubscriptionSource(Parcel& p, RequestInfo *pRI) {
Howard Sue32dbfd2015-01-07 15:55:57 +08001810 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001811
1812 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1813 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1814 }
1815
1816 // RILs that support RADIO_STATE_ON should support this request.
1817 if (RADIO_STATE_ON == state) {
1818 dispatchVoid(p, pRI);
1819 return;
1820 }
1821
Ethan Chend6e30652013-08-04 22:49:56 -07001822 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001823 // will not support this new request either and decode CDMA Subscription Source
Ethan Chend6e30652013-08-04 22:49:56 -07001824 // from Radio State
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001825 cdmaSubscriptionSource = decodeCdmaSubscriptionSource(state);
1826
1827 if (cdmaSubscriptionSource < 0)
1828 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1829 else
1830 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &cdmaSubscriptionSource, sizeof(int));
1831}
1832
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001833static void dispatchSetInitialAttachApn(Parcel &p, RequestInfo *pRI)
1834{
1835 RIL_InitialAttachApn pf;
1836 int32_t t;
1837 status_t status;
1838
1839 memset(&pf, 0, sizeof(pf));
1840
1841 pf.apn = strdupReadString(p);
1842 pf.protocol = strdupReadString(p);
1843
1844 status = p.readInt32(&t);
1845 pf.authtype = (int) t;
1846
1847 pf.username = strdupReadString(p);
1848 pf.password = strdupReadString(p);
1849
1850 startRequest;
Christopher N. Hesse65084862017-02-07 22:21:27 +01001851 appendPrintBuf("%sapn=%s, protocol=%s, authtype=%d, username=%s, password=%s",
Andreas Schneidera8d09502015-06-23 18:41:38 +02001852 printBuf, pf.apn, pf.protocol, pf.authtype, pf.username, pf.password);
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001853 closeRequest;
1854 printRequest(pRI->token, pRI->pCI->requestNumber);
1855
1856 if (status != NO_ERROR) {
1857 goto invalid;
1858 }
Howard Sue32dbfd2015-01-07 15:55:57 +08001859 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001860
1861#ifdef MEMSET_FREED
1862 memsetString(pf.apn);
1863 memsetString(pf.protocol);
1864 memsetString(pf.username);
1865 memsetString(pf.password);
1866#endif
1867
1868 free(pf.apn);
1869 free(pf.protocol);
1870 free(pf.username);
1871 free(pf.password);
1872
1873#ifdef MEMSET_FREED
1874 memset(&pf, 0, sizeof(pf));
1875#endif
1876
1877 return;
1878invalid:
1879 invalidCommandBlock(pRI);
1880 return;
1881}
1882
Howard Sue32dbfd2015-01-07 15:55:57 +08001883static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI) {
1884 RIL_NV_ReadItem nvri;
1885 int32_t t;
1886 status_t status;
1887
1888 memset(&nvri, 0, sizeof(nvri));
1889
1890 status = p.readInt32(&t);
1891 nvri.itemID = (RIL_NV_Item) t;
1892
1893 if (status != NO_ERROR) {
1894 goto invalid;
1895 }
1896
1897 startRequest;
1898 appendPrintBuf("%snvri.itemID=%d, ", printBuf, nvri.itemID);
1899 closeRequest;
1900
1901 printRequest(pRI->token, pRI->pCI->requestNumber);
1902
1903 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvri, sizeof(nvri), pRI, pRI->socket_id);
1904
1905#ifdef MEMSET_FREED
1906 memset(&nvri, 0, sizeof(nvri));
1907#endif
1908
1909 return;
1910
1911invalid:
1912 invalidCommandBlock(pRI);
1913 return;
1914}
1915
1916static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI) {
1917 RIL_NV_WriteItem nvwi;
1918 int32_t t;
1919 status_t status;
1920
1921 memset(&nvwi, 0, sizeof(nvwi));
1922
1923 status = p.readInt32(&t);
1924 nvwi.itemID = (RIL_NV_Item) t;
1925
1926 nvwi.value = strdupReadString(p);
1927
1928 if (status != NO_ERROR || nvwi.value == NULL) {
1929 goto invalid;
1930 }
1931
1932 startRequest;
1933 appendPrintBuf("%snvwi.itemID=%d, value=%s, ", printBuf, nvwi.itemID,
1934 nvwi.value);
1935 closeRequest;
1936
1937 printRequest(pRI->token, pRI->pCI->requestNumber);
1938
1939 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvwi, sizeof(nvwi), pRI, pRI->socket_id);
1940
1941#ifdef MEMSET_FREED
1942 memsetString(nvwi.value);
1943#endif
1944
1945 free(nvwi.value);
1946
1947#ifdef MEMSET_FREED
1948 memset(&nvwi, 0, sizeof(nvwi));
1949#endif
1950
1951 return;
1952
1953invalid:
1954 invalidCommandBlock(pRI);
1955 return;
1956}
1957
1958
1959static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI) {
1960 RIL_SelectUiccSub uicc_sub;
1961 status_t status;
1962 int32_t t;
1963 memset(&uicc_sub, 0, sizeof(uicc_sub));
1964
1965 status = p.readInt32(&t);
1966 if (status != NO_ERROR) {
1967 goto invalid;
1968 }
1969 uicc_sub.slot = (int) t;
1970
1971 status = p.readInt32(&t);
1972 if (status != NO_ERROR) {
1973 goto invalid;
1974 }
1975 uicc_sub.app_index = (int) t;
1976
1977 status = p.readInt32(&t);
1978 if (status != NO_ERROR) {
1979 goto invalid;
1980 }
1981 uicc_sub.sub_type = (RIL_SubscriptionType) t;
1982
1983 status = p.readInt32(&t);
1984 if (status != NO_ERROR) {
1985 goto invalid;
1986 }
1987 uicc_sub.act_status = (RIL_UiccSubActStatus) t;
1988
1989 startRequest;
1990 appendPrintBuf("slot=%d, app_index=%d, act_status = %d", uicc_sub.slot, uicc_sub.app_index,
1991 uicc_sub.act_status);
1992 RLOGD("dispatchUiccSubscription, slot=%d, app_index=%d, act_status = %d", uicc_sub.slot,
1993 uicc_sub.app_index, uicc_sub.act_status);
1994 closeRequest;
1995 printRequest(pRI->token, pRI->pCI->requestNumber);
1996
1997 CALL_ONREQUEST(pRI->pCI->requestNumber, &uicc_sub, sizeof(uicc_sub), pRI, pRI->socket_id);
1998
1999#ifdef MEMSET_FREED
2000 memset(&uicc_sub, 0, sizeof(uicc_sub));
2001#endif
2002 return;
2003
2004invalid:
2005 invalidCommandBlock(pRI);
2006 return;
2007}
2008
2009static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI)
2010{
2011 RIL_SimAuthentication pf;
2012 int32_t t;
2013 status_t status;
2014
2015 memset(&pf, 0, sizeof(pf));
2016
2017 status = p.readInt32(&t);
2018 pf.authContext = (int) t;
2019 pf.authData = strdupReadString(p);
2020 pf.aid = strdupReadString(p);
2021
2022 startRequest;
Christopher N. Hesse65084862017-02-07 22:21:27 +01002023 appendPrintBuf("authContext=%s, authData=%s, aid=%s", pf.authContext, pf.authData, pf.aid);
Howard Sue32dbfd2015-01-07 15:55:57 +08002024 closeRequest;
2025 printRequest(pRI->token, pRI->pCI->requestNumber);
2026
2027 if (status != NO_ERROR) {
2028 goto invalid;
2029 }
2030 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
2031
2032#ifdef MEMSET_FREED
2033 memsetString(pf.authData);
2034 memsetString(pf.aid);
2035#endif
2036
2037 free(pf.authData);
2038 free(pf.aid);
2039
2040#ifdef MEMSET_FREED
2041 memset(&pf, 0, sizeof(pf));
2042#endif
2043
2044 return;
2045invalid:
2046 invalidCommandBlock(pRI);
2047 return;
2048}
2049
2050static void dispatchDataProfile(Parcel &p, RequestInfo *pRI) {
2051 int32_t t;
2052 status_t status;
2053 int32_t num;
2054
2055 status = p.readInt32(&num);
Christopher N. Hesse65084862017-02-07 22:21:27 +01002056 if (status != NO_ERROR || num < 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002057 goto invalid;
2058 }
2059
2060 {
Sanket Padawedf3dabe2016-02-29 10:09:26 -08002061 RIL_DataProfileInfo *dataProfiles =
Christopher N. Hesse65084862017-02-07 22:21:27 +01002062 (RIL_DataProfileInfo *)calloc(num, sizeof(RIL_DataProfileInfo));
Sanket Padawedf3dabe2016-02-29 10:09:26 -08002063 if (dataProfiles == NULL) {
2064 RLOGE("Memory allocation failed for request %s",
2065 requestToString(pRI->pCI->requestNumber));
2066 return;
2067 }
2068 RIL_DataProfileInfo **dataProfilePtrs =
Christopher N. Hesse65084862017-02-07 22:21:27 +01002069 (RIL_DataProfileInfo **)calloc(num, sizeof(RIL_DataProfileInfo *));
Sanket Padawedf3dabe2016-02-29 10:09:26 -08002070 if (dataProfilePtrs == NULL) {
2071 RLOGE("Memory allocation failed for request %s",
2072 requestToString(pRI->pCI->requestNumber));
2073 free(dataProfiles);
2074 return;
2075 }
Howard Sue32dbfd2015-01-07 15:55:57 +08002076
2077 startRequest;
2078 for (int i = 0 ; i < num ; i++ ) {
2079 dataProfilePtrs[i] = &dataProfiles[i];
2080
2081 status = p.readInt32(&t);
2082 dataProfiles[i].profileId = (int) t;
2083
2084 dataProfiles[i].apn = strdupReadString(p);
2085 dataProfiles[i].protocol = strdupReadString(p);
2086 status = p.readInt32(&t);
2087 dataProfiles[i].authType = (int) t;
2088
2089 dataProfiles[i].user = strdupReadString(p);
2090 dataProfiles[i].password = strdupReadString(p);
2091
2092 status = p.readInt32(&t);
2093 dataProfiles[i].type = (int) t;
2094
2095 status = p.readInt32(&t);
2096 dataProfiles[i].maxConnsTime = (int) t;
2097 status = p.readInt32(&t);
2098 dataProfiles[i].maxConns = (int) t;
2099 status = p.readInt32(&t);
2100 dataProfiles[i].waitTime = (int) t;
2101
2102 status = p.readInt32(&t);
2103 dataProfiles[i].enabled = (int) t;
2104
2105 appendPrintBuf("%s [%d: profileId=%d, apn =%s, protocol =%s, authType =%d, \
2106 user =%s, password =%s, type =%d, maxConnsTime =%d, maxConns =%d, \
2107 waitTime =%d, enabled =%d]", printBuf, i, dataProfiles[i].profileId,
2108 dataProfiles[i].apn, dataProfiles[i].protocol, dataProfiles[i].authType,
2109 dataProfiles[i].user, dataProfiles[i].password, dataProfiles[i].type,
2110 dataProfiles[i].maxConnsTime, dataProfiles[i].maxConns,
2111 dataProfiles[i].waitTime, dataProfiles[i].enabled);
2112 }
2113 closeRequest;
2114 printRequest(pRI->token, pRI->pCI->requestNumber);
2115
2116 if (status != NO_ERROR) {
Sanket Padawedf3dabe2016-02-29 10:09:26 -08002117 free(dataProfiles);
2118 free(dataProfilePtrs);
Howard Sue32dbfd2015-01-07 15:55:57 +08002119 goto invalid;
2120 }
2121 CALL_ONREQUEST(pRI->pCI->requestNumber,
2122 dataProfilePtrs,
2123 num * sizeof(RIL_DataProfileInfo *),
2124 pRI, pRI->socket_id);
2125
2126#ifdef MEMSET_FREED
2127 memset(dataProfiles, 0, num * sizeof(RIL_DataProfileInfo));
2128 memset(dataProfilePtrs, 0, num * sizeof(RIL_DataProfileInfo *));
2129#endif
Sanket Padawedf3dabe2016-02-29 10:09:26 -08002130 free(dataProfiles);
2131 free(dataProfilePtrs);
Howard Sue32dbfd2015-01-07 15:55:57 +08002132 }
2133
2134 return;
2135
2136invalid:
2137 invalidCommandBlock(pRI);
2138 return;
2139}
2140
Howard Subd82ef12015-04-12 10:25:05 +02002141static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI){
2142 RIL_RadioCapability rc;
2143 int32_t t;
2144 status_t status;
2145
2146 memset (&rc, 0, sizeof(RIL_RadioCapability));
2147
2148 status = p.readInt32(&t);
2149 rc.version = (int)t;
2150 if (status != NO_ERROR) {
2151 goto invalid;
2152 }
2153
2154 status = p.readInt32(&t);
2155 rc.session= (int)t;
2156 if (status != NO_ERROR) {
2157 goto invalid;
2158 }
2159
2160 status = p.readInt32(&t);
2161 rc.phase= (int)t;
2162 if (status != NO_ERROR) {
2163 goto invalid;
2164 }
2165
2166 status = p.readInt32(&t);
2167 rc.rat = (int)t;
2168 if (status != NO_ERROR) {
2169 goto invalid;
2170 }
2171
2172 status = readStringFromParcelInplace(p, rc.logicalModemUuid, sizeof(rc.logicalModemUuid));
2173 if (status != NO_ERROR) {
2174 goto invalid;
2175 }
2176
2177 status = p.readInt32(&t);
2178 rc.status = (int)t;
2179
2180 if (status != NO_ERROR) {
2181 goto invalid;
2182 }
2183
2184 startRequest;
2185 appendPrintBuf("%s [version:%d, session:%d, phase:%d, rat:%d, \
Andreas Schneidera8d09502015-06-23 18:41:38 +02002186 logicalModemUuid:%s, status:%d", printBuf, rc.version, rc.session,
Christopher N. Hesse65084862017-02-07 22:21:27 +01002187 rc.phase, rc.rat, rc.logicalModemUuid, rc.session);
Howard Subd82ef12015-04-12 10:25:05 +02002188
2189 closeRequest;
2190 printRequest(pRI->token, pRI->pCI->requestNumber);
2191
2192 CALL_ONREQUEST(pRI->pCI->requestNumber,
2193 &rc,
2194 sizeof(RIL_RadioCapability),
2195 pRI, pRI->socket_id);
2196 return;
2197invalid:
2198 invalidCommandBlock(pRI);
2199 return;
2200}
2201
Christopher N. Hesse65084862017-02-07 22:21:27 +01002202/**
2203 * Callee expects const RIL_CarrierRestrictions *
2204 */
2205static void dispatchCarrierRestrictions(Parcel &p, RequestInfo *pRI) {
2206 RIL_CarrierRestrictions cr;
2207 RIL_Carrier * allowed_carriers = NULL;
2208 RIL_Carrier * excluded_carriers = NULL;
2209 int32_t t;
2210 status_t status;
2211
2212 memset(&cr, 0, sizeof(RIL_CarrierRestrictions));
2213
2214 if (s_callbacks.version < 14) {
2215 RLOGE("Unsuppoted RIL version %d, min version expected %d",
2216 s_callbacks.version, 14);
2217 RIL_onRequestComplete(pRI, RIL_E_REQUEST_NOT_SUPPORTED, NULL, 0);
2218 return;
2219 }
2220
2221 status = p.readInt32(&t);
2222 if (status != NO_ERROR) {
2223 goto invalid;
2224 }
2225 allowed_carriers = (RIL_Carrier *)calloc(t, sizeof(RIL_Carrier));
2226 if (allowed_carriers == NULL) {
2227 RLOGE("Memory allocation failed for request %s", requestToString(pRI->pCI->requestNumber));
2228 goto exit;
2229 }
2230 cr.len_allowed_carriers = t;
2231 cr.allowed_carriers = allowed_carriers;
2232
2233 status = p.readInt32(&t);
2234 if (status != NO_ERROR) {
2235 goto invalid;
2236 }
2237 excluded_carriers = (RIL_Carrier *)calloc(t, sizeof(RIL_Carrier));
2238 if (excluded_carriers == NULL) {
2239 RLOGE("Memory allocation failed for request %s", requestToString(pRI->pCI->requestNumber));
2240 goto exit;
2241 }
2242 cr.len_excluded_carriers = t;
2243 cr.excluded_carriers = excluded_carriers;
2244
2245 startRequest;
2246 appendPrintBuf("%s len_allowed_carriers:%d, len_excluded_carriers:%d,",
2247 printBuf, cr.len_allowed_carriers, cr.len_excluded_carriers);
2248
2249 appendPrintBuf("%s allowed_carriers:", printBuf);
2250 for (int32_t i = 0; i < cr.len_allowed_carriers; i++) {
2251 RIL_Carrier *p_cr = allowed_carriers + i;
2252 p_cr->mcc = strdupReadString(p);
2253 p_cr->mnc = strdupReadString(p);
2254 status = p.readInt32(&t);
2255 p_cr->match_type = static_cast<RIL_CarrierMatchType>(t);
2256 if (status != NO_ERROR) {
2257 goto invalid;
2258 }
2259 p_cr->match_data = strdupReadString(p);
2260 appendPrintBuf("%s [%d mcc:%s, mnc:%s, match_type:%d, match_data:%s],",
2261 printBuf, i, p_cr->mcc, p_cr->mnc, p_cr->match_type, p_cr->match_data);
2262 }
2263
2264 for (int32_t i = 0; i < cr.len_excluded_carriers; i++) {
2265 RIL_Carrier *p_cr = excluded_carriers + i;
2266 p_cr->mcc = strdupReadString(p);
2267 p_cr->mnc = strdupReadString(p);
2268 status = p.readInt32(&t);
2269 p_cr->match_type = static_cast<RIL_CarrierMatchType>(t);
2270 if (status != NO_ERROR) {
2271 goto invalid;
2272 }
2273 p_cr->match_data = strdupReadString(p);
2274 appendPrintBuf("%s [%d mcc:%s, mnc:%s, match_type:%d, match_data:%s],",
2275 printBuf, i, p_cr->mcc, p_cr->mnc, p_cr->match_type, p_cr->match_data);
2276 }
2277
2278 closeRequest;
2279 printRequest(pRI->token, pRI->pCI->requestNumber);
2280
2281 CALL_ONREQUEST(pRI->pCI->requestNumber,
2282 &cr,
2283 sizeof(RIL_CarrierRestrictions),
2284 pRI, pRI->socket_id);
2285
2286 goto exit;
2287
2288invalid:
2289 invalidCommandBlock(pRI);
2290 RIL_onRequestComplete(pRI, RIL_E_INVALID_ARGUMENTS, NULL, 0);
2291exit:
2292 if (allowed_carriers != NULL) {
2293 free(allowed_carriers);
2294 }
2295 if (excluded_carriers != NULL) {
2296 free(excluded_carriers);
2297 }
2298 return;
2299}
2300
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002301static int
2302blockingWrite(int fd, const void *buffer, size_t len) {
2303 size_t writeOffset = 0;
2304 const uint8_t *toWrite;
2305
2306 toWrite = (const uint8_t *)buffer;
2307
2308 while (writeOffset < len) {
2309 ssize_t written;
2310 do {
2311 written = write (fd, toWrite + writeOffset,
2312 len - writeOffset);
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002313 } while (written < 0 && ((errno == EINTR) || (errno == EAGAIN)));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002314
2315 if (written >= 0) {
2316 writeOffset += written;
2317 } else { // written < 0
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002318 RLOGE ("RIL Response: unexpected error on write errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002319 close(fd);
2320 return -1;
2321 }
2322 }
Robert Greenwaltbc29c432015-04-29 16:57:39 -07002323#if VDBG
Dheeraj Shettycc231012014-07-02 21:27:57 +02002324 RLOGE("RIL Response bytes written:%d", writeOffset);
Robert Greenwaltbc29c432015-04-29 16:57:39 -07002325#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002326 return 0;
2327}
2328
2329static int
Howard Sue32dbfd2015-01-07 15:55:57 +08002330sendResponseRaw (const void *data, size_t dataSize, RIL_SOCKET_ID socket_id) {
2331 int fd = s_ril_param_socket.fdCommand;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002332 int ret;
2333 uint32_t header;
Howard Sue32dbfd2015-01-07 15:55:57 +08002334 pthread_mutex_t * writeMutexHook = &s_writeMutex;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002335
Robert Greenwaltbc29c432015-04-29 16:57:39 -07002336#if VDBG
Christopher N. Hesse65084862017-02-07 22:21:27 +01002337 RLOGE("Send Response to %s", rilSocketIdToString(socket_id));
Robert Greenwaltbc29c432015-04-29 16:57:39 -07002338#endif
Howard Sue32dbfd2015-01-07 15:55:57 +08002339
2340#if (SIM_COUNT >= 2)
2341 if (socket_id == RIL_SOCKET_2) {
2342 fd = s_ril_param_socket2.fdCommand;
2343 writeMutexHook = &s_writeMutex_socket2;
2344 }
2345#if (SIM_COUNT >= 3)
2346 else if (socket_id == RIL_SOCKET_3) {
2347 fd = s_ril_param_socket3.fdCommand;
2348 writeMutexHook = &s_writeMutex_socket3;
2349 }
2350#endif
2351#if (SIM_COUNT >= 4)
2352 else if (socket_id == RIL_SOCKET_4) {
2353 fd = s_ril_param_socket4.fdCommand;
2354 writeMutexHook = &s_writeMutex_socket4;
2355 }
2356#endif
2357#endif
2358 if (fd < 0) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002359 return -1;
2360 }
2361
Howard Subd82ef12015-04-12 10:25:05 +02002362 if (dataSize > MAX_COMMAND_BYTES) {
2363 RLOGE("RIL: packet larger than %u (%u)",
2364 MAX_COMMAND_BYTES, (unsigned int )dataSize);
2365
2366 return -1;
2367 }
2368
Howard Sue32dbfd2015-01-07 15:55:57 +08002369 pthread_mutex_lock(writeMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002370
2371 header = htonl(dataSize);
2372
2373 ret = blockingWrite(fd, (void *)&header, sizeof(header));
2374
2375 if (ret < 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002376 pthread_mutex_unlock(writeMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002377 return ret;
2378 }
2379
2380 ret = blockingWrite(fd, data, dataSize);
2381
2382 if (ret < 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002383 pthread_mutex_unlock(writeMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002384 return ret;
2385 }
2386
Howard Sue32dbfd2015-01-07 15:55:57 +08002387 pthread_mutex_unlock(writeMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002388
2389 return 0;
2390}
2391
2392static int
Howard Sue32dbfd2015-01-07 15:55:57 +08002393sendResponse (Parcel &p, RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002394 printResponse;
Howard Sue32dbfd2015-01-07 15:55:57 +08002395 return sendResponseRaw(p.data(), p.dataSize(), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002396}
2397
Howard Sue32dbfd2015-01-07 15:55:57 +08002398/** response is an int* pointing to an array of ints */
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002399
2400static int
2401responseInts(Parcel &p, void *response, size_t responselen) {
2402 int numInts;
2403
2404 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002405 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002406 return RIL_ERRNO_INVALID_RESPONSE;
2407 }
2408 if (responselen % sizeof(int) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002409 RLOGE("responseInts: invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002410 (int)responselen, (int)sizeof(int));
2411 return RIL_ERRNO_INVALID_RESPONSE;
2412 }
2413
2414 int *p_int = (int *) response;
2415
Howard Sue32dbfd2015-01-07 15:55:57 +08002416 numInts = responselen / sizeof(int);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002417 p.writeInt32 (numInts);
2418
2419 /* each int*/
2420 startResponse;
2421 for (int i = 0 ; i < numInts ; i++) {
2422 appendPrintBuf("%s%d,", printBuf, p_int[i]);
2423 p.writeInt32(p_int[i]);
2424 }
2425 removeLastChar;
2426 closeResponse;
2427
2428 return 0;
2429}
2430
Christopher N. Hesse65084862017-02-07 22:21:27 +01002431// Response is an int or RIL_LastCallFailCauseInfo.
2432// Currently, only Shamu plans to use RIL_LastCallFailCauseInfo.
2433// TODO(yjl): Let all implementations use RIL_LastCallFailCauseInfo.
2434static int responseFailCause(Parcel &p, void *response, size_t responselen) {
Daniel Hillenbrandd0b84162015-04-12 11:53:23 +02002435 int numInts;
2436
2437 if (response == NULL && responselen != 0) {
2438 RLOGE("invalid response: NULL");
2439 return RIL_ERRNO_INVALID_RESPONSE;
2440 }
Christopher N. Hesse65084862017-02-07 22:21:27 +01002441 if (responselen == sizeof(int)) {
2442 startResponse;
2443 int *p_int = (int *) response;
2444 appendPrintBuf("%s%d,", printBuf, p_int[0]);
2445 p.writeInt32(p_int[0]);
2446 removeLastChar;
2447 closeResponse;
2448 } else if (responselen == sizeof(RIL_LastCallFailCauseInfo)) {
2449 startResponse;
2450 RIL_LastCallFailCauseInfo *p_fail_cause_info = (RIL_LastCallFailCauseInfo *) response;
2451 appendPrintBuf("%s[cause_code=%d,vendor_cause=%s]", printBuf, p_fail_cause_info->cause_code,
2452 p_fail_cause_info->vendor_cause);
2453 p.writeInt32(p_fail_cause_info->cause_code);
2454 writeStringToParcel(p, p_fail_cause_info->vendor_cause);
2455 removeLastChar;
2456 closeResponse;
2457 } else {
2458 RLOGE("responseFailCause: invalid response length %d expected an int or "
2459 "RIL_LastCallFailCauseInfo", (int)responselen);
2460 return RIL_ERRNO_INVALID_RESPONSE;
Daniel Hillenbrandd0b84162015-04-12 11:53:23 +02002461 }
2462
Daniel Hillenbrandd0b84162015-04-12 11:53:23 +02002463 return 0;
2464}
2465
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002466/** response is a char **, pointing to an array of char *'s
2467 The parcel will begin with the version */
2468static int responseStringsWithVersion(int version, Parcel &p, void *response, size_t responselen) {
2469 p.writeInt32(version);
2470 return responseStrings(p, response, responselen);
2471}
2472
2473/** response is a char **, pointing to an array of char *'s */
2474static int responseStrings(Parcel &p, void *response, size_t responselen) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002475 int numStrings;
2476
2477 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002478 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002479 return RIL_ERRNO_INVALID_RESPONSE;
2480 }
2481 if (responselen % sizeof(char *) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002482 RLOGE("responseStrings: invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002483 (int)responselen, (int)sizeof(char *));
2484 return RIL_ERRNO_INVALID_RESPONSE;
2485 }
2486
2487 if (response == NULL) {
2488 p.writeInt32 (0);
2489 } else {
2490 char **p_cur = (char **) response;
2491
2492 numStrings = responselen / sizeof(char *);
Dheeraj CVR48d3f722016-10-04 11:10:55 +04002493 p.writeInt32 (numStrings);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002494
2495 /* each string*/
2496 startResponse;
2497 for (int i = 0 ; i < numStrings ; i++) {
2498 appendPrintBuf("%s%s,", printBuf, (char*)p_cur[i]);
2499 writeStringToParcel (p, p_cur[i]);
2500 }
2501 removeLastChar;
2502 closeResponse;
2503 }
2504 return 0;
2505}
2506
Howard Subd82ef12015-04-12 10:25:05 +02002507
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002508/**
2509 * NULL strings are accepted
2510 * FIXME currently ignores responselen
2511 */
2512static int responseString(Parcel &p, void *response, size_t responselen) {
2513 /* one string only */
2514 startResponse;
2515 appendPrintBuf("%s%s", printBuf, (char*)response);
2516 closeResponse;
2517
2518 writeStringToParcel(p, (const char *)response);
2519
2520 return 0;
2521}
2522
2523static int responseVoid(Parcel &p, void *response, size_t responselen) {
2524 startResponse;
2525 removeLastChar;
2526 return 0;
2527}
2528
2529static int responseCallList(Parcel &p, void *response, size_t responselen) {
2530 int num;
2531
2532 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002533 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002534 return RIL_ERRNO_INVALID_RESPONSE;
2535 }
2536
2537 if (responselen % sizeof (RIL_Call *) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002538 RLOGE("responseCallList: invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002539 (int)responselen, (int)sizeof (RIL_Call *));
2540 return RIL_ERRNO_INVALID_RESPONSE;
2541 }
2542
2543 startResponse;
2544 /* number of call info's */
2545 num = responselen / sizeof(RIL_Call *);
2546 p.writeInt32(num);
2547
2548 for (int i = 0 ; i < num ; i++) {
2549 RIL_Call *p_cur = ((RIL_Call **) response)[i];
2550 /* each call info */
2551 p.writeInt32(p_cur->state);
2552 p.writeInt32(p_cur->index);
2553 p.writeInt32(p_cur->toa);
2554 p.writeInt32(p_cur->isMpty);
2555 p.writeInt32(p_cur->isMT);
2556 p.writeInt32(p_cur->als);
2557 p.writeInt32(p_cur->isVoice);
Andreas Schneider29472682015-01-01 19:00:04 +01002558
Christopher N. Hesse621e63e2016-02-22 21:57:39 +01002559#ifdef NEEDS_VIDEO_CALL_FIELD
Andreas Schneider29472682015-01-01 19:00:04 +01002560 p.writeInt32(p_cur->isVideo);
Sayd1052772015-12-13 17:25:01 +09002561#endif
Andreas Schneider29472682015-01-01 19:00:04 +01002562
Christopher N. Hesse621e63e2016-02-22 21:57:39 +01002563#ifdef SAMSUNG_NEXT_GEN_MODEM
Andreas Schneider29472682015-01-01 19:00:04 +01002564 /* Pass CallDetails */
2565 p.writeInt32(0);
2566 p.writeInt32(0);
2567 writeStringToParcel(p, "");
2568#endif
2569
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002570 p.writeInt32(p_cur->isVoicePrivacy);
2571 writeStringToParcel(p, p_cur->number);
2572 p.writeInt32(p_cur->numberPresentation);
2573 writeStringToParcel(p, p_cur->name);
2574 p.writeInt32(p_cur->namePresentation);
2575 // Remove when partners upgrade to version 3
2576 if ((s_callbacks.version < 3) || (p_cur->uusInfo == NULL || p_cur->uusInfo->uusData == NULL)) {
2577 p.writeInt32(0); /* UUS Information is absent */
2578 } else {
2579 RIL_UUS_Info *uusInfo = p_cur->uusInfo;
2580 p.writeInt32(1); /* UUS Information is present */
2581 p.writeInt32(uusInfo->uusType);
2582 p.writeInt32(uusInfo->uusDcs);
2583 p.writeInt32(uusInfo->uusLength);
2584 p.write(uusInfo->uusData, uusInfo->uusLength);
2585 }
2586 appendPrintBuf("%s[id=%d,%s,toa=%d,",
2587 printBuf,
2588 p_cur->index,
2589 callStateToString(p_cur->state),
2590 p_cur->toa);
2591 appendPrintBuf("%s%s,%s,als=%d,%s,%s,",
2592 printBuf,
2593 (p_cur->isMpty)?"conf":"norm",
2594 (p_cur->isMT)?"mt":"mo",
2595 p_cur->als,
2596 (p_cur->isVoice)?"voc":"nonvoc",
2597 (p_cur->isVoicePrivacy)?"evp":"noevp");
Christopher N. Hesse621e63e2016-02-22 21:57:39 +01002598#ifdef SAMSUNG_NEXT_GEN_MODEM
Andreas Schneider29472682015-01-01 19:00:04 +01002599 appendPrintBuf("%s,%s,",
2600 printBuf,
2601 (p_cur->isVideo) ? "vid" : "novid");
2602#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002603 appendPrintBuf("%s%s,cli=%d,name='%s',%d]",
2604 printBuf,
2605 p_cur->number,
2606 p_cur->numberPresentation,
2607 p_cur->name,
2608 p_cur->namePresentation);
2609 }
2610 removeLastChar;
2611 closeResponse;
2612
2613 return 0;
2614}
2615
2616static int responseSMS(Parcel &p, void *response, size_t responselen) {
2617 if (response == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002618 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002619 return RIL_ERRNO_INVALID_RESPONSE;
2620 }
2621
2622 if (responselen != sizeof (RIL_SMS_Response) ) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002623 RLOGE("invalid response length %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002624 (int)responselen, (int)sizeof (RIL_SMS_Response));
2625 return RIL_ERRNO_INVALID_RESPONSE;
2626 }
2627
2628 RIL_SMS_Response *p_cur = (RIL_SMS_Response *) response;
2629
2630 p.writeInt32(p_cur->messageRef);
2631 writeStringToParcel(p, p_cur->ackPDU);
2632 p.writeInt32(p_cur->errorCode);
2633
2634 startResponse;
2635 appendPrintBuf("%s%d,%s,%d", printBuf, p_cur->messageRef,
2636 (char*)p_cur->ackPDU, p_cur->errorCode);
2637 closeResponse;
2638
2639 return 0;
2640}
2641
2642static int responseDataCallListV4(Parcel &p, void *response, size_t responselen)
2643{
2644 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002645 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002646 return RIL_ERRNO_INVALID_RESPONSE;
2647 }
2648
2649 if (responselen % sizeof(RIL_Data_Call_Response_v4) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002650 RLOGE("responseDataCallListV4: invalid response length %d expected multiple of %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002651 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v4));
2652 return RIL_ERRNO_INVALID_RESPONSE;
2653 }
2654
Howard Sue32dbfd2015-01-07 15:55:57 +08002655 // Write version
2656 p.writeInt32(4);
2657
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002658 int num = responselen / sizeof(RIL_Data_Call_Response_v4);
2659 p.writeInt32(num);
2660
2661 RIL_Data_Call_Response_v4 *p_cur = (RIL_Data_Call_Response_v4 *) response;
2662 startResponse;
2663 int i;
2664 for (i = 0; i < num; i++) {
2665 p.writeInt32(p_cur[i].cid);
2666 p.writeInt32(p_cur[i].active);
2667 writeStringToParcel(p, p_cur[i].type);
2668 // apn is not used, so don't send.
2669 writeStringToParcel(p, p_cur[i].address);
2670 appendPrintBuf("%s[cid=%d,%s,%s,%s],", printBuf,
2671 p_cur[i].cid,
2672 (p_cur[i].active==0)?"down":"up",
2673 (char*)p_cur[i].type,
2674 (char*)p_cur[i].address);
2675 }
2676 removeLastChar;
2677 closeResponse;
2678
2679 return 0;
2680}
2681
Howard Sue32dbfd2015-01-07 15:55:57 +08002682static int responseDataCallListV6(Parcel &p, void *response, size_t responselen)
2683{
2684 if (response == NULL && responselen != 0) {
2685 RLOGE("invalid response: NULL");
2686 return RIL_ERRNO_INVALID_RESPONSE;
2687 }
2688
2689 if (responselen % sizeof(RIL_Data_Call_Response_v6) != 0) {
2690 RLOGE("responseDataCallListV6: invalid response length %d expected multiple of %d",
2691 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v6));
2692 return RIL_ERRNO_INVALID_RESPONSE;
2693 }
2694
2695 // Write version
2696 p.writeInt32(6);
2697
2698 int num = responselen / sizeof(RIL_Data_Call_Response_v6);
2699 p.writeInt32(num);
2700
2701 RIL_Data_Call_Response_v6 *p_cur = (RIL_Data_Call_Response_v6 *) response;
2702 startResponse;
2703 int i;
2704 for (i = 0; i < num; i++) {
2705 p.writeInt32((int)p_cur[i].status);
2706 p.writeInt32(p_cur[i].suggestedRetryTime);
2707 p.writeInt32(p_cur[i].cid);
2708 p.writeInt32(p_cur[i].active);
2709 writeStringToParcel(p, p_cur[i].type);
2710 writeStringToParcel(p, p_cur[i].ifname);
2711 writeStringToParcel(p, p_cur[i].addresses);
2712 writeStringToParcel(p, p_cur[i].dnses);
Christopher N. Hesse65084862017-02-07 22:21:27 +01002713 writeStringToParcel(p, p_cur[i].gateways);
Howard Sue32dbfd2015-01-07 15:55:57 +08002714 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s],", printBuf,
2715 p_cur[i].status,
2716 p_cur[i].suggestedRetryTime,
2717 p_cur[i].cid,
2718 (p_cur[i].active==0)?"down":"up",
2719 (char*)p_cur[i].type,
2720 (char*)p_cur[i].ifname,
2721 (char*)p_cur[i].addresses,
2722 (char*)p_cur[i].dnses,
Christopher N. Hesse65084862017-02-07 22:21:27 +01002723 (char*)p_cur[i].gateways);
Howard Sue32dbfd2015-01-07 15:55:57 +08002724 }
2725 removeLastChar;
2726 closeResponse;
2727
2728 return 0;
2729}
2730
Howard Subd82ef12015-04-12 10:25:05 +02002731static int responseDataCallListV9(Parcel &p, void *response, size_t responselen)
2732{
2733 if (response == NULL && responselen != 0) {
2734 RLOGE("invalid response: NULL");
2735 return RIL_ERRNO_INVALID_RESPONSE;
2736 }
2737
2738 if (responselen % sizeof(RIL_Data_Call_Response_v9) != 0) {
2739 RLOGE("responseDataCallListV9: invalid response length %d expected multiple of %d",
2740 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v9));
2741 return RIL_ERRNO_INVALID_RESPONSE;
2742 }
2743
2744 // Write version
2745 p.writeInt32(10);
2746
2747 int num = responselen / sizeof(RIL_Data_Call_Response_v9);
2748 p.writeInt32(num);
2749
2750 RIL_Data_Call_Response_v9 *p_cur = (RIL_Data_Call_Response_v9 *) response;
2751 startResponse;
2752 int i;
2753 for (i = 0; i < num; i++) {
2754 p.writeInt32((int)p_cur[i].status);
2755 p.writeInt32(p_cur[i].suggestedRetryTime);
2756 p.writeInt32(p_cur[i].cid);
2757 p.writeInt32(p_cur[i].active);
2758 writeStringToParcel(p, p_cur[i].type);
2759 writeStringToParcel(p, p_cur[i].ifname);
2760 writeStringToParcel(p, p_cur[i].addresses);
2761 writeStringToParcel(p, p_cur[i].dnses);
2762 writeStringToParcel(p, p_cur[i].gateways);
2763 writeStringToParcel(p, p_cur[i].pcscf);
2764 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s],", printBuf,
2765 p_cur[i].status,
2766 p_cur[i].suggestedRetryTime,
2767 p_cur[i].cid,
2768 (p_cur[i].active==0)?"down":"up",
2769 (char*)p_cur[i].type,
2770 (char*)p_cur[i].ifname,
2771 (char*)p_cur[i].addresses,
2772 (char*)p_cur[i].dnses,
2773 (char*)p_cur[i].gateways,
2774 (char*)p_cur[i].pcscf);
2775 }
2776 removeLastChar;
2777 closeResponse;
2778
2779 return 0;
2780}
2781
Sanket Padawe9343e872016-01-11 12:45:43 -08002782static int responseDataCallListV11(Parcel &p, void *response, size_t responselen) {
2783 if (response == NULL && responselen != 0) {
2784 RLOGE("invalid response: NULL");
2785 return RIL_ERRNO_INVALID_RESPONSE;
2786 }
2787
2788 if (responselen % sizeof(RIL_Data_Call_Response_v11) != 0) {
2789 RLOGE("invalid response length %d expected multiple of %d",
2790 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v11));
2791 return RIL_ERRNO_INVALID_RESPONSE;
2792 }
2793
2794 // Write version
2795 p.writeInt32(11);
2796
2797 int num = responselen / sizeof(RIL_Data_Call_Response_v11);
2798 p.writeInt32(num);
2799
2800 RIL_Data_Call_Response_v11 *p_cur = (RIL_Data_Call_Response_v11 *) response;
2801 startResponse;
2802 int i;
2803 for (i = 0; i < num; i++) {
2804 p.writeInt32((int)p_cur[i].status);
2805 p.writeInt32(p_cur[i].suggestedRetryTime);
2806 p.writeInt32(p_cur[i].cid);
2807 p.writeInt32(p_cur[i].active);
2808 writeStringToParcel(p, p_cur[i].type);
2809 writeStringToParcel(p, p_cur[i].ifname);
2810 writeStringToParcel(p, p_cur[i].addresses);
2811 writeStringToParcel(p, p_cur[i].dnses);
2812 writeStringToParcel(p, p_cur[i].gateways);
2813 writeStringToParcel(p, p_cur[i].pcscf);
2814 p.writeInt32(p_cur[i].mtu);
2815 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s,mtu=%d],", printBuf,
2816 p_cur[i].status,
2817 p_cur[i].suggestedRetryTime,
2818 p_cur[i].cid,
2819 (p_cur[i].active==0)?"down":"up",
2820 (char*)p_cur[i].type,
2821 (char*)p_cur[i].ifname,
2822 (char*)p_cur[i].addresses,
2823 (char*)p_cur[i].dnses,
2824 (char*)p_cur[i].gateways,
2825 (char*)p_cur[i].pcscf,
2826 p_cur[i].mtu);
2827 }
2828 removeLastChar;
2829 closeResponse;
2830
2831 return 0;
2832}
Howard Subd82ef12015-04-12 10:25:05 +02002833
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002834static int responseDataCallList(Parcel &p, void *response, size_t responselen)
2835{
Sanket Padawe9343e872016-01-11 12:45:43 -08002836 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
2837 if (s_callbacks.version < 5) {
2838 RLOGD("responseDataCallList: v4");
2839 return responseDataCallListV4(p, response, responselen);
2840 } else if (responselen % sizeof(RIL_Data_Call_Response_v6) == 0) {
2841 return responseDataCallListV6(p, response, responselen);
2842 } else if (responselen % sizeof(RIL_Data_Call_Response_v9) == 0) {
2843 return responseDataCallListV9(p, response, responselen);
2844 } else {
2845 return responseDataCallListV11(p, response, responselen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002846 }
Sanket Padawea79128a2016-01-26 18:44:01 -08002847 } else { // RIL version >= 13
Howard Subd82ef12015-04-12 10:25:05 +02002848 if (responselen % sizeof(RIL_Data_Call_Response_v11) != 0) {
Sanket Padawe9343e872016-01-11 12:45:43 -08002849 RLOGE("Data structure expected is RIL_Data_Call_Response_v11");
2850 if (!isDebuggable()) {
2851 return RIL_ERRNO_INVALID_RESPONSE;
2852 } else {
2853 assert(0);
2854 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002855 }
Sanket Padawe9343e872016-01-11 12:45:43 -08002856 return responseDataCallListV11(p, response, responselen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002857 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002858}
2859
2860static int responseSetupDataCall(Parcel &p, void *response, size_t responselen)
2861{
2862 if (s_callbacks.version < 5) {
2863 return responseStringsWithVersion(s_callbacks.version, p, response, responselen);
2864 } else {
2865 return responseDataCallList(p, response, responselen);
2866 }
2867}
2868
2869static int responseRaw(Parcel &p, void *response, size_t responselen) {
2870 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002871 RLOGE("invalid response: NULL with responselen != 0");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002872 return RIL_ERRNO_INVALID_RESPONSE;
2873 }
2874
2875 // The java code reads -1 size as null byte array
2876 if (response == NULL) {
2877 p.writeInt32(-1);
2878 } else {
2879 p.writeInt32(responselen);
2880 p.write(response, responselen);
2881 }
2882
2883 return 0;
2884}
2885
2886
2887static int responseSIM_IO(Parcel &p, void *response, size_t responselen) {
2888 if (response == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002889 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002890 return RIL_ERRNO_INVALID_RESPONSE;
2891 }
2892
2893 if (responselen != sizeof (RIL_SIM_IO_Response) ) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002894 RLOGE("invalid response length was %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002895 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
2896 return RIL_ERRNO_INVALID_RESPONSE;
2897 }
2898
2899 RIL_SIM_IO_Response *p_cur = (RIL_SIM_IO_Response *) response;
2900 p.writeInt32(p_cur->sw1);
2901 p.writeInt32(p_cur->sw2);
2902 writeStringToParcel(p, p_cur->simResponse);
2903
2904 startResponse;
2905 appendPrintBuf("%ssw1=0x%X,sw2=0x%X,%s", printBuf, p_cur->sw1, p_cur->sw2,
2906 (char*)p_cur->simResponse);
2907 closeResponse;
2908
2909
2910 return 0;
2911}
2912
2913static int responseCallForwards(Parcel &p, void *response, size_t responselen) {
2914 int num;
2915
2916 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002917 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002918 return RIL_ERRNO_INVALID_RESPONSE;
2919 }
2920
2921 if (responselen % sizeof(RIL_CallForwardInfo *) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002922 RLOGE("responseCallForwards: invalid response length %d expected multiple of %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002923 (int)responselen, (int)sizeof(RIL_CallForwardInfo *));
2924 return RIL_ERRNO_INVALID_RESPONSE;
2925 }
2926
2927 /* number of call info's */
2928 num = responselen / sizeof(RIL_CallForwardInfo *);
2929 p.writeInt32(num);
2930
2931 startResponse;
2932 for (int i = 0 ; i < num ; i++) {
2933 RIL_CallForwardInfo *p_cur = ((RIL_CallForwardInfo **) response)[i];
2934
2935 p.writeInt32(p_cur->status);
2936 p.writeInt32(p_cur->reason);
2937 p.writeInt32(p_cur->serviceClass);
2938 p.writeInt32(p_cur->toa);
2939 writeStringToParcel(p, p_cur->number);
2940 p.writeInt32(p_cur->timeSeconds);
2941 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
2942 (p_cur->status==1)?"enable":"disable",
2943 p_cur->reason, p_cur->serviceClass, p_cur->toa,
2944 (char*)p_cur->number,
2945 p_cur->timeSeconds);
2946 }
2947 removeLastChar;
2948 closeResponse;
2949
2950 return 0;
2951}
2952
2953static int responseSsn(Parcel &p, void *response, size_t responselen) {
2954 if (response == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002955 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002956 return RIL_ERRNO_INVALID_RESPONSE;
2957 }
2958
2959 if (responselen != sizeof(RIL_SuppSvcNotification)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002960 RLOGE("invalid response length was %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002961 (int)responselen, (int)sizeof (RIL_SuppSvcNotification));
2962 return RIL_ERRNO_INVALID_RESPONSE;
2963 }
2964
2965 RIL_SuppSvcNotification *p_cur = (RIL_SuppSvcNotification *) response;
2966 p.writeInt32(p_cur->notificationType);
2967 p.writeInt32(p_cur->code);
2968 p.writeInt32(p_cur->index);
2969 p.writeInt32(p_cur->type);
2970 writeStringToParcel(p, p_cur->number);
2971
2972 startResponse;
2973 appendPrintBuf("%s%s,code=%d,id=%d,type=%d,%s", printBuf,
2974 (p_cur->notificationType==0)?"mo":"mt",
2975 p_cur->code, p_cur->index, p_cur->type,
2976 (char*)p_cur->number);
2977 closeResponse;
2978
2979 return 0;
2980}
2981
2982static int responseCellList(Parcel &p, void *response, size_t responselen) {
2983 int num;
2984
2985 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002986 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002987 return RIL_ERRNO_INVALID_RESPONSE;
2988 }
2989
2990 if (responselen % sizeof (RIL_NeighboringCell *) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002991 RLOGE("responseCellList: invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002992 (int)responselen, (int)sizeof (RIL_NeighboringCell *));
2993 return RIL_ERRNO_INVALID_RESPONSE;
2994 }
2995
2996 startResponse;
2997 /* number of records */
2998 num = responselen / sizeof(RIL_NeighboringCell *);
2999 p.writeInt32(num);
3000
3001 for (int i = 0 ; i < num ; i++) {
3002 RIL_NeighboringCell *p_cur = ((RIL_NeighboringCell **) response)[i];
3003
3004 p.writeInt32(p_cur->rssi);
3005 writeStringToParcel (p, p_cur->cid);
3006
3007 appendPrintBuf("%s[cid=%s,rssi=%d],", printBuf,
3008 p_cur->cid, p_cur->rssi);
3009 }
3010 removeLastChar;
3011 closeResponse;
3012
3013 return 0;
3014}
3015
3016/**
3017 * Marshall the signalInfoRecord into the parcel if it exists.
3018 */
3019static void marshallSignalInfoRecord(Parcel &p,
3020 RIL_CDMA_SignalInfoRecord &p_signalInfoRecord) {
3021 p.writeInt32(p_signalInfoRecord.isPresent);
3022 p.writeInt32(p_signalInfoRecord.signalType);
3023 p.writeInt32(p_signalInfoRecord.alertPitch);
3024 p.writeInt32(p_signalInfoRecord.signal);
3025}
3026
3027static int responseCdmaInformationRecords(Parcel &p,
3028 void *response, size_t responselen) {
3029 int num;
3030 char* string8 = NULL;
3031 int buffer_lenght;
3032 RIL_CDMA_InformationRecord *infoRec;
3033
3034 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003035 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003036 return RIL_ERRNO_INVALID_RESPONSE;
3037 }
3038
3039 if (responselen != sizeof (RIL_CDMA_InformationRecords)) {
Howard Sue32dbfd2015-01-07 15:55:57 +08003040 RLOGE("responseCdmaInformationRecords: invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003041 (int)responselen, (int)sizeof (RIL_CDMA_InformationRecords *));
3042 return RIL_ERRNO_INVALID_RESPONSE;
3043 }
3044
3045 RIL_CDMA_InformationRecords *p_cur =
3046 (RIL_CDMA_InformationRecords *) response;
3047 num = MIN(p_cur->numberOfInfoRecs, RIL_CDMA_MAX_NUMBER_OF_INFO_RECS);
3048
3049 startResponse;
3050 p.writeInt32(num);
3051
3052 for (int i = 0 ; i < num ; i++) {
3053 infoRec = &p_cur->infoRec[i];
3054 p.writeInt32(infoRec->name);
3055 switch (infoRec->name) {
3056 case RIL_CDMA_DISPLAY_INFO_REC:
3057 case RIL_CDMA_EXTENDED_DISPLAY_INFO_REC:
3058 if (infoRec->rec.display.alpha_len >
3059 CDMA_ALPHA_INFO_BUFFER_LENGTH) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003060 RLOGE("invalid display info response length %d \
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003061 expected not more than %d\n",
3062 (int)infoRec->rec.display.alpha_len,
3063 CDMA_ALPHA_INFO_BUFFER_LENGTH);
3064 return RIL_ERRNO_INVALID_RESPONSE;
3065 }
Christopher N. Hesse65084862017-02-07 22:21:27 +01003066 string8 = (char*) calloc(infoRec->rec.display.alpha_len + 1, sizeof(char));
Sanket Padawedf3dabe2016-02-29 10:09:26 -08003067 if (string8 == NULL) {
3068 RLOGE("Memory allocation failed for responseCdmaInformationRecords");
3069 closeRequest;
3070 return RIL_ERRNO_NO_MEMORY;
3071 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003072 for (int i = 0 ; i < infoRec->rec.display.alpha_len ; i++) {
3073 string8[i] = infoRec->rec.display.alpha_buf[i];
3074 }
3075 string8[(int)infoRec->rec.display.alpha_len] = '\0';
3076 writeStringToParcel(p, (const char*)string8);
3077 free(string8);
3078 string8 = NULL;
3079 break;
3080 case RIL_CDMA_CALLED_PARTY_NUMBER_INFO_REC:
3081 case RIL_CDMA_CALLING_PARTY_NUMBER_INFO_REC:
3082 case RIL_CDMA_CONNECTED_NUMBER_INFO_REC:
3083 if (infoRec->rec.number.len > CDMA_NUMBER_INFO_BUFFER_LENGTH) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003084 RLOGE("invalid display info response length %d \
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003085 expected not more than %d\n",
3086 (int)infoRec->rec.number.len,
3087 CDMA_NUMBER_INFO_BUFFER_LENGTH);
3088 return RIL_ERRNO_INVALID_RESPONSE;
3089 }
Christopher N. Hesse65084862017-02-07 22:21:27 +01003090 string8 = (char*) calloc(infoRec->rec.number.len + 1, sizeof(char));
Sanket Padawedf3dabe2016-02-29 10:09:26 -08003091 if (string8 == NULL) {
3092 RLOGE("Memory allocation failed for responseCdmaInformationRecords");
3093 closeRequest;
3094 return RIL_ERRNO_NO_MEMORY;
3095 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003096 for (int i = 0 ; i < infoRec->rec.number.len; i++) {
3097 string8[i] = infoRec->rec.number.buf[i];
3098 }
3099 string8[(int)infoRec->rec.number.len] = '\0';
3100 writeStringToParcel(p, (const char*)string8);
3101 free(string8);
3102 string8 = NULL;
3103 p.writeInt32(infoRec->rec.number.number_type);
3104 p.writeInt32(infoRec->rec.number.number_plan);
3105 p.writeInt32(infoRec->rec.number.pi);
3106 p.writeInt32(infoRec->rec.number.si);
3107 break;
3108 case RIL_CDMA_SIGNAL_INFO_REC:
3109 p.writeInt32(infoRec->rec.signal.isPresent);
3110 p.writeInt32(infoRec->rec.signal.signalType);
3111 p.writeInt32(infoRec->rec.signal.alertPitch);
3112 p.writeInt32(infoRec->rec.signal.signal);
3113
3114 appendPrintBuf("%sisPresent=%X, signalType=%X, \
3115 alertPitch=%X, signal=%X, ",
3116 printBuf, (int)infoRec->rec.signal.isPresent,
3117 (int)infoRec->rec.signal.signalType,
3118 (int)infoRec->rec.signal.alertPitch,
3119 (int)infoRec->rec.signal.signal);
3120 removeLastChar;
3121 break;
3122 case RIL_CDMA_REDIRECTING_NUMBER_INFO_REC:
3123 if (infoRec->rec.redir.redirectingNumber.len >
3124 CDMA_NUMBER_INFO_BUFFER_LENGTH) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003125 RLOGE("invalid display info response length %d \
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003126 expected not more than %d\n",
3127 (int)infoRec->rec.redir.redirectingNumber.len,
3128 CDMA_NUMBER_INFO_BUFFER_LENGTH);
3129 return RIL_ERRNO_INVALID_RESPONSE;
3130 }
Christopher N. Hesse65084862017-02-07 22:21:27 +01003131 string8 = (char*) calloc(infoRec->rec.redir.redirectingNumber.len + 1,
3132 sizeof(char));
Sanket Padawedf3dabe2016-02-29 10:09:26 -08003133 if (string8 == NULL) {
3134 RLOGE("Memory allocation failed for responseCdmaInformationRecords");
3135 closeRequest;
3136 return RIL_ERRNO_NO_MEMORY;
3137 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003138 for (int i = 0;
3139 i < infoRec->rec.redir.redirectingNumber.len;
3140 i++) {
3141 string8[i] = infoRec->rec.redir.redirectingNumber.buf[i];
3142 }
3143 string8[(int)infoRec->rec.redir.redirectingNumber.len] = '\0';
3144 writeStringToParcel(p, (const char*)string8);
3145 free(string8);
3146 string8 = NULL;
3147 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_type);
3148 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_plan);
3149 p.writeInt32(infoRec->rec.redir.redirectingNumber.pi);
3150 p.writeInt32(infoRec->rec.redir.redirectingNumber.si);
3151 p.writeInt32(infoRec->rec.redir.redirectingReason);
3152 break;
3153 case RIL_CDMA_LINE_CONTROL_INFO_REC:
3154 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPolarityIncluded);
3155 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlToggle);
3156 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlReverse);
3157 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPowerDenial);
3158
3159 appendPrintBuf("%slineCtrlPolarityIncluded=%d, \
3160 lineCtrlToggle=%d, lineCtrlReverse=%d, \
3161 lineCtrlPowerDenial=%d, ", printBuf,
3162 (int)infoRec->rec.lineCtrl.lineCtrlPolarityIncluded,
3163 (int)infoRec->rec.lineCtrl.lineCtrlToggle,
3164 (int)infoRec->rec.lineCtrl.lineCtrlReverse,
3165 (int)infoRec->rec.lineCtrl.lineCtrlPowerDenial);
3166 removeLastChar;
3167 break;
3168 case RIL_CDMA_T53_CLIR_INFO_REC:
3169 p.writeInt32((int)(infoRec->rec.clir.cause));
3170
3171 appendPrintBuf("%scause%d", printBuf, infoRec->rec.clir.cause);
3172 removeLastChar;
3173 break;
3174 case RIL_CDMA_T53_AUDIO_CONTROL_INFO_REC:
3175 p.writeInt32(infoRec->rec.audioCtrl.upLink);
3176 p.writeInt32(infoRec->rec.audioCtrl.downLink);
3177
3178 appendPrintBuf("%supLink=%d, downLink=%d, ", printBuf,
3179 infoRec->rec.audioCtrl.upLink,
3180 infoRec->rec.audioCtrl.downLink);
3181 removeLastChar;
3182 break;
3183 case RIL_CDMA_T53_RELEASE_INFO_REC:
3184 // TODO(Moto): See David Krause, he has the answer:)
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003185 RLOGE("RIL_CDMA_T53_RELEASE_INFO_REC: return INVALID_RESPONSE");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003186 return RIL_ERRNO_INVALID_RESPONSE;
3187 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003188 RLOGE("Incorrect name value");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003189 return RIL_ERRNO_INVALID_RESPONSE;
3190 }
3191 }
3192 closeResponse;
3193
3194 return 0;
3195}
3196
Sanket Padawe9343e872016-01-11 12:45:43 -08003197static void responseRilSignalStrengthV5(Parcel &p, RIL_SignalStrength_v10 *p_cur) {
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303198 int gsmSignalStrength;
3199 int cdmaDbm;
3200 int evdoDbm;
3201
Sanket Padawe9343e872016-01-11 12:45:43 -08003202 gsmSignalStrength = p_cur->GW_SignalStrength.signalStrength & 0xFF;
Utkarsh Gupta8ede9fa2015-04-23 13:21:49 +05303203
3204#ifdef MODEM_TYPE_XMM6260
3205 if (gsmSignalStrength < 0 ||
3206 (gsmSignalStrength > 31 && p_cur->GW_SignalStrength.signalStrength != 99)) {
3207 gsmSignalStrength = p_cur->CDMA_SignalStrength.dbm;
3208 }
3209#else
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303210 if (gsmSignalStrength < 0) {
3211 gsmSignalStrength = 99;
3212 } else if (gsmSignalStrength > 31 && gsmSignalStrength != 99) {
3213 gsmSignalStrength = 31;
3214 }
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303215#endif
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303216
Christopher N. Hesse621e63e2016-02-22 21:57:39 +01003217#if defined(MODEM_TYPE_XMM6262) || defined(SAMSUNG_NEXT_GEN_MODEM)
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303218 cdmaDbm = p_cur->CDMA_SignalStrength.dbm & 0xFF;
3219 if (cdmaDbm < 0) {
3220 cdmaDbm = 99;
3221 } else if (cdmaDbm > 31 && cdmaDbm != 99) {
3222 cdmaDbm = 31;
3223 }
3224#else
Caio Schnepperec042542015-04-14 08:03:43 -03003225 cdmaDbm = p_cur->CDMA_SignalStrength.dbm;
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303226#endif
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303227
Christopher N. Hesse621e63e2016-02-22 21:57:39 +01003228#if defined(MODEM_TYPE_XMM6262) || defined(SAMSUNG_NEXT_GEN_MODEM)
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303229 evdoDbm = p_cur->EVDO_SignalStrength.dbm & 0xFF;
3230 if (evdoDbm < 0) {
3231 evdoDbm = 99;
3232 } else if (evdoDbm > 31 && evdoDbm != 99) {
3233 evdoDbm = 31;
3234 }
3235#else
3236 evdoDbm = p_cur->EVDO_SignalStrength.dbm;
3237#endif
Christopher N. Hesse65084862017-02-07 22:21:27 +01003238
3239 p.writeInt32(gsmSignalStrength);
3240 p.writeInt32(p_cur->GW_SignalStrength.bitErrorRate);
3241 p.writeInt32(cdmaDbm);
3242 p.writeInt32(p_cur->CDMA_SignalStrength.ecio);
3243 p.writeInt32(evdoDbm);
3244 p.writeInt32(p_cur->EVDO_SignalStrength.ecio);
3245 p.writeInt32(p_cur->EVDO_SignalStrength.signalNoiseRatio);
Sanket Padawe9343e872016-01-11 12:45:43 -08003246}
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003247
Sanket Padawe9343e872016-01-11 12:45:43 -08003248static void responseRilSignalStrengthV6Extra(Parcel &p, RIL_SignalStrength_v10 *p_cur) {
3249 /*
3250 * Fixup LTE for backwards compatibility
3251 */
3252 // signalStrength: -1 -> 99
3253 if (p_cur->LTE_SignalStrength.signalStrength == -1) {
3254 p_cur->LTE_SignalStrength.signalStrength = 99;
3255 }
3256 // rsrp: -1 -> INT_MAX all other negative value to positive.
3257 // So remap here
3258 if (p_cur->LTE_SignalStrength.rsrp == -1) {
3259 p_cur->LTE_SignalStrength.rsrp = INT_MAX;
3260 } else if (p_cur->LTE_SignalStrength.rsrp < -1) {
3261 p_cur->LTE_SignalStrength.rsrp = -p_cur->LTE_SignalStrength.rsrp;
3262 }
3263 // rsrq: -1 -> INT_MAX
3264 if (p_cur->LTE_SignalStrength.rsrq == -1) {
3265 p_cur->LTE_SignalStrength.rsrq = INT_MAX;
3266 }
3267 // Not remapping rssnr is already using INT_MAX
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003268
Sanket Padawe9343e872016-01-11 12:45:43 -08003269 // cqi: -1 -> INT_MAX
3270 if (p_cur->LTE_SignalStrength.cqi == -1) {
3271 p_cur->LTE_SignalStrength.cqi = INT_MAX;
3272 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003273
Sanket Padawe9343e872016-01-11 12:45:43 -08003274 p.writeInt32(p_cur->LTE_SignalStrength.signalStrength);
3275 p.writeInt32(p_cur->LTE_SignalStrength.rsrp);
3276 p.writeInt32(p_cur->LTE_SignalStrength.rsrq);
3277 p.writeInt32(p_cur->LTE_SignalStrength.rssnr);
3278 p.writeInt32(p_cur->LTE_SignalStrength.cqi);
3279}
3280
3281static void responseRilSignalStrengthV10(Parcel &p, RIL_SignalStrength_v10 *p_cur) {
3282 responseRilSignalStrengthV5(p, p_cur);
3283 responseRilSignalStrengthV6Extra(p, p_cur);
3284 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
3285}
3286
Sanket Padawe9343e872016-01-11 12:45:43 -08003287static int responseRilSignalStrength(Parcel &p,
3288 void *response, size_t responselen) {
3289 if (response == NULL && responselen != 0) {
3290 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003291 return RIL_ERRNO_INVALID_RESPONSE;
3292 }
3293
Sanket Padawe6daeeef2016-06-08 14:09:26 -07003294 RIL_SignalStrength_v10 *p_cur;
Sanket Padawe9343e872016-01-11 12:45:43 -08003295 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
3296 if (responselen >= sizeof (RIL_SignalStrength_v5)) {
Sanket Padawe6daeeef2016-06-08 14:09:26 -07003297 p_cur = ((RIL_SignalStrength_v10 *) response);
Sanket Padawe9343e872016-01-11 12:45:43 -08003298
3299 responseRilSignalStrengthV5(p, p_cur);
3300
3301 if (responselen >= sizeof (RIL_SignalStrength_v6)) {
3302 responseRilSignalStrengthV6Extra(p, p_cur);
3303 if (responselen >= sizeof (RIL_SignalStrength_v10)) {
3304 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
3305 } else {
3306 p.writeInt32(INT_MAX);
3307 }
3308 } else {
3309 p.writeInt32(99);
3310 p.writeInt32(INT_MAX);
3311 p.writeInt32(INT_MAX);
3312 p.writeInt32(INT_MAX);
3313 p.writeInt32(INT_MAX);
3314 p.writeInt32(INT_MAX);
3315 }
3316 } else {
3317 RLOGE("invalid response length");
3318 return RIL_ERRNO_INVALID_RESPONSE;
3319 }
Sanket Padawea79128a2016-01-26 18:44:01 -08003320 } else { // RIL version >= 13
Sanket Padawe9343e872016-01-11 12:45:43 -08003321 if (responselen % sizeof(RIL_SignalStrength_v10) != 0) {
3322 RLOGE("Data structure expected is RIL_SignalStrength_v10");
3323 if (!isDebuggable()) {
3324 return RIL_ERRNO_INVALID_RESPONSE;
3325 } else {
3326 assert(0);
3327 }
3328 }
Sanket Padawe6daeeef2016-06-08 14:09:26 -07003329 p_cur = ((RIL_SignalStrength_v10 *) response);
Sanket Padawe9343e872016-01-11 12:45:43 -08003330 responseRilSignalStrengthV10(p, p_cur);
3331 }
Sanket Padawe9343e872016-01-11 12:45:43 -08003332 startResponse;
3333 appendPrintBuf("%s[signalStrength=%d,bitErrorRate=%d,\
3334 CDMA_SS.dbm=%d,CDMA_SSecio=%d,\
3335 EVDO_SS.dbm=%d,EVDO_SS.ecio=%d,\
3336 EVDO_SS.signalNoiseRatio=%d,\
3337 LTE_SS.signalStrength=%d,LTE_SS.rsrp=%d,LTE_SS.rsrq=%d,\
3338 LTE_SS.rssnr=%d,LTE_SS.cqi=%d,TDSCDMA_SS.rscp=%d]",
3339 printBuf,
3340 gsmSignalStrength,
3341 p_cur->GW_SignalStrength.bitErrorRate,
3342 cdmaDbm,
3343 p_cur->CDMA_SignalStrength.ecio,
3344 evdoDbm,
3345 p_cur->EVDO_SignalStrength.ecio,
3346 p_cur->EVDO_SignalStrength.signalNoiseRatio,
3347 p_cur->LTE_SignalStrength.signalStrength,
3348 p_cur->LTE_SignalStrength.rsrp,
3349 p_cur->LTE_SignalStrength.rsrq,
3350 p_cur->LTE_SignalStrength.rssnr,
3351 p_cur->LTE_SignalStrength.cqi,
3352 p_cur->TD_SCDMA_SignalStrength.rscp);
3353 closeResponse;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003354 return 0;
3355}
3356
3357static int responseCallRing(Parcel &p, void *response, size_t responselen) {
3358 if ((response == NULL) || (responselen == 0)) {
3359 return responseVoid(p, response, responselen);
3360 } else {
3361 return responseCdmaSignalInfoRecord(p, response, responselen);
3362 }
3363}
3364
3365static int responseCdmaSignalInfoRecord(Parcel &p, void *response, size_t responselen) {
3366 if (response == NULL || responselen == 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003367 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003368 return RIL_ERRNO_INVALID_RESPONSE;
3369 }
3370
3371 if (responselen != sizeof (RIL_CDMA_SignalInfoRecord)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003372 RLOGE("invalid response length %d expected sizeof (RIL_CDMA_SignalInfoRecord) of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003373 (int)responselen, (int)sizeof (RIL_CDMA_SignalInfoRecord));
3374 return RIL_ERRNO_INVALID_RESPONSE;
3375 }
3376
3377 startResponse;
3378
3379 RIL_CDMA_SignalInfoRecord *p_cur = ((RIL_CDMA_SignalInfoRecord *) response);
3380 marshallSignalInfoRecord(p, *p_cur);
3381
3382 appendPrintBuf("%s[isPresent=%d,signalType=%d,alertPitch=%d\
3383 signal=%d]",
3384 printBuf,
3385 p_cur->isPresent,
3386 p_cur->signalType,
3387 p_cur->alertPitch,
3388 p_cur->signal);
3389
3390 closeResponse;
3391 return 0;
3392}
3393
3394static int responseCdmaCallWaiting(Parcel &p, void *response,
3395 size_t responselen) {
3396 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003397 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003398 return RIL_ERRNO_INVALID_RESPONSE;
3399 }
3400
3401 if (responselen < sizeof(RIL_CDMA_CallWaiting_v6)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003402 RLOGW("Upgrade to ril version %d\n", RIL_VERSION);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003403 }
3404
3405 RIL_CDMA_CallWaiting_v6 *p_cur = ((RIL_CDMA_CallWaiting_v6 *) response);
3406
3407 writeStringToParcel(p, p_cur->number);
3408 p.writeInt32(p_cur->numberPresentation);
3409 writeStringToParcel(p, p_cur->name);
3410 marshallSignalInfoRecord(p, p_cur->signalInfoRecord);
3411
Sanket Padawe9343e872016-01-11 12:45:43 -08003412 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
3413 if (responselen >= sizeof(RIL_CDMA_CallWaiting_v6)) {
3414 p.writeInt32(p_cur->number_type);
3415 p.writeInt32(p_cur->number_plan);
3416 } else {
3417 p.writeInt32(0);
3418 p.writeInt32(0);
3419 }
Sanket Padawea79128a2016-01-26 18:44:01 -08003420 } else { // RIL version >= 13
Sanket Padawe9343e872016-01-11 12:45:43 -08003421 if (responselen % sizeof(RIL_CDMA_CallWaiting_v6) != 0) {
3422 RLOGE("Data structure expected is RIL_CDMA_CallWaiting_v6");
3423 if (!isDebuggable()) {
3424 return RIL_ERRNO_INVALID_RESPONSE;
3425 } else {
3426 assert(0);
3427 }
3428 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003429 p.writeInt32(p_cur->number_type);
3430 p.writeInt32(p_cur->number_plan);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003431 }
3432
3433 startResponse;
3434 appendPrintBuf("%snumber=%s,numberPresentation=%d, name=%s,\
3435 signalInfoRecord[isPresent=%d,signalType=%d,alertPitch=%d\
3436 signal=%d,number_type=%d,number_plan=%d]",
3437 printBuf,
3438 p_cur->number,
3439 p_cur->numberPresentation,
3440 p_cur->name,
3441 p_cur->signalInfoRecord.isPresent,
3442 p_cur->signalInfoRecord.signalType,
3443 p_cur->signalInfoRecord.alertPitch,
3444 p_cur->signalInfoRecord.signal,
3445 p_cur->number_type,
3446 p_cur->number_plan);
3447 closeResponse;
3448
3449 return 0;
3450}
3451
Sanket Padawe9343e872016-01-11 12:45:43 -08003452static void responseSimRefreshV7(Parcel &p, void *response) {
3453 RIL_SimRefreshResponse_v7 *p_cur = ((RIL_SimRefreshResponse_v7 *) response);
3454 p.writeInt32(p_cur->result);
3455 p.writeInt32(p_cur->ef_id);
3456 writeStringToParcel(p, p_cur->aid);
3457
3458 appendPrintBuf("%sresult=%d, ef_id=%d, aid=%s",
3459 printBuf,
3460 p_cur->result,
3461 p_cur->ef_id,
3462 p_cur->aid);
3463
3464}
3465
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003466static int responseSimRefresh(Parcel &p, void *response, size_t responselen) {
3467 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003468 RLOGE("responseSimRefresh: invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003469 return RIL_ERRNO_INVALID_RESPONSE;
3470 }
3471
3472 startResponse;
Sanket Padawe9343e872016-01-11 12:45:43 -08003473 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
Sanket Padawe201aca32016-01-21 15:49:33 -08003474 if (s_callbacks.version >= 7) {
Sanket Padawe9343e872016-01-11 12:45:43 -08003475 responseSimRefreshV7(p, response);
3476 } else {
3477 int *p_cur = ((int *) response);
3478 p.writeInt32(p_cur[0]);
3479 p.writeInt32(p_cur[1]);
3480 writeStringToParcel(p, NULL);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003481
Sanket Padawe9343e872016-01-11 12:45:43 -08003482 appendPrintBuf("%sresult=%d, ef_id=%d",
3483 printBuf,
3484 p_cur[0],
3485 p_cur[1]);
3486 }
Sanket Padawea79128a2016-01-26 18:44:01 -08003487 } else { // RIL version >= 13
Sanket Padawe9343e872016-01-11 12:45:43 -08003488 if (responselen % sizeof(RIL_SimRefreshResponse_v7) != 0) {
3489 RLOGE("Data structure expected is RIL_SimRefreshResponse_v7");
3490 if (!isDebuggable()) {
3491 return RIL_ERRNO_INVALID_RESPONSE;
3492 } else {
3493 assert(0);
3494 }
3495 }
3496 responseSimRefreshV7(p, response);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003497
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003498 }
3499 closeResponse;
3500
3501 return 0;
3502}
3503
Sanket Padawea79128a2016-01-26 18:44:01 -08003504static int responseCellInfoListV6(Parcel &p, void *response, size_t responselen) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003505 if (response == NULL && responselen != 0) {
3506 RLOGE("invalid response: NULL");
3507 return RIL_ERRNO_INVALID_RESPONSE;
3508 }
3509
3510 if (responselen % sizeof(RIL_CellInfo) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08003511 RLOGE("responseCellInfoList: invalid response length %d expected multiple of %d",
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003512 (int)responselen, (int)sizeof(RIL_CellInfo));
3513 return RIL_ERRNO_INVALID_RESPONSE;
3514 }
3515
3516 int num = responselen / sizeof(RIL_CellInfo);
3517 p.writeInt32(num);
3518
3519 RIL_CellInfo *p_cur = (RIL_CellInfo *) response;
3520 startResponse;
3521 int i;
3522 for (i = 0; i < num; i++) {
3523 appendPrintBuf("%s[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", printBuf, i,
3524 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
3525 p.writeInt32((int)p_cur->cellInfoType);
3526 p.writeInt32(p_cur->registered);
3527 p.writeInt32(p_cur->timeStampType);
3528 p.writeInt64(p_cur->timeStamp);
3529 switch(p_cur->cellInfoType) {
3530 case RIL_CELL_INFO_TYPE_GSM: {
3531 appendPrintBuf("%s GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,", printBuf,
3532 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
3533 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
3534 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
3535 p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3536 appendPrintBuf("%s gsmSS: ss=%d,ber=%d],", printBuf,
3537 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
3538 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3539
3540 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
3541 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
3542 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
3543 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
Christopher N. Hesse65084862017-02-07 22:21:27 +01003544 p.writeInt32(INT_MAX); /* skip arfcn */
3545 p.writeInt32(INT_MAX); /* skip bsic */
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003546 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
3547 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3548 break;
3549 }
3550 case RIL_CELL_INFO_TYPE_WCDMA: {
3551 appendPrintBuf("%s WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,", printBuf,
3552 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
3553 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
3554 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
3555 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
3556 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3557 appendPrintBuf("%s wcdmaSS: ss=%d,ber=%d],", printBuf,
3558 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
3559 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3560
3561 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
3562 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
3563 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
3564 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
3565 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
Christopher N. Hesse65084862017-02-07 22:21:27 +01003566 p.writeInt32(INT_MAX); /* skip uarfcn */
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003567 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
3568 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3569 break;
3570 }
3571 case RIL_CELL_INFO_TYPE_CDMA: {
3572 appendPrintBuf("%s CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d", printBuf,
3573 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
3574 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
3575 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
3576 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
3577 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3578
3579 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
3580 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
3581 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
3582 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
3583 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3584
3585 appendPrintBuf("%s cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d", printBuf,
3586 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
3587 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
3588 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
3589 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
3590 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3591
3592 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
3593 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
3594 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
3595 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
3596 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3597 break;
3598 }
3599 case RIL_CELL_INFO_TYPE_LTE: {
3600 appendPrintBuf("%s LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d", printBuf,
3601 p_cur->CellInfo.lte.cellIdentityLte.mcc,
3602 p_cur->CellInfo.lte.cellIdentityLte.mnc,
3603 p_cur->CellInfo.lte.cellIdentityLte.ci,
3604 p_cur->CellInfo.lte.cellIdentityLte.pci,
3605 p_cur->CellInfo.lte.cellIdentityLte.tac);
3606
3607 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
3608 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
3609 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
3610 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
3611 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
Christopher N. Hesse65084862017-02-07 22:21:27 +01003612 p.writeInt32(INT_MAX); /* skip earfcn */
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003613
3614 appendPrintBuf("%s lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d", printBuf,
3615 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
3616 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
3617 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
3618 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
3619 p_cur->CellInfo.lte.signalStrengthLte.cqi,
3620 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3621 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
3622 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
3623 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
3624 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
3625 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
3626 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3627 break;
3628 }
Howard Sue32dbfd2015-01-07 15:55:57 +08003629 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
3630 appendPrintBuf("%s TDSCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,cpid=%d,", printBuf,
3631 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc,
3632 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc,
3633 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac,
3634 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid,
3635 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3636 appendPrintBuf("%s tdscdmaSS: rscp=%d],", printBuf,
3637 p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3638
3639 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
3640 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
3641 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
3642 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
3643 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3644 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3645 break;
3646 }
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003647 }
3648 p_cur += 1;
3649 }
3650 removeLastChar;
3651 closeResponse;
3652
3653 return 0;
3654}
3655
Sanket Padawea79128a2016-01-26 18:44:01 -08003656static int responseCellInfoListV12(Parcel &p, void *response, size_t responselen) {
3657 if (response == NULL && responselen != 0) {
3658 RLOGE("invalid response: NULL");
3659 return RIL_ERRNO_INVALID_RESPONSE;
3660 }
3661
3662 if (responselen % sizeof(RIL_CellInfo_v12) != 0) {
3663 RLOGE("responseCellInfoList: invalid response length %d expected multiple of %d",
3664 (int)responselen, (int)sizeof(RIL_CellInfo_v12));
3665 return RIL_ERRNO_INVALID_RESPONSE;
3666 }
3667
3668 int num = responselen / sizeof(RIL_CellInfo_v12);
3669 p.writeInt32(num);
3670
3671 RIL_CellInfo_v12 *p_cur = (RIL_CellInfo_v12 *) response;
3672 startResponse;
3673 int i;
3674 for (i = 0; i < num; i++) {
3675 appendPrintBuf("%s[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", printBuf, i,
3676 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
3677 RLOGE("[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", i,
3678 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
3679 p.writeInt32((int)p_cur->cellInfoType);
3680 p.writeInt32(p_cur->registered);
3681 p.writeInt32(p_cur->timeStampType);
3682 p.writeInt64(p_cur->timeStamp);
3683 switch(p_cur->cellInfoType) {
3684 case RIL_CELL_INFO_TYPE_GSM: {
3685 appendPrintBuf("%s GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,arfcn=%d,bsic=%x", printBuf,
3686 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
3687 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
3688 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
3689 p_cur->CellInfo.gsm.cellIdentityGsm.cid,
3690 p_cur->CellInfo.gsm.cellIdentityGsm.arfcn,
3691 p_cur->CellInfo.gsm.cellIdentityGsm.bsic);
3692 RLOGE("GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,arfcn=%d,bsic=%x",
3693 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
3694 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
3695 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
3696 p_cur->CellInfo.gsm.cellIdentityGsm.cid,
3697 p_cur->CellInfo.gsm.cellIdentityGsm.arfcn,
3698 p_cur->CellInfo.gsm.cellIdentityGsm.bsic);
3699 RLOGE("gsmSS: ss=%d,ber=%d, ta=%d],",
3700 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
3701 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate,
3702 p_cur->CellInfo.gsm.signalStrengthGsm.timingAdvance);
3703 appendPrintBuf("%s gsmSS: ss=%d,ber=%d, ta=%d],", printBuf,
3704 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
3705 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate,
3706 p_cur->CellInfo.gsm.signalStrengthGsm.timingAdvance);
3707
3708 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
3709 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
3710 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
3711 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3712 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.arfcn);
3713 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.bsic);
3714 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
3715 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3716 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.timingAdvance);
3717 break;
3718 }
3719 case RIL_CELL_INFO_TYPE_WCDMA: {
3720 RLOGE("WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,uarfcn=%d",
3721 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
3722 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
3723 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
3724 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
3725 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc,
3726 p_cur->CellInfo.wcdma.cellIdentityWcdma.uarfcn);
3727 RLOGE("wcdmaSS: ss=%d,ber=%d],",
3728 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
3729 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3730 appendPrintBuf("%s WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,uarfcn=%d", printBuf,
3731 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
3732 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
3733 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
3734 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
3735 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc,
3736 p_cur->CellInfo.wcdma.cellIdentityWcdma.uarfcn);
3737 appendPrintBuf("%s wcdmaSS: ss=%d,ber=%d],", printBuf,
3738 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
3739 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3740
3741 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
3742 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
3743 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
3744 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
3745 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3746 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.uarfcn);
3747 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
3748 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3749 break;
3750 }
3751 case RIL_CELL_INFO_TYPE_CDMA: {
3752 RLOGE("CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d",
3753 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
3754 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
3755 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
3756 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
3757 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3758
3759 appendPrintBuf("%s CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d", printBuf,
3760 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
3761 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
3762 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
3763 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
3764 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3765
3766 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
3767 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
3768 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
3769 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
3770 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3771
3772 RLOGE("cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d",
3773 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
3774 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
3775 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
3776 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
3777 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3778
3779 appendPrintBuf("%s cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d", printBuf,
3780 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
3781 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
3782 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
3783 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
3784 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3785
3786 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
3787 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
3788 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
3789 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
3790 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3791 break;
3792 }
3793 case RIL_CELL_INFO_TYPE_LTE: {
3794 RLOGE("LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d,earfcn=%d",
3795 p_cur->CellInfo.lte.cellIdentityLte.mcc,
3796 p_cur->CellInfo.lte.cellIdentityLte.mnc,
3797 p_cur->CellInfo.lte.cellIdentityLte.ci,
3798 p_cur->CellInfo.lte.cellIdentityLte.pci,
3799 p_cur->CellInfo.lte.cellIdentityLte.tac,
3800 p_cur->CellInfo.lte.cellIdentityLte.earfcn);
3801
3802 appendPrintBuf("%s LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d,earfcn=%d", printBuf,
3803 p_cur->CellInfo.lte.cellIdentityLte.mcc,
3804 p_cur->CellInfo.lte.cellIdentityLte.mnc,
3805 p_cur->CellInfo.lte.cellIdentityLte.ci,
3806 p_cur->CellInfo.lte.cellIdentityLte.pci,
3807 p_cur->CellInfo.lte.cellIdentityLte.tac,
3808 p_cur->CellInfo.lte.cellIdentityLte.earfcn);
3809
3810 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
3811 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
3812 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
3813 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
3814 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
3815 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.earfcn);
3816
3817 RLOGE("lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d",
3818 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
3819 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
3820 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
3821 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
3822 p_cur->CellInfo.lte.signalStrengthLte.cqi,
3823 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3824 appendPrintBuf("%s lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d", printBuf,
3825 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
3826 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
3827 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
3828 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
3829 p_cur->CellInfo.lte.signalStrengthLte.cqi,
3830 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3831 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
3832 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
3833 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
3834 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
3835 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
3836 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3837 break;
3838 }
3839 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
3840 appendPrintBuf("%s TDSCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,cpid=%d,", printBuf,
3841 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc,
3842 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc,
3843 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac,
3844 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid,
3845 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3846 appendPrintBuf("%s tdscdmaSS: rscp=%d],", printBuf,
3847 p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3848
3849 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
3850 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
3851 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
3852 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
3853 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3854 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3855 break;
3856 }
3857 }
3858 p_cur += 1;
3859 }
3860 removeLastChar;
3861 closeResponse;
3862 return 0;
3863}
3864
3865static int responseCellInfoList(Parcel &p, void *response, size_t responselen)
3866{
3867 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
3868 if (s_callbacks.version < 12) {
3869 RLOGD("responseCellInfoList: v6");
3870 return responseCellInfoListV6(p, response, responselen);
3871 } else {
3872 RLOGD("responseCellInfoList: v12");
3873 return responseCellInfoListV12(p, response, responselen);
3874 }
3875 } else { // RIL version >= 13
3876 if (responselen % sizeof(RIL_CellInfo_v12) != 0) {
3877 RLOGE("Data structure expected is RIL_CellInfo_v12");
3878 if (!isDebuggable()) {
3879 return RIL_ERRNO_INVALID_RESPONSE;
3880 } else {
3881 assert(0);
3882 }
3883 }
3884 return responseCellInfoListV12(p, response, responselen);
3885 }
3886
3887 return 0;
3888}
3889
Howard Sue32dbfd2015-01-07 15:55:57 +08003890static int responseHardwareConfig(Parcel &p, void *response, size_t responselen)
3891{
3892 if (response == NULL && responselen != 0) {
3893 RLOGE("invalid response: NULL");
3894 return RIL_ERRNO_INVALID_RESPONSE;
3895 }
3896
3897 if (responselen % sizeof(RIL_HardwareConfig) != 0) {
3898 RLOGE("responseHardwareConfig: invalid response length %d expected multiple of %d",
3899 (int)responselen, (int)sizeof(RIL_HardwareConfig));
3900 return RIL_ERRNO_INVALID_RESPONSE;
3901 }
3902
3903 int num = responselen / sizeof(RIL_HardwareConfig);
3904 int i;
3905 RIL_HardwareConfig *p_cur = (RIL_HardwareConfig *) response;
3906
3907 p.writeInt32(num);
3908
3909 startResponse;
3910 for (i = 0; i < num; i++) {
3911 switch (p_cur[i].type) {
3912 case RIL_HARDWARE_CONFIG_MODEM: {
3913 writeStringToParcel(p, p_cur[i].uuid);
3914 p.writeInt32((int)p_cur[i].state);
3915 p.writeInt32(p_cur[i].cfg.modem.rat);
3916 p.writeInt32(p_cur[i].cfg.modem.maxVoice);
3917 p.writeInt32(p_cur[i].cfg.modem.maxData);
3918 p.writeInt32(p_cur[i].cfg.modem.maxStandby);
3919
3920 appendPrintBuf("%s modem: uuid=%s,state=%d,rat=%08x,maxV=%d,maxD=%d,maxS=%d", printBuf,
3921 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.modem.rat,
3922 p_cur[i].cfg.modem.maxVoice, p_cur[i].cfg.modem.maxData, p_cur[i].cfg.modem.maxStandby);
3923 break;
3924 }
3925 case RIL_HARDWARE_CONFIG_SIM: {
3926 writeStringToParcel(p, p_cur[i].uuid);
3927 p.writeInt32((int)p_cur[i].state);
3928 writeStringToParcel(p, p_cur[i].cfg.sim.modemUuid);
3929
3930 appendPrintBuf("%s sim: uuid=%s,state=%d,modem-uuid=%s", printBuf,
3931 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.sim.modemUuid);
3932 break;
3933 }
3934 }
3935 }
3936 removeLastChar;
3937 closeResponse;
3938 return 0;
3939}
3940
Howard Subd82ef12015-04-12 10:25:05 +02003941static int responseRadioCapability(Parcel &p, void *response, size_t responselen) {
3942 if (response == NULL) {
3943 RLOGE("invalid response: NULL");
3944 return RIL_ERRNO_INVALID_RESPONSE;
3945 }
3946
3947 if (responselen != sizeof (RIL_RadioCapability) ) {
3948 RLOGE("invalid response length was %d expected %d",
3949 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3950 return RIL_ERRNO_INVALID_RESPONSE;
3951 }
3952
3953 RIL_RadioCapability *p_cur = (RIL_RadioCapability *) response;
3954 p.writeInt32(p_cur->version);
3955 p.writeInt32(p_cur->session);
3956 p.writeInt32(p_cur->phase);
3957 p.writeInt32(p_cur->rat);
3958 writeStringToParcel(p, p_cur->logicalModemUuid);
3959 p.writeInt32(p_cur->status);
3960
3961 startResponse;
3962 appendPrintBuf("%s[version=%d,session=%d,phase=%d,\
Christopher N. Hesse65084862017-02-07 22:21:27 +01003963 rat=%s,logicalModemUuid=%s,status=%d]",
Howard Subd82ef12015-04-12 10:25:05 +02003964 printBuf,
3965 p_cur->version,
3966 p_cur->session,
3967 p_cur->phase,
3968 p_cur->rat,
3969 p_cur->logicalModemUuid,
3970 p_cur->status);
3971 closeResponse;
3972 return 0;
3973}
3974
3975static int responseSSData(Parcel &p, void *response, size_t responselen) {
3976 RLOGD("In responseSSData");
3977 int num;
3978
3979 if (response == NULL && responselen != 0) {
3980 RLOGE("invalid response length was %d expected %d",
3981 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3982 return RIL_ERRNO_INVALID_RESPONSE;
3983 }
3984
3985 if (responselen != sizeof(RIL_StkCcUnsolSsResponse)) {
3986 RLOGE("invalid response length %d, expected %d",
3987 (int)responselen, (int)sizeof(RIL_StkCcUnsolSsResponse));
3988 return RIL_ERRNO_INVALID_RESPONSE;
3989 }
3990
3991 startResponse;
3992 RIL_StkCcUnsolSsResponse *p_cur = (RIL_StkCcUnsolSsResponse *) response;
3993 p.writeInt32(p_cur->serviceType);
3994 p.writeInt32(p_cur->requestType);
3995 p.writeInt32(p_cur->teleserviceType);
3996 p.writeInt32(p_cur->serviceClass);
3997 p.writeInt32(p_cur->result);
3998
3999 if (isServiceTypeCfQuery(p_cur->serviceType, p_cur->requestType)) {
4000 RLOGD("responseSSData CF type, num of Cf elements %d", p_cur->cfData.numValidIndexes);
4001 if (p_cur->cfData.numValidIndexes > NUM_SERVICE_CLASSES) {
4002 RLOGE("numValidIndexes is greater than max value %d, "
4003 "truncating it to max value", NUM_SERVICE_CLASSES);
4004 p_cur->cfData.numValidIndexes = NUM_SERVICE_CLASSES;
4005 }
4006 /* number of call info's */
4007 p.writeInt32(p_cur->cfData.numValidIndexes);
4008
4009 for (int i = 0; i < p_cur->cfData.numValidIndexes; i++) {
4010 RIL_CallForwardInfo cf = p_cur->cfData.cfInfo[i];
4011
4012 p.writeInt32(cf.status);
4013 p.writeInt32(cf.reason);
4014 p.writeInt32(cf.serviceClass);
4015 p.writeInt32(cf.toa);
4016 writeStringToParcel(p, cf.number);
4017 p.writeInt32(cf.timeSeconds);
4018 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
4019 (cf.status==1)?"enable":"disable", cf.reason, cf.serviceClass, cf.toa,
4020 (char*)cf.number, cf.timeSeconds);
4021 RLOGD("Data: %d,reason=%d,cls=%d,toa=%d,num=%s,tout=%d],", cf.status,
4022 cf.reason, cf.serviceClass, cf.toa, (char*)cf.number, cf.timeSeconds);
4023 }
4024 } else {
4025 p.writeInt32 (SS_INFO_MAX);
4026
4027 /* each int*/
4028 for (int i = 0; i < SS_INFO_MAX; i++) {
4029 appendPrintBuf("%s%d,", printBuf, p_cur->ssInfo[i]);
4030 RLOGD("Data: %d",p_cur->ssInfo[i]);
4031 p.writeInt32(p_cur->ssInfo[i]);
4032 }
4033 }
4034 removeLastChar;
4035 closeResponse;
4036
4037 return 0;
4038}
4039
4040static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType) {
4041 if ((reqType == SS_INTERROGATION) &&
4042 (serType == SS_CFU ||
4043 serType == SS_CF_BUSY ||
4044 serType == SS_CF_NO_REPLY ||
4045 serType == SS_CF_NOT_REACHABLE ||
4046 serType == SS_CF_ALL ||
4047 serType == SS_CF_ALL_CONDITIONAL)) {
4048 return true;
4049 }
4050 return false;
4051}
4052
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004053static void triggerEvLoop() {
4054 int ret;
4055 if (!pthread_equal(pthread_self(), s_tid_dispatch)) {
4056 /* trigger event loop to wakeup. No reason to do this,
4057 * if we're in the event loop thread */
4058 do {
4059 ret = write (s_fdWakeupWrite, " ", 1);
4060 } while (ret < 0 && errno == EINTR);
4061 }
4062}
4063
4064static void rilEventAddWakeup(struct ril_event *ev) {
4065 ril_event_add(ev);
4066 triggerEvLoop();
4067}
4068
4069static void sendSimStatusAppInfo(Parcel &p, int num_apps, RIL_AppStatus appStatus[]) {
4070 p.writeInt32(num_apps);
4071 startResponse;
4072 for (int i = 0; i < num_apps; i++) {
4073 p.writeInt32(appStatus[i].app_type);
4074 p.writeInt32(appStatus[i].app_state);
4075 p.writeInt32(appStatus[i].perso_substate);
4076 writeStringToParcel(p, (const char*)(appStatus[i].aid_ptr));
4077 writeStringToParcel(p, (const char*)
4078 (appStatus[i].app_label_ptr));
4079 p.writeInt32(appStatus[i].pin1_replaced);
4080 p.writeInt32(appStatus[i].pin1);
4081 p.writeInt32(appStatus[i].pin2);
4082 appendPrintBuf("%s[app_type=%d,app_state=%d,perso_substate=%d,\
4083 aid_ptr=%s,app_label_ptr=%s,pin1_replaced=%d,pin1=%d,pin2=%d],",
4084 printBuf,
4085 appStatus[i].app_type,
4086 appStatus[i].app_state,
4087 appStatus[i].perso_substate,
4088 appStatus[i].aid_ptr,
4089 appStatus[i].app_label_ptr,
4090 appStatus[i].pin1_replaced,
4091 appStatus[i].pin1,
4092 appStatus[i].pin2);
4093 }
4094 closeResponse;
4095}
4096
Sanket Padawe9343e872016-01-11 12:45:43 -08004097static void responseSimStatusV5(Parcel &p, void *response) {
4098 RIL_CardStatus_v5 *p_cur = ((RIL_CardStatus_v5 *) response);
4099
4100 p.writeInt32(p_cur->card_state);
4101 p.writeInt32(p_cur->universal_pin_state);
4102 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
4103 p.writeInt32(p_cur->cdma_subscription_app_index);
Kyle Repinski5a2cc4e2016-08-31 01:04:02 -05004104 p.writeInt32(-1);
Sanket Padawe9343e872016-01-11 12:45:43 -08004105
4106 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
4107}
4108
4109static void responseSimStatusV6(Parcel &p, void *response) {
4110 RIL_CardStatus_v6 *p_cur = ((RIL_CardStatus_v6 *) response);
4111
4112 p.writeInt32(p_cur->card_state);
4113 p.writeInt32(p_cur->universal_pin_state);
4114 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
4115 p.writeInt32(p_cur->cdma_subscription_app_index);
4116 p.writeInt32(p_cur->ims_subscription_app_index);
4117
4118 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
4119}
4120
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004121static int responseSimStatus(Parcel &p, void *response, size_t responselen) {
Howard Sue32dbfd2015-01-07 15:55:57 +08004122 int i;
4123
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004124 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004125 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004126 return RIL_ERRNO_INVALID_RESPONSE;
4127 }
4128
Sanket Padawe9343e872016-01-11 12:45:43 -08004129 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
4130 if (responselen == sizeof (RIL_CardStatus_v6)) {
4131 responseSimStatusV6(p, response);
4132 } else if (responselen == sizeof (RIL_CardStatus_v5)) {
4133 responseSimStatusV5(p, response);
4134 } else {
4135 RLOGE("responseSimStatus: A RilCardStatus_v6 or _v5 expected\n");
4136 return RIL_ERRNO_INVALID_RESPONSE;
4137 }
Sanket Padawea79128a2016-01-26 18:44:01 -08004138 } else { // RIL version >= 13
Sanket Padawe9343e872016-01-11 12:45:43 -08004139 if (responselen % sizeof(RIL_CardStatus_v6) != 0) {
4140 RLOGE("Data structure expected is RIL_CardStatus_v6");
4141 if (!isDebuggable()) {
4142 return RIL_ERRNO_INVALID_RESPONSE;
4143 } else {
4144 assert(0);
4145 }
4146 }
4147 responseSimStatusV6(p, response);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004148 }
4149
4150 return 0;
4151}
4152
4153static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen) {
4154 int num = responselen / sizeof(RIL_GSM_BroadcastSmsConfigInfo *);
4155 p.writeInt32(num);
4156
4157 startResponse;
4158 RIL_GSM_BroadcastSmsConfigInfo **p_cur =
4159 (RIL_GSM_BroadcastSmsConfigInfo **) response;
4160 for (int i = 0; i < num; i++) {
4161 p.writeInt32(p_cur[i]->fromServiceId);
4162 p.writeInt32(p_cur[i]->toServiceId);
4163 p.writeInt32(p_cur[i]->fromCodeScheme);
4164 p.writeInt32(p_cur[i]->toCodeScheme);
4165 p.writeInt32(p_cur[i]->selected);
4166
4167 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId=%d, \
4168 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]",
4169 printBuf, i, p_cur[i]->fromServiceId, p_cur[i]->toServiceId,
4170 p_cur[i]->fromCodeScheme, p_cur[i]->toCodeScheme,
4171 p_cur[i]->selected);
4172 }
4173 closeResponse;
4174
4175 return 0;
4176}
4177
4178static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen) {
4179 RIL_CDMA_BroadcastSmsConfigInfo **p_cur =
4180 (RIL_CDMA_BroadcastSmsConfigInfo **) response;
4181
4182 int num = responselen / sizeof (RIL_CDMA_BroadcastSmsConfigInfo *);
4183 p.writeInt32(num);
4184
4185 startResponse;
4186 for (int i = 0 ; i < num ; i++ ) {
4187 p.writeInt32(p_cur[i]->service_category);
4188 p.writeInt32(p_cur[i]->language);
4189 p.writeInt32(p_cur[i]->selected);
4190
4191 appendPrintBuf("%s [%d: srvice_category=%d, language =%d, \
4192 selected =%d], ",
4193 printBuf, i, p_cur[i]->service_category, p_cur[i]->language,
4194 p_cur[i]->selected);
4195 }
4196 closeResponse;
4197
4198 return 0;
4199}
4200
4201static int responseCdmaSms(Parcel &p, void *response, size_t responselen) {
4202 int num;
4203 int digitCount;
4204 int digitLimit;
4205 uint8_t uct;
4206 void* dest;
4207
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004208 RLOGD("Inside responseCdmaSms");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004209
4210 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004211 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004212 return RIL_ERRNO_INVALID_RESPONSE;
4213 }
4214
4215 if (responselen != sizeof(RIL_CDMA_SMS_Message)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004216 RLOGE("invalid response length was %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004217 (int)responselen, (int)sizeof(RIL_CDMA_SMS_Message));
4218 return RIL_ERRNO_INVALID_RESPONSE;
4219 }
4220
4221 RIL_CDMA_SMS_Message *p_cur = (RIL_CDMA_SMS_Message *) response;
4222 p.writeInt32(p_cur->uTeleserviceID);
4223 p.write(&(p_cur->bIsServicePresent),sizeof(uct));
4224 p.writeInt32(p_cur->uServicecategory);
4225 p.writeInt32(p_cur->sAddress.digit_mode);
4226 p.writeInt32(p_cur->sAddress.number_mode);
4227 p.writeInt32(p_cur->sAddress.number_type);
4228 p.writeInt32(p_cur->sAddress.number_plan);
4229 p.write(&(p_cur->sAddress.number_of_digits), sizeof(uct));
4230 digitLimit= MIN((p_cur->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
4231 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
4232 p.write(&(p_cur->sAddress.digits[digitCount]),sizeof(uct));
4233 }
4234
4235 p.writeInt32(p_cur->sSubAddress.subaddressType);
4236 p.write(&(p_cur->sSubAddress.odd),sizeof(uct));
4237 p.write(&(p_cur->sSubAddress.number_of_digits),sizeof(uct));
4238 digitLimit= MIN((p_cur->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
4239 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
4240 p.write(&(p_cur->sSubAddress.digits[digitCount]),sizeof(uct));
4241 }
4242
4243 digitLimit= MIN((p_cur->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
4244 p.writeInt32(p_cur->uBearerDataLen);
4245 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
4246 p.write(&(p_cur->aBearerData[digitCount]), sizeof(uct));
4247 }
4248
4249 startResponse;
4250 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
4251 sAddress.digit_mode=%d, sAddress.number_mode=%d, sAddress.number_type=%d, ",
4252 printBuf, p_cur->uTeleserviceID,p_cur->bIsServicePresent,p_cur->uServicecategory,
4253 p_cur->sAddress.digit_mode, p_cur->sAddress.number_mode,p_cur->sAddress.number_type);
4254 closeResponse;
4255
4256 return 0;
4257}
4258
Howard Sue32dbfd2015-01-07 15:55:57 +08004259static int responseDcRtInfo(Parcel &p, void *response, size_t responselen)
4260{
4261 int num = responselen / sizeof(RIL_DcRtInfo);
4262 if ((responselen % sizeof(RIL_DcRtInfo) != 0) || (num != 1)) {
4263 RLOGE("responseDcRtInfo: invalid response length %d expected multiple of %d",
4264 (int)responselen, (int)sizeof(RIL_DcRtInfo));
4265 return RIL_ERRNO_INVALID_RESPONSE;
4266 }
4267
4268 startResponse;
4269 RIL_DcRtInfo *pDcRtInfo = (RIL_DcRtInfo *)response;
4270 p.writeInt64(pDcRtInfo->time);
4271 p.writeInt32(pDcRtInfo->powerState);
4272 appendPrintBuf("%s[time=%d,powerState=%d]", printBuf,
4273 pDcRtInfo->time,
Christopher N. Hesse65084862017-02-07 22:21:27 +01004274 pDcRtInfo->powerState);
Howard Sue32dbfd2015-01-07 15:55:57 +08004275 closeResponse;
4276
4277 return 0;
4278}
4279
fenglu9bdede02015-04-14 14:53:55 -07004280static int responseLceStatus(Parcel &p, void *response, size_t responselen) {
4281 if (response == NULL || responselen != sizeof(RIL_LceStatusInfo)) {
4282 if (response == NULL) {
4283 RLOGE("invalid response: NULL");
4284 }
4285 else {
Christopher N. Hesse65084862017-02-07 22:21:27 +01004286 RLOGE("responseLceStatus: invalid response length %u expecting len: %u",
4287 (unsigned)sizeof(RIL_LceStatusInfo), (unsigned)responselen);
fenglu9bdede02015-04-14 14:53:55 -07004288 }
4289 return RIL_ERRNO_INVALID_RESPONSE;
4290 }
4291
4292 RIL_LceStatusInfo *p_cur = (RIL_LceStatusInfo *)response;
4293 p.write((void *)p_cur, 1); // p_cur->lce_status takes one byte.
4294 p.writeInt32(p_cur->actual_interval_ms);
4295
4296 startResponse;
4297 appendPrintBuf("LCE Status: %d, actual_interval_ms: %d",
4298 p_cur->lce_status, p_cur->actual_interval_ms);
4299 closeResponse;
4300
4301 return 0;
4302}
4303
4304static int responseLceData(Parcel &p, void *response, size_t responselen) {
4305 if (response == NULL || responselen != sizeof(RIL_LceDataInfo)) {
4306 if (response == NULL) {
4307 RLOGE("invalid response: NULL");
4308 }
4309 else {
Christopher N. Hesse65084862017-02-07 22:21:27 +01004310 RLOGE("responseLceData: invalid response length %u expecting len: %u",
4311 (unsigned)sizeof(RIL_LceDataInfo), (unsigned)responselen);
fenglu9bdede02015-04-14 14:53:55 -07004312 }
4313 return RIL_ERRNO_INVALID_RESPONSE;
4314 }
4315
4316 RIL_LceDataInfo *p_cur = (RIL_LceDataInfo *)response;
4317 p.writeInt32(p_cur->last_hop_capacity_kbps);
4318
4319 /* p_cur->confidence_level and p_cur->lce_suspended take 1 byte each.*/
4320 p.write((void *)&(p_cur->confidence_level), 1);
4321 p.write((void *)&(p_cur->lce_suspended), 1);
4322
4323 startResponse;
Hyejine942c332015-09-14 16:27:28 -07004324 appendPrintBuf("LCE info received: capacity %d confidence level %d \
4325 and suspended %d",
fenglu9bdede02015-04-14 14:53:55 -07004326 p_cur->last_hop_capacity_kbps, p_cur->confidence_level,
4327 p_cur->lce_suspended);
4328 closeResponse;
4329
4330 return 0;
4331}
4332
Prerepa Viswanadham8e755592015-05-28 00:37:32 -07004333static int responseActivityData(Parcel &p, void *response, size_t responselen) {
4334 if (response == NULL || responselen != sizeof(RIL_ActivityStatsInfo)) {
4335 if (response == NULL) {
4336 RLOGE("invalid response: NULL");
4337 }
4338 else {
Christopher N. Hesse65084862017-02-07 22:21:27 +01004339 RLOGE("responseActivityData: invalid response length %u expecting len: %u",
4340 (unsigned)sizeof(RIL_ActivityStatsInfo), (unsigned)responselen);
Prerepa Viswanadham8e755592015-05-28 00:37:32 -07004341 }
4342 return RIL_ERRNO_INVALID_RESPONSE;
4343 }
4344
4345 RIL_ActivityStatsInfo *p_cur = (RIL_ActivityStatsInfo *)response;
4346 p.writeInt32(p_cur->sleep_mode_time_ms);
4347 p.writeInt32(p_cur->idle_mode_time_ms);
4348 for(int i = 0; i < RIL_NUM_TX_POWER_LEVELS; i++) {
4349 p.writeInt32(p_cur->tx_mode_time_ms[i]);
4350 }
4351 p.writeInt32(p_cur->rx_mode_time_ms);
4352
4353 startResponse;
Hyejine942c332015-09-14 16:27:28 -07004354 appendPrintBuf("Modem activity info received: sleep_mode_time_ms %d idle_mode_time_ms %d \
4355 tx_mode_time_ms %d %d %d %d %d and rx_mode_time_ms %d",
Prerepa Viswanadham8e755592015-05-28 00:37:32 -07004356 p_cur->sleep_mode_time_ms, p_cur->idle_mode_time_ms, p_cur->tx_mode_time_ms[0],
4357 p_cur->tx_mode_time_ms[1], p_cur->tx_mode_time_ms[2], p_cur->tx_mode_time_ms[3],
4358 p_cur->tx_mode_time_ms[4], p_cur->rx_mode_time_ms);
4359 closeResponse;
4360
4361 return 0;
4362}
4363
Christopher N. Hesse65084862017-02-07 22:21:27 +01004364static int responseCarrierRestrictions(Parcel &p, void *response, size_t responselen) {
4365 if (response == NULL) {
4366 RLOGE("invalid response: NULL");
4367 return RIL_ERRNO_INVALID_RESPONSE;
4368 }
4369 if (responselen != sizeof(RIL_CarrierRestrictions)) {
4370 RLOGE("responseCarrierRestrictions: invalid response length %u expecting len: %u",
4371 (unsigned)responselen, (unsigned)sizeof(RIL_CarrierRestrictions));
4372 return RIL_ERRNO_INVALID_RESPONSE;
4373 }
4374
4375 RIL_CarrierRestrictions *p_cr = (RIL_CarrierRestrictions *)response;
4376 startResponse;
4377
4378 p.writeInt32(p_cr->len_allowed_carriers);
4379 p.writeInt32(p_cr->len_excluded_carriers);
4380 appendPrintBuf(" %s len_allowed_carriers: %d, len_excluded_carriers: %d,", printBuf,
4381 p_cr->len_allowed_carriers,p_cr->len_excluded_carriers);
4382
4383 appendPrintBuf(" %s allowed_carriers:", printBuf);
4384 for(int32_t i = 0; i < p_cr->len_allowed_carriers; i++) {
4385 RIL_Carrier *carrier = p_cr->allowed_carriers + i;
4386 writeStringToParcel(p, carrier->mcc);
4387 writeStringToParcel(p, carrier->mnc);
4388 p.writeInt32(carrier->match_type);
4389 writeStringToParcel(p, carrier->match_data);
4390 appendPrintBuf(" %s [%d mcc: %s, mnc: %s, match_type: %d, match_data: %s],", printBuf,
4391 i, carrier->mcc, carrier->mnc, carrier->match_type, carrier->match_data);
4392 }
4393
4394 appendPrintBuf(" %s excluded_carriers:", printBuf);
4395 for(int32_t i = 0; i < p_cr->len_excluded_carriers; i++) {
4396 RIL_Carrier *carrier = p_cr->excluded_carriers + i;
4397 writeStringToParcel(p, carrier->mcc);
4398 writeStringToParcel(p, carrier->mnc);
4399 p.writeInt32(carrier->match_type);
4400 writeStringToParcel(p, carrier->match_data);
4401 appendPrintBuf(" %s [%d mcc: %s, mnc: %s, match_type: %d, match_data: %s],", printBuf,
4402 i, carrier->mcc, carrier->mnc, carrier->match_type, carrier->match_data);
4403 }
4404
4405 closeResponse;
4406
4407 return 0;
4408}
4409
4410static int responsePcoData(Parcel &p, void *response, size_t responselen) {
4411 if (response == NULL) {
4412 RLOGE("responsePcoData: invalid NULL response");
4413 return RIL_ERRNO_INVALID_RESPONSE;
4414 }
4415 if (responselen != sizeof(RIL_PCO_Data)) {
4416 RLOGE("responsePcoData: invalid response length %u, expecting %u",
4417 (unsigned)responselen, (unsigned)sizeof(RIL_PCO_Data));
4418 return RIL_ERRNO_INVALID_RESPONSE;
4419 }
4420
4421 RIL_PCO_Data *p_cur = (RIL_PCO_Data *)response;
4422 p.writeInt32(p_cur->cid);
4423 writeStringToParcel(p, p_cur->bearer_proto);
4424 p.writeInt32(p_cur->pco_id);
4425 p.writeInt32(p_cur->contents_length);
4426 p.write(p_cur->contents, p_cur->contents_length);
4427
4428 startResponse;
4429 appendPrintBuf("PCO data received: cid %d, id %d, length %d",
4430 p_cur->cid, p_cur->pco_id, p_cur->contents_length);
4431 closeResponse;
4432
4433 return 0;
4434}
4435
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004436/**
4437 * A write on the wakeup fd is done just to pop us out of select()
4438 * We empty the buffer here and then ril_event will reset the timers on the
4439 * way back down
4440 */
4441static void processWakeupCallback(int fd, short flags, void *param) {
4442 char buff[16];
4443 int ret;
4444
Ethan Chend6e30652013-08-04 22:49:56 -07004445 RLOGV("processWakeupCallback");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004446
4447 /* empty our wakeup socket out */
4448 do {
4449 ret = read(s_fdWakeupRead, &buff, sizeof(buff));
4450 } while (ret > 0 || (ret < 0 && errno == EINTR));
4451}
4452
Howard Sue32dbfd2015-01-07 15:55:57 +08004453static void onCommandsSocketClosed(RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004454 int ret;
4455 RequestInfo *p_cur;
Howard Sue32dbfd2015-01-07 15:55:57 +08004456 /* Hook for current context
4457 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
4458 pthread_mutex_t * pendingRequestsMutexHook = &s_pendingRequestsMutex;
4459 /* pendingRequestsHook refer to &s_pendingRequests */
4460 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004461
Howard Sue32dbfd2015-01-07 15:55:57 +08004462#if (SIM_COUNT >= 2)
4463 if (socket_id == RIL_SOCKET_2) {
4464 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
4465 pendingRequestsHook = &s_pendingRequests_socket2;
4466 }
4467#if (SIM_COUNT >= 3)
4468 else if (socket_id == RIL_SOCKET_3) {
4469 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
4470 pendingRequestsHook = &s_pendingRequests_socket3;
4471 }
4472#endif
4473#if (SIM_COUNT >= 4)
4474 else if (socket_id == RIL_SOCKET_4) {
4475 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
4476 pendingRequestsHook = &s_pendingRequests_socket4;
4477 }
4478#endif
4479#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004480 /* mark pending requests as "cancelled" so we dont report responses */
Howard Sue32dbfd2015-01-07 15:55:57 +08004481 ret = pthread_mutex_lock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004482 assert (ret == 0);
4483
Howard Sue32dbfd2015-01-07 15:55:57 +08004484 p_cur = *pendingRequestsHook;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004485
Howard Sue32dbfd2015-01-07 15:55:57 +08004486 for (p_cur = *pendingRequestsHook
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004487 ; p_cur != NULL
4488 ; p_cur = p_cur->p_next
4489 ) {
4490 p_cur->cancelled = 1;
4491 }
4492
Howard Sue32dbfd2015-01-07 15:55:57 +08004493 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004494 assert (ret == 0);
4495}
4496
4497static void processCommandsCallback(int fd, short flags, void *param) {
4498 RecordStream *p_rs;
4499 void *p_record;
4500 size_t recordlen;
4501 int ret;
Howard Sue32dbfd2015-01-07 15:55:57 +08004502 SocketListenParam *p_info = (SocketListenParam *)param;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004503
Howard Sue32dbfd2015-01-07 15:55:57 +08004504 assert(fd == p_info->fdCommand);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004505
Howard Sue32dbfd2015-01-07 15:55:57 +08004506 p_rs = p_info->p_rs;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004507
4508 for (;;) {
4509 /* loop until EAGAIN/EINTR, end of stream, or other error */
4510 ret = record_stream_get_next(p_rs, &p_record, &recordlen);
4511
4512 if (ret == 0 && p_record == NULL) {
4513 /* end-of-stream */
4514 break;
4515 } else if (ret < 0) {
4516 break;
4517 } else if (ret == 0) { /* && p_record != NULL */
Howard Sue32dbfd2015-01-07 15:55:57 +08004518 processCommandBuffer(p_record, recordlen, p_info->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004519 }
4520 }
4521
4522 if (ret == 0 || !(errno == EAGAIN || errno == EINTR)) {
4523 /* fatal error or end-of-stream */
4524 if (ret != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004525 RLOGE("error on reading command socket errno:%d\n", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004526 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004527 RLOGW("EOS. Closing command socket.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004528 }
4529
Howard Sue32dbfd2015-01-07 15:55:57 +08004530 close(fd);
4531 p_info->fdCommand = -1;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004532
Howard Sue32dbfd2015-01-07 15:55:57 +08004533 ril_event_del(p_info->commands_event);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004534
4535 record_stream_free(p_rs);
4536
4537 /* start listening for new connections again */
4538 rilEventAddWakeup(&s_listen_event);
4539
Howard Sue32dbfd2015-01-07 15:55:57 +08004540 onCommandsSocketClosed(p_info->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004541 }
4542}
4543
Howard Subd82ef12015-04-12 10:25:05 +02004544
Howard Sue32dbfd2015-01-07 15:55:57 +08004545static void onNewCommandConnect(RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004546 // Inform we are connected and the ril version
4547 int rilVer = s_callbacks.version;
Howard Sue32dbfd2015-01-07 15:55:57 +08004548 RIL_UNSOL_RESPONSE(RIL_UNSOL_RIL_CONNECTED,
4549 &rilVer, sizeof(rilVer), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004550
4551 // implicit radio state changed
Howard Sue32dbfd2015-01-07 15:55:57 +08004552 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
4553 NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004554
4555 // Send last NITZ time data, in case it was missed
4556 if (s_lastNITZTimeData != NULL) {
Howard Sue32dbfd2015-01-07 15:55:57 +08004557 sendResponseRaw(s_lastNITZTimeData, s_lastNITZTimeDataSize, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004558
4559 free(s_lastNITZTimeData);
4560 s_lastNITZTimeData = NULL;
4561 }
4562
4563 // Get version string
4564 if (s_callbacks.getVersion != NULL) {
4565 const char *version;
4566 version = s_callbacks.getVersion();
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004567 RLOGI("RIL Daemon version: %s\n", version);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004568
4569 property_set(PROPERTY_RIL_IMPL, version);
4570 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004571 RLOGI("RIL Daemon version: unavailable\n");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004572 property_set(PROPERTY_RIL_IMPL, "unavailable");
4573 }
4574
4575}
4576
4577static void listenCallback (int fd, short flags, void *param) {
4578 int ret;
4579 int err;
4580 int is_phone_socket;
Howard Sue32dbfd2015-01-07 15:55:57 +08004581 int fdCommand = -1;
Christopher N. Hesse65084862017-02-07 22:21:27 +01004582 const char* processName;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004583 RecordStream *p_rs;
Dheeraj Shettycc231012014-07-02 21:27:57 +02004584 MySocketListenParam* listenParam;
4585 RilSocket *sapSocket = NULL;
4586 socketClient *sClient = NULL;
4587
Howard Sue32dbfd2015-01-07 15:55:57 +08004588 SocketListenParam *p_info = (SocketListenParam *)param;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004589
Dheeraj Shettycc231012014-07-02 21:27:57 +02004590 if(RIL_SAP_SOCKET == p_info->type) {
4591 listenParam = (MySocketListenParam *)param;
4592 sapSocket = listenParam->socket;
4593 }
4594
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004595 struct sockaddr_un peeraddr;
4596 socklen_t socklen = sizeof (peeraddr);
4597
4598 struct ucred creds;
4599 socklen_t szCreds = sizeof(creds);
4600
4601 struct passwd *pwd = NULL;
4602
Dheeraj Shettycc231012014-07-02 21:27:57 +02004603 if(NULL == sapSocket) {
4604 assert (*p_info->fdCommand < 0);
4605 assert (fd == *p_info->fdListen);
4606 processName = PHONE_PROCESS;
4607 } else {
4608 assert (sapSocket->commandFd < 0);
4609 assert (fd == sapSocket->listenFd);
4610 processName = BLUETOOTH_PROCESS;
4611 }
4612
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004613
Howard Sue32dbfd2015-01-07 15:55:57 +08004614 fdCommand = accept(fd, (sockaddr *) &peeraddr, &socklen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004615
Howard Sue32dbfd2015-01-07 15:55:57 +08004616 if (fdCommand < 0 ) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004617 RLOGE("Error on accept() errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004618 /* start listening for new connections again */
Dheeraj Shettycc231012014-07-02 21:27:57 +02004619 if(NULL == sapSocket) {
4620 rilEventAddWakeup(p_info->listen_event);
4621 } else {
4622 rilEventAddWakeup(sapSocket->getListenEvent());
4623 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004624 return;
4625 }
4626
4627 /* check the credential of the other side and only accept socket from
4628 * phone process
4629 */
4630 errno = 0;
4631 is_phone_socket = 0;
4632
Howard Sue32dbfd2015-01-07 15:55:57 +08004633 err = getsockopt(fdCommand, SOL_SOCKET, SO_PEERCRED, &creds, &szCreds);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004634
4635 if (err == 0 && szCreds > 0) {
4636 errno = 0;
4637 pwd = getpwuid(creds.uid);
4638 if (pwd != NULL) {
Dheeraj Shettycc231012014-07-02 21:27:57 +02004639 if (strcmp(pwd->pw_name, processName) == 0) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004640 is_phone_socket = 1;
4641 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004642 RLOGE("RILD can't accept socket from process %s", pwd->pw_name);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004643 }
4644 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004645 RLOGE("Error on getpwuid() errno: %d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004646 }
4647 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004648 RLOGD("Error on getsockopt() errno: %d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004649 }
4650
Howard Subd82ef12015-04-12 10:25:05 +02004651 if (!is_phone_socket) {
Dheeraj Shettycc231012014-07-02 21:27:57 +02004652 RLOGE("RILD must accept socket from %s", processName);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004653
Dheeraj Shettycc231012014-07-02 21:27:57 +02004654 close(fdCommand);
4655 fdCommand = -1;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004656
Dheeraj Shettycc231012014-07-02 21:27:57 +02004657 if(NULL == sapSocket) {
4658 onCommandsSocketClosed(p_info->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004659
Dheeraj Shettycc231012014-07-02 21:27:57 +02004660 /* start listening for new connections again */
4661 rilEventAddWakeup(p_info->listen_event);
4662 } else {
4663 sapSocket->onCommandsSocketClosed();
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004664
Dheeraj Shettycc231012014-07-02 21:27:57 +02004665 /* start listening for new connections again */
4666 rilEventAddWakeup(sapSocket->getListenEvent());
4667 }
4668
4669 return;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004670 }
4671
Howard Sue32dbfd2015-01-07 15:55:57 +08004672 ret = fcntl(fdCommand, F_SETFL, O_NONBLOCK);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004673
4674 if (ret < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004675 RLOGE ("Error setting O_NONBLOCK errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004676 }
4677
Dheeraj Shettycc231012014-07-02 21:27:57 +02004678 if(NULL == sapSocket) {
4679 RLOGI("libril: new connection to %s", rilSocketIdToString(p_info->socket_id));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004680
Dheeraj Shettycc231012014-07-02 21:27:57 +02004681 p_info->fdCommand = fdCommand;
4682 p_rs = record_stream_new(p_info->fdCommand, MAX_COMMAND_BYTES);
4683 p_info->p_rs = p_rs;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004684
Dheeraj Shettycc231012014-07-02 21:27:57 +02004685 ril_event_set (p_info->commands_event, p_info->fdCommand, 1,
Howard Sue32dbfd2015-01-07 15:55:57 +08004686 p_info->processCommandsCallback, p_info);
Dheeraj Shettycc231012014-07-02 21:27:57 +02004687 rilEventAddWakeup (p_info->commands_event);
Howard Sue32dbfd2015-01-07 15:55:57 +08004688
Dheeraj Shettycc231012014-07-02 21:27:57 +02004689 onNewCommandConnect(p_info->socket_id);
4690 } else {
4691 RLOGI("libril: new connection");
Howard Sue32dbfd2015-01-07 15:55:57 +08004692
Dheeraj Shettycc231012014-07-02 21:27:57 +02004693 sapSocket->setCommandFd(fdCommand);
4694 p_rs = record_stream_new(sapSocket->getCommandFd(), MAX_COMMAND_BYTES);
4695 sClient = new socketClient(sapSocket,p_rs);
4696 ril_event_set (sapSocket->getCallbackEvent(), sapSocket->getCommandFd(), 1,
4697 sapSocket->getCommandCb(), sClient);
4698
4699 rilEventAddWakeup(sapSocket->getCallbackEvent());
4700 sapSocket->onNewCommandConnect();
4701 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004702}
4703
4704static void freeDebugCallbackArgs(int number, char **args) {
4705 for (int i = 0; i < number; i++) {
4706 if (args[i] != NULL) {
4707 free(args[i]);
4708 }
4709 }
4710 free(args);
4711}
4712
4713static void debugCallback (int fd, short flags, void *param) {
4714 int acceptFD, option;
4715 struct sockaddr_un peeraddr;
4716 socklen_t socklen = sizeof (peeraddr);
4717 int data;
4718 unsigned int qxdm_data[6];
4719 const char *deactData[1] = {"1"};
4720 char *actData[1];
4721 RIL_Dial dialData;
4722 int hangupData[1] = {1};
4723 int number;
4724 char **args;
Howard Sue32dbfd2015-01-07 15:55:57 +08004725 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
4726 int sim_id = 0;
4727
4728 RLOGI("debugCallback for socket %s", rilSocketIdToString(socket_id));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004729
4730 acceptFD = accept (fd, (sockaddr *) &peeraddr, &socklen);
4731
4732 if (acceptFD < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004733 RLOGE ("error accepting on debug port: %d\n", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004734 return;
4735 }
4736
4737 if (recv(acceptFD, &number, sizeof(int), 0) != sizeof(int)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004738 RLOGE ("error reading on socket: number of Args: \n");
Sanket Padawedf3dabe2016-02-29 10:09:26 -08004739 close(acceptFD);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004740 return;
4741 }
Sanket Padawedf3dabe2016-02-29 10:09:26 -08004742
Christopher N. Hesse65084862017-02-07 22:21:27 +01004743 if (number < 0) {
4744 RLOGE ("Invalid number of arguments: \n");
4745 close(acceptFD);
4746 return;
4747 }
4748
4749 args = (char **) calloc(number, sizeof(char*));
Sanket Padawedf3dabe2016-02-29 10:09:26 -08004750 if (args == NULL) {
4751 RLOGE("Memory allocation failed for debug args");
4752 close(acceptFD);
4753 return;
4754 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004755
4756 for (int i = 0; i < number; i++) {
4757 int len;
4758 if (recv(acceptFD, &len, sizeof(int), 0) != sizeof(int)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004759 RLOGE ("error reading on socket: Len of Args: \n");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004760 freeDebugCallbackArgs(i, args);
Sanket Padawedf3dabe2016-02-29 10:09:26 -08004761 close(acceptFD);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004762 return;
4763 }
Sanket Padawedf3dabe2016-02-29 10:09:26 -08004764
Christopher N. Hesse65084862017-02-07 22:21:27 +01004765 if (len == INT_MAX || len < 0) {
4766 RLOGE("Invalid value of len: \n");
4767 freeDebugCallbackArgs(i, args);
4768 close(acceptFD);
4769 return;
4770 }
4771
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004772 // +1 for null-term
Christopher N. Hesse65084862017-02-07 22:21:27 +01004773 args[i] = (char *) calloc(len + 1, sizeof(char));
Sanket Padawedf3dabe2016-02-29 10:09:26 -08004774 if (args[i] == NULL) {
4775 RLOGE("Memory allocation failed for debug args");
4776 freeDebugCallbackArgs(i, args);
4777 close(acceptFD);
4778 return;
4779 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004780 if (recv(acceptFD, args[i], sizeof(char) * len, 0)
4781 != (int)sizeof(char) * len) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004782 RLOGE ("error reading on socket: Args[%d] \n", i);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004783 freeDebugCallbackArgs(i, args);
Sanket Padawedf3dabe2016-02-29 10:09:26 -08004784 close(acceptFD);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004785 return;
4786 }
4787 char * buf = args[i];
4788 buf[len] = 0;
Howard Sue32dbfd2015-01-07 15:55:57 +08004789 if ((i+1) == number) {
4790 /* The last argument should be sim id 0(SIM1)~3(SIM4) */
4791 sim_id = atoi(args[i]);
4792 switch (sim_id) {
4793 case 0:
4794 socket_id = RIL_SOCKET_1;
4795 break;
4796 #if (SIM_COUNT >= 2)
4797 case 1:
4798 socket_id = RIL_SOCKET_2;
4799 break;
4800 #endif
4801 #if (SIM_COUNT >= 3)
4802 case 2:
4803 socket_id = RIL_SOCKET_3;
4804 break;
4805 #endif
4806 #if (SIM_COUNT >= 4)
4807 case 3:
4808 socket_id = RIL_SOCKET_4;
4809 break;
4810 #endif
4811 default:
4812 socket_id = RIL_SOCKET_1;
4813 break;
4814 }
4815 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004816 }
4817
4818 switch (atoi(args[0])) {
4819 case 0:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004820 RLOGI ("Connection on debug port: issuing reset.");
Howard Sue32dbfd2015-01-07 15:55:57 +08004821 issueLocalRequest(RIL_REQUEST_RESET_RADIO, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004822 break;
4823 case 1:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004824 RLOGI ("Connection on debug port: issuing radio power off.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004825 data = 0;
Howard Sue32dbfd2015-01-07 15:55:57 +08004826 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004827 // Close the socket
Howard Subd82ef12015-04-12 10:25:05 +02004828 if (socket_id == RIL_SOCKET_1 && s_ril_param_socket.fdCommand > 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08004829 close(s_ril_param_socket.fdCommand);
4830 s_ril_param_socket.fdCommand = -1;
4831 }
4832 #if (SIM_COUNT == 2)
4833 else if (socket_id == RIL_SOCKET_2 && s_ril_param_socket2.fdCommand > 0) {
4834 close(s_ril_param_socket2.fdCommand);
4835 s_ril_param_socket2.fdCommand = -1;
4836 }
4837 #endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004838 break;
4839 case 2:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004840 RLOGI ("Debug port: issuing unsolicited voice network change.");
Howard Sue32dbfd2015-01-07 15:55:57 +08004841 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004842 break;
4843 case 3:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004844 RLOGI ("Debug port: QXDM log enable.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004845 qxdm_data[0] = 65536; // head.func_tag
4846 qxdm_data[1] = 16; // head.len
4847 qxdm_data[2] = 1; // mode: 1 for 'start logging'
4848 qxdm_data[3] = 32; // log_file_size: 32megabytes
4849 qxdm_data[4] = 0; // log_mask
4850 qxdm_data[5] = 8; // log_max_fileindex
4851 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Howard Sue32dbfd2015-01-07 15:55:57 +08004852 6 * sizeof(int), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004853 break;
4854 case 4:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004855 RLOGI ("Debug port: QXDM log disable.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004856 qxdm_data[0] = 65536;
4857 qxdm_data[1] = 16;
4858 qxdm_data[2] = 0; // mode: 0 for 'stop logging'
4859 qxdm_data[3] = 32;
4860 qxdm_data[4] = 0;
4861 qxdm_data[5] = 8;
4862 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Howard Sue32dbfd2015-01-07 15:55:57 +08004863 6 * sizeof(int), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004864 break;
4865 case 5:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004866 RLOGI("Debug port: Radio On");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004867 data = 1;
Howard Sue32dbfd2015-01-07 15:55:57 +08004868 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004869 sleep(2);
4870 // Set network selection automatic.
Howard Sue32dbfd2015-01-07 15:55:57 +08004871 issueLocalRequest(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004872 break;
4873 case 6:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004874 RLOGI("Debug port: Setup Data Call, Apn :%s\n", args[1]);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004875 actData[0] = args[1];
4876 issueLocalRequest(RIL_REQUEST_SETUP_DATA_CALL, &actData,
Howard Sue32dbfd2015-01-07 15:55:57 +08004877 sizeof(actData), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004878 break;
4879 case 7:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004880 RLOGI("Debug port: Deactivate Data Call");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004881 issueLocalRequest(RIL_REQUEST_DEACTIVATE_DATA_CALL, &deactData,
Howard Sue32dbfd2015-01-07 15:55:57 +08004882 sizeof(deactData), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004883 break;
4884 case 8:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004885 RLOGI("Debug port: Dial Call");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004886 dialData.clir = 0;
4887 dialData.address = args[1];
Howard Sue32dbfd2015-01-07 15:55:57 +08004888 issueLocalRequest(RIL_REQUEST_DIAL, &dialData, sizeof(dialData), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004889 break;
4890 case 9:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004891 RLOGI("Debug port: Answer Call");
Howard Sue32dbfd2015-01-07 15:55:57 +08004892 issueLocalRequest(RIL_REQUEST_ANSWER, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004893 break;
4894 case 10:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004895 RLOGI("Debug port: End Call");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004896 issueLocalRequest(RIL_REQUEST_HANGUP, &hangupData,
Howard Sue32dbfd2015-01-07 15:55:57 +08004897 sizeof(hangupData), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004898 break;
4899 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004900 RLOGE ("Invalid request");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004901 break;
4902 }
4903 freeDebugCallbackArgs(number, args);
4904 close(acceptFD);
4905}
4906
4907
4908static void userTimerCallback (int fd, short flags, void *param) {
4909 UserCallbackInfo *p_info;
4910
4911 p_info = (UserCallbackInfo *)param;
4912
4913 p_info->p_callback(p_info->userParam);
4914
4915
4916 // FIXME generalize this...there should be a cancel mechanism
4917 if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) {
4918 s_last_wake_timeout_info = NULL;
4919 }
4920
4921 free(p_info);
4922}
4923
4924
4925static void *
4926eventLoop(void *param) {
4927 int ret;
4928 int filedes[2];
4929
4930 ril_event_init();
4931
4932 pthread_mutex_lock(&s_startupMutex);
4933
4934 s_started = 1;
4935 pthread_cond_broadcast(&s_startupCond);
4936
4937 pthread_mutex_unlock(&s_startupMutex);
4938
4939 ret = pipe(filedes);
4940
4941 if (ret < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004942 RLOGE("Error in pipe() errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004943 return NULL;
4944 }
4945
4946 s_fdWakeupRead = filedes[0];
4947 s_fdWakeupWrite = filedes[1];
4948
4949 fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK);
4950
4951 ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,
4952 processWakeupCallback, NULL);
4953
4954 rilEventAddWakeup (&s_wakeupfd_event);
4955
4956 // Only returns on error
4957 ril_event_loop();
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004958 RLOGE ("error in event_loop_base errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004959 // kill self to restart on error
4960 kill(0, SIGKILL);
4961
4962 return NULL;
4963}
4964
4965extern "C" void
4966RIL_startEventLoop(void) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004967 /* spin up eventLoop thread and wait for it to get started */
4968 s_started = 0;
4969 pthread_mutex_lock(&s_startupMutex);
4970
Howard Sue32dbfd2015-01-07 15:55:57 +08004971 pthread_attr_t attr;
4972 pthread_attr_init(&attr);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004973 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
Howard Sue32dbfd2015-01-07 15:55:57 +08004974
4975 int result = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
4976 if (result != 0) {
4977 RLOGE("Failed to create dispatch thread: %s", strerror(result));
4978 goto done;
4979 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004980
4981 while (s_started == 0) {
4982 pthread_cond_wait(&s_startupCond, &s_startupMutex);
4983 }
4984
Howard Sue32dbfd2015-01-07 15:55:57 +08004985done:
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004986 pthread_mutex_unlock(&s_startupMutex);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004987}
4988
4989// Used for testing purpose only.
4990extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) {
4991 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4992}
4993
Howard Sue32dbfd2015-01-07 15:55:57 +08004994static void startListen(RIL_SOCKET_ID socket_id, SocketListenParam* socket_listen_p) {
4995 int fdListen = -1;
4996 int ret;
4997 char socket_name[10];
4998
4999 memset(socket_name, 0, sizeof(char)*10);
5000
5001 switch(socket_id) {
5002 case RIL_SOCKET_1:
5003 strncpy(socket_name, RIL_getRilSocketName(), 9);
5004 break;
5005 #if (SIM_COUNT >= 2)
5006 case RIL_SOCKET_2:
5007 strncpy(socket_name, SOCKET2_NAME_RIL, 9);
5008 break;
5009 #endif
5010 #if (SIM_COUNT >= 3)
5011 case RIL_SOCKET_3:
5012 strncpy(socket_name, SOCKET3_NAME_RIL, 9);
5013 break;
5014 #endif
5015 #if (SIM_COUNT >= 4)
5016 case RIL_SOCKET_4:
5017 strncpy(socket_name, SOCKET4_NAME_RIL, 9);
5018 break;
5019 #endif
5020 default:
5021 RLOGE("Socket id is wrong!!");
5022 return;
5023 }
5024
5025 RLOGI("Start to listen %s", rilSocketIdToString(socket_id));
5026
5027 fdListen = android_get_control_socket(socket_name);
5028 if (fdListen < 0) {
5029 RLOGE("Failed to get socket %s", socket_name);
5030 exit(-1);
5031 }
5032
5033 ret = listen(fdListen, 4);
5034
5035 if (ret < 0) {
5036 RLOGE("Failed to listen on control socket '%d': %s",
5037 fdListen, strerror(errno));
5038 exit(-1);
5039 }
5040 socket_listen_p->fdListen = fdListen;
5041
5042 /* note: non-persistent so we can accept only one connection at a time */
5043 ril_event_set (socket_listen_p->listen_event, fdListen, false,
5044 listenCallback, socket_listen_p);
5045
5046 rilEventAddWakeup (socket_listen_p->listen_event);
5047}
5048
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005049extern "C" void
5050RIL_register (const RIL_RadioFunctions *callbacks) {
5051 int ret;
5052 int flags;
5053
Howard Sue32dbfd2015-01-07 15:55:57 +08005054 RLOGI("SIM_COUNT: %d", SIM_COUNT);
5055
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005056 if (callbacks == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005057 RLOGE("RIL_register: RIL_RadioFunctions * null");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005058 return;
5059 }
5060 if (callbacks->version < RIL_VERSION_MIN) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005061 RLOGE("RIL_register: version %d is to old, min version is %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005062 callbacks->version, RIL_VERSION_MIN);
5063 return;
5064 }
Sanket Padawe9343e872016-01-11 12:45:43 -08005065
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005066 RLOGE("RIL_register: RIL version %d", callbacks->version);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005067
5068 if (s_registerCalled > 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005069 RLOGE("RIL_register has been called more than once. "
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005070 "Subsequent call ignored");
5071 return;
5072 }
5073
5074 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
5075
Howard Sue32dbfd2015-01-07 15:55:57 +08005076 /* Initialize socket1 parameters */
5077 s_ril_param_socket = {
5078 RIL_SOCKET_1, /* socket_id */
5079 -1, /* fdListen */
5080 -1, /* fdCommand */
5081 PHONE_PROCESS, /* processName */
5082 &s_commands_event, /* commands_event */
5083 &s_listen_event, /* listen_event */
5084 processCommandsCallback, /* processCommandsCallback */
Christopher N. Hesse65084862017-02-07 22:21:27 +01005085 NULL, /* p_rs */
5086 RIL_TELEPHONY_SOCKET /* type */
Howard Sue32dbfd2015-01-07 15:55:57 +08005087 };
5088
5089#if (SIM_COUNT >= 2)
5090 s_ril_param_socket2 = {
5091 RIL_SOCKET_2, /* socket_id */
5092 -1, /* fdListen */
5093 -1, /* fdCommand */
5094 PHONE_PROCESS, /* processName */
5095 &s_commands_event_socket2, /* commands_event */
5096 &s_listen_event_socket2, /* listen_event */
5097 processCommandsCallback, /* processCommandsCallback */
Christopher N. Hesse65084862017-02-07 22:21:27 +01005098 NULL, /* p_rs */
5099 RIL_TELEPHONY_SOCKET /* type */
Howard Sue32dbfd2015-01-07 15:55:57 +08005100 };
5101#endif
5102
5103#if (SIM_COUNT >= 3)
5104 s_ril_param_socket3 = {
5105 RIL_SOCKET_3, /* socket_id */
5106 -1, /* fdListen */
5107 -1, /* fdCommand */
5108 PHONE_PROCESS, /* processName */
5109 &s_commands_event_socket3, /* commands_event */
5110 &s_listen_event_socket3, /* listen_event */
5111 processCommandsCallback, /* processCommandsCallback */
Christopher N. Hesse65084862017-02-07 22:21:27 +01005112 NULL, /* p_rs */
5113 RIL_TELEPHONY_SOCKET /* type */
Howard Sue32dbfd2015-01-07 15:55:57 +08005114 };
5115#endif
5116
5117#if (SIM_COUNT >= 4)
5118 s_ril_param_socket4 = {
5119 RIL_SOCKET_4, /* socket_id */
5120 -1, /* fdListen */
5121 -1, /* fdCommand */
5122 PHONE_PROCESS, /* processName */
5123 &s_commands_event_socket4, /* commands_event */
5124 &s_listen_event_socket4, /* listen_event */
5125 processCommandsCallback, /* processCommandsCallback */
Christopher N. Hesse65084862017-02-07 22:21:27 +01005126 NULL, /* p_rs */
5127 RIL_TELEPHONY_SOCKET /* type */
Howard Sue32dbfd2015-01-07 15:55:57 +08005128 };
5129#endif
5130
Howard Subd82ef12015-04-12 10:25:05 +02005131
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005132 s_registerCalled = 1;
5133
Howard Sue32dbfd2015-01-07 15:55:57 +08005134 RLOGI("s_registerCalled flag set, %d", s_started);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005135 // Little self-check
5136
5137 for (int i = 0; i < (int)NUM_ELEMS(s_commands); i++) {
5138 assert(i == s_commands[i].requestNumber);
5139 }
5140
Howard Subd82ef12015-04-12 10:25:05 +02005141 for (int i = 0; i < (int)NUM_ELEMS(s_commands_v); i++) {
5142 assert(i + RIL_VENDOR_COMMANDS_OFFSET == s_commands[i].requestNumber);
5143 }
5144
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005145 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses); i++) {
Howard Sue32dbfd2015-01-07 15:55:57 +08005146 assert(i + RIL_UNSOL_RESPONSE_BASE
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005147 == s_unsolResponses[i].requestNumber);
5148 }
5149
Howard Subd82ef12015-04-12 10:25:05 +02005150 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses_v); i++) {
5151 assert(i + RIL_UNSOL_RESPONSE_BASE + RIL_VENDOR_COMMANDS_OFFSET
5152 == s_unsolResponses[i].requestNumber);
5153 }
5154
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005155 // New rild impl calls RIL_startEventLoop() first
5156 // old standalone impl wants it here.
5157
5158 if (s_started == 0) {
5159 RIL_startEventLoop();
5160 }
5161
Howard Sue32dbfd2015-01-07 15:55:57 +08005162 // start listen socket1
5163 startListen(RIL_SOCKET_1, &s_ril_param_socket);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005164
Howard Sue32dbfd2015-01-07 15:55:57 +08005165#if (SIM_COUNT >= 2)
5166 // start listen socket2
5167 startListen(RIL_SOCKET_2, &s_ril_param_socket2);
5168#endif /* (SIM_COUNT == 2) */
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005169
Howard Sue32dbfd2015-01-07 15:55:57 +08005170#if (SIM_COUNT >= 3)
5171 // start listen socket3
5172 startListen(RIL_SOCKET_3, &s_ril_param_socket3);
5173#endif /* (SIM_COUNT == 3) */
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005174
Howard Sue32dbfd2015-01-07 15:55:57 +08005175#if (SIM_COUNT >= 4)
5176 // start listen socket4
5177 startListen(RIL_SOCKET_4, &s_ril_param_socket4);
5178#endif /* (SIM_COUNT == 4) */
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005179
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005180
5181#if 1
5182 // start debug interface socket
5183
Howard Sue32dbfd2015-01-07 15:55:57 +08005184 char *inst = NULL;
5185 if (strlen(RIL_getRilSocketName()) >= strlen(SOCKET_NAME_RIL)) {
5186 inst = RIL_getRilSocketName() + strlen(SOCKET_NAME_RIL);
5187 }
5188
5189 char rildebug[MAX_DEBUG_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL_DEBUG;
5190 if (inst != NULL) {
Christopher N. Hesse65084862017-02-07 22:21:27 +01005191 strlcat(rildebug, inst, MAX_DEBUG_SOCKET_NAME_LENGTH);
Howard Sue32dbfd2015-01-07 15:55:57 +08005192 }
5193
5194 s_fdDebug = android_get_control_socket(rildebug);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005195 if (s_fdDebug < 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08005196 RLOGE("Failed to get socket : %s errno:%d", rildebug, errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005197 exit(-1);
5198 }
5199
5200 ret = listen(s_fdDebug, 4);
5201
5202 if (ret < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005203 RLOGE("Failed to listen on ril debug socket '%d': %s",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005204 s_fdDebug, strerror(errno));
5205 exit(-1);
5206 }
5207
5208 ril_event_set (&s_debug_event, s_fdDebug, true,
5209 debugCallback, NULL);
5210
5211 rilEventAddWakeup (&s_debug_event);
5212#endif
5213
5214}
5215
Dheeraj Shettycc231012014-07-02 21:27:57 +02005216extern "C" void
5217RIL_register_socket (RIL_RadioFunctions *(*Init)(const struct RIL_Env *, int, char **),RIL_SOCKET_TYPE socketType, int argc, char **argv) {
5218
5219 RIL_RadioFunctions* UimFuncs = NULL;
5220
5221 if(Init) {
5222 UimFuncs = Init(&RilSapSocket::uimRilEnv, argc, argv);
5223
5224 switch(socketType) {
5225 case RIL_SAP_SOCKET:
5226 RilSapSocket::initSapSocket("sap_uim_socket1", UimFuncs);
5227
5228#if (SIM_COUNT >= 2)
5229 RilSapSocket::initSapSocket("sap_uim_socket2", UimFuncs);
5230#endif
5231
5232#if (SIM_COUNT >= 3)
5233 RilSapSocket::initSapSocket("sap_uim_socket3", UimFuncs);
5234#endif
5235
5236#if (SIM_COUNT >= 4)
5237 RilSapSocket::initSapSocket("sap_uim_socket4", UimFuncs);
5238#endif
Christopher N. Hesse65084862017-02-07 22:21:27 +01005239 break;
5240 default:;
Dheeraj Shettycc231012014-07-02 21:27:57 +02005241 }
5242 }
5243}
5244
Sanket Padawea7c043d2016-01-27 15:09:12 -08005245// Check and remove RequestInfo if its a response and not just ack sent back
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005246static int
Sanket Padawea7c043d2016-01-27 15:09:12 -08005247checkAndDequeueRequestInfoIfAck(struct RequestInfo *pRI, bool isAck) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005248 int ret = 0;
Howard Sue32dbfd2015-01-07 15:55:57 +08005249 /* Hook for current context
5250 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
5251 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
5252 /* pendingRequestsHook refer to &s_pendingRequests */
5253 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005254
5255 if (pRI == NULL) {
5256 return 0;
5257 }
5258
Howard Sue32dbfd2015-01-07 15:55:57 +08005259#if (SIM_COUNT >= 2)
5260 if (pRI->socket_id == RIL_SOCKET_2) {
5261 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
5262 pendingRequestsHook = &s_pendingRequests_socket2;
5263 }
5264#if (SIM_COUNT >= 3)
5265 if (pRI->socket_id == RIL_SOCKET_3) {
5266 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
5267 pendingRequestsHook = &s_pendingRequests_socket3;
5268 }
5269#endif
5270#if (SIM_COUNT >= 4)
5271 if (pRI->socket_id == RIL_SOCKET_4) {
5272 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
5273 pendingRequestsHook = &s_pendingRequests_socket4;
5274 }
5275#endif
5276#endif
5277 pthread_mutex_lock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005278
Howard Sue32dbfd2015-01-07 15:55:57 +08005279 for(RequestInfo **ppCur = pendingRequestsHook
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005280 ; *ppCur != NULL
5281 ; ppCur = &((*ppCur)->p_next)
5282 ) {
5283 if (pRI == *ppCur) {
5284 ret = 1;
Sanket Padawea7c043d2016-01-27 15:09:12 -08005285 if (isAck) { // Async ack
5286 if (pRI->wasAckSent == 1) {
5287 RLOGD("Ack was already sent for %s", requestToString(pRI->pCI->requestNumber));
5288 } else {
5289 pRI->wasAckSent = 1;
5290 }
5291 } else {
5292 *ppCur = (*ppCur)->p_next;
5293 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005294 break;
5295 }
5296 }
5297
Howard Sue32dbfd2015-01-07 15:55:57 +08005298 pthread_mutex_unlock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005299
5300 return ret;
5301}
5302
Sanket Padawea7c043d2016-01-27 15:09:12 -08005303static int findFd(int socket_id) {
Howard Sue32dbfd2015-01-07 15:55:57 +08005304 int fd = s_ril_param_socket.fdCommand;
Howard Sue32dbfd2015-01-07 15:55:57 +08005305#if (SIM_COUNT >= 2)
5306 if (socket_id == RIL_SOCKET_2) {
5307 fd = s_ril_param_socket2.fdCommand;
5308 }
5309#if (SIM_COUNT >= 3)
Sanket Padawea7c043d2016-01-27 15:09:12 -08005310 if (socket_id == RIL_SOCKET_3) {
5311 fd = s_ril_param_socket3.fdCommand;
5312 }
Howard Sue32dbfd2015-01-07 15:55:57 +08005313#endif
5314#if (SIM_COUNT >= 4)
5315 if (socket_id == RIL_SOCKET_4) {
5316 fd = s_ril_param_socket4.fdCommand;
5317 }
5318#endif
5319#endif
Sanket Padawea7c043d2016-01-27 15:09:12 -08005320 return fd;
5321}
5322
5323extern "C" void
5324RIL_onRequestAck(RIL_Token t) {
5325 RequestInfo *pRI;
5326 int ret, fd;
5327
5328 size_t errorOffset;
5329 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
5330
5331 pRI = (RequestInfo *)t;
5332
5333 if (!checkAndDequeueRequestInfoIfAck(pRI, true)) {
5334 RLOGE ("RIL_onRequestAck: invalid RIL_Token");
5335 return;
5336 }
5337
5338 socket_id = pRI->socket_id;
5339 fd = findFd(socket_id);
5340
5341#if VDBG
5342 RLOGD("Request Ack, %s", rilSocketIdToString(socket_id));
5343#endif
5344
5345 appendPrintBuf("Ack [%04d]< %s", pRI->token, requestToString(pRI->pCI->requestNumber));
5346
5347 if (pRI->cancelled == 0) {
5348 Parcel p;
5349
5350 p.writeInt32 (RESPONSE_SOLICITED_ACK);
5351 p.writeInt32 (pRI->token);
5352
5353 if (fd < 0) {
5354 RLOGD ("RIL onRequestComplete: Command channel closed");
5355 }
5356
5357 sendResponse(p, socket_id);
5358 }
5359}
5360
5361extern "C" void
5362RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) {
5363 RequestInfo *pRI;
5364 int ret;
5365 int fd;
5366 size_t errorOffset;
5367 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
5368
5369 pRI = (RequestInfo *)t;
5370
5371 if (!checkAndDequeueRequestInfoIfAck(pRI, false)) {
5372 RLOGE ("RIL_onRequestComplete: invalid RIL_Token");
5373 return;
5374 }
5375
5376 socket_id = pRI->socket_id;
5377 fd = findFd(socket_id);
5378
Robert Greenwaltbc29c432015-04-29 16:57:39 -07005379#if VDBG
Howard Sue32dbfd2015-01-07 15:55:57 +08005380 RLOGD("RequestComplete, %s", rilSocketIdToString(socket_id));
Robert Greenwaltbc29c432015-04-29 16:57:39 -07005381#endif
Howard Sue32dbfd2015-01-07 15:55:57 +08005382
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005383 if (pRI->local > 0) {
5384 // Locally issued command...void only!
5385 // response does not go back up the command socket
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005386 RLOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005387
5388 goto done;
5389 }
5390
5391 appendPrintBuf("[%04d]< %s",
5392 pRI->token, requestToString(pRI->pCI->requestNumber));
5393
5394 if (pRI->cancelled == 0) {
5395 Parcel p;
5396
Sanket Padawea7c043d2016-01-27 15:09:12 -08005397 if (s_callbacks.version >= 13 && pRI->wasAckSent == 1) {
5398 // If ack was already sent, then this call is an asynchronous response. So we need to
5399 // send id indicating that we expect an ack from RIL.java as we acquire wakelock here.
5400 p.writeInt32 (RESPONSE_SOLICITED_ACK_EXP);
5401 grabPartialWakeLock();
5402 } else {
5403 p.writeInt32 (RESPONSE_SOLICITED);
5404 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005405 p.writeInt32 (pRI->token);
5406 errorOffset = p.dataPosition();
5407
5408 p.writeInt32 (e);
5409
5410 if (response != NULL) {
5411 // there is a response payload, no matter success or not.
5412 ret = pRI->pCI->responseFunction(p, response, responselen);
5413
5414 /* if an error occurred, rewind and mark it */
5415 if (ret != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08005416 RLOGE ("responseFunction error, ret %d", ret);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005417 p.setDataPosition(errorOffset);
5418 p.writeInt32 (ret);
5419 }
5420 }
5421
5422 if (e != RIL_E_SUCCESS) {
5423 appendPrintBuf("%s fails by %s", printBuf, failCauseToString(e));
5424 }
5425
Howard Sue32dbfd2015-01-07 15:55:57 +08005426 if (fd < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005427 RLOGD ("RIL onRequestComplete: Command channel closed");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005428 }
Howard Sue32dbfd2015-01-07 15:55:57 +08005429 sendResponse(p, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005430 }
5431
5432done:
5433 free(pRI);
5434}
5435
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005436static void
5437grabPartialWakeLock() {
Sanket Padawea7c043d2016-01-27 15:09:12 -08005438 if (s_callbacks.version >= 13) {
5439 int ret;
5440 ret = pthread_mutex_lock(&s_wakeLockCountMutex);
5441 assert(ret == 0);
5442 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
Sanket Padawedf3dabe2016-02-29 10:09:26 -08005443
5444 UserCallbackInfo *p_info =
5445 internalRequestTimedCallback(wakeTimeoutCallback, NULL, &TIMEVAL_WAKE_TIMEOUT);
5446 if (p_info == NULL) {
5447 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
5448 } else {
5449 s_wakelock_count++;
5450 if (s_last_wake_timeout_info != NULL) {
5451 s_last_wake_timeout_info->userParam = (void *)1;
5452 }
5453 s_last_wake_timeout_info = p_info;
Sanket Padawea7c043d2016-01-27 15:09:12 -08005454 }
Sanket Padawea7c043d2016-01-27 15:09:12 -08005455 ret = pthread_mutex_unlock(&s_wakeLockCountMutex);
5456 assert(ret == 0);
5457 } else {
5458 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
5459 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005460}
5461
5462static void
5463releaseWakeLock() {
Sanket Padawea7c043d2016-01-27 15:09:12 -08005464 if (s_callbacks.version >= 13) {
5465 int ret;
5466 ret = pthread_mutex_lock(&s_wakeLockCountMutex);
5467 assert(ret == 0);
5468
5469 if (s_wakelock_count > 1) {
5470 s_wakelock_count--;
5471 } else {
5472 s_wakelock_count = 0;
5473 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
5474 if (s_last_wake_timeout_info != NULL) {
5475 s_last_wake_timeout_info->userParam = (void *)1;
5476 }
5477 }
5478
5479 ret = pthread_mutex_unlock(&s_wakeLockCountMutex);
5480 assert(ret == 0);
5481 } else {
5482 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
5483 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005484}
5485
5486/**
5487 * Timer callback to put us back to sleep before the default timeout
5488 */
5489static void
5490wakeTimeoutCallback (void *param) {
5491 // We're using "param != NULL" as a cancellation mechanism
Sanket Padawea7c043d2016-01-27 15:09:12 -08005492 if (s_callbacks.version >= 13) {
5493 if (param == NULL) {
5494 int ret;
5495 ret = pthread_mutex_lock(&s_wakeLockCountMutex);
5496 assert(ret == 0);
5497 s_wakelock_count = 0;
5498 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
5499 ret = pthread_mutex_unlock(&s_wakeLockCountMutex);
5500 assert(ret == 0);
5501 }
5502 } else {
5503 if (param == NULL) {
5504 releaseWakeLock();
5505 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005506 }
5507}
5508
5509static int
5510decodeVoiceRadioTechnology (RIL_RadioState radioState) {
5511 switch (radioState) {
5512 case RADIO_STATE_SIM_NOT_READY:
5513 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
5514 case RADIO_STATE_SIM_READY:
5515 return RADIO_TECH_UMTS;
5516
5517 case RADIO_STATE_RUIM_NOT_READY:
5518 case RADIO_STATE_RUIM_READY:
5519 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
5520 case RADIO_STATE_NV_NOT_READY:
5521 case RADIO_STATE_NV_READY:
5522 return RADIO_TECH_1xRTT;
5523
5524 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005525 RLOGD("decodeVoiceRadioTechnology: Invoked with incorrect RadioState");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005526 return -1;
5527 }
5528}
5529
5530static int
5531decodeCdmaSubscriptionSource (RIL_RadioState radioState) {
5532 switch (radioState) {
5533 case RADIO_STATE_SIM_NOT_READY:
5534 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
5535 case RADIO_STATE_SIM_READY:
5536 case RADIO_STATE_RUIM_NOT_READY:
5537 case RADIO_STATE_RUIM_READY:
5538 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
5539 return CDMA_SUBSCRIPTION_SOURCE_RUIM_SIM;
5540
5541 case RADIO_STATE_NV_NOT_READY:
5542 case RADIO_STATE_NV_READY:
5543 return CDMA_SUBSCRIPTION_SOURCE_NV;
5544
5545 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005546 RLOGD("decodeCdmaSubscriptionSource: Invoked with incorrect RadioState");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005547 return -1;
5548 }
5549}
5550
5551static int
5552decodeSimStatus (RIL_RadioState radioState) {
5553 switch (radioState) {
5554 case RADIO_STATE_SIM_NOT_READY:
5555 case RADIO_STATE_RUIM_NOT_READY:
5556 case RADIO_STATE_NV_NOT_READY:
5557 case RADIO_STATE_NV_READY:
5558 return -1;
5559 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
5560 case RADIO_STATE_SIM_READY:
5561 case RADIO_STATE_RUIM_READY:
5562 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
5563 return radioState;
5564 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005565 RLOGD("decodeSimStatus: Invoked with incorrect RadioState");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005566 return -1;
5567 }
5568}
5569
5570static bool is3gpp2(int radioTech) {
5571 switch (radioTech) {
5572 case RADIO_TECH_IS95A:
5573 case RADIO_TECH_IS95B:
5574 case RADIO_TECH_1xRTT:
5575 case RADIO_TECH_EVDO_0:
5576 case RADIO_TECH_EVDO_A:
5577 case RADIO_TECH_EVDO_B:
5578 case RADIO_TECH_EHRPD:
5579 return true;
5580 default:
5581 return false;
5582 }
5583}
5584
5585/* If RIL sends SIM states or RUIM states, store the voice radio
5586 * technology and subscription source information so that they can be
5587 * returned when telephony framework requests them
5588 */
5589static RIL_RadioState
Howard Subd82ef12015-04-12 10:25:05 +02005590processRadioState(RIL_RadioState newRadioState, RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005591
5592 if((newRadioState > RADIO_STATE_UNAVAILABLE) && (newRadioState < RADIO_STATE_ON)) {
5593 int newVoiceRadioTech;
5594 int newCdmaSubscriptionSource;
5595 int newSimStatus;
5596
5597 /* This is old RIL. Decode Subscription source and Voice Radio Technology
5598 from Radio State and send change notifications if there has been a change */
5599 newVoiceRadioTech = decodeVoiceRadioTechnology(newRadioState);
5600 if(newVoiceRadioTech != voiceRadioTech) {
5601 voiceRadioTech = newVoiceRadioTech;
Howard Sue32dbfd2015-01-07 15:55:57 +08005602 RIL_UNSOL_RESPONSE(RIL_UNSOL_VOICE_RADIO_TECH_CHANGED,
5603 &voiceRadioTech, sizeof(voiceRadioTech), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005604 }
5605 if(is3gpp2(newVoiceRadioTech)) {
5606 newCdmaSubscriptionSource = decodeCdmaSubscriptionSource(newRadioState);
5607 if(newCdmaSubscriptionSource != cdmaSubscriptionSource) {
5608 cdmaSubscriptionSource = newCdmaSubscriptionSource;
Howard Sue32dbfd2015-01-07 15:55:57 +08005609 RIL_UNSOL_RESPONSE(RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED,
5610 &cdmaSubscriptionSource, sizeof(cdmaSubscriptionSource), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005611 }
5612 }
5613 newSimStatus = decodeSimStatus(newRadioState);
5614 if(newSimStatus != simRuimStatus) {
5615 simRuimStatus = newSimStatus;
Howard Sue32dbfd2015-01-07 15:55:57 +08005616 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005617 }
5618
5619 /* Send RADIO_ON to telephony */
5620 newRadioState = RADIO_STATE_ON;
5621 }
5622
5623 return newRadioState;
5624}
5625
Howard Subd82ef12015-04-12 10:25:05 +02005626
Howard Sue32dbfd2015-01-07 15:55:57 +08005627#if defined(ANDROID_MULTI_SIM)
5628extern "C"
Andreas Schneider47b2d962015-04-13 22:54:49 +02005629void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Howard Sue32dbfd2015-01-07 15:55:57 +08005630 size_t datalen, RIL_SOCKET_ID socket_id)
5631#else
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005632extern "C"
Andreas Schneider47b2d962015-04-13 22:54:49 +02005633void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005634 size_t datalen)
Howard Sue32dbfd2015-01-07 15:55:57 +08005635#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005636{
Christopher N. Hesse65084862017-02-07 22:21:27 +01005637 int unsolResponseIndex;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005638 int ret;
5639 int64_t timeReceived = 0;
5640 bool shouldScheduleTimeout = false;
5641 RIL_RadioState newState;
Howard Sue32dbfd2015-01-07 15:55:57 +08005642 RIL_SOCKET_ID soc_id = RIL_SOCKET_1;
Howard Subd82ef12015-04-12 10:25:05 +02005643 UnsolResponseInfo *pRI = NULL;
Christopher N. Hesse65084862017-02-07 22:21:27 +01005644 int32_t pRI_elements;
Howard Sue32dbfd2015-01-07 15:55:57 +08005645
5646#if defined(ANDROID_MULTI_SIM)
5647 soc_id = socket_id;
5648#endif
5649
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005650
5651 if (s_registerCalled == 0) {
5652 // Ignore RIL_onUnsolicitedResponse before RIL_register
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005653 RLOGW("RIL_onUnsolicitedResponse called before RIL_register");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005654 return;
5655 }
Howard Sue32dbfd2015-01-07 15:55:57 +08005656
Christopher N. Hesse65084862017-02-07 22:21:27 +01005657 unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
5658 pRI = s_unsolResponses;
5659
Howard Subd82ef12015-04-12 10:25:05 +02005660 /* Hack to include Samsung responses */
5661 if (unsolResponse > RIL_VENDOR_COMMANDS_OFFSET + RIL_UNSOL_RESPONSE_BASE) {
Christopher N. Hesse65084862017-02-07 22:21:27 +01005662 unsolResponseIndex -= RIL_VENDOR_COMMANDS_OFFSET;
5663 pRI = s_unsolResponses_v;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005664
Christopher N. Hesse65084862017-02-07 22:21:27 +01005665 RLOGD("SAMSUNG: unsolResponse=%d, unsolResponseIndex=%d", unsolResponse, unsolResponseIndex);
5666 }
Howard Subd82ef12015-04-12 10:25:05 +02005667
Christopher N. Hesse65084862017-02-07 22:21:27 +01005668 pRI_elements = pRI == s_unsolResponses
5669 ? (int32_t)NUM_ELEMS(s_unsolResponses) : (int32_t)NUM_ELEMS(s_unsolResponses_v);
5670
5671 if (unsolResponseIndex >= 0 && unsolResponseIndex < pRI_elements) {
5672 pRI = &pRI[unsolResponseIndex];
Howard Subd82ef12015-04-12 10:25:05 +02005673 } else {
Christopher N. Hesse65084862017-02-07 22:21:27 +01005674 RLOGE("unsolResponseIndex out of bounds: %d, using %s response array", unsolResponseIndex,
5675 pRI == s_unsolResponses ? "AOSP" : "Samsung");
Howard Subd82ef12015-04-12 10:25:05 +02005676 }
5677
5678 if (pRI == NULL || pRI->responseFunction == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005679 RLOGE("unsupported unsolicited response code %d", unsolResponse);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005680 return;
5681 }
5682
5683 // Grab a wake lock if needed for this reponse,
5684 // as we exit we'll either release it immediately
5685 // or set a timer to release it later.
Howard Subd82ef12015-04-12 10:25:05 +02005686 switch (pRI->wakeType) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005687 case WAKE_PARTIAL:
5688 grabPartialWakeLock();
5689 shouldScheduleTimeout = true;
5690 break;
5691
5692 case DONT_WAKE:
5693 default:
5694 // No wake lock is grabed so don't set timeout
5695 shouldScheduleTimeout = false;
5696 break;
5697 }
5698
5699 // Mark the time this was received, doing this
5700 // after grabing the wakelock incase getting
5701 // the elapsedRealTime might cause us to goto
5702 // sleep.
5703 if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
5704 timeReceived = elapsedRealtime();
5705 }
5706
5707 appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
5708
5709 Parcel p;
Sanket Padawe9f972082016-02-03 11:46:02 -08005710 if (s_callbacks.version >= 13
5711 && pRI->wakeType == WAKE_PARTIAL) {
5712 p.writeInt32 (RESPONSE_UNSOLICITED_ACK_EXP);
5713 } else {
5714 p.writeInt32 (RESPONSE_UNSOLICITED);
5715 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005716 p.writeInt32 (unsolResponse);
5717
Howard Subd82ef12015-04-12 10:25:05 +02005718 ret = pRI->responseFunction(p, const_cast<void*>(data), datalen);
5719
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005720 if (ret != 0) {
5721 // Problem with the response. Don't continue;
5722 goto error_exit;
5723 }
5724
5725 // some things get more payload
5726 switch(unsolResponse) {
5727 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
Howard Sue32dbfd2015-01-07 15:55:57 +08005728 newState = processRadioState(CALL_ONSTATEREQUEST(soc_id), soc_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005729 p.writeInt32(newState);
5730 appendPrintBuf("%s {%s}", printBuf,
Howard Sue32dbfd2015-01-07 15:55:57 +08005731 radioStateToString(CALL_ONSTATEREQUEST(soc_id)));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005732 break;
5733
5734
5735 case RIL_UNSOL_NITZ_TIME_RECEIVED:
5736 // Store the time that this was received so the
5737 // handler of this message can account for
5738 // the time it takes to arrive and process. In
5739 // particular the system has been known to sleep
5740 // before this message can be processed.
5741 p.writeInt64(timeReceived);
5742 break;
5743 }
5744
Sanket Padawedf3dabe2016-02-29 10:09:26 -08005745 if (s_callbacks.version < 13) {
5746 if (shouldScheduleTimeout) {
5747 UserCallbackInfo *p_info = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
5748 &TIMEVAL_WAKE_TIMEOUT);
5749
5750 if (p_info == NULL) {
5751 goto error_exit;
5752 } else {
5753 // Cancel the previous request
5754 if (s_last_wake_timeout_info != NULL) {
5755 s_last_wake_timeout_info->userParam = (void *)1;
5756 }
5757 s_last_wake_timeout_info = p_info;
5758 }
5759 }
5760 }
5761
Robert Greenwaltbc29c432015-04-29 16:57:39 -07005762#if VDBG
Howard Sue32dbfd2015-01-07 15:55:57 +08005763 RLOGI("%s UNSOLICITED: %s length:%d", rilSocketIdToString(soc_id), requestToString(unsolResponse), p.dataSize());
Robert Greenwaltbc29c432015-04-29 16:57:39 -07005764#endif
Howard Sue32dbfd2015-01-07 15:55:57 +08005765 ret = sendResponse(p, soc_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005766 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
5767
5768 // Unfortunately, NITZ time is not poll/update like everything
5769 // else in the system. So, if the upstream client isn't connected,
5770 // keep a copy of the last NITZ response (with receive time noted
5771 // above) around so we can deliver it when it is connected
5772
5773 if (s_lastNITZTimeData != NULL) {
5774 free (s_lastNITZTimeData);
5775 s_lastNITZTimeData = NULL;
5776 }
5777
Christopher N. Hesse65084862017-02-07 22:21:27 +01005778 s_lastNITZTimeData = calloc(p.dataSize(), 1);
Sanket Padawedf3dabe2016-02-29 10:09:26 -08005779 if (s_lastNITZTimeData == NULL) {
5780 RLOGE("Memory allocation failed in RIL_onUnsolicitedResponse");
5781 goto error_exit;
5782 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005783 s_lastNITZTimeDataSize = p.dataSize();
5784 memcpy(s_lastNITZTimeData, p.data(), p.dataSize());
5785 }
5786
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005787 // Normal exit
5788 return;
5789
5790error_exit:
5791 if (shouldScheduleTimeout) {
5792 releaseWakeLock();
5793 }
5794}
5795
5796/** FIXME generalize this if you track UserCAllbackInfo, clear it
5797 when the callback occurs
5798*/
5799static UserCallbackInfo *
5800internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
5801 const struct timeval *relativeTime)
5802{
5803 struct timeval myRelativeTime;
5804 UserCallbackInfo *p_info;
5805
Christopher N. Hesse65084862017-02-07 22:21:27 +01005806 p_info = (UserCallbackInfo *) calloc(1, sizeof(UserCallbackInfo));
Sanket Padawedf3dabe2016-02-29 10:09:26 -08005807 if (p_info == NULL) {
5808 RLOGE("Memory allocation failed in internalRequestTimedCallback");
5809 return p_info;
5810
5811 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005812
5813 p_info->p_callback = callback;
5814 p_info->userParam = param;
5815
5816 if (relativeTime == NULL) {
5817 /* treat null parameter as a 0 relative time */
5818 memset (&myRelativeTime, 0, sizeof(myRelativeTime));
5819 } else {
5820 /* FIXME I think event_add's tv param is really const anyway */
5821 memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
5822 }
5823
5824 ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
5825
5826 ril_timer_add(&(p_info->event), &myRelativeTime);
5827
5828 triggerEvLoop();
5829 return p_info;
5830}
5831
5832
5833extern "C" void
5834RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
5835 const struct timeval *relativeTime) {
5836 internalRequestTimedCallback (callback, param, relativeTime);
5837}
5838
5839const char *
5840failCauseToString(RIL_Errno e) {
5841 switch(e) {
5842 case RIL_E_SUCCESS: return "E_SUCCESS";
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005843 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RADIO_NOT_AVAILABLE";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005844 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
5845 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
5846 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
5847 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
5848 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
5849 case RIL_E_CANCELLED: return "E_CANCELLED";
5850 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
5851 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
5852 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
5853 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
5854 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
5855#ifdef FEATURE_MULTIMODE_ANDROID
5856 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
5857 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
5858#endif
Sanket Padawe6049dec2016-02-08 14:28:59 -08005859 case RIL_E_FDN_CHECK_FAILURE: return "E_FDN_CHECK_FAILURE";
5860 case RIL_E_MISSING_RESOURCE: return "E_MISSING_RESOURCE";
5861 case RIL_E_NO_SUCH_ELEMENT: return "E_NO_SUCH_ELEMENT";
5862 case RIL_E_DIAL_MODIFIED_TO_USSD: return "E_DIAL_MODIFIED_TO_USSD";
5863 case RIL_E_DIAL_MODIFIED_TO_SS: return "E_DIAL_MODIFIED_TO_SS";
5864 case RIL_E_DIAL_MODIFIED_TO_DIAL: return "E_DIAL_MODIFIED_TO_DIAL";
5865 case RIL_E_USSD_MODIFIED_TO_DIAL: return "E_USSD_MODIFIED_TO_DIAL";
5866 case RIL_E_USSD_MODIFIED_TO_SS: return "E_USSD_MODIFIED_TO_SS";
5867 case RIL_E_USSD_MODIFIED_TO_USSD: return "E_USSD_MODIFIED_TO_USSD";
5868 case RIL_E_SS_MODIFIED_TO_DIAL: return "E_SS_MODIFIED_TO_DIAL";
5869 case RIL_E_SS_MODIFIED_TO_USSD: return "E_SS_MODIFIED_TO_USSD";
5870 case RIL_E_SUBSCRIPTION_NOT_SUPPORTED: return "E_SUBSCRIPTION_NOT_SUPPORTED";
5871 case RIL_E_SS_MODIFIED_TO_SS: return "E_SS_MODIFIED_TO_SS";
5872 case RIL_E_LCE_NOT_SUPPORTED: return "E_LCE_NOT_SUPPORTED";
5873 case RIL_E_NO_MEMORY: return "E_NO_MEMORY";
5874 case RIL_E_INTERNAL_ERR: return "E_INTERNAL_ERR";
5875 case RIL_E_SYSTEM_ERR: return "E_SYSTEM_ERR";
5876 case RIL_E_MODEM_ERR: return "E_MODEM_ERR";
5877 case RIL_E_INVALID_STATE: return "E_INVALID_STATE";
5878 case RIL_E_NO_RESOURCES: return "E_NO_RESOURCES";
5879 case RIL_E_SIM_ERR: return "E_SIM_ERR";
5880 case RIL_E_INVALID_ARGUMENTS: return "E_INVALID_ARGUMENTS";
5881 case RIL_E_INVALID_SIM_STATE: return "E_INVALID_SIM_STATE";
5882 case RIL_E_INVALID_MODEM_STATE: return "E_INVALID_MODEM_STATE";
5883 case RIL_E_INVALID_CALL_ID: return "E_INVALID_CALL_ID";
5884 case RIL_E_NO_SMS_TO_ACK: return "E_NO_SMS_TO_ACK";
5885 case RIL_E_NETWORK_ERR: return "E_NETWORK_ERR";
5886 case RIL_E_REQUEST_RATE_LIMITED: return "E_REQUEST_RATE_LIMITED";
twen.chang7dd377c2016-03-04 18:27:48 +08005887 case RIL_E_SIM_BUSY: return "E_SIM_BUSY";
5888 case RIL_E_SIM_FULL: return "E_SIM_FULL";
5889 case RIL_E_NETWORK_REJECT: return "E_NETWORK_REJECT";
5890 case RIL_E_OPERATION_NOT_ALLOWED: return "E_OPERATION_NOT_ALLOWED";
5891 case RIL_E_EMPTY_RECORD: "E_EMPTY_RECORD";
Ajay Nambi69659752016-03-11 12:02:55 -08005892 case RIL_E_INVALID_SMS_FORMAT: return "E_INVALID_SMS_FORMAT";
5893 case RIL_E_ENCODING_ERR: return "E_ENCODING_ERR";
5894 case RIL_E_INVALID_SMSC_ADDRESS: return "E_INVALID_SMSC_ADDRESS";
5895 case RIL_E_NO_SUCH_ENTRY: return "E_NO_SUCH_ENTRY";
5896 case RIL_E_NETWORK_NOT_READY: return "E_NETWORK_NOT_READY";
5897 case RIL_E_NOT_PROVISIONED: return "E_NOT_PROVISIONED";
Ajay Nambi0af7d1c2016-03-19 09:02:28 -07005898 case RIL_E_NO_SUBSCRIPTION: return "E_NO_SUBSCRIPTION";
5899 case RIL_E_NO_NETWORK_FOUND: return "E_NO_NETWORK_FOUND";
5900 case RIL_E_DEVICE_IN_USE: return "E_DEVICE_IN_USE";
5901 case RIL_E_ABORTED: return "E_ABORTED";
Sanket Padawedb5d1e02016-02-09 09:56:31 -08005902 case RIL_E_OEM_ERROR_1: return "E_OEM_ERROR_1";
5903 case RIL_E_OEM_ERROR_2: return "E_OEM_ERROR_2";
5904 case RIL_E_OEM_ERROR_3: return "E_OEM_ERROR_3";
5905 case RIL_E_OEM_ERROR_4: return "E_OEM_ERROR_4";
5906 case RIL_E_OEM_ERROR_5: return "E_OEM_ERROR_5";
5907 case RIL_E_OEM_ERROR_6: return "E_OEM_ERROR_6";
5908 case RIL_E_OEM_ERROR_7: return "E_OEM_ERROR_7";
5909 case RIL_E_OEM_ERROR_8: return "E_OEM_ERROR_8";
5910 case RIL_E_OEM_ERROR_9: return "E_OEM_ERROR_9";
5911 case RIL_E_OEM_ERROR_10: return "E_OEM_ERROR_10";
5912 case RIL_E_OEM_ERROR_11: return "E_OEM_ERROR_11";
5913 case RIL_E_OEM_ERROR_12: return "E_OEM_ERROR_12";
5914 case RIL_E_OEM_ERROR_13: return "E_OEM_ERROR_13";
5915 case RIL_E_OEM_ERROR_14: return "E_OEM_ERROR_14";
5916 case RIL_E_OEM_ERROR_15: return "E_OEM_ERROR_15";
5917 case RIL_E_OEM_ERROR_16: return "E_OEM_ERROR_16";
5918 case RIL_E_OEM_ERROR_17: return "E_OEM_ERROR_17";
5919 case RIL_E_OEM_ERROR_18: return "E_OEM_ERROR_18";
5920 case RIL_E_OEM_ERROR_19: return "E_OEM_ERROR_19";
5921 case RIL_E_OEM_ERROR_20: return "E_OEM_ERROR_20";
5922 case RIL_E_OEM_ERROR_21: return "E_OEM_ERROR_21";
5923 case RIL_E_OEM_ERROR_22: return "E_OEM_ERROR_22";
5924 case RIL_E_OEM_ERROR_23: return "E_OEM_ERROR_23";
5925 case RIL_E_OEM_ERROR_24: return "E_OEM_ERROR_24";
5926 case RIL_E_OEM_ERROR_25: return "E_OEM_ERROR_25";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005927 default: return "<unknown error>";
5928 }
5929}
5930
5931const char *
5932radioStateToString(RIL_RadioState s) {
5933 switch(s) {
5934 case RADIO_STATE_OFF: return "RADIO_OFF";
5935 case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
5936 case RADIO_STATE_SIM_NOT_READY: return "RADIO_SIM_NOT_READY";
5937 case RADIO_STATE_SIM_LOCKED_OR_ABSENT: return "RADIO_SIM_LOCKED_OR_ABSENT";
5938 case RADIO_STATE_SIM_READY: return "RADIO_SIM_READY";
5939 case RADIO_STATE_RUIM_NOT_READY:return"RADIO_RUIM_NOT_READY";
5940 case RADIO_STATE_RUIM_READY:return"RADIO_RUIM_READY";
5941 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:return"RADIO_RUIM_LOCKED_OR_ABSENT";
5942 case RADIO_STATE_NV_NOT_READY:return"RADIO_NV_NOT_READY";
5943 case RADIO_STATE_NV_READY:return"RADIO_NV_READY";
5944 case RADIO_STATE_ON:return"RADIO_ON";
5945 default: return "<unknown state>";
5946 }
5947}
5948
5949const char *
5950callStateToString(RIL_CallState s) {
5951 switch(s) {
5952 case RIL_CALL_ACTIVE : return "ACTIVE";
5953 case RIL_CALL_HOLDING: return "HOLDING";
5954 case RIL_CALL_DIALING: return "DIALING";
5955 case RIL_CALL_ALERTING: return "ALERTING";
5956 case RIL_CALL_INCOMING: return "INCOMING";
5957 case RIL_CALL_WAITING: return "WAITING";
5958 default: return "<unknown state>";
5959 }
5960}
5961
5962const char *
5963requestToString(int request) {
5964/*
5965 cat libs/telephony/ril_commands.h \
5966 | egrep "^ *{RIL_" \
5967 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
5968
5969
5970 cat libs/telephony/ril_unsol_commands.h \
5971 | egrep "^ *{RIL_" \
5972 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
5973
5974*/
5975 switch(request) {
5976 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
5977 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
5978 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
5979 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
5980 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
5981 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
5982 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
5983 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
5984 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
5985 case RIL_REQUEST_DIAL: return "DIAL";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005986 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
5987 case RIL_REQUEST_HANGUP: return "HANGUP";
5988 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
5989 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
5990 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
5991 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
5992 case RIL_REQUEST_UDUB: return "UDUB";
5993 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
5994 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
5995 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
5996 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
5997 case RIL_REQUEST_OPERATOR: return "OPERATOR";
5998 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
5999 case RIL_REQUEST_DTMF: return "DTMF";
6000 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
6001 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
6002 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
6003 case RIL_REQUEST_SIM_IO: return "SIM_IO";
6004 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
6005 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
6006 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
6007 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
6008 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
6009 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
6010 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
6011 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
6012 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
6013 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
6014 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
6015 case RIL_REQUEST_ANSWER: return "ANSWER";
6016 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
6017 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
6018 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
6019 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
6020 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
6021 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
6022 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
6023 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";
6024 case RIL_REQUEST_DTMF_START: return "DTMF_START";
6025 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
6026 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
6027 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
6028 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
6029 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
6030 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
6031 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
6032 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
6033 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
6034 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
6035 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
Christopher N. Hesse65084862017-02-07 22:21:27 +01006036 case RIL_REQUEST_NV_RESET_CONFIG: return "NV_RESET_CONFIG";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02006037 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
6038 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
6039 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
6040 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
6041 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
6042 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
6043 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
6044 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
6045 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
6046 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
6047 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
6048 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
6049 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
XpLoDWilDba5c6a32013-07-27 21:12:19 +02006050 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE:return"CDMA_SET_SUBSCRIPTION_SOURCE";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02006051 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"CDMA_SET_ROAMING_PREFERENCE";
6052 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"CDMA_QUERY_ROAMING_PREFERENCE";
6053 case RIL_REQUEST_SET_TTY_MODE:return"SET_TTY_MODE";
6054 case RIL_REQUEST_QUERY_TTY_MODE:return"QUERY_TTY_MODE";
6055 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
6056 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
6057 case RIL_REQUEST_CDMA_FLASH:return"CDMA_FLASH";
6058 case RIL_REQUEST_CDMA_BURST_DTMF:return"CDMA_BURST_DTMF";
6059 case RIL_REQUEST_CDMA_SEND_SMS:return"CDMA_SEND_SMS";
6060 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:return"CDMA_SMS_ACKNOWLEDGE";
6061 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG:return"GSM_GET_BROADCAST_SMS_CONFIG";
6062 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG:return"GSM_SET_BROADCAST_SMS_CONFIG";
6063 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG:return "CDMA_GET_BROADCAST_SMS_CONFIG";
6064 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG:return "CDMA_SET_BROADCAST_SMS_CONFIG";
6065 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION:return "CDMA_SMS_BROADCAST_ACTIVATION";
Ethan Chend6e30652013-08-04 22:49:56 -07006066 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return"CDMA_VALIDATE_AND_WRITE_AKEY";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02006067 case RIL_REQUEST_CDMA_SUBSCRIPTION: return"CDMA_SUBSCRIPTION";
6068 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
6069 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
6070 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
6071 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
6072 case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
6073 case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
6074 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
6075 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
6076 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
6077 case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
6078 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
6079 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
6080 case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
Ajay Nambie63b4f62011-11-15 11:19:30 -08006081 case RIL_REQUEST_WRITE_SMS_TO_SIM: return "WRITE_SMS_TO_SIM";
XpLoDWilDba5c6a32013-07-27 21:12:19 +02006082 case RIL_REQUEST_GET_CELL_INFO_LIST: return"GET_CELL_INFO_LIST";
6083 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return"SET_UNSOL_CELL_INFO_LIST_RATE";
Andrew Jiangca4a9a02014-01-18 18:04:08 -05006084 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "RIL_REQUEST_SET_INITIAL_ATTACH_APN";
6085 case RIL_REQUEST_IMS_REGISTRATION_STATE: return "IMS_REGISTRATION_STATE";
6086 case RIL_REQUEST_IMS_SEND_SMS: return "IMS_SEND_SMS";
Howard Sue32dbfd2015-01-07 15:55:57 +08006087 case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "SIM_TRANSMIT_APDU_BASIC";
6088 case RIL_REQUEST_SIM_OPEN_CHANNEL: return "SIM_OPEN_CHANNEL";
6089 case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "SIM_CLOSE_CHANNEL";
6090 case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "SIM_TRANSMIT_APDU_CHANNEL";
Howard Subd82ef12015-04-12 10:25:05 +02006091 case RIL_REQUEST_GET_RADIO_CAPABILITY: return "RIL_REQUEST_GET_RADIO_CAPABILITY";
6092 case RIL_REQUEST_SET_RADIO_CAPABILITY: return "RIL_REQUEST_SET_RADIO_CAPABILITY";
Howard Sue32dbfd2015-01-07 15:55:57 +08006093 case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "SET_UICC_SUBSCRIPTION";
6094 case RIL_REQUEST_ALLOW_DATA: return "ALLOW_DATA";
6095 case RIL_REQUEST_GET_HARDWARE_CONFIG: return "GET_HARDWARE_CONFIG";
6096 case RIL_REQUEST_SIM_AUTHENTICATION: return "SIM_AUTHENTICATION";
6097 case RIL_REQUEST_GET_DC_RT_INFO: return "GET_DC_RT_INFO";
6098 case RIL_REQUEST_SET_DC_RT_INFO_RATE: return "SET_DC_RT_INFO_RATE";
6099 case RIL_REQUEST_SET_DATA_PROFILE: return "SET_DATA_PROFILE";
Christopher N. Hesse65084862017-02-07 22:21:27 +01006100 case RIL_REQUEST_SET_CARRIER_RESTRICTIONS: return "SET_CARRIER_RESTRICTIONS";
6101 case RIL_REQUEST_GET_CARRIER_RESTRICTIONS: return "GET_CARRIER_RESTRICTIONS";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02006102 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
6103 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
6104 case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED";
6105 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
6106 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
6107 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
6108 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
6109 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)";
6110 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
6111 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
Howard Subd82ef12015-04-12 10:25:05 +02006112 case RIL_UNSOL_SUPP_SVC_NOTIFICATION: return "UNSOL_SUPP_SVC_NOTIFICATION";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02006113 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
6114 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
6115 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
6116 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
6117 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL";
6118 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
Christopher N. Hesse65084862017-02-07 22:21:27 +01006119 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02006120 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
6121 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
6122 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_NEW_CDMA_SMS";
6123 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_NEW_BROADCAST_SMS";
6124 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
6125 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
6126 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
6127 case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
6128 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
6129 case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
6130 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
6131 case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
6132 case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
6133 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
6134 case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
6135 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
6136 case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
6137 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
Ethan Chend6e30652013-08-04 22:49:56 -07006138 case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
Andrew Jiangca4a9a02014-01-18 18:04:08 -05006139 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "RESPONSE_IMS_NETWORK_STATE_CHANGED";
Howard Sue32dbfd2015-01-07 15:55:57 +08006140 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return "UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED";
6141 case RIL_UNSOL_SRVCC_STATE_NOTIFY: return "UNSOL_SRVCC_STATE_NOTIFY";
6142 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return "HARDWARE_CONFIG_CHANGED";
6143 case RIL_UNSOL_DC_RT_INFO_CHANGED: return "UNSOL_DC_RT_INFO_CHANGED";
Howard Subd82ef12015-04-12 10:25:05 +02006144 case RIL_UNSOL_ON_SS: return "UNSOL_ON_SS";
6145 case RIL_UNSOL_STK_CC_ALPHA_NOTIFY: return "UNSOL_STK_CC_ALPHA_NOTIFY";
Howard Sue32dbfd2015-01-07 15:55:57 +08006146 case RIL_REQUEST_SHUTDOWN: return "SHUTDOWN";
Christopher N. Hesse65084862017-02-07 22:21:27 +01006147 case RIL_UNSOL_RADIO_CAPABILITY: return "RIL_UNSOL_RADIO_CAPABILITY";
Sanket Padawea7c043d2016-01-27 15:09:12 -08006148 case RIL_RESPONSE_ACKNOWLEDGEMENT: return "RIL_RESPONSE_ACKNOWLEDGEMENT";
Christopher N. Hesse65084862017-02-07 22:21:27 +01006149 case RIL_UNSOL_PCO_DATA: return "RIL_UNSOL_PCO_DATA";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02006150 default: return "<unknown request>";
6151 }
6152}
6153
Howard Sue32dbfd2015-01-07 15:55:57 +08006154const char *
6155rilSocketIdToString(RIL_SOCKET_ID socket_id)
6156{
6157 switch(socket_id) {
6158 case RIL_SOCKET_1:
6159 return "RIL_SOCKET_1";
6160#if (SIM_COUNT >= 2)
6161 case RIL_SOCKET_2:
6162 return "RIL_SOCKET_2";
6163#endif
6164#if (SIM_COUNT >= 3)
6165 case RIL_SOCKET_3:
6166 return "RIL_SOCKET_3";
6167#endif
6168#if (SIM_COUNT >= 4)
6169 case RIL_SOCKET_4:
6170 return "RIL_SOCKET_4";
6171#endif
6172 default:
6173 return "not a valid RIL";
6174 }
6175}
6176
Sanket Padawe9343e872016-01-11 12:45:43 -08006177/*
6178 * Returns true for a debuggable build.
6179 */
6180static bool isDebuggable() {
6181 char debuggable[PROP_VALUE_MAX];
6182 property_get("ro.debuggable", debuggable, "0");
6183 if (strcmp(debuggable, "1") == 0) {
6184 return true;
6185 }
6186 return false;
6187}
6188
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02006189} /* namespace android */
Dheeraj Shettycc231012014-07-02 21:27:57 +02006190
6191void rilEventAddWakeup_helper(struct ril_event *ev) {
6192 android::rilEventAddWakeup(ev);
6193}
6194
6195void listenCallback_helper(int fd, short flags, void *param) {
6196 android::listenCallback(fd, flags, param);
6197}
6198
6199int blockingWrite_helper(int fd, void *buffer, size_t len) {
6200 return android::blockingWrite(fd, buffer, len);
6201}