blob: 96ca84c4ba304736cf791b92439e43129532b4e7 [file] [log] [blame]
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001/* //device/libs/telephony/ril.cpp
2**
3** Copyright 2006, The Android Open Source Project
4**
Wink Saville7f856802009-06-09 10:23:37 -07005** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08008**
Wink Saville7f856802009-06-09 10:23:37 -07009** http://www.apache.org/licenses/LICENSE-2.0
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080010**
Wink Saville7f856802009-06-09 10:23:37 -070011** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080015** limitations under the License.
16*/
17
18#define LOG_TAG "RILC"
19
20#include <hardware_legacy/power.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080021#include <telephony/ril.h>
Wink Savillef4c4d362009-04-02 01:37:03 -070022#include <telephony/ril_cdma_sms.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080023#include <cutils/sockets.h>
24#include <cutils/jstring.h>
Dima Zavin622bf2b2013-05-22 11:29:34 -070025#include <telephony/record_stream.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080026#include <utils/Log.h>
27#include <utils/SystemClock.h>
28#include <pthread.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080029#include <cutils/jstring.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080030#include <sys/types.h>
Wink Saville18e4ab12013-04-07 17:31:04 -070031#include <sys/limits.h>
Sanket Padawe4c05f352016-01-26 16:19:00 -080032#include <sys/system_properties.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080033#include <pwd.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080034#include <stdio.h>
35#include <stdlib.h>
36#include <stdarg.h>
37#include <string.h>
38#include <unistd.h>
39#include <fcntl.h>
40#include <time.h>
41#include <errno.h>
42#include <assert.h>
43#include <ctype.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080044#include <sys/un.h>
45#include <assert.h>
46#include <netinet/in.h>
47#include <cutils/properties.h>
Dheeraj Shetty27976c42014-07-02 21:27:57 +020048#include <RilSapSocket.h>
Amit Mahajan18fe36b2016-08-25 11:19:21 -070049#include <ril_service.h>
Amit Mahajanc2c71852016-11-29 16:48:54 -080050#include <sap_service.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080051
Dheeraj Shetty27976c42014-07-02 21:27:57 +020052extern "C" void
53RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen);
Sanket Padawe6ff9a872016-01-27 15:09:12 -080054
55extern "C" void
56RIL_onRequestAck(RIL_Token t);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080057namespace android {
58
59#define PHONE_PROCESS "radio"
Dheeraj Shetty27976c42014-07-02 21:27:57 +020060#define BLUETOOTH_PROCESS "bluetooth"
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080061
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080062#define SOCKET_NAME_RIL_DEBUG "rild-debug"
63
64#define ANDROID_WAKE_LOCK_NAME "radio-interface"
65
Nathan Harolda0153392015-07-28 14:54:58 -070066#define ANDROID_WAKE_LOCK_SECS 0
67#define ANDROID_WAKE_LOCK_USECS 200000
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080068
69#define PROPERTY_RIL_IMPL "gsm.version.ril-impl"
70
71// match with constant in RIL.java
72#define MAX_COMMAND_BYTES (8 * 1024)
73
74// Basically: memset buffers that the client library
75// shouldn't be using anymore in an attempt to find
76// memory usage issues sooner.
77#define MEMSET_FREED 1
78
79#define NUM_ELEMS(a) (sizeof (a) / sizeof (a)[0])
80
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080081/* Negative values for private RIL errno's */
Chih-Hung Hsieh434554c2016-05-12 10:01:16 -070082#define RIL_ERRNO_INVALID_RESPONSE (-1)
Robert Greenwalt78e2c9c2016-05-16 12:36:42 -070083#define RIL_ERRNO_NO_MEMORY (-12)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080084
85// request, response, and unsolicited msg print macro
86#define PRINTBUF_SIZE 8096
87
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080088enum WakeType {DONT_WAKE, WAKE_PARTIAL};
89
90typedef struct {
91 int requestNumber;
Amit Mahajan18fe36b2016-08-25 11:19:21 -070092 int (*responseFunction) (Parcel &p, int slotId, int requestNumber, int responseType, int token,
93 RIL_Errno e, void *response, size_t responselen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080094 WakeType wakeType;
95} UnsolResponseInfo;
96
Wink Saville3d54e742009-05-18 18:00:44 -070097typedef struct UserCallbackInfo {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080098 RIL_TimedCallback p_callback;
99 void *userParam;
100 struct ril_event event;
101 struct UserCallbackInfo *p_next;
102} UserCallbackInfo;
103
Etan Cohend3652192014-06-20 08:28:44 -0700104extern "C" const char * failCauseToString(RIL_Errno);
105extern "C" const char * callStateToString(RIL_CallState);
106extern "C" const char * radioStateToString(RIL_RadioState);
107extern "C" const char * rilSocketIdToString(RIL_SOCKET_ID socket_id);
108
109extern "C"
110char rild[MAX_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800111/*******************************************************************/
112
113RIL_RadioFunctions s_callbacks = {0, NULL, NULL, NULL, NULL, NULL};
114static int s_registerCalled = 0;
115
116static pthread_t s_tid_dispatch;
117static pthread_t s_tid_reader;
118static int s_started = 0;
119
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800120static int s_fdDebug = -1;
Etan Cohend3652192014-06-20 08:28:44 -0700121static int s_fdDebug_socket2 = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800122
123static int s_fdWakeupRead;
124static int s_fdWakeupWrite;
125
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800126int s_wakelock_count = 0;
127
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800128static struct ril_event s_commands_event;
129static struct ril_event s_wakeupfd_event;
130static struct ril_event s_listen_event;
Etan Cohend3652192014-06-20 08:28:44 -0700131static SocketListenParam s_ril_param_socket;
132
133static pthread_mutex_t s_pendingRequestsMutex = PTHREAD_MUTEX_INITIALIZER;
134static pthread_mutex_t s_writeMutex = PTHREAD_MUTEX_INITIALIZER;
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800135static pthread_mutex_t s_wakeLockCountMutex = PTHREAD_MUTEX_INITIALIZER;
Etan Cohend3652192014-06-20 08:28:44 -0700136static RequestInfo *s_pendingRequests = NULL;
137
138#if (SIM_COUNT >= 2)
139static struct ril_event s_commands_event_socket2;
140static struct ril_event s_listen_event_socket2;
141static SocketListenParam s_ril_param_socket2;
142
143static pthread_mutex_t s_pendingRequestsMutex_socket2 = PTHREAD_MUTEX_INITIALIZER;
144static pthread_mutex_t s_writeMutex_socket2 = PTHREAD_MUTEX_INITIALIZER;
145static RequestInfo *s_pendingRequests_socket2 = NULL;
146#endif
147
148#if (SIM_COUNT >= 3)
149static struct ril_event s_commands_event_socket3;
150static struct ril_event s_listen_event_socket3;
151static SocketListenParam s_ril_param_socket3;
152
153static pthread_mutex_t s_pendingRequestsMutex_socket3 = PTHREAD_MUTEX_INITIALIZER;
154static pthread_mutex_t s_writeMutex_socket3 = PTHREAD_MUTEX_INITIALIZER;
155static RequestInfo *s_pendingRequests_socket3 = NULL;
156#endif
157
158#if (SIM_COUNT >= 4)
159static struct ril_event s_commands_event_socket4;
160static struct ril_event s_listen_event_socket4;
161static SocketListenParam s_ril_param_socket4;
162
163static pthread_mutex_t s_pendingRequestsMutex_socket4 = PTHREAD_MUTEX_INITIALIZER;
164static pthread_mutex_t s_writeMutex_socket4 = PTHREAD_MUTEX_INITIALIZER;
165static RequestInfo *s_pendingRequests_socket4 = NULL;
166#endif
167
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800168static struct ril_event s_wake_timeout_event;
169static struct ril_event s_debug_event;
170
171
Nathan Harolda0153392015-07-28 14:54:58 -0700172static const struct timeval TIMEVAL_WAKE_TIMEOUT = {ANDROID_WAKE_LOCK_SECS,ANDROID_WAKE_LOCK_USECS};
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800173
Etan Cohend3652192014-06-20 08:28:44 -0700174
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800175static pthread_mutex_t s_startupMutex = PTHREAD_MUTEX_INITIALIZER;
176static pthread_cond_t s_startupCond = PTHREAD_COND_INITIALIZER;
177
178static pthread_mutex_t s_dispatchMutex = PTHREAD_MUTEX_INITIALIZER;
179static pthread_cond_t s_dispatchCond = PTHREAD_COND_INITIALIZER;
180
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800181static RequestInfo *s_toDispatchHead = NULL;
182static RequestInfo *s_toDispatchTail = NULL;
183
184static UserCallbackInfo *s_last_wake_timeout_info = NULL;
185
186static void *s_lastNITZTimeData = NULL;
187static size_t s_lastNITZTimeDataSize;
188
189#if RILC_LOG
190 static char printBuf[PRINTBUF_SIZE];
191#endif
192
193/*******************************************************************/
Etan Cohend3652192014-06-20 08:28:44 -0700194static int sendResponse (Parcel &p, RIL_SOCKET_ID socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800195
196static void dispatchVoid (Parcel& p, RequestInfo *pRI);
197static void dispatchString (Parcel& p, RequestInfo *pRI);
198static void dispatchStrings (Parcel& p, RequestInfo *pRI);
199static void dispatchInts (Parcel& p, RequestInfo *pRI);
200static void dispatchDial (Parcel& p, RequestInfo *pRI);
201static void dispatchSIM_IO (Parcel& p, RequestInfo *pRI);
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800202static void dispatchSIM_APDU (Parcel& p, RequestInfo *pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800203static void dispatchCallForward(Parcel& p, RequestInfo *pRI);
204static void dispatchRaw(Parcel& p, RequestInfo *pRI);
205static void dispatchSmsWrite (Parcel &p, RequestInfo *pRI);
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -0700206static void dispatchDataCall (Parcel& p, RequestInfo *pRI);
Sungmin Choi75697532013-04-26 15:04:45 -0700207static void dispatchSetInitialAttachApn (Parcel& p, RequestInfo *pRI);
Wink Savillef4c4d362009-04-02 01:37:03 -0700208static void dispatchCdmaSms(Parcel &p, RequestInfo *pRI);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -0700209static void dispatchImsSms(Parcel &p, RequestInfo *pRI);
210static void dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
211static void dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
Wink Savillef4c4d362009-04-02 01:37:03 -0700212static void dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI);
Wink Savillea592eeb2009-05-22 13:26:36 -0700213static void dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI);
Wink Savillef4c4d362009-04-02 01:37:03 -0700214static void dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI);
215static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI);
Jake Hamby8a4a2332014-01-15 13:12:05 -0800216static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI);
217static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI);
Etan Cohend3652192014-06-20 08:28:44 -0700218static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI);
Amit Mahajan90530a62014-07-01 15:54:08 -0700219static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI);
Amit Mahajanc796e222014-08-13 16:54:01 +0000220static void dispatchDataProfile(Parcel &p, RequestInfo *pRI);
Wink Saville8b4e4f72014-10-17 15:01:45 -0700221static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI);
Meng Wangb4e34312016-05-12 14:54:36 -0700222static void dispatchCarrierRestrictions(Parcel &p, RequestInfo *pRI);
Amit Mahajan18fe36b2016-08-25 11:19:21 -0700223static int responseInts(Parcel &p, int slotId, int requestNumber, int responseType, int token,
224 RIL_Errno e, void *response, size_t responselen);
225static int responseFailCause(Parcel &p, int slotId, int requestNumber, int responseType, int token,
226 RIL_Errno e, void *response, size_t responselen);
227static int responseStrings(Parcel &p, int slotId, int requestNumber, int responseType, int token,
228 RIL_Errno e, void *response, size_t responselen);
229static int responseString(Parcel &p, int slotId, int requestNumber, int responseType, int token,
230 RIL_Errno e, void *response, size_t responselen);
231static int responseVoid(Parcel &p, int slotId, int requestNumber, int responseType, int token,
232 RIL_Errno e, void *response, size_t responselen);
233static int responseCallList(Parcel &p, int slotId, int requestNumber, int responseType, int token,
234 RIL_Errno e, void *response, size_t responselen);
235static int responseSMS(Parcel &p, int slotId, int requestNumber, int responseType, int token,
236 RIL_Errno e, void *response, size_t responselen);
237static int responseSIM_IO(Parcel &p, int slotId, int requestNumber, int responseType, int token,
238 RIL_Errno e, void *response, size_t responselen);
239static int responseCallForwards(Parcel &p, int slotId, int requestNumber, int responseType,
240 int token, RIL_Errno e, void *response, size_t responselen);
241static int responseDataCallList(Parcel &p, int slotId, int requestNumber, int responseType,
242 int token, RIL_Errno e, void *response, size_t responselen);
243static int responseSetupDataCall(Parcel &p, int slotId, int requestNumber, int responseType,
244 int token, RIL_Errno e, void *response, size_t responselen);
245static int responseRaw(Parcel &p, int slotId, int requestNumber, int responseType, int token,
246 RIL_Errno e, void *response, size_t responselen);
247static int responseSsn(Parcel &p, int slotId, int requestNumber, int responseType, int token,
248 RIL_Errno e, void *response, size_t responselen);
249static int responseGsmBrSmsCnf(Parcel &p, int slotId, int requestNumber, int responseType,
250 int token, RIL_Errno e, void *response, size_t responselen);
251static int responseCdmaBrSmsCnf(Parcel &p, int slotId, int requestNumber, int responseType,
252 int token, RIL_Errno e, void *response, size_t responselen);
253static int responseCdmaSms(Parcel &p, int slotId, int requestNumber, int responseType, int token,
254 RIL_Errno e, void *response, size_t responselen);
255static int responseCellList(Parcel &p, int slotId, int requestNumber, int responseType, int token,
256 RIL_Errno e, void *response, size_t responselen);
257static int responseCdmaInformationRecords(Parcel &p, int slotId, int requestNumber,
258 int responseType, int token, RIL_Errno e,void *response, size_t responselen);
259static int responseRilSignalStrength(Parcel &p, int slotId, int requestNumber, int responseType,
260 int token, RIL_Errno e,void *response, size_t responselen);
261static int responseCallRing(Parcel &p, int slotId, int requestNumber, int responseType, int token,
262 RIL_Errno e, void *response, size_t responselen);
263static int responseCdmaSignalInfoRecord(Parcel &p, int slotId, int requestNumber, int responseType,
264 int token, RIL_Errno e,void *response, size_t responselen);
265static int responseCdmaCallWaiting(Parcel &p, int slotId, int requestNumber, int responseType,
266 int token, RIL_Errno e,void *response, size_t responselen);
267static int responseSimRefresh(Parcel &p, int slotId, int requestNumber, int responseType, int token,
268 RIL_Errno e, void *response, size_t responselen);
269static int responseCellInfoList(Parcel &p, int slotId, int requestNumber, int responseType,
270 int token, RIL_Errno e, void *response, size_t responselen);
271static int responseHardwareConfig(Parcel &p, int slotId, int requestNumber, int responseType,
272 int token, RIL_Errno e, void *response, size_t responselen);
273static int responseDcRtInfo(Parcel &p, int slotId, int requestNumber, int responseType, int token,
274 RIL_Errno e, void *response, size_t responselen);
275static int responseRadioCapability(Parcel &p, int slotId, int requestNumber, int responseType,
276 int token, RIL_Errno e, void *response, size_t responselen);
277static int responseSSData(Parcel &p, int slotId, int requestNumber, int responseType, int token,
278 RIL_Errno e, void *response, size_t responselen);
279static int responseLceStatus(Parcel &p, int slotId, int requestNumber, int responseType, int token,
280 RIL_Errno e, void *response, size_t responselen);
281static int responseLceData(Parcel &p, int slotId, int requestNumber, int responseType, int token,
282 RIL_Errno e, void *response, size_t responselen);
283static int responseActivityData(Parcel &p, int slotId, int requestNumber, int responseType,
284 int token, RIL_Errno e, void *response, size_t responselen);
285static int responseCarrierRestrictions(Parcel &p, int slotId, int requestNumber, int responseType,
286 int token, RIL_Errno e, void *response, size_t responselen);
287static int responsePcoData(Parcel &p, int slotId, int requestNumber, int responseType, int token,
288 RIL_Errno e, void *response, size_t responselen);
Amit Mahajan54563d32014-11-22 00:54:49 +0000289
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800290static void grabPartialWakeLock();
Sanket Padawe85f952a2017-01-02 23:46:00 -0800291void releaseWakeLock();
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800292static void wakeTimeoutCallback(void *);
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800293
Sanket Padawe4c05f352016-01-26 16:19:00 -0800294static bool isDebuggable();
295
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800296#ifdef RIL_SHLIB
Etan Cohend3652192014-06-20 08:28:44 -0700297#if defined(ANDROID_MULTI_SIM)
Vinit Deshpande1b1ec2d2015-04-15 13:31:05 -0700298extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Etan Cohend3652192014-06-20 08:28:44 -0700299 size_t datalen, RIL_SOCKET_ID socket_id);
300#else
Vinit Deshpande1b1ec2d2015-04-15 13:31:05 -0700301extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800302 size_t datalen);
303#endif
Etan Cohend3652192014-06-20 08:28:44 -0700304#endif
305
306#if defined(ANDROID_MULTI_SIM)
307#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c), (d))
308#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d), (e))
309#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest(a)
310#else
311#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c))
312#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d))
313#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest()
314#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800315
Wink Saville7f856802009-06-09 10:23:37 -0700316static UserCallbackInfo * internalRequestTimedCallback
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -0700317 (RIL_TimedCallback callback, void *param,
318 const struct timeval *relativeTime);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800319
320/** Index == requestNumber */
321static CommandInfo s_commands[] = {
322#include "ril_commands.h"
323};
324
325static UnsolResponseInfo s_unsolResponses[] = {
326#include "ril_unsol_commands.h"
327};
328
Amit Mahajan18fe36b2016-08-25 11:19:21 -0700329char * RIL_getRilSocketName() {
Etan Cohend3652192014-06-20 08:28:44 -0700330 return rild;
331}
332
333extern "C"
Dheeraj Shetty27976c42014-07-02 21:27:57 +0200334void RIL_setRilSocketName(const char * s) {
Etan Cohend3652192014-06-20 08:28:44 -0700335 strncpy(rild, s, MAX_SOCKET_NAME_LENGTH);
336}
337
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800338static char *
Wink Savillef4c4d362009-04-02 01:37:03 -0700339strdupReadString(Parcel &p) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800340 size_t stringlen;
341 const char16_t *s16;
Wink Saville7f856802009-06-09 10:23:37 -0700342
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800343 s16 = p.readString16Inplace(&stringlen);
Wink Saville7f856802009-06-09 10:23:37 -0700344
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800345 return strndup16to8(s16, stringlen);
346}
347
Wink Saville8b4e4f72014-10-17 15:01:45 -0700348static status_t
349readStringFromParcelInplace(Parcel &p, char *str, size_t maxLen) {
350 size_t s16Len;
351 const char16_t *s16;
352
353 s16 = p.readString16Inplace(&s16Len);
354 if (s16 == NULL) {
355 return NO_MEMORY;
356 }
357 size_t strLen = strnlen16to8(s16, s16Len);
358 if ((strLen + 1) > maxLen) {
359 return NO_MEMORY;
360 }
361 if (strncpy16to8(str, s16, strLen) == NULL) {
362 return NO_MEMORY;
363 } else {
364 return NO_ERROR;
365 }
366}
367
Wink Savillef4c4d362009-04-02 01:37:03 -0700368static void writeStringToParcel(Parcel &p, const char *s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800369 char16_t *s16;
370 size_t s16_len;
371 s16 = strdup8to16(s, &s16_len);
372 p.writeString16(s16, s16_len);
373 free(s16);
374}
375
376
377static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700378memsetString (char *s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800379 if (s != NULL) {
380 memset (s, 0, strlen(s));
381 }
382}
383
384void nullParcelReleaseFunction (const uint8_t* data, size_t dataSize,
385 const size_t* objects, size_t objectsSize,
Wink Savillef4c4d362009-04-02 01:37:03 -0700386 void* cookie) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800387 // do nothing -- the data reference lives longer than the Parcel object
388}
389
Wink Saville7f856802009-06-09 10:23:37 -0700390/**
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800391 * To be called from dispatch thread
392 * Issue a single local request, ensuring that the response
Wink Saville7f856802009-06-09 10:23:37 -0700393 * is not sent back up to the command process
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800394 */
395static void
Etan Cohend3652192014-06-20 08:28:44 -0700396issueLocalRequest(int request, void *data, int len, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800397 RequestInfo *pRI;
398 int ret;
Etan Cohend3652192014-06-20 08:28:44 -0700399 /* Hook for current context */
400 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
401 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
402 /* pendingRequestsHook refer to &s_pendingRequests */
403 RequestInfo** pendingRequestsHook = &s_pendingRequests;
404
405#if (SIM_COUNT == 2)
406 if (socket_id == RIL_SOCKET_2) {
407 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
408 pendingRequestsHook = &s_pendingRequests_socket2;
409 }
410#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800411
412 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
Sanket Padawe55227b52016-02-29 10:09:26 -0800413 if (pRI == NULL) {
414 RLOGE("Memory allocation failed for request %s", requestToString(request));
415 return;
416 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800417
418 pRI->local = 1;
419 pRI->token = 0xffffffff; // token is not used in this context
420 pRI->pCI = &(s_commands[request]);
Etan Cohend3652192014-06-20 08:28:44 -0700421 pRI->socket_id = socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800422
Etan Cohend3652192014-06-20 08:28:44 -0700423 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800424 assert (ret == 0);
425
Etan Cohend3652192014-06-20 08:28:44 -0700426 pRI->p_next = *pendingRequestsHook;
427 *pendingRequestsHook = pRI;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800428
Etan Cohend3652192014-06-20 08:28:44 -0700429 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800430 assert (ret == 0);
431
Wink Saville8eb2a122012-11-19 16:05:13 -0800432 RLOGD("C[locl]> %s", requestToString(request));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800433
Etan Cohend3652192014-06-20 08:28:44 -0700434 CALL_ONREQUEST(request, data, len, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800435}
436
437
438
439static int
Etan Cohend3652192014-06-20 08:28:44 -0700440processCommandBuffer(void *buffer, size_t buflen, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800441 Parcel p;
442 status_t status;
443 int32_t request;
444 int32_t token;
445 RequestInfo *pRI;
446 int ret;
Etan Cohend3652192014-06-20 08:28:44 -0700447 /* Hook for current context */
448 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
449 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
450 /* pendingRequestsHook refer to &s_pendingRequests */
451 RequestInfo** pendingRequestsHook = &s_pendingRequests;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800452
453 p.setData((uint8_t *) buffer, buflen);
454
455 // status checked at end
456 status = p.readInt32(&request);
457 status = p.readInt32 (&token);
458
Etan Cohend3652192014-06-20 08:28:44 -0700459#if (SIM_COUNT >= 2)
460 if (socket_id == RIL_SOCKET_2) {
461 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
462 pendingRequestsHook = &s_pendingRequests_socket2;
463 }
464#if (SIM_COUNT >= 3)
465 else if (socket_id == RIL_SOCKET_3) {
466 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
467 pendingRequestsHook = &s_pendingRequests_socket3;
468 }
469#endif
470#if (SIM_COUNT >= 4)
471 else if (socket_id == RIL_SOCKET_4) {
472 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
473 pendingRequestsHook = &s_pendingRequests_socket4;
474 }
475#endif
476#endif
477
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800478 if (status != NO_ERROR) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800479 RLOGE("invalid request block");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800480 return 0;
481 }
482
Sooraj Sasindran405313f2016-05-06 16:19:56 -0700483 // Received an Ack for the previous result sent to RIL.java,
484 // so release wakelock and exit
485 if (request == RIL_RESPONSE_ACKNOWLEDGEMENT) {
486 releaseWakeLock();
487 return 0;
488 }
489
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800490 if (request < 1 || request >= (int32_t)NUM_ELEMS(s_commands)) {
Etan Cohend3652192014-06-20 08:28:44 -0700491 Parcel pErr;
Wink Saville8eb2a122012-11-19 16:05:13 -0800492 RLOGE("unsupported request code %d token %d", request, token);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800493 // FIXME this should perhaps return a response
Etan Cohend3652192014-06-20 08:28:44 -0700494 pErr.writeInt32 (RESPONSE_SOLICITED);
495 pErr.writeInt32 (token);
496 pErr.writeInt32 (RIL_E_GENERIC_FAILURE);
497
498 sendResponse(pErr, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800499 return 0;
500 }
501
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800502 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
Sanket Padawe55227b52016-02-29 10:09:26 -0800503 if (pRI == NULL) {
504 RLOGE("Memory allocation failed for request %s", requestToString(request));
505 return 0;
506 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800507
508 pRI->token = token;
509 pRI->pCI = &(s_commands[request]);
Etan Cohend3652192014-06-20 08:28:44 -0700510 pRI->socket_id = socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800511
Etan Cohend3652192014-06-20 08:28:44 -0700512 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800513 assert (ret == 0);
514
Etan Cohend3652192014-06-20 08:28:44 -0700515 pRI->p_next = *pendingRequestsHook;
516 *pendingRequestsHook = pRI;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800517
Etan Cohend3652192014-06-20 08:28:44 -0700518 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800519 assert (ret == 0);
520
Wink Saville7f856802009-06-09 10:23:37 -0700521 pRI->pCI->dispatchFunction(p, pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800522
523 return 0;
524}
525
Sanket Padawe85f952a2017-01-02 23:46:00 -0800526RequestInfo *
527addRequestToList(int serial, int slotId, int request) {
528 RequestInfo *pRI;
Amit Mahajan18fe36b2016-08-25 11:19:21 -0700529 int ret;
Sanket Padawe85f952a2017-01-02 23:46:00 -0800530 RIL_SOCKET_ID socket_id = (RIL_SOCKET_ID) slotId;
Amit Mahajan18fe36b2016-08-25 11:19:21 -0700531 /* Hook for current context */
532 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
533 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
534 /* pendingRequestsHook refer to &s_pendingRequests */
535 RequestInfo** pendingRequestsHook = &s_pendingRequests;
536
537#if (SIM_COUNT >= 2)
538 if (socket_id == RIL_SOCKET_2) {
539 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
540 pendingRequestsHook = &s_pendingRequests_socket2;
541 }
542#if (SIM_COUNT >= 3)
543 else if (socket_id == RIL_SOCKET_3) {
544 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
545 pendingRequestsHook = &s_pendingRequests_socket3;
546 }
547#endif
548#if (SIM_COUNT >= 4)
549 else if (socket_id == RIL_SOCKET_4) {
550 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
551 pendingRequestsHook = &s_pendingRequests_socket4;
552 }
553#endif
554#endif
555
Sanket Padawe85f952a2017-01-02 23:46:00 -0800556 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
557 if (pRI == NULL) {
558 RLOGE("Memory allocation failed for request %s", requestToString(request));
559 return NULL;
Amit Mahajan18fe36b2016-08-25 11:19:21 -0700560 }
561
Sanket Padawe85f952a2017-01-02 23:46:00 -0800562 pRI->token = serial;
563 pRI->pCI = &(s_commands[request]);
564 pRI->socket_id = socket_id;
565
Amit Mahajan18fe36b2016-08-25 11:19:21 -0700566 ret = pthread_mutex_lock(pendingRequestsMutexHook);
567 assert (ret == 0);
568
569 pRI->p_next = *pendingRequestsHook;
570 *pendingRequestsHook = pRI;
571
572 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
573 assert (ret == 0);
574
Sanket Padawe85f952a2017-01-02 23:46:00 -0800575 return pRI;
Amit Mahajan18fe36b2016-08-25 11:19:21 -0700576}
577
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800578static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700579invalidCommandBlock (RequestInfo *pRI) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800580 RLOGE("invalid command block for token %d request %s",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800581 pRI->token, requestToString(pRI->pCI->requestNumber));
582}
583
584/** Callee expects NULL */
Wink Saville7f856802009-06-09 10:23:37 -0700585static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700586dispatchVoid (Parcel& p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800587 clearPrintBuf;
588 printRequest(pRI->token, pRI->pCI->requestNumber);
Etan Cohend3652192014-06-20 08:28:44 -0700589 CALL_ONREQUEST(pRI->pCI->requestNumber, NULL, 0, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800590}
591
592/** Callee expects const char * */
593static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700594dispatchString (Parcel& p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800595 status_t status;
596 size_t datalen;
597 size_t stringlen;
598 char *string8 = NULL;
599
600 string8 = strdupReadString(p);
601
602 startRequest;
603 appendPrintBuf("%s%s", printBuf, string8);
604 closeRequest;
605 printRequest(pRI->token, pRI->pCI->requestNumber);
606
Etan Cohend3652192014-06-20 08:28:44 -0700607 CALL_ONREQUEST(pRI->pCI->requestNumber, string8,
608 sizeof(char *), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800609
610#ifdef MEMSET_FREED
611 memsetString(string8);
612#endif
613
614 free(string8);
615 return;
616invalid:
617 invalidCommandBlock(pRI);
618 return;
619}
620
621/** Callee expects const char ** */
622static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700623dispatchStrings (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800624 int32_t countStrings;
625 status_t status;
626 size_t datalen;
627 char **pStrings;
628
629 status = p.readInt32 (&countStrings);
630
631 if (status != NO_ERROR) {
632 goto invalid;
633 }
634
635 startRequest;
636 if (countStrings == 0) {
637 // just some non-null pointer
Sanket Padawe0cfc5532016-03-07 17:12:19 -0800638 pStrings = (char **)calloc(1, sizeof(char *));
Sanket Padawe55227b52016-02-29 10:09:26 -0800639 if (pStrings == NULL) {
640 RLOGE("Memory allocation failed for request %s",
641 requestToString(pRI->pCI->requestNumber));
642 closeRequest;
643 return;
644 }
645
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800646 datalen = 0;
Sanket Padawe0cfc5532016-03-07 17:12:19 -0800647 } else if (countStrings < 0) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800648 pStrings = NULL;
649 datalen = 0;
650 } else {
651 datalen = sizeof(char *) * countStrings;
Wink Saville7f856802009-06-09 10:23:37 -0700652
Sanket Padawe0cfc5532016-03-07 17:12:19 -0800653 pStrings = (char **)calloc(countStrings, sizeof(char *));
Sanket Padawe55227b52016-02-29 10:09:26 -0800654 if (pStrings == NULL) {
655 RLOGE("Memory allocation failed for request %s",
656 requestToString(pRI->pCI->requestNumber));
657 closeRequest;
658 return;
659 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800660
661 for (int i = 0 ; i < countStrings ; i++) {
662 pStrings[i] = strdupReadString(p);
663 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
664 }
665 }
666 removeLastChar;
667 closeRequest;
668 printRequest(pRI->token, pRI->pCI->requestNumber);
669
Etan Cohend3652192014-06-20 08:28:44 -0700670 CALL_ONREQUEST(pRI->pCI->requestNumber, pStrings, datalen, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800671
672 if (pStrings != NULL) {
673 for (int i = 0 ; i < countStrings ; i++) {
674#ifdef MEMSET_FREED
675 memsetString (pStrings[i]);
676#endif
677 free(pStrings[i]);
678 }
679
680#ifdef MEMSET_FREED
681 memset(pStrings, 0, datalen);
682#endif
Sanket Padawe0cfc5532016-03-07 17:12:19 -0800683 free(pStrings);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800684 }
Wink Saville7f856802009-06-09 10:23:37 -0700685
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800686 return;
687invalid:
688 invalidCommandBlock(pRI);
689 return;
690}
691
692/** Callee expects const int * */
693static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700694dispatchInts (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800695 int32_t count;
696 status_t status;
697 size_t datalen;
698 int *pInts;
699
700 status = p.readInt32 (&count);
701
Sanket Padawe0cfc5532016-03-07 17:12:19 -0800702 if (status != NO_ERROR || count <= 0) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800703 goto invalid;
704 }
705
706 datalen = sizeof(int) * count;
Sanket Padawe0cfc5532016-03-07 17:12:19 -0800707 pInts = (int *)calloc(count, sizeof(int));
Sanket Padawe55227b52016-02-29 10:09:26 -0800708 if (pInts == NULL) {
709 RLOGE("Memory allocation failed for request %s", requestToString(pRI->pCI->requestNumber));
710 return;
711 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800712
713 startRequest;
714 for (int i = 0 ; i < count ; i++) {
715 int32_t t;
716
717 status = p.readInt32(&t);
718 pInts[i] = (int)t;
719 appendPrintBuf("%s%d,", printBuf, t);
720
721 if (status != NO_ERROR) {
Sanket Padawe0cfc5532016-03-07 17:12:19 -0800722 free(pInts);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800723 goto invalid;
724 }
725 }
726 removeLastChar;
727 closeRequest;
728 printRequest(pRI->token, pRI->pCI->requestNumber);
729
Etan Cohend3652192014-06-20 08:28:44 -0700730 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<int *>(pInts),
731 datalen, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800732
733#ifdef MEMSET_FREED
734 memset(pInts, 0, datalen);
735#endif
Sanket Padawe0cfc5532016-03-07 17:12:19 -0800736 free(pInts);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800737 return;
738invalid:
739 invalidCommandBlock(pRI);
740 return;
741}
742
743
Wink Saville7f856802009-06-09 10:23:37 -0700744/**
745 * Callee expects const RIL_SMS_WriteArgs *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800746 * Payload is:
747 * int32_t status
748 * String pdu
749 */
750static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700751dispatchSmsWrite (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800752 RIL_SMS_WriteArgs args;
753 int32_t t;
754 status_t status;
755
Mark Salyzyndba25612015-04-09 07:18:35 -0700756 RLOGD("dispatchSmsWrite");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800757 memset (&args, 0, sizeof(args));
758
759 status = p.readInt32(&t);
760 args.status = (int)t;
761
762 args.pdu = strdupReadString(p);
763
764 if (status != NO_ERROR || args.pdu == NULL) {
765 goto invalid;
766 }
767
768 args.smsc = strdupReadString(p);
769
770 startRequest;
771 appendPrintBuf("%s%d,%s,smsc=%s", printBuf, args.status,
772 (char*)args.pdu, (char*)args.smsc);
773 closeRequest;
774 printRequest(pRI->token, pRI->pCI->requestNumber);
Wink Saville7f856802009-06-09 10:23:37 -0700775
Etan Cohend3652192014-06-20 08:28:44 -0700776 CALL_ONREQUEST(pRI->pCI->requestNumber, &args, sizeof(args), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800777
778#ifdef MEMSET_FREED
779 memsetString (args.pdu);
780#endif
781
782 free (args.pdu);
Wink Saville7f856802009-06-09 10:23:37 -0700783
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800784#ifdef MEMSET_FREED
785 memset(&args, 0, sizeof(args));
786#endif
787
788 return;
789invalid:
790 invalidCommandBlock(pRI);
791 return;
792}
793
Wink Saville7f856802009-06-09 10:23:37 -0700794/**
795 * Callee expects const RIL_Dial *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800796 * Payload is:
797 * String address
798 * int32_t clir
799 */
800static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700801dispatchDial (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800802 RIL_Dial dial;
Wink Saville74fa3882009-12-22 15:35:41 -0800803 RIL_UUS_Info uusInfo;
Wink Saville7bce0822010-01-08 15:20:12 -0800804 int32_t sizeOfDial;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800805 int32_t t;
Wink Saville74fa3882009-12-22 15:35:41 -0800806 int32_t uusPresent;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800807 status_t status;
808
Mark Salyzyndba25612015-04-09 07:18:35 -0700809 RLOGD("dispatchDial");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800810 memset (&dial, 0, sizeof(dial));
811
812 dial.address = strdupReadString(p);
813
814 status = p.readInt32(&t);
815 dial.clir = (int)t;
816
817 if (status != NO_ERROR || dial.address == NULL) {
818 goto invalid;
819 }
820
Wink Saville3a4840b2010-04-07 13:29:58 -0700821 if (s_callbacks.version < 3) { // Remove when partners upgrade to version 3
Wink Saville74fa3882009-12-22 15:35:41 -0800822 uusPresent = 0;
Wink Saville7bce0822010-01-08 15:20:12 -0800823 sizeOfDial = sizeof(dial) - sizeof(RIL_UUS_Info *);
Wink Saville74fa3882009-12-22 15:35:41 -0800824 } else {
825 status = p.readInt32(&uusPresent);
826
827 if (status != NO_ERROR) {
828 goto invalid;
829 }
830
831 if (uusPresent == 0) {
832 dial.uusInfo = NULL;
833 } else {
834 int32_t len;
835
836 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
837
838 status = p.readInt32(&t);
839 uusInfo.uusType = (RIL_UUS_Type) t;
840
841 status = p.readInt32(&t);
842 uusInfo.uusDcs = (RIL_UUS_DCS) t;
843
844 status = p.readInt32(&len);
845 if (status != NO_ERROR) {
846 goto invalid;
847 }
848
849 // The java code writes -1 for null arrays
850 if (((int) len) == -1) {
851 uusInfo.uusData = NULL;
852 len = 0;
853 } else {
854 uusInfo.uusData = (char*) p.readInplace(len);
Sooraj Sasindrane0491222016-09-23 11:20:39 -0700855 // check if the length is invalid
856 if (uusInfo.uusData == NULL) {
857 goto invalid;
858 }
Wink Saville74fa3882009-12-22 15:35:41 -0800859 }
860
861 uusInfo.uusLength = len;
862 dial.uusInfo = &uusInfo;
863 }
Wink Saville7bce0822010-01-08 15:20:12 -0800864 sizeOfDial = sizeof(dial);
Wink Saville74fa3882009-12-22 15:35:41 -0800865 }
866
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800867 startRequest;
868 appendPrintBuf("%snum=%s,clir=%d", printBuf, dial.address, dial.clir);
Wink Saville74fa3882009-12-22 15:35:41 -0800869 if (uusPresent) {
870 appendPrintBuf("%s,uusType=%d,uusDcs=%d,uusLen=%d", printBuf,
871 dial.uusInfo->uusType, dial.uusInfo->uusDcs,
872 dial.uusInfo->uusLength);
873 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800874 closeRequest;
875 printRequest(pRI->token, pRI->pCI->requestNumber);
876
Etan Cohend3652192014-06-20 08:28:44 -0700877 CALL_ONREQUEST(pRI->pCI->requestNumber, &dial, sizeOfDial, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800878
879#ifdef MEMSET_FREED
880 memsetString (dial.address);
881#endif
882
883 free (dial.address);
Wink Saville7f856802009-06-09 10:23:37 -0700884
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800885#ifdef MEMSET_FREED
Wink Saville74fa3882009-12-22 15:35:41 -0800886 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800887 memset(&dial, 0, sizeof(dial));
888#endif
889
890 return;
891invalid:
892 invalidCommandBlock(pRI);
893 return;
894}
895
Wink Saville7f856802009-06-09 10:23:37 -0700896/**
897 * Callee expects const RIL_SIM_IO *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800898 * Payload is:
899 * int32_t command
900 * int32_t fileid
901 * String path
902 * int32_t p1, p2, p3
Wink Saville7f856802009-06-09 10:23:37 -0700903 * String data
904 * String pin2
Wink Savillec0114b32011-02-18 10:14:07 -0800905 * String aidPtr
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800906 */
907static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700908dispatchSIM_IO (Parcel &p, RequestInfo *pRI) {
Wink Savillec0114b32011-02-18 10:14:07 -0800909 union RIL_SIM_IO {
910 RIL_SIM_IO_v6 v6;
911 RIL_SIM_IO_v5 v5;
912 } simIO;
913
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800914 int32_t t;
Wink Savillec0114b32011-02-18 10:14:07 -0800915 int size;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800916 status_t status;
917
Robert Greenwalt191e4dc2015-04-29 16:57:39 -0700918#if VDBG
Mark Salyzyndba25612015-04-09 07:18:35 -0700919 RLOGD("dispatchSIM_IO");
Robert Greenwalt191e4dc2015-04-29 16:57:39 -0700920#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800921 memset (&simIO, 0, sizeof(simIO));
922
Wink Saville7f856802009-06-09 10:23:37 -0700923 // note we only check status at the end
924
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800925 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800926 simIO.v6.command = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800927
928 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800929 simIO.v6.fileid = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800930
Wink Savillec0114b32011-02-18 10:14:07 -0800931 simIO.v6.path = strdupReadString(p);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800932
933 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800934 simIO.v6.p1 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800935
936 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800937 simIO.v6.p2 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800938
939 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800940 simIO.v6.p3 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800941
Wink Savillec0114b32011-02-18 10:14:07 -0800942 simIO.v6.data = strdupReadString(p);
943 simIO.v6.pin2 = strdupReadString(p);
944 simIO.v6.aidPtr = strdupReadString(p);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800945
946 startRequest;
Wink Savillec0114b32011-02-18 10:14:07 -0800947 appendPrintBuf("%scmd=0x%X,efid=0x%X,path=%s,%d,%d,%d,%s,pin2=%s,aid=%s", printBuf,
948 simIO.v6.command, simIO.v6.fileid, (char*)simIO.v6.path,
949 simIO.v6.p1, simIO.v6.p2, simIO.v6.p3,
950 (char*)simIO.v6.data, (char*)simIO.v6.pin2, simIO.v6.aidPtr);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800951 closeRequest;
952 printRequest(pRI->token, pRI->pCI->requestNumber);
Wink Saville7f856802009-06-09 10:23:37 -0700953
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800954 if (status != NO_ERROR) {
955 goto invalid;
956 }
957
Wink Savillec0114b32011-02-18 10:14:07 -0800958 size = (s_callbacks.version < 6) ? sizeof(simIO.v5) : sizeof(simIO.v6);
Etan Cohend3652192014-06-20 08:28:44 -0700959 CALL_ONREQUEST(pRI->pCI->requestNumber, &simIO, size, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800960
961#ifdef MEMSET_FREED
Wink Savillec0114b32011-02-18 10:14:07 -0800962 memsetString (simIO.v6.path);
963 memsetString (simIO.v6.data);
964 memsetString (simIO.v6.pin2);
965 memsetString (simIO.v6.aidPtr);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800966#endif
967
Wink Savillec0114b32011-02-18 10:14:07 -0800968 free (simIO.v6.path);
969 free (simIO.v6.data);
970 free (simIO.v6.pin2);
971 free (simIO.v6.aidPtr);
Wink Saville7f856802009-06-09 10:23:37 -0700972
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800973#ifdef MEMSET_FREED
974 memset(&simIO, 0, sizeof(simIO));
975#endif
976
977 return;
978invalid:
979 invalidCommandBlock(pRI);
980 return;
981}
982
983/**
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800984 * Callee expects const RIL_SIM_APDU *
985 * Payload is:
986 * int32_t sessionid
987 * int32_t cla
988 * int32_t instruction
989 * int32_t p1, p2, p3
990 * String data
991 */
992static void
993dispatchSIM_APDU (Parcel &p, RequestInfo *pRI) {
994 int32_t t;
995 status_t status;
996 RIL_SIM_APDU apdu;
997
Robert Greenwalt191e4dc2015-04-29 16:57:39 -0700998#if VDBG
Mark Salyzyndba25612015-04-09 07:18:35 -0700999 RLOGD("dispatchSIM_APDU");
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07001000#endif
Shishir Agrawal2458d8d2013-11-27 14:53:05 -08001001 memset (&apdu, 0, sizeof(RIL_SIM_APDU));
1002
1003 // Note we only check status at the end. Any single failure leads to
1004 // subsequent reads filing.
1005 status = p.readInt32(&t);
1006 apdu.sessionid = (int)t;
1007
1008 status = p.readInt32(&t);
1009 apdu.cla = (int)t;
1010
1011 status = p.readInt32(&t);
1012 apdu.instruction = (int)t;
1013
1014 status = p.readInt32(&t);
1015 apdu.p1 = (int)t;
1016
1017 status = p.readInt32(&t);
1018 apdu.p2 = (int)t;
1019
1020 status = p.readInt32(&t);
1021 apdu.p3 = (int)t;
1022
1023 apdu.data = strdupReadString(p);
1024
1025 startRequest;
1026 appendPrintBuf("%ssessionid=%d,cla=%d,ins=%d,p1=%d,p2=%d,p3=%d,data=%s",
1027 printBuf, apdu.sessionid, apdu.cla, apdu.instruction, apdu.p1, apdu.p2,
1028 apdu.p3, (char*)apdu.data);
1029 closeRequest;
1030 printRequest(pRI->token, pRI->pCI->requestNumber);
1031
1032 if (status != NO_ERROR) {
1033 goto invalid;
1034 }
1035
Etan Cohend3652192014-06-20 08:28:44 -07001036 CALL_ONREQUEST(pRI->pCI->requestNumber, &apdu, sizeof(RIL_SIM_APDU), pRI, pRI->socket_id);
Shishir Agrawal2458d8d2013-11-27 14:53:05 -08001037
1038#ifdef MEMSET_FREED
1039 memsetString(apdu.data);
1040#endif
1041 free(apdu.data);
1042
1043#ifdef MEMSET_FREED
1044 memset(&apdu, 0, sizeof(RIL_SIM_APDU));
1045#endif
1046
1047 return;
1048invalid:
1049 invalidCommandBlock(pRI);
1050 return;
1051}
1052
1053
1054/**
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001055 * Callee expects const RIL_CallForwardInfo *
1056 * Payload is:
1057 * int32_t status/action
1058 * int32_t reason
1059 * int32_t serviceCode
1060 * int32_t toa
1061 * String number (0 length -> null)
1062 * int32_t timeSeconds
1063 */
Wink Saville7f856802009-06-09 10:23:37 -07001064static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001065dispatchCallForward(Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001066 RIL_CallForwardInfo cff;
1067 int32_t t;
1068 status_t status;
1069
Mark Salyzyndba25612015-04-09 07:18:35 -07001070 RLOGD("dispatchCallForward");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001071 memset (&cff, 0, sizeof(cff));
1072
Wink Saville7f856802009-06-09 10:23:37 -07001073 // note we only check status at the end
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001074
1075 status = p.readInt32(&t);
1076 cff.status = (int)t;
Wink Saville7f856802009-06-09 10:23:37 -07001077
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001078 status = p.readInt32(&t);
1079 cff.reason = (int)t;
1080
1081 status = p.readInt32(&t);
1082 cff.serviceClass = (int)t;
1083
1084 status = p.readInt32(&t);
1085 cff.toa = (int)t;
1086
1087 cff.number = strdupReadString(p);
1088
1089 status = p.readInt32(&t);
1090 cff.timeSeconds = (int)t;
1091
1092 if (status != NO_ERROR) {
1093 goto invalid;
1094 }
1095
1096 // special case: number 0-length fields is null
1097
1098 if (cff.number != NULL && strlen (cff.number) == 0) {
1099 cff.number = NULL;
1100 }
1101
1102 startRequest;
1103 appendPrintBuf("%sstat=%d,reason=%d,serv=%d,toa=%d,%s,tout=%d", printBuf,
1104 cff.status, cff.reason, cff.serviceClass, cff.toa,
1105 (char*)cff.number, cff.timeSeconds);
1106 closeRequest;
1107 printRequest(pRI->token, pRI->pCI->requestNumber);
1108
Etan Cohend3652192014-06-20 08:28:44 -07001109 CALL_ONREQUEST(pRI->pCI->requestNumber, &cff, sizeof(cff), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001110
1111#ifdef MEMSET_FREED
1112 memsetString(cff.number);
1113#endif
1114
1115 free (cff.number);
1116
1117#ifdef MEMSET_FREED
1118 memset(&cff, 0, sizeof(cff));
1119#endif
1120
1121 return;
1122invalid:
1123 invalidCommandBlock(pRI);
1124 return;
1125}
1126
1127
Wink Saville7f856802009-06-09 10:23:37 -07001128static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001129dispatchRaw(Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001130 int32_t len;
1131 status_t status;
1132 const void *data;
1133
1134 status = p.readInt32(&len);
1135
1136 if (status != NO_ERROR) {
1137 goto invalid;
1138 }
1139
1140 // The java code writes -1 for null arrays
1141 if (((int)len) == -1) {
1142 data = NULL;
1143 len = 0;
Wink Saville7f856802009-06-09 10:23:37 -07001144 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001145
1146 data = p.readInplace(len);
1147
1148 startRequest;
1149 appendPrintBuf("%sraw_size=%d", printBuf, len);
1150 closeRequest;
1151 printRequest(pRI->token, pRI->pCI->requestNumber);
1152
Etan Cohend3652192014-06-20 08:28:44 -07001153 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<void *>(data), len, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001154
1155 return;
1156invalid:
1157 invalidCommandBlock(pRI);
1158 return;
1159}
1160
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001161static status_t
1162constructCdmaSms(Parcel &p, RequestInfo *pRI, RIL_CDMA_SMS_Message& rcsm) {
Wink Savillef4c4d362009-04-02 01:37:03 -07001163 int32_t t;
1164 uint8_t ut;
1165 status_t status;
1166 int32_t digitCount;
1167 int digitLimit;
Wink Saville7f856802009-06-09 10:23:37 -07001168
Wink Savillef4c4d362009-04-02 01:37:03 -07001169 memset(&rcsm, 0, sizeof(rcsm));
1170
1171 status = p.readInt32(&t);
1172 rcsm.uTeleserviceID = (int) t;
1173
1174 status = p.read(&ut,sizeof(ut));
1175 rcsm.bIsServicePresent = (uint8_t) ut;
1176
1177 status = p.readInt32(&t);
1178 rcsm.uServicecategory = (int) t;
1179
1180 status = p.readInt32(&t);
1181 rcsm.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1182
1183 status = p.readInt32(&t);
1184 rcsm.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1185
1186 status = p.readInt32(&t);
1187 rcsm.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1188
1189 status = p.readInt32(&t);
1190 rcsm.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1191
1192 status = p.read(&ut,sizeof(ut));
1193 rcsm.sAddress.number_of_digits= (uint8_t) ut;
1194
1195 digitLimit= MIN((rcsm.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
1196 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1197 status = p.read(&ut,sizeof(ut));
1198 rcsm.sAddress.digits[digitCount] = (uint8_t) ut;
1199 }
1200
Wink Saville7f856802009-06-09 10:23:37 -07001201 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001202 rcsm.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1203
Wink Saville7f856802009-06-09 10:23:37 -07001204 status = p.read(&ut,sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001205 rcsm.sSubAddress.odd = (uint8_t) ut;
1206
1207 status = p.read(&ut,sizeof(ut));
1208 rcsm.sSubAddress.number_of_digits = (uint8_t) ut;
1209
1210 digitLimit= MIN((rcsm.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
Wink Saville7f856802009-06-09 10:23:37 -07001211 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1212 status = p.read(&ut,sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001213 rcsm.sSubAddress.digits[digitCount] = (uint8_t) ut;
1214 }
1215
Wink Saville7f856802009-06-09 10:23:37 -07001216 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001217 rcsm.uBearerDataLen = (int) t;
1218
1219 digitLimit= MIN((rcsm.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
Wink Saville7f856802009-06-09 10:23:37 -07001220 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1221 status = p.read(&ut, sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001222 rcsm.aBearerData[digitCount] = (uint8_t) ut;
1223 }
1224
1225 if (status != NO_ERROR) {
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001226 return status;
Wink Savillef4c4d362009-04-02 01:37:03 -07001227 }
1228
1229 startRequest;
1230 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
Wink Saville1b5fd232009-04-22 14:50:00 -07001231 sAddress.digit_mode=%d, sAddress.Number_mode=%d, sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07001232 printBuf, rcsm.uTeleserviceID,rcsm.bIsServicePresent,rcsm.uServicecategory,
Wink Saville1b5fd232009-04-22 14:50:00 -07001233 rcsm.sAddress.digit_mode, rcsm.sAddress.number_mode,rcsm.sAddress.number_type);
Wink Savillef4c4d362009-04-02 01:37:03 -07001234 closeRequest;
Wink Saville7f856802009-06-09 10:23:37 -07001235
Wink Savillef4c4d362009-04-02 01:37:03 -07001236 printRequest(pRI->token, pRI->pCI->requestNumber);
1237
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001238 return status;
1239}
1240
1241static void
1242dispatchCdmaSms(Parcel &p, RequestInfo *pRI) {
1243 RIL_CDMA_SMS_Message rcsm;
1244
Mark Salyzyndba25612015-04-09 07:18:35 -07001245 RLOGD("dispatchCdmaSms");
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001246 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1247 goto invalid;
1248 }
1249
Etan Cohend3652192014-06-20 08:28:44 -07001250 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001251
1252#ifdef MEMSET_FREED
1253 memset(&rcsm, 0, sizeof(rcsm));
1254#endif
1255
1256 return;
1257
1258invalid:
1259 invalidCommandBlock(pRI);
1260 return;
1261}
1262
Wink Saville7f856802009-06-09 10:23:37 -07001263static void
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001264dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1265 RIL_IMS_SMS_Message rism;
1266 RIL_CDMA_SMS_Message rcsm;
1267
Mark Salyzyndba25612015-04-09 07:18:35 -07001268 RLOGD("dispatchImsCdmaSms: retry=%d, messageRef=%d", retry, messageRef);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001269
1270 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1271 goto invalid;
1272 }
1273 memset(&rism, 0, sizeof(rism));
1274 rism.tech = RADIO_TECH_3GPP2;
1275 rism.retry = retry;
1276 rism.messageRef = messageRef;
1277 rism.message.cdmaMessage = &rcsm;
1278
Etan Cohend3652192014-06-20 08:28:44 -07001279 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001280 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Etan Cohend3652192014-06-20 08:28:44 -07001281 +sizeof(rcsm),pRI, pRI->socket_id);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001282
1283#ifdef MEMSET_FREED
1284 memset(&rcsm, 0, sizeof(rcsm));
1285 memset(&rism, 0, sizeof(rism));
1286#endif
1287
1288 return;
1289
1290invalid:
1291 invalidCommandBlock(pRI);
1292 return;
1293}
1294
1295static void
1296dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1297 RIL_IMS_SMS_Message rism;
1298 int32_t countStrings;
1299 status_t status;
1300 size_t datalen;
1301 char **pStrings;
Mark Salyzyndba25612015-04-09 07:18:35 -07001302 RLOGD("dispatchImsGsmSms: retry=%d, messageRef=%d", retry, messageRef);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001303
1304 status = p.readInt32 (&countStrings);
1305
1306 if (status != NO_ERROR) {
1307 goto invalid;
1308 }
1309
1310 memset(&rism, 0, sizeof(rism));
1311 rism.tech = RADIO_TECH_3GPP;
1312 rism.retry = retry;
1313 rism.messageRef = messageRef;
1314
1315 startRequest;
Etan Cohen5d891b72014-02-27 17:25:17 -08001316 appendPrintBuf("%stech=%d, retry=%d, messageRef=%d, ", printBuf,
1317 (int)rism.tech, (int)rism.retry, rism.messageRef);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001318 if (countStrings == 0) {
1319 // just some non-null pointer
Sanket Padawe0cfc5532016-03-07 17:12:19 -08001320 pStrings = (char **)calloc(1, sizeof(char *));
Sanket Padawe55227b52016-02-29 10:09:26 -08001321 if (pStrings == NULL) {
1322 RLOGE("Memory allocation failed for request %s",
1323 requestToString(pRI->pCI->requestNumber));
1324 closeRequest;
1325 return;
1326 }
1327
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001328 datalen = 0;
Sanket Padawe0cfc5532016-03-07 17:12:19 -08001329 } else if (countStrings < 0) {
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001330 pStrings = NULL;
1331 datalen = 0;
1332 } else {
Meng Wangef966a32016-06-20 17:38:18 -07001333 if ((size_t)countStrings > (INT_MAX/sizeof(char *))) {
Sanket Padawe0cfc5532016-03-07 17:12:19 -08001334 RLOGE("Invalid value of countStrings: \n");
1335 closeRequest;
1336 return;
1337 }
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001338 datalen = sizeof(char *) * countStrings;
1339
Sanket Padawe0cfc5532016-03-07 17:12:19 -08001340 pStrings = (char **)calloc(countStrings, sizeof(char *));
Sanket Padawe55227b52016-02-29 10:09:26 -08001341 if (pStrings == NULL) {
1342 RLOGE("Memory allocation failed for request %s",
1343 requestToString(pRI->pCI->requestNumber));
1344 closeRequest;
1345 return;
1346 }
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001347
1348 for (int i = 0 ; i < countStrings ; i++) {
1349 pStrings[i] = strdupReadString(p);
1350 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
1351 }
1352 }
1353 removeLastChar;
1354 closeRequest;
1355 printRequest(pRI->token, pRI->pCI->requestNumber);
1356
1357 rism.message.gsmMessage = pStrings;
Etan Cohend3652192014-06-20 08:28:44 -07001358 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001359 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Etan Cohend3652192014-06-20 08:28:44 -07001360 +datalen, pRI, pRI->socket_id);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001361
1362 if (pStrings != NULL) {
1363 for (int i = 0 ; i < countStrings ; i++) {
1364#ifdef MEMSET_FREED
1365 memsetString (pStrings[i]);
1366#endif
1367 free(pStrings[i]);
1368 }
1369
1370#ifdef MEMSET_FREED
1371 memset(pStrings, 0, datalen);
1372#endif
Sanket Padawe0cfc5532016-03-07 17:12:19 -08001373 free(pStrings);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001374 }
1375
1376#ifdef MEMSET_FREED
1377 memset(&rism, 0, sizeof(rism));
1378#endif
1379 return;
1380invalid:
1381 ALOGE("dispatchImsGsmSms invalid block");
1382 invalidCommandBlock(pRI);
1383 return;
1384}
1385
1386static void
1387dispatchImsSms(Parcel &p, RequestInfo *pRI) {
1388 int32_t t;
1389 status_t status = p.readInt32(&t);
1390 RIL_RadioTechnologyFamily format;
1391 uint8_t retry;
1392 int32_t messageRef;
1393
Mark Salyzyndba25612015-04-09 07:18:35 -07001394 RLOGD("dispatchImsSms");
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001395 if (status != NO_ERROR) {
1396 goto invalid;
1397 }
1398 format = (RIL_RadioTechnologyFamily) t;
1399
1400 // read retry field
1401 status = p.read(&retry,sizeof(retry));
1402 if (status != NO_ERROR) {
1403 goto invalid;
1404 }
1405 // read messageRef field
1406 status = p.read(&messageRef,sizeof(messageRef));
1407 if (status != NO_ERROR) {
1408 goto invalid;
1409 }
1410
1411 if (RADIO_TECH_3GPP == format) {
1412 dispatchImsGsmSms(p, pRI, retry, messageRef);
1413 } else if (RADIO_TECH_3GPP2 == format) {
1414 dispatchImsCdmaSms(p, pRI, retry, messageRef);
1415 } else {
1416 ALOGE("requestImsSendSMS invalid format value =%d", format);
1417 }
1418
1419 return;
1420
1421invalid:
1422 invalidCommandBlock(pRI);
1423 return;
1424}
1425
1426static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001427dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI) {
1428 RIL_CDMA_SMS_Ack rcsa;
1429 int32_t t;
1430 status_t status;
1431 int32_t digitCount;
1432
Mark Salyzyndba25612015-04-09 07:18:35 -07001433 RLOGD("dispatchCdmaSmsAck");
Wink Savillef4c4d362009-04-02 01:37:03 -07001434 memset(&rcsa, 0, sizeof(rcsa));
1435
1436 status = p.readInt32(&t);
1437 rcsa.uErrorClass = (RIL_CDMA_SMS_ErrorClass) t;
1438
1439 status = p.readInt32(&t);
1440 rcsa.uSMSCauseCode = (int) t;
1441
1442 if (status != NO_ERROR) {
1443 goto invalid;
1444 }
1445
1446 startRequest;
Wink Saville1b5fd232009-04-22 14:50:00 -07001447 appendPrintBuf("%suErrorClass=%d, uTLStatus=%d, ",
1448 printBuf, rcsa.uErrorClass, rcsa.uSMSCauseCode);
Wink Savillef4c4d362009-04-02 01:37:03 -07001449 closeRequest;
1450
1451 printRequest(pRI->token, pRI->pCI->requestNumber);
1452
Etan Cohend3652192014-06-20 08:28:44 -07001453 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsa, sizeof(rcsa),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001454
1455#ifdef MEMSET_FREED
1456 memset(&rcsa, 0, sizeof(rcsa));
1457#endif
1458
1459 return;
1460
1461invalid:
1462 invalidCommandBlock(pRI);
1463 return;
1464}
1465
Wink Savillea592eeb2009-05-22 13:26:36 -07001466static void
1467dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1468 int32_t t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001469 status_t status;
Wink Savillea592eeb2009-05-22 13:26:36 -07001470 int32_t num;
Wink Savillef4c4d362009-04-02 01:37:03 -07001471
Wink Savillea592eeb2009-05-22 13:26:36 -07001472 status = p.readInt32(&num);
Wink Savillef4c4d362009-04-02 01:37:03 -07001473 if (status != NO_ERROR) {
1474 goto invalid;
1475 }
1476
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001477 {
1478 RIL_GSM_BroadcastSmsConfigInfo gsmBci[num];
1479 RIL_GSM_BroadcastSmsConfigInfo *gsmBciPtrs[num];
Wink Savillea592eeb2009-05-22 13:26:36 -07001480
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001481 startRequest;
1482 for (int i = 0 ; i < num ; i++ ) {
1483 gsmBciPtrs[i] = &gsmBci[i];
Wink Savillef4c4d362009-04-02 01:37:03 -07001484
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001485 status = p.readInt32(&t);
1486 gsmBci[i].fromServiceId = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001487
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001488 status = p.readInt32(&t);
1489 gsmBci[i].toServiceId = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001490
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001491 status = p.readInt32(&t);
1492 gsmBci[i].fromCodeScheme = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001493
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001494 status = p.readInt32(&t);
1495 gsmBci[i].toCodeScheme = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001496
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001497 status = p.readInt32(&t);
1498 gsmBci[i].selected = (uint8_t) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001499
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001500 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId =%d, \
1501 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]", printBuf, i,
1502 gsmBci[i].fromServiceId, gsmBci[i].toServiceId,
1503 gsmBci[i].fromCodeScheme, gsmBci[i].toCodeScheme,
1504 gsmBci[i].selected);
1505 }
1506 closeRequest;
Wink Savillef4c4d362009-04-02 01:37:03 -07001507
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001508 if (status != NO_ERROR) {
1509 goto invalid;
1510 }
Wink Savillef4c4d362009-04-02 01:37:03 -07001511
Etan Cohend3652192014-06-20 08:28:44 -07001512 CALL_ONREQUEST(pRI->pCI->requestNumber,
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001513 gsmBciPtrs,
1514 num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *),
Etan Cohend3652192014-06-20 08:28:44 -07001515 pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001516
1517#ifdef MEMSET_FREED
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001518 memset(gsmBci, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo));
1519 memset(gsmBciPtrs, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *));
Wink Savillef4c4d362009-04-02 01:37:03 -07001520#endif
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001521 }
Wink Savillef4c4d362009-04-02 01:37:03 -07001522
1523 return;
1524
1525invalid:
1526 invalidCommandBlock(pRI);
1527 return;
Wink Savillea592eeb2009-05-22 13:26:36 -07001528}
Wink Savillef4c4d362009-04-02 01:37:03 -07001529
Wink Savillea592eeb2009-05-22 13:26:36 -07001530static void
1531dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1532 int32_t t;
1533 status_t status;
1534 int32_t num;
1535
1536 status = p.readInt32(&num);
1537 if (status != NO_ERROR) {
1538 goto invalid;
1539 }
1540
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001541 {
1542 RIL_CDMA_BroadcastSmsConfigInfo cdmaBci[num];
1543 RIL_CDMA_BroadcastSmsConfigInfo *cdmaBciPtrs[num];
Wink Savillea592eeb2009-05-22 13:26:36 -07001544
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001545 startRequest;
1546 for (int i = 0 ; i < num ; i++ ) {
1547 cdmaBciPtrs[i] = &cdmaBci[i];
Wink Savillea592eeb2009-05-22 13:26:36 -07001548
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001549 status = p.readInt32(&t);
1550 cdmaBci[i].service_category = (int) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001551
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001552 status = p.readInt32(&t);
1553 cdmaBci[i].language = (int) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001554
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001555 status = p.readInt32(&t);
1556 cdmaBci[i].selected = (uint8_t) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001557
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001558 appendPrintBuf("%s [%d: service_category=%d, language =%d, \
1559 entries.bSelected =%d]", printBuf, i, cdmaBci[i].service_category,
1560 cdmaBci[i].language, cdmaBci[i].selected);
1561 }
1562 closeRequest;
Wink Savillea592eeb2009-05-22 13:26:36 -07001563
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001564 if (status != NO_ERROR) {
1565 goto invalid;
1566 }
Wink Savillea592eeb2009-05-22 13:26:36 -07001567
Etan Cohend3652192014-06-20 08:28:44 -07001568 CALL_ONREQUEST(pRI->pCI->requestNumber,
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001569 cdmaBciPtrs,
1570 num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *),
Etan Cohend3652192014-06-20 08:28:44 -07001571 pRI, pRI->socket_id);
Wink Savillea592eeb2009-05-22 13:26:36 -07001572
1573#ifdef MEMSET_FREED
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001574 memset(cdmaBci, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo));
1575 memset(cdmaBciPtrs, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *));
Wink Savillea592eeb2009-05-22 13:26:36 -07001576#endif
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001577 }
Wink Savillea592eeb2009-05-22 13:26:36 -07001578
1579 return;
1580
1581invalid:
1582 invalidCommandBlock(pRI);
1583 return;
Wink Savillef4c4d362009-04-02 01:37:03 -07001584}
1585
1586static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI) {
1587 RIL_CDMA_SMS_WriteArgs rcsw;
1588 int32_t t;
1589 uint32_t ut;
1590 uint8_t uct;
1591 status_t status;
1592 int32_t digitCount;
Sukanya Rajkhowa605c7842013-10-29 14:55:30 +08001593 int32_t digitLimit;
Wink Savillef4c4d362009-04-02 01:37:03 -07001594
1595 memset(&rcsw, 0, sizeof(rcsw));
1596
1597 status = p.readInt32(&t);
1598 rcsw.status = t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001599
Wink Savillef4c4d362009-04-02 01:37:03 -07001600 status = p.readInt32(&t);
1601 rcsw.message.uTeleserviceID = (int) t;
1602
1603 status = p.read(&uct,sizeof(uct));
1604 rcsw.message.bIsServicePresent = (uint8_t) uct;
1605
1606 status = p.readInt32(&t);
1607 rcsw.message.uServicecategory = (int) t;
1608
1609 status = p.readInt32(&t);
1610 rcsw.message.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1611
1612 status = p.readInt32(&t);
1613 rcsw.message.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1614
1615 status = p.readInt32(&t);
1616 rcsw.message.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1617
1618 status = p.readInt32(&t);
1619 rcsw.message.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1620
1621 status = p.read(&uct,sizeof(uct));
1622 rcsw.message.sAddress.number_of_digits = (uint8_t) uct;
1623
Sukanya Rajkhowa605c7842013-10-29 14:55:30 +08001624 digitLimit = MIN((rcsw.message.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
1625
1626 for(digitCount = 0 ; digitCount < digitLimit; digitCount ++) {
Wink Savillef4c4d362009-04-02 01:37:03 -07001627 status = p.read(&uct,sizeof(uct));
1628 rcsw.message.sAddress.digits[digitCount] = (uint8_t) uct;
1629 }
1630
Wink Savillea592eeb2009-05-22 13:26:36 -07001631 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001632 rcsw.message.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1633
Wink Savillea592eeb2009-05-22 13:26:36 -07001634 status = p.read(&uct,sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001635 rcsw.message.sSubAddress.odd = (uint8_t) uct;
1636
1637 status = p.read(&uct,sizeof(uct));
1638 rcsw.message.sSubAddress.number_of_digits = (uint8_t) uct;
1639
Sukanya Rajkhowa605c7842013-10-29 14:55:30 +08001640 digitLimit = MIN((rcsw.message.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
1641
1642 for(digitCount = 0 ; digitCount < digitLimit; digitCount ++) {
Wink Savillea592eeb2009-05-22 13:26:36 -07001643 status = p.read(&uct,sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001644 rcsw.message.sSubAddress.digits[digitCount] = (uint8_t) uct;
1645 }
1646
Wink Savillea592eeb2009-05-22 13:26:36 -07001647 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001648 rcsw.message.uBearerDataLen = (int) t;
1649
Sukanya Rajkhowa605c7842013-10-29 14:55:30 +08001650 digitLimit = MIN((rcsw.message.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
1651
1652 for(digitCount = 0 ; digitCount < digitLimit; digitCount ++) {
Wink Savillea592eeb2009-05-22 13:26:36 -07001653 status = p.read(&uct, sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001654 rcsw.message.aBearerData[digitCount] = (uint8_t) uct;
1655 }
1656
1657 if (status != NO_ERROR) {
1658 goto invalid;
1659 }
1660
1661 startRequest;
Wink Saville1b5fd232009-04-22 14:50:00 -07001662 appendPrintBuf("%sstatus=%d, message.uTeleserviceID=%d, message.bIsServicePresent=%d, \
1663 message.uServicecategory=%d, message.sAddress.digit_mode=%d, \
1664 message.sAddress.number_mode=%d, \
1665 message.sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07001666 printBuf, rcsw.status, rcsw.message.uTeleserviceID, rcsw.message.bIsServicePresent,
Wink Saville1b5fd232009-04-22 14:50:00 -07001667 rcsw.message.uServicecategory, rcsw.message.sAddress.digit_mode,
1668 rcsw.message.sAddress.number_mode,
1669 rcsw.message.sAddress.number_type);
Wink Savillef4c4d362009-04-02 01:37:03 -07001670 closeRequest;
1671
1672 printRequest(pRI->token, pRI->pCI->requestNumber);
1673
Etan Cohend3652192014-06-20 08:28:44 -07001674 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsw, sizeof(rcsw),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001675
1676#ifdef MEMSET_FREED
1677 memset(&rcsw, 0, sizeof(rcsw));
1678#endif
1679
1680 return;
1681
1682invalid:
1683 invalidCommandBlock(pRI);
1684 return;
1685
1686}
1687
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -07001688// For backwards compatibility in RIL_REQUEST_SETUP_DATA_CALL.
1689// Version 4 of the RIL interface adds a new PDP type parameter to support
1690// IPv6 and dual-stack PDP contexts. When dealing with a previous version of
1691// RIL, remove the parameter from the request.
1692static void dispatchDataCall(Parcel& p, RequestInfo *pRI) {
1693 // In RIL v3, REQUEST_SETUP_DATA_CALL takes 6 parameters.
1694 const int numParamsRilV3 = 6;
1695
1696 // The first bytes of the RIL parcel contain the request number and the
1697 // serial number - see processCommandBuffer(). Copy them over too.
1698 int pos = p.dataPosition();
1699
1700 int numParams = p.readInt32();
1701 if (s_callbacks.version < 4 && numParams > numParamsRilV3) {
1702 Parcel p2;
1703 p2.appendFrom(&p, 0, pos);
1704 p2.writeInt32(numParamsRilV3);
1705 for(int i = 0; i < numParamsRilV3; i++) {
1706 p2.writeString16(p.readString16());
1707 }
1708 p2.setDataPosition(pos);
1709 dispatchStrings(p2, pRI);
1710 } else {
Lorenzo Colitti57ce1f22010-09-13 12:23:50 -07001711 p.setDataPosition(pos);
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -07001712 dispatchStrings(p, pRI);
1713 }
1714}
1715
Sungmin Choi75697532013-04-26 15:04:45 -07001716static void dispatchSetInitialAttachApn(Parcel &p, RequestInfo *pRI)
1717{
1718 RIL_InitialAttachApn pf;
1719 int32_t t;
1720 status_t status;
1721
1722 memset(&pf, 0, sizeof(pf));
1723
1724 pf.apn = strdupReadString(p);
1725 pf.protocol = strdupReadString(p);
1726
1727 status = p.readInt32(&t);
1728 pf.authtype = (int) t;
1729
1730 pf.username = strdupReadString(p);
1731 pf.password = strdupReadString(p);
1732
1733 startRequest;
Etan Cohen5d891b72014-02-27 17:25:17 -08001734 appendPrintBuf("%sapn=%s, protocol=%s, authtype=%d, username=%s, password=%s",
1735 printBuf, pf.apn, pf.protocol, pf.authtype, pf.username, pf.password);
Sungmin Choi75697532013-04-26 15:04:45 -07001736 closeRequest;
1737 printRequest(pRI->token, pRI->pCI->requestNumber);
1738
1739 if (status != NO_ERROR) {
1740 goto invalid;
1741 }
Etan Cohend3652192014-06-20 08:28:44 -07001742 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
Sungmin Choi75697532013-04-26 15:04:45 -07001743
1744#ifdef MEMSET_FREED
1745 memsetString(pf.apn);
1746 memsetString(pf.protocol);
1747 memsetString(pf.username);
1748 memsetString(pf.password);
1749#endif
1750
1751 free(pf.apn);
1752 free(pf.protocol);
1753 free(pf.username);
1754 free(pf.password);
1755
1756#ifdef MEMSET_FREED
1757 memset(&pf, 0, sizeof(pf));
1758#endif
1759
1760 return;
1761invalid:
1762 invalidCommandBlock(pRI);
1763 return;
1764}
1765
Jake Hamby8a4a2332014-01-15 13:12:05 -08001766static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI) {
1767 RIL_NV_ReadItem nvri;
1768 int32_t t;
1769 status_t status;
1770
1771 memset(&nvri, 0, sizeof(nvri));
1772
1773 status = p.readInt32(&t);
1774 nvri.itemID = (RIL_NV_Item) t;
1775
1776 if (status != NO_ERROR) {
1777 goto invalid;
1778 }
1779
1780 startRequest;
1781 appendPrintBuf("%snvri.itemID=%d, ", printBuf, nvri.itemID);
1782 closeRequest;
1783
1784 printRequest(pRI->token, pRI->pCI->requestNumber);
1785
Etan Cohend3652192014-06-20 08:28:44 -07001786 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvri, sizeof(nvri), pRI, pRI->socket_id);
Jake Hamby8a4a2332014-01-15 13:12:05 -08001787
1788#ifdef MEMSET_FREED
1789 memset(&nvri, 0, sizeof(nvri));
1790#endif
1791
1792 return;
1793
1794invalid:
1795 invalidCommandBlock(pRI);
1796 return;
1797}
1798
1799static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI) {
1800 RIL_NV_WriteItem nvwi;
1801 int32_t t;
1802 status_t status;
1803
1804 memset(&nvwi, 0, sizeof(nvwi));
1805
1806 status = p.readInt32(&t);
1807 nvwi.itemID = (RIL_NV_Item) t;
1808
1809 nvwi.value = strdupReadString(p);
1810
1811 if (status != NO_ERROR || nvwi.value == NULL) {
1812 goto invalid;
1813 }
1814
1815 startRequest;
1816 appendPrintBuf("%snvwi.itemID=%d, value=%s, ", printBuf, nvwi.itemID,
1817 nvwi.value);
1818 closeRequest;
1819
1820 printRequest(pRI->token, pRI->pCI->requestNumber);
1821
Etan Cohend3652192014-06-20 08:28:44 -07001822 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvwi, sizeof(nvwi), pRI, pRI->socket_id);
Jake Hamby8a4a2332014-01-15 13:12:05 -08001823
1824#ifdef MEMSET_FREED
1825 memsetString(nvwi.value);
1826#endif
1827
1828 free(nvwi.value);
1829
1830#ifdef MEMSET_FREED
1831 memset(&nvwi, 0, sizeof(nvwi));
1832#endif
1833
1834 return;
1835
1836invalid:
1837 invalidCommandBlock(pRI);
1838 return;
1839}
1840
1841
Etan Cohend3652192014-06-20 08:28:44 -07001842static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI) {
1843 RIL_SelectUiccSub uicc_sub;
1844 status_t status;
1845 int32_t t;
1846 memset(&uicc_sub, 0, sizeof(uicc_sub));
1847
1848 status = p.readInt32(&t);
1849 if (status != NO_ERROR) {
1850 goto invalid;
1851 }
1852 uicc_sub.slot = (int) t;
1853
1854 status = p.readInt32(&t);
1855 if (status != NO_ERROR) {
1856 goto invalid;
1857 }
1858 uicc_sub.app_index = (int) t;
1859
1860 status = p.readInt32(&t);
1861 if (status != NO_ERROR) {
1862 goto invalid;
1863 }
1864 uicc_sub.sub_type = (RIL_SubscriptionType) t;
1865
1866 status = p.readInt32(&t);
1867 if (status != NO_ERROR) {
1868 goto invalid;
1869 }
1870 uicc_sub.act_status = (RIL_UiccSubActStatus) t;
1871
1872 startRequest;
1873 appendPrintBuf("slot=%d, app_index=%d, act_status = %d", uicc_sub.slot, uicc_sub.app_index,
1874 uicc_sub.act_status);
1875 RLOGD("dispatchUiccSubscription, slot=%d, app_index=%d, act_status = %d", uicc_sub.slot,
1876 uicc_sub.app_index, uicc_sub.act_status);
1877 closeRequest;
1878 printRequest(pRI->token, pRI->pCI->requestNumber);
1879
1880 CALL_ONREQUEST(pRI->pCI->requestNumber, &uicc_sub, sizeof(uicc_sub), pRI, pRI->socket_id);
1881
1882#ifdef MEMSET_FREED
1883 memset(&uicc_sub, 0, sizeof(uicc_sub));
1884#endif
1885 return;
1886
1887invalid:
1888 invalidCommandBlock(pRI);
1889 return;
1890}
1891
Amit Mahajan90530a62014-07-01 15:54:08 -07001892static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI)
1893{
1894 RIL_SimAuthentication pf;
1895 int32_t t;
1896 status_t status;
1897
1898 memset(&pf, 0, sizeof(pf));
1899
1900 status = p.readInt32(&t);
1901 pf.authContext = (int) t;
1902 pf.authData = strdupReadString(p);
1903 pf.aid = strdupReadString(p);
1904
1905 startRequest;
1906 appendPrintBuf("authContext=%s, authData=%s, aid=%s", pf.authContext, pf.authData, pf.aid);
1907 closeRequest;
1908 printRequest(pRI->token, pRI->pCI->requestNumber);
1909
1910 if (status != NO_ERROR) {
1911 goto invalid;
1912 }
1913 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
1914
1915#ifdef MEMSET_FREED
1916 memsetString(pf.authData);
1917 memsetString(pf.aid);
1918#endif
1919
1920 free(pf.authData);
1921 free(pf.aid);
1922
1923#ifdef MEMSET_FREED
1924 memset(&pf, 0, sizeof(pf));
1925#endif
1926
1927 return;
1928invalid:
1929 invalidCommandBlock(pRI);
1930 return;
1931}
1932
Amit Mahajanc796e222014-08-13 16:54:01 +00001933static void dispatchDataProfile(Parcel &p, RequestInfo *pRI) {
1934 int32_t t;
1935 status_t status;
1936 int32_t num;
1937
1938 status = p.readInt32(&num);
Sanket Padawe0cfc5532016-03-07 17:12:19 -08001939 if (status != NO_ERROR || num < 0) {
Amit Mahajanc796e222014-08-13 16:54:01 +00001940 goto invalid;
1941 }
1942
1943 {
Sanket Padawe55227b52016-02-29 10:09:26 -08001944 RIL_DataProfileInfo *dataProfiles =
Sanket Padawe0cfc5532016-03-07 17:12:19 -08001945 (RIL_DataProfileInfo *)calloc(num, sizeof(RIL_DataProfileInfo));
Sanket Padawe55227b52016-02-29 10:09:26 -08001946 if (dataProfiles == NULL) {
1947 RLOGE("Memory allocation failed for request %s",
1948 requestToString(pRI->pCI->requestNumber));
1949 return;
1950 }
1951 RIL_DataProfileInfo **dataProfilePtrs =
Sanket Padawe0cfc5532016-03-07 17:12:19 -08001952 (RIL_DataProfileInfo **)calloc(num, sizeof(RIL_DataProfileInfo *));
Sanket Padawe55227b52016-02-29 10:09:26 -08001953 if (dataProfilePtrs == NULL) {
1954 RLOGE("Memory allocation failed for request %s",
1955 requestToString(pRI->pCI->requestNumber));
1956 free(dataProfiles);
1957 return;
1958 }
Amit Mahajanc796e222014-08-13 16:54:01 +00001959
1960 startRequest;
1961 for (int i = 0 ; i < num ; i++ ) {
1962 dataProfilePtrs[i] = &dataProfiles[i];
1963
1964 status = p.readInt32(&t);
1965 dataProfiles[i].profileId = (int) t;
1966
1967 dataProfiles[i].apn = strdupReadString(p);
1968 dataProfiles[i].protocol = strdupReadString(p);
1969 status = p.readInt32(&t);
1970 dataProfiles[i].authType = (int) t;
1971
1972 dataProfiles[i].user = strdupReadString(p);
1973 dataProfiles[i].password = strdupReadString(p);
1974
1975 status = p.readInt32(&t);
1976 dataProfiles[i].type = (int) t;
1977
1978 status = p.readInt32(&t);
1979 dataProfiles[i].maxConnsTime = (int) t;
1980 status = p.readInt32(&t);
1981 dataProfiles[i].maxConns = (int) t;
1982 status = p.readInt32(&t);
1983 dataProfiles[i].waitTime = (int) t;
1984
1985 status = p.readInt32(&t);
1986 dataProfiles[i].enabled = (int) t;
1987
1988 appendPrintBuf("%s [%d: profileId=%d, apn =%s, protocol =%s, authType =%d, \
1989 user =%s, password =%s, type =%d, maxConnsTime =%d, maxConns =%d, \
1990 waitTime =%d, enabled =%d]", printBuf, i, dataProfiles[i].profileId,
1991 dataProfiles[i].apn, dataProfiles[i].protocol, dataProfiles[i].authType,
1992 dataProfiles[i].user, dataProfiles[i].password, dataProfiles[i].type,
1993 dataProfiles[i].maxConnsTime, dataProfiles[i].maxConns,
1994 dataProfiles[i].waitTime, dataProfiles[i].enabled);
1995 }
1996 closeRequest;
1997 printRequest(pRI->token, pRI->pCI->requestNumber);
1998
1999 if (status != NO_ERROR) {
Sanket Padawe55227b52016-02-29 10:09:26 -08002000 free(dataProfiles);
2001 free(dataProfilePtrs);
Amit Mahajanc796e222014-08-13 16:54:01 +00002002 goto invalid;
2003 }
2004 CALL_ONREQUEST(pRI->pCI->requestNumber,
2005 dataProfilePtrs,
2006 num * sizeof(RIL_DataProfileInfo *),
2007 pRI, pRI->socket_id);
2008
2009#ifdef MEMSET_FREED
2010 memset(dataProfiles, 0, num * sizeof(RIL_DataProfileInfo));
2011 memset(dataProfilePtrs, 0, num * sizeof(RIL_DataProfileInfo *));
2012#endif
Sanket Padawe55227b52016-02-29 10:09:26 -08002013 free(dataProfiles);
2014 free(dataProfilePtrs);
Amit Mahajanc796e222014-08-13 16:54:01 +00002015 }
2016
2017 return;
2018
2019invalid:
2020 invalidCommandBlock(pRI);
2021 return;
2022}
2023
Wink Saville8b4e4f72014-10-17 15:01:45 -07002024static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI){
2025 RIL_RadioCapability rc;
2026 int32_t t;
2027 status_t status;
2028
2029 memset (&rc, 0, sizeof(RIL_RadioCapability));
2030
2031 status = p.readInt32(&t);
2032 rc.version = (int)t;
2033 if (status != NO_ERROR) {
2034 goto invalid;
2035 }
2036
2037 status = p.readInt32(&t);
2038 rc.session= (int)t;
2039 if (status != NO_ERROR) {
2040 goto invalid;
2041 }
2042
2043 status = p.readInt32(&t);
2044 rc.phase= (int)t;
2045 if (status != NO_ERROR) {
2046 goto invalid;
2047 }
2048
2049 status = p.readInt32(&t);
2050 rc.rat = (int)t;
2051 if (status != NO_ERROR) {
2052 goto invalid;
2053 }
2054
2055 status = readStringFromParcelInplace(p, rc.logicalModemUuid, sizeof(rc.logicalModemUuid));
2056 if (status != NO_ERROR) {
2057 goto invalid;
2058 }
2059
2060 status = p.readInt32(&t);
2061 rc.status = (int)t;
2062
2063 if (status != NO_ERROR) {
2064 goto invalid;
2065 }
2066
2067 startRequest;
2068 appendPrintBuf("%s [version:%d, session:%d, phase:%d, rat:%d, \
Chih-Wei Huang8593f262015-10-02 15:09:52 +08002069 logicalModemUuid:%s, status:%d", printBuf, rc.version, rc.session,
Legler Wu8caf06f2014-10-29 14:02:14 +08002070 rc.phase, rc.rat, rc.logicalModemUuid, rc.session);
Wink Saville8b4e4f72014-10-17 15:01:45 -07002071
2072 closeRequest;
2073 printRequest(pRI->token, pRI->pCI->requestNumber);
2074
2075 CALL_ONREQUEST(pRI->pCI->requestNumber,
2076 &rc,
2077 sizeof(RIL_RadioCapability),
2078 pRI, pRI->socket_id);
2079 return;
2080invalid:
2081 invalidCommandBlock(pRI);
2082 return;
2083}
2084
Meng Wangb4e34312016-05-12 14:54:36 -07002085/**
2086 * Callee expects const RIL_CarrierRestrictions *
2087 */
2088static void dispatchCarrierRestrictions(Parcel &p, RequestInfo *pRI) {
2089 RIL_CarrierRestrictions cr;
2090 RIL_Carrier * allowed_carriers = NULL;
2091 RIL_Carrier * excluded_carriers = NULL;
2092 int32_t t;
2093 status_t status;
2094
2095 memset(&cr, 0, sizeof(RIL_CarrierRestrictions));
2096
Robert Greenwalt27e99c52016-06-01 16:31:38 -07002097 if (s_callbacks.version < 14) {
Meng Wangb4e34312016-05-12 14:54:36 -07002098 RLOGE("Unsuppoted RIL version %d, min version expected %d",
Robert Greenwalt27e99c52016-06-01 16:31:38 -07002099 s_callbacks.version, 14);
Meng Wangdf8398c2016-05-25 12:59:15 -07002100 RIL_onRequestComplete(pRI, RIL_E_REQUEST_NOT_SUPPORTED, NULL, 0);
2101 return;
Meng Wangb4e34312016-05-12 14:54:36 -07002102 }
2103
2104 status = p.readInt32(&t);
2105 if (status != NO_ERROR) {
2106 goto invalid;
2107 }
2108 allowed_carriers = (RIL_Carrier *)calloc(t, sizeof(RIL_Carrier));
2109 if (allowed_carriers == NULL) {
2110 RLOGE("Memory allocation failed for request %s", requestToString(pRI->pCI->requestNumber));
2111 goto exit;
2112 }
2113 cr.len_allowed_carriers = t;
2114 cr.allowed_carriers = allowed_carriers;
2115
2116 status = p.readInt32(&t);
2117 if (status != NO_ERROR) {
2118 goto invalid;
2119 }
2120 excluded_carriers = (RIL_Carrier *)calloc(t, sizeof(RIL_Carrier));
2121 if (excluded_carriers == NULL) {
2122 RLOGE("Memory allocation failed for request %s", requestToString(pRI->pCI->requestNumber));
2123 goto exit;
2124 }
2125 cr.len_excluded_carriers = t;
2126 cr.excluded_carriers = excluded_carriers;
2127
Meng Wang5d703cb2016-06-08 11:53:25 -07002128 startRequest;
2129 appendPrintBuf("%s len_allowed_carriers:%d, len_excluded_carriers:%d,",
2130 printBuf, cr.len_allowed_carriers, cr.len_excluded_carriers);
2131
2132 appendPrintBuf("%s allowed_carriers:", printBuf);
Meng Wangb4e34312016-05-12 14:54:36 -07002133 for (int32_t i = 0; i < cr.len_allowed_carriers; i++) {
2134 RIL_Carrier *p_cr = allowed_carriers + i;
Meng Wang5d703cb2016-06-08 11:53:25 -07002135 p_cr->mcc = strdupReadString(p);
2136 p_cr->mnc = strdupReadString(p);
Meng Wangb4e34312016-05-12 14:54:36 -07002137 status = p.readInt32(&t);
2138 p_cr->match_type = static_cast<RIL_CarrierMatchType>(t);
2139 if (status != NO_ERROR) {
2140 goto invalid;
2141 }
Meng Wang5d703cb2016-06-08 11:53:25 -07002142 p_cr->match_data = strdupReadString(p);
2143 appendPrintBuf("%s [%d mcc:%s, mnc:%s, match_type:%d, match_data:%s],",
2144 printBuf, i, p_cr->mcc, p_cr->mnc, p_cr->match_type, p_cr->match_data);
Meng Wangb4e34312016-05-12 14:54:36 -07002145 }
2146
2147 for (int32_t i = 0; i < cr.len_excluded_carriers; i++) {
2148 RIL_Carrier *p_cr = excluded_carriers + i;
Meng Wang5d703cb2016-06-08 11:53:25 -07002149 p_cr->mcc = strdupReadString(p);
2150 p_cr->mnc = strdupReadString(p);
Meng Wangb4e34312016-05-12 14:54:36 -07002151 status = p.readInt32(&t);
2152 p_cr->match_type = static_cast<RIL_CarrierMatchType>(t);
2153 if (status != NO_ERROR) {
2154 goto invalid;
2155 }
Meng Wang5d703cb2016-06-08 11:53:25 -07002156 p_cr->match_data = strdupReadString(p);
2157 appendPrintBuf("%s [%d mcc:%s, mnc:%s, match_type:%d, match_data:%s],",
2158 printBuf, i, p_cr->mcc, p_cr->mnc, p_cr->match_type, p_cr->match_data);
Meng Wangb4e34312016-05-12 14:54:36 -07002159 }
2160
Meng Wangb4e34312016-05-12 14:54:36 -07002161 closeRequest;
2162 printRequest(pRI->token, pRI->pCI->requestNumber);
2163
2164 CALL_ONREQUEST(pRI->pCI->requestNumber,
2165 &cr,
2166 sizeof(RIL_CarrierRestrictions),
2167 pRI, pRI->socket_id);
2168
2169 goto exit;
2170
2171invalid:
2172 invalidCommandBlock(pRI);
Meng Wangdf8398c2016-05-25 12:59:15 -07002173 RIL_onRequestComplete(pRI, RIL_E_INVALID_ARGUMENTS, NULL, 0);
Meng Wangb4e34312016-05-12 14:54:36 -07002174exit:
2175 if (allowed_carriers != NULL) {
2176 free(allowed_carriers);
2177 }
2178 if (excluded_carriers != NULL) {
2179 free(excluded_carriers);
2180 }
2181 return;
2182}
2183
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002184static int
Wink Savillef4c4d362009-04-02 01:37:03 -07002185blockingWrite(int fd, const void *buffer, size_t len) {
Wink Saville7f856802009-06-09 10:23:37 -07002186 size_t writeOffset = 0;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002187 const uint8_t *toWrite;
2188
2189 toWrite = (const uint8_t *)buffer;
2190
2191 while (writeOffset < len) {
2192 ssize_t written;
2193 do {
2194 written = write (fd, toWrite + writeOffset,
2195 len - writeOffset);
Banavathu, Srinivas Naik38884902011-07-05 20:04:25 +05302196 } while (written < 0 && ((errno == EINTR) || (errno == EAGAIN)));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002197
2198 if (written >= 0) {
2199 writeOffset += written;
2200 } else { // written < 0
Wink Saville8eb2a122012-11-19 16:05:13 -08002201 RLOGE ("RIL Response: unexpected error on write errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002202 close(fd);
2203 return -1;
2204 }
2205 }
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07002206#if VDBG
Dheeraj Shetty27976c42014-07-02 21:27:57 +02002207 RLOGE("RIL Response bytes written:%d", writeOffset);
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07002208#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002209 return 0;
2210}
2211
2212static int
Etan Cohend3652192014-06-20 08:28:44 -07002213sendResponseRaw (const void *data, size_t dataSize, RIL_SOCKET_ID socket_id) {
2214 int fd = s_ril_param_socket.fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002215 int ret;
2216 uint32_t header;
Etan Cohend3652192014-06-20 08:28:44 -07002217 pthread_mutex_t * writeMutexHook = &s_writeMutex;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002218
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07002219#if VDBG
Etan Cohend3652192014-06-20 08:28:44 -07002220 RLOGE("Send Response to %s", rilSocketIdToString(socket_id));
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07002221#endif
Etan Cohend3652192014-06-20 08:28:44 -07002222
2223#if (SIM_COUNT >= 2)
2224 if (socket_id == RIL_SOCKET_2) {
2225 fd = s_ril_param_socket2.fdCommand;
2226 writeMutexHook = &s_writeMutex_socket2;
2227 }
2228#if (SIM_COUNT >= 3)
2229 else if (socket_id == RIL_SOCKET_3) {
2230 fd = s_ril_param_socket3.fdCommand;
2231 writeMutexHook = &s_writeMutex_socket3;
2232 }
2233#endif
2234#if (SIM_COUNT >= 4)
2235 else if (socket_id == RIL_SOCKET_4) {
2236 fd = s_ril_param_socket4.fdCommand;
2237 writeMutexHook = &s_writeMutex_socket4;
2238 }
2239#endif
2240#endif
2241 if (fd < 0) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002242 return -1;
2243 }
2244
2245 if (dataSize > MAX_COMMAND_BYTES) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002246 RLOGE("RIL: packet larger than %u (%u)",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002247 MAX_COMMAND_BYTES, (unsigned int )dataSize);
2248
2249 return -1;
2250 }
Wink Saville7f856802009-06-09 10:23:37 -07002251
Etan Cohend3652192014-06-20 08:28:44 -07002252 pthread_mutex_lock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002253
2254 header = htonl(dataSize);
2255
2256 ret = blockingWrite(fd, (void *)&header, sizeof(header));
2257
2258 if (ret < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002259 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002260 return ret;
2261 }
2262
Kennyee1fadc2009-08-13 00:45:53 +08002263 ret = blockingWrite(fd, data, dataSize);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002264
2265 if (ret < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002266 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002267 return ret;
2268 }
2269
Etan Cohend3652192014-06-20 08:28:44 -07002270 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002271
2272 return 0;
2273}
2274
2275static int
Etan Cohend3652192014-06-20 08:28:44 -07002276sendResponse (Parcel &p, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002277 printResponse;
Etan Cohend3652192014-06-20 08:28:44 -07002278 return sendResponseRaw(p.data(), p.dataSize(), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002279}
2280
Mohamad Ayyash74f7e662014-04-18 11:43:28 -07002281/** response is an int* pointing to an array of ints */
Wink Saville7f856802009-06-09 10:23:37 -07002282
2283static int
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002284responseInts(Parcel &p, int slotId, int requestNumber, int responseType, int token, RIL_Errno e,
2285 void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002286 int numInts;
2287
2288 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002289 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002290 return RIL_ERRNO_INVALID_RESPONSE;
2291 }
2292 if (responselen % sizeof(int) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002293 RLOGE("responseInts: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002294 (int)responselen, (int)sizeof(int));
2295 return RIL_ERRNO_INVALID_RESPONSE;
2296 }
2297
2298 int *p_int = (int *) response;
2299
Mohamad Ayyash74f7e662014-04-18 11:43:28 -07002300 numInts = responselen / sizeof(int);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002301 p.writeInt32 (numInts);
2302
2303 /* each int*/
2304 startResponse;
2305 for (int i = 0 ; i < numInts ; i++) {
2306 appendPrintBuf("%s%d,", printBuf, p_int[i]);
2307 p.writeInt32(p_int[i]);
2308 }
2309 removeLastChar;
2310 closeResponse;
2311
2312 return 0;
2313}
2314
Chao Liu548a81e2015-05-14 16:13:46 -07002315// Response is an int or RIL_LastCallFailCauseInfo.
2316// Currently, only Shamu plans to use RIL_LastCallFailCauseInfo.
2317// TODO(yjl): Let all implementations use RIL_LastCallFailCauseInfo.
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002318static int responseFailCause(Parcel &p, int slotId, int requestNumber, int responseType, int token,
2319 RIL_Errno e, void *response, size_t responselen) {
Chao Liu548a81e2015-05-14 16:13:46 -07002320 if (response == NULL && responselen != 0) {
2321 RLOGE("invalid response: NULL");
2322 return RIL_ERRNO_INVALID_RESPONSE;
2323 }
2324
2325 if (responselen == sizeof(int)) {
Sungmin Choia408c252015-07-01 16:22:46 +09002326 startResponse;
2327 int *p_int = (int *) response;
2328 appendPrintBuf("%s%d,", printBuf, p_int[0]);
2329 p.writeInt32(p_int[0]);
2330 removeLastChar;
2331 closeResponse;
Chao Liu548a81e2015-05-14 16:13:46 -07002332 } else if (responselen == sizeof(RIL_LastCallFailCauseInfo)) {
2333 startResponse;
2334 RIL_LastCallFailCauseInfo *p_fail_cause_info = (RIL_LastCallFailCauseInfo *) response;
2335 appendPrintBuf("%s[cause_code=%d,vendor_cause=%s]", printBuf, p_fail_cause_info->cause_code,
2336 p_fail_cause_info->vendor_cause);
2337 p.writeInt32(p_fail_cause_info->cause_code);
2338 writeStringToParcel(p, p_fail_cause_info->vendor_cause);
2339 removeLastChar;
2340 closeResponse;
2341 } else {
2342 RLOGE("responseFailCause: invalid response length %d expected an int or "
2343 "RIL_LastCallFailCauseInfo", (int)responselen);
2344 return RIL_ERRNO_INVALID_RESPONSE;
2345 }
2346
2347 return 0;
2348}
2349
Wink Saville43808972011-01-13 17:39:51 -08002350/** response is a char **, pointing to an array of char *'s
2351 The parcel will begin with the version */
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002352static int responseStringsWithVersion(int version, Parcel &p, int slotId, int requestNumber,
2353 int responseType, int token, RIL_Errno e, void *response, size_t responselen) {
Wink Saville43808972011-01-13 17:39:51 -08002354 p.writeInt32(version);
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002355 return responseStrings(p, slotId, requestNumber, responseType, token, e, response, responselen);
Wink Saville43808972011-01-13 17:39:51 -08002356}
2357
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002358/** response is a char **, pointing to an array of char *'s */
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002359static int responseStrings(Parcel &p, int slotId, int requestNumber, int responseType, int token,
2360 RIL_Errno e, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002361 int numStrings;
Wink Saville7f856802009-06-09 10:23:37 -07002362
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002363 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002364 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002365 return RIL_ERRNO_INVALID_RESPONSE;
2366 }
2367 if (responselen % sizeof(char *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002368 RLOGE("responseStrings: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002369 (int)responselen, (int)sizeof(char *));
2370 return RIL_ERRNO_INVALID_RESPONSE;
2371 }
2372
2373 if (response == NULL) {
2374 p.writeInt32 (0);
2375 } else {
2376 char **p_cur = (char **) response;
2377
2378 numStrings = responselen / sizeof(char *);
2379 p.writeInt32 (numStrings);
2380
2381 /* each string*/
2382 startResponse;
2383 for (int i = 0 ; i < numStrings ; i++) {
2384 appendPrintBuf("%s%s,", printBuf, (char*)p_cur[i]);
2385 writeStringToParcel (p, p_cur[i]);
2386 }
2387 removeLastChar;
2388 closeResponse;
2389 }
2390 return 0;
2391}
2392
2393
2394/**
Wink Saville7f856802009-06-09 10:23:37 -07002395 * NULL strings are accepted
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002396 * FIXME currently ignores responselen
2397 */
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002398static int responseString(Parcel &p, int slotId, int requestNumber, int responseType, int token,
2399 RIL_Errno e, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002400 /* one string only */
2401 startResponse;
2402 appendPrintBuf("%s%s", printBuf, (char*)response);
2403 closeResponse;
2404
2405 writeStringToParcel(p, (const char *)response);
2406
2407 return 0;
2408}
2409
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002410static int responseVoid(Parcel &p, int slotId, int requestNumber, int responseType, int token,
2411 RIL_Errno e, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002412 startResponse;
2413 removeLastChar;
2414 return 0;
2415}
2416
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002417static int responseCallList(Parcel &p, int slotId, int requestNumber, int responseType, int token,
2418 RIL_Errno e, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002419 int num;
2420
2421 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002422 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002423 return RIL_ERRNO_INVALID_RESPONSE;
2424 }
2425
2426 if (responselen % sizeof (RIL_Call *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002427 RLOGE("responseCallList: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002428 (int)responselen, (int)sizeof (RIL_Call *));
2429 return RIL_ERRNO_INVALID_RESPONSE;
2430 }
2431
2432 startResponse;
2433 /* number of call info's */
2434 num = responselen / sizeof(RIL_Call *);
2435 p.writeInt32(num);
2436
2437 for (int i = 0 ; i < num ; i++) {
2438 RIL_Call *p_cur = ((RIL_Call **) response)[i];
2439 /* each call info */
2440 p.writeInt32(p_cur->state);
2441 p.writeInt32(p_cur->index);
2442 p.writeInt32(p_cur->toa);
2443 p.writeInt32(p_cur->isMpty);
2444 p.writeInt32(p_cur->isMT);
2445 p.writeInt32(p_cur->als);
2446 p.writeInt32(p_cur->isVoice);
Wink Saville1b5fd232009-04-22 14:50:00 -07002447 p.writeInt32(p_cur->isVoicePrivacy);
2448 writeStringToParcel(p, p_cur->number);
John Wangff368742009-03-24 17:56:29 -07002449 p.writeInt32(p_cur->numberPresentation);
Wink Saville1b5fd232009-04-22 14:50:00 -07002450 writeStringToParcel(p, p_cur->name);
2451 p.writeInt32(p_cur->namePresentation);
Wink Saville3a4840b2010-04-07 13:29:58 -07002452 // Remove when partners upgrade to version 3
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002453 if (s_callbacks.version < 3 || p_cur->uusInfo == NULL || p_cur->uusInfo->uusData == NULL) {
Wink Saville74fa3882009-12-22 15:35:41 -08002454 p.writeInt32(0); /* UUS Information is absent */
2455 } else {
2456 RIL_UUS_Info *uusInfo = p_cur->uusInfo;
2457 p.writeInt32(1); /* UUS Information is present */
2458 p.writeInt32(uusInfo->uusType);
2459 p.writeInt32(uusInfo->uusDcs);
2460 p.writeInt32(uusInfo->uusLength);
2461 p.write(uusInfo->uusData, uusInfo->uusLength);
2462 }
Wink Saville3d54e742009-05-18 18:00:44 -07002463 appendPrintBuf("%s[id=%d,%s,toa=%d,",
John Wangff368742009-03-24 17:56:29 -07002464 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002465 p_cur->index,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002466 callStateToString(p_cur->state),
Wink Saville3d54e742009-05-18 18:00:44 -07002467 p_cur->toa);
2468 appendPrintBuf("%s%s,%s,als=%d,%s,%s,",
2469 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002470 (p_cur->isMpty)?"conf":"norm",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002471 (p_cur->isMT)?"mt":"mo",
2472 p_cur->als,
2473 (p_cur->isVoice)?"voc":"nonvoc",
Wink Saville3d54e742009-05-18 18:00:44 -07002474 (p_cur->isVoicePrivacy)?"evp":"noevp");
2475 appendPrintBuf("%s%s,cli=%d,name='%s',%d]",
2476 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002477 p_cur->number,
2478 p_cur->numberPresentation,
2479 p_cur->name,
2480 p_cur->namePresentation);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002481 }
2482 removeLastChar;
2483 closeResponse;
2484
2485 return 0;
2486}
2487
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002488static int responseSMS(Parcel &p, int slotId, int requestNumber, int responseType, int token,
2489 RIL_Errno e, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002490 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002491 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002492 return RIL_ERRNO_INVALID_RESPONSE;
2493 }
2494
2495 if (responselen != sizeof (RIL_SMS_Response) ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002496 RLOGE("invalid response length %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002497 (int)responselen, (int)sizeof (RIL_SMS_Response));
2498 return RIL_ERRNO_INVALID_RESPONSE;
2499 }
2500
2501 RIL_SMS_Response *p_cur = (RIL_SMS_Response *) response;
2502
2503 p.writeInt32(p_cur->messageRef);
2504 writeStringToParcel(p, p_cur->ackPDU);
Jaikumar Ganesh920c78f2009-06-04 10:53:15 -07002505 p.writeInt32(p_cur->errorCode);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002506
2507 startResponse;
Jaikumar Ganesh920c78f2009-06-04 10:53:15 -07002508 appendPrintBuf("%s%d,%s,%d", printBuf, p_cur->messageRef,
2509 (char*)p_cur->ackPDU, p_cur->errorCode);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002510 closeResponse;
2511
2512 return 0;
2513}
2514
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002515static int responseDataCallListV4(Parcel &p, int slotId, int requestNumber, int responseType,
2516 int token, RIL_Errno e, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002517 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002518 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002519 return RIL_ERRNO_INVALID_RESPONSE;
2520 }
2521
Wink Savillec0114b32011-02-18 10:14:07 -08002522 if (responselen % sizeof(RIL_Data_Call_Response_v4) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002523 RLOGE("responseDataCallListV4: invalid response length %d expected multiple of %d",
Wink Savillec0114b32011-02-18 10:14:07 -08002524 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v4));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002525 return RIL_ERRNO_INVALID_RESPONSE;
2526 }
2527
Amit Mahajan52500162014-07-29 17:36:48 -07002528 // Write version
2529 p.writeInt32(4);
2530
Wink Savillec0114b32011-02-18 10:14:07 -08002531 int num = responselen / sizeof(RIL_Data_Call_Response_v4);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002532 p.writeInt32(num);
2533
Wink Savillec0114b32011-02-18 10:14:07 -08002534 RIL_Data_Call_Response_v4 *p_cur = (RIL_Data_Call_Response_v4 *) response;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002535 startResponse;
2536 int i;
2537 for (i = 0; i < num; i++) {
2538 p.writeInt32(p_cur[i].cid);
2539 p.writeInt32(p_cur[i].active);
2540 writeStringToParcel(p, p_cur[i].type);
Wink Savillec0114b32011-02-18 10:14:07 -08002541 // apn is not used, so don't send.
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002542 writeStringToParcel(p, p_cur[i].address);
Wink Savillec0114b32011-02-18 10:14:07 -08002543 appendPrintBuf("%s[cid=%d,%s,%s,%s],", printBuf,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002544 p_cur[i].cid,
2545 (p_cur[i].active==0)?"down":"up",
2546 (char*)p_cur[i].type,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002547 (char*)p_cur[i].address);
2548 }
2549 removeLastChar;
2550 closeResponse;
2551
2552 return 0;
2553}
2554
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002555static int responseDataCallListV6(Parcel &p, int slotId, int requestNumber, int responseType,
2556 int token, RIL_Errno e, void *response, size_t responselen) {
Amit Mahajan52500162014-07-29 17:36:48 -07002557 if (response == NULL && responselen != 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002558 RLOGE("invalid response: NULL");
2559 return RIL_ERRNO_INVALID_RESPONSE;
2560 }
2561
2562 if (responselen % sizeof(RIL_Data_Call_Response_v6) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002563 RLOGE("responseDataCallListV6: invalid response length %d expected multiple of %d",
Etan Cohend3652192014-06-20 08:28:44 -07002564 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v6));
2565 return RIL_ERRNO_INVALID_RESPONSE;
2566 }
2567
Amit Mahajan52500162014-07-29 17:36:48 -07002568 // Write version
2569 p.writeInt32(6);
2570
Etan Cohend3652192014-06-20 08:28:44 -07002571 int num = responselen / sizeof(RIL_Data_Call_Response_v6);
2572 p.writeInt32(num);
2573
2574 RIL_Data_Call_Response_v6 *p_cur = (RIL_Data_Call_Response_v6 *) response;
2575 startResponse;
2576 int i;
2577 for (i = 0; i < num; i++) {
2578 p.writeInt32((int)p_cur[i].status);
2579 p.writeInt32(p_cur[i].suggestedRetryTime);
2580 p.writeInt32(p_cur[i].cid);
2581 p.writeInt32(p_cur[i].active);
2582 writeStringToParcel(p, p_cur[i].type);
2583 writeStringToParcel(p, p_cur[i].ifname);
2584 writeStringToParcel(p, p_cur[i].addresses);
2585 writeStringToParcel(p, p_cur[i].dnses);
2586 writeStringToParcel(p, p_cur[i].gateways);
2587 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s],", printBuf,
2588 p_cur[i].status,
2589 p_cur[i].suggestedRetryTime,
2590 p_cur[i].cid,
2591 (p_cur[i].active==0)?"down":"up",
2592 (char*)p_cur[i].type,
2593 (char*)p_cur[i].ifname,
2594 (char*)p_cur[i].addresses,
2595 (char*)p_cur[i].dnses,
2596 (char*)p_cur[i].gateways);
2597 }
2598 removeLastChar;
2599 closeResponse;
2600
2601 return 0;
2602}
2603
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002604static int responseDataCallListV9(Parcel &p, int slotId, int requestNumber, int responseType,
2605 int token, RIL_Errno e, void *response, size_t responselen) {
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002606 if (response == NULL && responselen != 0) {
2607 RLOGE("invalid response: NULL");
2608 return RIL_ERRNO_INVALID_RESPONSE;
2609 }
2610
2611 if (responselen % sizeof(RIL_Data_Call_Response_v9) != 0) {
2612 RLOGE("responseDataCallListV9: invalid response length %d expected multiple of %d",
2613 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v9));
2614 return RIL_ERRNO_INVALID_RESPONSE;
2615 }
2616
2617 // Write version
2618 p.writeInt32(10);
2619
2620 int num = responselen / sizeof(RIL_Data_Call_Response_v9);
2621 p.writeInt32(num);
2622
2623 RIL_Data_Call_Response_v9 *p_cur = (RIL_Data_Call_Response_v9 *) response;
2624 startResponse;
2625 int i;
2626 for (i = 0; i < num; i++) {
2627 p.writeInt32((int)p_cur[i].status);
2628 p.writeInt32(p_cur[i].suggestedRetryTime);
2629 p.writeInt32(p_cur[i].cid);
2630 p.writeInt32(p_cur[i].active);
2631 writeStringToParcel(p, p_cur[i].type);
2632 writeStringToParcel(p, p_cur[i].ifname);
2633 writeStringToParcel(p, p_cur[i].addresses);
2634 writeStringToParcel(p, p_cur[i].dnses);
2635 writeStringToParcel(p, p_cur[i].gateways);
2636 writeStringToParcel(p, p_cur[i].pcscf);
2637 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s],", printBuf,
2638 p_cur[i].status,
2639 p_cur[i].suggestedRetryTime,
2640 p_cur[i].cid,
2641 (p_cur[i].active==0)?"down":"up",
2642 (char*)p_cur[i].type,
2643 (char*)p_cur[i].ifname,
2644 (char*)p_cur[i].addresses,
2645 (char*)p_cur[i].dnses,
2646 (char*)p_cur[i].gateways,
2647 (char*)p_cur[i].pcscf);
2648 }
2649 removeLastChar;
2650 closeResponse;
2651
2652 return 0;
2653}
2654
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002655static int responseDataCallListV11(Parcel &p, int slotId, int requestNumber, int responseType,
2656 int token, RIL_Errno e, void *response, size_t responselen) {
Sanket Padawe4c05f352016-01-26 16:19:00 -08002657 if (response == NULL && responselen != 0) {
2658 RLOGE("invalid response: NULL");
2659 return RIL_ERRNO_INVALID_RESPONSE;
2660 }
2661
2662 if (responselen % sizeof(RIL_Data_Call_Response_v11) != 0) {
2663 RLOGE("invalid response length %d expected multiple of %d",
2664 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v11));
2665 return RIL_ERRNO_INVALID_RESPONSE;
2666 }
2667
2668 // Write version
2669 p.writeInt32(11);
2670
2671 int num = responselen / sizeof(RIL_Data_Call_Response_v11);
2672 p.writeInt32(num);
2673
2674 RIL_Data_Call_Response_v11 *p_cur = (RIL_Data_Call_Response_v11 *) response;
2675 startResponse;
2676 int i;
2677 for (i = 0; i < num; i++) {
2678 p.writeInt32((int)p_cur[i].status);
2679 p.writeInt32(p_cur[i].suggestedRetryTime);
2680 p.writeInt32(p_cur[i].cid);
2681 p.writeInt32(p_cur[i].active);
2682 writeStringToParcel(p, p_cur[i].type);
2683 writeStringToParcel(p, p_cur[i].ifname);
2684 writeStringToParcel(p, p_cur[i].addresses);
2685 writeStringToParcel(p, p_cur[i].dnses);
2686 writeStringToParcel(p, p_cur[i].gateways);
2687 writeStringToParcel(p, p_cur[i].pcscf);
2688 p.writeInt32(p_cur[i].mtu);
2689 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s,mtu=%d],", printBuf,
2690 p_cur[i].status,
2691 p_cur[i].suggestedRetryTime,
2692 p_cur[i].cid,
2693 (p_cur[i].active==0)?"down":"up",
2694 (char*)p_cur[i].type,
2695 (char*)p_cur[i].ifname,
2696 (char*)p_cur[i].addresses,
2697 (char*)p_cur[i].dnses,
2698 (char*)p_cur[i].gateways,
2699 (char*)p_cur[i].pcscf,
2700 p_cur[i].mtu);
2701 }
2702 removeLastChar;
2703 closeResponse;
2704
2705 return 0;
2706}
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002707
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002708static int responseDataCallList(Parcel &p, int slotId, int requestNumber, int responseType,
2709 int token, RIL_Errno e, void *response, size_t responselen) {
Sanket Padawe4c05f352016-01-26 16:19:00 -08002710 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
2711 if (s_callbacks.version < 5) {
2712 RLOGD("responseDataCallList: v4");
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002713 return responseDataCallListV4(p, slotId, requestNumber, responseType, token, e,
2714 response, responselen);
Sanket Padawe4c05f352016-01-26 16:19:00 -08002715 } else if (responselen % sizeof(RIL_Data_Call_Response_v6) == 0) {
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002716 return responseDataCallListV6(p, slotId, requestNumber, responseType, token, e,
2717 response, responselen);
Sanket Padawe4c05f352016-01-26 16:19:00 -08002718 } else if (responselen % sizeof(RIL_Data_Call_Response_v9) == 0) {
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002719 return responseDataCallListV9(p, slotId, requestNumber, responseType, token, e,
2720 response, responselen);
Sanket Padawe4c05f352016-01-26 16:19:00 -08002721 } else {
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002722 return responseDataCallListV11(p, slotId, requestNumber, responseType, token, e,
2723 response, responselen);
Wink Saville43808972011-01-13 17:39:51 -08002724 }
Sanket Padawe00909612016-01-26 18:44:01 -08002725 } else { // RIL version >= 13
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002726 if (responselen % sizeof(RIL_Data_Call_Response_v11) != 0) {
Sanket Padawe4c05f352016-01-26 16:19:00 -08002727 RLOGE("Data structure expected is RIL_Data_Call_Response_v11");
2728 if (!isDebuggable()) {
2729 return RIL_ERRNO_INVALID_RESPONSE;
2730 } else {
2731 assert(0);
2732 }
Wink Saville43808972011-01-13 17:39:51 -08002733 }
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002734 return responseDataCallListV11(p, slotId, requestNumber, responseType, token, e, response,
2735 responselen);
Wink Saville43808972011-01-13 17:39:51 -08002736 }
Wink Saville43808972011-01-13 17:39:51 -08002737}
2738
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002739static int responseSetupDataCall(Parcel &p, int slotId, int requestNumber, int responseType,
2740 int token, RIL_Errno e, void *response, size_t responselen) {
Wink Saville43808972011-01-13 17:39:51 -08002741 if (s_callbacks.version < 5) {
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002742 return responseStringsWithVersion(s_callbacks.version, p, slotId, requestNumber,
2743 responseType, token, e, response, responselen);
Wink Saville43808972011-01-13 17:39:51 -08002744 } else {
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002745 return responseDataCallList(p, slotId, requestNumber, responseType, token, e, response,
2746 responselen);
Wink Saville43808972011-01-13 17:39:51 -08002747 }
2748}
2749
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002750static int responseRaw(Parcel &p, int slotId, int requestNumber, int responseType, int token,
2751 RIL_Errno e, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002752 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002753 RLOGE("invalid response: NULL with responselen != 0");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002754 return RIL_ERRNO_INVALID_RESPONSE;
2755 }
2756
2757 // The java code reads -1 size as null byte array
2758 if (response == NULL) {
Wink Saville7f856802009-06-09 10:23:37 -07002759 p.writeInt32(-1);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002760 } else {
2761 p.writeInt32(responselen);
2762 p.write(response, responselen);
2763 }
2764
2765 return 0;
2766}
2767
2768
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002769static int responseSIM_IO(Parcel &p, int slotId, int requestNumber, int responseType, int token,
2770 RIL_Errno e, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002771 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002772 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002773 return RIL_ERRNO_INVALID_RESPONSE;
2774 }
2775
2776 if (responselen != sizeof (RIL_SIM_IO_Response) ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002777 RLOGE("invalid response length was %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002778 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
2779 return RIL_ERRNO_INVALID_RESPONSE;
2780 }
2781
2782 RIL_SIM_IO_Response *p_cur = (RIL_SIM_IO_Response *) response;
2783 p.writeInt32(p_cur->sw1);
2784 p.writeInt32(p_cur->sw2);
2785 writeStringToParcel(p, p_cur->simResponse);
2786
2787 startResponse;
2788 appendPrintBuf("%ssw1=0x%X,sw2=0x%X,%s", printBuf, p_cur->sw1, p_cur->sw2,
2789 (char*)p_cur->simResponse);
2790 closeResponse;
2791
2792
2793 return 0;
2794}
2795
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002796static int responseCallForwards(Parcel &p, int slotId, int requestNumber, int responseType,
2797 int token, RIL_Errno e, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002798 int num;
Wink Saville7f856802009-06-09 10:23:37 -07002799
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002800 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002801 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002802 return RIL_ERRNO_INVALID_RESPONSE;
2803 }
2804
2805 if (responselen % sizeof(RIL_CallForwardInfo *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002806 RLOGE("responseCallForwards: invalid response length %d expected multiple of %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002807 (int)responselen, (int)sizeof(RIL_CallForwardInfo *));
2808 return RIL_ERRNO_INVALID_RESPONSE;
2809 }
2810
2811 /* number of call info's */
2812 num = responselen / sizeof(RIL_CallForwardInfo *);
2813 p.writeInt32(num);
2814
2815 startResponse;
2816 for (int i = 0 ; i < num ; i++) {
2817 RIL_CallForwardInfo *p_cur = ((RIL_CallForwardInfo **) response)[i];
2818
2819 p.writeInt32(p_cur->status);
2820 p.writeInt32(p_cur->reason);
2821 p.writeInt32(p_cur->serviceClass);
2822 p.writeInt32(p_cur->toa);
2823 writeStringToParcel(p, p_cur->number);
2824 p.writeInt32(p_cur->timeSeconds);
2825 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
2826 (p_cur->status==1)?"enable":"disable",
2827 p_cur->reason, p_cur->serviceClass, p_cur->toa,
2828 (char*)p_cur->number,
2829 p_cur->timeSeconds);
2830 }
2831 removeLastChar;
2832 closeResponse;
Wink Saville7f856802009-06-09 10:23:37 -07002833
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002834 return 0;
2835}
2836
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002837static int responseSsn(Parcel &p, int slotId, int requestNumber, int responseType, int token,
2838 RIL_Errno e, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002839 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002840 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002841 return RIL_ERRNO_INVALID_RESPONSE;
2842 }
2843
2844 if (responselen != sizeof(RIL_SuppSvcNotification)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002845 RLOGE("invalid response length was %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002846 (int)responselen, (int)sizeof (RIL_SuppSvcNotification));
2847 return RIL_ERRNO_INVALID_RESPONSE;
2848 }
2849
2850 RIL_SuppSvcNotification *p_cur = (RIL_SuppSvcNotification *) response;
2851 p.writeInt32(p_cur->notificationType);
2852 p.writeInt32(p_cur->code);
2853 p.writeInt32(p_cur->index);
2854 p.writeInt32(p_cur->type);
2855 writeStringToParcel(p, p_cur->number);
2856
2857 startResponse;
2858 appendPrintBuf("%s%s,code=%d,id=%d,type=%d,%s", printBuf,
2859 (p_cur->notificationType==0)?"mo":"mt",
2860 p_cur->code, p_cur->index, p_cur->type,
2861 (char*)p_cur->number);
2862 closeResponse;
2863
2864 return 0;
2865}
2866
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002867static int responseCellList(Parcel &p, int slotId, int requestNumber, int responseType, int token,
2868 RIL_Errno e, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002869 int num;
2870
2871 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002872 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002873 return RIL_ERRNO_INVALID_RESPONSE;
2874 }
2875
2876 if (responselen % sizeof (RIL_NeighboringCell *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002877 RLOGE("responseCellList: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002878 (int)responselen, (int)sizeof (RIL_NeighboringCell *));
2879 return RIL_ERRNO_INVALID_RESPONSE;
2880 }
2881
2882 startResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002883 /* number of records */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002884 num = responselen / sizeof(RIL_NeighboringCell *);
2885 p.writeInt32(num);
2886
2887 for (int i = 0 ; i < num ; i++) {
2888 RIL_NeighboringCell *p_cur = ((RIL_NeighboringCell **) response)[i];
2889
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002890 p.writeInt32(p_cur->rssi);
2891 writeStringToParcel (p, p_cur->cid);
2892
2893 appendPrintBuf("%s[cid=%s,rssi=%d],", printBuf,
2894 p_cur->cid, p_cur->rssi);
2895 }
2896 removeLastChar;
2897 closeResponse;
2898
2899 return 0;
2900}
2901
Wink Saville3d54e742009-05-18 18:00:44 -07002902/**
2903 * Marshall the signalInfoRecord into the parcel if it exists.
2904 */
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002905static void marshallSignalInfoRecord(Parcel &p, RIL_CDMA_SignalInfoRecord &p_signalInfoRecord) {
Wink Saville3d54e742009-05-18 18:00:44 -07002906 p.writeInt32(p_signalInfoRecord.isPresent);
2907 p.writeInt32(p_signalInfoRecord.signalType);
2908 p.writeInt32(p_signalInfoRecord.alertPitch);
2909 p.writeInt32(p_signalInfoRecord.signal);
2910}
2911
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002912static int responseCdmaInformationRecords(Parcel &p, int slotId, int requestNumber,
2913 int responseType, int token, RIL_Errno e, void *response, size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07002914 int num;
Wink Savillea592eeb2009-05-22 13:26:36 -07002915 char* string8 = NULL;
2916 int buffer_lenght;
2917 RIL_CDMA_InformationRecord *infoRec;
Wink Saville3d54e742009-05-18 18:00:44 -07002918
2919 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002920 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002921 return RIL_ERRNO_INVALID_RESPONSE;
2922 }
2923
Wink Savillea592eeb2009-05-22 13:26:36 -07002924 if (responselen != sizeof (RIL_CDMA_InformationRecords)) {
Amit Mahajan18fe36b2016-08-25 11:19:21 -07002925 RLOGE("responseCdmaInformationRecords: invalid response length %d expected multiple of \
2926 %d\n", (int)responselen, (int)sizeof (RIL_CDMA_InformationRecords *));
Wink Saville3d54e742009-05-18 18:00:44 -07002927 return RIL_ERRNO_INVALID_RESPONSE;
2928 }
2929
Wink Savillea592eeb2009-05-22 13:26:36 -07002930 RIL_CDMA_InformationRecords *p_cur =
2931 (RIL_CDMA_InformationRecords *) response;
2932 num = MIN(p_cur->numberOfInfoRecs, RIL_CDMA_MAX_NUMBER_OF_INFO_RECS);
Wink Saville3d54e742009-05-18 18:00:44 -07002933
2934 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07002935 p.writeInt32(num);
Wink Saville3d54e742009-05-18 18:00:44 -07002936
Wink Savillea592eeb2009-05-22 13:26:36 -07002937 for (int i = 0 ; i < num ; i++) {
2938 infoRec = &p_cur->infoRec[i];
2939 p.writeInt32(infoRec->name);
2940 switch (infoRec->name) {
Wink Saville3d54e742009-05-18 18:00:44 -07002941 case RIL_CDMA_DISPLAY_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002942 case RIL_CDMA_EXTENDED_DISPLAY_INFO_REC:
2943 if (infoRec->rec.display.alpha_len >
2944 CDMA_ALPHA_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002945 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002946 expected not more than %d\n",
2947 (int)infoRec->rec.display.alpha_len,
2948 CDMA_ALPHA_INFO_BUFFER_LENGTH);
2949 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002950 }
Sanket Padawe0cfc5532016-03-07 17:12:19 -08002951 string8 = (char*) calloc(infoRec->rec.display.alpha_len + 1, sizeof(char));
Sanket Padawe55227b52016-02-29 10:09:26 -08002952 if (string8 == NULL) {
2953 RLOGE("Memory allocation failed for responseCdmaInformationRecords");
2954 closeRequest;
2955 return RIL_ERRNO_NO_MEMORY;
2956 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002957 for (int i = 0 ; i < infoRec->rec.display.alpha_len ; i++) {
2958 string8[i] = infoRec->rec.display.alpha_buf[i];
2959 }
Wink Saville43808972011-01-13 17:39:51 -08002960 string8[(int)infoRec->rec.display.alpha_len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002961 writeStringToParcel(p, (const char*)string8);
2962 free(string8);
2963 string8 = NULL;
Wink Saville3d54e742009-05-18 18:00:44 -07002964 break;
2965 case RIL_CDMA_CALLED_PARTY_NUMBER_INFO_REC:
Wink Saville3d54e742009-05-18 18:00:44 -07002966 case RIL_CDMA_CALLING_PARTY_NUMBER_INFO_REC:
Wink Saville3d54e742009-05-18 18:00:44 -07002967 case RIL_CDMA_CONNECTED_NUMBER_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002968 if (infoRec->rec.number.len > CDMA_NUMBER_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002969 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002970 expected not more than %d\n",
2971 (int)infoRec->rec.number.len,
2972 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2973 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002974 }
Sanket Padawe0cfc5532016-03-07 17:12:19 -08002975 string8 = (char*) calloc(infoRec->rec.number.len + 1, sizeof(char));
Sanket Padawe55227b52016-02-29 10:09:26 -08002976 if (string8 == NULL) {
2977 RLOGE("Memory allocation failed for responseCdmaInformationRecords");
2978 closeRequest;
2979 return RIL_ERRNO_NO_MEMORY;
2980 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002981 for (int i = 0 ; i < infoRec->rec.number.len; i++) {
2982 string8[i] = infoRec->rec.number.buf[i];
2983 }
Wink Saville43808972011-01-13 17:39:51 -08002984 string8[(int)infoRec->rec.number.len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002985 writeStringToParcel(p, (const char*)string8);
2986 free(string8);
2987 string8 = NULL;
2988 p.writeInt32(infoRec->rec.number.number_type);
2989 p.writeInt32(infoRec->rec.number.number_plan);
2990 p.writeInt32(infoRec->rec.number.pi);
2991 p.writeInt32(infoRec->rec.number.si);
Wink Saville3d54e742009-05-18 18:00:44 -07002992 break;
2993 case RIL_CDMA_SIGNAL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002994 p.writeInt32(infoRec->rec.signal.isPresent);
2995 p.writeInt32(infoRec->rec.signal.signalType);
2996 p.writeInt32(infoRec->rec.signal.alertPitch);
2997 p.writeInt32(infoRec->rec.signal.signal);
2998
2999 appendPrintBuf("%sisPresent=%X, signalType=%X, \
3000 alertPitch=%X, signal=%X, ",
3001 printBuf, (int)infoRec->rec.signal.isPresent,
3002 (int)infoRec->rec.signal.signalType,
3003 (int)infoRec->rec.signal.alertPitch,
3004 (int)infoRec->rec.signal.signal);
3005 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07003006 break;
3007 case RIL_CDMA_REDIRECTING_NUMBER_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07003008 if (infoRec->rec.redir.redirectingNumber.len >
3009 CDMA_NUMBER_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003010 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07003011 expected not more than %d\n",
3012 (int)infoRec->rec.redir.redirectingNumber.len,
3013 CDMA_NUMBER_INFO_BUFFER_LENGTH);
3014 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07003015 }
Sanket Padawe0cfc5532016-03-07 17:12:19 -08003016 string8 = (char*) calloc(infoRec->rec.redir.redirectingNumber.len + 1,
3017 sizeof(char));
Sanket Padawe55227b52016-02-29 10:09:26 -08003018 if (string8 == NULL) {
3019 RLOGE("Memory allocation failed for responseCdmaInformationRecords");
3020 closeRequest;
3021 return RIL_ERRNO_NO_MEMORY;
3022 }
Wink Savillea592eeb2009-05-22 13:26:36 -07003023 for (int i = 0;
3024 i < infoRec->rec.redir.redirectingNumber.len;
3025 i++) {
3026 string8[i] = infoRec->rec.redir.redirectingNumber.buf[i];
3027 }
Wink Saville43808972011-01-13 17:39:51 -08003028 string8[(int)infoRec->rec.redir.redirectingNumber.len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07003029 writeStringToParcel(p, (const char*)string8);
3030 free(string8);
3031 string8 = NULL;
3032 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_type);
3033 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_plan);
3034 p.writeInt32(infoRec->rec.redir.redirectingNumber.pi);
3035 p.writeInt32(infoRec->rec.redir.redirectingNumber.si);
3036 p.writeInt32(infoRec->rec.redir.redirectingReason);
Wink Saville3d54e742009-05-18 18:00:44 -07003037 break;
3038 case RIL_CDMA_LINE_CONTROL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07003039 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPolarityIncluded);
3040 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlToggle);
3041 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlReverse);
3042 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPowerDenial);
3043
3044 appendPrintBuf("%slineCtrlPolarityIncluded=%d, \
3045 lineCtrlToggle=%d, lineCtrlReverse=%d, \
3046 lineCtrlPowerDenial=%d, ", printBuf,
3047 (int)infoRec->rec.lineCtrl.lineCtrlPolarityIncluded,
3048 (int)infoRec->rec.lineCtrl.lineCtrlToggle,
3049 (int)infoRec->rec.lineCtrl.lineCtrlReverse,
3050 (int)infoRec->rec.lineCtrl.lineCtrlPowerDenial);
3051 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07003052 break;
3053 case RIL_CDMA_T53_CLIR_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07003054 p.writeInt32((int)(infoRec->rec.clir.cause));
Wink Saville3d54e742009-05-18 18:00:44 -07003055
Wink Savillea592eeb2009-05-22 13:26:36 -07003056 appendPrintBuf("%scause%d", printBuf, infoRec->rec.clir.cause);
3057 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07003058 break;
3059 case RIL_CDMA_T53_AUDIO_CONTROL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07003060 p.writeInt32(infoRec->rec.audioCtrl.upLink);
3061 p.writeInt32(infoRec->rec.audioCtrl.downLink);
3062
3063 appendPrintBuf("%supLink=%d, downLink=%d, ", printBuf,
3064 infoRec->rec.audioCtrl.upLink,
3065 infoRec->rec.audioCtrl.downLink);
3066 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07003067 break;
Wink Savillea592eeb2009-05-22 13:26:36 -07003068 case RIL_CDMA_T53_RELEASE_INFO_REC:
3069 // TODO(Moto): See David Krause, he has the answer:)
Wink Saville8eb2a122012-11-19 16:05:13 -08003070 RLOGE("RIL_CDMA_T53_RELEASE_INFO_REC: return INVALID_RESPONSE");
Wink Savillea592eeb2009-05-22 13:26:36 -07003071 return RIL_ERRNO_INVALID_RESPONSE;
3072 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08003073 RLOGE("Incorrect name value");
Wink Savillea592eeb2009-05-22 13:26:36 -07003074 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07003075 }
3076 }
Wink Savillea592eeb2009-05-22 13:26:36 -07003077 closeResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07003078
Wink Savillea592eeb2009-05-22 13:26:36 -07003079 return 0;
Wink Saville3d54e742009-05-18 18:00:44 -07003080}
3081
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003082static void responseRilSignalStrengthV5(Parcel &p, int slotId, int requestNumber, int responseType,
3083 int token, RIL_Errno e, RIL_SignalStrength_v10 *p_cur) {
Sanket Padawe4c05f352016-01-26 16:19:00 -08003084 p.writeInt32(p_cur->GW_SignalStrength.signalStrength);
3085 p.writeInt32(p_cur->GW_SignalStrength.bitErrorRate);
3086 p.writeInt32(p_cur->CDMA_SignalStrength.dbm);
3087 p.writeInt32(p_cur->CDMA_SignalStrength.ecio);
3088 p.writeInt32(p_cur->EVDO_SignalStrength.dbm);
3089 p.writeInt32(p_cur->EVDO_SignalStrength.ecio);
3090 p.writeInt32(p_cur->EVDO_SignalStrength.signalNoiseRatio);
3091}
3092
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003093static void responseRilSignalStrengthV6Extra(Parcel &p, int slotId, int requestNumber,
3094 int responseType, int token, RIL_Errno e, RIL_SignalStrength_v10 *p_cur) {
Sanket Padawe4c05f352016-01-26 16:19:00 -08003095 /*
3096 * Fixup LTE for backwards compatibility
3097 */
3098 // signalStrength: -1 -> 99
3099 if (p_cur->LTE_SignalStrength.signalStrength == -1) {
3100 p_cur->LTE_SignalStrength.signalStrength = 99;
3101 }
3102 // rsrp: -1 -> INT_MAX all other negative value to positive.
3103 // So remap here
3104 if (p_cur->LTE_SignalStrength.rsrp == -1) {
3105 p_cur->LTE_SignalStrength.rsrp = INT_MAX;
3106 } else if (p_cur->LTE_SignalStrength.rsrp < -1) {
3107 p_cur->LTE_SignalStrength.rsrp = -p_cur->LTE_SignalStrength.rsrp;
3108 }
3109 // rsrq: -1 -> INT_MAX
3110 if (p_cur->LTE_SignalStrength.rsrq == -1) {
3111 p_cur->LTE_SignalStrength.rsrq = INT_MAX;
3112 }
3113 // Not remapping rssnr is already using INT_MAX
3114
3115 // cqi: -1 -> INT_MAX
3116 if (p_cur->LTE_SignalStrength.cqi == -1) {
3117 p_cur->LTE_SignalStrength.cqi = INT_MAX;
3118 }
3119
3120 p.writeInt32(p_cur->LTE_SignalStrength.signalStrength);
3121 p.writeInt32(p_cur->LTE_SignalStrength.rsrp);
3122 p.writeInt32(p_cur->LTE_SignalStrength.rsrq);
3123 p.writeInt32(p_cur->LTE_SignalStrength.rssnr);
3124 p.writeInt32(p_cur->LTE_SignalStrength.cqi);
3125}
3126
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003127static void responseRilSignalStrengthV10(Parcel &p, int slotId, int requestNumber, int responseType,
3128 int token, RIL_Errno e, RIL_SignalStrength_v10 *p_cur) {
3129 responseRilSignalStrengthV5(p, slotId, requestNumber, responseType, token, e, p_cur);
3130 responseRilSignalStrengthV6Extra(p, slotId, requestNumber, responseType, token, e, p_cur);
Sanket Padawe4c05f352016-01-26 16:19:00 -08003131 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
3132}
3133
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003134static int responseRilSignalStrength(Parcel &p, int slotId, int requestNumber, int responseType,
3135 int token, RIL_Errno e, void *response, size_t responselen) {
Wink Savillea592eeb2009-05-22 13:26:36 -07003136 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003137 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07003138 return RIL_ERRNO_INVALID_RESPONSE;
3139 }
3140
Sanket Padawe626099e2016-06-08 14:09:26 -07003141 RIL_SignalStrength_v10 *p_cur;
Sanket Padawe4c05f352016-01-26 16:19:00 -08003142 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
3143 if (responselen >= sizeof (RIL_SignalStrength_v5)) {
Sanket Padawe626099e2016-06-08 14:09:26 -07003144 p_cur = ((RIL_SignalStrength_v10 *) response);
Wink Saville3d54e742009-05-18 18:00:44 -07003145
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003146 responseRilSignalStrengthV5(p, slotId, requestNumber, responseType, token, e, p_cur);
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07003147
Sanket Padawe4c05f352016-01-26 16:19:00 -08003148 if (responselen >= sizeof (RIL_SignalStrength_v6)) {
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003149 responseRilSignalStrengthV6Extra(p, slotId, requestNumber, responseType, token, e,
3150 p_cur);
Sanket Padawe4c05f352016-01-26 16:19:00 -08003151 if (responselen >= sizeof (RIL_SignalStrength_v10)) {
3152 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
3153 } else {
3154 p.writeInt32(INT_MAX);
Wink Saville18e4ab12013-04-07 17:31:04 -07003155 }
Etan Cohend3652192014-06-20 08:28:44 -07003156 } else {
Sanket Padawe4c05f352016-01-26 16:19:00 -08003157 p.writeInt32(99);
3158 p.writeInt32(INT_MAX);
3159 p.writeInt32(INT_MAX);
3160 p.writeInt32(INT_MAX);
3161 p.writeInt32(INT_MAX);
Etan Cohend3652192014-06-20 08:28:44 -07003162 p.writeInt32(INT_MAX);
3163 }
Wink Savillec0114b32011-02-18 10:14:07 -08003164 } else {
Sanket Padawe4c05f352016-01-26 16:19:00 -08003165 RLOGE("invalid response length");
3166 return RIL_ERRNO_INVALID_RESPONSE;
Wink Savillec0114b32011-02-18 10:14:07 -08003167 }
Sanket Padawe00909612016-01-26 18:44:01 -08003168 } else { // RIL version >= 13
Sanket Padawe4c05f352016-01-26 16:19:00 -08003169 if (responselen % sizeof(RIL_SignalStrength_v10) != 0) {
3170 RLOGE("Data structure expected is RIL_SignalStrength_v10");
3171 if (!isDebuggable()) {
3172 return RIL_ERRNO_INVALID_RESPONSE;
3173 } else {
3174 assert(0);
3175 }
3176 }
Sanket Padawe626099e2016-06-08 14:09:26 -07003177 p_cur = ((RIL_SignalStrength_v10 *) response);
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003178 responseRilSignalStrengthV10(p, slotId, requestNumber, responseType, token, e, p_cur);
Wink Saville3d54e742009-05-18 18:00:44 -07003179 }
Sanket Padawe4c05f352016-01-26 16:19:00 -08003180 startResponse;
3181 appendPrintBuf("%s[signalStrength=%d,bitErrorRate=%d,\
3182 CDMA_SS.dbm=%d,CDMA_SSecio=%d,\
3183 EVDO_SS.dbm=%d,EVDO_SS.ecio=%d,\
3184 EVDO_SS.signalNoiseRatio=%d,\
3185 LTE_SS.signalStrength=%d,LTE_SS.rsrp=%d,LTE_SS.rsrq=%d,\
3186 LTE_SS.rssnr=%d,LTE_SS.cqi=%d,TDSCDMA_SS.rscp=%d]",
3187 printBuf,
3188 p_cur->GW_SignalStrength.signalStrength,
3189 p_cur->GW_SignalStrength.bitErrorRate,
3190 p_cur->CDMA_SignalStrength.dbm,
3191 p_cur->CDMA_SignalStrength.ecio,
3192 p_cur->EVDO_SignalStrength.dbm,
3193 p_cur->EVDO_SignalStrength.ecio,
3194 p_cur->EVDO_SignalStrength.signalNoiseRatio,
3195 p_cur->LTE_SignalStrength.signalStrength,
3196 p_cur->LTE_SignalStrength.rsrp,
3197 p_cur->LTE_SignalStrength.rsrq,
3198 p_cur->LTE_SignalStrength.rssnr,
3199 p_cur->LTE_SignalStrength.cqi,
3200 p_cur->TD_SCDMA_SignalStrength.rscp);
3201 closeResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07003202 return 0;
3203}
3204
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003205static int responseCallRing(Parcel &p, int slotId, int requestNumber, int responseType, int token,
3206 RIL_Errno e, void *response, size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07003207 if ((response == NULL) || (responselen == 0)) {
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003208 return responseVoid(p, slotId, requestNumber, responseType, token, e, response,
3209 responselen);
Wink Saville3d54e742009-05-18 18:00:44 -07003210 } else {
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003211 return responseCdmaSignalInfoRecord(p, slotId, requestNumber, responseType, token, e,
3212 response, responselen);
Wink Saville3d54e742009-05-18 18:00:44 -07003213 }
3214}
3215
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003216static int responseCdmaSignalInfoRecord(Parcel &p, int slotId, int requestNumber, int responseType,
3217 int token, RIL_Errno e, void *response, size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07003218 if (response == NULL || responselen == 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003219 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07003220 return RIL_ERRNO_INVALID_RESPONSE;
3221 }
3222
3223 if (responselen != sizeof (RIL_CDMA_SignalInfoRecord)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003224 RLOGE("invalid response length %d expected sizeof (RIL_CDMA_SignalInfoRecord) of %d\n",
Wink Saville3d54e742009-05-18 18:00:44 -07003225 (int)responselen, (int)sizeof (RIL_CDMA_SignalInfoRecord));
3226 return RIL_ERRNO_INVALID_RESPONSE;
3227 }
3228
3229 startResponse;
3230
3231 RIL_CDMA_SignalInfoRecord *p_cur = ((RIL_CDMA_SignalInfoRecord *) response);
3232 marshallSignalInfoRecord(p, *p_cur);
3233
3234 appendPrintBuf("%s[isPresent=%d,signalType=%d,alertPitch=%d\
3235 signal=%d]",
3236 printBuf,
3237 p_cur->isPresent,
3238 p_cur->signalType,
3239 p_cur->alertPitch,
3240 p_cur->signal);
3241
3242 closeResponse;
3243 return 0;
3244}
3245
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003246static int responseCdmaCallWaiting(Parcel &p, int slotId, int requestNumber, int responseType,
3247 int token, RIL_Errno e, void *response, size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07003248 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003249 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07003250 return RIL_ERRNO_INVALID_RESPONSE;
3251 }
3252
Wink Savillec0114b32011-02-18 10:14:07 -08003253 if (responselen < sizeof(RIL_CDMA_CallWaiting_v6)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003254 RLOGW("Upgrade to ril version %d\n", RIL_VERSION);
Wink Savillec0114b32011-02-18 10:14:07 -08003255 }
3256
3257 RIL_CDMA_CallWaiting_v6 *p_cur = ((RIL_CDMA_CallWaiting_v6 *) response);
3258
3259 writeStringToParcel(p, p_cur->number);
3260 p.writeInt32(p_cur->numberPresentation);
3261 writeStringToParcel(p, p_cur->name);
3262 marshallSignalInfoRecord(p, p_cur->signalInfoRecord);
3263
Sanket Padawe4c05f352016-01-26 16:19:00 -08003264 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
3265 if (responselen >= sizeof(RIL_CDMA_CallWaiting_v6)) {
3266 p.writeInt32(p_cur->number_type);
3267 p.writeInt32(p_cur->number_plan);
3268 } else {
3269 p.writeInt32(0);
3270 p.writeInt32(0);
3271 }
Sanket Padawe00909612016-01-26 18:44:01 -08003272 } else { // RIL version >= 13
Sanket Padawe4c05f352016-01-26 16:19:00 -08003273 if (responselen % sizeof(RIL_CDMA_CallWaiting_v6) != 0) {
3274 RLOGE("Data structure expected is RIL_CDMA_CallWaiting_v6");
3275 if (!isDebuggable()) {
3276 return RIL_ERRNO_INVALID_RESPONSE;
3277 } else {
3278 assert(0);
3279 }
3280 }
Wink Savillec0114b32011-02-18 10:14:07 -08003281 p.writeInt32(p_cur->number_type);
3282 p.writeInt32(p_cur->number_plan);
Wink Saville3d54e742009-05-18 18:00:44 -07003283 }
3284
3285 startResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07003286 appendPrintBuf("%snumber=%s,numberPresentation=%d, name=%s,\
3287 signalInfoRecord[isPresent=%d,signalType=%d,alertPitch=%d\
Wink Savillec0114b32011-02-18 10:14:07 -08003288 signal=%d,number_type=%d,number_plan=%d]",
Wink Saville3d54e742009-05-18 18:00:44 -07003289 printBuf,
3290 p_cur->number,
3291 p_cur->numberPresentation,
3292 p_cur->name,
3293 p_cur->signalInfoRecord.isPresent,
3294 p_cur->signalInfoRecord.signalType,
3295 p_cur->signalInfoRecord.alertPitch,
Wink Savillec0114b32011-02-18 10:14:07 -08003296 p_cur->signalInfoRecord.signal,
3297 p_cur->number_type,
3298 p_cur->number_plan);
Wink Saville3d54e742009-05-18 18:00:44 -07003299 closeResponse;
3300
3301 return 0;
3302}
3303
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003304static void responseSimRefreshV7(Parcel &p, int slotId, int requestNumber, int responseType,
3305 int token, RIL_Errno e, void *response) {
Sanket Padawe4c05f352016-01-26 16:19:00 -08003306 RIL_SimRefreshResponse_v7 *p_cur = ((RIL_SimRefreshResponse_v7 *) response);
3307 p.writeInt32(p_cur->result);
3308 p.writeInt32(p_cur->ef_id);
3309 writeStringToParcel(p, p_cur->aid);
3310
3311 appendPrintBuf("%sresult=%d, ef_id=%d, aid=%s",
3312 printBuf,
3313 p_cur->result,
3314 p_cur->ef_id,
3315 p_cur->aid);
3316
3317}
3318
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003319static int responseSimRefresh(Parcel &p, int slotId, int requestNumber, int responseType, int token,
3320 RIL_Errno e, void *response, size_t responselen) {
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003321 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003322 RLOGE("responseSimRefresh: invalid response: NULL");
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003323 return RIL_ERRNO_INVALID_RESPONSE;
3324 }
3325
3326 startResponse;
Sanket Padawe4c05f352016-01-26 16:19:00 -08003327 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
Sanket Padawe66701c52016-01-26 17:44:34 -08003328 if (s_callbacks.version >= 7) {
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003329 responseSimRefreshV7(p, slotId, requestNumber, responseType, token, e, response);
Sanket Padawe4c05f352016-01-26 16:19:00 -08003330 } else {
3331 int *p_cur = ((int *) response);
3332 p.writeInt32(p_cur[0]);
3333 p.writeInt32(p_cur[1]);
3334 writeStringToParcel(p, NULL);
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003335
Sanket Padawe4c05f352016-01-26 16:19:00 -08003336 appendPrintBuf("%sresult=%d, ef_id=%d",
3337 printBuf,
3338 p_cur[0],
3339 p_cur[1]);
3340 }
Sanket Padawe00909612016-01-26 18:44:01 -08003341 } else { // RIL version >= 13
Sanket Padawe4c05f352016-01-26 16:19:00 -08003342 if (responselen % sizeof(RIL_SimRefreshResponse_v7) != 0) {
3343 RLOGE("Data structure expected is RIL_SimRefreshResponse_v7");
3344 if (!isDebuggable()) {
3345 return RIL_ERRNO_INVALID_RESPONSE;
3346 } else {
3347 assert(0);
3348 }
3349 }
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003350 responseSimRefreshV7(p, slotId, requestNumber, responseType, token, e, response);
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003351
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003352 }
3353 closeResponse;
3354
3355 return 0;
3356}
3357
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003358static int responseCellInfoListV6(Parcel &p, int slotId, int requestNumber, int responseType,
3359 int token, RIL_Errno e, void *response, size_t responselen) {
Wink Saville8a9e0212013-04-09 12:11:38 -07003360 if (response == NULL && responselen != 0) {
3361 RLOGE("invalid response: NULL");
3362 return RIL_ERRNO_INVALID_RESPONSE;
3363 }
3364
3365 if (responselen % sizeof(RIL_CellInfo) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07003366 RLOGE("responseCellInfoList: invalid response length %d expected multiple of %d",
Wink Saville8a9e0212013-04-09 12:11:38 -07003367 (int)responselen, (int)sizeof(RIL_CellInfo));
3368 return RIL_ERRNO_INVALID_RESPONSE;
3369 }
3370
3371 int num = responselen / sizeof(RIL_CellInfo);
3372 p.writeInt32(num);
3373
3374 RIL_CellInfo *p_cur = (RIL_CellInfo *) response;
3375 startResponse;
3376 int i;
3377 for (i = 0; i < num; i++) {
Wink Saville8a9e0212013-04-09 12:11:38 -07003378 p.writeInt32((int)p_cur->cellInfoType);
3379 p.writeInt32(p_cur->registered);
3380 p.writeInt32(p_cur->timeStampType);
3381 p.writeInt64(p_cur->timeStamp);
3382 switch(p_cur->cellInfoType) {
3383 case RIL_CELL_INFO_TYPE_GSM: {
Wink Saville8a9e0212013-04-09 12:11:38 -07003384 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
3385 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
3386 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
3387 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
Wink Saville8a9e0212013-04-09 12:11:38 -07003388 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
3389 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3390 break;
3391 }
Wink Savillec57b3eb2013-04-17 12:51:41 -07003392 case RIL_CELL_INFO_TYPE_WCDMA: {
Wink Savillec57b3eb2013-04-17 12:51:41 -07003393 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
3394 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
3395 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
3396 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
3397 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3398 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
3399 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3400 break;
3401 }
Wink Saville8a9e0212013-04-09 12:11:38 -07003402 case RIL_CELL_INFO_TYPE_CDMA: {
Wink Saville8a9e0212013-04-09 12:11:38 -07003403 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
3404 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
3405 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
3406 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
3407 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3408
Wink Saville8a9e0212013-04-09 12:11:38 -07003409 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
3410 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
3411 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
3412 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
3413 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3414 break;
3415 }
3416 case RIL_CELL_INFO_TYPE_LTE: {
Wink Saville8a9e0212013-04-09 12:11:38 -07003417 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
3418 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
3419 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
3420 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
3421 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
3422
Wink Saville8a9e0212013-04-09 12:11:38 -07003423 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
3424 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
3425 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
3426 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
3427 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
3428 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3429 break;
3430 }
Etan Cohend3652192014-06-20 08:28:44 -07003431 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
Etan Cohend3652192014-06-20 08:28:44 -07003432 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
3433 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
3434 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
3435 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
3436 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3437 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3438 break;
3439 }
Wink Saville8a9e0212013-04-09 12:11:38 -07003440 }
3441 p_cur += 1;
3442 }
3443 removeLastChar;
3444 closeResponse;
3445
3446 return 0;
3447}
3448
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003449static int responseCellInfoListV12(Parcel &p, int slotId, int requestNumber, int responseType,
3450 int token, RIL_Errno e, void *response, size_t responselen) {
Sanket Padawe00909612016-01-26 18:44:01 -08003451 if (response == NULL && responselen != 0) {
3452 RLOGE("invalid response: NULL");
3453 return RIL_ERRNO_INVALID_RESPONSE;
3454 }
3455
3456 if (responselen % sizeof(RIL_CellInfo_v12) != 0) {
3457 RLOGE("responseCellInfoList: invalid response length %d expected multiple of %d",
3458 (int)responselen, (int)sizeof(RIL_CellInfo_v12));
3459 return RIL_ERRNO_INVALID_RESPONSE;
3460 }
3461
3462 int num = responselen / sizeof(RIL_CellInfo_v12);
3463 p.writeInt32(num);
3464
3465 RIL_CellInfo_v12 *p_cur = (RIL_CellInfo_v12 *) response;
3466 startResponse;
3467 int i;
3468 for (i = 0; i < num; i++) {
Sanket Padawe00909612016-01-26 18:44:01 -08003469 p.writeInt32((int)p_cur->cellInfoType);
3470 p.writeInt32(p_cur->registered);
3471 p.writeInt32(p_cur->timeStampType);
3472 p.writeInt64(p_cur->timeStamp);
3473 switch(p_cur->cellInfoType) {
3474 case RIL_CELL_INFO_TYPE_GSM: {
Sanket Padawe00909612016-01-26 18:44:01 -08003475 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
3476 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
3477 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
3478 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3479 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.arfcn);
3480 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.bsic);
3481 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
3482 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3483 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.timingAdvance);
3484 break;
3485 }
3486 case RIL_CELL_INFO_TYPE_WCDMA: {
Sanket Padawe00909612016-01-26 18:44:01 -08003487 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
3488 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
3489 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
3490 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
3491 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3492 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.uarfcn);
3493 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
3494 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3495 break;
3496 }
3497 case RIL_CELL_INFO_TYPE_CDMA: {
Sanket Padawe00909612016-01-26 18:44:01 -08003498 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
3499 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
3500 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
3501 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
3502 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3503
Sanket Padawe00909612016-01-26 18:44:01 -08003504 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
3505 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
3506 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
3507 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
3508 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3509 break;
3510 }
3511 case RIL_CELL_INFO_TYPE_LTE: {
Sanket Padawe00909612016-01-26 18:44:01 -08003512 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
3513 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
3514 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
3515 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
3516 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
3517 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.earfcn);
3518
Sanket Padawe00909612016-01-26 18:44:01 -08003519 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
3520 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
3521 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
3522 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
3523 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
3524 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3525 break;
3526 }
3527 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
Sanket Padawe00909612016-01-26 18:44:01 -08003528 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
3529 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
3530 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
3531 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
3532 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3533 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3534 break;
3535 }
3536 }
3537 p_cur += 1;
3538 }
3539 removeLastChar;
3540 closeResponse;
3541 return 0;
3542}
3543
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003544static int responseCellInfoList(Parcel &p, int slotId, int requestNumber, int responseType,
3545 int token, RIL_Errno e, void *response, size_t responselen) {
Sanket Padawe00909612016-01-26 18:44:01 -08003546 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
3547 if (s_callbacks.version < 12) {
3548 RLOGD("responseCellInfoList: v6");
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003549 return responseCellInfoListV6(p, slotId, requestNumber, responseType, token, e,
3550 response, responselen);
Sanket Padawe00909612016-01-26 18:44:01 -08003551 } else {
3552 RLOGD("responseCellInfoList: v12");
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003553 return responseCellInfoListV12(p, slotId, requestNumber, responseType, token, e,
3554 response, responselen);
Sanket Padawe00909612016-01-26 18:44:01 -08003555 }
3556 } else { // RIL version >= 13
3557 if (responselen % sizeof(RIL_CellInfo_v12) != 0) {
3558 RLOGE("Data structure expected is RIL_CellInfo_v12");
3559 if (!isDebuggable()) {
3560 return RIL_ERRNO_INVALID_RESPONSE;
3561 } else {
3562 assert(0);
3563 }
3564 }
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003565 return responseCellInfoListV12(p, slotId, requestNumber, responseType, token, e, response,
3566 responselen);
Sanket Padawe00909612016-01-26 18:44:01 -08003567 }
3568
3569 return 0;
3570}
3571
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003572static int responseHardwareConfig(Parcel &p, int slotId, int requestNumber, int responseType,
3573 int token, RIL_Errno e, void *response, size_t responselen) {
Etan Cohend3652192014-06-20 08:28:44 -07003574 if (response == NULL && responselen != 0) {
3575 RLOGE("invalid response: NULL");
3576 return RIL_ERRNO_INVALID_RESPONSE;
3577 }
3578
3579 if (responselen % sizeof(RIL_HardwareConfig) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07003580 RLOGE("responseHardwareConfig: invalid response length %d expected multiple of %d",
Etan Cohend3652192014-06-20 08:28:44 -07003581 (int)responselen, (int)sizeof(RIL_HardwareConfig));
3582 return RIL_ERRNO_INVALID_RESPONSE;
3583 }
3584
3585 int num = responselen / sizeof(RIL_HardwareConfig);
3586 int i;
3587 RIL_HardwareConfig *p_cur = (RIL_HardwareConfig *) response;
3588
3589 p.writeInt32(num);
3590
3591 startResponse;
3592 for (i = 0; i < num; i++) {
3593 switch (p_cur[i].type) {
3594 case RIL_HARDWARE_CONFIG_MODEM: {
3595 writeStringToParcel(p, p_cur[i].uuid);
3596 p.writeInt32((int)p_cur[i].state);
3597 p.writeInt32(p_cur[i].cfg.modem.rat);
3598 p.writeInt32(p_cur[i].cfg.modem.maxVoice);
3599 p.writeInt32(p_cur[i].cfg.modem.maxData);
3600 p.writeInt32(p_cur[i].cfg.modem.maxStandby);
3601
3602 appendPrintBuf("%s modem: uuid=%s,state=%d,rat=%08x,maxV=%d,maxD=%d,maxS=%d", printBuf,
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003603 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.modem.rat,
3604 p_cur[i].cfg.modem.maxVoice, p_cur[i].cfg.modem.maxData,
3605 p_cur[i].cfg.modem.maxStandby);
Etan Cohend3652192014-06-20 08:28:44 -07003606 break;
3607 }
3608 case RIL_HARDWARE_CONFIG_SIM: {
3609 writeStringToParcel(p, p_cur[i].uuid);
3610 p.writeInt32((int)p_cur[i].state);
3611 writeStringToParcel(p, p_cur[i].cfg.sim.modemUuid);
3612
3613 appendPrintBuf("%s sim: uuid=%s,state=%d,modem-uuid=%s", printBuf,
3614 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.sim.modemUuid);
3615 break;
3616 }
3617 }
3618 }
3619 removeLastChar;
3620 closeResponse;
3621 return 0;
3622}
3623
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003624static int responseRadioCapability(Parcel &p, int slotId, int requestNumber, int responseType,
3625 int token, RIL_Errno e, void *response, size_t responselen) {
Wink Saville8b4e4f72014-10-17 15:01:45 -07003626 if (response == NULL) {
3627 RLOGE("invalid response: NULL");
3628 return RIL_ERRNO_INVALID_RESPONSE;
3629 }
3630
3631 if (responselen != sizeof (RIL_RadioCapability) ) {
3632 RLOGE("invalid response length was %d expected %d",
3633 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3634 return RIL_ERRNO_INVALID_RESPONSE;
3635 }
3636
3637 RIL_RadioCapability *p_cur = (RIL_RadioCapability *) response;
3638 p.writeInt32(p_cur->version);
3639 p.writeInt32(p_cur->session);
3640 p.writeInt32(p_cur->phase);
3641 p.writeInt32(p_cur->rat);
3642 writeStringToParcel(p, p_cur->logicalModemUuid);
3643 p.writeInt32(p_cur->status);
3644
3645 startResponse;
3646 appendPrintBuf("%s[version=%d,session=%d,phase=%d,\
Legler Wu8caf06f2014-10-29 14:02:14 +08003647 rat=%s,logicalModemUuid=%s,status=%d]",
Wink Saville8b4e4f72014-10-17 15:01:45 -07003648 printBuf,
3649 p_cur->version,
3650 p_cur->session,
3651 p_cur->phase,
3652 p_cur->rat,
Legler Wu8caf06f2014-10-29 14:02:14 +08003653 p_cur->logicalModemUuid,
Wink Saville8b4e4f72014-10-17 15:01:45 -07003654 p_cur->status);
3655 closeResponse;
3656 return 0;
3657}
3658
Wink Saville3d54e742009-05-18 18:00:44 -07003659static void triggerEvLoop() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003660 int ret;
3661 if (!pthread_equal(pthread_self(), s_tid_dispatch)) {
3662 /* trigger event loop to wakeup. No reason to do this,
3663 * if we're in the event loop thread */
3664 do {
3665 ret = write (s_fdWakeupWrite, " ", 1);
3666 } while (ret < 0 && errno == EINTR);
3667 }
3668}
3669
Wink Saville3d54e742009-05-18 18:00:44 -07003670static void rilEventAddWakeup(struct ril_event *ev) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003671 ril_event_add(ev);
3672 triggerEvLoop();
3673}
3674
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003675static int responseGsmBrSmsCnf(Parcel &p, int slotId, int requestNumber, int responseType,
3676 int token, RIL_Errno e, void *response, size_t responselen) {
Wink Savillea592eeb2009-05-22 13:26:36 -07003677 int num = responselen / sizeof(RIL_GSM_BroadcastSmsConfigInfo *);
Wink Savillef4c4d362009-04-02 01:37:03 -07003678 p.writeInt32(num);
3679
Wink Savillef4c4d362009-04-02 01:37:03 -07003680 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07003681 RIL_GSM_BroadcastSmsConfigInfo **p_cur =
3682 (RIL_GSM_BroadcastSmsConfigInfo **) response;
3683 for (int i = 0; i < num; i++) {
3684 p.writeInt32(p_cur[i]->fromServiceId);
3685 p.writeInt32(p_cur[i]->toServiceId);
3686 p.writeInt32(p_cur[i]->fromCodeScheme);
3687 p.writeInt32(p_cur[i]->toCodeScheme);
3688 p.writeInt32(p_cur[i]->selected);
3689
3690 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId=%d, \
3691 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]",
3692 printBuf, i, p_cur[i]->fromServiceId, p_cur[i]->toServiceId,
3693 p_cur[i]->fromCodeScheme, p_cur[i]->toCodeScheme,
3694 p_cur[i]->selected);
3695 }
Wink Savillef4c4d362009-04-02 01:37:03 -07003696 closeResponse;
3697
3698 return 0;
3699}
3700
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003701static int responseCdmaBrSmsCnf(Parcel &p, int slotId, int requestNumber, int responseType,
3702 int token, RIL_Errno e, void *response, size_t responselen) {
Wink Savillea592eeb2009-05-22 13:26:36 -07003703 RIL_CDMA_BroadcastSmsConfigInfo **p_cur =
3704 (RIL_CDMA_BroadcastSmsConfigInfo **) response;
Wink Savillef4c4d362009-04-02 01:37:03 -07003705
Wink Savillea592eeb2009-05-22 13:26:36 -07003706 int num = responselen / sizeof (RIL_CDMA_BroadcastSmsConfigInfo *);
3707 p.writeInt32(num);
Wink Savillef4c4d362009-04-02 01:37:03 -07003708
3709 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07003710 for (int i = 0 ; i < num ; i++ ) {
3711 p.writeInt32(p_cur[i]->service_category);
3712 p.writeInt32(p_cur[i]->language);
3713 p.writeInt32(p_cur[i]->selected);
Wink Savillef4c4d362009-04-02 01:37:03 -07003714
Wink Savillea592eeb2009-05-22 13:26:36 -07003715 appendPrintBuf("%s [%d: srvice_category=%d, language =%d, \
3716 selected =%d], ",
3717 printBuf, i, p_cur[i]->service_category, p_cur[i]->language,
3718 p_cur[i]->selected);
Wink Savillef5903df2009-04-24 11:54:14 -07003719 }
Wink Savillea592eeb2009-05-22 13:26:36 -07003720 closeResponse;
Wink Savillef5903df2009-04-24 11:54:14 -07003721
Wink Savillef4c4d362009-04-02 01:37:03 -07003722 return 0;
3723}
3724
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003725static int responseCdmaSms(Parcel &p, int slotId, int requestNumber, int responseType, int token,
3726 RIL_Errno e, void *response, size_t responselen) {
Wink Savillef4c4d362009-04-02 01:37:03 -07003727 int num;
3728 int digitCount;
3729 int digitLimit;
3730 uint8_t uct;
3731 void* dest;
3732
Wink Saville8eb2a122012-11-19 16:05:13 -08003733 RLOGD("Inside responseCdmaSms");
Wink Savillef5903df2009-04-24 11:54:14 -07003734
Wink Savillef4c4d362009-04-02 01:37:03 -07003735 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003736 RLOGE("invalid response: NULL");
Wink Savillef4c4d362009-04-02 01:37:03 -07003737 return RIL_ERRNO_INVALID_RESPONSE;
3738 }
3739
Wink Savillef5903df2009-04-24 11:54:14 -07003740 if (responselen != sizeof(RIL_CDMA_SMS_Message)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003741 RLOGE("invalid response length was %d expected %d",
Wink Savillef5903df2009-04-24 11:54:14 -07003742 (int)responselen, (int)sizeof(RIL_CDMA_SMS_Message));
Wink Savillef4c4d362009-04-02 01:37:03 -07003743 return RIL_ERRNO_INVALID_RESPONSE;
3744 }
3745
3746 RIL_CDMA_SMS_Message *p_cur = (RIL_CDMA_SMS_Message *) response;
3747 p.writeInt32(p_cur->uTeleserviceID);
3748 p.write(&(p_cur->bIsServicePresent),sizeof(uct));
3749 p.writeInt32(p_cur->uServicecategory);
3750 p.writeInt32(p_cur->sAddress.digit_mode);
3751 p.writeInt32(p_cur->sAddress.number_mode);
3752 p.writeInt32(p_cur->sAddress.number_type);
3753 p.writeInt32(p_cur->sAddress.number_plan);
3754 p.write(&(p_cur->sAddress.number_of_digits), sizeof(uct));
3755 digitLimit= MIN((p_cur->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
3756 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3757 p.write(&(p_cur->sAddress.digits[digitCount]),sizeof(uct));
3758 }
3759
3760 p.writeInt32(p_cur->sSubAddress.subaddressType);
3761 p.write(&(p_cur->sSubAddress.odd),sizeof(uct));
3762 p.write(&(p_cur->sSubAddress.number_of_digits),sizeof(uct));
3763 digitLimit= MIN((p_cur->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
3764 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3765 p.write(&(p_cur->sSubAddress.digits[digitCount]),sizeof(uct));
3766 }
3767
3768 digitLimit= MIN((p_cur->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
3769 p.writeInt32(p_cur->uBearerDataLen);
3770 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3771 p.write(&(p_cur->aBearerData[digitCount]), sizeof(uct));
3772 }
3773
3774 startResponse;
3775 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
Wink Saville1b5fd232009-04-22 14:50:00 -07003776 sAddress.digit_mode=%d, sAddress.number_mode=%d, sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07003777 printBuf, p_cur->uTeleserviceID,p_cur->bIsServicePresent,p_cur->uServicecategory,
3778 p_cur->sAddress.digit_mode, p_cur->sAddress.number_mode,p_cur->sAddress.number_type);
3779 closeResponse;
3780
3781 return 0;
3782}
3783
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003784static int responseDcRtInfo(Parcel &p, int slotId, int requestNumber, int responseType, int token,
3785 RIL_Errno e, void *response, size_t responselen)
Wink Savillec29360a2014-07-13 05:17:28 -07003786{
3787 int num = responselen / sizeof(RIL_DcRtInfo);
3788 if ((responselen % sizeof(RIL_DcRtInfo) != 0) || (num != 1)) {
Amit Mahajan52500162014-07-29 17:36:48 -07003789 RLOGE("responseDcRtInfo: invalid response length %d expected multiple of %d",
Wink Savillec29360a2014-07-13 05:17:28 -07003790 (int)responselen, (int)sizeof(RIL_DcRtInfo));
3791 return RIL_ERRNO_INVALID_RESPONSE;
3792 }
3793
3794 startResponse;
3795 RIL_DcRtInfo *pDcRtInfo = (RIL_DcRtInfo *)response;
3796 p.writeInt64(pDcRtInfo->time);
3797 p.writeInt32(pDcRtInfo->powerState);
3798 appendPrintBuf("%s[time=%d,powerState=%d]", printBuf,
3799 pDcRtInfo->time,
3800 pDcRtInfo->powerState);
3801 closeResponse;
3802
3803 return 0;
3804}
3805
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003806static int responseLceStatus(Parcel &p, int slotId, int requestNumber, int responseType, int token,
3807 RIL_Errno e, void *response, size_t responselen) {
fengluf7408292015-04-14 14:53:55 -07003808 if (response == NULL || responselen != sizeof(RIL_LceStatusInfo)) {
3809 if (response == NULL) {
3810 RLOGE("invalid response: NULL");
3811 }
3812 else {
Meng Wangef966a32016-06-20 17:38:18 -07003813 RLOGE("responseLceStatus: invalid response length %u expecting len: %u",
3814 (unsigned)sizeof(RIL_LceStatusInfo), (unsigned)responselen);
fengluf7408292015-04-14 14:53:55 -07003815 }
3816 return RIL_ERRNO_INVALID_RESPONSE;
3817 }
3818
3819 RIL_LceStatusInfo *p_cur = (RIL_LceStatusInfo *)response;
3820 p.write((void *)p_cur, 1); // p_cur->lce_status takes one byte.
3821 p.writeInt32(p_cur->actual_interval_ms);
3822
3823 startResponse;
3824 appendPrintBuf("LCE Status: %d, actual_interval_ms: %d",
3825 p_cur->lce_status, p_cur->actual_interval_ms);
3826 closeResponse;
3827
3828 return 0;
3829}
3830
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003831static int responseLceData(Parcel &p, int slotId, int requestNumber, int responseType, int token,
3832 RIL_Errno e, void *response, size_t responselen) {
fengluf7408292015-04-14 14:53:55 -07003833 if (response == NULL || responselen != sizeof(RIL_LceDataInfo)) {
3834 if (response == NULL) {
3835 RLOGE("invalid response: NULL");
3836 }
3837 else {
Meng Wangef966a32016-06-20 17:38:18 -07003838 RLOGE("responseLceData: invalid response length %u expecting len: %u",
3839 (unsigned)sizeof(RIL_LceDataInfo), (unsigned)responselen);
fengluf7408292015-04-14 14:53:55 -07003840 }
3841 return RIL_ERRNO_INVALID_RESPONSE;
3842 }
3843
3844 RIL_LceDataInfo *p_cur = (RIL_LceDataInfo *)response;
3845 p.writeInt32(p_cur->last_hop_capacity_kbps);
3846
3847 /* p_cur->confidence_level and p_cur->lce_suspended take 1 byte each.*/
3848 p.write((void *)&(p_cur->confidence_level), 1);
3849 p.write((void *)&(p_cur->lce_suspended), 1);
3850
3851 startResponse;
Hyejin606dd672015-09-14 16:27:28 -07003852 appendPrintBuf("LCE info received: capacity %d confidence level %d \
fengluf7408292015-04-14 14:53:55 -07003853 and suspended %d",
3854 p_cur->last_hop_capacity_kbps, p_cur->confidence_level,
3855 p_cur->lce_suspended);
3856 closeResponse;
3857
3858 return 0;
3859}
3860
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003861static int responseActivityData(Parcel &p, int slotId, int requestNumber, int responseType,
3862 int token, RIL_Errno e, void *response, size_t responselen) {
Prerepa Viswanadham73157492015-05-28 00:37:32 -07003863 if (response == NULL || responselen != sizeof(RIL_ActivityStatsInfo)) {
3864 if (response == NULL) {
3865 RLOGE("invalid response: NULL");
3866 }
3867 else {
Meng Wangef966a32016-06-20 17:38:18 -07003868 RLOGE("responseActivityData: invalid response length %u expecting len: %u",
3869 (unsigned)sizeof(RIL_ActivityStatsInfo), (unsigned)responselen);
Prerepa Viswanadham73157492015-05-28 00:37:32 -07003870 }
3871 return RIL_ERRNO_INVALID_RESPONSE;
3872 }
3873
3874 RIL_ActivityStatsInfo *p_cur = (RIL_ActivityStatsInfo *)response;
3875 p.writeInt32(p_cur->sleep_mode_time_ms);
3876 p.writeInt32(p_cur->idle_mode_time_ms);
3877 for(int i = 0; i < RIL_NUM_TX_POWER_LEVELS; i++) {
3878 p.writeInt32(p_cur->tx_mode_time_ms[i]);
3879 }
3880 p.writeInt32(p_cur->rx_mode_time_ms);
3881
3882 startResponse;
Hyejin606dd672015-09-14 16:27:28 -07003883 appendPrintBuf("Modem activity info received: sleep_mode_time_ms %d idle_mode_time_ms %d \
Prerepa Viswanadham73157492015-05-28 00:37:32 -07003884 tx_mode_time_ms %d %d %d %d %d and rx_mode_time_ms %d",
3885 p_cur->sleep_mode_time_ms, p_cur->idle_mode_time_ms, p_cur->tx_mode_time_ms[0],
3886 p_cur->tx_mode_time_ms[1], p_cur->tx_mode_time_ms[2], p_cur->tx_mode_time_ms[3],
3887 p_cur->tx_mode_time_ms[4], p_cur->rx_mode_time_ms);
3888 closeResponse;
3889
3890 return 0;
3891}
3892
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003893static int responseCarrierRestrictions(Parcel &p, int slotId, int requestNumber, int responseType,
3894 int token, RIL_Errno e, void *response, size_t responselen) {
Meng Wangb4e34312016-05-12 14:54:36 -07003895 if (response == NULL) {
3896 RLOGE("invalid response: NULL");
3897 return RIL_ERRNO_INVALID_RESPONSE;
3898 }
3899 if (responselen != sizeof(RIL_CarrierRestrictions)) {
Meng Wangef966a32016-06-20 17:38:18 -07003900 RLOGE("responseCarrierRestrictions: invalid response length %u expecting len: %u",
3901 (unsigned)responselen, (unsigned)sizeof(RIL_CarrierRestrictions));
Meng Wangb4e34312016-05-12 14:54:36 -07003902 return RIL_ERRNO_INVALID_RESPONSE;
3903 }
3904
3905 RIL_CarrierRestrictions *p_cr = (RIL_CarrierRestrictions *)response;
Meng Wangb460ba82016-06-09 09:21:26 -07003906 startResponse;
3907
3908 p.writeInt32(p_cr->len_allowed_carriers);
3909 p.writeInt32(p_cr->len_excluded_carriers);
3910 appendPrintBuf(" %s len_allowed_carriers: %d, len_excluded_carriers: %d,", printBuf,
3911 p_cr->len_allowed_carriers,p_cr->len_excluded_carriers);
3912
3913 appendPrintBuf(" %s allowed_carriers:", printBuf);
3914 for(int32_t i = 0; i < p_cr->len_allowed_carriers; i++) {
Meng Wangb4e34312016-05-12 14:54:36 -07003915 RIL_Carrier *carrier = p_cr->allowed_carriers + i;
Meng Wangb460ba82016-06-09 09:21:26 -07003916 writeStringToParcel(p, carrier->mcc);
3917 writeStringToParcel(p, carrier->mnc);
Meng Wangb4e34312016-05-12 14:54:36 -07003918 p.writeInt32(carrier->match_type);
Meng Wangb460ba82016-06-09 09:21:26 -07003919 writeStringToParcel(p, carrier->match_data);
3920 appendPrintBuf(" %s [%d mcc: %s, mnc: %s, match_type: %d, match_data: %s],", printBuf,
3921 i, carrier->mcc, carrier->mnc, carrier->match_type, carrier->match_data);
Meng Wangb4e34312016-05-12 14:54:36 -07003922 }
3923
Meng Wangb460ba82016-06-09 09:21:26 -07003924 appendPrintBuf(" %s excluded_carriers:", printBuf);
3925 for(int32_t i = 0; i < p_cr->len_excluded_carriers; i++) {
3926 RIL_Carrier *carrier = p_cr->excluded_carriers + i;
3927 writeStringToParcel(p, carrier->mcc);
3928 writeStringToParcel(p, carrier->mnc);
3929 p.writeInt32(carrier->match_type);
3930 writeStringToParcel(p, carrier->match_data);
3931 appendPrintBuf(" %s [%d mcc: %s, mnc: %s, match_type: %d, match_data: %s],", printBuf,
3932 i, carrier->mcc, carrier->mnc, carrier->match_type, carrier->match_data);
3933 }
3934
Meng Wangb4e34312016-05-12 14:54:36 -07003935 closeResponse;
3936
3937 return 0;
3938}
3939
Amit Mahajan18fe36b2016-08-25 11:19:21 -07003940static int responsePcoData(Parcel &p, int slotId, int requestNumber, int responseType, int token,
3941 RIL_Errno e, void *response, size_t responselen) {
Robert Greenwalt27e99c52016-06-01 16:31:38 -07003942 if (response == NULL) {
3943 RLOGE("responsePcoData: invalid NULL response");
3944 return RIL_ERRNO_INVALID_RESPONSE;
3945 }
3946 if (responselen != sizeof(RIL_PCO_Data)) {
Meng Wangef966a32016-06-20 17:38:18 -07003947 RLOGE("responsePcoData: invalid response length %u, expecting %u",
3948 (unsigned)responselen, (unsigned)sizeof(RIL_PCO_Data));
Robert Greenwalt27e99c52016-06-01 16:31:38 -07003949 return RIL_ERRNO_INVALID_RESPONSE;
3950 }
3951
3952 RIL_PCO_Data *p_cur = (RIL_PCO_Data *)response;
3953 p.writeInt32(p_cur->cid);
3954 writeStringToParcel(p, p_cur->bearer_proto);
3955 p.writeInt32(p_cur->pco_id);
3956 p.writeInt32(p_cur->contents_length);
3957 p.write(p_cur->contents, p_cur->contents_length);
3958
3959 startResponse;
3960 appendPrintBuf("PCO data received: cid %d, id %d, length %d",
3961 p_cur->cid, p_cur->pco_id, p_cur->contents_length);
3962 closeResponse;
3963
3964 return 0;
3965}
3966
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003967/**
3968 * A write on the wakeup fd is done just to pop us out of select()
3969 * We empty the buffer here and then ril_event will reset the timers on the
3970 * way back down
3971 */
Wink Savillef4c4d362009-04-02 01:37:03 -07003972static void processWakeupCallback(int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003973 char buff[16];
3974 int ret;
3975
Wink Saville8eb2a122012-11-19 16:05:13 -08003976 RLOGV("processWakeupCallback");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003977
3978 /* empty our wakeup socket out */
3979 do {
3980 ret = read(s_fdWakeupRead, &buff, sizeof(buff));
Wink Saville7f856802009-06-09 10:23:37 -07003981 } while (ret > 0 || (ret < 0 && errno == EINTR));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003982}
3983
Etan Cohend3652192014-06-20 08:28:44 -07003984static void onCommandsSocketClosed(RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003985 int ret;
3986 RequestInfo *p_cur;
Etan Cohend3652192014-06-20 08:28:44 -07003987 /* Hook for current context
3988 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
3989 pthread_mutex_t * pendingRequestsMutexHook = &s_pendingRequestsMutex;
3990 /* pendingRequestsHook refer to &s_pendingRequests */
3991 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003992
Etan Cohend3652192014-06-20 08:28:44 -07003993#if (SIM_COUNT >= 2)
3994 if (socket_id == RIL_SOCKET_2) {
3995 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
3996 pendingRequestsHook = &s_pendingRequests_socket2;
3997 }
3998#if (SIM_COUNT >= 3)
3999 else if (socket_id == RIL_SOCKET_3) {
4000 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
4001 pendingRequestsHook = &s_pendingRequests_socket3;
4002 }
4003#endif
4004#if (SIM_COUNT >= 4)
4005 else if (socket_id == RIL_SOCKET_4) {
4006 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
4007 pendingRequestsHook = &s_pendingRequests_socket4;
4008 }
4009#endif
4010#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004011 /* mark pending requests as "cancelled" so we dont report responses */
Etan Cohend3652192014-06-20 08:28:44 -07004012 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004013 assert (ret == 0);
4014
Etan Cohend3652192014-06-20 08:28:44 -07004015 p_cur = *pendingRequestsHook;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004016
Etan Cohend3652192014-06-20 08:28:44 -07004017 for (p_cur = *pendingRequestsHook
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004018 ; p_cur != NULL
4019 ; p_cur = p_cur->p_next
4020 ) {
4021 p_cur->cancelled = 1;
4022 }
4023
Etan Cohend3652192014-06-20 08:28:44 -07004024 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004025 assert (ret == 0);
4026}
4027
Wink Savillef4c4d362009-04-02 01:37:03 -07004028static void processCommandsCallback(int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004029 RecordStream *p_rs;
4030 void *p_record;
4031 size_t recordlen;
4032 int ret;
Etan Cohend3652192014-06-20 08:28:44 -07004033 SocketListenParam *p_info = (SocketListenParam *)param;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004034
Etan Cohend3652192014-06-20 08:28:44 -07004035 assert(fd == p_info->fdCommand);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004036
Etan Cohend3652192014-06-20 08:28:44 -07004037 p_rs = p_info->p_rs;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004038
4039 for (;;) {
4040 /* loop until EAGAIN/EINTR, end of stream, or other error */
4041 ret = record_stream_get_next(p_rs, &p_record, &recordlen);
4042
4043 if (ret == 0 && p_record == NULL) {
4044 /* end-of-stream */
4045 break;
4046 } else if (ret < 0) {
4047 break;
4048 } else if (ret == 0) { /* && p_record != NULL */
Etan Cohend3652192014-06-20 08:28:44 -07004049 processCommandBuffer(p_record, recordlen, p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004050 }
4051 }
4052
4053 if (ret == 0 || !(errno == EAGAIN || errno == EINTR)) {
4054 /* fatal error or end-of-stream */
4055 if (ret != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004056 RLOGE("error on reading command socket errno:%d\n", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004057 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08004058 RLOGW("EOS. Closing command socket.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004059 }
Wink Saville7f856802009-06-09 10:23:37 -07004060
Etan Cohend3652192014-06-20 08:28:44 -07004061 close(fd);
4062 p_info->fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004063
Etan Cohend3652192014-06-20 08:28:44 -07004064 ril_event_del(p_info->commands_event);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004065
4066 record_stream_free(p_rs);
4067
4068 /* start listening for new connections again */
4069 rilEventAddWakeup(&s_listen_event);
4070
Etan Cohend3652192014-06-20 08:28:44 -07004071 onCommandsSocketClosed(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004072 }
4073}
4074
4075
Etan Cohend3652192014-06-20 08:28:44 -07004076static void onNewCommandConnect(RIL_SOCKET_ID socket_id) {
Wink Saville5b9df332011-04-06 16:24:21 -07004077 // Inform we are connected and the ril version
Jake Hambya9c18d12011-04-12 23:32:08 -07004078 int rilVer = s_callbacks.version;
Etan Cohend3652192014-06-20 08:28:44 -07004079 RIL_UNSOL_RESPONSE(RIL_UNSOL_RIL_CONNECTED,
4080 &rilVer, sizeof(rilVer), socket_id);
Wink Saville5b9df332011-04-06 16:24:21 -07004081
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004082 // implicit radio state changed
Etan Cohend3652192014-06-20 08:28:44 -07004083 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
4084 NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004085
4086 // Send last NITZ time data, in case it was missed
4087 if (s_lastNITZTimeData != NULL) {
Etan Cohend3652192014-06-20 08:28:44 -07004088 sendResponseRaw(s_lastNITZTimeData, s_lastNITZTimeDataSize, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004089
4090 free(s_lastNITZTimeData);
4091 s_lastNITZTimeData = NULL;
4092 }
4093
4094 // Get version string
4095 if (s_callbacks.getVersion != NULL) {
4096 const char *version;
4097 version = s_callbacks.getVersion();
Wink Saville8eb2a122012-11-19 16:05:13 -08004098 RLOGI("RIL Daemon version: %s\n", version);
Wink Saville7f856802009-06-09 10:23:37 -07004099
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004100 property_set(PROPERTY_RIL_IMPL, version);
4101 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08004102 RLOGI("RIL Daemon version: unavailable\n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004103 property_set(PROPERTY_RIL_IMPL, "unavailable");
4104 }
4105
4106}
4107
Wink Savillef4c4d362009-04-02 01:37:03 -07004108static void listenCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004109 int ret;
4110 int err;
4111 int is_phone_socket;
Etan Cohend3652192014-06-20 08:28:44 -07004112 int fdCommand = -1;
Meng Wangef966a32016-06-20 17:38:18 -07004113 const char* processName;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004114 RecordStream *p_rs;
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004115 MySocketListenParam* listenParam;
4116 RilSocket *sapSocket = NULL;
4117 socketClient *sClient = NULL;
4118
Etan Cohend3652192014-06-20 08:28:44 -07004119 SocketListenParam *p_info = (SocketListenParam *)param;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004120
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004121 if(RIL_SAP_SOCKET == p_info->type) {
4122 listenParam = (MySocketListenParam *)param;
4123 sapSocket = listenParam->socket;
4124 }
4125
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004126 struct sockaddr_un peeraddr;
4127 socklen_t socklen = sizeof (peeraddr);
4128
4129 struct ucred creds;
4130 socklen_t szCreds = sizeof(creds);
4131
4132 struct passwd *pwd = NULL;
4133
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004134 if(NULL == sapSocket) {
George Burgess IVd9cee0a2016-10-27 22:51:30 -07004135 assert (p_info->fdCommand < 0);
4136 assert (fd == p_info->fdListen);
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004137 processName = PHONE_PROCESS;
4138 } else {
George Burgess IVd9cee0a2016-10-27 22:51:30 -07004139 assert (sapSocket->getCommandFd() < 0);
4140 assert (fd == sapSocket->getListenFd());
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004141 processName = BLUETOOTH_PROCESS;
4142 }
4143
Wink Saville7f856802009-06-09 10:23:37 -07004144
Etan Cohend3652192014-06-20 08:28:44 -07004145 fdCommand = accept(fd, (sockaddr *) &peeraddr, &socklen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004146
Etan Cohend3652192014-06-20 08:28:44 -07004147 if (fdCommand < 0 ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004148 RLOGE("Error on accept() errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004149 /* start listening for new connections again */
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004150 if(NULL == sapSocket) {
4151 rilEventAddWakeup(p_info->listen_event);
4152 } else {
4153 rilEventAddWakeup(sapSocket->getListenEvent());
4154 }
Etan Cohend3652192014-06-20 08:28:44 -07004155 return;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004156 }
4157
4158 /* check the credential of the other side and only accept socket from
4159 * phone process
Wink Saville7f856802009-06-09 10:23:37 -07004160 */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004161 errno = 0;
4162 is_phone_socket = 0;
Wink Savillef4c4d362009-04-02 01:37:03 -07004163
Etan Cohend3652192014-06-20 08:28:44 -07004164 err = getsockopt(fdCommand, SOL_SOCKET, SO_PEERCRED, &creds, &szCreds);
Wink Savillef4c4d362009-04-02 01:37:03 -07004165
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004166 if (err == 0 && szCreds > 0) {
Wink Savillef4c4d362009-04-02 01:37:03 -07004167 errno = 0;
4168 pwd = getpwuid(creds.uid);
4169 if (pwd != NULL) {
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004170 if (strcmp(pwd->pw_name, processName) == 0) {
Wink Savillef4c4d362009-04-02 01:37:03 -07004171 is_phone_socket = 1;
4172 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08004173 RLOGE("RILD can't accept socket from process %s", pwd->pw_name);
Wink Savillef4c4d362009-04-02 01:37:03 -07004174 }
4175 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08004176 RLOGE("Error on getpwuid() errno: %d", errno);
Wink Savillef4c4d362009-04-02 01:37:03 -07004177 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004178 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08004179 RLOGD("Error on getsockopt() errno: %d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004180 }
4181
Etan Cohend3652192014-06-20 08:28:44 -07004182 if (!is_phone_socket) {
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004183 RLOGE("RILD must accept socket from %s", processName);
Wink Saville7f856802009-06-09 10:23:37 -07004184
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004185 close(fdCommand);
4186 fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004187
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004188 if(NULL == sapSocket) {
4189 onCommandsSocketClosed(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004190
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004191 /* start listening for new connections again */
4192 rilEventAddWakeup(p_info->listen_event);
4193 } else {
4194 sapSocket->onCommandsSocketClosed();
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004195
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004196 /* start listening for new connections again */
4197 rilEventAddWakeup(sapSocket->getListenEvent());
4198 }
4199
4200 return;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004201 }
4202
Etan Cohend3652192014-06-20 08:28:44 -07004203 ret = fcntl(fdCommand, F_SETFL, O_NONBLOCK);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004204
4205 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004206 RLOGE ("Error setting O_NONBLOCK errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004207 }
4208
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004209 if(NULL == sapSocket) {
4210 RLOGI("libril: new connection to %s", rilSocketIdToString(p_info->socket_id));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004211
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004212 p_info->fdCommand = fdCommand;
4213 p_rs = record_stream_new(p_info->fdCommand, MAX_COMMAND_BYTES);
4214 p_info->p_rs = p_rs;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004215
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004216 ril_event_set (p_info->commands_event, p_info->fdCommand, 1,
Etan Cohend3652192014-06-20 08:28:44 -07004217 p_info->processCommandsCallback, p_info);
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004218 rilEventAddWakeup (p_info->commands_event);
Etan Cohend3652192014-06-20 08:28:44 -07004219
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004220 onNewCommandConnect(p_info->socket_id);
4221 } else {
4222 RLOGI("libril: new connection");
Etan Cohend3652192014-06-20 08:28:44 -07004223
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004224 sapSocket->setCommandFd(fdCommand);
4225 p_rs = record_stream_new(sapSocket->getCommandFd(), MAX_COMMAND_BYTES);
4226 sClient = new socketClient(sapSocket,p_rs);
4227 ril_event_set (sapSocket->getCallbackEvent(), sapSocket->getCommandFd(), 1,
4228 sapSocket->getCommandCb(), sClient);
4229
4230 rilEventAddWakeup(sapSocket->getCallbackEvent());
4231 sapSocket->onNewCommandConnect();
4232 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004233}
4234
4235static void freeDebugCallbackArgs(int number, char **args) {
4236 for (int i = 0; i < number; i++) {
4237 if (args[i] != NULL) {
4238 free(args[i]);
4239 }
4240 }
4241 free(args);
4242}
4243
Wink Savillef4c4d362009-04-02 01:37:03 -07004244static void debugCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004245 int acceptFD, option;
4246 struct sockaddr_un peeraddr;
4247 socklen_t socklen = sizeof (peeraddr);
4248 int data;
4249 unsigned int qxdm_data[6];
4250 const char *deactData[1] = {"1"};
4251 char *actData[1];
4252 RIL_Dial dialData;
4253 int hangupData[1] = {1};
4254 int number;
4255 char **args;
Etan Cohend3652192014-06-20 08:28:44 -07004256 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
4257 int sim_id = 0;
4258
4259 RLOGI("debugCallback for socket %s", rilSocketIdToString(socket_id));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004260
4261 acceptFD = accept (fd, (sockaddr *) &peeraddr, &socklen);
4262
4263 if (acceptFD < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004264 RLOGE ("error accepting on debug port: %d\n", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004265 return;
4266 }
4267
4268 if (recv(acceptFD, &number, sizeof(int), 0) != sizeof(int)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004269 RLOGE ("error reading on socket: number of Args: \n");
Sanket Padawe55227b52016-02-29 10:09:26 -08004270 close(acceptFD);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004271 return;
4272 }
Sanket Padawe55227b52016-02-29 10:09:26 -08004273
Sanket Padawe0cfc5532016-03-07 17:12:19 -08004274 if (number < 0) {
4275 RLOGE ("Invalid number of arguments: \n");
4276 close(acceptFD);
4277 return;
4278 }
4279
4280 args = (char **) calloc(number, sizeof(char*));
Sanket Padawe55227b52016-02-29 10:09:26 -08004281 if (args == NULL) {
4282 RLOGE("Memory allocation failed for debug args");
4283 close(acceptFD);
4284 return;
4285 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004286
4287 for (int i = 0; i < number; i++) {
4288 int len;
4289 if (recv(acceptFD, &len, sizeof(int), 0) != sizeof(int)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004290 RLOGE ("error reading on socket: Len of Args: \n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004291 freeDebugCallbackArgs(i, args);
Sanket Padawe55227b52016-02-29 10:09:26 -08004292 close(acceptFD);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004293 return;
4294 }
Sanket Padawe0cfc5532016-03-07 17:12:19 -08004295 if (len == INT_MAX || len < 0) {
4296 RLOGE("Invalid value of len: \n");
4297 freeDebugCallbackArgs(i, args);
4298 close(acceptFD);
4299 return;
4300 }
Sanket Padawe55227b52016-02-29 10:09:26 -08004301
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004302 // +1 for null-term
Sanket Padawe0cfc5532016-03-07 17:12:19 -08004303 args[i] = (char *) calloc(len + 1, sizeof(char));
Sanket Padawe55227b52016-02-29 10:09:26 -08004304 if (args[i] == NULL) {
4305 RLOGE("Memory allocation failed for debug args");
4306 freeDebugCallbackArgs(i, args);
4307 close(acceptFD);
4308 return;
4309 }
Wink Saville7f856802009-06-09 10:23:37 -07004310 if (recv(acceptFD, args[i], sizeof(char) * len, 0)
Wink Saville1b5fd232009-04-22 14:50:00 -07004311 != (int)sizeof(char) * len) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004312 RLOGE ("error reading on socket: Args[%d] \n", i);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004313 freeDebugCallbackArgs(i, args);
Sanket Padawe55227b52016-02-29 10:09:26 -08004314 close(acceptFD);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004315 return;
4316 }
4317 char * buf = args[i];
4318 buf[len] = 0;
Etan Cohend3652192014-06-20 08:28:44 -07004319 if ((i+1) == number) {
4320 /* The last argument should be sim id 0(SIM1)~3(SIM4) */
4321 sim_id = atoi(args[i]);
4322 switch (sim_id) {
4323 case 0:
4324 socket_id = RIL_SOCKET_1;
4325 break;
4326 #if (SIM_COUNT >= 2)
4327 case 1:
4328 socket_id = RIL_SOCKET_2;
4329 break;
4330 #endif
4331 #if (SIM_COUNT >= 3)
4332 case 2:
4333 socket_id = RIL_SOCKET_3;
4334 break;
4335 #endif
4336 #if (SIM_COUNT >= 4)
4337 case 3:
4338 socket_id = RIL_SOCKET_4;
4339 break;
4340 #endif
4341 default:
4342 socket_id = RIL_SOCKET_1;
4343 break;
4344 }
4345 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004346 }
4347
4348 switch (atoi(args[0])) {
4349 case 0:
Wink Saville8eb2a122012-11-19 16:05:13 -08004350 RLOGI ("Connection on debug port: issuing reset.");
Etan Cohend3652192014-06-20 08:28:44 -07004351 issueLocalRequest(RIL_REQUEST_RESET_RADIO, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004352 break;
4353 case 1:
Wink Saville8eb2a122012-11-19 16:05:13 -08004354 RLOGI ("Connection on debug port: issuing radio power off.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004355 data = 0;
Etan Cohend3652192014-06-20 08:28:44 -07004356 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004357 // Close the socket
Etan Cohend3652192014-06-20 08:28:44 -07004358 if (socket_id == RIL_SOCKET_1 && s_ril_param_socket.fdCommand > 0) {
4359 close(s_ril_param_socket.fdCommand);
4360 s_ril_param_socket.fdCommand = -1;
4361 }
4362 #if (SIM_COUNT == 2)
4363 else if (socket_id == RIL_SOCKET_2 && s_ril_param_socket2.fdCommand > 0) {
4364 close(s_ril_param_socket2.fdCommand);
4365 s_ril_param_socket2.fdCommand = -1;
4366 }
4367 #endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004368 break;
4369 case 2:
Wink Saville8eb2a122012-11-19 16:05:13 -08004370 RLOGI ("Debug port: issuing unsolicited voice network change.");
Etan Cohend3652192014-06-20 08:28:44 -07004371 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004372 break;
4373 case 3:
Wink Saville8eb2a122012-11-19 16:05:13 -08004374 RLOGI ("Debug port: QXDM log enable.");
Xia Wangd855ef42010-07-27 17:26:55 -07004375 qxdm_data[0] = 65536; // head.func_tag
4376 qxdm_data[1] = 16; // head.len
4377 qxdm_data[2] = 1; // mode: 1 for 'start logging'
4378 qxdm_data[3] = 32; // log_file_size: 32megabytes
4379 qxdm_data[4] = 0; // log_mask
4380 qxdm_data[5] = 8; // log_max_fileindex
Wink Saville7f856802009-06-09 10:23:37 -07004381 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Etan Cohend3652192014-06-20 08:28:44 -07004382 6 * sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004383 break;
4384 case 4:
Wink Saville8eb2a122012-11-19 16:05:13 -08004385 RLOGI ("Debug port: QXDM log disable.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004386 qxdm_data[0] = 65536;
4387 qxdm_data[1] = 16;
Xia Wangd855ef42010-07-27 17:26:55 -07004388 qxdm_data[2] = 0; // mode: 0 for 'stop logging'
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004389 qxdm_data[3] = 32;
4390 qxdm_data[4] = 0;
Xia Wangd855ef42010-07-27 17:26:55 -07004391 qxdm_data[5] = 8;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004392 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Etan Cohend3652192014-06-20 08:28:44 -07004393 6 * sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004394 break;
4395 case 5:
Wink Saville8eb2a122012-11-19 16:05:13 -08004396 RLOGI("Debug port: Radio On");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004397 data = 1;
Etan Cohend3652192014-06-20 08:28:44 -07004398 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004399 sleep(2);
4400 // Set network selection automatic.
Etan Cohend3652192014-06-20 08:28:44 -07004401 issueLocalRequest(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004402 break;
4403 case 6:
Wink Saville8eb2a122012-11-19 16:05:13 -08004404 RLOGI("Debug port: Setup Data Call, Apn :%s\n", args[1]);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004405 actData[0] = args[1];
Wink Saville7f856802009-06-09 10:23:37 -07004406 issueLocalRequest(RIL_REQUEST_SETUP_DATA_CALL, &actData,
Etan Cohend3652192014-06-20 08:28:44 -07004407 sizeof(actData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004408 break;
4409 case 7:
Wink Saville8eb2a122012-11-19 16:05:13 -08004410 RLOGI("Debug port: Deactivate Data Call");
Wink Saville7f856802009-06-09 10:23:37 -07004411 issueLocalRequest(RIL_REQUEST_DEACTIVATE_DATA_CALL, &deactData,
Etan Cohend3652192014-06-20 08:28:44 -07004412 sizeof(deactData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004413 break;
4414 case 8:
Wink Saville8eb2a122012-11-19 16:05:13 -08004415 RLOGI("Debug port: Dial Call");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004416 dialData.clir = 0;
4417 dialData.address = args[1];
Etan Cohend3652192014-06-20 08:28:44 -07004418 issueLocalRequest(RIL_REQUEST_DIAL, &dialData, sizeof(dialData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004419 break;
4420 case 9:
Wink Saville8eb2a122012-11-19 16:05:13 -08004421 RLOGI("Debug port: Answer Call");
Etan Cohend3652192014-06-20 08:28:44 -07004422 issueLocalRequest(RIL_REQUEST_ANSWER, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004423 break;
4424 case 10:
Wink Saville8eb2a122012-11-19 16:05:13 -08004425 RLOGI("Debug port: End Call");
Wink Saville7f856802009-06-09 10:23:37 -07004426 issueLocalRequest(RIL_REQUEST_HANGUP, &hangupData,
Etan Cohend3652192014-06-20 08:28:44 -07004427 sizeof(hangupData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004428 break;
4429 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004430 RLOGE ("Invalid request");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004431 break;
4432 }
4433 freeDebugCallbackArgs(number, args);
4434 close(acceptFD);
4435}
4436
4437
Wink Savillef4c4d362009-04-02 01:37:03 -07004438static void userTimerCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004439 UserCallbackInfo *p_info;
4440
4441 p_info = (UserCallbackInfo *)param;
4442
4443 p_info->p_callback(p_info->userParam);
4444
4445
4446 // FIXME generalize this...there should be a cancel mechanism
4447 if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) {
4448 s_last_wake_timeout_info = NULL;
4449 }
4450
4451 free(p_info);
4452}
4453
4454
4455static void *
Wink Savillef4c4d362009-04-02 01:37:03 -07004456eventLoop(void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004457 int ret;
4458 int filedes[2];
4459
4460 ril_event_init();
4461
4462 pthread_mutex_lock(&s_startupMutex);
4463
4464 s_started = 1;
4465 pthread_cond_broadcast(&s_startupCond);
4466
4467 pthread_mutex_unlock(&s_startupMutex);
4468
4469 ret = pipe(filedes);
4470
4471 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004472 RLOGE("Error in pipe() errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004473 return NULL;
4474 }
4475
4476 s_fdWakeupRead = filedes[0];
4477 s_fdWakeupWrite = filedes[1];
4478
4479 fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK);
4480
4481 ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,
4482 processWakeupCallback, NULL);
4483
4484 rilEventAddWakeup (&s_wakeupfd_event);
4485
4486 // Only returns on error
4487 ril_event_loop();
Wink Saville8eb2a122012-11-19 16:05:13 -08004488 RLOGE ("error in event_loop_base errno:%d", errno);
Kazuhiro Ondo5cdc1352011-10-14 17:50:58 -05004489 // kill self to restart on error
4490 kill(0, SIGKILL);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004491
4492 return NULL;
4493}
4494
Wink Saville7f856802009-06-09 10:23:37 -07004495extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07004496RIL_startEventLoop(void) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004497 /* spin up eventLoop thread and wait for it to get started */
4498 s_started = 0;
4499 pthread_mutex_lock(&s_startupMutex);
4500
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004501 pthread_attr_t attr;
4502 pthread_attr_init(&attr);
Wink Saville7f856802009-06-09 10:23:37 -07004503 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004504
Elliott Hughesfd81e712014-01-06 12:46:02 -08004505 int result = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
4506 if (result != 0) {
4507 RLOGE("Failed to create dispatch thread: %s", strerror(result));
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004508 goto done;
4509 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004510
4511 while (s_started == 0) {
4512 pthread_cond_wait(&s_startupCond, &s_startupMutex);
4513 }
4514
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004515done:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004516 pthread_mutex_unlock(&s_startupMutex);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004517}
4518
4519// Used for testing purpose only.
4520extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) {
4521 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4522}
4523
Etan Cohend3652192014-06-20 08:28:44 -07004524static void startListen(RIL_SOCKET_ID socket_id, SocketListenParam* socket_listen_p) {
4525 int fdListen = -1;
4526 int ret;
4527 char socket_name[10];
4528
4529 memset(socket_name, 0, sizeof(char)*10);
4530
4531 switch(socket_id) {
4532 case RIL_SOCKET_1:
4533 strncpy(socket_name, RIL_getRilSocketName(), 9);
4534 break;
4535 #if (SIM_COUNT >= 2)
4536 case RIL_SOCKET_2:
4537 strncpy(socket_name, SOCKET2_NAME_RIL, 9);
4538 break;
4539 #endif
4540 #if (SIM_COUNT >= 3)
4541 case RIL_SOCKET_3:
4542 strncpy(socket_name, SOCKET3_NAME_RIL, 9);
4543 break;
4544 #endif
4545 #if (SIM_COUNT >= 4)
4546 case RIL_SOCKET_4:
4547 strncpy(socket_name, SOCKET4_NAME_RIL, 9);
4548 break;
4549 #endif
4550 default:
4551 RLOGE("Socket id is wrong!!");
4552 return;
4553 }
4554
4555 RLOGI("Start to listen %s", rilSocketIdToString(socket_id));
4556
4557 fdListen = android_get_control_socket(socket_name);
4558 if (fdListen < 0) {
4559 RLOGE("Failed to get socket %s", socket_name);
4560 exit(-1);
4561 }
4562
4563 ret = listen(fdListen, 4);
4564
4565 if (ret < 0) {
4566 RLOGE("Failed to listen on control socket '%d': %s",
4567 fdListen, strerror(errno));
4568 exit(-1);
4569 }
4570 socket_listen_p->fdListen = fdListen;
4571
4572 /* note: non-persistent so we can accept only one connection at a time */
4573 ril_event_set (socket_listen_p->listen_event, fdListen, false,
4574 listenCallback, socket_listen_p);
4575
4576 rilEventAddWakeup (socket_listen_p->listen_event);
4577}
4578
Wink Saville7f856802009-06-09 10:23:37 -07004579extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07004580RIL_register (const RIL_RadioFunctions *callbacks) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004581 int ret;
4582 int flags;
4583
Etan Cohend3652192014-06-20 08:28:44 -07004584 RLOGI("SIM_COUNT: %d", SIM_COUNT);
4585
Wink Saville43808972011-01-13 17:39:51 -08004586 if (callbacks == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004587 RLOGE("RIL_register: RIL_RadioFunctions * null");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004588 return;
4589 }
Wink Saville43808972011-01-13 17:39:51 -08004590 if (callbacks->version < RIL_VERSION_MIN) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004591 RLOGE("RIL_register: version %d is to old, min version is %d",
Wink Saville43808972011-01-13 17:39:51 -08004592 callbacks->version, RIL_VERSION_MIN);
4593 return;
Wink Saville3a4840b2010-04-07 13:29:58 -07004594 }
Sanket Padawe4c05f352016-01-26 16:19:00 -08004595
Wink Saville8eb2a122012-11-19 16:05:13 -08004596 RLOGE("RIL_register: RIL version %d", callbacks->version);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004597
4598 if (s_registerCalled > 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004599 RLOGE("RIL_register has been called more than once. "
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004600 "Subsequent call ignored");
4601 return;
4602 }
4603
4604 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4605
Etan Cohend3652192014-06-20 08:28:44 -07004606 /* Initialize socket1 parameters */
4607 s_ril_param_socket = {
4608 RIL_SOCKET_1, /* socket_id */
4609 -1, /* fdListen */
4610 -1, /* fdCommand */
4611 PHONE_PROCESS, /* processName */
4612 &s_commands_event, /* commands_event */
4613 &s_listen_event, /* listen_event */
4614 processCommandsCallback, /* processCommandsCallback */
Meng Wangef966a32016-06-20 17:38:18 -07004615 NULL, /* p_rs */
4616 RIL_TELEPHONY_SOCKET /* type */
Etan Cohend3652192014-06-20 08:28:44 -07004617 };
4618
4619#if (SIM_COUNT >= 2)
4620 s_ril_param_socket2 = {
4621 RIL_SOCKET_2, /* socket_id */
4622 -1, /* fdListen */
4623 -1, /* fdCommand */
4624 PHONE_PROCESS, /* processName */
4625 &s_commands_event_socket2, /* commands_event */
4626 &s_listen_event_socket2, /* listen_event */
4627 processCommandsCallback, /* processCommandsCallback */
Meng Wangef966a32016-06-20 17:38:18 -07004628 NULL, /* p_rs */
4629 RIL_TELEPHONY_SOCKET /* type */
Etan Cohend3652192014-06-20 08:28:44 -07004630 };
4631#endif
4632
4633#if (SIM_COUNT >= 3)
4634 s_ril_param_socket3 = {
4635 RIL_SOCKET_3, /* socket_id */
4636 -1, /* fdListen */
4637 -1, /* fdCommand */
4638 PHONE_PROCESS, /* processName */
4639 &s_commands_event_socket3, /* commands_event */
4640 &s_listen_event_socket3, /* listen_event */
4641 processCommandsCallback, /* processCommandsCallback */
Meng Wangef966a32016-06-20 17:38:18 -07004642 NULL, /* p_rs */
4643 RIL_TELEPHONY_SOCKET /* type */
Etan Cohend3652192014-06-20 08:28:44 -07004644 };
4645#endif
4646
4647#if (SIM_COUNT >= 4)
4648 s_ril_param_socket4 = {
4649 RIL_SOCKET_4, /* socket_id */
4650 -1, /* fdListen */
4651 -1, /* fdCommand */
4652 PHONE_PROCESS, /* processName */
4653 &s_commands_event_socket4, /* commands_event */
4654 &s_listen_event_socket4, /* listen_event */
4655 processCommandsCallback, /* processCommandsCallback */
Meng Wangef966a32016-06-20 17:38:18 -07004656 NULL, /* p_rs */
4657 RIL_TELEPHONY_SOCKET /* type */
Etan Cohend3652192014-06-20 08:28:44 -07004658 };
4659#endif
4660
4661
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004662 s_registerCalled = 1;
4663
Etan Cohend3652192014-06-20 08:28:44 -07004664 RLOGI("s_registerCalled flag set, %d", s_started);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004665 // Little self-check
4666
Wink Savillef4c4d362009-04-02 01:37:03 -07004667 for (int i = 0; i < (int)NUM_ELEMS(s_commands); i++) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004668 assert(i == s_commands[i].requestNumber);
4669 }
4670
Wink Savillef4c4d362009-04-02 01:37:03 -07004671 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses); i++) {
Wink Saville7f856802009-06-09 10:23:37 -07004672 assert(i + RIL_UNSOL_RESPONSE_BASE
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004673 == s_unsolResponses[i].requestNumber);
4674 }
4675
4676 // New rild impl calls RIL_startEventLoop() first
4677 // old standalone impl wants it here.
4678
4679 if (s_started == 0) {
4680 RIL_startEventLoop();
4681 }
4682
Etan Cohend3652192014-06-20 08:28:44 -07004683 // start listen socket1
4684 startListen(RIL_SOCKET_1, &s_ril_param_socket);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004685
Etan Cohend3652192014-06-20 08:28:44 -07004686#if (SIM_COUNT >= 2)
4687 // start listen socket2
4688 startListen(RIL_SOCKET_2, &s_ril_param_socket2);
4689#endif /* (SIM_COUNT == 2) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004690
Etan Cohend3652192014-06-20 08:28:44 -07004691#if (SIM_COUNT >= 3)
4692 // start listen socket3
4693 startListen(RIL_SOCKET_3, &s_ril_param_socket3);
4694#endif /* (SIM_COUNT == 3) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004695
Etan Cohend3652192014-06-20 08:28:44 -07004696#if (SIM_COUNT >= 4)
4697 // start listen socket4
4698 startListen(RIL_SOCKET_4, &s_ril_param_socket4);
4699#endif /* (SIM_COUNT == 4) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004700
Amit Mahajan18fe36b2016-08-25 11:19:21 -07004701 radio::registerService(&s_callbacks, s_commands);
4702 RLOGI("RILHIDL called registerService");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004703
4704#if 1
4705 // start debug interface socket
4706
Etan Cohend3652192014-06-20 08:28:44 -07004707 char *inst = NULL;
4708 if (strlen(RIL_getRilSocketName()) >= strlen(SOCKET_NAME_RIL)) {
4709 inst = RIL_getRilSocketName() + strlen(SOCKET_NAME_RIL);
4710 }
4711
4712 char rildebug[MAX_DEBUG_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL_DEBUG;
4713 if (inst != NULL) {
Nick Kralevichc52e45e2015-02-08 07:54:16 -08004714 strlcat(rildebug, inst, MAX_DEBUG_SOCKET_NAME_LENGTH);
Etan Cohend3652192014-06-20 08:28:44 -07004715 }
4716
4717 s_fdDebug = android_get_control_socket(rildebug);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004718 if (s_fdDebug < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07004719 RLOGE("Failed to get socket : %s errno:%d", rildebug, errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004720 exit(-1);
4721 }
4722
4723 ret = listen(s_fdDebug, 4);
4724
4725 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004726 RLOGE("Failed to listen on ril debug socket '%d': %s",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004727 s_fdDebug, strerror(errno));
4728 exit(-1);
4729 }
4730
4731 ril_event_set (&s_debug_event, s_fdDebug, true,
4732 debugCallback, NULL);
4733
4734 rilEventAddWakeup (&s_debug_event);
4735#endif
4736
4737}
4738
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004739extern "C" void
Amit Mahajan18fe36b2016-08-25 11:19:21 -07004740RIL_register_socket (RIL_RadioFunctions *(*Init)(const struct RIL_Env *, int, char **),
4741 RIL_SOCKET_TYPE socketType, int argc, char **argv) {
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004742
4743 RIL_RadioFunctions* UimFuncs = NULL;
4744
4745 if(Init) {
4746 UimFuncs = Init(&RilSapSocket::uimRilEnv, argc, argv);
4747
4748 switch(socketType) {
4749 case RIL_SAP_SOCKET:
4750 RilSapSocket::initSapSocket("sap_uim_socket1", UimFuncs);
4751
4752#if (SIM_COUNT >= 2)
4753 RilSapSocket::initSapSocket("sap_uim_socket2", UimFuncs);
4754#endif
4755
4756#if (SIM_COUNT >= 3)
4757 RilSapSocket::initSapSocket("sap_uim_socket3", UimFuncs);
4758#endif
4759
4760#if (SIM_COUNT >= 4)
4761 RilSapSocket::initSapSocket("sap_uim_socket4", UimFuncs);
4762#endif
Meng Wangef966a32016-06-20 17:38:18 -07004763 break;
4764 default:;
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004765 }
Amit Mahajanc2c71852016-11-29 16:48:54 -08004766
4767 RLOGI("RIL_register_socket: calling registerService");
4768 sap::registerService(UimFuncs);
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004769 }
4770}
4771
Sanket Padawe6ff9a872016-01-27 15:09:12 -08004772// Check and remove RequestInfo if its a response and not just ack sent back
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004773static int
Sanket Padawe6ff9a872016-01-27 15:09:12 -08004774checkAndDequeueRequestInfoIfAck(struct RequestInfo *pRI, bool isAck) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004775 int ret = 0;
Etan Cohend3652192014-06-20 08:28:44 -07004776 /* Hook for current context
4777 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
4778 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
4779 /* pendingRequestsHook refer to &s_pendingRequests */
4780 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
Wink Saville7f856802009-06-09 10:23:37 -07004781
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004782 if (pRI == NULL) {
4783 return 0;
4784 }
4785
Etan Cohend3652192014-06-20 08:28:44 -07004786#if (SIM_COUNT >= 2)
4787 if (pRI->socket_id == RIL_SOCKET_2) {
4788 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
4789 pendingRequestsHook = &s_pendingRequests_socket2;
4790 }
4791#if (SIM_COUNT >= 3)
4792 if (pRI->socket_id == RIL_SOCKET_3) {
4793 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
4794 pendingRequestsHook = &s_pendingRequests_socket3;
4795 }
4796#endif
4797#if (SIM_COUNT >= 4)
4798 if (pRI->socket_id == RIL_SOCKET_4) {
4799 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
4800 pendingRequestsHook = &s_pendingRequests_socket4;
4801 }
4802#endif
4803#endif
4804 pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004805
Etan Cohend3652192014-06-20 08:28:44 -07004806 for(RequestInfo **ppCur = pendingRequestsHook
Wink Saville7f856802009-06-09 10:23:37 -07004807 ; *ppCur != NULL
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004808 ; ppCur = &((*ppCur)->p_next)
4809 ) {
4810 if (pRI == *ppCur) {
4811 ret = 1;
Sanket Padawe6ff9a872016-01-27 15:09:12 -08004812 if (isAck) { // Async ack
4813 if (pRI->wasAckSent == 1) {
4814 RLOGD("Ack was already sent for %s", requestToString(pRI->pCI->requestNumber));
4815 } else {
4816 pRI->wasAckSent = 1;
4817 }
4818 } else {
4819 *ppCur = (*ppCur)->p_next;
4820 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004821 break;
4822 }
4823 }
4824
Etan Cohend3652192014-06-20 08:28:44 -07004825 pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004826
4827 return ret;
4828}
4829
Sanket Padawe6ff9a872016-01-27 15:09:12 -08004830static int findFd(int socket_id) {
Etan Cohend3652192014-06-20 08:28:44 -07004831 int fd = s_ril_param_socket.fdCommand;
Etan Cohend3652192014-06-20 08:28:44 -07004832#if (SIM_COUNT >= 2)
4833 if (socket_id == RIL_SOCKET_2) {
4834 fd = s_ril_param_socket2.fdCommand;
4835 }
4836#if (SIM_COUNT >= 3)
Sanket Padawe6ff9a872016-01-27 15:09:12 -08004837 if (socket_id == RIL_SOCKET_3) {
4838 fd = s_ril_param_socket3.fdCommand;
4839 }
Etan Cohend3652192014-06-20 08:28:44 -07004840#endif
4841#if (SIM_COUNT >= 4)
4842 if (socket_id == RIL_SOCKET_4) {
4843 fd = s_ril_param_socket4.fdCommand;
4844 }
4845#endif
4846#endif
Sanket Padawe6ff9a872016-01-27 15:09:12 -08004847 return fd;
4848}
4849
4850extern "C" void
4851RIL_onRequestAck(RIL_Token t) {
4852 RequestInfo *pRI;
4853 int ret, fd;
4854
4855 size_t errorOffset;
4856 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
4857
4858 pRI = (RequestInfo *)t;
4859
4860 if (!checkAndDequeueRequestInfoIfAck(pRI, true)) {
4861 RLOGE ("RIL_onRequestAck: invalid RIL_Token");
4862 return;
4863 }
4864
4865 socket_id = pRI->socket_id;
4866 fd = findFd(socket_id);
4867
4868#if VDBG
4869 RLOGD("Request Ack, %s", rilSocketIdToString(socket_id));
4870#endif
4871
4872 appendPrintBuf("Ack [%04d]< %s", pRI->token, requestToString(pRI->pCI->requestNumber));
4873
4874 if (pRI->cancelled == 0) {
4875 Parcel p;
4876
4877 p.writeInt32 (RESPONSE_SOLICITED_ACK);
4878 p.writeInt32 (pRI->token);
4879
Sanket Padawe85f952a2017-01-02 23:46:00 -08004880 switch(pRI->pCI->requestNumber) {
4881 case RIL_REQUEST_GET_SIM_STATUS:
4882 case RIL_REQUEST_ENTER_SIM_PIN:
4883 case RIL_REQUEST_ENTER_SIM_PUK:
4884 case RIL_REQUEST_ENTER_SIM_PIN2:
4885 case RIL_REQUEST_ENTER_SIM_PUK2:
4886 case RIL_REQUEST_CHANGE_SIM_PIN:
4887 case RIL_REQUEST_CHANGE_SIM_PIN2:
4888 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION:
4889 case RIL_REQUEST_GET_CURRENT_CALLS:
4890 case RIL_REQUEST_DIAL:
Amit Mahajan32ec8a42017-01-24 05:45:02 -08004891 pthread_rwlock_t *radioServiceRwlockPtr = radio::getRadioServiceRwlock(
4892 (int) socket_id);
4893 int rwlockRet = pthread_rwlock_rdlock(radioServiceRwlockPtr);
4894 assert(rwlockRet == 0);
4895
Sanket Padawe85f952a2017-01-02 23:46:00 -08004896 radio::acknowledgeRequest((int) socket_id, pRI->token);
Amit Mahajan32ec8a42017-01-24 05:45:02 -08004897
4898 rwlockRet = pthread_rwlock_unlock(radioServiceRwlockPtr);
4899 assert(rwlockRet == 0);
4900
Sanket Padawe85f952a2017-01-02 23:46:00 -08004901 return;
4902 }
4903
Sanket Padawe6ff9a872016-01-27 15:09:12 -08004904 if (fd < 0) {
Sanket Padawe85f952a2017-01-02 23:46:00 -08004905 RLOGD ("RIL onRequestAck: Command channel closed");
Sanket Padawe6ff9a872016-01-27 15:09:12 -08004906 }
4907
4908 sendResponse(p, socket_id);
4909 }
4910}
Sanket Padawe6ff9a872016-01-27 15:09:12 -08004911extern "C" void
4912RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) {
4913 RequestInfo *pRI;
4914 int ret;
4915 int fd;
4916 size_t errorOffset;
4917 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
4918
4919 pRI = (RequestInfo *)t;
4920
4921 if (!checkAndDequeueRequestInfoIfAck(pRI, false)) {
4922 RLOGE ("RIL_onRequestComplete: invalid RIL_Token");
4923 return;
4924 }
4925
4926 socket_id = pRI->socket_id;
4927 fd = findFd(socket_id);
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07004928#if VDBG
Etan Cohend3652192014-06-20 08:28:44 -07004929 RLOGD("RequestComplete, %s", rilSocketIdToString(socket_id));
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07004930#endif
Etan Cohend3652192014-06-20 08:28:44 -07004931
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004932 if (pRI->local > 0) {
4933 // Locally issued command...void only!
4934 // response does not go back up the command socket
Wink Saville8eb2a122012-11-19 16:05:13 -08004935 RLOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004936
4937 goto done;
4938 }
4939
4940 appendPrintBuf("[%04d]< %s",
4941 pRI->token, requestToString(pRI->pCI->requestNumber));
4942
4943 if (pRI->cancelled == 0) {
4944 Parcel p;
4945
Amit Mahajan18fe36b2016-08-25 11:19:21 -07004946 int responseType;
Sanket Padawe6ff9a872016-01-27 15:09:12 -08004947 if (s_callbacks.version >= 13 && pRI->wasAckSent == 1) {
4948 // If ack was already sent, then this call is an asynchronous response. So we need to
4949 // send id indicating that we expect an ack from RIL.java as we acquire wakelock here.
Amit Mahajan18fe36b2016-08-25 11:19:21 -07004950 responseType = RESPONSE_SOLICITED_ACK_EXP;
Sanket Padawe6ff9a872016-01-27 15:09:12 -08004951 grabPartialWakeLock();
4952 } else {
Amit Mahajan18fe36b2016-08-25 11:19:21 -07004953 responseType = RESPONSE_SOLICITED;
Sanket Padawe6ff9a872016-01-27 15:09:12 -08004954 }
Amit Mahajan18fe36b2016-08-25 11:19:21 -07004955 p.writeInt32 (responseType);
4956
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004957 p.writeInt32 (pRI->token);
4958 errorOffset = p.dataPosition();
4959
4960 p.writeInt32 (e);
4961
Sanket Padawe85f952a2017-01-02 23:46:00 -08004962 bool hidlized = false;
4963 switch(pRI->pCI->requestNumber) {
4964 case RIL_REQUEST_GET_SIM_STATUS:
4965 case RIL_REQUEST_ENTER_SIM_PIN:
4966 case RIL_REQUEST_ENTER_SIM_PUK:
4967 case RIL_REQUEST_ENTER_SIM_PIN2:
4968 case RIL_REQUEST_ENTER_SIM_PUK2:
4969 case RIL_REQUEST_CHANGE_SIM_PIN:
4970 case RIL_REQUEST_CHANGE_SIM_PIN2:
4971 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION:
4972 case RIL_REQUEST_GET_CURRENT_CALLS:
4973 case RIL_REQUEST_DIAL:
4974 hidlized = true;
4975 break;
4976 }
4977
4978 if (response != NULL || hidlized) {
johnwangb2a61842009-06-02 14:55:45 -07004979 // there is a response payload, no matter success or not.
Amit Mahajan18fe36b2016-08-25 11:19:21 -07004980 RLOGE ("Calling responseFunction() for token %d", pRI->token);
Amit Mahajan32ec8a42017-01-24 05:45:02 -08004981
4982 pthread_rwlock_t *radioServiceRwlockPtr = radio::getRadioServiceRwlock((int) socket_id);
4983 int rwlockRet = pthread_rwlock_rdlock(radioServiceRwlockPtr);
4984 assert(rwlockRet == 0);
4985
Amit Mahajan18fe36b2016-08-25 11:19:21 -07004986 ret = pRI->pCI->responseFunction(p, (int) socket_id, pRI->pCI->requestNumber,
4987 responseType, pRI->token, e, response, responselen);
4988
Amit Mahajan32ec8a42017-01-24 05:45:02 -08004989 rwlockRet = pthread_rwlock_unlock(radioServiceRwlockPtr);
4990 assert(rwlockRet == 0);
4991
Sanket Padawe85f952a2017-01-02 23:46:00 -08004992 if (hidlized) {
4993 free(pRI);
Amit Mahajan18fe36b2016-08-25 11:19:21 -07004994 return;
4995 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004996
4997 /* if an error occurred, rewind and mark it */
4998 if (ret != 0) {
Etan Cohend3652192014-06-20 08:28:44 -07004999 RLOGE ("responseFunction error, ret %d", ret);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005000 p.setDataPosition(errorOffset);
5001 p.writeInt32 (ret);
5002 }
johnwangb2a61842009-06-02 14:55:45 -07005003 }
5004
5005 if (e != RIL_E_SUCCESS) {
5006 appendPrintBuf("%s fails by %s", printBuf, failCauseToString(e));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005007 }
5008
Etan Cohend3652192014-06-20 08:28:44 -07005009 if (fd < 0) {
Sanket Padawe85f952a2017-01-02 23:46:00 -08005010 RLOGD ("RIL_onRequestComplete: Command channel closed");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005011 }
Etan Cohend3652192014-06-20 08:28:44 -07005012 sendResponse(p, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005013 }
5014
5015done:
5016 free(pRI);
5017}
5018
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005019static void
Wink Savillef4c4d362009-04-02 01:37:03 -07005020grabPartialWakeLock() {
Sanket Padawe6ff9a872016-01-27 15:09:12 -08005021 if (s_callbacks.version >= 13) {
5022 int ret;
5023 ret = pthread_mutex_lock(&s_wakeLockCountMutex);
5024 assert(ret == 0);
5025 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
Sanket Padawe55227b52016-02-29 10:09:26 -08005026
5027 UserCallbackInfo *p_info =
5028 internalRequestTimedCallback(wakeTimeoutCallback, NULL, &TIMEVAL_WAKE_TIMEOUT);
5029 if (p_info == NULL) {
5030 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
5031 } else {
5032 s_wakelock_count++;
5033 if (s_last_wake_timeout_info != NULL) {
5034 s_last_wake_timeout_info->userParam = (void *)1;
5035 }
5036 s_last_wake_timeout_info = p_info;
Sanket Padawe6ff9a872016-01-27 15:09:12 -08005037 }
Sanket Padawe6ff9a872016-01-27 15:09:12 -08005038 ret = pthread_mutex_unlock(&s_wakeLockCountMutex);
5039 assert(ret == 0);
5040 } else {
5041 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
5042 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005043}
5044
Sanket Padawe85f952a2017-01-02 23:46:00 -08005045void
Wink Savillef4c4d362009-04-02 01:37:03 -07005046releaseWakeLock() {
Sanket Padawe6ff9a872016-01-27 15:09:12 -08005047 if (s_callbacks.version >= 13) {
5048 int ret;
5049 ret = pthread_mutex_lock(&s_wakeLockCountMutex);
5050 assert(ret == 0);
5051
5052 if (s_wakelock_count > 1) {
5053 s_wakelock_count--;
5054 } else {
5055 s_wakelock_count = 0;
5056 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
5057 if (s_last_wake_timeout_info != NULL) {
5058 s_last_wake_timeout_info->userParam = (void *)1;
5059 }
5060 }
5061
5062 ret = pthread_mutex_unlock(&s_wakeLockCountMutex);
5063 assert(ret == 0);
5064 } else {
5065 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
5066 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005067}
5068
5069/**
5070 * Timer callback to put us back to sleep before the default timeout
5071 */
5072static void
Wink Savillef4c4d362009-04-02 01:37:03 -07005073wakeTimeoutCallback (void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005074 // We're using "param != NULL" as a cancellation mechanism
Sanket Padawe6ff9a872016-01-27 15:09:12 -08005075 if (s_callbacks.version >= 13) {
5076 if (param == NULL) {
5077 int ret;
5078 ret = pthread_mutex_lock(&s_wakeLockCountMutex);
5079 assert(ret == 0);
5080 s_wakelock_count = 0;
5081 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
5082 ret = pthread_mutex_unlock(&s_wakeLockCountMutex);
5083 assert(ret == 0);
5084 }
5085 } else {
5086 if (param == NULL) {
5087 releaseWakeLock();
5088 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005089 }
5090}
5091
Etan Cohend3652192014-06-20 08:28:44 -07005092#if defined(ANDROID_MULTI_SIM)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005093extern "C"
Bernhard Rosenkränzerd613b962014-11-17 20:52:09 +01005094void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Etan Cohend3652192014-06-20 08:28:44 -07005095 size_t datalen, RIL_SOCKET_ID socket_id)
5096#else
5097extern "C"
Bernhard Rosenkränzerd613b962014-11-17 20:52:09 +01005098void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005099 size_t datalen)
Etan Cohend3652192014-06-20 08:28:44 -07005100#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005101{
5102 int unsolResponseIndex;
5103 int ret;
5104 int64_t timeReceived = 0;
5105 bool shouldScheduleTimeout = false;
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005106 RIL_RadioState newState;
Etan Cohend3652192014-06-20 08:28:44 -07005107 RIL_SOCKET_ID soc_id = RIL_SOCKET_1;
5108
5109#if defined(ANDROID_MULTI_SIM)
5110 soc_id = socket_id;
5111#endif
5112
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005113
5114 if (s_registerCalled == 0) {
5115 // Ignore RIL_onUnsolicitedResponse before RIL_register
Wink Saville8eb2a122012-11-19 16:05:13 -08005116 RLOGW("RIL_onUnsolicitedResponse called before RIL_register");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005117 return;
5118 }
Wink Saville7f856802009-06-09 10:23:37 -07005119
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005120 unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
5121
5122 if ((unsolResponseIndex < 0)
5123 || (unsolResponseIndex >= (int32_t)NUM_ELEMS(s_unsolResponses))) {
Wink Saville8eb2a122012-11-19 16:05:13 -08005124 RLOGE("unsupported unsolicited response code %d", unsolResponse);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005125 return;
5126 }
5127
5128 // Grab a wake lock if needed for this reponse,
5129 // as we exit we'll either release it immediately
5130 // or set a timer to release it later.
5131 switch (s_unsolResponses[unsolResponseIndex].wakeType) {
5132 case WAKE_PARTIAL:
5133 grabPartialWakeLock();
5134 shouldScheduleTimeout = true;
5135 break;
5136
5137 case DONT_WAKE:
5138 default:
5139 // No wake lock is grabed so don't set timeout
5140 shouldScheduleTimeout = false;
5141 break;
5142 }
5143
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005144 appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
5145
5146 Parcel p;
Amit Mahajan18fe36b2016-08-25 11:19:21 -07005147 int responseType;
Sanket Padawed8c0b462016-02-03 11:46:02 -08005148 if (s_callbacks.version >= 13
5149 && s_unsolResponses[unsolResponseIndex].wakeType == WAKE_PARTIAL) {
Amit Mahajan18fe36b2016-08-25 11:19:21 -07005150 responseType = RESPONSE_UNSOLICITED_ACK_EXP;
Sanket Padawed8c0b462016-02-03 11:46:02 -08005151 } else {
Amit Mahajan18fe36b2016-08-25 11:19:21 -07005152 responseType = RESPONSE_UNSOLICITED;
Sanket Padawed8c0b462016-02-03 11:46:02 -08005153 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005154
Amit Mahajan32ec8a42017-01-24 05:45:02 -08005155 pthread_rwlock_t *radioServiceRwlockPtr = radio::getRadioServiceRwlock((int) soc_id);
5156 int rwlockRet = pthread_rwlock_rdlock(radioServiceRwlockPtr);
5157 assert(rwlockRet == 0);
5158
Amit Mahajan18fe36b2016-08-25 11:19:21 -07005159 ret = s_unsolResponses[unsolResponseIndex].responseFunction(
5160 p, (int) soc_id, unsolResponse, responseType, 0, RIL_E_SUCCESS, const_cast<void*>(data),
5161 datalen);
Amit Mahajan32ec8a42017-01-24 05:45:02 -08005162
5163 rwlockRet = pthread_rwlock_unlock(radioServiceRwlockPtr);
5164 assert(rwlockRet == 0);
5165
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005166 if (ret != 0) {
5167 // Problem with the response. Don't continue;
5168 goto error_exit;
5169 }
5170
5171 // some things get more payload
5172 switch(unsolResponse) {
5173 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
Naveen Kalla2baf7232016-10-11 13:49:20 -07005174 newState = CALL_ONSTATEREQUEST(soc_id);
Naveen Kalla2baf7232016-10-11 13:49:20 -07005175 appendPrintBuf("%s {%s}", printBuf, radioStateToString(newState));
Amit Mahajan14566d32017-01-06 16:55:33 -08005176 break;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005177 }
5178
Sanket Padawe55227b52016-02-29 10:09:26 -08005179 if (s_callbacks.version < 13) {
5180 if (shouldScheduleTimeout) {
5181 UserCallbackInfo *p_info = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
5182 &TIMEVAL_WAKE_TIMEOUT);
5183
5184 if (p_info == NULL) {
5185 goto error_exit;
5186 } else {
5187 // Cancel the previous request
5188 if (s_last_wake_timeout_info != NULL) {
5189 s_last_wake_timeout_info->userParam = (void *)1;
5190 }
5191 s_last_wake_timeout_info = p_info;
5192 }
5193 }
5194 }
5195
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07005196#if VDBG
Amit Mahajan18fe36b2016-08-25 11:19:21 -07005197 RLOGI("%s UNSOLICITED: %s length:%d", rilSocketIdToString(soc_id),
5198 requestToString(unsolResponse), p.dataSize());
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07005199#endif
Amit Mahajan18fe36b2016-08-25 11:19:21 -07005200 ret = 0;
5201 switch (unsolResponse) {
5202 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
Amit Mahajan32ec8a42017-01-24 05:45:02 -08005203 rwlockRet = pthread_rwlock_rdlock(radioServiceRwlockPtr);
5204 assert(rwlockRet == 0);
5205
Amit Mahajanbd3257b2016-12-28 17:28:07 -08005206 radio::radioStateChangedInd(soc_id, responseType, newState);
Amit Mahajan32ec8a42017-01-24 05:45:02 -08005207
5208 rwlockRet = pthread_rwlock_unlock(radioServiceRwlockPtr);
5209 assert(rwlockRet == 0);
Amit Mahajanbd3257b2016-12-28 17:28:07 -08005210 break;
Amit Mahajan18fe36b2016-08-25 11:19:21 -07005211 }
5212
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005213 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
5214
5215 // Unfortunately, NITZ time is not poll/update like everything
5216 // else in the system. So, if the upstream client isn't connected,
5217 // keep a copy of the last NITZ response (with receive time noted
5218 // above) around so we can deliver it when it is connected
5219
5220 if (s_lastNITZTimeData != NULL) {
5221 free (s_lastNITZTimeData);
5222 s_lastNITZTimeData = NULL;
5223 }
5224
Sanket Padawe0cfc5532016-03-07 17:12:19 -08005225 s_lastNITZTimeData = calloc(p.dataSize(), 1);
Sanket Padawe55227b52016-02-29 10:09:26 -08005226 if (s_lastNITZTimeData == NULL) {
5227 RLOGE("Memory allocation failed in RIL_onUnsolicitedResponse");
5228 goto error_exit;
5229 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005230 s_lastNITZTimeDataSize = p.dataSize();
5231 memcpy(s_lastNITZTimeData, p.data(), p.dataSize());
5232 }
5233
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005234 // Normal exit
5235 return;
5236
5237error_exit:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005238 if (shouldScheduleTimeout) {
5239 releaseWakeLock();
5240 }
5241}
5242
Wink Saville7f856802009-06-09 10:23:37 -07005243/** FIXME generalize this if you track UserCAllbackInfo, clear it
5244 when the callback occurs
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005245*/
5246static UserCallbackInfo *
Wink Saville7f856802009-06-09 10:23:37 -07005247internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07005248 const struct timeval *relativeTime)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005249{
5250 struct timeval myRelativeTime;
5251 UserCallbackInfo *p_info;
5252
Sanket Padawe0cfc5532016-03-07 17:12:19 -08005253 p_info = (UserCallbackInfo *) calloc(1, sizeof(UserCallbackInfo));
Sanket Padawe55227b52016-02-29 10:09:26 -08005254 if (p_info == NULL) {
5255 RLOGE("Memory allocation failed in internalRequestTimedCallback");
5256 return p_info;
5257
5258 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005259
Wink Saville7f856802009-06-09 10:23:37 -07005260 p_info->p_callback = callback;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005261 p_info->userParam = param;
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07005262
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005263 if (relativeTime == NULL) {
5264 /* treat null parameter as a 0 relative time */
5265 memset (&myRelativeTime, 0, sizeof(myRelativeTime));
5266 } else {
5267 /* FIXME I think event_add's tv param is really const anyway */
5268 memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
5269 }
5270
5271 ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
5272
5273 ril_timer_add(&(p_info->event), &myRelativeTime);
5274
5275 triggerEvLoop();
5276 return p_info;
5277}
5278
Naveen Kalla7edd07c2010-06-21 18:54:47 -07005279
5280extern "C" void
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07005281RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
5282 const struct timeval *relativeTime) {
5283 internalRequestTimedCallback (callback, param, relativeTime);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005284}
5285
5286const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07005287failCauseToString(RIL_Errno e) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005288 switch(e) {
5289 case RIL_E_SUCCESS: return "E_SUCCESS";
Robert Greenwalt2126ab22013-04-09 12:20:45 -07005290 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RADIO_NOT_AVAILABLE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005291 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
5292 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
5293 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
5294 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
5295 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
5296 case RIL_E_CANCELLED: return "E_CANCELLED";
5297 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
5298 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
5299 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
Wink Savillef4c4d362009-04-02 01:37:03 -07005300 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
John Wang75534472010-04-20 15:11:42 -07005301 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
Wink Saville7f856802009-06-09 10:23:37 -07005302#ifdef FEATURE_MULTIMODE_ANDROID
Wink Savillef4c4d362009-04-02 01:37:03 -07005303 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
5304 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
5305#endif
Sanket Padaweb39e5c92016-02-08 14:28:59 -08005306 case RIL_E_FDN_CHECK_FAILURE: return "E_FDN_CHECK_FAILURE";
5307 case RIL_E_MISSING_RESOURCE: return "E_MISSING_RESOURCE";
5308 case RIL_E_NO_SUCH_ELEMENT: return "E_NO_SUCH_ELEMENT";
5309 case RIL_E_DIAL_MODIFIED_TO_USSD: return "E_DIAL_MODIFIED_TO_USSD";
5310 case RIL_E_DIAL_MODIFIED_TO_SS: return "E_DIAL_MODIFIED_TO_SS";
5311 case RIL_E_DIAL_MODIFIED_TO_DIAL: return "E_DIAL_MODIFIED_TO_DIAL";
5312 case RIL_E_USSD_MODIFIED_TO_DIAL: return "E_USSD_MODIFIED_TO_DIAL";
5313 case RIL_E_USSD_MODIFIED_TO_SS: return "E_USSD_MODIFIED_TO_SS";
5314 case RIL_E_USSD_MODIFIED_TO_USSD: return "E_USSD_MODIFIED_TO_USSD";
5315 case RIL_E_SS_MODIFIED_TO_DIAL: return "E_SS_MODIFIED_TO_DIAL";
5316 case RIL_E_SS_MODIFIED_TO_USSD: return "E_SS_MODIFIED_TO_USSD";
5317 case RIL_E_SUBSCRIPTION_NOT_SUPPORTED: return "E_SUBSCRIPTION_NOT_SUPPORTED";
5318 case RIL_E_SS_MODIFIED_TO_SS: return "E_SS_MODIFIED_TO_SS";
5319 case RIL_E_LCE_NOT_SUPPORTED: return "E_LCE_NOT_SUPPORTED";
5320 case RIL_E_NO_MEMORY: return "E_NO_MEMORY";
5321 case RIL_E_INTERNAL_ERR: return "E_INTERNAL_ERR";
5322 case RIL_E_SYSTEM_ERR: return "E_SYSTEM_ERR";
5323 case RIL_E_MODEM_ERR: return "E_MODEM_ERR";
5324 case RIL_E_INVALID_STATE: return "E_INVALID_STATE";
5325 case RIL_E_NO_RESOURCES: return "E_NO_RESOURCES";
5326 case RIL_E_SIM_ERR: return "E_SIM_ERR";
5327 case RIL_E_INVALID_ARGUMENTS: return "E_INVALID_ARGUMENTS";
5328 case RIL_E_INVALID_SIM_STATE: return "E_INVALID_SIM_STATE";
5329 case RIL_E_INVALID_MODEM_STATE: return "E_INVALID_MODEM_STATE";
5330 case RIL_E_INVALID_CALL_ID: return "E_INVALID_CALL_ID";
5331 case RIL_E_NO_SMS_TO_ACK: return "E_NO_SMS_TO_ACK";
5332 case RIL_E_NETWORK_ERR: return "E_NETWORK_ERR";
5333 case RIL_E_REQUEST_RATE_LIMITED: return "E_REQUEST_RATE_LIMITED";
twen.changdf7add02016-03-04 18:27:48 +08005334 case RIL_E_SIM_BUSY: return "E_SIM_BUSY";
5335 case RIL_E_SIM_FULL: return "E_SIM_FULL";
5336 case RIL_E_NETWORK_REJECT: return "E_NETWORK_REJECT";
5337 case RIL_E_OPERATION_NOT_ALLOWED: return "E_OPERATION_NOT_ALLOWED";
5338 case RIL_E_EMPTY_RECORD: "E_EMPTY_RECORD";
Ajay Nambi68900f52016-03-11 12:02:55 -08005339 case RIL_E_INVALID_SMS_FORMAT: return "E_INVALID_SMS_FORMAT";
5340 case RIL_E_ENCODING_ERR: return "E_ENCODING_ERR";
5341 case RIL_E_INVALID_SMSC_ADDRESS: return "E_INVALID_SMSC_ADDRESS";
5342 case RIL_E_NO_SUCH_ENTRY: return "E_NO_SUCH_ENTRY";
5343 case RIL_E_NETWORK_NOT_READY: return "E_NETWORK_NOT_READY";
5344 case RIL_E_NOT_PROVISIONED: return "E_NOT_PROVISIONED";
Ajay Nambi10345892016-03-19 09:02:28 -07005345 case RIL_E_NO_SUBSCRIPTION: return "E_NO_SUBSCRIPTION";
5346 case RIL_E_NO_NETWORK_FOUND: return "E_NO_NETWORK_FOUND";
5347 case RIL_E_DEVICE_IN_USE: return "E_DEVICE_IN_USE";
5348 case RIL_E_ABORTED: return "E_ABORTED";
Sanket Padawe85f952a2017-01-02 23:46:00 -08005349 case RIL_E_INVALID_RESPONSE: return "INVALID_RESPONSE";
Sanket Padawe0106aed2016-02-09 09:56:31 -08005350 case RIL_E_OEM_ERROR_1: return "E_OEM_ERROR_1";
5351 case RIL_E_OEM_ERROR_2: return "E_OEM_ERROR_2";
5352 case RIL_E_OEM_ERROR_3: return "E_OEM_ERROR_3";
5353 case RIL_E_OEM_ERROR_4: return "E_OEM_ERROR_4";
5354 case RIL_E_OEM_ERROR_5: return "E_OEM_ERROR_5";
5355 case RIL_E_OEM_ERROR_6: return "E_OEM_ERROR_6";
5356 case RIL_E_OEM_ERROR_7: return "E_OEM_ERROR_7";
5357 case RIL_E_OEM_ERROR_8: return "E_OEM_ERROR_8";
5358 case RIL_E_OEM_ERROR_9: return "E_OEM_ERROR_9";
5359 case RIL_E_OEM_ERROR_10: return "E_OEM_ERROR_10";
5360 case RIL_E_OEM_ERROR_11: return "E_OEM_ERROR_11";
5361 case RIL_E_OEM_ERROR_12: return "E_OEM_ERROR_12";
5362 case RIL_E_OEM_ERROR_13: return "E_OEM_ERROR_13";
5363 case RIL_E_OEM_ERROR_14: return "E_OEM_ERROR_14";
5364 case RIL_E_OEM_ERROR_15: return "E_OEM_ERROR_15";
5365 case RIL_E_OEM_ERROR_16: return "E_OEM_ERROR_16";
5366 case RIL_E_OEM_ERROR_17: return "E_OEM_ERROR_17";
5367 case RIL_E_OEM_ERROR_18: return "E_OEM_ERROR_18";
5368 case RIL_E_OEM_ERROR_19: return "E_OEM_ERROR_19";
5369 case RIL_E_OEM_ERROR_20: return "E_OEM_ERROR_20";
5370 case RIL_E_OEM_ERROR_21: return "E_OEM_ERROR_21";
5371 case RIL_E_OEM_ERROR_22: return "E_OEM_ERROR_22";
5372 case RIL_E_OEM_ERROR_23: return "E_OEM_ERROR_23";
5373 case RIL_E_OEM_ERROR_24: return "E_OEM_ERROR_24";
5374 case RIL_E_OEM_ERROR_25: return "E_OEM_ERROR_25";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005375 default: return "<unknown error>";
5376 }
5377}
5378
5379const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07005380radioStateToString(RIL_RadioState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005381 switch(s) {
5382 case RADIO_STATE_OFF: return "RADIO_OFF";
5383 case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005384 case RADIO_STATE_ON:return"RADIO_ON";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005385 default: return "<unknown state>";
5386 }
5387}
5388
5389const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07005390callStateToString(RIL_CallState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005391 switch(s) {
5392 case RIL_CALL_ACTIVE : return "ACTIVE";
5393 case RIL_CALL_HOLDING: return "HOLDING";
5394 case RIL_CALL_DIALING: return "DIALING";
5395 case RIL_CALL_ALERTING: return "ALERTING";
5396 case RIL_CALL_INCOMING: return "INCOMING";
5397 case RIL_CALL_WAITING: return "WAITING";
5398 default: return "<unknown state>";
5399 }
5400}
5401
5402const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07005403requestToString(int request) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005404/*
5405 cat libs/telephony/ril_commands.h \
5406 | egrep "^ *{RIL_" \
5407 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
5408
5409
5410 cat libs/telephony/ril_unsol_commands.h \
5411 | egrep "^ *{RIL_" \
5412 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
5413
5414*/
5415 switch(request) {
5416 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
5417 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
5418 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
5419 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
5420 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
5421 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
5422 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
5423 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
5424 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
5425 case RIL_REQUEST_DIAL: return "DIAL";
5426 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
5427 case RIL_REQUEST_HANGUP: return "HANGUP";
5428 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
5429 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
5430 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
5431 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
5432 case RIL_REQUEST_UDUB: return "UDUB";
5433 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
5434 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
Wink Savillec0114b32011-02-18 10:14:07 -08005435 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
5436 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005437 case RIL_REQUEST_OPERATOR: return "OPERATOR";
5438 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
5439 case RIL_REQUEST_DTMF: return "DTMF";
5440 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
5441 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
Wink Savillef4c4d362009-04-02 01:37:03 -07005442 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005443 case RIL_REQUEST_SIM_IO: return "SIM_IO";
5444 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
5445 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
5446 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
5447 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
5448 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
5449 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
5450 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
5451 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
5452 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
5453 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
5454 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
5455 case RIL_REQUEST_ANSWER: return "ANSWER";
Wink Savillef4c4d362009-04-02 01:37:03 -07005456 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005457 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
5458 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
5459 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
5460 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
5461 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
5462 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
Matt Mower897915e2015-04-08 23:16:03 -05005463 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS: return "QUERY_AVAILABLE_NETWORKS";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005464 case RIL_REQUEST_DTMF_START: return "DTMF_START";
5465 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
5466 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
5467 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005468 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
5469 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
5470 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
Wink Savillef4c4d362009-04-02 01:37:03 -07005471 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
5472 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005473 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
5474 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
5475 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
Matt Mower897915e2015-04-08 23:16:03 -05005476 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
5477 case RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION: return "SET_SUPP_SVC_NOTIFICATION";
5478 case RIL_REQUEST_WRITE_SMS_TO_SIM: return "WRITE_SMS_TO_SIM";
5479 case RIL_REQUEST_DELETE_SMS_ON_SIM: return "DELETE_SMS_ON_SIM";
Wink Savillef4c4d362009-04-02 01:37:03 -07005480 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
5481 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005482 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
5483 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
5484 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
5485 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
5486 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005487 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
Matt Mower897915e2015-04-08 23:16:03 -05005488 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
5489 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
5490 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005491 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
Matt Mower897915e2015-04-08 23:16:03 -05005492 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE: return "CDMA_SET_SUBSCRIPTION_SOURCE";
5493 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE: return "CDMA_SET_ROAMING_PREFERENCE";
5494 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE: return "CDMA_QUERY_ROAMING_PREFERENCE";
5495 case RIL_REQUEST_SET_TTY_MODE: return "SET_TTY_MODE";
5496 case RIL_REQUEST_QUERY_TTY_MODE: return "QUERY_TTY_MODE";
5497 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE: return "CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
5498 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE: return "CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
5499 case RIL_REQUEST_CDMA_FLASH: return "CDMA_FLASH";
5500 case RIL_REQUEST_CDMA_BURST_DTMF: return "CDMA_BURST_DTMF";
5501 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return "CDMA_VALIDATE_AND_WRITE_AKEY";
5502 case RIL_REQUEST_CDMA_SEND_SMS: return "CDMA_SEND_SMS";
5503 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE: return "CDMA_SMS_ACKNOWLEDGE";
5504 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG: return "GSM_GET_BROADCAST_SMS_CONFIG";
5505 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG: return "GSM_SET_BROADCAST_SMS_CONFIG";
5506 case RIL_REQUEST_GSM_SMS_BROADCAST_ACTIVATION: return "GSM_SMS_BROADCAST_ACTIVATION";
5507 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG: return "CDMA_GET_BROADCAST_SMS_CONFIG";
5508 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG: return "CDMA_SET_BROADCAST_SMS_CONFIG";
5509 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION: return "CDMA_SMS_BROADCAST_ACTIVATION";
5510 case RIL_REQUEST_CDMA_SUBSCRIPTION: return "CDMA_SUBSCRIPTION";
Wink Savillef4c4d362009-04-02 01:37:03 -07005511 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
5512 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
5513 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
jsh000a9fe2009-05-11 14:52:35 -07005514 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
5515 case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
5516 case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
jsh09a68ba2009-06-10 11:56:38 -07005517 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
jsh563fd722010-06-08 16:52:24 -07005518 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
Wink Savillec0114b32011-02-18 10:14:07 -08005519 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
Jake Hambyfa8d5842011-08-19 16:22:18 -07005520 case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
Matt Mower897915e2015-04-08 23:16:03 -05005521 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
5522 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "STK_SEND_ENVELOPE_WITH_STATUS";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005523 case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
Matt Mower897915e2015-04-08 23:16:03 -05005524 case RIL_REQUEST_GET_CELL_INFO_LIST: return "GET_CELL_INFO_LIST";
5525 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return "SET_UNSOL_CELL_INFO_LIST_RATE";
5526 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "SET_INITIAL_ATTACH_APN";
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07005527 case RIL_REQUEST_IMS_REGISTRATION_STATE: return "IMS_REGISTRATION_STATE";
5528 case RIL_REQUEST_IMS_SEND_SMS: return "IMS_SEND_SMS";
Shishir Agrawal2458d8d2013-11-27 14:53:05 -08005529 case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "SIM_TRANSMIT_APDU_BASIC";
5530 case RIL_REQUEST_SIM_OPEN_CHANNEL: return "SIM_OPEN_CHANNEL";
5531 case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "SIM_CLOSE_CHANNEL";
5532 case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "SIM_TRANSMIT_APDU_CHANNEL";
Matt Mower897915e2015-04-08 23:16:03 -05005533 case RIL_REQUEST_NV_READ_ITEM: return "NV_READ_ITEM";
5534 case RIL_REQUEST_NV_WRITE_ITEM: return "NV_WRITE_ITEM";
5535 case RIL_REQUEST_NV_WRITE_CDMA_PRL: return "NV_WRITE_CDMA_PRL";
5536 case RIL_REQUEST_NV_RESET_CONFIG: return "NV_RESET_CONFIG";
Etan Cohend3652192014-06-20 08:28:44 -07005537 case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "SET_UICC_SUBSCRIPTION";
5538 case RIL_REQUEST_ALLOW_DATA: return "ALLOW_DATA";
Amit Mahajan2b772032014-06-26 14:20:11 -07005539 case RIL_REQUEST_GET_HARDWARE_CONFIG: return "GET_HARDWARE_CONFIG";
5540 case RIL_REQUEST_SIM_AUTHENTICATION: return "SIM_AUTHENTICATION";
Wink Savillec29360a2014-07-13 05:17:28 -07005541 case RIL_REQUEST_GET_DC_RT_INFO: return "GET_DC_RT_INFO";
5542 case RIL_REQUEST_SET_DC_RT_INFO_RATE: return "SET_DC_RT_INFO_RATE";
Amit Mahajanc796e222014-08-13 16:54:01 +00005543 case RIL_REQUEST_SET_DATA_PROFILE: return "SET_DATA_PROFILE";
Matt Mower897915e2015-04-08 23:16:03 -05005544 case RIL_REQUEST_SHUTDOWN: return "SHUTDOWN";
5545 case RIL_REQUEST_GET_RADIO_CAPABILITY: return "GET_RADIO_CAPABILITY";
5546 case RIL_REQUEST_SET_RADIO_CAPABILITY: return "SET_RADIO_CAPABILITY";
5547 case RIL_REQUEST_START_LCE: return "START_LCE";
5548 case RIL_REQUEST_STOP_LCE: return "STOP_LCE";
5549 case RIL_REQUEST_PULL_LCEDATA: return "PULL_LCEDATA";
5550 case RIL_REQUEST_GET_ACTIVITY_INFO: return "GET_ACTIVITY_INFO";
Meng Wangb4e34312016-05-12 14:54:36 -07005551 case RIL_REQUEST_SET_CARRIER_RESTRICTIONS: return "SET_CARRIER_RESTRICTIONS";
5552 case RIL_REQUEST_GET_CARRIER_RESTRICTIONS: return "GET_CARRIER_RESTRICTIONS";
Matt Mower897915e2015-04-08 23:16:03 -05005553 case RIL_RESPONSE_ACKNOWLEDGEMENT: return "RESPONSE_ACKNOWLEDGEMENT";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005554 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
5555 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08005556 case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005557 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
5558 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
5559 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
5560 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
Matt Mower897915e2015-04-08 23:16:03 -05005561 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005562 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
5563 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
Matt Mower897915e2015-04-08 23:16:03 -05005564 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
Sanket Padawe0eb4fba2016-01-26 17:28:38 -08005565 case RIL_UNSOL_SUPP_SVC_NOTIFICATION: return "UNSOL_SUPP_SVC_NOTIFICATION";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005566 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
5567 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
5568 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
5569 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
Matt Mower897915e2015-04-08 23:16:03 -05005570 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FULL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005571 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005572 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
Wink Savillef4c4d362009-04-02 01:37:03 -07005573 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
Matt Mower897915e2015-04-08 23:16:03 -05005574 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_RESPONSE_CDMA_NEW_SMS";
5575 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_RESPONSE_NEW_BROADCAST_SMS";
Wink Savillef4c4d362009-04-02 01:37:03 -07005576 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
Wink Saville3d54e742009-05-18 18:00:44 -07005577 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
5578 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
5579 case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
5580 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
5581 case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
Jaikumar Ganeshaf6ecbf2009-04-29 13:27:51 -07005582 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
John Wang5d621da2009-09-18 17:17:48 -07005583 case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
John Wang5909cf82010-01-29 00:18:54 -08005584 case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
Wink Savilleee274582011-04-16 15:05:49 -07005585 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08005586 case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
5587 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
Wink Saville5b9df332011-04-06 16:24:21 -07005588 case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005589 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
Wink Saville8a9e0212013-04-09 12:11:38 -07005590 case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
Matt Mower897915e2015-04-08 23:16:03 -05005591 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED";
Etan Cohend3652192014-06-20 08:28:44 -07005592 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return "UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED";
5593 case RIL_UNSOL_SRVCC_STATE_NOTIFY: return "UNSOL_SRVCC_STATE_NOTIFY";
Matt Mower897915e2015-04-08 23:16:03 -05005594 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return "UNSOL_HARDWARE_CONFIG_CHANGED";
Wink Savillec29360a2014-07-13 05:17:28 -07005595 case RIL_UNSOL_DC_RT_INFO_CHANGED: return "UNSOL_DC_RT_INFO_CHANGED";
Matt Mower897915e2015-04-08 23:16:03 -05005596 case RIL_UNSOL_RADIO_CAPABILITY: return "UNSOL_RADIO_CAPABILITY";
Mark Salyzyn0078c8d2016-12-12 14:41:47 -08005597 case RIL_UNSOL_MODEM_RESTART: return "UNSOL_MODEM_RESTART";
Matt Mower897915e2015-04-08 23:16:03 -05005598 case RIL_UNSOL_ON_SS: return "UNSOL_ON_SS";
5599 case RIL_UNSOL_STK_CC_ALPHA_NOTIFY: return "UNSOL_STK_CC_ALPHA_NOTIFY";
5600 case RIL_UNSOL_LCEDATA_RECV: return "UNSOL_LCEDATA_RECV";
5601 case RIL_UNSOL_PCO_DATA: return "UNSOL_PCO_DATA";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005602 default: return "<unknown request>";
5603 }
5604}
5605
Etan Cohend3652192014-06-20 08:28:44 -07005606const char *
5607rilSocketIdToString(RIL_SOCKET_ID socket_id)
5608{
5609 switch(socket_id) {
5610 case RIL_SOCKET_1:
5611 return "RIL_SOCKET_1";
5612#if (SIM_COUNT >= 2)
5613 case RIL_SOCKET_2:
5614 return "RIL_SOCKET_2";
5615#endif
5616#if (SIM_COUNT >= 3)
5617 case RIL_SOCKET_3:
5618 return "RIL_SOCKET_3";
5619#endif
5620#if (SIM_COUNT >= 4)
5621 case RIL_SOCKET_4:
5622 return "RIL_SOCKET_4";
5623#endif
5624 default:
5625 return "not a valid RIL";
5626 }
5627}
5628
Sanket Padawe4c05f352016-01-26 16:19:00 -08005629/*
5630 * Returns true for a debuggable build.
5631 */
5632static bool isDebuggable() {
5633 char debuggable[PROP_VALUE_MAX];
5634 property_get("ro.debuggable", debuggable, "0");
5635 if (strcmp(debuggable, "1") == 0) {
5636 return true;
5637 }
5638 return false;
5639}
5640
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005641} /* namespace android */
Dheeraj Shetty27976c42014-07-02 21:27:57 +02005642
5643void rilEventAddWakeup_helper(struct ril_event *ev) {
5644 android::rilEventAddWakeup(ev);
5645}
5646
5647void listenCallback_helper(int fd, short flags, void *param) {
5648 android::listenCallback(fd, flags, param);
5649}
5650
5651int blockingWrite_helper(int fd, void *buffer, size_t len) {
5652 return android::blockingWrite(fd, buffer, len);
5653}