blob: 4478ea22d683c8a40b242df1d57c3412b6d8334d [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);
Simon Shields5b75c572017-02-13 10:26:17 +11002713#if defined(MODEM_TYPE_XMM6262) || defined(MODEM_TYPE_XMM6260)
2714 writeStringToParcel(p, p_cur[i].addresses);
2715#else
Christopher N. Hesse65084862017-02-07 22:21:27 +01002716 writeStringToParcel(p, p_cur[i].gateways);
Simon Shields5b75c572017-02-13 10:26:17 +11002717#endif
Howard Sue32dbfd2015-01-07 15:55:57 +08002718 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s],", printBuf,
2719 p_cur[i].status,
2720 p_cur[i].suggestedRetryTime,
2721 p_cur[i].cid,
2722 (p_cur[i].active==0)?"down":"up",
2723 (char*)p_cur[i].type,
2724 (char*)p_cur[i].ifname,
2725 (char*)p_cur[i].addresses,
2726 (char*)p_cur[i].dnses,
Simon Shields5b75c572017-02-13 10:26:17 +11002727#if defined(MODEM_TYPE_XMM6262) || defined(MODEM_TYPE_XMM6260)
2728 (char*)p_cur[i].addresses
2729#else
2730 (char*)p_cur[i].gateways
2731#endif
2732 );
Howard Sue32dbfd2015-01-07 15:55:57 +08002733 }
2734 removeLastChar;
2735 closeResponse;
2736
2737 return 0;
2738}
2739
Howard Subd82ef12015-04-12 10:25:05 +02002740static int responseDataCallListV9(Parcel &p, void *response, size_t responselen)
2741{
2742 if (response == NULL && responselen != 0) {
2743 RLOGE("invalid response: NULL");
2744 return RIL_ERRNO_INVALID_RESPONSE;
2745 }
2746
2747 if (responselen % sizeof(RIL_Data_Call_Response_v9) != 0) {
2748 RLOGE("responseDataCallListV9: invalid response length %d expected multiple of %d",
2749 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v9));
2750 return RIL_ERRNO_INVALID_RESPONSE;
2751 }
2752
2753 // Write version
2754 p.writeInt32(10);
2755
2756 int num = responselen / sizeof(RIL_Data_Call_Response_v9);
2757 p.writeInt32(num);
2758
2759 RIL_Data_Call_Response_v9 *p_cur = (RIL_Data_Call_Response_v9 *) response;
2760 startResponse;
2761 int i;
2762 for (i = 0; i < num; i++) {
2763 p.writeInt32((int)p_cur[i].status);
2764 p.writeInt32(p_cur[i].suggestedRetryTime);
2765 p.writeInt32(p_cur[i].cid);
2766 p.writeInt32(p_cur[i].active);
2767 writeStringToParcel(p, p_cur[i].type);
2768 writeStringToParcel(p, p_cur[i].ifname);
2769 writeStringToParcel(p, p_cur[i].addresses);
2770 writeStringToParcel(p, p_cur[i].dnses);
2771 writeStringToParcel(p, p_cur[i].gateways);
2772 writeStringToParcel(p, p_cur[i].pcscf);
2773 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s],", printBuf,
2774 p_cur[i].status,
2775 p_cur[i].suggestedRetryTime,
2776 p_cur[i].cid,
2777 (p_cur[i].active==0)?"down":"up",
2778 (char*)p_cur[i].type,
2779 (char*)p_cur[i].ifname,
2780 (char*)p_cur[i].addresses,
2781 (char*)p_cur[i].dnses,
2782 (char*)p_cur[i].gateways,
2783 (char*)p_cur[i].pcscf);
2784 }
2785 removeLastChar;
2786 closeResponse;
2787
2788 return 0;
2789}
2790
Sanket Padawe9343e872016-01-11 12:45:43 -08002791static int responseDataCallListV11(Parcel &p, void *response, size_t responselen) {
2792 if (response == NULL && responselen != 0) {
2793 RLOGE("invalid response: NULL");
2794 return RIL_ERRNO_INVALID_RESPONSE;
2795 }
2796
2797 if (responselen % sizeof(RIL_Data_Call_Response_v11) != 0) {
2798 RLOGE("invalid response length %d expected multiple of %d",
2799 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v11));
2800 return RIL_ERRNO_INVALID_RESPONSE;
2801 }
2802
2803 // Write version
2804 p.writeInt32(11);
2805
2806 int num = responselen / sizeof(RIL_Data_Call_Response_v11);
2807 p.writeInt32(num);
2808
2809 RIL_Data_Call_Response_v11 *p_cur = (RIL_Data_Call_Response_v11 *) response;
2810 startResponse;
2811 int i;
2812 for (i = 0; i < num; i++) {
2813 p.writeInt32((int)p_cur[i].status);
2814 p.writeInt32(p_cur[i].suggestedRetryTime);
2815 p.writeInt32(p_cur[i].cid);
2816 p.writeInt32(p_cur[i].active);
2817 writeStringToParcel(p, p_cur[i].type);
2818 writeStringToParcel(p, p_cur[i].ifname);
2819 writeStringToParcel(p, p_cur[i].addresses);
2820 writeStringToParcel(p, p_cur[i].dnses);
2821 writeStringToParcel(p, p_cur[i].gateways);
2822 writeStringToParcel(p, p_cur[i].pcscf);
2823 p.writeInt32(p_cur[i].mtu);
2824 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s,mtu=%d],", printBuf,
2825 p_cur[i].status,
2826 p_cur[i].suggestedRetryTime,
2827 p_cur[i].cid,
2828 (p_cur[i].active==0)?"down":"up",
2829 (char*)p_cur[i].type,
2830 (char*)p_cur[i].ifname,
2831 (char*)p_cur[i].addresses,
2832 (char*)p_cur[i].dnses,
2833 (char*)p_cur[i].gateways,
2834 (char*)p_cur[i].pcscf,
2835 p_cur[i].mtu);
2836 }
2837 removeLastChar;
2838 closeResponse;
2839
2840 return 0;
2841}
Howard Subd82ef12015-04-12 10:25:05 +02002842
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002843static int responseDataCallList(Parcel &p, void *response, size_t responselen)
2844{
Sanket Padawe9343e872016-01-11 12:45:43 -08002845 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
2846 if (s_callbacks.version < 5) {
2847 RLOGD("responseDataCallList: v4");
2848 return responseDataCallListV4(p, response, responselen);
2849 } else if (responselen % sizeof(RIL_Data_Call_Response_v6) == 0) {
2850 return responseDataCallListV6(p, response, responselen);
2851 } else if (responselen % sizeof(RIL_Data_Call_Response_v9) == 0) {
2852 return responseDataCallListV9(p, response, responselen);
2853 } else {
2854 return responseDataCallListV11(p, response, responselen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002855 }
Sanket Padawea79128a2016-01-26 18:44:01 -08002856 } else { // RIL version >= 13
Howard Subd82ef12015-04-12 10:25:05 +02002857 if (responselen % sizeof(RIL_Data_Call_Response_v11) != 0) {
Sanket Padawe9343e872016-01-11 12:45:43 -08002858 RLOGE("Data structure expected is RIL_Data_Call_Response_v11");
2859 if (!isDebuggable()) {
2860 return RIL_ERRNO_INVALID_RESPONSE;
2861 } else {
2862 assert(0);
2863 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002864 }
Sanket Padawe9343e872016-01-11 12:45:43 -08002865 return responseDataCallListV11(p, response, responselen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002866 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002867}
2868
2869static int responseSetupDataCall(Parcel &p, void *response, size_t responselen)
2870{
2871 if (s_callbacks.version < 5) {
2872 return responseStringsWithVersion(s_callbacks.version, p, response, responselen);
2873 } else {
2874 return responseDataCallList(p, response, responselen);
2875 }
2876}
2877
2878static int responseRaw(Parcel &p, void *response, size_t responselen) {
2879 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002880 RLOGE("invalid response: NULL with responselen != 0");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002881 return RIL_ERRNO_INVALID_RESPONSE;
2882 }
2883
2884 // The java code reads -1 size as null byte array
2885 if (response == NULL) {
2886 p.writeInt32(-1);
2887 } else {
2888 p.writeInt32(responselen);
2889 p.write(response, responselen);
2890 }
2891
2892 return 0;
2893}
2894
2895
2896static int responseSIM_IO(Parcel &p, void *response, size_t responselen) {
2897 if (response == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002898 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002899 return RIL_ERRNO_INVALID_RESPONSE;
2900 }
2901
2902 if (responselen != sizeof (RIL_SIM_IO_Response) ) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002903 RLOGE("invalid response length was %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002904 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
2905 return RIL_ERRNO_INVALID_RESPONSE;
2906 }
2907
2908 RIL_SIM_IO_Response *p_cur = (RIL_SIM_IO_Response *) response;
2909 p.writeInt32(p_cur->sw1);
2910 p.writeInt32(p_cur->sw2);
2911 writeStringToParcel(p, p_cur->simResponse);
2912
2913 startResponse;
2914 appendPrintBuf("%ssw1=0x%X,sw2=0x%X,%s", printBuf, p_cur->sw1, p_cur->sw2,
2915 (char*)p_cur->simResponse);
2916 closeResponse;
2917
2918
2919 return 0;
2920}
2921
2922static int responseCallForwards(Parcel &p, void *response, size_t responselen) {
2923 int num;
2924
2925 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002926 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002927 return RIL_ERRNO_INVALID_RESPONSE;
2928 }
2929
2930 if (responselen % sizeof(RIL_CallForwardInfo *) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002931 RLOGE("responseCallForwards: invalid response length %d expected multiple of %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002932 (int)responselen, (int)sizeof(RIL_CallForwardInfo *));
2933 return RIL_ERRNO_INVALID_RESPONSE;
2934 }
2935
2936 /* number of call info's */
2937 num = responselen / sizeof(RIL_CallForwardInfo *);
2938 p.writeInt32(num);
2939
2940 startResponse;
2941 for (int i = 0 ; i < num ; i++) {
2942 RIL_CallForwardInfo *p_cur = ((RIL_CallForwardInfo **) response)[i];
2943
2944 p.writeInt32(p_cur->status);
2945 p.writeInt32(p_cur->reason);
2946 p.writeInt32(p_cur->serviceClass);
2947 p.writeInt32(p_cur->toa);
2948 writeStringToParcel(p, p_cur->number);
2949 p.writeInt32(p_cur->timeSeconds);
2950 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
2951 (p_cur->status==1)?"enable":"disable",
2952 p_cur->reason, p_cur->serviceClass, p_cur->toa,
2953 (char*)p_cur->number,
2954 p_cur->timeSeconds);
2955 }
2956 removeLastChar;
2957 closeResponse;
2958
2959 return 0;
2960}
2961
2962static int responseSsn(Parcel &p, void *response, size_t responselen) {
2963 if (response == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002964 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002965 return RIL_ERRNO_INVALID_RESPONSE;
2966 }
2967
2968 if (responselen != sizeof(RIL_SuppSvcNotification)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002969 RLOGE("invalid response length was %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002970 (int)responselen, (int)sizeof (RIL_SuppSvcNotification));
2971 return RIL_ERRNO_INVALID_RESPONSE;
2972 }
2973
2974 RIL_SuppSvcNotification *p_cur = (RIL_SuppSvcNotification *) response;
2975 p.writeInt32(p_cur->notificationType);
2976 p.writeInt32(p_cur->code);
2977 p.writeInt32(p_cur->index);
2978 p.writeInt32(p_cur->type);
2979 writeStringToParcel(p, p_cur->number);
2980
2981 startResponse;
2982 appendPrintBuf("%s%s,code=%d,id=%d,type=%d,%s", printBuf,
2983 (p_cur->notificationType==0)?"mo":"mt",
2984 p_cur->code, p_cur->index, p_cur->type,
2985 (char*)p_cur->number);
2986 closeResponse;
2987
2988 return 0;
2989}
2990
2991static int responseCellList(Parcel &p, void *response, size_t responselen) {
2992 int num;
2993
2994 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002995 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002996 return RIL_ERRNO_INVALID_RESPONSE;
2997 }
2998
2999 if (responselen % sizeof (RIL_NeighboringCell *) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08003000 RLOGE("responseCellList: invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003001 (int)responselen, (int)sizeof (RIL_NeighboringCell *));
3002 return RIL_ERRNO_INVALID_RESPONSE;
3003 }
3004
3005 startResponse;
3006 /* number of records */
3007 num = responselen / sizeof(RIL_NeighboringCell *);
3008 p.writeInt32(num);
3009
3010 for (int i = 0 ; i < num ; i++) {
3011 RIL_NeighboringCell *p_cur = ((RIL_NeighboringCell **) response)[i];
3012
3013 p.writeInt32(p_cur->rssi);
3014 writeStringToParcel (p, p_cur->cid);
3015
3016 appendPrintBuf("%s[cid=%s,rssi=%d],", printBuf,
3017 p_cur->cid, p_cur->rssi);
3018 }
3019 removeLastChar;
3020 closeResponse;
3021
3022 return 0;
3023}
3024
3025/**
3026 * Marshall the signalInfoRecord into the parcel if it exists.
3027 */
3028static void marshallSignalInfoRecord(Parcel &p,
3029 RIL_CDMA_SignalInfoRecord &p_signalInfoRecord) {
3030 p.writeInt32(p_signalInfoRecord.isPresent);
3031 p.writeInt32(p_signalInfoRecord.signalType);
3032 p.writeInt32(p_signalInfoRecord.alertPitch);
3033 p.writeInt32(p_signalInfoRecord.signal);
3034}
3035
3036static int responseCdmaInformationRecords(Parcel &p,
3037 void *response, size_t responselen) {
3038 int num;
3039 char* string8 = NULL;
3040 int buffer_lenght;
3041 RIL_CDMA_InformationRecord *infoRec;
3042
3043 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003044 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003045 return RIL_ERRNO_INVALID_RESPONSE;
3046 }
3047
3048 if (responselen != sizeof (RIL_CDMA_InformationRecords)) {
Howard Sue32dbfd2015-01-07 15:55:57 +08003049 RLOGE("responseCdmaInformationRecords: invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003050 (int)responselen, (int)sizeof (RIL_CDMA_InformationRecords *));
3051 return RIL_ERRNO_INVALID_RESPONSE;
3052 }
3053
3054 RIL_CDMA_InformationRecords *p_cur =
3055 (RIL_CDMA_InformationRecords *) response;
3056 num = MIN(p_cur->numberOfInfoRecs, RIL_CDMA_MAX_NUMBER_OF_INFO_RECS);
3057
3058 startResponse;
3059 p.writeInt32(num);
3060
3061 for (int i = 0 ; i < num ; i++) {
3062 infoRec = &p_cur->infoRec[i];
3063 p.writeInt32(infoRec->name);
3064 switch (infoRec->name) {
3065 case RIL_CDMA_DISPLAY_INFO_REC:
3066 case RIL_CDMA_EXTENDED_DISPLAY_INFO_REC:
3067 if (infoRec->rec.display.alpha_len >
3068 CDMA_ALPHA_INFO_BUFFER_LENGTH) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003069 RLOGE("invalid display info response length %d \
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003070 expected not more than %d\n",
3071 (int)infoRec->rec.display.alpha_len,
3072 CDMA_ALPHA_INFO_BUFFER_LENGTH);
3073 return RIL_ERRNO_INVALID_RESPONSE;
3074 }
Christopher N. Hesse65084862017-02-07 22:21:27 +01003075 string8 = (char*) calloc(infoRec->rec.display.alpha_len + 1, sizeof(char));
Sanket Padawedf3dabe2016-02-29 10:09:26 -08003076 if (string8 == NULL) {
3077 RLOGE("Memory allocation failed for responseCdmaInformationRecords");
3078 closeRequest;
3079 return RIL_ERRNO_NO_MEMORY;
3080 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003081 for (int i = 0 ; i < infoRec->rec.display.alpha_len ; i++) {
3082 string8[i] = infoRec->rec.display.alpha_buf[i];
3083 }
3084 string8[(int)infoRec->rec.display.alpha_len] = '\0';
3085 writeStringToParcel(p, (const char*)string8);
3086 free(string8);
3087 string8 = NULL;
3088 break;
3089 case RIL_CDMA_CALLED_PARTY_NUMBER_INFO_REC:
3090 case RIL_CDMA_CALLING_PARTY_NUMBER_INFO_REC:
3091 case RIL_CDMA_CONNECTED_NUMBER_INFO_REC:
3092 if (infoRec->rec.number.len > CDMA_NUMBER_INFO_BUFFER_LENGTH) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003093 RLOGE("invalid display info response length %d \
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003094 expected not more than %d\n",
3095 (int)infoRec->rec.number.len,
3096 CDMA_NUMBER_INFO_BUFFER_LENGTH);
3097 return RIL_ERRNO_INVALID_RESPONSE;
3098 }
Christopher N. Hesse65084862017-02-07 22:21:27 +01003099 string8 = (char*) calloc(infoRec->rec.number.len + 1, sizeof(char));
Sanket Padawedf3dabe2016-02-29 10:09:26 -08003100 if (string8 == NULL) {
3101 RLOGE("Memory allocation failed for responseCdmaInformationRecords");
3102 closeRequest;
3103 return RIL_ERRNO_NO_MEMORY;
3104 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003105 for (int i = 0 ; i < infoRec->rec.number.len; i++) {
3106 string8[i] = infoRec->rec.number.buf[i];
3107 }
3108 string8[(int)infoRec->rec.number.len] = '\0';
3109 writeStringToParcel(p, (const char*)string8);
3110 free(string8);
3111 string8 = NULL;
3112 p.writeInt32(infoRec->rec.number.number_type);
3113 p.writeInt32(infoRec->rec.number.number_plan);
3114 p.writeInt32(infoRec->rec.number.pi);
3115 p.writeInt32(infoRec->rec.number.si);
3116 break;
3117 case RIL_CDMA_SIGNAL_INFO_REC:
3118 p.writeInt32(infoRec->rec.signal.isPresent);
3119 p.writeInt32(infoRec->rec.signal.signalType);
3120 p.writeInt32(infoRec->rec.signal.alertPitch);
3121 p.writeInt32(infoRec->rec.signal.signal);
3122
3123 appendPrintBuf("%sisPresent=%X, signalType=%X, \
3124 alertPitch=%X, signal=%X, ",
3125 printBuf, (int)infoRec->rec.signal.isPresent,
3126 (int)infoRec->rec.signal.signalType,
3127 (int)infoRec->rec.signal.alertPitch,
3128 (int)infoRec->rec.signal.signal);
3129 removeLastChar;
3130 break;
3131 case RIL_CDMA_REDIRECTING_NUMBER_INFO_REC:
3132 if (infoRec->rec.redir.redirectingNumber.len >
3133 CDMA_NUMBER_INFO_BUFFER_LENGTH) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003134 RLOGE("invalid display info response length %d \
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003135 expected not more than %d\n",
3136 (int)infoRec->rec.redir.redirectingNumber.len,
3137 CDMA_NUMBER_INFO_BUFFER_LENGTH);
3138 return RIL_ERRNO_INVALID_RESPONSE;
3139 }
Christopher N. Hesse65084862017-02-07 22:21:27 +01003140 string8 = (char*) calloc(infoRec->rec.redir.redirectingNumber.len + 1,
3141 sizeof(char));
Sanket Padawedf3dabe2016-02-29 10:09:26 -08003142 if (string8 == NULL) {
3143 RLOGE("Memory allocation failed for responseCdmaInformationRecords");
3144 closeRequest;
3145 return RIL_ERRNO_NO_MEMORY;
3146 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003147 for (int i = 0;
3148 i < infoRec->rec.redir.redirectingNumber.len;
3149 i++) {
3150 string8[i] = infoRec->rec.redir.redirectingNumber.buf[i];
3151 }
3152 string8[(int)infoRec->rec.redir.redirectingNumber.len] = '\0';
3153 writeStringToParcel(p, (const char*)string8);
3154 free(string8);
3155 string8 = NULL;
3156 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_type);
3157 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_plan);
3158 p.writeInt32(infoRec->rec.redir.redirectingNumber.pi);
3159 p.writeInt32(infoRec->rec.redir.redirectingNumber.si);
3160 p.writeInt32(infoRec->rec.redir.redirectingReason);
3161 break;
3162 case RIL_CDMA_LINE_CONTROL_INFO_REC:
3163 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPolarityIncluded);
3164 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlToggle);
3165 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlReverse);
3166 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPowerDenial);
3167
3168 appendPrintBuf("%slineCtrlPolarityIncluded=%d, \
3169 lineCtrlToggle=%d, lineCtrlReverse=%d, \
3170 lineCtrlPowerDenial=%d, ", printBuf,
3171 (int)infoRec->rec.lineCtrl.lineCtrlPolarityIncluded,
3172 (int)infoRec->rec.lineCtrl.lineCtrlToggle,
3173 (int)infoRec->rec.lineCtrl.lineCtrlReverse,
3174 (int)infoRec->rec.lineCtrl.lineCtrlPowerDenial);
3175 removeLastChar;
3176 break;
3177 case RIL_CDMA_T53_CLIR_INFO_REC:
3178 p.writeInt32((int)(infoRec->rec.clir.cause));
3179
3180 appendPrintBuf("%scause%d", printBuf, infoRec->rec.clir.cause);
3181 removeLastChar;
3182 break;
3183 case RIL_CDMA_T53_AUDIO_CONTROL_INFO_REC:
3184 p.writeInt32(infoRec->rec.audioCtrl.upLink);
3185 p.writeInt32(infoRec->rec.audioCtrl.downLink);
3186
3187 appendPrintBuf("%supLink=%d, downLink=%d, ", printBuf,
3188 infoRec->rec.audioCtrl.upLink,
3189 infoRec->rec.audioCtrl.downLink);
3190 removeLastChar;
3191 break;
3192 case RIL_CDMA_T53_RELEASE_INFO_REC:
3193 // TODO(Moto): See David Krause, he has the answer:)
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003194 RLOGE("RIL_CDMA_T53_RELEASE_INFO_REC: return INVALID_RESPONSE");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003195 return RIL_ERRNO_INVALID_RESPONSE;
3196 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003197 RLOGE("Incorrect name value");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003198 return RIL_ERRNO_INVALID_RESPONSE;
3199 }
3200 }
3201 closeResponse;
3202
3203 return 0;
3204}
3205
Sanket Padawe9343e872016-01-11 12:45:43 -08003206static void responseRilSignalStrengthV5(Parcel &p, RIL_SignalStrength_v10 *p_cur) {
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303207 int gsmSignalStrength;
3208 int cdmaDbm;
3209 int evdoDbm;
3210
Sanket Padawe9343e872016-01-11 12:45:43 -08003211 gsmSignalStrength = p_cur->GW_SignalStrength.signalStrength & 0xFF;
Utkarsh Gupta8ede9fa2015-04-23 13:21:49 +05303212
3213#ifdef MODEM_TYPE_XMM6260
3214 if (gsmSignalStrength < 0 ||
3215 (gsmSignalStrength > 31 && p_cur->GW_SignalStrength.signalStrength != 99)) {
3216 gsmSignalStrength = p_cur->CDMA_SignalStrength.dbm;
3217 }
3218#else
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303219 if (gsmSignalStrength < 0) {
3220 gsmSignalStrength = 99;
3221 } else if (gsmSignalStrength > 31 && gsmSignalStrength != 99) {
3222 gsmSignalStrength = 31;
3223 }
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303224#endif
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303225
Christopher N. Hesse621e63e2016-02-22 21:57:39 +01003226#if defined(MODEM_TYPE_XMM6262) || defined(SAMSUNG_NEXT_GEN_MODEM)
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303227 cdmaDbm = p_cur->CDMA_SignalStrength.dbm & 0xFF;
3228 if (cdmaDbm < 0) {
3229 cdmaDbm = 99;
3230 } else if (cdmaDbm > 31 && cdmaDbm != 99) {
3231 cdmaDbm = 31;
3232 }
3233#else
Caio Schnepperec042542015-04-14 08:03:43 -03003234 cdmaDbm = p_cur->CDMA_SignalStrength.dbm;
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303235#endif
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303236
Christopher N. Hesse621e63e2016-02-22 21:57:39 +01003237#if defined(MODEM_TYPE_XMM6262) || defined(SAMSUNG_NEXT_GEN_MODEM)
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303238 evdoDbm = p_cur->EVDO_SignalStrength.dbm & 0xFF;
3239 if (evdoDbm < 0) {
3240 evdoDbm = 99;
3241 } else if (evdoDbm > 31 && evdoDbm != 99) {
3242 evdoDbm = 31;
3243 }
3244#else
3245 evdoDbm = p_cur->EVDO_SignalStrength.dbm;
3246#endif
Christopher N. Hesse65084862017-02-07 22:21:27 +01003247
3248 p.writeInt32(gsmSignalStrength);
3249 p.writeInt32(p_cur->GW_SignalStrength.bitErrorRate);
3250 p.writeInt32(cdmaDbm);
3251 p.writeInt32(p_cur->CDMA_SignalStrength.ecio);
3252 p.writeInt32(evdoDbm);
3253 p.writeInt32(p_cur->EVDO_SignalStrength.ecio);
3254 p.writeInt32(p_cur->EVDO_SignalStrength.signalNoiseRatio);
Sanket Padawe9343e872016-01-11 12:45:43 -08003255}
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003256
Sanket Padawe9343e872016-01-11 12:45:43 -08003257static void responseRilSignalStrengthV6Extra(Parcel &p, RIL_SignalStrength_v10 *p_cur) {
3258 /*
3259 * Fixup LTE for backwards compatibility
3260 */
3261 // signalStrength: -1 -> 99
3262 if (p_cur->LTE_SignalStrength.signalStrength == -1) {
3263 p_cur->LTE_SignalStrength.signalStrength = 99;
3264 }
3265 // rsrp: -1 -> INT_MAX all other negative value to positive.
3266 // So remap here
3267 if (p_cur->LTE_SignalStrength.rsrp == -1) {
3268 p_cur->LTE_SignalStrength.rsrp = INT_MAX;
3269 } else if (p_cur->LTE_SignalStrength.rsrp < -1) {
3270 p_cur->LTE_SignalStrength.rsrp = -p_cur->LTE_SignalStrength.rsrp;
3271 }
3272 // rsrq: -1 -> INT_MAX
3273 if (p_cur->LTE_SignalStrength.rsrq == -1) {
3274 p_cur->LTE_SignalStrength.rsrq = INT_MAX;
3275 }
3276 // Not remapping rssnr is already using INT_MAX
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003277
Sanket Padawe9343e872016-01-11 12:45:43 -08003278 // cqi: -1 -> INT_MAX
3279 if (p_cur->LTE_SignalStrength.cqi == -1) {
3280 p_cur->LTE_SignalStrength.cqi = INT_MAX;
3281 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003282
Sanket Padawe9343e872016-01-11 12:45:43 -08003283 p.writeInt32(p_cur->LTE_SignalStrength.signalStrength);
3284 p.writeInt32(p_cur->LTE_SignalStrength.rsrp);
3285 p.writeInt32(p_cur->LTE_SignalStrength.rsrq);
3286 p.writeInt32(p_cur->LTE_SignalStrength.rssnr);
3287 p.writeInt32(p_cur->LTE_SignalStrength.cqi);
3288}
3289
3290static void responseRilSignalStrengthV10(Parcel &p, RIL_SignalStrength_v10 *p_cur) {
3291 responseRilSignalStrengthV5(p, p_cur);
3292 responseRilSignalStrengthV6Extra(p, p_cur);
3293 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
3294}
3295
Sanket Padawe9343e872016-01-11 12:45:43 -08003296static int responseRilSignalStrength(Parcel &p,
3297 void *response, size_t responselen) {
3298 if (response == NULL && responselen != 0) {
3299 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003300 return RIL_ERRNO_INVALID_RESPONSE;
3301 }
3302
Sanket Padawe6daeeef2016-06-08 14:09:26 -07003303 RIL_SignalStrength_v10 *p_cur;
Sanket Padawe9343e872016-01-11 12:45:43 -08003304 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
3305 if (responselen >= sizeof (RIL_SignalStrength_v5)) {
Sanket Padawe6daeeef2016-06-08 14:09:26 -07003306 p_cur = ((RIL_SignalStrength_v10 *) response);
Sanket Padawe9343e872016-01-11 12:45:43 -08003307
3308 responseRilSignalStrengthV5(p, p_cur);
3309
3310 if (responselen >= sizeof (RIL_SignalStrength_v6)) {
3311 responseRilSignalStrengthV6Extra(p, p_cur);
3312 if (responselen >= sizeof (RIL_SignalStrength_v10)) {
3313 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
3314 } else {
3315 p.writeInt32(INT_MAX);
3316 }
3317 } else {
3318 p.writeInt32(99);
3319 p.writeInt32(INT_MAX);
3320 p.writeInt32(INT_MAX);
3321 p.writeInt32(INT_MAX);
3322 p.writeInt32(INT_MAX);
3323 p.writeInt32(INT_MAX);
3324 }
3325 } else {
3326 RLOGE("invalid response length");
3327 return RIL_ERRNO_INVALID_RESPONSE;
3328 }
Sanket Padawea79128a2016-01-26 18:44:01 -08003329 } else { // RIL version >= 13
Sanket Padawe9343e872016-01-11 12:45:43 -08003330 if (responselen % sizeof(RIL_SignalStrength_v10) != 0) {
3331 RLOGE("Data structure expected is RIL_SignalStrength_v10");
3332 if (!isDebuggable()) {
3333 return RIL_ERRNO_INVALID_RESPONSE;
3334 } else {
3335 assert(0);
3336 }
3337 }
Sanket Padawe6daeeef2016-06-08 14:09:26 -07003338 p_cur = ((RIL_SignalStrength_v10 *) response);
Sanket Padawe9343e872016-01-11 12:45:43 -08003339 responseRilSignalStrengthV10(p, p_cur);
3340 }
Sanket Padawe9343e872016-01-11 12:45:43 -08003341 startResponse;
3342 appendPrintBuf("%s[signalStrength=%d,bitErrorRate=%d,\
3343 CDMA_SS.dbm=%d,CDMA_SSecio=%d,\
3344 EVDO_SS.dbm=%d,EVDO_SS.ecio=%d,\
3345 EVDO_SS.signalNoiseRatio=%d,\
3346 LTE_SS.signalStrength=%d,LTE_SS.rsrp=%d,LTE_SS.rsrq=%d,\
3347 LTE_SS.rssnr=%d,LTE_SS.cqi=%d,TDSCDMA_SS.rscp=%d]",
3348 printBuf,
3349 gsmSignalStrength,
3350 p_cur->GW_SignalStrength.bitErrorRate,
3351 cdmaDbm,
3352 p_cur->CDMA_SignalStrength.ecio,
3353 evdoDbm,
3354 p_cur->EVDO_SignalStrength.ecio,
3355 p_cur->EVDO_SignalStrength.signalNoiseRatio,
3356 p_cur->LTE_SignalStrength.signalStrength,
3357 p_cur->LTE_SignalStrength.rsrp,
3358 p_cur->LTE_SignalStrength.rsrq,
3359 p_cur->LTE_SignalStrength.rssnr,
3360 p_cur->LTE_SignalStrength.cqi,
3361 p_cur->TD_SCDMA_SignalStrength.rscp);
3362 closeResponse;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003363 return 0;
3364}
3365
3366static int responseCallRing(Parcel &p, void *response, size_t responselen) {
3367 if ((response == NULL) || (responselen == 0)) {
3368 return responseVoid(p, response, responselen);
3369 } else {
3370 return responseCdmaSignalInfoRecord(p, response, responselen);
3371 }
3372}
3373
3374static int responseCdmaSignalInfoRecord(Parcel &p, void *response, size_t responselen) {
3375 if (response == NULL || responselen == 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003376 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003377 return RIL_ERRNO_INVALID_RESPONSE;
3378 }
3379
3380 if (responselen != sizeof (RIL_CDMA_SignalInfoRecord)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003381 RLOGE("invalid response length %d expected sizeof (RIL_CDMA_SignalInfoRecord) of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003382 (int)responselen, (int)sizeof (RIL_CDMA_SignalInfoRecord));
3383 return RIL_ERRNO_INVALID_RESPONSE;
3384 }
3385
3386 startResponse;
3387
3388 RIL_CDMA_SignalInfoRecord *p_cur = ((RIL_CDMA_SignalInfoRecord *) response);
3389 marshallSignalInfoRecord(p, *p_cur);
3390
3391 appendPrintBuf("%s[isPresent=%d,signalType=%d,alertPitch=%d\
3392 signal=%d]",
3393 printBuf,
3394 p_cur->isPresent,
3395 p_cur->signalType,
3396 p_cur->alertPitch,
3397 p_cur->signal);
3398
3399 closeResponse;
3400 return 0;
3401}
3402
3403static int responseCdmaCallWaiting(Parcel &p, void *response,
3404 size_t responselen) {
3405 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003406 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003407 return RIL_ERRNO_INVALID_RESPONSE;
3408 }
3409
3410 if (responselen < sizeof(RIL_CDMA_CallWaiting_v6)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003411 RLOGW("Upgrade to ril version %d\n", RIL_VERSION);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003412 }
3413
3414 RIL_CDMA_CallWaiting_v6 *p_cur = ((RIL_CDMA_CallWaiting_v6 *) response);
3415
3416 writeStringToParcel(p, p_cur->number);
3417 p.writeInt32(p_cur->numberPresentation);
3418 writeStringToParcel(p, p_cur->name);
3419 marshallSignalInfoRecord(p, p_cur->signalInfoRecord);
3420
Sanket Padawe9343e872016-01-11 12:45:43 -08003421 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
3422 if (responselen >= sizeof(RIL_CDMA_CallWaiting_v6)) {
3423 p.writeInt32(p_cur->number_type);
3424 p.writeInt32(p_cur->number_plan);
3425 } else {
3426 p.writeInt32(0);
3427 p.writeInt32(0);
3428 }
Sanket Padawea79128a2016-01-26 18:44:01 -08003429 } else { // RIL version >= 13
Sanket Padawe9343e872016-01-11 12:45:43 -08003430 if (responselen % sizeof(RIL_CDMA_CallWaiting_v6) != 0) {
3431 RLOGE("Data structure expected is RIL_CDMA_CallWaiting_v6");
3432 if (!isDebuggable()) {
3433 return RIL_ERRNO_INVALID_RESPONSE;
3434 } else {
3435 assert(0);
3436 }
3437 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003438 p.writeInt32(p_cur->number_type);
3439 p.writeInt32(p_cur->number_plan);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003440 }
3441
3442 startResponse;
3443 appendPrintBuf("%snumber=%s,numberPresentation=%d, name=%s,\
3444 signalInfoRecord[isPresent=%d,signalType=%d,alertPitch=%d\
3445 signal=%d,number_type=%d,number_plan=%d]",
3446 printBuf,
3447 p_cur->number,
3448 p_cur->numberPresentation,
3449 p_cur->name,
3450 p_cur->signalInfoRecord.isPresent,
3451 p_cur->signalInfoRecord.signalType,
3452 p_cur->signalInfoRecord.alertPitch,
3453 p_cur->signalInfoRecord.signal,
3454 p_cur->number_type,
3455 p_cur->number_plan);
3456 closeResponse;
3457
3458 return 0;
3459}
3460
Sanket Padawe9343e872016-01-11 12:45:43 -08003461static void responseSimRefreshV7(Parcel &p, void *response) {
3462 RIL_SimRefreshResponse_v7 *p_cur = ((RIL_SimRefreshResponse_v7 *) response);
3463 p.writeInt32(p_cur->result);
3464 p.writeInt32(p_cur->ef_id);
3465 writeStringToParcel(p, p_cur->aid);
3466
3467 appendPrintBuf("%sresult=%d, ef_id=%d, aid=%s",
3468 printBuf,
3469 p_cur->result,
3470 p_cur->ef_id,
3471 p_cur->aid);
3472
3473}
3474
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003475static int responseSimRefresh(Parcel &p, void *response, size_t responselen) {
3476 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003477 RLOGE("responseSimRefresh: invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003478 return RIL_ERRNO_INVALID_RESPONSE;
3479 }
3480
3481 startResponse;
Sanket Padawe9343e872016-01-11 12:45:43 -08003482 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
Sanket Padawe201aca32016-01-21 15:49:33 -08003483 if (s_callbacks.version >= 7) {
Sanket Padawe9343e872016-01-11 12:45:43 -08003484 responseSimRefreshV7(p, response);
3485 } else {
3486 int *p_cur = ((int *) response);
3487 p.writeInt32(p_cur[0]);
3488 p.writeInt32(p_cur[1]);
3489 writeStringToParcel(p, NULL);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003490
Sanket Padawe9343e872016-01-11 12:45:43 -08003491 appendPrintBuf("%sresult=%d, ef_id=%d",
3492 printBuf,
3493 p_cur[0],
3494 p_cur[1]);
3495 }
Sanket Padawea79128a2016-01-26 18:44:01 -08003496 } else { // RIL version >= 13
Sanket Padawe9343e872016-01-11 12:45:43 -08003497 if (responselen % sizeof(RIL_SimRefreshResponse_v7) != 0) {
3498 RLOGE("Data structure expected is RIL_SimRefreshResponse_v7");
3499 if (!isDebuggable()) {
3500 return RIL_ERRNO_INVALID_RESPONSE;
3501 } else {
3502 assert(0);
3503 }
3504 }
3505 responseSimRefreshV7(p, response);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003506
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003507 }
3508 closeResponse;
3509
3510 return 0;
3511}
3512
Sanket Padawea79128a2016-01-26 18:44:01 -08003513static int responseCellInfoListV6(Parcel &p, void *response, size_t responselen) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003514 if (response == NULL && responselen != 0) {
3515 RLOGE("invalid response: NULL");
3516 return RIL_ERRNO_INVALID_RESPONSE;
3517 }
3518
3519 if (responselen % sizeof(RIL_CellInfo) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08003520 RLOGE("responseCellInfoList: invalid response length %d expected multiple of %d",
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003521 (int)responselen, (int)sizeof(RIL_CellInfo));
3522 return RIL_ERRNO_INVALID_RESPONSE;
3523 }
3524
3525 int num = responselen / sizeof(RIL_CellInfo);
3526 p.writeInt32(num);
3527
3528 RIL_CellInfo *p_cur = (RIL_CellInfo *) response;
3529 startResponse;
3530 int i;
3531 for (i = 0; i < num; i++) {
3532 appendPrintBuf("%s[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", printBuf, i,
3533 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
3534 p.writeInt32((int)p_cur->cellInfoType);
3535 p.writeInt32(p_cur->registered);
3536 p.writeInt32(p_cur->timeStampType);
3537 p.writeInt64(p_cur->timeStamp);
3538 switch(p_cur->cellInfoType) {
3539 case RIL_CELL_INFO_TYPE_GSM: {
3540 appendPrintBuf("%s GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,", printBuf,
3541 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
3542 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
3543 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
3544 p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3545 appendPrintBuf("%s gsmSS: ss=%d,ber=%d],", printBuf,
3546 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
3547 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3548
3549 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
3550 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
3551 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
3552 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
Christopher N. Hesse65084862017-02-07 22:21:27 +01003553 p.writeInt32(INT_MAX); /* skip arfcn */
3554 p.writeInt32(INT_MAX); /* skip bsic */
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003555 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
3556 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3557 break;
3558 }
3559 case RIL_CELL_INFO_TYPE_WCDMA: {
3560 appendPrintBuf("%s WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,", printBuf,
3561 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
3562 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
3563 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
3564 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
3565 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3566 appendPrintBuf("%s wcdmaSS: ss=%d,ber=%d],", printBuf,
3567 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
3568 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3569
3570 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
3571 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
3572 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
3573 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
3574 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
Christopher N. Hesse65084862017-02-07 22:21:27 +01003575 p.writeInt32(INT_MAX); /* skip uarfcn */
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003576 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
3577 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3578 break;
3579 }
3580 case RIL_CELL_INFO_TYPE_CDMA: {
3581 appendPrintBuf("%s CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d", printBuf,
3582 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
3583 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
3584 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
3585 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
3586 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3587
3588 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
3589 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
3590 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
3591 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
3592 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3593
3594 appendPrintBuf("%s cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d", printBuf,
3595 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
3596 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
3597 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
3598 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
3599 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3600
3601 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
3602 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
3603 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
3604 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
3605 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3606 break;
3607 }
3608 case RIL_CELL_INFO_TYPE_LTE: {
3609 appendPrintBuf("%s LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d", printBuf,
3610 p_cur->CellInfo.lte.cellIdentityLte.mcc,
3611 p_cur->CellInfo.lte.cellIdentityLte.mnc,
3612 p_cur->CellInfo.lte.cellIdentityLte.ci,
3613 p_cur->CellInfo.lte.cellIdentityLte.pci,
3614 p_cur->CellInfo.lte.cellIdentityLte.tac);
3615
3616 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
3617 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
3618 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
3619 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
3620 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
Christopher N. Hesse65084862017-02-07 22:21:27 +01003621 p.writeInt32(INT_MAX); /* skip earfcn */
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003622
3623 appendPrintBuf("%s lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d", printBuf,
3624 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
3625 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
3626 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
3627 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
3628 p_cur->CellInfo.lte.signalStrengthLte.cqi,
3629 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3630 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
3631 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
3632 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
3633 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
3634 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
3635 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3636 break;
3637 }
Howard Sue32dbfd2015-01-07 15:55:57 +08003638 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
3639 appendPrintBuf("%s TDSCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,cpid=%d,", printBuf,
3640 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc,
3641 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc,
3642 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac,
3643 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid,
3644 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3645 appendPrintBuf("%s tdscdmaSS: rscp=%d],", printBuf,
3646 p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3647
3648 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
3649 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
3650 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
3651 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
3652 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3653 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3654 break;
3655 }
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003656 }
3657 p_cur += 1;
3658 }
3659 removeLastChar;
3660 closeResponse;
3661
3662 return 0;
3663}
3664
Sanket Padawea79128a2016-01-26 18:44:01 -08003665static int responseCellInfoListV12(Parcel &p, void *response, size_t responselen) {
3666 if (response == NULL && responselen != 0) {
3667 RLOGE("invalid response: NULL");
3668 return RIL_ERRNO_INVALID_RESPONSE;
3669 }
3670
3671 if (responselen % sizeof(RIL_CellInfo_v12) != 0) {
3672 RLOGE("responseCellInfoList: invalid response length %d expected multiple of %d",
3673 (int)responselen, (int)sizeof(RIL_CellInfo_v12));
3674 return RIL_ERRNO_INVALID_RESPONSE;
3675 }
3676
3677 int num = responselen / sizeof(RIL_CellInfo_v12);
3678 p.writeInt32(num);
3679
3680 RIL_CellInfo_v12 *p_cur = (RIL_CellInfo_v12 *) response;
3681 startResponse;
3682 int i;
3683 for (i = 0; i < num; i++) {
3684 appendPrintBuf("%s[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", printBuf, i,
3685 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
3686 RLOGE("[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", i,
3687 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
3688 p.writeInt32((int)p_cur->cellInfoType);
3689 p.writeInt32(p_cur->registered);
3690 p.writeInt32(p_cur->timeStampType);
3691 p.writeInt64(p_cur->timeStamp);
3692 switch(p_cur->cellInfoType) {
3693 case RIL_CELL_INFO_TYPE_GSM: {
3694 appendPrintBuf("%s GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,arfcn=%d,bsic=%x", printBuf,
3695 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
3696 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
3697 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
3698 p_cur->CellInfo.gsm.cellIdentityGsm.cid,
3699 p_cur->CellInfo.gsm.cellIdentityGsm.arfcn,
3700 p_cur->CellInfo.gsm.cellIdentityGsm.bsic);
3701 RLOGE("GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,arfcn=%d,bsic=%x",
3702 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
3703 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
3704 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
3705 p_cur->CellInfo.gsm.cellIdentityGsm.cid,
3706 p_cur->CellInfo.gsm.cellIdentityGsm.arfcn,
3707 p_cur->CellInfo.gsm.cellIdentityGsm.bsic);
3708 RLOGE("gsmSS: ss=%d,ber=%d, ta=%d],",
3709 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
3710 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate,
3711 p_cur->CellInfo.gsm.signalStrengthGsm.timingAdvance);
3712 appendPrintBuf("%s gsmSS: ss=%d,ber=%d, ta=%d],", printBuf,
3713 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
3714 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate,
3715 p_cur->CellInfo.gsm.signalStrengthGsm.timingAdvance);
3716
3717 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
3718 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
3719 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
3720 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3721 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.arfcn);
3722 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.bsic);
3723 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
3724 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3725 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.timingAdvance);
3726 break;
3727 }
3728 case RIL_CELL_INFO_TYPE_WCDMA: {
3729 RLOGE("WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,uarfcn=%d",
3730 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
3731 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
3732 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
3733 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
3734 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc,
3735 p_cur->CellInfo.wcdma.cellIdentityWcdma.uarfcn);
3736 RLOGE("wcdmaSS: ss=%d,ber=%d],",
3737 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
3738 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3739 appendPrintBuf("%s WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,uarfcn=%d", printBuf,
3740 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
3741 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
3742 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
3743 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
3744 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc,
3745 p_cur->CellInfo.wcdma.cellIdentityWcdma.uarfcn);
3746 appendPrintBuf("%s wcdmaSS: ss=%d,ber=%d],", printBuf,
3747 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
3748 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3749
3750 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
3751 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
3752 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
3753 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
3754 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3755 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.uarfcn);
3756 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
3757 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3758 break;
3759 }
3760 case RIL_CELL_INFO_TYPE_CDMA: {
3761 RLOGE("CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d",
3762 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
3763 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
3764 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
3765 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
3766 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3767
3768 appendPrintBuf("%s CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d", printBuf,
3769 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
3770 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
3771 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
3772 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
3773 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3774
3775 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
3776 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
3777 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
3778 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
3779 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3780
3781 RLOGE("cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d",
3782 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
3783 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
3784 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
3785 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
3786 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3787
3788 appendPrintBuf("%s cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d", printBuf,
3789 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
3790 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
3791 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
3792 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
3793 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3794
3795 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
3796 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
3797 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
3798 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
3799 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3800 break;
3801 }
3802 case RIL_CELL_INFO_TYPE_LTE: {
3803 RLOGE("LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d,earfcn=%d",
3804 p_cur->CellInfo.lte.cellIdentityLte.mcc,
3805 p_cur->CellInfo.lte.cellIdentityLte.mnc,
3806 p_cur->CellInfo.lte.cellIdentityLte.ci,
3807 p_cur->CellInfo.lte.cellIdentityLte.pci,
3808 p_cur->CellInfo.lte.cellIdentityLte.tac,
3809 p_cur->CellInfo.lte.cellIdentityLte.earfcn);
3810
3811 appendPrintBuf("%s LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d,earfcn=%d", printBuf,
3812 p_cur->CellInfo.lte.cellIdentityLte.mcc,
3813 p_cur->CellInfo.lte.cellIdentityLte.mnc,
3814 p_cur->CellInfo.lte.cellIdentityLte.ci,
3815 p_cur->CellInfo.lte.cellIdentityLte.pci,
3816 p_cur->CellInfo.lte.cellIdentityLte.tac,
3817 p_cur->CellInfo.lte.cellIdentityLte.earfcn);
3818
3819 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
3820 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
3821 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
3822 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
3823 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
3824 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.earfcn);
3825
3826 RLOGE("lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d",
3827 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
3828 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
3829 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
3830 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
3831 p_cur->CellInfo.lte.signalStrengthLte.cqi,
3832 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3833 appendPrintBuf("%s lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d", printBuf,
3834 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
3835 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
3836 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
3837 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
3838 p_cur->CellInfo.lte.signalStrengthLte.cqi,
3839 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3840 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
3841 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
3842 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
3843 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
3844 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
3845 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3846 break;
3847 }
3848 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
3849 appendPrintBuf("%s TDSCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,cpid=%d,", printBuf,
3850 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc,
3851 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc,
3852 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac,
3853 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid,
3854 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3855 appendPrintBuf("%s tdscdmaSS: rscp=%d],", printBuf,
3856 p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3857
3858 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
3859 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
3860 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
3861 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
3862 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3863 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3864 break;
3865 }
3866 }
3867 p_cur += 1;
3868 }
3869 removeLastChar;
3870 closeResponse;
3871 return 0;
3872}
3873
3874static int responseCellInfoList(Parcel &p, void *response, size_t responselen)
3875{
3876 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
3877 if (s_callbacks.version < 12) {
3878 RLOGD("responseCellInfoList: v6");
3879 return responseCellInfoListV6(p, response, responselen);
3880 } else {
3881 RLOGD("responseCellInfoList: v12");
3882 return responseCellInfoListV12(p, response, responselen);
3883 }
3884 } else { // RIL version >= 13
3885 if (responselen % sizeof(RIL_CellInfo_v12) != 0) {
3886 RLOGE("Data structure expected is RIL_CellInfo_v12");
3887 if (!isDebuggable()) {
3888 return RIL_ERRNO_INVALID_RESPONSE;
3889 } else {
3890 assert(0);
3891 }
3892 }
3893 return responseCellInfoListV12(p, response, responselen);
3894 }
3895
3896 return 0;
3897}
3898
Howard Sue32dbfd2015-01-07 15:55:57 +08003899static int responseHardwareConfig(Parcel &p, void *response, size_t responselen)
3900{
3901 if (response == NULL && responselen != 0) {
3902 RLOGE("invalid response: NULL");
3903 return RIL_ERRNO_INVALID_RESPONSE;
3904 }
3905
3906 if (responselen % sizeof(RIL_HardwareConfig) != 0) {
3907 RLOGE("responseHardwareConfig: invalid response length %d expected multiple of %d",
3908 (int)responselen, (int)sizeof(RIL_HardwareConfig));
3909 return RIL_ERRNO_INVALID_RESPONSE;
3910 }
3911
3912 int num = responselen / sizeof(RIL_HardwareConfig);
3913 int i;
3914 RIL_HardwareConfig *p_cur = (RIL_HardwareConfig *) response;
3915
3916 p.writeInt32(num);
3917
3918 startResponse;
3919 for (i = 0; i < num; i++) {
3920 switch (p_cur[i].type) {
3921 case RIL_HARDWARE_CONFIG_MODEM: {
3922 writeStringToParcel(p, p_cur[i].uuid);
3923 p.writeInt32((int)p_cur[i].state);
3924 p.writeInt32(p_cur[i].cfg.modem.rat);
3925 p.writeInt32(p_cur[i].cfg.modem.maxVoice);
3926 p.writeInt32(p_cur[i].cfg.modem.maxData);
3927 p.writeInt32(p_cur[i].cfg.modem.maxStandby);
3928
3929 appendPrintBuf("%s modem: uuid=%s,state=%d,rat=%08x,maxV=%d,maxD=%d,maxS=%d", printBuf,
3930 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.modem.rat,
3931 p_cur[i].cfg.modem.maxVoice, p_cur[i].cfg.modem.maxData, p_cur[i].cfg.modem.maxStandby);
3932 break;
3933 }
3934 case RIL_HARDWARE_CONFIG_SIM: {
3935 writeStringToParcel(p, p_cur[i].uuid);
3936 p.writeInt32((int)p_cur[i].state);
3937 writeStringToParcel(p, p_cur[i].cfg.sim.modemUuid);
3938
3939 appendPrintBuf("%s sim: uuid=%s,state=%d,modem-uuid=%s", printBuf,
3940 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.sim.modemUuid);
3941 break;
3942 }
3943 }
3944 }
3945 removeLastChar;
3946 closeResponse;
3947 return 0;
3948}
3949
Howard Subd82ef12015-04-12 10:25:05 +02003950static int responseRadioCapability(Parcel &p, void *response, size_t responselen) {
3951 if (response == NULL) {
3952 RLOGE("invalid response: NULL");
3953 return RIL_ERRNO_INVALID_RESPONSE;
3954 }
3955
3956 if (responselen != sizeof (RIL_RadioCapability) ) {
3957 RLOGE("invalid response length was %d expected %d",
3958 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3959 return RIL_ERRNO_INVALID_RESPONSE;
3960 }
3961
3962 RIL_RadioCapability *p_cur = (RIL_RadioCapability *) response;
3963 p.writeInt32(p_cur->version);
3964 p.writeInt32(p_cur->session);
3965 p.writeInt32(p_cur->phase);
3966 p.writeInt32(p_cur->rat);
3967 writeStringToParcel(p, p_cur->logicalModemUuid);
3968 p.writeInt32(p_cur->status);
3969
3970 startResponse;
3971 appendPrintBuf("%s[version=%d,session=%d,phase=%d,\
Christopher N. Hesse65084862017-02-07 22:21:27 +01003972 rat=%s,logicalModemUuid=%s,status=%d]",
Howard Subd82ef12015-04-12 10:25:05 +02003973 printBuf,
3974 p_cur->version,
3975 p_cur->session,
3976 p_cur->phase,
3977 p_cur->rat,
3978 p_cur->logicalModemUuid,
3979 p_cur->status);
3980 closeResponse;
3981 return 0;
3982}
3983
3984static int responseSSData(Parcel &p, void *response, size_t responselen) {
3985 RLOGD("In responseSSData");
3986 int num;
3987
3988 if (response == NULL && responselen != 0) {
3989 RLOGE("invalid response length was %d expected %d",
3990 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3991 return RIL_ERRNO_INVALID_RESPONSE;
3992 }
3993
3994 if (responselen != sizeof(RIL_StkCcUnsolSsResponse)) {
3995 RLOGE("invalid response length %d, expected %d",
3996 (int)responselen, (int)sizeof(RIL_StkCcUnsolSsResponse));
3997 return RIL_ERRNO_INVALID_RESPONSE;
3998 }
3999
4000 startResponse;
4001 RIL_StkCcUnsolSsResponse *p_cur = (RIL_StkCcUnsolSsResponse *) response;
4002 p.writeInt32(p_cur->serviceType);
4003 p.writeInt32(p_cur->requestType);
4004 p.writeInt32(p_cur->teleserviceType);
4005 p.writeInt32(p_cur->serviceClass);
4006 p.writeInt32(p_cur->result);
4007
4008 if (isServiceTypeCfQuery(p_cur->serviceType, p_cur->requestType)) {
4009 RLOGD("responseSSData CF type, num of Cf elements %d", p_cur->cfData.numValidIndexes);
4010 if (p_cur->cfData.numValidIndexes > NUM_SERVICE_CLASSES) {
4011 RLOGE("numValidIndexes is greater than max value %d, "
4012 "truncating it to max value", NUM_SERVICE_CLASSES);
4013 p_cur->cfData.numValidIndexes = NUM_SERVICE_CLASSES;
4014 }
4015 /* number of call info's */
4016 p.writeInt32(p_cur->cfData.numValidIndexes);
4017
4018 for (int i = 0; i < p_cur->cfData.numValidIndexes; i++) {
4019 RIL_CallForwardInfo cf = p_cur->cfData.cfInfo[i];
4020
4021 p.writeInt32(cf.status);
4022 p.writeInt32(cf.reason);
4023 p.writeInt32(cf.serviceClass);
4024 p.writeInt32(cf.toa);
4025 writeStringToParcel(p, cf.number);
4026 p.writeInt32(cf.timeSeconds);
4027 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
4028 (cf.status==1)?"enable":"disable", cf.reason, cf.serviceClass, cf.toa,
4029 (char*)cf.number, cf.timeSeconds);
4030 RLOGD("Data: %d,reason=%d,cls=%d,toa=%d,num=%s,tout=%d],", cf.status,
4031 cf.reason, cf.serviceClass, cf.toa, (char*)cf.number, cf.timeSeconds);
4032 }
4033 } else {
4034 p.writeInt32 (SS_INFO_MAX);
4035
4036 /* each int*/
4037 for (int i = 0; i < SS_INFO_MAX; i++) {
4038 appendPrintBuf("%s%d,", printBuf, p_cur->ssInfo[i]);
4039 RLOGD("Data: %d",p_cur->ssInfo[i]);
4040 p.writeInt32(p_cur->ssInfo[i]);
4041 }
4042 }
4043 removeLastChar;
4044 closeResponse;
4045
4046 return 0;
4047}
4048
4049static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType) {
4050 if ((reqType == SS_INTERROGATION) &&
4051 (serType == SS_CFU ||
4052 serType == SS_CF_BUSY ||
4053 serType == SS_CF_NO_REPLY ||
4054 serType == SS_CF_NOT_REACHABLE ||
4055 serType == SS_CF_ALL ||
4056 serType == SS_CF_ALL_CONDITIONAL)) {
4057 return true;
4058 }
4059 return false;
4060}
4061
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004062static void triggerEvLoop() {
4063 int ret;
4064 if (!pthread_equal(pthread_self(), s_tid_dispatch)) {
4065 /* trigger event loop to wakeup. No reason to do this,
4066 * if we're in the event loop thread */
4067 do {
4068 ret = write (s_fdWakeupWrite, " ", 1);
4069 } while (ret < 0 && errno == EINTR);
4070 }
4071}
4072
4073static void rilEventAddWakeup(struct ril_event *ev) {
4074 ril_event_add(ev);
4075 triggerEvLoop();
4076}
4077
4078static void sendSimStatusAppInfo(Parcel &p, int num_apps, RIL_AppStatus appStatus[]) {
4079 p.writeInt32(num_apps);
4080 startResponse;
4081 for (int i = 0; i < num_apps; i++) {
4082 p.writeInt32(appStatus[i].app_type);
4083 p.writeInt32(appStatus[i].app_state);
4084 p.writeInt32(appStatus[i].perso_substate);
4085 writeStringToParcel(p, (const char*)(appStatus[i].aid_ptr));
4086 writeStringToParcel(p, (const char*)
4087 (appStatus[i].app_label_ptr));
4088 p.writeInt32(appStatus[i].pin1_replaced);
4089 p.writeInt32(appStatus[i].pin1);
4090 p.writeInt32(appStatus[i].pin2);
4091 appendPrintBuf("%s[app_type=%d,app_state=%d,perso_substate=%d,\
4092 aid_ptr=%s,app_label_ptr=%s,pin1_replaced=%d,pin1=%d,pin2=%d],",
4093 printBuf,
4094 appStatus[i].app_type,
4095 appStatus[i].app_state,
4096 appStatus[i].perso_substate,
4097 appStatus[i].aid_ptr,
4098 appStatus[i].app_label_ptr,
4099 appStatus[i].pin1_replaced,
4100 appStatus[i].pin1,
4101 appStatus[i].pin2);
4102 }
4103 closeResponse;
4104}
4105
Sanket Padawe9343e872016-01-11 12:45:43 -08004106static void responseSimStatusV5(Parcel &p, void *response) {
4107 RIL_CardStatus_v5 *p_cur = ((RIL_CardStatus_v5 *) response);
4108
4109 p.writeInt32(p_cur->card_state);
4110 p.writeInt32(p_cur->universal_pin_state);
4111 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
4112 p.writeInt32(p_cur->cdma_subscription_app_index);
Kyle Repinski5a2cc4e2016-08-31 01:04:02 -05004113 p.writeInt32(-1);
Sanket Padawe9343e872016-01-11 12:45:43 -08004114
4115 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
4116}
4117
4118static void responseSimStatusV6(Parcel &p, void *response) {
4119 RIL_CardStatus_v6 *p_cur = ((RIL_CardStatus_v6 *) response);
4120
4121 p.writeInt32(p_cur->card_state);
4122 p.writeInt32(p_cur->universal_pin_state);
4123 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
4124 p.writeInt32(p_cur->cdma_subscription_app_index);
4125 p.writeInt32(p_cur->ims_subscription_app_index);
4126
4127 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
4128}
4129
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004130static int responseSimStatus(Parcel &p, void *response, size_t responselen) {
Howard Sue32dbfd2015-01-07 15:55:57 +08004131 int i;
4132
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004133 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004134 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004135 return RIL_ERRNO_INVALID_RESPONSE;
4136 }
4137
Sanket Padawe9343e872016-01-11 12:45:43 -08004138 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
4139 if (responselen == sizeof (RIL_CardStatus_v6)) {
4140 responseSimStatusV6(p, response);
4141 } else if (responselen == sizeof (RIL_CardStatus_v5)) {
4142 responseSimStatusV5(p, response);
4143 } else {
4144 RLOGE("responseSimStatus: A RilCardStatus_v6 or _v5 expected\n");
4145 return RIL_ERRNO_INVALID_RESPONSE;
4146 }
Sanket Padawea79128a2016-01-26 18:44:01 -08004147 } else { // RIL version >= 13
Sanket Padawe9343e872016-01-11 12:45:43 -08004148 if (responselen % sizeof(RIL_CardStatus_v6) != 0) {
4149 RLOGE("Data structure expected is RIL_CardStatus_v6");
4150 if (!isDebuggable()) {
4151 return RIL_ERRNO_INVALID_RESPONSE;
4152 } else {
4153 assert(0);
4154 }
4155 }
4156 responseSimStatusV6(p, response);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004157 }
4158
4159 return 0;
4160}
4161
4162static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen) {
4163 int num = responselen / sizeof(RIL_GSM_BroadcastSmsConfigInfo *);
4164 p.writeInt32(num);
4165
4166 startResponse;
4167 RIL_GSM_BroadcastSmsConfigInfo **p_cur =
4168 (RIL_GSM_BroadcastSmsConfigInfo **) response;
4169 for (int i = 0; i < num; i++) {
4170 p.writeInt32(p_cur[i]->fromServiceId);
4171 p.writeInt32(p_cur[i]->toServiceId);
4172 p.writeInt32(p_cur[i]->fromCodeScheme);
4173 p.writeInt32(p_cur[i]->toCodeScheme);
4174 p.writeInt32(p_cur[i]->selected);
4175
4176 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId=%d, \
4177 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]",
4178 printBuf, i, p_cur[i]->fromServiceId, p_cur[i]->toServiceId,
4179 p_cur[i]->fromCodeScheme, p_cur[i]->toCodeScheme,
4180 p_cur[i]->selected);
4181 }
4182 closeResponse;
4183
4184 return 0;
4185}
4186
4187static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen) {
4188 RIL_CDMA_BroadcastSmsConfigInfo **p_cur =
4189 (RIL_CDMA_BroadcastSmsConfigInfo **) response;
4190
4191 int num = responselen / sizeof (RIL_CDMA_BroadcastSmsConfigInfo *);
4192 p.writeInt32(num);
4193
4194 startResponse;
4195 for (int i = 0 ; i < num ; i++ ) {
4196 p.writeInt32(p_cur[i]->service_category);
4197 p.writeInt32(p_cur[i]->language);
4198 p.writeInt32(p_cur[i]->selected);
4199
4200 appendPrintBuf("%s [%d: srvice_category=%d, language =%d, \
4201 selected =%d], ",
4202 printBuf, i, p_cur[i]->service_category, p_cur[i]->language,
4203 p_cur[i]->selected);
4204 }
4205 closeResponse;
4206
4207 return 0;
4208}
4209
4210static int responseCdmaSms(Parcel &p, void *response, size_t responselen) {
4211 int num;
4212 int digitCount;
4213 int digitLimit;
4214 uint8_t uct;
4215 void* dest;
4216
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004217 RLOGD("Inside responseCdmaSms");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004218
4219 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004220 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004221 return RIL_ERRNO_INVALID_RESPONSE;
4222 }
4223
4224 if (responselen != sizeof(RIL_CDMA_SMS_Message)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004225 RLOGE("invalid response length was %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004226 (int)responselen, (int)sizeof(RIL_CDMA_SMS_Message));
4227 return RIL_ERRNO_INVALID_RESPONSE;
4228 }
4229
4230 RIL_CDMA_SMS_Message *p_cur = (RIL_CDMA_SMS_Message *) response;
4231 p.writeInt32(p_cur->uTeleserviceID);
4232 p.write(&(p_cur->bIsServicePresent),sizeof(uct));
4233 p.writeInt32(p_cur->uServicecategory);
4234 p.writeInt32(p_cur->sAddress.digit_mode);
4235 p.writeInt32(p_cur->sAddress.number_mode);
4236 p.writeInt32(p_cur->sAddress.number_type);
4237 p.writeInt32(p_cur->sAddress.number_plan);
4238 p.write(&(p_cur->sAddress.number_of_digits), sizeof(uct));
4239 digitLimit= MIN((p_cur->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
4240 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
4241 p.write(&(p_cur->sAddress.digits[digitCount]),sizeof(uct));
4242 }
4243
4244 p.writeInt32(p_cur->sSubAddress.subaddressType);
4245 p.write(&(p_cur->sSubAddress.odd),sizeof(uct));
4246 p.write(&(p_cur->sSubAddress.number_of_digits),sizeof(uct));
4247 digitLimit= MIN((p_cur->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
4248 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
4249 p.write(&(p_cur->sSubAddress.digits[digitCount]),sizeof(uct));
4250 }
4251
4252 digitLimit= MIN((p_cur->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
4253 p.writeInt32(p_cur->uBearerDataLen);
4254 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
4255 p.write(&(p_cur->aBearerData[digitCount]), sizeof(uct));
4256 }
4257
4258 startResponse;
4259 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
4260 sAddress.digit_mode=%d, sAddress.number_mode=%d, sAddress.number_type=%d, ",
4261 printBuf, p_cur->uTeleserviceID,p_cur->bIsServicePresent,p_cur->uServicecategory,
4262 p_cur->sAddress.digit_mode, p_cur->sAddress.number_mode,p_cur->sAddress.number_type);
4263 closeResponse;
4264
4265 return 0;
4266}
4267
Howard Sue32dbfd2015-01-07 15:55:57 +08004268static int responseDcRtInfo(Parcel &p, void *response, size_t responselen)
4269{
4270 int num = responselen / sizeof(RIL_DcRtInfo);
4271 if ((responselen % sizeof(RIL_DcRtInfo) != 0) || (num != 1)) {
4272 RLOGE("responseDcRtInfo: invalid response length %d expected multiple of %d",
4273 (int)responselen, (int)sizeof(RIL_DcRtInfo));
4274 return RIL_ERRNO_INVALID_RESPONSE;
4275 }
4276
4277 startResponse;
4278 RIL_DcRtInfo *pDcRtInfo = (RIL_DcRtInfo *)response;
4279 p.writeInt64(pDcRtInfo->time);
4280 p.writeInt32(pDcRtInfo->powerState);
4281 appendPrintBuf("%s[time=%d,powerState=%d]", printBuf,
4282 pDcRtInfo->time,
Christopher N. Hesse65084862017-02-07 22:21:27 +01004283 pDcRtInfo->powerState);
Howard Sue32dbfd2015-01-07 15:55:57 +08004284 closeResponse;
4285
4286 return 0;
4287}
4288
fenglu9bdede02015-04-14 14:53:55 -07004289static int responseLceStatus(Parcel &p, void *response, size_t responselen) {
4290 if (response == NULL || responselen != sizeof(RIL_LceStatusInfo)) {
4291 if (response == NULL) {
4292 RLOGE("invalid response: NULL");
4293 }
4294 else {
Christopher N. Hesse65084862017-02-07 22:21:27 +01004295 RLOGE("responseLceStatus: invalid response length %u expecting len: %u",
4296 (unsigned)sizeof(RIL_LceStatusInfo), (unsigned)responselen);
fenglu9bdede02015-04-14 14:53:55 -07004297 }
4298 return RIL_ERRNO_INVALID_RESPONSE;
4299 }
4300
4301 RIL_LceStatusInfo *p_cur = (RIL_LceStatusInfo *)response;
4302 p.write((void *)p_cur, 1); // p_cur->lce_status takes one byte.
4303 p.writeInt32(p_cur->actual_interval_ms);
4304
4305 startResponse;
4306 appendPrintBuf("LCE Status: %d, actual_interval_ms: %d",
4307 p_cur->lce_status, p_cur->actual_interval_ms);
4308 closeResponse;
4309
4310 return 0;
4311}
4312
4313static int responseLceData(Parcel &p, void *response, size_t responselen) {
4314 if (response == NULL || responselen != sizeof(RIL_LceDataInfo)) {
4315 if (response == NULL) {
4316 RLOGE("invalid response: NULL");
4317 }
4318 else {
Christopher N. Hesse65084862017-02-07 22:21:27 +01004319 RLOGE("responseLceData: invalid response length %u expecting len: %u",
4320 (unsigned)sizeof(RIL_LceDataInfo), (unsigned)responselen);
fenglu9bdede02015-04-14 14:53:55 -07004321 }
4322 return RIL_ERRNO_INVALID_RESPONSE;
4323 }
4324
4325 RIL_LceDataInfo *p_cur = (RIL_LceDataInfo *)response;
4326 p.writeInt32(p_cur->last_hop_capacity_kbps);
4327
4328 /* p_cur->confidence_level and p_cur->lce_suspended take 1 byte each.*/
4329 p.write((void *)&(p_cur->confidence_level), 1);
4330 p.write((void *)&(p_cur->lce_suspended), 1);
4331
4332 startResponse;
Hyejine942c332015-09-14 16:27:28 -07004333 appendPrintBuf("LCE info received: capacity %d confidence level %d \
4334 and suspended %d",
fenglu9bdede02015-04-14 14:53:55 -07004335 p_cur->last_hop_capacity_kbps, p_cur->confidence_level,
4336 p_cur->lce_suspended);
4337 closeResponse;
4338
4339 return 0;
4340}
4341
Prerepa Viswanadham8e755592015-05-28 00:37:32 -07004342static int responseActivityData(Parcel &p, void *response, size_t responselen) {
4343 if (response == NULL || responselen != sizeof(RIL_ActivityStatsInfo)) {
4344 if (response == NULL) {
4345 RLOGE("invalid response: NULL");
4346 }
4347 else {
Christopher N. Hesse65084862017-02-07 22:21:27 +01004348 RLOGE("responseActivityData: invalid response length %u expecting len: %u",
4349 (unsigned)sizeof(RIL_ActivityStatsInfo), (unsigned)responselen);
Prerepa Viswanadham8e755592015-05-28 00:37:32 -07004350 }
4351 return RIL_ERRNO_INVALID_RESPONSE;
4352 }
4353
4354 RIL_ActivityStatsInfo *p_cur = (RIL_ActivityStatsInfo *)response;
4355 p.writeInt32(p_cur->sleep_mode_time_ms);
4356 p.writeInt32(p_cur->idle_mode_time_ms);
4357 for(int i = 0; i < RIL_NUM_TX_POWER_LEVELS; i++) {
4358 p.writeInt32(p_cur->tx_mode_time_ms[i]);
4359 }
4360 p.writeInt32(p_cur->rx_mode_time_ms);
4361
4362 startResponse;
Hyejine942c332015-09-14 16:27:28 -07004363 appendPrintBuf("Modem activity info received: sleep_mode_time_ms %d idle_mode_time_ms %d \
4364 tx_mode_time_ms %d %d %d %d %d and rx_mode_time_ms %d",
Prerepa Viswanadham8e755592015-05-28 00:37:32 -07004365 p_cur->sleep_mode_time_ms, p_cur->idle_mode_time_ms, p_cur->tx_mode_time_ms[0],
4366 p_cur->tx_mode_time_ms[1], p_cur->tx_mode_time_ms[2], p_cur->tx_mode_time_ms[3],
4367 p_cur->tx_mode_time_ms[4], p_cur->rx_mode_time_ms);
4368 closeResponse;
4369
4370 return 0;
4371}
4372
Christopher N. Hesse65084862017-02-07 22:21:27 +01004373static int responseCarrierRestrictions(Parcel &p, void *response, size_t responselen) {
4374 if (response == NULL) {
4375 RLOGE("invalid response: NULL");
4376 return RIL_ERRNO_INVALID_RESPONSE;
4377 }
4378 if (responselen != sizeof(RIL_CarrierRestrictions)) {
4379 RLOGE("responseCarrierRestrictions: invalid response length %u expecting len: %u",
4380 (unsigned)responselen, (unsigned)sizeof(RIL_CarrierRestrictions));
4381 return RIL_ERRNO_INVALID_RESPONSE;
4382 }
4383
4384 RIL_CarrierRestrictions *p_cr = (RIL_CarrierRestrictions *)response;
4385 startResponse;
4386
4387 p.writeInt32(p_cr->len_allowed_carriers);
4388 p.writeInt32(p_cr->len_excluded_carriers);
4389 appendPrintBuf(" %s len_allowed_carriers: %d, len_excluded_carriers: %d,", printBuf,
4390 p_cr->len_allowed_carriers,p_cr->len_excluded_carriers);
4391
4392 appendPrintBuf(" %s allowed_carriers:", printBuf);
4393 for(int32_t i = 0; i < p_cr->len_allowed_carriers; i++) {
4394 RIL_Carrier *carrier = p_cr->allowed_carriers + i;
4395 writeStringToParcel(p, carrier->mcc);
4396 writeStringToParcel(p, carrier->mnc);
4397 p.writeInt32(carrier->match_type);
4398 writeStringToParcel(p, carrier->match_data);
4399 appendPrintBuf(" %s [%d mcc: %s, mnc: %s, match_type: %d, match_data: %s],", printBuf,
4400 i, carrier->mcc, carrier->mnc, carrier->match_type, carrier->match_data);
4401 }
4402
4403 appendPrintBuf(" %s excluded_carriers:", printBuf);
4404 for(int32_t i = 0; i < p_cr->len_excluded_carriers; i++) {
4405 RIL_Carrier *carrier = p_cr->excluded_carriers + i;
4406 writeStringToParcel(p, carrier->mcc);
4407 writeStringToParcel(p, carrier->mnc);
4408 p.writeInt32(carrier->match_type);
4409 writeStringToParcel(p, carrier->match_data);
4410 appendPrintBuf(" %s [%d mcc: %s, mnc: %s, match_type: %d, match_data: %s],", printBuf,
4411 i, carrier->mcc, carrier->mnc, carrier->match_type, carrier->match_data);
4412 }
4413
4414 closeResponse;
4415
4416 return 0;
4417}
4418
4419static int responsePcoData(Parcel &p, void *response, size_t responselen) {
4420 if (response == NULL) {
4421 RLOGE("responsePcoData: invalid NULL response");
4422 return RIL_ERRNO_INVALID_RESPONSE;
4423 }
4424 if (responselen != sizeof(RIL_PCO_Data)) {
4425 RLOGE("responsePcoData: invalid response length %u, expecting %u",
4426 (unsigned)responselen, (unsigned)sizeof(RIL_PCO_Data));
4427 return RIL_ERRNO_INVALID_RESPONSE;
4428 }
4429
4430 RIL_PCO_Data *p_cur = (RIL_PCO_Data *)response;
4431 p.writeInt32(p_cur->cid);
4432 writeStringToParcel(p, p_cur->bearer_proto);
4433 p.writeInt32(p_cur->pco_id);
4434 p.writeInt32(p_cur->contents_length);
4435 p.write(p_cur->contents, p_cur->contents_length);
4436
4437 startResponse;
4438 appendPrintBuf("PCO data received: cid %d, id %d, length %d",
4439 p_cur->cid, p_cur->pco_id, p_cur->contents_length);
4440 closeResponse;
4441
4442 return 0;
4443}
4444
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004445/**
4446 * A write on the wakeup fd is done just to pop us out of select()
4447 * We empty the buffer here and then ril_event will reset the timers on the
4448 * way back down
4449 */
4450static void processWakeupCallback(int fd, short flags, void *param) {
4451 char buff[16];
4452 int ret;
4453
Ethan Chend6e30652013-08-04 22:49:56 -07004454 RLOGV("processWakeupCallback");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004455
4456 /* empty our wakeup socket out */
4457 do {
4458 ret = read(s_fdWakeupRead, &buff, sizeof(buff));
4459 } while (ret > 0 || (ret < 0 && errno == EINTR));
4460}
4461
Howard Sue32dbfd2015-01-07 15:55:57 +08004462static void onCommandsSocketClosed(RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004463 int ret;
4464 RequestInfo *p_cur;
Howard Sue32dbfd2015-01-07 15:55:57 +08004465 /* Hook for current context
4466 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
4467 pthread_mutex_t * pendingRequestsMutexHook = &s_pendingRequestsMutex;
4468 /* pendingRequestsHook refer to &s_pendingRequests */
4469 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004470
Howard Sue32dbfd2015-01-07 15:55:57 +08004471#if (SIM_COUNT >= 2)
4472 if (socket_id == RIL_SOCKET_2) {
4473 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
4474 pendingRequestsHook = &s_pendingRequests_socket2;
4475 }
4476#if (SIM_COUNT >= 3)
4477 else if (socket_id == RIL_SOCKET_3) {
4478 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
4479 pendingRequestsHook = &s_pendingRequests_socket3;
4480 }
4481#endif
4482#if (SIM_COUNT >= 4)
4483 else if (socket_id == RIL_SOCKET_4) {
4484 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
4485 pendingRequestsHook = &s_pendingRequests_socket4;
4486 }
4487#endif
4488#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004489 /* mark pending requests as "cancelled" so we dont report responses */
Howard Sue32dbfd2015-01-07 15:55:57 +08004490 ret = pthread_mutex_lock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004491 assert (ret == 0);
4492
Howard Sue32dbfd2015-01-07 15:55:57 +08004493 p_cur = *pendingRequestsHook;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004494
Howard Sue32dbfd2015-01-07 15:55:57 +08004495 for (p_cur = *pendingRequestsHook
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004496 ; p_cur != NULL
4497 ; p_cur = p_cur->p_next
4498 ) {
4499 p_cur->cancelled = 1;
4500 }
4501
Howard Sue32dbfd2015-01-07 15:55:57 +08004502 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004503 assert (ret == 0);
4504}
4505
4506static void processCommandsCallback(int fd, short flags, void *param) {
4507 RecordStream *p_rs;
4508 void *p_record;
4509 size_t recordlen;
4510 int ret;
Howard Sue32dbfd2015-01-07 15:55:57 +08004511 SocketListenParam *p_info = (SocketListenParam *)param;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004512
Howard Sue32dbfd2015-01-07 15:55:57 +08004513 assert(fd == p_info->fdCommand);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004514
Howard Sue32dbfd2015-01-07 15:55:57 +08004515 p_rs = p_info->p_rs;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004516
4517 for (;;) {
4518 /* loop until EAGAIN/EINTR, end of stream, or other error */
4519 ret = record_stream_get_next(p_rs, &p_record, &recordlen);
4520
4521 if (ret == 0 && p_record == NULL) {
4522 /* end-of-stream */
4523 break;
4524 } else if (ret < 0) {
4525 break;
4526 } else if (ret == 0) { /* && p_record != NULL */
Howard Sue32dbfd2015-01-07 15:55:57 +08004527 processCommandBuffer(p_record, recordlen, p_info->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004528 }
4529 }
4530
4531 if (ret == 0 || !(errno == EAGAIN || errno == EINTR)) {
4532 /* fatal error or end-of-stream */
4533 if (ret != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004534 RLOGE("error on reading command socket errno:%d\n", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004535 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004536 RLOGW("EOS. Closing command socket.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004537 }
4538
Howard Sue32dbfd2015-01-07 15:55:57 +08004539 close(fd);
4540 p_info->fdCommand = -1;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004541
Howard Sue32dbfd2015-01-07 15:55:57 +08004542 ril_event_del(p_info->commands_event);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004543
4544 record_stream_free(p_rs);
4545
4546 /* start listening for new connections again */
4547 rilEventAddWakeup(&s_listen_event);
4548
Howard Sue32dbfd2015-01-07 15:55:57 +08004549 onCommandsSocketClosed(p_info->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004550 }
4551}
4552
Howard Subd82ef12015-04-12 10:25:05 +02004553
Howard Sue32dbfd2015-01-07 15:55:57 +08004554static void onNewCommandConnect(RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004555 // Inform we are connected and the ril version
4556 int rilVer = s_callbacks.version;
Howard Sue32dbfd2015-01-07 15:55:57 +08004557 RIL_UNSOL_RESPONSE(RIL_UNSOL_RIL_CONNECTED,
4558 &rilVer, sizeof(rilVer), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004559
4560 // implicit radio state changed
Howard Sue32dbfd2015-01-07 15:55:57 +08004561 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
4562 NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004563
4564 // Send last NITZ time data, in case it was missed
4565 if (s_lastNITZTimeData != NULL) {
Howard Sue32dbfd2015-01-07 15:55:57 +08004566 sendResponseRaw(s_lastNITZTimeData, s_lastNITZTimeDataSize, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004567
4568 free(s_lastNITZTimeData);
4569 s_lastNITZTimeData = NULL;
4570 }
4571
4572 // Get version string
4573 if (s_callbacks.getVersion != NULL) {
4574 const char *version;
4575 version = s_callbacks.getVersion();
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004576 RLOGI("RIL Daemon version: %s\n", version);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004577
4578 property_set(PROPERTY_RIL_IMPL, version);
4579 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004580 RLOGI("RIL Daemon version: unavailable\n");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004581 property_set(PROPERTY_RIL_IMPL, "unavailable");
4582 }
4583
4584}
4585
4586static void listenCallback (int fd, short flags, void *param) {
4587 int ret;
4588 int err;
4589 int is_phone_socket;
Howard Sue32dbfd2015-01-07 15:55:57 +08004590 int fdCommand = -1;
Christopher N. Hesse65084862017-02-07 22:21:27 +01004591 const char* processName;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004592 RecordStream *p_rs;
Dheeraj Shettycc231012014-07-02 21:27:57 +02004593 MySocketListenParam* listenParam;
4594 RilSocket *sapSocket = NULL;
4595 socketClient *sClient = NULL;
4596
Howard Sue32dbfd2015-01-07 15:55:57 +08004597 SocketListenParam *p_info = (SocketListenParam *)param;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004598
Dheeraj Shettycc231012014-07-02 21:27:57 +02004599 if(RIL_SAP_SOCKET == p_info->type) {
4600 listenParam = (MySocketListenParam *)param;
4601 sapSocket = listenParam->socket;
4602 }
4603
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004604 struct sockaddr_un peeraddr;
4605 socklen_t socklen = sizeof (peeraddr);
4606
4607 struct ucred creds;
4608 socklen_t szCreds = sizeof(creds);
4609
4610 struct passwd *pwd = NULL;
4611
Dheeraj Shettycc231012014-07-02 21:27:57 +02004612 if(NULL == sapSocket) {
4613 assert (*p_info->fdCommand < 0);
4614 assert (fd == *p_info->fdListen);
4615 processName = PHONE_PROCESS;
4616 } else {
4617 assert (sapSocket->commandFd < 0);
4618 assert (fd == sapSocket->listenFd);
4619 processName = BLUETOOTH_PROCESS;
4620 }
4621
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004622
Howard Sue32dbfd2015-01-07 15:55:57 +08004623 fdCommand = accept(fd, (sockaddr *) &peeraddr, &socklen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004624
Howard Sue32dbfd2015-01-07 15:55:57 +08004625 if (fdCommand < 0 ) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004626 RLOGE("Error on accept() errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004627 /* start listening for new connections again */
Dheeraj Shettycc231012014-07-02 21:27:57 +02004628 if(NULL == sapSocket) {
4629 rilEventAddWakeup(p_info->listen_event);
4630 } else {
4631 rilEventAddWakeup(sapSocket->getListenEvent());
4632 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004633 return;
4634 }
4635
4636 /* check the credential of the other side and only accept socket from
4637 * phone process
4638 */
4639 errno = 0;
4640 is_phone_socket = 0;
4641
Howard Sue32dbfd2015-01-07 15:55:57 +08004642 err = getsockopt(fdCommand, SOL_SOCKET, SO_PEERCRED, &creds, &szCreds);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004643
4644 if (err == 0 && szCreds > 0) {
4645 errno = 0;
4646 pwd = getpwuid(creds.uid);
4647 if (pwd != NULL) {
Dheeraj Shettycc231012014-07-02 21:27:57 +02004648 if (strcmp(pwd->pw_name, processName) == 0) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004649 is_phone_socket = 1;
4650 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004651 RLOGE("RILD can't accept socket from process %s", pwd->pw_name);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004652 }
4653 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004654 RLOGE("Error on getpwuid() errno: %d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004655 }
4656 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004657 RLOGD("Error on getsockopt() errno: %d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004658 }
4659
Howard Subd82ef12015-04-12 10:25:05 +02004660 if (!is_phone_socket) {
Dheeraj Shettycc231012014-07-02 21:27:57 +02004661 RLOGE("RILD must accept socket from %s", processName);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004662
Dheeraj Shettycc231012014-07-02 21:27:57 +02004663 close(fdCommand);
4664 fdCommand = -1;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004665
Dheeraj Shettycc231012014-07-02 21:27:57 +02004666 if(NULL == sapSocket) {
4667 onCommandsSocketClosed(p_info->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004668
Dheeraj Shettycc231012014-07-02 21:27:57 +02004669 /* start listening for new connections again */
4670 rilEventAddWakeup(p_info->listen_event);
4671 } else {
4672 sapSocket->onCommandsSocketClosed();
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004673
Dheeraj Shettycc231012014-07-02 21:27:57 +02004674 /* start listening for new connections again */
4675 rilEventAddWakeup(sapSocket->getListenEvent());
4676 }
4677
4678 return;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004679 }
4680
Howard Sue32dbfd2015-01-07 15:55:57 +08004681 ret = fcntl(fdCommand, F_SETFL, O_NONBLOCK);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004682
4683 if (ret < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004684 RLOGE ("Error setting O_NONBLOCK errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004685 }
4686
Dheeraj Shettycc231012014-07-02 21:27:57 +02004687 if(NULL == sapSocket) {
4688 RLOGI("libril: new connection to %s", rilSocketIdToString(p_info->socket_id));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004689
Dheeraj Shettycc231012014-07-02 21:27:57 +02004690 p_info->fdCommand = fdCommand;
4691 p_rs = record_stream_new(p_info->fdCommand, MAX_COMMAND_BYTES);
4692 p_info->p_rs = p_rs;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004693
Dheeraj Shettycc231012014-07-02 21:27:57 +02004694 ril_event_set (p_info->commands_event, p_info->fdCommand, 1,
Howard Sue32dbfd2015-01-07 15:55:57 +08004695 p_info->processCommandsCallback, p_info);
Dheeraj Shettycc231012014-07-02 21:27:57 +02004696 rilEventAddWakeup (p_info->commands_event);
Howard Sue32dbfd2015-01-07 15:55:57 +08004697
Dheeraj Shettycc231012014-07-02 21:27:57 +02004698 onNewCommandConnect(p_info->socket_id);
4699 } else {
4700 RLOGI("libril: new connection");
Howard Sue32dbfd2015-01-07 15:55:57 +08004701
Dheeraj Shettycc231012014-07-02 21:27:57 +02004702 sapSocket->setCommandFd(fdCommand);
4703 p_rs = record_stream_new(sapSocket->getCommandFd(), MAX_COMMAND_BYTES);
4704 sClient = new socketClient(sapSocket,p_rs);
4705 ril_event_set (sapSocket->getCallbackEvent(), sapSocket->getCommandFd(), 1,
4706 sapSocket->getCommandCb(), sClient);
4707
4708 rilEventAddWakeup(sapSocket->getCallbackEvent());
4709 sapSocket->onNewCommandConnect();
4710 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004711}
4712
4713static void freeDebugCallbackArgs(int number, char **args) {
4714 for (int i = 0; i < number; i++) {
4715 if (args[i] != NULL) {
4716 free(args[i]);
4717 }
4718 }
4719 free(args);
4720}
4721
4722static void debugCallback (int fd, short flags, void *param) {
4723 int acceptFD, option;
4724 struct sockaddr_un peeraddr;
4725 socklen_t socklen = sizeof (peeraddr);
4726 int data;
4727 unsigned int qxdm_data[6];
4728 const char *deactData[1] = {"1"};
4729 char *actData[1];
4730 RIL_Dial dialData;
4731 int hangupData[1] = {1};
4732 int number;
4733 char **args;
Howard Sue32dbfd2015-01-07 15:55:57 +08004734 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
4735 int sim_id = 0;
4736
4737 RLOGI("debugCallback for socket %s", rilSocketIdToString(socket_id));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004738
4739 acceptFD = accept (fd, (sockaddr *) &peeraddr, &socklen);
4740
4741 if (acceptFD < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004742 RLOGE ("error accepting on debug port: %d\n", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004743 return;
4744 }
4745
4746 if (recv(acceptFD, &number, sizeof(int), 0) != sizeof(int)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004747 RLOGE ("error reading on socket: number of Args: \n");
Sanket Padawedf3dabe2016-02-29 10:09:26 -08004748 close(acceptFD);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004749 return;
4750 }
Sanket Padawedf3dabe2016-02-29 10:09:26 -08004751
Christopher N. Hesse65084862017-02-07 22:21:27 +01004752 if (number < 0) {
4753 RLOGE ("Invalid number of arguments: \n");
4754 close(acceptFD);
4755 return;
4756 }
4757
4758 args = (char **) calloc(number, sizeof(char*));
Sanket Padawedf3dabe2016-02-29 10:09:26 -08004759 if (args == NULL) {
4760 RLOGE("Memory allocation failed for debug args");
4761 close(acceptFD);
4762 return;
4763 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004764
4765 for (int i = 0; i < number; i++) {
4766 int len;
4767 if (recv(acceptFD, &len, sizeof(int), 0) != sizeof(int)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004768 RLOGE ("error reading on socket: Len of Args: \n");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004769 freeDebugCallbackArgs(i, args);
Sanket Padawedf3dabe2016-02-29 10:09:26 -08004770 close(acceptFD);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004771 return;
4772 }
Sanket Padawedf3dabe2016-02-29 10:09:26 -08004773
Christopher N. Hesse65084862017-02-07 22:21:27 +01004774 if (len == INT_MAX || len < 0) {
4775 RLOGE("Invalid value of len: \n");
4776 freeDebugCallbackArgs(i, args);
4777 close(acceptFD);
4778 return;
4779 }
4780
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004781 // +1 for null-term
Christopher N. Hesse65084862017-02-07 22:21:27 +01004782 args[i] = (char *) calloc(len + 1, sizeof(char));
Sanket Padawedf3dabe2016-02-29 10:09:26 -08004783 if (args[i] == NULL) {
4784 RLOGE("Memory allocation failed for debug args");
4785 freeDebugCallbackArgs(i, args);
4786 close(acceptFD);
4787 return;
4788 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004789 if (recv(acceptFD, args[i], sizeof(char) * len, 0)
4790 != (int)sizeof(char) * len) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004791 RLOGE ("error reading on socket: Args[%d] \n", i);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004792 freeDebugCallbackArgs(i, args);
Sanket Padawedf3dabe2016-02-29 10:09:26 -08004793 close(acceptFD);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004794 return;
4795 }
4796 char * buf = args[i];
4797 buf[len] = 0;
Howard Sue32dbfd2015-01-07 15:55:57 +08004798 if ((i+1) == number) {
4799 /* The last argument should be sim id 0(SIM1)~3(SIM4) */
4800 sim_id = atoi(args[i]);
4801 switch (sim_id) {
4802 case 0:
4803 socket_id = RIL_SOCKET_1;
4804 break;
4805 #if (SIM_COUNT >= 2)
4806 case 1:
4807 socket_id = RIL_SOCKET_2;
4808 break;
4809 #endif
4810 #if (SIM_COUNT >= 3)
4811 case 2:
4812 socket_id = RIL_SOCKET_3;
4813 break;
4814 #endif
4815 #if (SIM_COUNT >= 4)
4816 case 3:
4817 socket_id = RIL_SOCKET_4;
4818 break;
4819 #endif
4820 default:
4821 socket_id = RIL_SOCKET_1;
4822 break;
4823 }
4824 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004825 }
4826
4827 switch (atoi(args[0])) {
4828 case 0:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004829 RLOGI ("Connection on debug port: issuing reset.");
Howard Sue32dbfd2015-01-07 15:55:57 +08004830 issueLocalRequest(RIL_REQUEST_RESET_RADIO, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004831 break;
4832 case 1:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004833 RLOGI ("Connection on debug port: issuing radio power off.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004834 data = 0;
Howard Sue32dbfd2015-01-07 15:55:57 +08004835 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004836 // Close the socket
Howard Subd82ef12015-04-12 10:25:05 +02004837 if (socket_id == RIL_SOCKET_1 && s_ril_param_socket.fdCommand > 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08004838 close(s_ril_param_socket.fdCommand);
4839 s_ril_param_socket.fdCommand = -1;
4840 }
4841 #if (SIM_COUNT == 2)
4842 else if (socket_id == RIL_SOCKET_2 && s_ril_param_socket2.fdCommand > 0) {
4843 close(s_ril_param_socket2.fdCommand);
4844 s_ril_param_socket2.fdCommand = -1;
4845 }
4846 #endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004847 break;
4848 case 2:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004849 RLOGI ("Debug port: issuing unsolicited voice network change.");
Howard Sue32dbfd2015-01-07 15:55:57 +08004850 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004851 break;
4852 case 3:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004853 RLOGI ("Debug port: QXDM log enable.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004854 qxdm_data[0] = 65536; // head.func_tag
4855 qxdm_data[1] = 16; // head.len
4856 qxdm_data[2] = 1; // mode: 1 for 'start logging'
4857 qxdm_data[3] = 32; // log_file_size: 32megabytes
4858 qxdm_data[4] = 0; // log_mask
4859 qxdm_data[5] = 8; // log_max_fileindex
4860 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Howard Sue32dbfd2015-01-07 15:55:57 +08004861 6 * sizeof(int), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004862 break;
4863 case 4:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004864 RLOGI ("Debug port: QXDM log disable.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004865 qxdm_data[0] = 65536;
4866 qxdm_data[1] = 16;
4867 qxdm_data[2] = 0; // mode: 0 for 'stop logging'
4868 qxdm_data[3] = 32;
4869 qxdm_data[4] = 0;
4870 qxdm_data[5] = 8;
4871 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Howard Sue32dbfd2015-01-07 15:55:57 +08004872 6 * sizeof(int), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004873 break;
4874 case 5:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004875 RLOGI("Debug port: Radio On");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004876 data = 1;
Howard Sue32dbfd2015-01-07 15:55:57 +08004877 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004878 sleep(2);
4879 // Set network selection automatic.
Howard Sue32dbfd2015-01-07 15:55:57 +08004880 issueLocalRequest(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004881 break;
4882 case 6:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004883 RLOGI("Debug port: Setup Data Call, Apn :%s\n", args[1]);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004884 actData[0] = args[1];
4885 issueLocalRequest(RIL_REQUEST_SETUP_DATA_CALL, &actData,
Howard Sue32dbfd2015-01-07 15:55:57 +08004886 sizeof(actData), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004887 break;
4888 case 7:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004889 RLOGI("Debug port: Deactivate Data Call");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004890 issueLocalRequest(RIL_REQUEST_DEACTIVATE_DATA_CALL, &deactData,
Howard Sue32dbfd2015-01-07 15:55:57 +08004891 sizeof(deactData), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004892 break;
4893 case 8:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004894 RLOGI("Debug port: Dial Call");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004895 dialData.clir = 0;
4896 dialData.address = args[1];
Howard Sue32dbfd2015-01-07 15:55:57 +08004897 issueLocalRequest(RIL_REQUEST_DIAL, &dialData, sizeof(dialData), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004898 break;
4899 case 9:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004900 RLOGI("Debug port: Answer Call");
Howard Sue32dbfd2015-01-07 15:55:57 +08004901 issueLocalRequest(RIL_REQUEST_ANSWER, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004902 break;
4903 case 10:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004904 RLOGI("Debug port: End Call");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004905 issueLocalRequest(RIL_REQUEST_HANGUP, &hangupData,
Howard Sue32dbfd2015-01-07 15:55:57 +08004906 sizeof(hangupData), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004907 break;
4908 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004909 RLOGE ("Invalid request");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004910 break;
4911 }
4912 freeDebugCallbackArgs(number, args);
4913 close(acceptFD);
4914}
4915
4916
4917static void userTimerCallback (int fd, short flags, void *param) {
4918 UserCallbackInfo *p_info;
4919
4920 p_info = (UserCallbackInfo *)param;
4921
4922 p_info->p_callback(p_info->userParam);
4923
4924
4925 // FIXME generalize this...there should be a cancel mechanism
4926 if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) {
4927 s_last_wake_timeout_info = NULL;
4928 }
4929
4930 free(p_info);
4931}
4932
4933
4934static void *
4935eventLoop(void *param) {
4936 int ret;
4937 int filedes[2];
4938
4939 ril_event_init();
4940
4941 pthread_mutex_lock(&s_startupMutex);
4942
4943 s_started = 1;
4944 pthread_cond_broadcast(&s_startupCond);
4945
4946 pthread_mutex_unlock(&s_startupMutex);
4947
4948 ret = pipe(filedes);
4949
4950 if (ret < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004951 RLOGE("Error in pipe() errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004952 return NULL;
4953 }
4954
4955 s_fdWakeupRead = filedes[0];
4956 s_fdWakeupWrite = filedes[1];
4957
4958 fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK);
4959
4960 ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,
4961 processWakeupCallback, NULL);
4962
4963 rilEventAddWakeup (&s_wakeupfd_event);
4964
4965 // Only returns on error
4966 ril_event_loop();
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004967 RLOGE ("error in event_loop_base errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004968 // kill self to restart on error
4969 kill(0, SIGKILL);
4970
4971 return NULL;
4972}
4973
4974extern "C" void
4975RIL_startEventLoop(void) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004976 /* spin up eventLoop thread and wait for it to get started */
4977 s_started = 0;
4978 pthread_mutex_lock(&s_startupMutex);
4979
Howard Sue32dbfd2015-01-07 15:55:57 +08004980 pthread_attr_t attr;
4981 pthread_attr_init(&attr);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004982 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
Howard Sue32dbfd2015-01-07 15:55:57 +08004983
4984 int result = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
4985 if (result != 0) {
4986 RLOGE("Failed to create dispatch thread: %s", strerror(result));
4987 goto done;
4988 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004989
4990 while (s_started == 0) {
4991 pthread_cond_wait(&s_startupCond, &s_startupMutex);
4992 }
4993
Howard Sue32dbfd2015-01-07 15:55:57 +08004994done:
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004995 pthread_mutex_unlock(&s_startupMutex);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004996}
4997
4998// Used for testing purpose only.
4999extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) {
5000 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
5001}
5002
Howard Sue32dbfd2015-01-07 15:55:57 +08005003static void startListen(RIL_SOCKET_ID socket_id, SocketListenParam* socket_listen_p) {
5004 int fdListen = -1;
5005 int ret;
5006 char socket_name[10];
5007
5008 memset(socket_name, 0, sizeof(char)*10);
5009
5010 switch(socket_id) {
5011 case RIL_SOCKET_1:
5012 strncpy(socket_name, RIL_getRilSocketName(), 9);
5013 break;
5014 #if (SIM_COUNT >= 2)
5015 case RIL_SOCKET_2:
5016 strncpy(socket_name, SOCKET2_NAME_RIL, 9);
5017 break;
5018 #endif
5019 #if (SIM_COUNT >= 3)
5020 case RIL_SOCKET_3:
5021 strncpy(socket_name, SOCKET3_NAME_RIL, 9);
5022 break;
5023 #endif
5024 #if (SIM_COUNT >= 4)
5025 case RIL_SOCKET_4:
5026 strncpy(socket_name, SOCKET4_NAME_RIL, 9);
5027 break;
5028 #endif
5029 default:
5030 RLOGE("Socket id is wrong!!");
5031 return;
5032 }
5033
5034 RLOGI("Start to listen %s", rilSocketIdToString(socket_id));
5035
5036 fdListen = android_get_control_socket(socket_name);
5037 if (fdListen < 0) {
5038 RLOGE("Failed to get socket %s", socket_name);
5039 exit(-1);
5040 }
5041
5042 ret = listen(fdListen, 4);
5043
5044 if (ret < 0) {
5045 RLOGE("Failed to listen on control socket '%d': %s",
5046 fdListen, strerror(errno));
5047 exit(-1);
5048 }
5049 socket_listen_p->fdListen = fdListen;
5050
5051 /* note: non-persistent so we can accept only one connection at a time */
5052 ril_event_set (socket_listen_p->listen_event, fdListen, false,
5053 listenCallback, socket_listen_p);
5054
5055 rilEventAddWakeup (socket_listen_p->listen_event);
5056}
5057
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005058extern "C" void
5059RIL_register (const RIL_RadioFunctions *callbacks) {
5060 int ret;
5061 int flags;
5062
Howard Sue32dbfd2015-01-07 15:55:57 +08005063 RLOGI("SIM_COUNT: %d", SIM_COUNT);
5064
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005065 if (callbacks == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005066 RLOGE("RIL_register: RIL_RadioFunctions * null");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005067 return;
5068 }
5069 if (callbacks->version < RIL_VERSION_MIN) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005070 RLOGE("RIL_register: version %d is to old, min version is %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005071 callbacks->version, RIL_VERSION_MIN);
5072 return;
5073 }
Sanket Padawe9343e872016-01-11 12:45:43 -08005074
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005075 RLOGE("RIL_register: RIL version %d", callbacks->version);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005076
5077 if (s_registerCalled > 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005078 RLOGE("RIL_register has been called more than once. "
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005079 "Subsequent call ignored");
5080 return;
5081 }
5082
5083 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
5084
Howard Sue32dbfd2015-01-07 15:55:57 +08005085 /* Initialize socket1 parameters */
5086 s_ril_param_socket = {
5087 RIL_SOCKET_1, /* socket_id */
5088 -1, /* fdListen */
5089 -1, /* fdCommand */
5090 PHONE_PROCESS, /* processName */
5091 &s_commands_event, /* commands_event */
5092 &s_listen_event, /* listen_event */
5093 processCommandsCallback, /* processCommandsCallback */
Christopher N. Hesse65084862017-02-07 22:21:27 +01005094 NULL, /* p_rs */
5095 RIL_TELEPHONY_SOCKET /* type */
Howard Sue32dbfd2015-01-07 15:55:57 +08005096 };
5097
5098#if (SIM_COUNT >= 2)
5099 s_ril_param_socket2 = {
5100 RIL_SOCKET_2, /* socket_id */
5101 -1, /* fdListen */
5102 -1, /* fdCommand */
5103 PHONE_PROCESS, /* processName */
5104 &s_commands_event_socket2, /* commands_event */
5105 &s_listen_event_socket2, /* listen_event */
5106 processCommandsCallback, /* processCommandsCallback */
Christopher N. Hesse65084862017-02-07 22:21:27 +01005107 NULL, /* p_rs */
5108 RIL_TELEPHONY_SOCKET /* type */
Howard Sue32dbfd2015-01-07 15:55:57 +08005109 };
5110#endif
5111
5112#if (SIM_COUNT >= 3)
5113 s_ril_param_socket3 = {
5114 RIL_SOCKET_3, /* socket_id */
5115 -1, /* fdListen */
5116 -1, /* fdCommand */
5117 PHONE_PROCESS, /* processName */
5118 &s_commands_event_socket3, /* commands_event */
5119 &s_listen_event_socket3, /* listen_event */
5120 processCommandsCallback, /* processCommandsCallback */
Christopher N. Hesse65084862017-02-07 22:21:27 +01005121 NULL, /* p_rs */
5122 RIL_TELEPHONY_SOCKET /* type */
Howard Sue32dbfd2015-01-07 15:55:57 +08005123 };
5124#endif
5125
5126#if (SIM_COUNT >= 4)
5127 s_ril_param_socket4 = {
5128 RIL_SOCKET_4, /* socket_id */
5129 -1, /* fdListen */
5130 -1, /* fdCommand */
5131 PHONE_PROCESS, /* processName */
5132 &s_commands_event_socket4, /* commands_event */
5133 &s_listen_event_socket4, /* listen_event */
5134 processCommandsCallback, /* processCommandsCallback */
Christopher N. Hesse65084862017-02-07 22:21:27 +01005135 NULL, /* p_rs */
5136 RIL_TELEPHONY_SOCKET /* type */
Howard Sue32dbfd2015-01-07 15:55:57 +08005137 };
5138#endif
5139
Howard Subd82ef12015-04-12 10:25:05 +02005140
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005141 s_registerCalled = 1;
5142
Howard Sue32dbfd2015-01-07 15:55:57 +08005143 RLOGI("s_registerCalled flag set, %d", s_started);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005144 // Little self-check
5145
5146 for (int i = 0; i < (int)NUM_ELEMS(s_commands); i++) {
5147 assert(i == s_commands[i].requestNumber);
5148 }
5149
Howard Subd82ef12015-04-12 10:25:05 +02005150 for (int i = 0; i < (int)NUM_ELEMS(s_commands_v); i++) {
5151 assert(i + RIL_VENDOR_COMMANDS_OFFSET == s_commands[i].requestNumber);
5152 }
5153
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005154 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses); i++) {
Howard Sue32dbfd2015-01-07 15:55:57 +08005155 assert(i + RIL_UNSOL_RESPONSE_BASE
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005156 == s_unsolResponses[i].requestNumber);
5157 }
5158
Howard Subd82ef12015-04-12 10:25:05 +02005159 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses_v); i++) {
5160 assert(i + RIL_UNSOL_RESPONSE_BASE + RIL_VENDOR_COMMANDS_OFFSET
5161 == s_unsolResponses[i].requestNumber);
5162 }
5163
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005164 // New rild impl calls RIL_startEventLoop() first
5165 // old standalone impl wants it here.
5166
5167 if (s_started == 0) {
5168 RIL_startEventLoop();
5169 }
5170
Howard Sue32dbfd2015-01-07 15:55:57 +08005171 // start listen socket1
5172 startListen(RIL_SOCKET_1, &s_ril_param_socket);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005173
Howard Sue32dbfd2015-01-07 15:55:57 +08005174#if (SIM_COUNT >= 2)
5175 // start listen socket2
5176 startListen(RIL_SOCKET_2, &s_ril_param_socket2);
5177#endif /* (SIM_COUNT == 2) */
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005178
Howard Sue32dbfd2015-01-07 15:55:57 +08005179#if (SIM_COUNT >= 3)
5180 // start listen socket3
5181 startListen(RIL_SOCKET_3, &s_ril_param_socket3);
5182#endif /* (SIM_COUNT == 3) */
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005183
Howard Sue32dbfd2015-01-07 15:55:57 +08005184#if (SIM_COUNT >= 4)
5185 // start listen socket4
5186 startListen(RIL_SOCKET_4, &s_ril_param_socket4);
5187#endif /* (SIM_COUNT == 4) */
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005188
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005189
5190#if 1
5191 // start debug interface socket
5192
Howard Sue32dbfd2015-01-07 15:55:57 +08005193 char *inst = NULL;
5194 if (strlen(RIL_getRilSocketName()) >= strlen(SOCKET_NAME_RIL)) {
5195 inst = RIL_getRilSocketName() + strlen(SOCKET_NAME_RIL);
5196 }
5197
5198 char rildebug[MAX_DEBUG_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL_DEBUG;
5199 if (inst != NULL) {
Christopher N. Hesse65084862017-02-07 22:21:27 +01005200 strlcat(rildebug, inst, MAX_DEBUG_SOCKET_NAME_LENGTH);
Howard Sue32dbfd2015-01-07 15:55:57 +08005201 }
5202
5203 s_fdDebug = android_get_control_socket(rildebug);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005204 if (s_fdDebug < 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08005205 RLOGE("Failed to get socket : %s errno:%d", rildebug, errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005206 exit(-1);
5207 }
5208
5209 ret = listen(s_fdDebug, 4);
5210
5211 if (ret < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005212 RLOGE("Failed to listen on ril debug socket '%d': %s",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005213 s_fdDebug, strerror(errno));
5214 exit(-1);
5215 }
5216
5217 ril_event_set (&s_debug_event, s_fdDebug, true,
5218 debugCallback, NULL);
5219
5220 rilEventAddWakeup (&s_debug_event);
5221#endif
5222
5223}
5224
Dheeraj Shettycc231012014-07-02 21:27:57 +02005225extern "C" void
5226RIL_register_socket (RIL_RadioFunctions *(*Init)(const struct RIL_Env *, int, char **),RIL_SOCKET_TYPE socketType, int argc, char **argv) {
5227
5228 RIL_RadioFunctions* UimFuncs = NULL;
5229
5230 if(Init) {
5231 UimFuncs = Init(&RilSapSocket::uimRilEnv, argc, argv);
5232
5233 switch(socketType) {
5234 case RIL_SAP_SOCKET:
5235 RilSapSocket::initSapSocket("sap_uim_socket1", UimFuncs);
5236
5237#if (SIM_COUNT >= 2)
5238 RilSapSocket::initSapSocket("sap_uim_socket2", UimFuncs);
5239#endif
5240
5241#if (SIM_COUNT >= 3)
5242 RilSapSocket::initSapSocket("sap_uim_socket3", UimFuncs);
5243#endif
5244
5245#if (SIM_COUNT >= 4)
5246 RilSapSocket::initSapSocket("sap_uim_socket4", UimFuncs);
5247#endif
Christopher N. Hesse65084862017-02-07 22:21:27 +01005248 break;
5249 default:;
Dheeraj Shettycc231012014-07-02 21:27:57 +02005250 }
5251 }
5252}
5253
Sanket Padawea7c043d2016-01-27 15:09:12 -08005254// Check and remove RequestInfo if its a response and not just ack sent back
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005255static int
Sanket Padawea7c043d2016-01-27 15:09:12 -08005256checkAndDequeueRequestInfoIfAck(struct RequestInfo *pRI, bool isAck) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005257 int ret = 0;
Howard Sue32dbfd2015-01-07 15:55:57 +08005258 /* Hook for current context
5259 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
5260 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
5261 /* pendingRequestsHook refer to &s_pendingRequests */
5262 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005263
5264 if (pRI == NULL) {
5265 return 0;
5266 }
5267
Howard Sue32dbfd2015-01-07 15:55:57 +08005268#if (SIM_COUNT >= 2)
5269 if (pRI->socket_id == RIL_SOCKET_2) {
5270 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
5271 pendingRequestsHook = &s_pendingRequests_socket2;
5272 }
5273#if (SIM_COUNT >= 3)
5274 if (pRI->socket_id == RIL_SOCKET_3) {
5275 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
5276 pendingRequestsHook = &s_pendingRequests_socket3;
5277 }
5278#endif
5279#if (SIM_COUNT >= 4)
5280 if (pRI->socket_id == RIL_SOCKET_4) {
5281 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
5282 pendingRequestsHook = &s_pendingRequests_socket4;
5283 }
5284#endif
5285#endif
5286 pthread_mutex_lock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005287
Howard Sue32dbfd2015-01-07 15:55:57 +08005288 for(RequestInfo **ppCur = pendingRequestsHook
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005289 ; *ppCur != NULL
5290 ; ppCur = &((*ppCur)->p_next)
5291 ) {
5292 if (pRI == *ppCur) {
5293 ret = 1;
Sanket Padawea7c043d2016-01-27 15:09:12 -08005294 if (isAck) { // Async ack
5295 if (pRI->wasAckSent == 1) {
5296 RLOGD("Ack was already sent for %s", requestToString(pRI->pCI->requestNumber));
5297 } else {
5298 pRI->wasAckSent = 1;
5299 }
5300 } else {
5301 *ppCur = (*ppCur)->p_next;
5302 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005303 break;
5304 }
5305 }
5306
Howard Sue32dbfd2015-01-07 15:55:57 +08005307 pthread_mutex_unlock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005308
5309 return ret;
5310}
5311
Sanket Padawea7c043d2016-01-27 15:09:12 -08005312static int findFd(int socket_id) {
Howard Sue32dbfd2015-01-07 15:55:57 +08005313 int fd = s_ril_param_socket.fdCommand;
Howard Sue32dbfd2015-01-07 15:55:57 +08005314#if (SIM_COUNT >= 2)
5315 if (socket_id == RIL_SOCKET_2) {
5316 fd = s_ril_param_socket2.fdCommand;
5317 }
5318#if (SIM_COUNT >= 3)
Sanket Padawea7c043d2016-01-27 15:09:12 -08005319 if (socket_id == RIL_SOCKET_3) {
5320 fd = s_ril_param_socket3.fdCommand;
5321 }
Howard Sue32dbfd2015-01-07 15:55:57 +08005322#endif
5323#if (SIM_COUNT >= 4)
5324 if (socket_id == RIL_SOCKET_4) {
5325 fd = s_ril_param_socket4.fdCommand;
5326 }
5327#endif
5328#endif
Sanket Padawea7c043d2016-01-27 15:09:12 -08005329 return fd;
5330}
5331
5332extern "C" void
5333RIL_onRequestAck(RIL_Token t) {
5334 RequestInfo *pRI;
5335 int ret, fd;
5336
5337 size_t errorOffset;
5338 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
5339
5340 pRI = (RequestInfo *)t;
5341
5342 if (!checkAndDequeueRequestInfoIfAck(pRI, true)) {
5343 RLOGE ("RIL_onRequestAck: invalid RIL_Token");
5344 return;
5345 }
5346
5347 socket_id = pRI->socket_id;
5348 fd = findFd(socket_id);
5349
5350#if VDBG
5351 RLOGD("Request Ack, %s", rilSocketIdToString(socket_id));
5352#endif
5353
5354 appendPrintBuf("Ack [%04d]< %s", pRI->token, requestToString(pRI->pCI->requestNumber));
5355
5356 if (pRI->cancelled == 0) {
5357 Parcel p;
5358
5359 p.writeInt32 (RESPONSE_SOLICITED_ACK);
5360 p.writeInt32 (pRI->token);
5361
5362 if (fd < 0) {
5363 RLOGD ("RIL onRequestComplete: Command channel closed");
5364 }
5365
5366 sendResponse(p, socket_id);
5367 }
5368}
5369
5370extern "C" void
5371RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) {
5372 RequestInfo *pRI;
5373 int ret;
5374 int fd;
5375 size_t errorOffset;
5376 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
5377
5378 pRI = (RequestInfo *)t;
5379
5380 if (!checkAndDequeueRequestInfoIfAck(pRI, false)) {
5381 RLOGE ("RIL_onRequestComplete: invalid RIL_Token");
5382 return;
5383 }
5384
5385 socket_id = pRI->socket_id;
5386 fd = findFd(socket_id);
5387
Robert Greenwaltbc29c432015-04-29 16:57:39 -07005388#if VDBG
Howard Sue32dbfd2015-01-07 15:55:57 +08005389 RLOGD("RequestComplete, %s", rilSocketIdToString(socket_id));
Robert Greenwaltbc29c432015-04-29 16:57:39 -07005390#endif
Howard Sue32dbfd2015-01-07 15:55:57 +08005391
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005392 if (pRI->local > 0) {
5393 // Locally issued command...void only!
5394 // response does not go back up the command socket
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005395 RLOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005396
5397 goto done;
5398 }
5399
5400 appendPrintBuf("[%04d]< %s",
5401 pRI->token, requestToString(pRI->pCI->requestNumber));
5402
5403 if (pRI->cancelled == 0) {
5404 Parcel p;
5405
Sanket Padawea7c043d2016-01-27 15:09:12 -08005406 if (s_callbacks.version >= 13 && pRI->wasAckSent == 1) {
5407 // If ack was already sent, then this call is an asynchronous response. So we need to
5408 // send id indicating that we expect an ack from RIL.java as we acquire wakelock here.
5409 p.writeInt32 (RESPONSE_SOLICITED_ACK_EXP);
5410 grabPartialWakeLock();
5411 } else {
5412 p.writeInt32 (RESPONSE_SOLICITED);
5413 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005414 p.writeInt32 (pRI->token);
5415 errorOffset = p.dataPosition();
5416
5417 p.writeInt32 (e);
5418
5419 if (response != NULL) {
5420 // there is a response payload, no matter success or not.
5421 ret = pRI->pCI->responseFunction(p, response, responselen);
5422
5423 /* if an error occurred, rewind and mark it */
5424 if (ret != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08005425 RLOGE ("responseFunction error, ret %d", ret);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005426 p.setDataPosition(errorOffset);
5427 p.writeInt32 (ret);
5428 }
5429 }
5430
5431 if (e != RIL_E_SUCCESS) {
5432 appendPrintBuf("%s fails by %s", printBuf, failCauseToString(e));
5433 }
5434
Howard Sue32dbfd2015-01-07 15:55:57 +08005435 if (fd < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005436 RLOGD ("RIL onRequestComplete: Command channel closed");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005437 }
Howard Sue32dbfd2015-01-07 15:55:57 +08005438 sendResponse(p, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005439 }
5440
5441done:
5442 free(pRI);
5443}
5444
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005445static void
5446grabPartialWakeLock() {
Sanket Padawea7c043d2016-01-27 15:09:12 -08005447 if (s_callbacks.version >= 13) {
5448 int ret;
5449 ret = pthread_mutex_lock(&s_wakeLockCountMutex);
5450 assert(ret == 0);
5451 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
Sanket Padawedf3dabe2016-02-29 10:09:26 -08005452
5453 UserCallbackInfo *p_info =
5454 internalRequestTimedCallback(wakeTimeoutCallback, NULL, &TIMEVAL_WAKE_TIMEOUT);
5455 if (p_info == NULL) {
5456 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
5457 } else {
5458 s_wakelock_count++;
5459 if (s_last_wake_timeout_info != NULL) {
5460 s_last_wake_timeout_info->userParam = (void *)1;
5461 }
5462 s_last_wake_timeout_info = p_info;
Sanket Padawea7c043d2016-01-27 15:09:12 -08005463 }
Sanket Padawea7c043d2016-01-27 15:09:12 -08005464 ret = pthread_mutex_unlock(&s_wakeLockCountMutex);
5465 assert(ret == 0);
5466 } else {
5467 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
5468 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005469}
5470
5471static void
5472releaseWakeLock() {
Sanket Padawea7c043d2016-01-27 15:09:12 -08005473 if (s_callbacks.version >= 13) {
5474 int ret;
5475 ret = pthread_mutex_lock(&s_wakeLockCountMutex);
5476 assert(ret == 0);
5477
5478 if (s_wakelock_count > 1) {
5479 s_wakelock_count--;
5480 } else {
5481 s_wakelock_count = 0;
5482 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
5483 if (s_last_wake_timeout_info != NULL) {
5484 s_last_wake_timeout_info->userParam = (void *)1;
5485 }
5486 }
5487
5488 ret = pthread_mutex_unlock(&s_wakeLockCountMutex);
5489 assert(ret == 0);
5490 } else {
5491 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
5492 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005493}
5494
5495/**
5496 * Timer callback to put us back to sleep before the default timeout
5497 */
5498static void
5499wakeTimeoutCallback (void *param) {
5500 // We're using "param != NULL" as a cancellation mechanism
Sanket Padawea7c043d2016-01-27 15:09:12 -08005501 if (s_callbacks.version >= 13) {
5502 if (param == NULL) {
5503 int ret;
5504 ret = pthread_mutex_lock(&s_wakeLockCountMutex);
5505 assert(ret == 0);
5506 s_wakelock_count = 0;
5507 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
5508 ret = pthread_mutex_unlock(&s_wakeLockCountMutex);
5509 assert(ret == 0);
5510 }
5511 } else {
5512 if (param == NULL) {
5513 releaseWakeLock();
5514 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005515 }
5516}
5517
5518static int
5519decodeVoiceRadioTechnology (RIL_RadioState radioState) {
5520 switch (radioState) {
5521 case RADIO_STATE_SIM_NOT_READY:
5522 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
5523 case RADIO_STATE_SIM_READY:
5524 return RADIO_TECH_UMTS;
5525
5526 case RADIO_STATE_RUIM_NOT_READY:
5527 case RADIO_STATE_RUIM_READY:
5528 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
5529 case RADIO_STATE_NV_NOT_READY:
5530 case RADIO_STATE_NV_READY:
5531 return RADIO_TECH_1xRTT;
5532
5533 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005534 RLOGD("decodeVoiceRadioTechnology: Invoked with incorrect RadioState");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005535 return -1;
5536 }
5537}
5538
5539static int
5540decodeCdmaSubscriptionSource (RIL_RadioState radioState) {
5541 switch (radioState) {
5542 case RADIO_STATE_SIM_NOT_READY:
5543 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
5544 case RADIO_STATE_SIM_READY:
5545 case RADIO_STATE_RUIM_NOT_READY:
5546 case RADIO_STATE_RUIM_READY:
5547 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
5548 return CDMA_SUBSCRIPTION_SOURCE_RUIM_SIM;
5549
5550 case RADIO_STATE_NV_NOT_READY:
5551 case RADIO_STATE_NV_READY:
5552 return CDMA_SUBSCRIPTION_SOURCE_NV;
5553
5554 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005555 RLOGD("decodeCdmaSubscriptionSource: Invoked with incorrect RadioState");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005556 return -1;
5557 }
5558}
5559
5560static int
5561decodeSimStatus (RIL_RadioState radioState) {
5562 switch (radioState) {
5563 case RADIO_STATE_SIM_NOT_READY:
5564 case RADIO_STATE_RUIM_NOT_READY:
5565 case RADIO_STATE_NV_NOT_READY:
5566 case RADIO_STATE_NV_READY:
5567 return -1;
5568 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
5569 case RADIO_STATE_SIM_READY:
5570 case RADIO_STATE_RUIM_READY:
5571 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
5572 return radioState;
5573 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005574 RLOGD("decodeSimStatus: Invoked with incorrect RadioState");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005575 return -1;
5576 }
5577}
5578
5579static bool is3gpp2(int radioTech) {
5580 switch (radioTech) {
5581 case RADIO_TECH_IS95A:
5582 case RADIO_TECH_IS95B:
5583 case RADIO_TECH_1xRTT:
5584 case RADIO_TECH_EVDO_0:
5585 case RADIO_TECH_EVDO_A:
5586 case RADIO_TECH_EVDO_B:
5587 case RADIO_TECH_EHRPD:
5588 return true;
5589 default:
5590 return false;
5591 }
5592}
5593
5594/* If RIL sends SIM states or RUIM states, store the voice radio
5595 * technology and subscription source information so that they can be
5596 * returned when telephony framework requests them
5597 */
5598static RIL_RadioState
Howard Subd82ef12015-04-12 10:25:05 +02005599processRadioState(RIL_RadioState newRadioState, RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005600
5601 if((newRadioState > RADIO_STATE_UNAVAILABLE) && (newRadioState < RADIO_STATE_ON)) {
5602 int newVoiceRadioTech;
5603 int newCdmaSubscriptionSource;
5604 int newSimStatus;
5605
5606 /* This is old RIL. Decode Subscription source and Voice Radio Technology
5607 from Radio State and send change notifications if there has been a change */
5608 newVoiceRadioTech = decodeVoiceRadioTechnology(newRadioState);
5609 if(newVoiceRadioTech != voiceRadioTech) {
5610 voiceRadioTech = newVoiceRadioTech;
Howard Sue32dbfd2015-01-07 15:55:57 +08005611 RIL_UNSOL_RESPONSE(RIL_UNSOL_VOICE_RADIO_TECH_CHANGED,
5612 &voiceRadioTech, sizeof(voiceRadioTech), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005613 }
5614 if(is3gpp2(newVoiceRadioTech)) {
5615 newCdmaSubscriptionSource = decodeCdmaSubscriptionSource(newRadioState);
5616 if(newCdmaSubscriptionSource != cdmaSubscriptionSource) {
5617 cdmaSubscriptionSource = newCdmaSubscriptionSource;
Howard Sue32dbfd2015-01-07 15:55:57 +08005618 RIL_UNSOL_RESPONSE(RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED,
5619 &cdmaSubscriptionSource, sizeof(cdmaSubscriptionSource), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005620 }
5621 }
5622 newSimStatus = decodeSimStatus(newRadioState);
5623 if(newSimStatus != simRuimStatus) {
5624 simRuimStatus = newSimStatus;
Howard Sue32dbfd2015-01-07 15:55:57 +08005625 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005626 }
5627
5628 /* Send RADIO_ON to telephony */
5629 newRadioState = RADIO_STATE_ON;
5630 }
5631
5632 return newRadioState;
5633}
5634
Howard Subd82ef12015-04-12 10:25:05 +02005635
Howard Sue32dbfd2015-01-07 15:55:57 +08005636#if defined(ANDROID_MULTI_SIM)
5637extern "C"
Andreas Schneider47b2d962015-04-13 22:54:49 +02005638void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Howard Sue32dbfd2015-01-07 15:55:57 +08005639 size_t datalen, RIL_SOCKET_ID socket_id)
5640#else
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005641extern "C"
Andreas Schneider47b2d962015-04-13 22:54:49 +02005642void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005643 size_t datalen)
Howard Sue32dbfd2015-01-07 15:55:57 +08005644#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005645{
Christopher N. Hesse65084862017-02-07 22:21:27 +01005646 int unsolResponseIndex;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005647 int ret;
5648 int64_t timeReceived = 0;
5649 bool shouldScheduleTimeout = false;
5650 RIL_RadioState newState;
Howard Sue32dbfd2015-01-07 15:55:57 +08005651 RIL_SOCKET_ID soc_id = RIL_SOCKET_1;
Howard Subd82ef12015-04-12 10:25:05 +02005652 UnsolResponseInfo *pRI = NULL;
Christopher N. Hesse65084862017-02-07 22:21:27 +01005653 int32_t pRI_elements;
Howard Sue32dbfd2015-01-07 15:55:57 +08005654
5655#if defined(ANDROID_MULTI_SIM)
5656 soc_id = socket_id;
5657#endif
5658
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005659
5660 if (s_registerCalled == 0) {
5661 // Ignore RIL_onUnsolicitedResponse before RIL_register
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005662 RLOGW("RIL_onUnsolicitedResponse called before RIL_register");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005663 return;
5664 }
Howard Sue32dbfd2015-01-07 15:55:57 +08005665
Christopher N. Hesse65084862017-02-07 22:21:27 +01005666 unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
5667 pRI = s_unsolResponses;
Christopher N. Hessecaece2d2017-02-11 18:59:31 +01005668 pRI_elements = (int32_t)NUM_ELEMS(s_unsolResponses);
Christopher N. Hesse65084862017-02-07 22:21:27 +01005669
Howard Subd82ef12015-04-12 10:25:05 +02005670 /* Hack to include Samsung responses */
5671 if (unsolResponse > RIL_VENDOR_COMMANDS_OFFSET + RIL_UNSOL_RESPONSE_BASE) {
Christopher N. Hesse65084862017-02-07 22:21:27 +01005672 pRI = s_unsolResponses_v;
Christopher N. Hessecaece2d2017-02-11 18:59:31 +01005673 pRI_elements = (int32_t)NUM_ELEMS(s_unsolResponses_v);
5674
5675 /*
5676 * Some of the vendor response codes cannot be found by calculating their index anymore,
5677 * because they have an even higher offset and are not ordered in the array.
5678 * Example: RIL_UNSOL_SNDMGR_WB_AMR_REPORT = 20017, but it's at index 33 in the vendor
5679 * response array.
5680 * Thus, look through all the vendor URIs (Unsol Response Info) and pick the correct index.
5681 * This has a cost of O(N).
5682 */
5683 int pRI_index;
5684 for (pRI_index = 0; pRI_index < pRI_elements; pRI_index++) {
5685 if (pRI[pRI_index].requestNumber == unsolResponse) {
5686 unsolResponseIndex = pRI_index;
5687 }
5688 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005689
Christopher N. Hesse65084862017-02-07 22:21:27 +01005690 RLOGD("SAMSUNG: unsolResponse=%d, unsolResponseIndex=%d", unsolResponse, unsolResponseIndex);
5691 }
Howard Subd82ef12015-04-12 10:25:05 +02005692
Christopher N. Hesse65084862017-02-07 22:21:27 +01005693 if (unsolResponseIndex >= 0 && unsolResponseIndex < pRI_elements) {
5694 pRI = &pRI[unsolResponseIndex];
Howard Subd82ef12015-04-12 10:25:05 +02005695 } else {
Christopher N. Hessecaece2d2017-02-11 18:59:31 +01005696 RLOGE("could not map unsolResponse=%d to %s response array (index=%d)", unsolResponse,
5697 pRI == s_unsolResponses ? "AOSP" : "Samsung", unsolResponseIndex);
Howard Subd82ef12015-04-12 10:25:05 +02005698 }
5699
5700 if (pRI == NULL || pRI->responseFunction == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005701 RLOGE("unsupported unsolicited response code %d", unsolResponse);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005702 return;
5703 }
5704
5705 // Grab a wake lock if needed for this reponse,
5706 // as we exit we'll either release it immediately
5707 // or set a timer to release it later.
Howard Subd82ef12015-04-12 10:25:05 +02005708 switch (pRI->wakeType) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005709 case WAKE_PARTIAL:
5710 grabPartialWakeLock();
5711 shouldScheduleTimeout = true;
5712 break;
5713
5714 case DONT_WAKE:
5715 default:
5716 // No wake lock is grabed so don't set timeout
5717 shouldScheduleTimeout = false;
5718 break;
5719 }
5720
5721 // Mark the time this was received, doing this
5722 // after grabing the wakelock incase getting
5723 // the elapsedRealTime might cause us to goto
5724 // sleep.
5725 if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
5726 timeReceived = elapsedRealtime();
5727 }
5728
5729 appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
5730
5731 Parcel p;
Sanket Padawe9f972082016-02-03 11:46:02 -08005732 if (s_callbacks.version >= 13
5733 && pRI->wakeType == WAKE_PARTIAL) {
5734 p.writeInt32 (RESPONSE_UNSOLICITED_ACK_EXP);
5735 } else {
5736 p.writeInt32 (RESPONSE_UNSOLICITED);
5737 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005738 p.writeInt32 (unsolResponse);
5739
Howard Subd82ef12015-04-12 10:25:05 +02005740 ret = pRI->responseFunction(p, const_cast<void*>(data), datalen);
5741
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005742 if (ret != 0) {
5743 // Problem with the response. Don't continue;
5744 goto error_exit;
5745 }
5746
5747 // some things get more payload
5748 switch(unsolResponse) {
5749 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
Howard Sue32dbfd2015-01-07 15:55:57 +08005750 newState = processRadioState(CALL_ONSTATEREQUEST(soc_id), soc_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005751 p.writeInt32(newState);
5752 appendPrintBuf("%s {%s}", printBuf,
Howard Sue32dbfd2015-01-07 15:55:57 +08005753 radioStateToString(CALL_ONSTATEREQUEST(soc_id)));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005754 break;
5755
5756
5757 case RIL_UNSOL_NITZ_TIME_RECEIVED:
5758 // Store the time that this was received so the
5759 // handler of this message can account for
5760 // the time it takes to arrive and process. In
5761 // particular the system has been known to sleep
5762 // before this message can be processed.
5763 p.writeInt64(timeReceived);
5764 break;
5765 }
5766
Sanket Padawedf3dabe2016-02-29 10:09:26 -08005767 if (s_callbacks.version < 13) {
5768 if (shouldScheduleTimeout) {
5769 UserCallbackInfo *p_info = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
5770 &TIMEVAL_WAKE_TIMEOUT);
5771
5772 if (p_info == NULL) {
5773 goto error_exit;
5774 } else {
5775 // Cancel the previous request
5776 if (s_last_wake_timeout_info != NULL) {
5777 s_last_wake_timeout_info->userParam = (void *)1;
5778 }
5779 s_last_wake_timeout_info = p_info;
5780 }
5781 }
5782 }
5783
Robert Greenwaltbc29c432015-04-29 16:57:39 -07005784#if VDBG
Howard Sue32dbfd2015-01-07 15:55:57 +08005785 RLOGI("%s UNSOLICITED: %s length:%d", rilSocketIdToString(soc_id), requestToString(unsolResponse), p.dataSize());
Robert Greenwaltbc29c432015-04-29 16:57:39 -07005786#endif
Howard Sue32dbfd2015-01-07 15:55:57 +08005787 ret = sendResponse(p, soc_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005788 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
5789
5790 // Unfortunately, NITZ time is not poll/update like everything
5791 // else in the system. So, if the upstream client isn't connected,
5792 // keep a copy of the last NITZ response (with receive time noted
5793 // above) around so we can deliver it when it is connected
5794
5795 if (s_lastNITZTimeData != NULL) {
5796 free (s_lastNITZTimeData);
5797 s_lastNITZTimeData = NULL;
5798 }
5799
Christopher N. Hesse65084862017-02-07 22:21:27 +01005800 s_lastNITZTimeData = calloc(p.dataSize(), 1);
Sanket Padawedf3dabe2016-02-29 10:09:26 -08005801 if (s_lastNITZTimeData == NULL) {
5802 RLOGE("Memory allocation failed in RIL_onUnsolicitedResponse");
5803 goto error_exit;
5804 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005805 s_lastNITZTimeDataSize = p.dataSize();
5806 memcpy(s_lastNITZTimeData, p.data(), p.dataSize());
5807 }
5808
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005809 // Normal exit
5810 return;
5811
5812error_exit:
5813 if (shouldScheduleTimeout) {
5814 releaseWakeLock();
5815 }
5816}
5817
5818/** FIXME generalize this if you track UserCAllbackInfo, clear it
5819 when the callback occurs
5820*/
5821static UserCallbackInfo *
5822internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
5823 const struct timeval *relativeTime)
5824{
5825 struct timeval myRelativeTime;
5826 UserCallbackInfo *p_info;
5827
Christopher N. Hesse65084862017-02-07 22:21:27 +01005828 p_info = (UserCallbackInfo *) calloc(1, sizeof(UserCallbackInfo));
Sanket Padawedf3dabe2016-02-29 10:09:26 -08005829 if (p_info == NULL) {
5830 RLOGE("Memory allocation failed in internalRequestTimedCallback");
5831 return p_info;
5832
5833 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005834
5835 p_info->p_callback = callback;
5836 p_info->userParam = param;
5837
5838 if (relativeTime == NULL) {
5839 /* treat null parameter as a 0 relative time */
5840 memset (&myRelativeTime, 0, sizeof(myRelativeTime));
5841 } else {
5842 /* FIXME I think event_add's tv param is really const anyway */
5843 memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
5844 }
5845
5846 ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
5847
5848 ril_timer_add(&(p_info->event), &myRelativeTime);
5849
5850 triggerEvLoop();
5851 return p_info;
5852}
5853
5854
5855extern "C" void
5856RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
5857 const struct timeval *relativeTime) {
5858 internalRequestTimedCallback (callback, param, relativeTime);
5859}
5860
5861const char *
5862failCauseToString(RIL_Errno e) {
5863 switch(e) {
5864 case RIL_E_SUCCESS: return "E_SUCCESS";
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005865 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RADIO_NOT_AVAILABLE";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005866 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
5867 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
5868 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
5869 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
5870 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
5871 case RIL_E_CANCELLED: return "E_CANCELLED";
5872 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
5873 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
5874 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
5875 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
5876 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
5877#ifdef FEATURE_MULTIMODE_ANDROID
5878 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
5879 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
5880#endif
Sanket Padawe6049dec2016-02-08 14:28:59 -08005881 case RIL_E_FDN_CHECK_FAILURE: return "E_FDN_CHECK_FAILURE";
5882 case RIL_E_MISSING_RESOURCE: return "E_MISSING_RESOURCE";
5883 case RIL_E_NO_SUCH_ELEMENT: return "E_NO_SUCH_ELEMENT";
5884 case RIL_E_DIAL_MODIFIED_TO_USSD: return "E_DIAL_MODIFIED_TO_USSD";
5885 case RIL_E_DIAL_MODIFIED_TO_SS: return "E_DIAL_MODIFIED_TO_SS";
5886 case RIL_E_DIAL_MODIFIED_TO_DIAL: return "E_DIAL_MODIFIED_TO_DIAL";
5887 case RIL_E_USSD_MODIFIED_TO_DIAL: return "E_USSD_MODIFIED_TO_DIAL";
5888 case RIL_E_USSD_MODIFIED_TO_SS: return "E_USSD_MODIFIED_TO_SS";
5889 case RIL_E_USSD_MODIFIED_TO_USSD: return "E_USSD_MODIFIED_TO_USSD";
5890 case RIL_E_SS_MODIFIED_TO_DIAL: return "E_SS_MODIFIED_TO_DIAL";
5891 case RIL_E_SS_MODIFIED_TO_USSD: return "E_SS_MODIFIED_TO_USSD";
5892 case RIL_E_SUBSCRIPTION_NOT_SUPPORTED: return "E_SUBSCRIPTION_NOT_SUPPORTED";
5893 case RIL_E_SS_MODIFIED_TO_SS: return "E_SS_MODIFIED_TO_SS";
5894 case RIL_E_LCE_NOT_SUPPORTED: return "E_LCE_NOT_SUPPORTED";
5895 case RIL_E_NO_MEMORY: return "E_NO_MEMORY";
5896 case RIL_E_INTERNAL_ERR: return "E_INTERNAL_ERR";
5897 case RIL_E_SYSTEM_ERR: return "E_SYSTEM_ERR";
5898 case RIL_E_MODEM_ERR: return "E_MODEM_ERR";
5899 case RIL_E_INVALID_STATE: return "E_INVALID_STATE";
5900 case RIL_E_NO_RESOURCES: return "E_NO_RESOURCES";
5901 case RIL_E_SIM_ERR: return "E_SIM_ERR";
5902 case RIL_E_INVALID_ARGUMENTS: return "E_INVALID_ARGUMENTS";
5903 case RIL_E_INVALID_SIM_STATE: return "E_INVALID_SIM_STATE";
5904 case RIL_E_INVALID_MODEM_STATE: return "E_INVALID_MODEM_STATE";
5905 case RIL_E_INVALID_CALL_ID: return "E_INVALID_CALL_ID";
5906 case RIL_E_NO_SMS_TO_ACK: return "E_NO_SMS_TO_ACK";
5907 case RIL_E_NETWORK_ERR: return "E_NETWORK_ERR";
5908 case RIL_E_REQUEST_RATE_LIMITED: return "E_REQUEST_RATE_LIMITED";
twen.chang7dd377c2016-03-04 18:27:48 +08005909 case RIL_E_SIM_BUSY: return "E_SIM_BUSY";
5910 case RIL_E_SIM_FULL: return "E_SIM_FULL";
5911 case RIL_E_NETWORK_REJECT: return "E_NETWORK_REJECT";
5912 case RIL_E_OPERATION_NOT_ALLOWED: return "E_OPERATION_NOT_ALLOWED";
5913 case RIL_E_EMPTY_RECORD: "E_EMPTY_RECORD";
Ajay Nambi69659752016-03-11 12:02:55 -08005914 case RIL_E_INVALID_SMS_FORMAT: return "E_INVALID_SMS_FORMAT";
5915 case RIL_E_ENCODING_ERR: return "E_ENCODING_ERR";
5916 case RIL_E_INVALID_SMSC_ADDRESS: return "E_INVALID_SMSC_ADDRESS";
5917 case RIL_E_NO_SUCH_ENTRY: return "E_NO_SUCH_ENTRY";
5918 case RIL_E_NETWORK_NOT_READY: return "E_NETWORK_NOT_READY";
5919 case RIL_E_NOT_PROVISIONED: return "E_NOT_PROVISIONED";
Ajay Nambi0af7d1c2016-03-19 09:02:28 -07005920 case RIL_E_NO_SUBSCRIPTION: return "E_NO_SUBSCRIPTION";
5921 case RIL_E_NO_NETWORK_FOUND: return "E_NO_NETWORK_FOUND";
5922 case RIL_E_DEVICE_IN_USE: return "E_DEVICE_IN_USE";
5923 case RIL_E_ABORTED: return "E_ABORTED";
Sanket Padawedb5d1e02016-02-09 09:56:31 -08005924 case RIL_E_OEM_ERROR_1: return "E_OEM_ERROR_1";
5925 case RIL_E_OEM_ERROR_2: return "E_OEM_ERROR_2";
5926 case RIL_E_OEM_ERROR_3: return "E_OEM_ERROR_3";
5927 case RIL_E_OEM_ERROR_4: return "E_OEM_ERROR_4";
5928 case RIL_E_OEM_ERROR_5: return "E_OEM_ERROR_5";
5929 case RIL_E_OEM_ERROR_6: return "E_OEM_ERROR_6";
5930 case RIL_E_OEM_ERROR_7: return "E_OEM_ERROR_7";
5931 case RIL_E_OEM_ERROR_8: return "E_OEM_ERROR_8";
5932 case RIL_E_OEM_ERROR_9: return "E_OEM_ERROR_9";
5933 case RIL_E_OEM_ERROR_10: return "E_OEM_ERROR_10";
5934 case RIL_E_OEM_ERROR_11: return "E_OEM_ERROR_11";
5935 case RIL_E_OEM_ERROR_12: return "E_OEM_ERROR_12";
5936 case RIL_E_OEM_ERROR_13: return "E_OEM_ERROR_13";
5937 case RIL_E_OEM_ERROR_14: return "E_OEM_ERROR_14";
5938 case RIL_E_OEM_ERROR_15: return "E_OEM_ERROR_15";
5939 case RIL_E_OEM_ERROR_16: return "E_OEM_ERROR_16";
5940 case RIL_E_OEM_ERROR_17: return "E_OEM_ERROR_17";
5941 case RIL_E_OEM_ERROR_18: return "E_OEM_ERROR_18";
5942 case RIL_E_OEM_ERROR_19: return "E_OEM_ERROR_19";
5943 case RIL_E_OEM_ERROR_20: return "E_OEM_ERROR_20";
5944 case RIL_E_OEM_ERROR_21: return "E_OEM_ERROR_21";
5945 case RIL_E_OEM_ERROR_22: return "E_OEM_ERROR_22";
5946 case RIL_E_OEM_ERROR_23: return "E_OEM_ERROR_23";
5947 case RIL_E_OEM_ERROR_24: return "E_OEM_ERROR_24";
5948 case RIL_E_OEM_ERROR_25: return "E_OEM_ERROR_25";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005949 default: return "<unknown error>";
5950 }
5951}
5952
5953const char *
5954radioStateToString(RIL_RadioState s) {
5955 switch(s) {
5956 case RADIO_STATE_OFF: return "RADIO_OFF";
5957 case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
5958 case RADIO_STATE_SIM_NOT_READY: return "RADIO_SIM_NOT_READY";
5959 case RADIO_STATE_SIM_LOCKED_OR_ABSENT: return "RADIO_SIM_LOCKED_OR_ABSENT";
5960 case RADIO_STATE_SIM_READY: return "RADIO_SIM_READY";
5961 case RADIO_STATE_RUIM_NOT_READY:return"RADIO_RUIM_NOT_READY";
5962 case RADIO_STATE_RUIM_READY:return"RADIO_RUIM_READY";
5963 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:return"RADIO_RUIM_LOCKED_OR_ABSENT";
5964 case RADIO_STATE_NV_NOT_READY:return"RADIO_NV_NOT_READY";
5965 case RADIO_STATE_NV_READY:return"RADIO_NV_READY";
5966 case RADIO_STATE_ON:return"RADIO_ON";
5967 default: return "<unknown state>";
5968 }
5969}
5970
5971const char *
5972callStateToString(RIL_CallState s) {
5973 switch(s) {
5974 case RIL_CALL_ACTIVE : return "ACTIVE";
5975 case RIL_CALL_HOLDING: return "HOLDING";
5976 case RIL_CALL_DIALING: return "DIALING";
5977 case RIL_CALL_ALERTING: return "ALERTING";
5978 case RIL_CALL_INCOMING: return "INCOMING";
5979 case RIL_CALL_WAITING: return "WAITING";
5980 default: return "<unknown state>";
5981 }
5982}
5983
5984const char *
5985requestToString(int request) {
5986/*
5987 cat libs/telephony/ril_commands.h \
5988 | egrep "^ *{RIL_" \
5989 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
5990
5991
5992 cat libs/telephony/ril_unsol_commands.h \
5993 | egrep "^ *{RIL_" \
5994 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
5995
5996*/
5997 switch(request) {
5998 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
5999 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
6000 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
6001 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
6002 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
6003 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
6004 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
6005 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
6006 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
6007 case RIL_REQUEST_DIAL: return "DIAL";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02006008 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
6009 case RIL_REQUEST_HANGUP: return "HANGUP";
6010 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
6011 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
6012 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
6013 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
6014 case RIL_REQUEST_UDUB: return "UDUB";
6015 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
6016 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
6017 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
6018 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
6019 case RIL_REQUEST_OPERATOR: return "OPERATOR";
6020 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
6021 case RIL_REQUEST_DTMF: return "DTMF";
6022 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
6023 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
6024 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
6025 case RIL_REQUEST_SIM_IO: return "SIM_IO";
6026 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
6027 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
6028 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
6029 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
6030 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
6031 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
6032 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
6033 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
6034 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
6035 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
6036 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
6037 case RIL_REQUEST_ANSWER: return "ANSWER";
6038 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
6039 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
6040 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
6041 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
6042 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
6043 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
6044 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
6045 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";
6046 case RIL_REQUEST_DTMF_START: return "DTMF_START";
6047 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
6048 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
6049 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
6050 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
6051 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
6052 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
6053 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
6054 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
6055 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
6056 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
6057 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
Christopher N. Hesse65084862017-02-07 22:21:27 +01006058 case RIL_REQUEST_NV_RESET_CONFIG: return "NV_RESET_CONFIG";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02006059 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
6060 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
6061 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
6062 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
6063 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
6064 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
6065 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
6066 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
6067 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
6068 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
6069 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
6070 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
6071 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
XpLoDWilDba5c6a32013-07-27 21:12:19 +02006072 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE:return"CDMA_SET_SUBSCRIPTION_SOURCE";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02006073 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"CDMA_SET_ROAMING_PREFERENCE";
6074 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"CDMA_QUERY_ROAMING_PREFERENCE";
6075 case RIL_REQUEST_SET_TTY_MODE:return"SET_TTY_MODE";
6076 case RIL_REQUEST_QUERY_TTY_MODE:return"QUERY_TTY_MODE";
6077 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
6078 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
6079 case RIL_REQUEST_CDMA_FLASH:return"CDMA_FLASH";
6080 case RIL_REQUEST_CDMA_BURST_DTMF:return"CDMA_BURST_DTMF";
6081 case RIL_REQUEST_CDMA_SEND_SMS:return"CDMA_SEND_SMS";
6082 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:return"CDMA_SMS_ACKNOWLEDGE";
6083 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG:return"GSM_GET_BROADCAST_SMS_CONFIG";
6084 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG:return"GSM_SET_BROADCAST_SMS_CONFIG";
6085 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG:return "CDMA_GET_BROADCAST_SMS_CONFIG";
6086 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG:return "CDMA_SET_BROADCAST_SMS_CONFIG";
6087 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION:return "CDMA_SMS_BROADCAST_ACTIVATION";
Ethan Chend6e30652013-08-04 22:49:56 -07006088 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return"CDMA_VALIDATE_AND_WRITE_AKEY";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02006089 case RIL_REQUEST_CDMA_SUBSCRIPTION: return"CDMA_SUBSCRIPTION";
6090 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
6091 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
6092 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
6093 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
6094 case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
6095 case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
6096 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
6097 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
6098 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
6099 case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
6100 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
6101 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
6102 case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
Ajay Nambie63b4f62011-11-15 11:19:30 -08006103 case RIL_REQUEST_WRITE_SMS_TO_SIM: return "WRITE_SMS_TO_SIM";
XpLoDWilDba5c6a32013-07-27 21:12:19 +02006104 case RIL_REQUEST_GET_CELL_INFO_LIST: return"GET_CELL_INFO_LIST";
6105 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return"SET_UNSOL_CELL_INFO_LIST_RATE";
Andrew Jiangca4a9a02014-01-18 18:04:08 -05006106 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "RIL_REQUEST_SET_INITIAL_ATTACH_APN";
6107 case RIL_REQUEST_IMS_REGISTRATION_STATE: return "IMS_REGISTRATION_STATE";
6108 case RIL_REQUEST_IMS_SEND_SMS: return "IMS_SEND_SMS";
Howard Sue32dbfd2015-01-07 15:55:57 +08006109 case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "SIM_TRANSMIT_APDU_BASIC";
6110 case RIL_REQUEST_SIM_OPEN_CHANNEL: return "SIM_OPEN_CHANNEL";
6111 case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "SIM_CLOSE_CHANNEL";
6112 case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "SIM_TRANSMIT_APDU_CHANNEL";
Howard Subd82ef12015-04-12 10:25:05 +02006113 case RIL_REQUEST_GET_RADIO_CAPABILITY: return "RIL_REQUEST_GET_RADIO_CAPABILITY";
6114 case RIL_REQUEST_SET_RADIO_CAPABILITY: return "RIL_REQUEST_SET_RADIO_CAPABILITY";
Howard Sue32dbfd2015-01-07 15:55:57 +08006115 case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "SET_UICC_SUBSCRIPTION";
6116 case RIL_REQUEST_ALLOW_DATA: return "ALLOW_DATA";
6117 case RIL_REQUEST_GET_HARDWARE_CONFIG: return "GET_HARDWARE_CONFIG";
6118 case RIL_REQUEST_SIM_AUTHENTICATION: return "SIM_AUTHENTICATION";
6119 case RIL_REQUEST_GET_DC_RT_INFO: return "GET_DC_RT_INFO";
6120 case RIL_REQUEST_SET_DC_RT_INFO_RATE: return "SET_DC_RT_INFO_RATE";
6121 case RIL_REQUEST_SET_DATA_PROFILE: return "SET_DATA_PROFILE";
Christopher N. Hesse65084862017-02-07 22:21:27 +01006122 case RIL_REQUEST_SET_CARRIER_RESTRICTIONS: return "SET_CARRIER_RESTRICTIONS";
6123 case RIL_REQUEST_GET_CARRIER_RESTRICTIONS: return "GET_CARRIER_RESTRICTIONS";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02006124 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
6125 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
6126 case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED";
6127 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
6128 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
6129 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
6130 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
6131 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)";
6132 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
6133 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
Howard Subd82ef12015-04-12 10:25:05 +02006134 case RIL_UNSOL_SUPP_SVC_NOTIFICATION: return "UNSOL_SUPP_SVC_NOTIFICATION";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02006135 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
6136 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
6137 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
6138 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
6139 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL";
6140 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
Christopher N. Hesse65084862017-02-07 22:21:27 +01006141 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02006142 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
6143 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
6144 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_NEW_CDMA_SMS";
6145 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_NEW_BROADCAST_SMS";
6146 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
6147 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
6148 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
6149 case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
6150 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
6151 case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
6152 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
6153 case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
6154 case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
6155 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
6156 case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
6157 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
6158 case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
6159 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
Ethan Chend6e30652013-08-04 22:49:56 -07006160 case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
Andrew Jiangca4a9a02014-01-18 18:04:08 -05006161 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "RESPONSE_IMS_NETWORK_STATE_CHANGED";
Howard Sue32dbfd2015-01-07 15:55:57 +08006162 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return "UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED";
6163 case RIL_UNSOL_SRVCC_STATE_NOTIFY: return "UNSOL_SRVCC_STATE_NOTIFY";
6164 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return "HARDWARE_CONFIG_CHANGED";
6165 case RIL_UNSOL_DC_RT_INFO_CHANGED: return "UNSOL_DC_RT_INFO_CHANGED";
Howard Subd82ef12015-04-12 10:25:05 +02006166 case RIL_UNSOL_ON_SS: return "UNSOL_ON_SS";
6167 case RIL_UNSOL_STK_CC_ALPHA_NOTIFY: return "UNSOL_STK_CC_ALPHA_NOTIFY";
Howard Sue32dbfd2015-01-07 15:55:57 +08006168 case RIL_REQUEST_SHUTDOWN: return "SHUTDOWN";
Christopher N. Hesse65084862017-02-07 22:21:27 +01006169 case RIL_UNSOL_RADIO_CAPABILITY: return "RIL_UNSOL_RADIO_CAPABILITY";
Sanket Padawea7c043d2016-01-27 15:09:12 -08006170 case RIL_RESPONSE_ACKNOWLEDGEMENT: return "RIL_RESPONSE_ACKNOWLEDGEMENT";
Christopher N. Hesse65084862017-02-07 22:21:27 +01006171 case RIL_UNSOL_PCO_DATA: return "RIL_UNSOL_PCO_DATA";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02006172 default: return "<unknown request>";
6173 }
6174}
6175
Howard Sue32dbfd2015-01-07 15:55:57 +08006176const char *
6177rilSocketIdToString(RIL_SOCKET_ID socket_id)
6178{
6179 switch(socket_id) {
6180 case RIL_SOCKET_1:
6181 return "RIL_SOCKET_1";
6182#if (SIM_COUNT >= 2)
6183 case RIL_SOCKET_2:
6184 return "RIL_SOCKET_2";
6185#endif
6186#if (SIM_COUNT >= 3)
6187 case RIL_SOCKET_3:
6188 return "RIL_SOCKET_3";
6189#endif
6190#if (SIM_COUNT >= 4)
6191 case RIL_SOCKET_4:
6192 return "RIL_SOCKET_4";
6193#endif
6194 default:
6195 return "not a valid RIL";
6196 }
6197}
6198
Sanket Padawe9343e872016-01-11 12:45:43 -08006199/*
6200 * Returns true for a debuggable build.
6201 */
6202static bool isDebuggable() {
6203 char debuggable[PROP_VALUE_MAX];
6204 property_get("ro.debuggable", debuggable, "0");
6205 if (strcmp(debuggable, "1") == 0) {
6206 return true;
6207 }
6208 return false;
6209}
6210
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02006211} /* namespace android */
Dheeraj Shettycc231012014-07-02 21:27:57 +02006212
6213void rilEventAddWakeup_helper(struct ril_event *ev) {
6214 android::rilEventAddWakeup(ev);
6215}
6216
6217void listenCallback_helper(int fd, short flags, void *param) {
6218 android::listenCallback(fd, flags, param);
6219}
6220
6221int blockingWrite_helper(int fd, void *buffer, size_t len) {
6222 return android::blockingWrite(fd, buffer, len);
6223}