blob: 416cc336b4de64d766aa3d61195ee2605074decc [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>
Mathias Agopian8a3c48c2009-05-19 19:11:50 -070029#include <binder/Parcel.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080030#include <cutils/jstring.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080031#include <sys/types.h>
Wink Saville18e4ab12013-04-07 17:31:04 -070032#include <sys/limits.h>
Sanket Padawe88cf6a52016-01-11 12:45:43 -080033#include <sys/system_properties.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080034#include <pwd.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080035#include <stdio.h>
36#include <stdlib.h>
37#include <stdarg.h>
38#include <string.h>
39#include <unistd.h>
40#include <fcntl.h>
41#include <time.h>
42#include <errno.h>
43#include <assert.h>
44#include <ctype.h>
45#include <alloca.h>
46#include <sys/un.h>
47#include <assert.h>
48#include <netinet/in.h>
49#include <cutils/properties.h>
Dheeraj Shetty27976c42014-07-02 21:27:57 +020050#include <RilSapSocket.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
62#define SOCKET_NAME_RIL "rild"
Etan Cohend3652192014-06-20 08:28:44 -070063#define SOCKET2_NAME_RIL "rild2"
64#define SOCKET3_NAME_RIL "rild3"
65#define SOCKET4_NAME_RIL "rild4"
66
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080067#define SOCKET_NAME_RIL_DEBUG "rild-debug"
68
69#define ANDROID_WAKE_LOCK_NAME "radio-interface"
70
Nathan Harolda0153392015-07-28 14:54:58 -070071#define ANDROID_WAKE_LOCK_SECS 0
72#define ANDROID_WAKE_LOCK_USECS 200000
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080073
74#define PROPERTY_RIL_IMPL "gsm.version.ril-impl"
75
76// match with constant in RIL.java
77#define MAX_COMMAND_BYTES (8 * 1024)
78
79// Basically: memset buffers that the client library
80// shouldn't be using anymore in an attempt to find
81// memory usage issues sooner.
82#define MEMSET_FREED 1
83
84#define NUM_ELEMS(a) (sizeof (a) / sizeof (a)[0])
85
Wink Savillef4c4d362009-04-02 01:37:03 -070086#define MIN(a,b) ((a)<(b) ? (a) : (b))
87
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080088/* Constants for response types */
89#define RESPONSE_SOLICITED 0
90#define RESPONSE_UNSOLICITED 1
Sanket Padawe6ff9a872016-01-27 15:09:12 -080091#define RESPONSE_SOLICITED_ACK 2
92#define RESPONSE_SOLICITED_ACK_EXP 3
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080093
94/* Negative values for private RIL errno's */
95#define RIL_ERRNO_INVALID_RESPONSE -1
96
97// request, response, and unsolicited msg print macro
98#define PRINTBUF_SIZE 8096
99
Robert Greenwalt191e4dc2015-04-29 16:57:39 -0700100// Enable verbose logging
101#define VDBG 0
102
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800103// Enable RILC log
104#define RILC_LOG 0
105
106#if RILC_LOG
107 #define startRequest sprintf(printBuf, "(")
108 #define closeRequest sprintf(printBuf, "%s)", printBuf)
109 #define printRequest(token, req) \
Wink Saville8eb2a122012-11-19 16:05:13 -0800110 RLOGD("[%04d]> %s %s", token, requestToString(req), printBuf)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800111
112 #define startResponse sprintf(printBuf, "%s {", printBuf)
113 #define closeResponse sprintf(printBuf, "%s}", printBuf)
Wink Saville8eb2a122012-11-19 16:05:13 -0800114 #define printResponse RLOGD("%s", printBuf)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800115
116 #define clearPrintBuf printBuf[0] = 0
117 #define removeLastChar printBuf[strlen(printBuf)-1] = 0
118 #define appendPrintBuf(x...) sprintf(printBuf, x)
119#else
120 #define startRequest
121 #define closeRequest
122 #define printRequest(token, req)
123 #define startResponse
124 #define closeResponse
125 #define printResponse
126 #define clearPrintBuf
127 #define removeLastChar
128 #define appendPrintBuf(x...)
129#endif
130
131enum WakeType {DONT_WAKE, WAKE_PARTIAL};
132
133typedef struct {
134 int requestNumber;
135 void (*dispatchFunction) (Parcel &p, struct RequestInfo *pRI);
136 int(*responseFunction) (Parcel &p, void *response, size_t responselen);
137} CommandInfo;
138
139typedef struct {
140 int requestNumber;
141 int (*responseFunction) (Parcel &p, void *response, size_t responselen);
142 WakeType wakeType;
143} UnsolResponseInfo;
144
145typedef struct RequestInfo {
Wink Saville7f856802009-06-09 10:23:37 -0700146 int32_t token; //this is not RIL_Token
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800147 CommandInfo *pCI;
148 struct RequestInfo *p_next;
149 char cancelled;
150 char local; // responses to local commands do not go back to command process
Etan Cohend3652192014-06-20 08:28:44 -0700151 RIL_SOCKET_ID socket_id;
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800152 int wasAckSent; // Indicates whether an ack was sent earlier
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800153} RequestInfo;
154
Wink Saville3d54e742009-05-18 18:00:44 -0700155typedef struct UserCallbackInfo {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800156 RIL_TimedCallback p_callback;
157 void *userParam;
158 struct ril_event event;
159 struct UserCallbackInfo *p_next;
160} UserCallbackInfo;
161
Etan Cohend3652192014-06-20 08:28:44 -0700162extern "C" const char * requestToString(int request);
163extern "C" const char * failCauseToString(RIL_Errno);
164extern "C" const char * callStateToString(RIL_CallState);
165extern "C" const char * radioStateToString(RIL_RadioState);
166extern "C" const char * rilSocketIdToString(RIL_SOCKET_ID socket_id);
167
168extern "C"
169char rild[MAX_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800170/*******************************************************************/
171
172RIL_RadioFunctions s_callbacks = {0, NULL, NULL, NULL, NULL, NULL};
173static int s_registerCalled = 0;
174
175static pthread_t s_tid_dispatch;
176static pthread_t s_tid_reader;
177static int s_started = 0;
178
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800179static int s_fdDebug = -1;
Etan Cohend3652192014-06-20 08:28:44 -0700180static int s_fdDebug_socket2 = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800181
182static int s_fdWakeupRead;
183static int s_fdWakeupWrite;
184
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800185int s_wakelock_count = 0;
186
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800187static struct ril_event s_commands_event;
188static struct ril_event s_wakeupfd_event;
189static struct ril_event s_listen_event;
Etan Cohend3652192014-06-20 08:28:44 -0700190static SocketListenParam s_ril_param_socket;
191
192static pthread_mutex_t s_pendingRequestsMutex = PTHREAD_MUTEX_INITIALIZER;
193static pthread_mutex_t s_writeMutex = PTHREAD_MUTEX_INITIALIZER;
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800194static pthread_mutex_t s_wakeLockCountMutex = PTHREAD_MUTEX_INITIALIZER;
Etan Cohend3652192014-06-20 08:28:44 -0700195static RequestInfo *s_pendingRequests = NULL;
196
197#if (SIM_COUNT >= 2)
198static struct ril_event s_commands_event_socket2;
199static struct ril_event s_listen_event_socket2;
200static SocketListenParam s_ril_param_socket2;
201
202static pthread_mutex_t s_pendingRequestsMutex_socket2 = PTHREAD_MUTEX_INITIALIZER;
203static pthread_mutex_t s_writeMutex_socket2 = PTHREAD_MUTEX_INITIALIZER;
204static RequestInfo *s_pendingRequests_socket2 = NULL;
205#endif
206
207#if (SIM_COUNT >= 3)
208static struct ril_event s_commands_event_socket3;
209static struct ril_event s_listen_event_socket3;
210static SocketListenParam s_ril_param_socket3;
211
212static pthread_mutex_t s_pendingRequestsMutex_socket3 = PTHREAD_MUTEX_INITIALIZER;
213static pthread_mutex_t s_writeMutex_socket3 = PTHREAD_MUTEX_INITIALIZER;
214static RequestInfo *s_pendingRequests_socket3 = NULL;
215#endif
216
217#if (SIM_COUNT >= 4)
218static struct ril_event s_commands_event_socket4;
219static struct ril_event s_listen_event_socket4;
220static SocketListenParam s_ril_param_socket4;
221
222static pthread_mutex_t s_pendingRequestsMutex_socket4 = PTHREAD_MUTEX_INITIALIZER;
223static pthread_mutex_t s_writeMutex_socket4 = PTHREAD_MUTEX_INITIALIZER;
224static RequestInfo *s_pendingRequests_socket4 = NULL;
225#endif
226
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800227static struct ril_event s_wake_timeout_event;
228static struct ril_event s_debug_event;
229
230
Nathan Harolda0153392015-07-28 14:54:58 -0700231static const struct timeval TIMEVAL_WAKE_TIMEOUT = {ANDROID_WAKE_LOCK_SECS,ANDROID_WAKE_LOCK_USECS};
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800232
Etan Cohend3652192014-06-20 08:28:44 -0700233
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800234static pthread_mutex_t s_startupMutex = PTHREAD_MUTEX_INITIALIZER;
235static pthread_cond_t s_startupCond = PTHREAD_COND_INITIALIZER;
236
237static pthread_mutex_t s_dispatchMutex = PTHREAD_MUTEX_INITIALIZER;
238static pthread_cond_t s_dispatchCond = PTHREAD_COND_INITIALIZER;
239
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800240static RequestInfo *s_toDispatchHead = NULL;
241static RequestInfo *s_toDispatchTail = NULL;
242
243static UserCallbackInfo *s_last_wake_timeout_info = NULL;
244
245static void *s_lastNITZTimeData = NULL;
246static size_t s_lastNITZTimeDataSize;
247
248#if RILC_LOG
249 static char printBuf[PRINTBUF_SIZE];
250#endif
251
252/*******************************************************************/
Etan Cohend3652192014-06-20 08:28:44 -0700253static int sendResponse (Parcel &p, RIL_SOCKET_ID socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800254
255static void dispatchVoid (Parcel& p, RequestInfo *pRI);
256static void dispatchString (Parcel& p, RequestInfo *pRI);
257static void dispatchStrings (Parcel& p, RequestInfo *pRI);
258static void dispatchInts (Parcel& p, RequestInfo *pRI);
259static void dispatchDial (Parcel& p, RequestInfo *pRI);
260static void dispatchSIM_IO (Parcel& p, RequestInfo *pRI);
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800261static void dispatchSIM_APDU (Parcel& p, RequestInfo *pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800262static void dispatchCallForward(Parcel& p, RequestInfo *pRI);
263static void dispatchRaw(Parcel& p, RequestInfo *pRI);
264static void dispatchSmsWrite (Parcel &p, RequestInfo *pRI);
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -0700265static void dispatchDataCall (Parcel& p, RequestInfo *pRI);
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800266static void dispatchVoiceRadioTech (Parcel& p, RequestInfo *pRI);
Sungmin Choi75697532013-04-26 15:04:45 -0700267static void dispatchSetInitialAttachApn (Parcel& p, RequestInfo *pRI);
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800268static void dispatchCdmaSubscriptionSource (Parcel& p, RequestInfo *pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800269
Wink Savillef4c4d362009-04-02 01:37:03 -0700270static void dispatchCdmaSms(Parcel &p, RequestInfo *pRI);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -0700271static void dispatchImsSms(Parcel &p, RequestInfo *pRI);
272static void dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
273static void dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
Wink Savillef4c4d362009-04-02 01:37:03 -0700274static void dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI);
Wink Savillea592eeb2009-05-22 13:26:36 -0700275static void dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI);
Wink Savillef4c4d362009-04-02 01:37:03 -0700276static void dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI);
277static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI);
Jake Hamby8a4a2332014-01-15 13:12:05 -0800278static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI);
279static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI);
Etan Cohend3652192014-06-20 08:28:44 -0700280static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI);
Amit Mahajan90530a62014-07-01 15:54:08 -0700281static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI);
Amit Mahajanc796e222014-08-13 16:54:01 +0000282static void dispatchDataProfile(Parcel &p, RequestInfo *pRI);
Wink Saville8b4e4f72014-10-17 15:01:45 -0700283static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800284static int responseInts(Parcel &p, void *response, size_t responselen);
Chao Liu548a81e2015-05-14 16:13:46 -0700285static int responseFailCause(Parcel &p, void *response, size_t responselen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800286static int responseStrings(Parcel &p, void *response, size_t responselen);
287static int responseString(Parcel &p, void *response, size_t responselen);
288static int responseVoid(Parcel &p, void *response, size_t responselen);
289static int responseCallList(Parcel &p, void *response, size_t responselen);
290static int responseSMS(Parcel &p, void *response, size_t responselen);
291static int responseSIM_IO(Parcel &p, void *response, size_t responselen);
292static int responseCallForwards(Parcel &p, void *response, size_t responselen);
Wink Savillef4c4d362009-04-02 01:37:03 -0700293static int responseDataCallList(Parcel &p, void *response, size_t responselen);
Wink Saville43808972011-01-13 17:39:51 -0800294static int responseSetupDataCall(Parcel &p, void *response, size_t responselen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800295static int responseRaw(Parcel &p, void *response, size_t responselen);
296static int responseSsn(Parcel &p, void *response, size_t responselen);
Wink Savillef4c4d362009-04-02 01:37:03 -0700297static int responseSimStatus(Parcel &p, void *response, size_t responselen);
Wink Savillea592eeb2009-05-22 13:26:36 -0700298static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen);
299static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen);
Wink Savillef4c4d362009-04-02 01:37:03 -0700300static int responseCdmaSms(Parcel &p, void *response, size_t responselen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800301static int responseCellList(Parcel &p, void *response, size_t responselen);
Wink Saville3d54e742009-05-18 18:00:44 -0700302static int responseCdmaInformationRecords(Parcel &p,void *response, size_t responselen);
303static int responseRilSignalStrength(Parcel &p,void *response, size_t responselen);
304static int responseCallRing(Parcel &p, void *response, size_t responselen);
305static int responseCdmaSignalInfoRecord(Parcel &p,void *response, size_t responselen);
306static int responseCdmaCallWaiting(Parcel &p,void *response, size_t responselen);
Alex Yakavenka45e740e2012-01-31 11:48:27 -0800307static int responseSimRefresh(Parcel &p, void *response, size_t responselen);
Wink Saville8a9e0212013-04-09 12:11:38 -0700308static int responseCellInfoList(Parcel &p, void *response, size_t responselen);
Etan Cohend3652192014-06-20 08:28:44 -0700309static int responseHardwareConfig(Parcel &p, void *response, size_t responselen);
Wink Savillec29360a2014-07-13 05:17:28 -0700310static int responseDcRtInfo(Parcel &p, void *response, size_t responselen);
Wink Saville8b4e4f72014-10-17 15:01:45 -0700311static int responseRadioCapability(Parcel &p, void *response, size_t responselen);
Amit Mahajan54563d32014-11-22 00:54:49 +0000312static int responseSSData(Parcel &p, void *response, size_t responselen);
fengluf7408292015-04-14 14:53:55 -0700313static int responseLceStatus(Parcel &p, void *response, size_t responselen);
314static int responseLceData(Parcel &p, void *response, size_t responselen);
Prerepa Viswanadham73157492015-05-28 00:37:32 -0700315static int responseActivityData(Parcel &p, void *response, size_t responselen);
Amit Mahajan54563d32014-11-22 00:54:49 +0000316
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800317static int decodeVoiceRadioTechnology (RIL_RadioState radioState);
318static int decodeCdmaSubscriptionSource (RIL_RadioState radioState);
319static RIL_RadioState processRadioState(RIL_RadioState newRadioState);
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800320static void grabPartialWakeLock();
321static void releaseWakeLock();
322static void wakeTimeoutCallback(void *);
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800323
Amit Mahajan54563d32014-11-22 00:54:49 +0000324static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType);
325
Sanket Padawe88cf6a52016-01-11 12:45:43 -0800326static bool isDebuggable();
327
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800328#ifdef RIL_SHLIB
Etan Cohend3652192014-06-20 08:28:44 -0700329#if defined(ANDROID_MULTI_SIM)
Vinit Deshpande1b1ec2d2015-04-15 13:31:05 -0700330extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Etan Cohend3652192014-06-20 08:28:44 -0700331 size_t datalen, RIL_SOCKET_ID socket_id);
332#else
Vinit Deshpande1b1ec2d2015-04-15 13:31:05 -0700333extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800334 size_t datalen);
335#endif
Etan Cohend3652192014-06-20 08:28:44 -0700336#endif
337
338#if defined(ANDROID_MULTI_SIM)
339#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c), (d))
340#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d), (e))
341#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest(a)
342#else
343#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c))
344#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d))
345#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest()
346#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800347
Wink Saville7f856802009-06-09 10:23:37 -0700348static UserCallbackInfo * internalRequestTimedCallback
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -0700349 (RIL_TimedCallback callback, void *param,
350 const struct timeval *relativeTime);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800351
352/** Index == requestNumber */
353static CommandInfo s_commands[] = {
354#include "ril_commands.h"
355};
356
357static UnsolResponseInfo s_unsolResponses[] = {
358#include "ril_unsol_commands.h"
359};
360
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800361/* For older RILs that do not support new commands RIL_REQUEST_VOICE_RADIO_TECH and
362 RIL_UNSOL_VOICE_RADIO_TECH_CHANGED messages, decode the voice radio tech from
363 radio state message and store it. Every time there is a change in Radio State
364 check to see if voice radio tech changes and notify telephony
365 */
366int voiceRadioTech = -1;
367
368/* For older RILs that do not support new commands RIL_REQUEST_GET_CDMA_SUBSCRIPTION_SOURCE
369 and RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED messages, decode the subscription
370 source from radio state and store it. Every time there is a change in Radio State
371 check to see if subscription source changed and notify telephony
372 */
373int cdmaSubscriptionSource = -1;
374
375/* For older RILs that do not send RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, decode the
376 SIM/RUIM state from radio state and store it. Every time there is a change in Radio State,
377 check to see if SIM/RUIM status changed and notify telephony
378 */
379int simRuimStatus = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800380
Etan Cohend3652192014-06-20 08:28:44 -0700381static char * RIL_getRilSocketName() {
382 return rild;
383}
384
385extern "C"
Dheeraj Shetty27976c42014-07-02 21:27:57 +0200386void RIL_setRilSocketName(const char * s) {
Etan Cohend3652192014-06-20 08:28:44 -0700387 strncpy(rild, s, MAX_SOCKET_NAME_LENGTH);
388}
389
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800390static char *
Wink Savillef4c4d362009-04-02 01:37:03 -0700391strdupReadString(Parcel &p) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800392 size_t stringlen;
393 const char16_t *s16;
Wink Saville7f856802009-06-09 10:23:37 -0700394
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800395 s16 = p.readString16Inplace(&stringlen);
Wink Saville7f856802009-06-09 10:23:37 -0700396
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800397 return strndup16to8(s16, stringlen);
398}
399
Wink Saville8b4e4f72014-10-17 15:01:45 -0700400static status_t
401readStringFromParcelInplace(Parcel &p, char *str, size_t maxLen) {
402 size_t s16Len;
403 const char16_t *s16;
404
405 s16 = p.readString16Inplace(&s16Len);
406 if (s16 == NULL) {
407 return NO_MEMORY;
408 }
409 size_t strLen = strnlen16to8(s16, s16Len);
410 if ((strLen + 1) > maxLen) {
411 return NO_MEMORY;
412 }
413 if (strncpy16to8(str, s16, strLen) == NULL) {
414 return NO_MEMORY;
415 } else {
416 return NO_ERROR;
417 }
418}
419
Wink Savillef4c4d362009-04-02 01:37:03 -0700420static void writeStringToParcel(Parcel &p, const char *s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800421 char16_t *s16;
422 size_t s16_len;
423 s16 = strdup8to16(s, &s16_len);
424 p.writeString16(s16, s16_len);
425 free(s16);
426}
427
428
429static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700430memsetString (char *s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800431 if (s != NULL) {
432 memset (s, 0, strlen(s));
433 }
434}
435
436void nullParcelReleaseFunction (const uint8_t* data, size_t dataSize,
437 const size_t* objects, size_t objectsSize,
Wink Savillef4c4d362009-04-02 01:37:03 -0700438 void* cookie) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800439 // do nothing -- the data reference lives longer than the Parcel object
440}
441
Wink Saville7f856802009-06-09 10:23:37 -0700442/**
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800443 * To be called from dispatch thread
444 * Issue a single local request, ensuring that the response
Wink Saville7f856802009-06-09 10:23:37 -0700445 * is not sent back up to the command process
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800446 */
447static void
Etan Cohend3652192014-06-20 08:28:44 -0700448issueLocalRequest(int request, void *data, int len, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800449 RequestInfo *pRI;
450 int ret;
Etan Cohend3652192014-06-20 08:28:44 -0700451 /* Hook for current context */
452 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
453 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
454 /* pendingRequestsHook refer to &s_pendingRequests */
455 RequestInfo** pendingRequestsHook = &s_pendingRequests;
456
457#if (SIM_COUNT == 2)
458 if (socket_id == RIL_SOCKET_2) {
459 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
460 pendingRequestsHook = &s_pendingRequests_socket2;
461 }
462#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800463
464 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
465
466 pRI->local = 1;
467 pRI->token = 0xffffffff; // token is not used in this context
468 pRI->pCI = &(s_commands[request]);
Etan Cohend3652192014-06-20 08:28:44 -0700469 pRI->socket_id = socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800470
Etan Cohend3652192014-06-20 08:28:44 -0700471 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800472 assert (ret == 0);
473
Etan Cohend3652192014-06-20 08:28:44 -0700474 pRI->p_next = *pendingRequestsHook;
475 *pendingRequestsHook = pRI;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800476
Etan Cohend3652192014-06-20 08:28:44 -0700477 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800478 assert (ret == 0);
479
Wink Saville8eb2a122012-11-19 16:05:13 -0800480 RLOGD("C[locl]> %s", requestToString(request));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800481
Etan Cohend3652192014-06-20 08:28:44 -0700482 CALL_ONREQUEST(request, data, len, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800483}
484
485
486
487static int
Etan Cohend3652192014-06-20 08:28:44 -0700488processCommandBuffer(void *buffer, size_t buflen, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800489 Parcel p;
490 status_t status;
491 int32_t request;
492 int32_t token;
493 RequestInfo *pRI;
494 int ret;
Etan Cohend3652192014-06-20 08:28:44 -0700495 /* Hook for current context */
496 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
497 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
498 /* pendingRequestsHook refer to &s_pendingRequests */
499 RequestInfo** pendingRequestsHook = &s_pendingRequests;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800500
501 p.setData((uint8_t *) buffer, buflen);
502
503 // status checked at end
504 status = p.readInt32(&request);
505 status = p.readInt32 (&token);
506
Etan Cohend3652192014-06-20 08:28:44 -0700507#if (SIM_COUNT >= 2)
508 if (socket_id == RIL_SOCKET_2) {
509 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
510 pendingRequestsHook = &s_pendingRequests_socket2;
511 }
512#if (SIM_COUNT >= 3)
513 else if (socket_id == RIL_SOCKET_3) {
514 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
515 pendingRequestsHook = &s_pendingRequests_socket3;
516 }
517#endif
518#if (SIM_COUNT >= 4)
519 else if (socket_id == RIL_SOCKET_4) {
520 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
521 pendingRequestsHook = &s_pendingRequests_socket4;
522 }
523#endif
524#endif
525
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800526 if (status != NO_ERROR) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800527 RLOGE("invalid request block");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800528 return 0;
529 }
530
531 if (request < 1 || request >= (int32_t)NUM_ELEMS(s_commands)) {
Etan Cohend3652192014-06-20 08:28:44 -0700532 Parcel pErr;
Wink Saville8eb2a122012-11-19 16:05:13 -0800533 RLOGE("unsupported request code %d token %d", request, token);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800534 // FIXME this should perhaps return a response
Etan Cohend3652192014-06-20 08:28:44 -0700535 pErr.writeInt32 (RESPONSE_SOLICITED);
536 pErr.writeInt32 (token);
537 pErr.writeInt32 (RIL_E_GENERIC_FAILURE);
538
539 sendResponse(pErr, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800540 return 0;
541 }
542
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800543 // Received an Ack for the previous result sent to RIL.java,
544 // so release wakelock and exit
545 if (request == RIL_RESPONSE_ACKNOWLEDGEMENT) {
546 releaseWakeLock();
547 return 0;
548 }
549
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800550
551 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
552
553 pRI->token = token;
554 pRI->pCI = &(s_commands[request]);
Etan Cohend3652192014-06-20 08:28:44 -0700555 pRI->socket_id = socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800556
Etan Cohend3652192014-06-20 08:28:44 -0700557 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800558 assert (ret == 0);
559
Etan Cohend3652192014-06-20 08:28:44 -0700560 pRI->p_next = *pendingRequestsHook;
561 *pendingRequestsHook = pRI;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800562
Etan Cohend3652192014-06-20 08:28:44 -0700563 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800564 assert (ret == 0);
565
566/* sLastDispatchedToken = token; */
567
Wink Saville7f856802009-06-09 10:23:37 -0700568 pRI->pCI->dispatchFunction(p, pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800569
570 return 0;
571}
572
573static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700574invalidCommandBlock (RequestInfo *pRI) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800575 RLOGE("invalid command block for token %d request %s",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800576 pRI->token, requestToString(pRI->pCI->requestNumber));
577}
578
579/** Callee expects NULL */
Wink Saville7f856802009-06-09 10:23:37 -0700580static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700581dispatchVoid (Parcel& p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800582 clearPrintBuf;
583 printRequest(pRI->token, pRI->pCI->requestNumber);
Etan Cohend3652192014-06-20 08:28:44 -0700584 CALL_ONREQUEST(pRI->pCI->requestNumber, NULL, 0, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800585}
586
587/** Callee expects const char * */
588static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700589dispatchString (Parcel& p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800590 status_t status;
591 size_t datalen;
592 size_t stringlen;
593 char *string8 = NULL;
594
595 string8 = strdupReadString(p);
596
597 startRequest;
598 appendPrintBuf("%s%s", printBuf, string8);
599 closeRequest;
600 printRequest(pRI->token, pRI->pCI->requestNumber);
601
Etan Cohend3652192014-06-20 08:28:44 -0700602 CALL_ONREQUEST(pRI->pCI->requestNumber, string8,
603 sizeof(char *), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800604
605#ifdef MEMSET_FREED
606 memsetString(string8);
607#endif
608
609 free(string8);
610 return;
611invalid:
612 invalidCommandBlock(pRI);
613 return;
614}
615
616/** Callee expects const char ** */
617static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700618dispatchStrings (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800619 int32_t countStrings;
620 status_t status;
621 size_t datalen;
622 char **pStrings;
623
624 status = p.readInt32 (&countStrings);
625
626 if (status != NO_ERROR) {
627 goto invalid;
628 }
629
630 startRequest;
631 if (countStrings == 0) {
632 // just some non-null pointer
633 pStrings = (char **)alloca(sizeof(char *));
634 datalen = 0;
635 } else if (((int)countStrings) == -1) {
636 pStrings = NULL;
637 datalen = 0;
638 } else {
639 datalen = sizeof(char *) * countStrings;
Wink Saville7f856802009-06-09 10:23:37 -0700640
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800641 pStrings = (char **)alloca(datalen);
642
643 for (int i = 0 ; i < countStrings ; i++) {
644 pStrings[i] = strdupReadString(p);
645 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
646 }
647 }
648 removeLastChar;
649 closeRequest;
650 printRequest(pRI->token, pRI->pCI->requestNumber);
651
Etan Cohend3652192014-06-20 08:28:44 -0700652 CALL_ONREQUEST(pRI->pCI->requestNumber, pStrings, datalen, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800653
654 if (pStrings != NULL) {
655 for (int i = 0 ; i < countStrings ; i++) {
656#ifdef MEMSET_FREED
657 memsetString (pStrings[i]);
658#endif
659 free(pStrings[i]);
660 }
661
662#ifdef MEMSET_FREED
663 memset(pStrings, 0, datalen);
664#endif
665 }
Wink Saville7f856802009-06-09 10:23:37 -0700666
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800667 return;
668invalid:
669 invalidCommandBlock(pRI);
670 return;
671}
672
673/** Callee expects const int * */
674static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700675dispatchInts (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800676 int32_t count;
677 status_t status;
678 size_t datalen;
679 int *pInts;
680
681 status = p.readInt32 (&count);
682
683 if (status != NO_ERROR || count == 0) {
684 goto invalid;
685 }
686
687 datalen = sizeof(int) * count;
688 pInts = (int *)alloca(datalen);
689
690 startRequest;
691 for (int i = 0 ; i < count ; i++) {
692 int32_t t;
693
694 status = p.readInt32(&t);
695 pInts[i] = (int)t;
696 appendPrintBuf("%s%d,", printBuf, t);
697
698 if (status != NO_ERROR) {
699 goto invalid;
700 }
701 }
702 removeLastChar;
703 closeRequest;
704 printRequest(pRI->token, pRI->pCI->requestNumber);
705
Etan Cohend3652192014-06-20 08:28:44 -0700706 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<int *>(pInts),
707 datalen, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800708
709#ifdef MEMSET_FREED
710 memset(pInts, 0, datalen);
711#endif
712
713 return;
714invalid:
715 invalidCommandBlock(pRI);
716 return;
717}
718
719
Wink Saville7f856802009-06-09 10:23:37 -0700720/**
721 * Callee expects const RIL_SMS_WriteArgs *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800722 * Payload is:
723 * int32_t status
724 * String pdu
725 */
726static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700727dispatchSmsWrite (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800728 RIL_SMS_WriteArgs args;
729 int32_t t;
730 status_t status;
731
Mark Salyzyndba25612015-04-09 07:18:35 -0700732 RLOGD("dispatchSmsWrite");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800733 memset (&args, 0, sizeof(args));
734
735 status = p.readInt32(&t);
736 args.status = (int)t;
737
738 args.pdu = strdupReadString(p);
739
740 if (status != NO_ERROR || args.pdu == NULL) {
741 goto invalid;
742 }
743
744 args.smsc = strdupReadString(p);
745
746 startRequest;
747 appendPrintBuf("%s%d,%s,smsc=%s", printBuf, args.status,
748 (char*)args.pdu, (char*)args.smsc);
749 closeRequest;
750 printRequest(pRI->token, pRI->pCI->requestNumber);
Wink Saville7f856802009-06-09 10:23:37 -0700751
Etan Cohend3652192014-06-20 08:28:44 -0700752 CALL_ONREQUEST(pRI->pCI->requestNumber, &args, sizeof(args), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800753
754#ifdef MEMSET_FREED
755 memsetString (args.pdu);
756#endif
757
758 free (args.pdu);
Wink Saville7f856802009-06-09 10:23:37 -0700759
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800760#ifdef MEMSET_FREED
761 memset(&args, 0, sizeof(args));
762#endif
763
764 return;
765invalid:
766 invalidCommandBlock(pRI);
767 return;
768}
769
Wink Saville7f856802009-06-09 10:23:37 -0700770/**
771 * Callee expects const RIL_Dial *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800772 * Payload is:
773 * String address
774 * int32_t clir
775 */
776static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700777dispatchDial (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800778 RIL_Dial dial;
Wink Saville74fa3882009-12-22 15:35:41 -0800779 RIL_UUS_Info uusInfo;
Wink Saville7bce0822010-01-08 15:20:12 -0800780 int32_t sizeOfDial;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800781 int32_t t;
Wink Saville74fa3882009-12-22 15:35:41 -0800782 int32_t uusPresent;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800783 status_t status;
784
Mark Salyzyndba25612015-04-09 07:18:35 -0700785 RLOGD("dispatchDial");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800786 memset (&dial, 0, sizeof(dial));
787
788 dial.address = strdupReadString(p);
789
790 status = p.readInt32(&t);
791 dial.clir = (int)t;
792
793 if (status != NO_ERROR || dial.address == NULL) {
794 goto invalid;
795 }
796
Wink Saville3a4840b2010-04-07 13:29:58 -0700797 if (s_callbacks.version < 3) { // Remove when partners upgrade to version 3
Wink Saville74fa3882009-12-22 15:35:41 -0800798 uusPresent = 0;
Wink Saville7bce0822010-01-08 15:20:12 -0800799 sizeOfDial = sizeof(dial) - sizeof(RIL_UUS_Info *);
Wink Saville74fa3882009-12-22 15:35:41 -0800800 } else {
801 status = p.readInt32(&uusPresent);
802
803 if (status != NO_ERROR) {
804 goto invalid;
805 }
806
807 if (uusPresent == 0) {
808 dial.uusInfo = NULL;
809 } else {
810 int32_t len;
811
812 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
813
814 status = p.readInt32(&t);
815 uusInfo.uusType = (RIL_UUS_Type) t;
816
817 status = p.readInt32(&t);
818 uusInfo.uusDcs = (RIL_UUS_DCS) t;
819
820 status = p.readInt32(&len);
821 if (status != NO_ERROR) {
822 goto invalid;
823 }
824
825 // The java code writes -1 for null arrays
826 if (((int) len) == -1) {
827 uusInfo.uusData = NULL;
828 len = 0;
829 } else {
830 uusInfo.uusData = (char*) p.readInplace(len);
831 }
832
833 uusInfo.uusLength = len;
834 dial.uusInfo = &uusInfo;
835 }
Wink Saville7bce0822010-01-08 15:20:12 -0800836 sizeOfDial = sizeof(dial);
Wink Saville74fa3882009-12-22 15:35:41 -0800837 }
838
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800839 startRequest;
840 appendPrintBuf("%snum=%s,clir=%d", printBuf, dial.address, dial.clir);
Wink Saville74fa3882009-12-22 15:35:41 -0800841 if (uusPresent) {
842 appendPrintBuf("%s,uusType=%d,uusDcs=%d,uusLen=%d", printBuf,
843 dial.uusInfo->uusType, dial.uusInfo->uusDcs,
844 dial.uusInfo->uusLength);
845 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800846 closeRequest;
847 printRequest(pRI->token, pRI->pCI->requestNumber);
848
Etan Cohend3652192014-06-20 08:28:44 -0700849 CALL_ONREQUEST(pRI->pCI->requestNumber, &dial, sizeOfDial, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800850
851#ifdef MEMSET_FREED
852 memsetString (dial.address);
853#endif
854
855 free (dial.address);
Wink Saville7f856802009-06-09 10:23:37 -0700856
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800857#ifdef MEMSET_FREED
Wink Saville74fa3882009-12-22 15:35:41 -0800858 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800859 memset(&dial, 0, sizeof(dial));
860#endif
861
862 return;
863invalid:
864 invalidCommandBlock(pRI);
865 return;
866}
867
Wink Saville7f856802009-06-09 10:23:37 -0700868/**
869 * Callee expects const RIL_SIM_IO *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800870 * Payload is:
871 * int32_t command
872 * int32_t fileid
873 * String path
874 * int32_t p1, p2, p3
Wink Saville7f856802009-06-09 10:23:37 -0700875 * String data
876 * String pin2
Wink Savillec0114b32011-02-18 10:14:07 -0800877 * String aidPtr
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800878 */
879static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700880dispatchSIM_IO (Parcel &p, RequestInfo *pRI) {
Wink Savillec0114b32011-02-18 10:14:07 -0800881 union RIL_SIM_IO {
882 RIL_SIM_IO_v6 v6;
883 RIL_SIM_IO_v5 v5;
884 } simIO;
885
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800886 int32_t t;
Wink Savillec0114b32011-02-18 10:14:07 -0800887 int size;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800888 status_t status;
889
Robert Greenwalt191e4dc2015-04-29 16:57:39 -0700890#if VDBG
Mark Salyzyndba25612015-04-09 07:18:35 -0700891 RLOGD("dispatchSIM_IO");
Robert Greenwalt191e4dc2015-04-29 16:57:39 -0700892#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800893 memset (&simIO, 0, sizeof(simIO));
894
Wink Saville7f856802009-06-09 10:23:37 -0700895 // note we only check status at the end
896
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800897 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800898 simIO.v6.command = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800899
900 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800901 simIO.v6.fileid = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800902
Wink Savillec0114b32011-02-18 10:14:07 -0800903 simIO.v6.path = strdupReadString(p);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800904
905 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800906 simIO.v6.p1 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800907
908 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800909 simIO.v6.p2 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800910
911 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800912 simIO.v6.p3 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800913
Wink Savillec0114b32011-02-18 10:14:07 -0800914 simIO.v6.data = strdupReadString(p);
915 simIO.v6.pin2 = strdupReadString(p);
916 simIO.v6.aidPtr = strdupReadString(p);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800917
918 startRequest;
Wink Savillec0114b32011-02-18 10:14:07 -0800919 appendPrintBuf("%scmd=0x%X,efid=0x%X,path=%s,%d,%d,%d,%s,pin2=%s,aid=%s", printBuf,
920 simIO.v6.command, simIO.v6.fileid, (char*)simIO.v6.path,
921 simIO.v6.p1, simIO.v6.p2, simIO.v6.p3,
922 (char*)simIO.v6.data, (char*)simIO.v6.pin2, simIO.v6.aidPtr);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800923 closeRequest;
924 printRequest(pRI->token, pRI->pCI->requestNumber);
Wink Saville7f856802009-06-09 10:23:37 -0700925
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800926 if (status != NO_ERROR) {
927 goto invalid;
928 }
929
Wink Savillec0114b32011-02-18 10:14:07 -0800930 size = (s_callbacks.version < 6) ? sizeof(simIO.v5) : sizeof(simIO.v6);
Etan Cohend3652192014-06-20 08:28:44 -0700931 CALL_ONREQUEST(pRI->pCI->requestNumber, &simIO, size, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800932
933#ifdef MEMSET_FREED
Wink Savillec0114b32011-02-18 10:14:07 -0800934 memsetString (simIO.v6.path);
935 memsetString (simIO.v6.data);
936 memsetString (simIO.v6.pin2);
937 memsetString (simIO.v6.aidPtr);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800938#endif
939
Wink Savillec0114b32011-02-18 10:14:07 -0800940 free (simIO.v6.path);
941 free (simIO.v6.data);
942 free (simIO.v6.pin2);
943 free (simIO.v6.aidPtr);
Wink Saville7f856802009-06-09 10:23:37 -0700944
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800945#ifdef MEMSET_FREED
946 memset(&simIO, 0, sizeof(simIO));
947#endif
948
949 return;
950invalid:
951 invalidCommandBlock(pRI);
952 return;
953}
954
955/**
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800956 * Callee expects const RIL_SIM_APDU *
957 * Payload is:
958 * int32_t sessionid
959 * int32_t cla
960 * int32_t instruction
961 * int32_t p1, p2, p3
962 * String data
963 */
964static void
965dispatchSIM_APDU (Parcel &p, RequestInfo *pRI) {
966 int32_t t;
967 status_t status;
968 RIL_SIM_APDU apdu;
969
Robert Greenwalt191e4dc2015-04-29 16:57:39 -0700970#if VDBG
Mark Salyzyndba25612015-04-09 07:18:35 -0700971 RLOGD("dispatchSIM_APDU");
Robert Greenwalt191e4dc2015-04-29 16:57:39 -0700972#endif
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800973 memset (&apdu, 0, sizeof(RIL_SIM_APDU));
974
975 // Note we only check status at the end. Any single failure leads to
976 // subsequent reads filing.
977 status = p.readInt32(&t);
978 apdu.sessionid = (int)t;
979
980 status = p.readInt32(&t);
981 apdu.cla = (int)t;
982
983 status = p.readInt32(&t);
984 apdu.instruction = (int)t;
985
986 status = p.readInt32(&t);
987 apdu.p1 = (int)t;
988
989 status = p.readInt32(&t);
990 apdu.p2 = (int)t;
991
992 status = p.readInt32(&t);
993 apdu.p3 = (int)t;
994
995 apdu.data = strdupReadString(p);
996
997 startRequest;
998 appendPrintBuf("%ssessionid=%d,cla=%d,ins=%d,p1=%d,p2=%d,p3=%d,data=%s",
999 printBuf, apdu.sessionid, apdu.cla, apdu.instruction, apdu.p1, apdu.p2,
1000 apdu.p3, (char*)apdu.data);
1001 closeRequest;
1002 printRequest(pRI->token, pRI->pCI->requestNumber);
1003
1004 if (status != NO_ERROR) {
1005 goto invalid;
1006 }
1007
Etan Cohend3652192014-06-20 08:28:44 -07001008 CALL_ONREQUEST(pRI->pCI->requestNumber, &apdu, sizeof(RIL_SIM_APDU), pRI, pRI->socket_id);
Shishir Agrawal2458d8d2013-11-27 14:53:05 -08001009
1010#ifdef MEMSET_FREED
1011 memsetString(apdu.data);
1012#endif
1013 free(apdu.data);
1014
1015#ifdef MEMSET_FREED
1016 memset(&apdu, 0, sizeof(RIL_SIM_APDU));
1017#endif
1018
1019 return;
1020invalid:
1021 invalidCommandBlock(pRI);
1022 return;
1023}
1024
1025
1026/**
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001027 * Callee expects const RIL_CallForwardInfo *
1028 * Payload is:
1029 * int32_t status/action
1030 * int32_t reason
1031 * int32_t serviceCode
1032 * int32_t toa
1033 * String number (0 length -> null)
1034 * int32_t timeSeconds
1035 */
Wink Saville7f856802009-06-09 10:23:37 -07001036static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001037dispatchCallForward(Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001038 RIL_CallForwardInfo cff;
1039 int32_t t;
1040 status_t status;
1041
Mark Salyzyndba25612015-04-09 07:18:35 -07001042 RLOGD("dispatchCallForward");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001043 memset (&cff, 0, sizeof(cff));
1044
Wink Saville7f856802009-06-09 10:23:37 -07001045 // note we only check status at the end
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001046
1047 status = p.readInt32(&t);
1048 cff.status = (int)t;
Wink Saville7f856802009-06-09 10:23:37 -07001049
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001050 status = p.readInt32(&t);
1051 cff.reason = (int)t;
1052
1053 status = p.readInt32(&t);
1054 cff.serviceClass = (int)t;
1055
1056 status = p.readInt32(&t);
1057 cff.toa = (int)t;
1058
1059 cff.number = strdupReadString(p);
1060
1061 status = p.readInt32(&t);
1062 cff.timeSeconds = (int)t;
1063
1064 if (status != NO_ERROR) {
1065 goto invalid;
1066 }
1067
1068 // special case: number 0-length fields is null
1069
1070 if (cff.number != NULL && strlen (cff.number) == 0) {
1071 cff.number = NULL;
1072 }
1073
1074 startRequest;
1075 appendPrintBuf("%sstat=%d,reason=%d,serv=%d,toa=%d,%s,tout=%d", printBuf,
1076 cff.status, cff.reason, cff.serviceClass, cff.toa,
1077 (char*)cff.number, cff.timeSeconds);
1078 closeRequest;
1079 printRequest(pRI->token, pRI->pCI->requestNumber);
1080
Etan Cohend3652192014-06-20 08:28:44 -07001081 CALL_ONREQUEST(pRI->pCI->requestNumber, &cff, sizeof(cff), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001082
1083#ifdef MEMSET_FREED
1084 memsetString(cff.number);
1085#endif
1086
1087 free (cff.number);
1088
1089#ifdef MEMSET_FREED
1090 memset(&cff, 0, sizeof(cff));
1091#endif
1092
1093 return;
1094invalid:
1095 invalidCommandBlock(pRI);
1096 return;
1097}
1098
1099
Wink Saville7f856802009-06-09 10:23:37 -07001100static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001101dispatchRaw(Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001102 int32_t len;
1103 status_t status;
1104 const void *data;
1105
1106 status = p.readInt32(&len);
1107
1108 if (status != NO_ERROR) {
1109 goto invalid;
1110 }
1111
1112 // The java code writes -1 for null arrays
1113 if (((int)len) == -1) {
1114 data = NULL;
1115 len = 0;
Wink Saville7f856802009-06-09 10:23:37 -07001116 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001117
1118 data = p.readInplace(len);
1119
1120 startRequest;
1121 appendPrintBuf("%sraw_size=%d", printBuf, len);
1122 closeRequest;
1123 printRequest(pRI->token, pRI->pCI->requestNumber);
1124
Etan Cohend3652192014-06-20 08:28:44 -07001125 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<void *>(data), len, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001126
1127 return;
1128invalid:
1129 invalidCommandBlock(pRI);
1130 return;
1131}
1132
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001133static status_t
1134constructCdmaSms(Parcel &p, RequestInfo *pRI, RIL_CDMA_SMS_Message& rcsm) {
Wink Savillef4c4d362009-04-02 01:37:03 -07001135 int32_t t;
1136 uint8_t ut;
1137 status_t status;
1138 int32_t digitCount;
1139 int digitLimit;
Wink Saville7f856802009-06-09 10:23:37 -07001140
Wink Savillef4c4d362009-04-02 01:37:03 -07001141 memset(&rcsm, 0, sizeof(rcsm));
1142
1143 status = p.readInt32(&t);
1144 rcsm.uTeleserviceID = (int) t;
1145
1146 status = p.read(&ut,sizeof(ut));
1147 rcsm.bIsServicePresent = (uint8_t) ut;
1148
1149 status = p.readInt32(&t);
1150 rcsm.uServicecategory = (int) t;
1151
1152 status = p.readInt32(&t);
1153 rcsm.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1154
1155 status = p.readInt32(&t);
1156 rcsm.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1157
1158 status = p.readInt32(&t);
1159 rcsm.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1160
1161 status = p.readInt32(&t);
1162 rcsm.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1163
1164 status = p.read(&ut,sizeof(ut));
1165 rcsm.sAddress.number_of_digits= (uint8_t) ut;
1166
1167 digitLimit= MIN((rcsm.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
1168 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1169 status = p.read(&ut,sizeof(ut));
1170 rcsm.sAddress.digits[digitCount] = (uint8_t) ut;
1171 }
1172
Wink Saville7f856802009-06-09 10:23:37 -07001173 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001174 rcsm.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1175
Wink Saville7f856802009-06-09 10:23:37 -07001176 status = p.read(&ut,sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001177 rcsm.sSubAddress.odd = (uint8_t) ut;
1178
1179 status = p.read(&ut,sizeof(ut));
1180 rcsm.sSubAddress.number_of_digits = (uint8_t) ut;
1181
1182 digitLimit= MIN((rcsm.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
Wink Saville7f856802009-06-09 10:23:37 -07001183 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1184 status = p.read(&ut,sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001185 rcsm.sSubAddress.digits[digitCount] = (uint8_t) ut;
1186 }
1187
Wink Saville7f856802009-06-09 10:23:37 -07001188 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001189 rcsm.uBearerDataLen = (int) t;
1190
1191 digitLimit= MIN((rcsm.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
Wink Saville7f856802009-06-09 10:23:37 -07001192 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1193 status = p.read(&ut, sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001194 rcsm.aBearerData[digitCount] = (uint8_t) ut;
1195 }
1196
1197 if (status != NO_ERROR) {
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001198 return status;
Wink Savillef4c4d362009-04-02 01:37:03 -07001199 }
1200
1201 startRequest;
1202 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
Wink Saville1b5fd232009-04-22 14:50:00 -07001203 sAddress.digit_mode=%d, sAddress.Number_mode=%d, sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07001204 printBuf, rcsm.uTeleserviceID,rcsm.bIsServicePresent,rcsm.uServicecategory,
Wink Saville1b5fd232009-04-22 14:50:00 -07001205 rcsm.sAddress.digit_mode, rcsm.sAddress.number_mode,rcsm.sAddress.number_type);
Wink Savillef4c4d362009-04-02 01:37:03 -07001206 closeRequest;
Wink Saville7f856802009-06-09 10:23:37 -07001207
Wink Savillef4c4d362009-04-02 01:37:03 -07001208 printRequest(pRI->token, pRI->pCI->requestNumber);
1209
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001210 return status;
1211}
1212
1213static void
1214dispatchCdmaSms(Parcel &p, RequestInfo *pRI) {
1215 RIL_CDMA_SMS_Message rcsm;
1216
Mark Salyzyndba25612015-04-09 07:18:35 -07001217 RLOGD("dispatchCdmaSms");
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001218 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1219 goto invalid;
1220 }
1221
Etan Cohend3652192014-06-20 08:28:44 -07001222 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001223
1224#ifdef MEMSET_FREED
1225 memset(&rcsm, 0, sizeof(rcsm));
1226#endif
1227
1228 return;
1229
1230invalid:
1231 invalidCommandBlock(pRI);
1232 return;
1233}
1234
Wink Saville7f856802009-06-09 10:23:37 -07001235static void
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001236dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1237 RIL_IMS_SMS_Message rism;
1238 RIL_CDMA_SMS_Message rcsm;
1239
Mark Salyzyndba25612015-04-09 07:18:35 -07001240 RLOGD("dispatchImsCdmaSms: retry=%d, messageRef=%d", retry, messageRef);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001241
1242 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1243 goto invalid;
1244 }
1245 memset(&rism, 0, sizeof(rism));
1246 rism.tech = RADIO_TECH_3GPP2;
1247 rism.retry = retry;
1248 rism.messageRef = messageRef;
1249 rism.message.cdmaMessage = &rcsm;
1250
Etan Cohend3652192014-06-20 08:28:44 -07001251 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001252 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Etan Cohend3652192014-06-20 08:28:44 -07001253 +sizeof(rcsm),pRI, pRI->socket_id);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001254
1255#ifdef MEMSET_FREED
1256 memset(&rcsm, 0, sizeof(rcsm));
1257 memset(&rism, 0, sizeof(rism));
1258#endif
1259
1260 return;
1261
1262invalid:
1263 invalidCommandBlock(pRI);
1264 return;
1265}
1266
1267static void
1268dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1269 RIL_IMS_SMS_Message rism;
1270 int32_t countStrings;
1271 status_t status;
1272 size_t datalen;
1273 char **pStrings;
Mark Salyzyndba25612015-04-09 07:18:35 -07001274 RLOGD("dispatchImsGsmSms: retry=%d, messageRef=%d", retry, messageRef);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001275
1276 status = p.readInt32 (&countStrings);
1277
1278 if (status != NO_ERROR) {
1279 goto invalid;
1280 }
1281
1282 memset(&rism, 0, sizeof(rism));
1283 rism.tech = RADIO_TECH_3GPP;
1284 rism.retry = retry;
1285 rism.messageRef = messageRef;
1286
1287 startRequest;
Etan Cohen5d891b72014-02-27 17:25:17 -08001288 appendPrintBuf("%stech=%d, retry=%d, messageRef=%d, ", printBuf,
1289 (int)rism.tech, (int)rism.retry, rism.messageRef);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001290 if (countStrings == 0) {
1291 // just some non-null pointer
1292 pStrings = (char **)alloca(sizeof(char *));
1293 datalen = 0;
1294 } else if (((int)countStrings) == -1) {
1295 pStrings = NULL;
1296 datalen = 0;
1297 } else {
1298 datalen = sizeof(char *) * countStrings;
1299
1300 pStrings = (char **)alloca(datalen);
1301
1302 for (int i = 0 ; i < countStrings ; i++) {
1303 pStrings[i] = strdupReadString(p);
1304 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
1305 }
1306 }
1307 removeLastChar;
1308 closeRequest;
1309 printRequest(pRI->token, pRI->pCI->requestNumber);
1310
1311 rism.message.gsmMessage = pStrings;
Etan Cohend3652192014-06-20 08:28:44 -07001312 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001313 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Etan Cohend3652192014-06-20 08:28:44 -07001314 +datalen, pRI, pRI->socket_id);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001315
1316 if (pStrings != NULL) {
1317 for (int i = 0 ; i < countStrings ; i++) {
1318#ifdef MEMSET_FREED
1319 memsetString (pStrings[i]);
1320#endif
1321 free(pStrings[i]);
1322 }
1323
1324#ifdef MEMSET_FREED
1325 memset(pStrings, 0, datalen);
1326#endif
1327 }
1328
1329#ifdef MEMSET_FREED
1330 memset(&rism, 0, sizeof(rism));
1331#endif
1332 return;
1333invalid:
1334 ALOGE("dispatchImsGsmSms invalid block");
1335 invalidCommandBlock(pRI);
1336 return;
1337}
1338
1339static void
1340dispatchImsSms(Parcel &p, RequestInfo *pRI) {
1341 int32_t t;
1342 status_t status = p.readInt32(&t);
1343 RIL_RadioTechnologyFamily format;
1344 uint8_t retry;
1345 int32_t messageRef;
1346
Mark Salyzyndba25612015-04-09 07:18:35 -07001347 RLOGD("dispatchImsSms");
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001348 if (status != NO_ERROR) {
1349 goto invalid;
1350 }
1351 format = (RIL_RadioTechnologyFamily) t;
1352
1353 // read retry field
1354 status = p.read(&retry,sizeof(retry));
1355 if (status != NO_ERROR) {
1356 goto invalid;
1357 }
1358 // read messageRef field
1359 status = p.read(&messageRef,sizeof(messageRef));
1360 if (status != NO_ERROR) {
1361 goto invalid;
1362 }
1363
1364 if (RADIO_TECH_3GPP == format) {
1365 dispatchImsGsmSms(p, pRI, retry, messageRef);
1366 } else if (RADIO_TECH_3GPP2 == format) {
1367 dispatchImsCdmaSms(p, pRI, retry, messageRef);
1368 } else {
1369 ALOGE("requestImsSendSMS invalid format value =%d", format);
1370 }
1371
1372 return;
1373
1374invalid:
1375 invalidCommandBlock(pRI);
1376 return;
1377}
1378
1379static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001380dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI) {
1381 RIL_CDMA_SMS_Ack rcsa;
1382 int32_t t;
1383 status_t status;
1384 int32_t digitCount;
1385
Mark Salyzyndba25612015-04-09 07:18:35 -07001386 RLOGD("dispatchCdmaSmsAck");
Wink Savillef4c4d362009-04-02 01:37:03 -07001387 memset(&rcsa, 0, sizeof(rcsa));
1388
1389 status = p.readInt32(&t);
1390 rcsa.uErrorClass = (RIL_CDMA_SMS_ErrorClass) t;
1391
1392 status = p.readInt32(&t);
1393 rcsa.uSMSCauseCode = (int) t;
1394
1395 if (status != NO_ERROR) {
1396 goto invalid;
1397 }
1398
1399 startRequest;
Wink Saville1b5fd232009-04-22 14:50:00 -07001400 appendPrintBuf("%suErrorClass=%d, uTLStatus=%d, ",
1401 printBuf, rcsa.uErrorClass, rcsa.uSMSCauseCode);
Wink Savillef4c4d362009-04-02 01:37:03 -07001402 closeRequest;
1403
1404 printRequest(pRI->token, pRI->pCI->requestNumber);
1405
Etan Cohend3652192014-06-20 08:28:44 -07001406 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsa, sizeof(rcsa),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001407
1408#ifdef MEMSET_FREED
1409 memset(&rcsa, 0, sizeof(rcsa));
1410#endif
1411
1412 return;
1413
1414invalid:
1415 invalidCommandBlock(pRI);
1416 return;
1417}
1418
Wink Savillea592eeb2009-05-22 13:26:36 -07001419static void
1420dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1421 int32_t t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001422 status_t status;
Wink Savillea592eeb2009-05-22 13:26:36 -07001423 int32_t num;
Wink Savillef4c4d362009-04-02 01:37:03 -07001424
Wink Savillea592eeb2009-05-22 13:26:36 -07001425 status = p.readInt32(&num);
Wink Savillef4c4d362009-04-02 01:37:03 -07001426 if (status != NO_ERROR) {
1427 goto invalid;
1428 }
1429
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001430 {
1431 RIL_GSM_BroadcastSmsConfigInfo gsmBci[num];
1432 RIL_GSM_BroadcastSmsConfigInfo *gsmBciPtrs[num];
Wink Savillea592eeb2009-05-22 13:26:36 -07001433
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001434 startRequest;
1435 for (int i = 0 ; i < num ; i++ ) {
1436 gsmBciPtrs[i] = &gsmBci[i];
Wink Savillef4c4d362009-04-02 01:37:03 -07001437
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001438 status = p.readInt32(&t);
1439 gsmBci[i].fromServiceId = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001440
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001441 status = p.readInt32(&t);
1442 gsmBci[i].toServiceId = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001443
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001444 status = p.readInt32(&t);
1445 gsmBci[i].fromCodeScheme = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001446
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001447 status = p.readInt32(&t);
1448 gsmBci[i].toCodeScheme = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001449
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001450 status = p.readInt32(&t);
1451 gsmBci[i].selected = (uint8_t) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001452
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001453 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId =%d, \
1454 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]", printBuf, i,
1455 gsmBci[i].fromServiceId, gsmBci[i].toServiceId,
1456 gsmBci[i].fromCodeScheme, gsmBci[i].toCodeScheme,
1457 gsmBci[i].selected);
1458 }
1459 closeRequest;
Wink Savillef4c4d362009-04-02 01:37:03 -07001460
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001461 if (status != NO_ERROR) {
1462 goto invalid;
1463 }
Wink Savillef4c4d362009-04-02 01:37:03 -07001464
Etan Cohend3652192014-06-20 08:28:44 -07001465 CALL_ONREQUEST(pRI->pCI->requestNumber,
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001466 gsmBciPtrs,
1467 num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *),
Etan Cohend3652192014-06-20 08:28:44 -07001468 pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001469
1470#ifdef MEMSET_FREED
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001471 memset(gsmBci, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo));
1472 memset(gsmBciPtrs, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *));
Wink Savillef4c4d362009-04-02 01:37:03 -07001473#endif
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001474 }
Wink Savillef4c4d362009-04-02 01:37:03 -07001475
1476 return;
1477
1478invalid:
1479 invalidCommandBlock(pRI);
1480 return;
Wink Savillea592eeb2009-05-22 13:26:36 -07001481}
Wink Savillef4c4d362009-04-02 01:37:03 -07001482
Wink Savillea592eeb2009-05-22 13:26:36 -07001483static void
1484dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1485 int32_t t;
1486 status_t status;
1487 int32_t num;
1488
1489 status = p.readInt32(&num);
1490 if (status != NO_ERROR) {
1491 goto invalid;
1492 }
1493
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001494 {
1495 RIL_CDMA_BroadcastSmsConfigInfo cdmaBci[num];
1496 RIL_CDMA_BroadcastSmsConfigInfo *cdmaBciPtrs[num];
Wink Savillea592eeb2009-05-22 13:26:36 -07001497
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001498 startRequest;
1499 for (int i = 0 ; i < num ; i++ ) {
1500 cdmaBciPtrs[i] = &cdmaBci[i];
Wink Savillea592eeb2009-05-22 13:26:36 -07001501
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001502 status = p.readInt32(&t);
1503 cdmaBci[i].service_category = (int) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001504
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001505 status = p.readInt32(&t);
1506 cdmaBci[i].language = (int) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001507
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001508 status = p.readInt32(&t);
1509 cdmaBci[i].selected = (uint8_t) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001510
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001511 appendPrintBuf("%s [%d: service_category=%d, language =%d, \
1512 entries.bSelected =%d]", printBuf, i, cdmaBci[i].service_category,
1513 cdmaBci[i].language, cdmaBci[i].selected);
1514 }
1515 closeRequest;
Wink Savillea592eeb2009-05-22 13:26:36 -07001516
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001517 if (status != NO_ERROR) {
1518 goto invalid;
1519 }
Wink Savillea592eeb2009-05-22 13:26:36 -07001520
Etan Cohend3652192014-06-20 08:28:44 -07001521 CALL_ONREQUEST(pRI->pCI->requestNumber,
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001522 cdmaBciPtrs,
1523 num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *),
Etan Cohend3652192014-06-20 08:28:44 -07001524 pRI, pRI->socket_id);
Wink Savillea592eeb2009-05-22 13:26:36 -07001525
1526#ifdef MEMSET_FREED
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001527 memset(cdmaBci, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo));
1528 memset(cdmaBciPtrs, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *));
Wink Savillea592eeb2009-05-22 13:26:36 -07001529#endif
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001530 }
Wink Savillea592eeb2009-05-22 13:26:36 -07001531
1532 return;
1533
1534invalid:
1535 invalidCommandBlock(pRI);
1536 return;
Wink Savillef4c4d362009-04-02 01:37:03 -07001537}
1538
1539static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI) {
1540 RIL_CDMA_SMS_WriteArgs rcsw;
1541 int32_t t;
1542 uint32_t ut;
1543 uint8_t uct;
1544 status_t status;
1545 int32_t digitCount;
1546
1547 memset(&rcsw, 0, sizeof(rcsw));
1548
1549 status = p.readInt32(&t);
1550 rcsw.status = t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001551
Wink Savillef4c4d362009-04-02 01:37:03 -07001552 status = p.readInt32(&t);
1553 rcsw.message.uTeleserviceID = (int) t;
1554
1555 status = p.read(&uct,sizeof(uct));
1556 rcsw.message.bIsServicePresent = (uint8_t) uct;
1557
1558 status = p.readInt32(&t);
1559 rcsw.message.uServicecategory = (int) t;
1560
1561 status = p.readInt32(&t);
1562 rcsw.message.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1563
1564 status = p.readInt32(&t);
1565 rcsw.message.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1566
1567 status = p.readInt32(&t);
1568 rcsw.message.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1569
1570 status = p.readInt32(&t);
1571 rcsw.message.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1572
1573 status = p.read(&uct,sizeof(uct));
1574 rcsw.message.sAddress.number_of_digits = (uint8_t) uct;
1575
1576 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_ADDRESS_MAX; digitCount ++) {
1577 status = p.read(&uct,sizeof(uct));
1578 rcsw.message.sAddress.digits[digitCount] = (uint8_t) uct;
1579 }
1580
Wink Savillea592eeb2009-05-22 13:26:36 -07001581 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001582 rcsw.message.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1583
Wink Savillea592eeb2009-05-22 13:26:36 -07001584 status = p.read(&uct,sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001585 rcsw.message.sSubAddress.odd = (uint8_t) uct;
1586
1587 status = p.read(&uct,sizeof(uct));
1588 rcsw.message.sSubAddress.number_of_digits = (uint8_t) uct;
1589
1590 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_SUBADDRESS_MAX; digitCount ++) {
Wink Savillea592eeb2009-05-22 13:26:36 -07001591 status = p.read(&uct,sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001592 rcsw.message.sSubAddress.digits[digitCount] = (uint8_t) uct;
1593 }
1594
Wink Savillea592eeb2009-05-22 13:26:36 -07001595 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001596 rcsw.message.uBearerDataLen = (int) t;
1597
1598 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_BEARER_DATA_MAX; digitCount ++) {
Wink Savillea592eeb2009-05-22 13:26:36 -07001599 status = p.read(&uct, sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001600 rcsw.message.aBearerData[digitCount] = (uint8_t) uct;
1601 }
1602
1603 if (status != NO_ERROR) {
1604 goto invalid;
1605 }
1606
1607 startRequest;
Wink Saville1b5fd232009-04-22 14:50:00 -07001608 appendPrintBuf("%sstatus=%d, message.uTeleserviceID=%d, message.bIsServicePresent=%d, \
1609 message.uServicecategory=%d, message.sAddress.digit_mode=%d, \
1610 message.sAddress.number_mode=%d, \
1611 message.sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07001612 printBuf, rcsw.status, rcsw.message.uTeleserviceID, rcsw.message.bIsServicePresent,
Wink Saville1b5fd232009-04-22 14:50:00 -07001613 rcsw.message.uServicecategory, rcsw.message.sAddress.digit_mode,
1614 rcsw.message.sAddress.number_mode,
1615 rcsw.message.sAddress.number_type);
Wink Savillef4c4d362009-04-02 01:37:03 -07001616 closeRequest;
1617
1618 printRequest(pRI->token, pRI->pCI->requestNumber);
1619
Etan Cohend3652192014-06-20 08:28:44 -07001620 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsw, sizeof(rcsw),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001621
1622#ifdef MEMSET_FREED
1623 memset(&rcsw, 0, sizeof(rcsw));
1624#endif
1625
1626 return;
1627
1628invalid:
1629 invalidCommandBlock(pRI);
1630 return;
1631
1632}
1633
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -07001634// For backwards compatibility in RIL_REQUEST_SETUP_DATA_CALL.
1635// Version 4 of the RIL interface adds a new PDP type parameter to support
1636// IPv6 and dual-stack PDP contexts. When dealing with a previous version of
1637// RIL, remove the parameter from the request.
1638static void dispatchDataCall(Parcel& p, RequestInfo *pRI) {
1639 // In RIL v3, REQUEST_SETUP_DATA_CALL takes 6 parameters.
1640 const int numParamsRilV3 = 6;
1641
1642 // The first bytes of the RIL parcel contain the request number and the
1643 // serial number - see processCommandBuffer(). Copy them over too.
1644 int pos = p.dataPosition();
1645
1646 int numParams = p.readInt32();
1647 if (s_callbacks.version < 4 && numParams > numParamsRilV3) {
1648 Parcel p2;
1649 p2.appendFrom(&p, 0, pos);
1650 p2.writeInt32(numParamsRilV3);
1651 for(int i = 0; i < numParamsRilV3; i++) {
1652 p2.writeString16(p.readString16());
1653 }
1654 p2.setDataPosition(pos);
1655 dispatchStrings(p2, pRI);
1656 } else {
Lorenzo Colitti57ce1f22010-09-13 12:23:50 -07001657 p.setDataPosition(pos);
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -07001658 dispatchStrings(p, pRI);
1659 }
1660}
1661
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001662// For backwards compatibility with RILs that dont support RIL_REQUEST_VOICE_RADIO_TECH.
1663// When all RILs handle this request, this function can be removed and
1664// the request can be sent directly to the RIL using dispatchVoid.
1665static void dispatchVoiceRadioTech(Parcel& p, RequestInfo *pRI) {
Etan Cohend3652192014-06-20 08:28:44 -07001666 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001667
1668 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1669 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1670 }
1671
1672 // RILs that support RADIO_STATE_ON should support this request.
1673 if (RADIO_STATE_ON == state) {
1674 dispatchVoid(p, pRI);
1675 return;
1676 }
1677
1678 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1679 // will not support this new request either and decode Voice Radio Technology
1680 // from Radio State
1681 voiceRadioTech = decodeVoiceRadioTechnology(state);
1682
1683 if (voiceRadioTech < 0)
1684 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1685 else
1686 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &voiceRadioTech, sizeof(int));
1687}
1688
1689// For backwards compatibility in RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE:.
1690// When all RILs handle this request, this function can be removed and
1691// the request can be sent directly to the RIL using dispatchVoid.
1692static void dispatchCdmaSubscriptionSource(Parcel& p, RequestInfo *pRI) {
Etan Cohend3652192014-06-20 08:28:44 -07001693 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001694
1695 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1696 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1697 }
1698
1699 // RILs that support RADIO_STATE_ON should support this request.
1700 if (RADIO_STATE_ON == state) {
1701 dispatchVoid(p, pRI);
1702 return;
1703 }
1704
1705 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1706 // will not support this new request either and decode CDMA Subscription Source
1707 // from Radio State
1708 cdmaSubscriptionSource = decodeCdmaSubscriptionSource(state);
1709
1710 if (cdmaSubscriptionSource < 0)
1711 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1712 else
1713 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &cdmaSubscriptionSource, sizeof(int));
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);
1939 if (status != NO_ERROR) {
1940 goto invalid;
1941 }
1942
1943 {
1944 RIL_DataProfileInfo dataProfiles[num];
1945 RIL_DataProfileInfo *dataProfilePtrs[num];
1946
1947 startRequest;
1948 for (int i = 0 ; i < num ; i++ ) {
1949 dataProfilePtrs[i] = &dataProfiles[i];
1950
1951 status = p.readInt32(&t);
1952 dataProfiles[i].profileId = (int) t;
1953
1954 dataProfiles[i].apn = strdupReadString(p);
1955 dataProfiles[i].protocol = strdupReadString(p);
1956 status = p.readInt32(&t);
1957 dataProfiles[i].authType = (int) t;
1958
1959 dataProfiles[i].user = strdupReadString(p);
1960 dataProfiles[i].password = strdupReadString(p);
1961
1962 status = p.readInt32(&t);
1963 dataProfiles[i].type = (int) t;
1964
1965 status = p.readInt32(&t);
1966 dataProfiles[i].maxConnsTime = (int) t;
1967 status = p.readInt32(&t);
1968 dataProfiles[i].maxConns = (int) t;
1969 status = p.readInt32(&t);
1970 dataProfiles[i].waitTime = (int) t;
1971
1972 status = p.readInt32(&t);
1973 dataProfiles[i].enabled = (int) t;
1974
1975 appendPrintBuf("%s [%d: profileId=%d, apn =%s, protocol =%s, authType =%d, \
1976 user =%s, password =%s, type =%d, maxConnsTime =%d, maxConns =%d, \
1977 waitTime =%d, enabled =%d]", printBuf, i, dataProfiles[i].profileId,
1978 dataProfiles[i].apn, dataProfiles[i].protocol, dataProfiles[i].authType,
1979 dataProfiles[i].user, dataProfiles[i].password, dataProfiles[i].type,
1980 dataProfiles[i].maxConnsTime, dataProfiles[i].maxConns,
1981 dataProfiles[i].waitTime, dataProfiles[i].enabled);
1982 }
1983 closeRequest;
1984 printRequest(pRI->token, pRI->pCI->requestNumber);
1985
1986 if (status != NO_ERROR) {
1987 goto invalid;
1988 }
1989 CALL_ONREQUEST(pRI->pCI->requestNumber,
1990 dataProfilePtrs,
1991 num * sizeof(RIL_DataProfileInfo *),
1992 pRI, pRI->socket_id);
1993
1994#ifdef MEMSET_FREED
1995 memset(dataProfiles, 0, num * sizeof(RIL_DataProfileInfo));
1996 memset(dataProfilePtrs, 0, num * sizeof(RIL_DataProfileInfo *));
1997#endif
1998 }
1999
2000 return;
2001
2002invalid:
2003 invalidCommandBlock(pRI);
2004 return;
2005}
2006
Wink Saville8b4e4f72014-10-17 15:01:45 -07002007static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI){
2008 RIL_RadioCapability rc;
2009 int32_t t;
2010 status_t status;
2011
2012 memset (&rc, 0, sizeof(RIL_RadioCapability));
2013
2014 status = p.readInt32(&t);
2015 rc.version = (int)t;
2016 if (status != NO_ERROR) {
2017 goto invalid;
2018 }
2019
2020 status = p.readInt32(&t);
2021 rc.session= (int)t;
2022 if (status != NO_ERROR) {
2023 goto invalid;
2024 }
2025
2026 status = p.readInt32(&t);
2027 rc.phase= (int)t;
2028 if (status != NO_ERROR) {
2029 goto invalid;
2030 }
2031
2032 status = p.readInt32(&t);
2033 rc.rat = (int)t;
2034 if (status != NO_ERROR) {
2035 goto invalid;
2036 }
2037
2038 status = readStringFromParcelInplace(p, rc.logicalModemUuid, sizeof(rc.logicalModemUuid));
2039 if (status != NO_ERROR) {
2040 goto invalid;
2041 }
2042
2043 status = p.readInt32(&t);
2044 rc.status = (int)t;
2045
2046 if (status != NO_ERROR) {
2047 goto invalid;
2048 }
2049
2050 startRequest;
2051 appendPrintBuf("%s [version:%d, session:%d, phase:%d, rat:%d, \
Chih-Wei Huang8593f262015-10-02 15:09:52 +08002052 logicalModemUuid:%s, status:%d", printBuf, rc.version, rc.session,
Legler Wu8caf06f2014-10-29 14:02:14 +08002053 rc.phase, rc.rat, rc.logicalModemUuid, rc.session);
Wink Saville8b4e4f72014-10-17 15:01:45 -07002054
2055 closeRequest;
2056 printRequest(pRI->token, pRI->pCI->requestNumber);
2057
2058 CALL_ONREQUEST(pRI->pCI->requestNumber,
2059 &rc,
2060 sizeof(RIL_RadioCapability),
2061 pRI, pRI->socket_id);
2062 return;
2063invalid:
2064 invalidCommandBlock(pRI);
2065 return;
2066}
2067
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002068static int
Wink Savillef4c4d362009-04-02 01:37:03 -07002069blockingWrite(int fd, const void *buffer, size_t len) {
Wink Saville7f856802009-06-09 10:23:37 -07002070 size_t writeOffset = 0;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002071 const uint8_t *toWrite;
2072
2073 toWrite = (const uint8_t *)buffer;
2074
2075 while (writeOffset < len) {
2076 ssize_t written;
2077 do {
2078 written = write (fd, toWrite + writeOffset,
2079 len - writeOffset);
Banavathu, Srinivas Naik38884902011-07-05 20:04:25 +05302080 } while (written < 0 && ((errno == EINTR) || (errno == EAGAIN)));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002081
2082 if (written >= 0) {
2083 writeOffset += written;
2084 } else { // written < 0
Wink Saville8eb2a122012-11-19 16:05:13 -08002085 RLOGE ("RIL Response: unexpected error on write errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002086 close(fd);
2087 return -1;
2088 }
2089 }
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07002090#if VDBG
Dheeraj Shetty27976c42014-07-02 21:27:57 +02002091 RLOGE("RIL Response bytes written:%d", writeOffset);
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07002092#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002093 return 0;
2094}
2095
2096static int
Etan Cohend3652192014-06-20 08:28:44 -07002097sendResponseRaw (const void *data, size_t dataSize, RIL_SOCKET_ID socket_id) {
2098 int fd = s_ril_param_socket.fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002099 int ret;
2100 uint32_t header;
Etan Cohend3652192014-06-20 08:28:44 -07002101 pthread_mutex_t * writeMutexHook = &s_writeMutex;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002102
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07002103#if VDBG
Etan Cohend3652192014-06-20 08:28:44 -07002104 RLOGE("Send Response to %s", rilSocketIdToString(socket_id));
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07002105#endif
Etan Cohend3652192014-06-20 08:28:44 -07002106
2107#if (SIM_COUNT >= 2)
2108 if (socket_id == RIL_SOCKET_2) {
2109 fd = s_ril_param_socket2.fdCommand;
2110 writeMutexHook = &s_writeMutex_socket2;
2111 }
2112#if (SIM_COUNT >= 3)
2113 else if (socket_id == RIL_SOCKET_3) {
2114 fd = s_ril_param_socket3.fdCommand;
2115 writeMutexHook = &s_writeMutex_socket3;
2116 }
2117#endif
2118#if (SIM_COUNT >= 4)
2119 else if (socket_id == RIL_SOCKET_4) {
2120 fd = s_ril_param_socket4.fdCommand;
2121 writeMutexHook = &s_writeMutex_socket4;
2122 }
2123#endif
2124#endif
2125 if (fd < 0) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002126 return -1;
2127 }
2128
2129 if (dataSize > MAX_COMMAND_BYTES) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002130 RLOGE("RIL: packet larger than %u (%u)",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002131 MAX_COMMAND_BYTES, (unsigned int )dataSize);
2132
2133 return -1;
2134 }
Wink Saville7f856802009-06-09 10:23:37 -07002135
Etan Cohend3652192014-06-20 08:28:44 -07002136 pthread_mutex_lock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002137
2138 header = htonl(dataSize);
2139
2140 ret = blockingWrite(fd, (void *)&header, sizeof(header));
2141
2142 if (ret < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002143 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002144 return ret;
2145 }
2146
Kennyee1fadc2009-08-13 00:45:53 +08002147 ret = blockingWrite(fd, data, dataSize);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002148
2149 if (ret < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002150 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002151 return ret;
2152 }
2153
Etan Cohend3652192014-06-20 08:28:44 -07002154 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002155
2156 return 0;
2157}
2158
2159static int
Etan Cohend3652192014-06-20 08:28:44 -07002160sendResponse (Parcel &p, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002161 printResponse;
Etan Cohend3652192014-06-20 08:28:44 -07002162 return sendResponseRaw(p.data(), p.dataSize(), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002163}
2164
Mohamad Ayyash74f7e662014-04-18 11:43:28 -07002165/** response is an int* pointing to an array of ints */
Wink Saville7f856802009-06-09 10:23:37 -07002166
2167static int
Wink Savillef4c4d362009-04-02 01:37:03 -07002168responseInts(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002169 int numInts;
2170
2171 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002172 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002173 return RIL_ERRNO_INVALID_RESPONSE;
2174 }
2175 if (responselen % sizeof(int) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002176 RLOGE("responseInts: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002177 (int)responselen, (int)sizeof(int));
2178 return RIL_ERRNO_INVALID_RESPONSE;
2179 }
2180
2181 int *p_int = (int *) response;
2182
Mohamad Ayyash74f7e662014-04-18 11:43:28 -07002183 numInts = responselen / sizeof(int);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002184 p.writeInt32 (numInts);
2185
2186 /* each int*/
2187 startResponse;
2188 for (int i = 0 ; i < numInts ; i++) {
2189 appendPrintBuf("%s%d,", printBuf, p_int[i]);
2190 p.writeInt32(p_int[i]);
2191 }
2192 removeLastChar;
2193 closeResponse;
2194
2195 return 0;
2196}
2197
Chao Liu548a81e2015-05-14 16:13:46 -07002198// Response is an int or RIL_LastCallFailCauseInfo.
2199// Currently, only Shamu plans to use RIL_LastCallFailCauseInfo.
2200// TODO(yjl): Let all implementations use RIL_LastCallFailCauseInfo.
2201static int responseFailCause(Parcel &p, void *response, size_t responselen) {
2202 if (response == NULL && responselen != 0) {
2203 RLOGE("invalid response: NULL");
2204 return RIL_ERRNO_INVALID_RESPONSE;
2205 }
2206
2207 if (responselen == sizeof(int)) {
Sungmin Choia408c252015-07-01 16:22:46 +09002208 startResponse;
2209 int *p_int = (int *) response;
2210 appendPrintBuf("%s%d,", printBuf, p_int[0]);
2211 p.writeInt32(p_int[0]);
2212 removeLastChar;
2213 closeResponse;
Chao Liu548a81e2015-05-14 16:13:46 -07002214 } else if (responselen == sizeof(RIL_LastCallFailCauseInfo)) {
2215 startResponse;
2216 RIL_LastCallFailCauseInfo *p_fail_cause_info = (RIL_LastCallFailCauseInfo *) response;
2217 appendPrintBuf("%s[cause_code=%d,vendor_cause=%s]", printBuf, p_fail_cause_info->cause_code,
2218 p_fail_cause_info->vendor_cause);
2219 p.writeInt32(p_fail_cause_info->cause_code);
2220 writeStringToParcel(p, p_fail_cause_info->vendor_cause);
2221 removeLastChar;
2222 closeResponse;
2223 } else {
2224 RLOGE("responseFailCause: invalid response length %d expected an int or "
2225 "RIL_LastCallFailCauseInfo", (int)responselen);
2226 return RIL_ERRNO_INVALID_RESPONSE;
2227 }
2228
2229 return 0;
2230}
2231
Wink Saville43808972011-01-13 17:39:51 -08002232/** response is a char **, pointing to an array of char *'s
2233 The parcel will begin with the version */
2234static int responseStringsWithVersion(int version, Parcel &p, void *response, size_t responselen) {
2235 p.writeInt32(version);
2236 return responseStrings(p, response, responselen);
2237}
2238
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002239/** response is a char **, pointing to an array of char *'s */
Wink Savillef4c4d362009-04-02 01:37:03 -07002240static int responseStrings(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002241 int numStrings;
Wink Saville7f856802009-06-09 10:23:37 -07002242
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002243 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002244 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002245 return RIL_ERRNO_INVALID_RESPONSE;
2246 }
2247 if (responselen % sizeof(char *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002248 RLOGE("responseStrings: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002249 (int)responselen, (int)sizeof(char *));
2250 return RIL_ERRNO_INVALID_RESPONSE;
2251 }
2252
2253 if (response == NULL) {
2254 p.writeInt32 (0);
2255 } else {
2256 char **p_cur = (char **) response;
2257
2258 numStrings = responselen / sizeof(char *);
2259 p.writeInt32 (numStrings);
2260
2261 /* each string*/
2262 startResponse;
2263 for (int i = 0 ; i < numStrings ; i++) {
2264 appendPrintBuf("%s%s,", printBuf, (char*)p_cur[i]);
2265 writeStringToParcel (p, p_cur[i]);
2266 }
2267 removeLastChar;
2268 closeResponse;
2269 }
2270 return 0;
2271}
2272
2273
2274/**
Wink Saville7f856802009-06-09 10:23:37 -07002275 * NULL strings are accepted
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002276 * FIXME currently ignores responselen
2277 */
Wink Savillef4c4d362009-04-02 01:37:03 -07002278static int responseString(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002279 /* one string only */
2280 startResponse;
2281 appendPrintBuf("%s%s", printBuf, (char*)response);
2282 closeResponse;
2283
2284 writeStringToParcel(p, (const char *)response);
2285
2286 return 0;
2287}
2288
Wink Savillef4c4d362009-04-02 01:37:03 -07002289static int responseVoid(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002290 startResponse;
2291 removeLastChar;
2292 return 0;
2293}
2294
Wink Savillef4c4d362009-04-02 01:37:03 -07002295static int responseCallList(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002296 int num;
2297
2298 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002299 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002300 return RIL_ERRNO_INVALID_RESPONSE;
2301 }
2302
2303 if (responselen % sizeof (RIL_Call *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002304 RLOGE("responseCallList: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002305 (int)responselen, (int)sizeof (RIL_Call *));
2306 return RIL_ERRNO_INVALID_RESPONSE;
2307 }
2308
2309 startResponse;
2310 /* number of call info's */
2311 num = responselen / sizeof(RIL_Call *);
2312 p.writeInt32(num);
2313
2314 for (int i = 0 ; i < num ; i++) {
2315 RIL_Call *p_cur = ((RIL_Call **) response)[i];
2316 /* each call info */
2317 p.writeInt32(p_cur->state);
2318 p.writeInt32(p_cur->index);
2319 p.writeInt32(p_cur->toa);
2320 p.writeInt32(p_cur->isMpty);
2321 p.writeInt32(p_cur->isMT);
2322 p.writeInt32(p_cur->als);
2323 p.writeInt32(p_cur->isVoice);
Wink Saville1b5fd232009-04-22 14:50:00 -07002324 p.writeInt32(p_cur->isVoicePrivacy);
2325 writeStringToParcel(p, p_cur->number);
John Wangff368742009-03-24 17:56:29 -07002326 p.writeInt32(p_cur->numberPresentation);
Wink Saville1b5fd232009-04-22 14:50:00 -07002327 writeStringToParcel(p, p_cur->name);
2328 p.writeInt32(p_cur->namePresentation);
Wink Saville3a4840b2010-04-07 13:29:58 -07002329 // Remove when partners upgrade to version 3
Wink Saville74fa3882009-12-22 15:35:41 -08002330 if ((s_callbacks.version < 3) || (p_cur->uusInfo == NULL || p_cur->uusInfo->uusData == NULL)) {
2331 p.writeInt32(0); /* UUS Information is absent */
2332 } else {
2333 RIL_UUS_Info *uusInfo = p_cur->uusInfo;
2334 p.writeInt32(1); /* UUS Information is present */
2335 p.writeInt32(uusInfo->uusType);
2336 p.writeInt32(uusInfo->uusDcs);
2337 p.writeInt32(uusInfo->uusLength);
2338 p.write(uusInfo->uusData, uusInfo->uusLength);
2339 }
Wink Saville3d54e742009-05-18 18:00:44 -07002340 appendPrintBuf("%s[id=%d,%s,toa=%d,",
John Wangff368742009-03-24 17:56:29 -07002341 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002342 p_cur->index,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002343 callStateToString(p_cur->state),
Wink Saville3d54e742009-05-18 18:00:44 -07002344 p_cur->toa);
2345 appendPrintBuf("%s%s,%s,als=%d,%s,%s,",
2346 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002347 (p_cur->isMpty)?"conf":"norm",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002348 (p_cur->isMT)?"mt":"mo",
2349 p_cur->als,
2350 (p_cur->isVoice)?"voc":"nonvoc",
Wink Saville3d54e742009-05-18 18:00:44 -07002351 (p_cur->isVoicePrivacy)?"evp":"noevp");
2352 appendPrintBuf("%s%s,cli=%d,name='%s',%d]",
2353 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002354 p_cur->number,
2355 p_cur->numberPresentation,
2356 p_cur->name,
2357 p_cur->namePresentation);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002358 }
2359 removeLastChar;
2360 closeResponse;
2361
2362 return 0;
2363}
2364
Wink Savillef4c4d362009-04-02 01:37:03 -07002365static int responseSMS(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002366 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002367 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002368 return RIL_ERRNO_INVALID_RESPONSE;
2369 }
2370
2371 if (responselen != sizeof (RIL_SMS_Response) ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002372 RLOGE("invalid response length %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002373 (int)responselen, (int)sizeof (RIL_SMS_Response));
2374 return RIL_ERRNO_INVALID_RESPONSE;
2375 }
2376
2377 RIL_SMS_Response *p_cur = (RIL_SMS_Response *) response;
2378
2379 p.writeInt32(p_cur->messageRef);
2380 writeStringToParcel(p, p_cur->ackPDU);
Jaikumar Ganesh920c78f2009-06-04 10:53:15 -07002381 p.writeInt32(p_cur->errorCode);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002382
2383 startResponse;
Jaikumar Ganesh920c78f2009-06-04 10:53:15 -07002384 appendPrintBuf("%s%d,%s,%d", printBuf, p_cur->messageRef,
2385 (char*)p_cur->ackPDU, p_cur->errorCode);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002386 closeResponse;
2387
2388 return 0;
2389}
2390
Wink Savillec0114b32011-02-18 10:14:07 -08002391static int responseDataCallListV4(Parcel &p, void *response, size_t responselen)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002392{
2393 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002394 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002395 return RIL_ERRNO_INVALID_RESPONSE;
2396 }
2397
Wink Savillec0114b32011-02-18 10:14:07 -08002398 if (responselen % sizeof(RIL_Data_Call_Response_v4) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002399 RLOGE("responseDataCallListV4: invalid response length %d expected multiple of %d",
Wink Savillec0114b32011-02-18 10:14:07 -08002400 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v4));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002401 return RIL_ERRNO_INVALID_RESPONSE;
2402 }
2403
Amit Mahajan52500162014-07-29 17:36:48 -07002404 // Write version
2405 p.writeInt32(4);
2406
Wink Savillec0114b32011-02-18 10:14:07 -08002407 int num = responselen / sizeof(RIL_Data_Call_Response_v4);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002408 p.writeInt32(num);
2409
Wink Savillec0114b32011-02-18 10:14:07 -08002410 RIL_Data_Call_Response_v4 *p_cur = (RIL_Data_Call_Response_v4 *) response;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002411 startResponse;
2412 int i;
2413 for (i = 0; i < num; i++) {
2414 p.writeInt32(p_cur[i].cid);
2415 p.writeInt32(p_cur[i].active);
2416 writeStringToParcel(p, p_cur[i].type);
Wink Savillec0114b32011-02-18 10:14:07 -08002417 // apn is not used, so don't send.
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002418 writeStringToParcel(p, p_cur[i].address);
Wink Savillec0114b32011-02-18 10:14:07 -08002419 appendPrintBuf("%s[cid=%d,%s,%s,%s],", printBuf,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002420 p_cur[i].cid,
2421 (p_cur[i].active==0)?"down":"up",
2422 (char*)p_cur[i].type,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002423 (char*)p_cur[i].address);
2424 }
2425 removeLastChar;
2426 closeResponse;
2427
2428 return 0;
2429}
2430
Etan Cohend3652192014-06-20 08:28:44 -07002431static int responseDataCallListV6(Parcel &p, void *response, size_t responselen)
2432{
Amit Mahajan52500162014-07-29 17:36:48 -07002433 if (response == NULL && responselen != 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002434 RLOGE("invalid response: NULL");
2435 return RIL_ERRNO_INVALID_RESPONSE;
2436 }
2437
2438 if (responselen % sizeof(RIL_Data_Call_Response_v6) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002439 RLOGE("responseDataCallListV6: invalid response length %d expected multiple of %d",
Etan Cohend3652192014-06-20 08:28:44 -07002440 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v6));
2441 return RIL_ERRNO_INVALID_RESPONSE;
2442 }
2443
Amit Mahajan52500162014-07-29 17:36:48 -07002444 // Write version
2445 p.writeInt32(6);
2446
Etan Cohend3652192014-06-20 08:28:44 -07002447 int num = responselen / sizeof(RIL_Data_Call_Response_v6);
2448 p.writeInt32(num);
2449
2450 RIL_Data_Call_Response_v6 *p_cur = (RIL_Data_Call_Response_v6 *) response;
2451 startResponse;
2452 int i;
2453 for (i = 0; i < num; i++) {
2454 p.writeInt32((int)p_cur[i].status);
2455 p.writeInt32(p_cur[i].suggestedRetryTime);
2456 p.writeInt32(p_cur[i].cid);
2457 p.writeInt32(p_cur[i].active);
2458 writeStringToParcel(p, p_cur[i].type);
2459 writeStringToParcel(p, p_cur[i].ifname);
2460 writeStringToParcel(p, p_cur[i].addresses);
2461 writeStringToParcel(p, p_cur[i].dnses);
2462 writeStringToParcel(p, p_cur[i].gateways);
2463 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s],", printBuf,
2464 p_cur[i].status,
2465 p_cur[i].suggestedRetryTime,
2466 p_cur[i].cid,
2467 (p_cur[i].active==0)?"down":"up",
2468 (char*)p_cur[i].type,
2469 (char*)p_cur[i].ifname,
2470 (char*)p_cur[i].addresses,
2471 (char*)p_cur[i].dnses,
2472 (char*)p_cur[i].gateways);
2473 }
2474 removeLastChar;
2475 closeResponse;
2476
2477 return 0;
2478}
2479
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002480static int responseDataCallListV9(Parcel &p, void *response, size_t responselen)
2481{
2482 if (response == NULL && responselen != 0) {
2483 RLOGE("invalid response: NULL");
2484 return RIL_ERRNO_INVALID_RESPONSE;
2485 }
2486
2487 if (responselen % sizeof(RIL_Data_Call_Response_v9) != 0) {
2488 RLOGE("responseDataCallListV9: invalid response length %d expected multiple of %d",
2489 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v9));
2490 return RIL_ERRNO_INVALID_RESPONSE;
2491 }
2492
2493 // Write version
2494 p.writeInt32(10);
2495
2496 int num = responselen / sizeof(RIL_Data_Call_Response_v9);
2497 p.writeInt32(num);
2498
2499 RIL_Data_Call_Response_v9 *p_cur = (RIL_Data_Call_Response_v9 *) response;
2500 startResponse;
2501 int i;
2502 for (i = 0; i < num; i++) {
2503 p.writeInt32((int)p_cur[i].status);
2504 p.writeInt32(p_cur[i].suggestedRetryTime);
2505 p.writeInt32(p_cur[i].cid);
2506 p.writeInt32(p_cur[i].active);
2507 writeStringToParcel(p, p_cur[i].type);
2508 writeStringToParcel(p, p_cur[i].ifname);
2509 writeStringToParcel(p, p_cur[i].addresses);
2510 writeStringToParcel(p, p_cur[i].dnses);
2511 writeStringToParcel(p, p_cur[i].gateways);
2512 writeStringToParcel(p, p_cur[i].pcscf);
2513 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s],", printBuf,
2514 p_cur[i].status,
2515 p_cur[i].suggestedRetryTime,
2516 p_cur[i].cid,
2517 (p_cur[i].active==0)?"down":"up",
2518 (char*)p_cur[i].type,
2519 (char*)p_cur[i].ifname,
2520 (char*)p_cur[i].addresses,
2521 (char*)p_cur[i].dnses,
2522 (char*)p_cur[i].gateways,
2523 (char*)p_cur[i].pcscf);
2524 }
2525 removeLastChar;
2526 closeResponse;
2527
2528 return 0;
2529}
2530
Sanket Padawe88cf6a52016-01-11 12:45:43 -08002531static int responseDataCallListV11(Parcel &p, void *response, size_t responselen) {
2532 if (response == NULL && responselen != 0) {
2533 RLOGE("invalid response: NULL");
2534 return RIL_ERRNO_INVALID_RESPONSE;
2535 }
2536
2537 if (responselen % sizeof(RIL_Data_Call_Response_v11) != 0) {
2538 RLOGE("invalid response length %d expected multiple of %d",
2539 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v11));
2540 return RIL_ERRNO_INVALID_RESPONSE;
2541 }
2542
2543 // Write version
2544 p.writeInt32(11);
2545
2546 int num = responselen / sizeof(RIL_Data_Call_Response_v11);
2547 p.writeInt32(num);
2548
2549 RIL_Data_Call_Response_v11 *p_cur = (RIL_Data_Call_Response_v11 *) response;
2550 startResponse;
2551 int i;
2552 for (i = 0; i < num; i++) {
2553 p.writeInt32((int)p_cur[i].status);
2554 p.writeInt32(p_cur[i].suggestedRetryTime);
2555 p.writeInt32(p_cur[i].cid);
2556 p.writeInt32(p_cur[i].active);
2557 writeStringToParcel(p, p_cur[i].type);
2558 writeStringToParcel(p, p_cur[i].ifname);
2559 writeStringToParcel(p, p_cur[i].addresses);
2560 writeStringToParcel(p, p_cur[i].dnses);
2561 writeStringToParcel(p, p_cur[i].gateways);
2562 writeStringToParcel(p, p_cur[i].pcscf);
2563 p.writeInt32(p_cur[i].mtu);
2564 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s,mtu=%d],", printBuf,
2565 p_cur[i].status,
2566 p_cur[i].suggestedRetryTime,
2567 p_cur[i].cid,
2568 (p_cur[i].active==0)?"down":"up",
2569 (char*)p_cur[i].type,
2570 (char*)p_cur[i].ifname,
2571 (char*)p_cur[i].addresses,
2572 (char*)p_cur[i].dnses,
2573 (char*)p_cur[i].gateways,
2574 (char*)p_cur[i].pcscf,
2575 p_cur[i].mtu);
2576 }
2577 removeLastChar;
2578 closeResponse;
2579
2580 return 0;
2581}
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002582
Wink Saville43808972011-01-13 17:39:51 -08002583static int responseDataCallList(Parcel &p, void *response, size_t responselen)
2584{
Sanket Padawe88cf6a52016-01-11 12:45:43 -08002585 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
2586 if (s_callbacks.version < 5) {
2587 RLOGD("responseDataCallList: v4");
2588 return responseDataCallListV4(p, response, responselen);
2589 } else if (responselen % sizeof(RIL_Data_Call_Response_v6) == 0) {
2590 return responseDataCallListV6(p, response, responselen);
2591 } else if (responselen % sizeof(RIL_Data_Call_Response_v9) == 0) {
2592 return responseDataCallListV9(p, response, responselen);
2593 } else {
2594 return responseDataCallListV11(p, response, responselen);
Wink Saville43808972011-01-13 17:39:51 -08002595 }
Sanket Padawef53c5fa2016-01-27 10:00:38 -08002596 } else { // RIL version >= 13
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002597 if (responselen % sizeof(RIL_Data_Call_Response_v11) != 0) {
Sanket Padawe88cf6a52016-01-11 12:45:43 -08002598 RLOGE("Data structure expected is RIL_Data_Call_Response_v11");
2599 if (!isDebuggable()) {
2600 return RIL_ERRNO_INVALID_RESPONSE;
2601 } else {
2602 assert(0);
2603 }
Wink Saville43808972011-01-13 17:39:51 -08002604 }
Sanket Padawe88cf6a52016-01-11 12:45:43 -08002605 return responseDataCallListV11(p, response, responselen);
Wink Saville43808972011-01-13 17:39:51 -08002606 }
Wink Saville43808972011-01-13 17:39:51 -08002607}
2608
2609static int responseSetupDataCall(Parcel &p, void *response, size_t responselen)
2610{
2611 if (s_callbacks.version < 5) {
2612 return responseStringsWithVersion(s_callbacks.version, p, response, responselen);
2613 } else {
2614 return responseDataCallList(p, response, responselen);
2615 }
2616}
2617
Wink Savillef4c4d362009-04-02 01:37:03 -07002618static int responseRaw(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002619 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002620 RLOGE("invalid response: NULL with responselen != 0");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002621 return RIL_ERRNO_INVALID_RESPONSE;
2622 }
2623
2624 // The java code reads -1 size as null byte array
2625 if (response == NULL) {
Wink Saville7f856802009-06-09 10:23:37 -07002626 p.writeInt32(-1);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002627 } else {
2628 p.writeInt32(responselen);
2629 p.write(response, responselen);
2630 }
2631
2632 return 0;
2633}
2634
2635
Wink Savillef4c4d362009-04-02 01:37:03 -07002636static int responseSIM_IO(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002637 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002638 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002639 return RIL_ERRNO_INVALID_RESPONSE;
2640 }
2641
2642 if (responselen != sizeof (RIL_SIM_IO_Response) ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002643 RLOGE("invalid response length was %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002644 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
2645 return RIL_ERRNO_INVALID_RESPONSE;
2646 }
2647
2648 RIL_SIM_IO_Response *p_cur = (RIL_SIM_IO_Response *) response;
2649 p.writeInt32(p_cur->sw1);
2650 p.writeInt32(p_cur->sw2);
2651 writeStringToParcel(p, p_cur->simResponse);
2652
2653 startResponse;
2654 appendPrintBuf("%ssw1=0x%X,sw2=0x%X,%s", printBuf, p_cur->sw1, p_cur->sw2,
2655 (char*)p_cur->simResponse);
2656 closeResponse;
2657
2658
2659 return 0;
2660}
2661
Wink Savillef4c4d362009-04-02 01:37:03 -07002662static int responseCallForwards(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002663 int num;
Wink Saville7f856802009-06-09 10:23:37 -07002664
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002665 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002666 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002667 return RIL_ERRNO_INVALID_RESPONSE;
2668 }
2669
2670 if (responselen % sizeof(RIL_CallForwardInfo *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002671 RLOGE("responseCallForwards: invalid response length %d expected multiple of %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002672 (int)responselen, (int)sizeof(RIL_CallForwardInfo *));
2673 return RIL_ERRNO_INVALID_RESPONSE;
2674 }
2675
2676 /* number of call info's */
2677 num = responselen / sizeof(RIL_CallForwardInfo *);
2678 p.writeInt32(num);
2679
2680 startResponse;
2681 for (int i = 0 ; i < num ; i++) {
2682 RIL_CallForwardInfo *p_cur = ((RIL_CallForwardInfo **) response)[i];
2683
2684 p.writeInt32(p_cur->status);
2685 p.writeInt32(p_cur->reason);
2686 p.writeInt32(p_cur->serviceClass);
2687 p.writeInt32(p_cur->toa);
2688 writeStringToParcel(p, p_cur->number);
2689 p.writeInt32(p_cur->timeSeconds);
2690 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
2691 (p_cur->status==1)?"enable":"disable",
2692 p_cur->reason, p_cur->serviceClass, p_cur->toa,
2693 (char*)p_cur->number,
2694 p_cur->timeSeconds);
2695 }
2696 removeLastChar;
2697 closeResponse;
Wink Saville7f856802009-06-09 10:23:37 -07002698
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002699 return 0;
2700}
2701
Wink Savillef4c4d362009-04-02 01:37:03 -07002702static int responseSsn(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002703 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002704 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002705 return RIL_ERRNO_INVALID_RESPONSE;
2706 }
2707
2708 if (responselen != sizeof(RIL_SuppSvcNotification)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002709 RLOGE("invalid response length was %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002710 (int)responselen, (int)sizeof (RIL_SuppSvcNotification));
2711 return RIL_ERRNO_INVALID_RESPONSE;
2712 }
2713
2714 RIL_SuppSvcNotification *p_cur = (RIL_SuppSvcNotification *) response;
2715 p.writeInt32(p_cur->notificationType);
2716 p.writeInt32(p_cur->code);
2717 p.writeInt32(p_cur->index);
2718 p.writeInt32(p_cur->type);
2719 writeStringToParcel(p, p_cur->number);
2720
2721 startResponse;
2722 appendPrintBuf("%s%s,code=%d,id=%d,type=%d,%s", printBuf,
2723 (p_cur->notificationType==0)?"mo":"mt",
2724 p_cur->code, p_cur->index, p_cur->type,
2725 (char*)p_cur->number);
2726 closeResponse;
2727
2728 return 0;
2729}
2730
Wink Saville3d54e742009-05-18 18:00:44 -07002731static int responseCellList(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002732 int num;
2733
2734 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002735 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002736 return RIL_ERRNO_INVALID_RESPONSE;
2737 }
2738
2739 if (responselen % sizeof (RIL_NeighboringCell *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002740 RLOGE("responseCellList: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002741 (int)responselen, (int)sizeof (RIL_NeighboringCell *));
2742 return RIL_ERRNO_INVALID_RESPONSE;
2743 }
2744
2745 startResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002746 /* number of records */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002747 num = responselen / sizeof(RIL_NeighboringCell *);
2748 p.writeInt32(num);
2749
2750 for (int i = 0 ; i < num ; i++) {
2751 RIL_NeighboringCell *p_cur = ((RIL_NeighboringCell **) response)[i];
2752
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002753 p.writeInt32(p_cur->rssi);
2754 writeStringToParcel (p, p_cur->cid);
2755
2756 appendPrintBuf("%s[cid=%s,rssi=%d],", printBuf,
2757 p_cur->cid, p_cur->rssi);
2758 }
2759 removeLastChar;
2760 closeResponse;
2761
2762 return 0;
2763}
2764
Wink Saville3d54e742009-05-18 18:00:44 -07002765/**
2766 * Marshall the signalInfoRecord into the parcel if it exists.
2767 */
Wink Savillea592eeb2009-05-22 13:26:36 -07002768static void marshallSignalInfoRecord(Parcel &p,
2769 RIL_CDMA_SignalInfoRecord &p_signalInfoRecord) {
Wink Saville3d54e742009-05-18 18:00:44 -07002770 p.writeInt32(p_signalInfoRecord.isPresent);
2771 p.writeInt32(p_signalInfoRecord.signalType);
2772 p.writeInt32(p_signalInfoRecord.alertPitch);
2773 p.writeInt32(p_signalInfoRecord.signal);
2774}
2775
Wink Savillea592eeb2009-05-22 13:26:36 -07002776static int responseCdmaInformationRecords(Parcel &p,
2777 void *response, size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07002778 int num;
Wink Savillea592eeb2009-05-22 13:26:36 -07002779 char* string8 = NULL;
2780 int buffer_lenght;
2781 RIL_CDMA_InformationRecord *infoRec;
Wink Saville3d54e742009-05-18 18:00:44 -07002782
2783 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002784 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002785 return RIL_ERRNO_INVALID_RESPONSE;
2786 }
2787
Wink Savillea592eeb2009-05-22 13:26:36 -07002788 if (responselen != sizeof (RIL_CDMA_InformationRecords)) {
Amit Mahajan52500162014-07-29 17:36:48 -07002789 RLOGE("responseCdmaInformationRecords: invalid response length %d expected multiple of %d\n",
Wink Savillea592eeb2009-05-22 13:26:36 -07002790 (int)responselen, (int)sizeof (RIL_CDMA_InformationRecords *));
Wink Saville3d54e742009-05-18 18:00:44 -07002791 return RIL_ERRNO_INVALID_RESPONSE;
2792 }
2793
Wink Savillea592eeb2009-05-22 13:26:36 -07002794 RIL_CDMA_InformationRecords *p_cur =
2795 (RIL_CDMA_InformationRecords *) response;
2796 num = MIN(p_cur->numberOfInfoRecs, RIL_CDMA_MAX_NUMBER_OF_INFO_RECS);
Wink Saville3d54e742009-05-18 18:00:44 -07002797
2798 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07002799 p.writeInt32(num);
Wink Saville3d54e742009-05-18 18:00:44 -07002800
Wink Savillea592eeb2009-05-22 13:26:36 -07002801 for (int i = 0 ; i < num ; i++) {
2802 infoRec = &p_cur->infoRec[i];
2803 p.writeInt32(infoRec->name);
2804 switch (infoRec->name) {
Wink Saville3d54e742009-05-18 18:00:44 -07002805 case RIL_CDMA_DISPLAY_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002806 case RIL_CDMA_EXTENDED_DISPLAY_INFO_REC:
2807 if (infoRec->rec.display.alpha_len >
2808 CDMA_ALPHA_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002809 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002810 expected not more than %d\n",
2811 (int)infoRec->rec.display.alpha_len,
2812 CDMA_ALPHA_INFO_BUFFER_LENGTH);
2813 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002814 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002815 string8 = (char*) malloc((infoRec->rec.display.alpha_len + 1)
2816 * sizeof(char) );
2817 for (int i = 0 ; i < infoRec->rec.display.alpha_len ; i++) {
2818 string8[i] = infoRec->rec.display.alpha_buf[i];
2819 }
Wink Saville43808972011-01-13 17:39:51 -08002820 string8[(int)infoRec->rec.display.alpha_len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002821 writeStringToParcel(p, (const char*)string8);
2822 free(string8);
2823 string8 = NULL;
Wink Saville3d54e742009-05-18 18:00:44 -07002824 break;
2825 case RIL_CDMA_CALLED_PARTY_NUMBER_INFO_REC:
Wink Saville3d54e742009-05-18 18:00:44 -07002826 case RIL_CDMA_CALLING_PARTY_NUMBER_INFO_REC:
Wink Saville3d54e742009-05-18 18:00:44 -07002827 case RIL_CDMA_CONNECTED_NUMBER_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002828 if (infoRec->rec.number.len > CDMA_NUMBER_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002829 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002830 expected not more than %d\n",
2831 (int)infoRec->rec.number.len,
2832 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2833 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002834 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002835 string8 = (char*) malloc((infoRec->rec.number.len + 1)
2836 * sizeof(char) );
2837 for (int i = 0 ; i < infoRec->rec.number.len; i++) {
2838 string8[i] = infoRec->rec.number.buf[i];
2839 }
Wink Saville43808972011-01-13 17:39:51 -08002840 string8[(int)infoRec->rec.number.len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002841 writeStringToParcel(p, (const char*)string8);
2842 free(string8);
2843 string8 = NULL;
2844 p.writeInt32(infoRec->rec.number.number_type);
2845 p.writeInt32(infoRec->rec.number.number_plan);
2846 p.writeInt32(infoRec->rec.number.pi);
2847 p.writeInt32(infoRec->rec.number.si);
Wink Saville3d54e742009-05-18 18:00:44 -07002848 break;
2849 case RIL_CDMA_SIGNAL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002850 p.writeInt32(infoRec->rec.signal.isPresent);
2851 p.writeInt32(infoRec->rec.signal.signalType);
2852 p.writeInt32(infoRec->rec.signal.alertPitch);
2853 p.writeInt32(infoRec->rec.signal.signal);
2854
2855 appendPrintBuf("%sisPresent=%X, signalType=%X, \
2856 alertPitch=%X, signal=%X, ",
2857 printBuf, (int)infoRec->rec.signal.isPresent,
2858 (int)infoRec->rec.signal.signalType,
2859 (int)infoRec->rec.signal.alertPitch,
2860 (int)infoRec->rec.signal.signal);
2861 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002862 break;
2863 case RIL_CDMA_REDIRECTING_NUMBER_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002864 if (infoRec->rec.redir.redirectingNumber.len >
2865 CDMA_NUMBER_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002866 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002867 expected not more than %d\n",
2868 (int)infoRec->rec.redir.redirectingNumber.len,
2869 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2870 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002871 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002872 string8 = (char*) malloc((infoRec->rec.redir.redirectingNumber
2873 .len + 1) * sizeof(char) );
2874 for (int i = 0;
2875 i < infoRec->rec.redir.redirectingNumber.len;
2876 i++) {
2877 string8[i] = infoRec->rec.redir.redirectingNumber.buf[i];
2878 }
Wink Saville43808972011-01-13 17:39:51 -08002879 string8[(int)infoRec->rec.redir.redirectingNumber.len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002880 writeStringToParcel(p, (const char*)string8);
2881 free(string8);
2882 string8 = NULL;
2883 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_type);
2884 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_plan);
2885 p.writeInt32(infoRec->rec.redir.redirectingNumber.pi);
2886 p.writeInt32(infoRec->rec.redir.redirectingNumber.si);
2887 p.writeInt32(infoRec->rec.redir.redirectingReason);
Wink Saville3d54e742009-05-18 18:00:44 -07002888 break;
2889 case RIL_CDMA_LINE_CONTROL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002890 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPolarityIncluded);
2891 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlToggle);
2892 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlReverse);
2893 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2894
2895 appendPrintBuf("%slineCtrlPolarityIncluded=%d, \
2896 lineCtrlToggle=%d, lineCtrlReverse=%d, \
2897 lineCtrlPowerDenial=%d, ", printBuf,
2898 (int)infoRec->rec.lineCtrl.lineCtrlPolarityIncluded,
2899 (int)infoRec->rec.lineCtrl.lineCtrlToggle,
2900 (int)infoRec->rec.lineCtrl.lineCtrlReverse,
2901 (int)infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2902 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002903 break;
2904 case RIL_CDMA_T53_CLIR_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002905 p.writeInt32((int)(infoRec->rec.clir.cause));
Wink Saville3d54e742009-05-18 18:00:44 -07002906
Wink Savillea592eeb2009-05-22 13:26:36 -07002907 appendPrintBuf("%scause%d", printBuf, infoRec->rec.clir.cause);
2908 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002909 break;
2910 case RIL_CDMA_T53_AUDIO_CONTROL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002911 p.writeInt32(infoRec->rec.audioCtrl.upLink);
2912 p.writeInt32(infoRec->rec.audioCtrl.downLink);
2913
2914 appendPrintBuf("%supLink=%d, downLink=%d, ", printBuf,
2915 infoRec->rec.audioCtrl.upLink,
2916 infoRec->rec.audioCtrl.downLink);
2917 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002918 break;
Wink Savillea592eeb2009-05-22 13:26:36 -07002919 case RIL_CDMA_T53_RELEASE_INFO_REC:
2920 // TODO(Moto): See David Krause, he has the answer:)
Wink Saville8eb2a122012-11-19 16:05:13 -08002921 RLOGE("RIL_CDMA_T53_RELEASE_INFO_REC: return INVALID_RESPONSE");
Wink Savillea592eeb2009-05-22 13:26:36 -07002922 return RIL_ERRNO_INVALID_RESPONSE;
2923 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08002924 RLOGE("Incorrect name value");
Wink Savillea592eeb2009-05-22 13:26:36 -07002925 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002926 }
2927 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002928 closeResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002929
Wink Savillea592eeb2009-05-22 13:26:36 -07002930 return 0;
Wink Saville3d54e742009-05-18 18:00:44 -07002931}
2932
Sanket Padawe88cf6a52016-01-11 12:45:43 -08002933static void responseRilSignalStrengthV5(Parcel &p, RIL_SignalStrength_v10 *p_cur) {
2934 p.writeInt32(p_cur->GW_SignalStrength.signalStrength);
2935 p.writeInt32(p_cur->GW_SignalStrength.bitErrorRate);
2936 p.writeInt32(p_cur->CDMA_SignalStrength.dbm);
2937 p.writeInt32(p_cur->CDMA_SignalStrength.ecio);
2938 p.writeInt32(p_cur->EVDO_SignalStrength.dbm);
2939 p.writeInt32(p_cur->EVDO_SignalStrength.ecio);
2940 p.writeInt32(p_cur->EVDO_SignalStrength.signalNoiseRatio);
2941}
2942
2943static void responseRilSignalStrengthV6Extra(Parcel &p, RIL_SignalStrength_v10 *p_cur) {
2944 /*
2945 * Fixup LTE for backwards compatibility
2946 */
2947 // signalStrength: -1 -> 99
2948 if (p_cur->LTE_SignalStrength.signalStrength == -1) {
2949 p_cur->LTE_SignalStrength.signalStrength = 99;
2950 }
2951 // rsrp: -1 -> INT_MAX all other negative value to positive.
2952 // So remap here
2953 if (p_cur->LTE_SignalStrength.rsrp == -1) {
2954 p_cur->LTE_SignalStrength.rsrp = INT_MAX;
2955 } else if (p_cur->LTE_SignalStrength.rsrp < -1) {
2956 p_cur->LTE_SignalStrength.rsrp = -p_cur->LTE_SignalStrength.rsrp;
2957 }
2958 // rsrq: -1 -> INT_MAX
2959 if (p_cur->LTE_SignalStrength.rsrq == -1) {
2960 p_cur->LTE_SignalStrength.rsrq = INT_MAX;
2961 }
2962 // Not remapping rssnr is already using INT_MAX
2963
2964 // cqi: -1 -> INT_MAX
2965 if (p_cur->LTE_SignalStrength.cqi == -1) {
2966 p_cur->LTE_SignalStrength.cqi = INT_MAX;
2967 }
2968
2969 p.writeInt32(p_cur->LTE_SignalStrength.signalStrength);
2970 p.writeInt32(p_cur->LTE_SignalStrength.rsrp);
2971 p.writeInt32(p_cur->LTE_SignalStrength.rsrq);
2972 p.writeInt32(p_cur->LTE_SignalStrength.rssnr);
2973 p.writeInt32(p_cur->LTE_SignalStrength.cqi);
2974}
2975
2976static void responseRilSignalStrengthV10(Parcel &p, RIL_SignalStrength_v10 *p_cur) {
2977 responseRilSignalStrengthV5(p, p_cur);
2978 responseRilSignalStrengthV6Extra(p, p_cur);
2979 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
2980}
2981
Wink Savillea592eeb2009-05-22 13:26:36 -07002982static int responseRilSignalStrength(Parcel &p,
2983 void *response, size_t responselen) {
2984 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002985 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002986 return RIL_ERRNO_INVALID_RESPONSE;
2987 }
2988
Sanket Padawe88cf6a52016-01-11 12:45:43 -08002989 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
2990 if (responselen >= sizeof (RIL_SignalStrength_v5)) {
2991 RIL_SignalStrength_v10 *p_cur = ((RIL_SignalStrength_v10 *) response);
Wink Saville3d54e742009-05-18 18:00:44 -07002992
Sanket Padawe88cf6a52016-01-11 12:45:43 -08002993 responseRilSignalStrengthV5(p, p_cur);
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002994
Sanket Padawe88cf6a52016-01-11 12:45:43 -08002995 if (responselen >= sizeof (RIL_SignalStrength_v6)) {
2996 responseRilSignalStrengthV6Extra(p, p_cur);
2997 if (responselen >= sizeof (RIL_SignalStrength_v10)) {
2998 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
2999 } else {
3000 p.writeInt32(INT_MAX);
Wink Saville18e4ab12013-04-07 17:31:04 -07003001 }
Etan Cohend3652192014-06-20 08:28:44 -07003002 } else {
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003003 p.writeInt32(99);
3004 p.writeInt32(INT_MAX);
3005 p.writeInt32(INT_MAX);
3006 p.writeInt32(INT_MAX);
3007 p.writeInt32(INT_MAX);
Etan Cohend3652192014-06-20 08:28:44 -07003008 p.writeInt32(INT_MAX);
3009 }
Wink Savillec0114b32011-02-18 10:14:07 -08003010 } else {
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003011 RLOGE("invalid response length");
3012 return RIL_ERRNO_INVALID_RESPONSE;
Wink Savillec0114b32011-02-18 10:14:07 -08003013 }
Sanket Padawef53c5fa2016-01-27 10:00:38 -08003014 } else { // RIL version >= 13
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003015 if (responselen % sizeof(RIL_SignalStrength_v10) != 0) {
3016 RLOGE("Data structure expected is RIL_SignalStrength_v10");
3017 if (!isDebuggable()) {
3018 return RIL_ERRNO_INVALID_RESPONSE;
3019 } else {
3020 assert(0);
3021 }
3022 }
3023 RIL_SignalStrength_v10 *p_cur = ((RIL_SignalStrength_v10 *) response);
3024 responseRilSignalStrengthV10(p, p_cur);
Wink Saville3d54e742009-05-18 18:00:44 -07003025 }
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003026 startResponse;
3027 appendPrintBuf("%s[signalStrength=%d,bitErrorRate=%d,\
3028 CDMA_SS.dbm=%d,CDMA_SSecio=%d,\
3029 EVDO_SS.dbm=%d,EVDO_SS.ecio=%d,\
3030 EVDO_SS.signalNoiseRatio=%d,\
3031 LTE_SS.signalStrength=%d,LTE_SS.rsrp=%d,LTE_SS.rsrq=%d,\
3032 LTE_SS.rssnr=%d,LTE_SS.cqi=%d,TDSCDMA_SS.rscp=%d]",
3033 printBuf,
3034 p_cur->GW_SignalStrength.signalStrength,
3035 p_cur->GW_SignalStrength.bitErrorRate,
3036 p_cur->CDMA_SignalStrength.dbm,
3037 p_cur->CDMA_SignalStrength.ecio,
3038 p_cur->EVDO_SignalStrength.dbm,
3039 p_cur->EVDO_SignalStrength.ecio,
3040 p_cur->EVDO_SignalStrength.signalNoiseRatio,
3041 p_cur->LTE_SignalStrength.signalStrength,
3042 p_cur->LTE_SignalStrength.rsrp,
3043 p_cur->LTE_SignalStrength.rsrq,
3044 p_cur->LTE_SignalStrength.rssnr,
3045 p_cur->LTE_SignalStrength.cqi,
3046 p_cur->TD_SCDMA_SignalStrength.rscp);
3047 closeResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07003048 return 0;
3049}
3050
3051static int responseCallRing(Parcel &p, void *response, size_t responselen) {
3052 if ((response == NULL) || (responselen == 0)) {
3053 return responseVoid(p, response, responselen);
3054 } else {
3055 return responseCdmaSignalInfoRecord(p, response, responselen);
3056 }
3057}
3058
3059static int responseCdmaSignalInfoRecord(Parcel &p, void *response, size_t responselen) {
3060 if (response == NULL || responselen == 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003061 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07003062 return RIL_ERRNO_INVALID_RESPONSE;
3063 }
3064
3065 if (responselen != sizeof (RIL_CDMA_SignalInfoRecord)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003066 RLOGE("invalid response length %d expected sizeof (RIL_CDMA_SignalInfoRecord) of %d\n",
Wink Saville3d54e742009-05-18 18:00:44 -07003067 (int)responselen, (int)sizeof (RIL_CDMA_SignalInfoRecord));
3068 return RIL_ERRNO_INVALID_RESPONSE;
3069 }
3070
3071 startResponse;
3072
3073 RIL_CDMA_SignalInfoRecord *p_cur = ((RIL_CDMA_SignalInfoRecord *) response);
3074 marshallSignalInfoRecord(p, *p_cur);
3075
3076 appendPrintBuf("%s[isPresent=%d,signalType=%d,alertPitch=%d\
3077 signal=%d]",
3078 printBuf,
3079 p_cur->isPresent,
3080 p_cur->signalType,
3081 p_cur->alertPitch,
3082 p_cur->signal);
3083
3084 closeResponse;
3085 return 0;
3086}
3087
Wink Savillea592eeb2009-05-22 13:26:36 -07003088static int responseCdmaCallWaiting(Parcel &p, void *response,
3089 size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07003090 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003091 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07003092 return RIL_ERRNO_INVALID_RESPONSE;
3093 }
3094
Wink Savillec0114b32011-02-18 10:14:07 -08003095 if (responselen < sizeof(RIL_CDMA_CallWaiting_v6)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003096 RLOGW("Upgrade to ril version %d\n", RIL_VERSION);
Wink Savillec0114b32011-02-18 10:14:07 -08003097 }
3098
3099 RIL_CDMA_CallWaiting_v6 *p_cur = ((RIL_CDMA_CallWaiting_v6 *) response);
3100
3101 writeStringToParcel(p, p_cur->number);
3102 p.writeInt32(p_cur->numberPresentation);
3103 writeStringToParcel(p, p_cur->name);
3104 marshallSignalInfoRecord(p, p_cur->signalInfoRecord);
3105
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003106 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
3107 if (responselen >= sizeof(RIL_CDMA_CallWaiting_v6)) {
3108 p.writeInt32(p_cur->number_type);
3109 p.writeInt32(p_cur->number_plan);
3110 } else {
3111 p.writeInt32(0);
3112 p.writeInt32(0);
3113 }
Sanket Padawef53c5fa2016-01-27 10:00:38 -08003114 } else { // RIL version >= 13
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003115 if (responselen % sizeof(RIL_CDMA_CallWaiting_v6) != 0) {
3116 RLOGE("Data structure expected is RIL_CDMA_CallWaiting_v6");
3117 if (!isDebuggable()) {
3118 return RIL_ERRNO_INVALID_RESPONSE;
3119 } else {
3120 assert(0);
3121 }
3122 }
Wink Savillec0114b32011-02-18 10:14:07 -08003123 p.writeInt32(p_cur->number_type);
3124 p.writeInt32(p_cur->number_plan);
Wink Saville3d54e742009-05-18 18:00:44 -07003125 }
3126
3127 startResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07003128 appendPrintBuf("%snumber=%s,numberPresentation=%d, name=%s,\
3129 signalInfoRecord[isPresent=%d,signalType=%d,alertPitch=%d\
Wink Savillec0114b32011-02-18 10:14:07 -08003130 signal=%d,number_type=%d,number_plan=%d]",
Wink Saville3d54e742009-05-18 18:00:44 -07003131 printBuf,
3132 p_cur->number,
3133 p_cur->numberPresentation,
3134 p_cur->name,
3135 p_cur->signalInfoRecord.isPresent,
3136 p_cur->signalInfoRecord.signalType,
3137 p_cur->signalInfoRecord.alertPitch,
Wink Savillec0114b32011-02-18 10:14:07 -08003138 p_cur->signalInfoRecord.signal,
3139 p_cur->number_type,
3140 p_cur->number_plan);
Wink Saville3d54e742009-05-18 18:00:44 -07003141 closeResponse;
3142
3143 return 0;
3144}
3145
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003146static void responseSimRefreshV7(Parcel &p, void *response) {
3147 RIL_SimRefreshResponse_v7 *p_cur = ((RIL_SimRefreshResponse_v7 *) response);
3148 p.writeInt32(p_cur->result);
3149 p.writeInt32(p_cur->ef_id);
3150 writeStringToParcel(p, p_cur->aid);
3151
3152 appendPrintBuf("%sresult=%d, ef_id=%d, aid=%s",
3153 printBuf,
3154 p_cur->result,
3155 p_cur->ef_id,
3156 p_cur->aid);
3157
3158}
3159
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003160static int responseSimRefresh(Parcel &p, void *response, size_t responselen) {
3161 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003162 RLOGE("responseSimRefresh: invalid response: NULL");
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003163 return RIL_ERRNO_INVALID_RESPONSE;
3164 }
3165
3166 startResponse;
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003167 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
Sanket Padawe41c94d02016-01-21 15:49:33 -08003168 if (s_callbacks.version >= 7) {
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003169 responseSimRefreshV7(p, response);
3170 } else {
3171 int *p_cur = ((int *) response);
3172 p.writeInt32(p_cur[0]);
3173 p.writeInt32(p_cur[1]);
3174 writeStringToParcel(p, NULL);
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003175
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003176 appendPrintBuf("%sresult=%d, ef_id=%d",
3177 printBuf,
3178 p_cur[0],
3179 p_cur[1]);
3180 }
Sanket Padawef53c5fa2016-01-27 10:00:38 -08003181 } else { // RIL version >= 13
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003182 if (responselen % sizeof(RIL_SimRefreshResponse_v7) != 0) {
3183 RLOGE("Data structure expected is RIL_SimRefreshResponse_v7");
3184 if (!isDebuggable()) {
3185 return RIL_ERRNO_INVALID_RESPONSE;
3186 } else {
3187 assert(0);
3188 }
3189 }
3190 responseSimRefreshV7(p, response);
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003191
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003192 }
3193 closeResponse;
3194
3195 return 0;
3196}
3197
Sanket Padawef53c5fa2016-01-27 10:00:38 -08003198static int responseCellInfoListV6(Parcel &p, void *response, size_t responselen) {
Wink Saville8a9e0212013-04-09 12:11:38 -07003199 if (response == NULL && responselen != 0) {
3200 RLOGE("invalid response: NULL");
3201 return RIL_ERRNO_INVALID_RESPONSE;
3202 }
3203
3204 if (responselen % sizeof(RIL_CellInfo) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07003205 RLOGE("responseCellInfoList: invalid response length %d expected multiple of %d",
Wink Saville8a9e0212013-04-09 12:11:38 -07003206 (int)responselen, (int)sizeof(RIL_CellInfo));
3207 return RIL_ERRNO_INVALID_RESPONSE;
3208 }
3209
3210 int num = responselen / sizeof(RIL_CellInfo);
3211 p.writeInt32(num);
3212
3213 RIL_CellInfo *p_cur = (RIL_CellInfo *) response;
3214 startResponse;
3215 int i;
3216 for (i = 0; i < num; i++) {
3217 appendPrintBuf("%s[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", printBuf, i,
3218 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
3219 p.writeInt32((int)p_cur->cellInfoType);
3220 p.writeInt32(p_cur->registered);
3221 p.writeInt32(p_cur->timeStampType);
3222 p.writeInt64(p_cur->timeStamp);
3223 switch(p_cur->cellInfoType) {
3224 case RIL_CELL_INFO_TYPE_GSM: {
Wink Savillec57b3eb2013-04-17 12:51:41 -07003225 appendPrintBuf("%s GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,", printBuf,
Wink Saville8a9e0212013-04-09 12:11:38 -07003226 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
3227 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
3228 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
Wink Savillec57b3eb2013-04-17 12:51:41 -07003229 p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3230 appendPrintBuf("%s gsmSS: ss=%d,ber=%d],", printBuf,
Wink Saville8a9e0212013-04-09 12:11:38 -07003231 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
3232 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3233
3234 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
3235 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
3236 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
3237 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
Wink Saville8a9e0212013-04-09 12:11:38 -07003238 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
3239 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3240 break;
3241 }
Wink Savillec57b3eb2013-04-17 12:51:41 -07003242 case RIL_CELL_INFO_TYPE_WCDMA: {
3243 appendPrintBuf("%s WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,", printBuf,
3244 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
3245 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
3246 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
3247 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
3248 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3249 appendPrintBuf("%s wcdmaSS: ss=%d,ber=%d],", printBuf,
3250 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
3251 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3252
3253 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
3254 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
3255 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
3256 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
3257 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3258 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
3259 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3260 break;
3261 }
Wink Saville8a9e0212013-04-09 12:11:38 -07003262 case RIL_CELL_INFO_TYPE_CDMA: {
3263 appendPrintBuf("%s CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d", printBuf,
3264 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
3265 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
3266 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
3267 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
3268 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3269
3270 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
3271 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
3272 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
3273 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
3274 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3275
3276 appendPrintBuf("%s cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d", printBuf,
3277 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
3278 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
3279 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
3280 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
3281 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3282
3283 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
3284 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
3285 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
3286 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
3287 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3288 break;
3289 }
3290 case RIL_CELL_INFO_TYPE_LTE: {
3291 appendPrintBuf("%s LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d", printBuf,
3292 p_cur->CellInfo.lte.cellIdentityLte.mcc,
3293 p_cur->CellInfo.lte.cellIdentityLte.mnc,
3294 p_cur->CellInfo.lte.cellIdentityLte.ci,
3295 p_cur->CellInfo.lte.cellIdentityLte.pci,
3296 p_cur->CellInfo.lte.cellIdentityLte.tac);
3297
3298 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
3299 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
3300 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
3301 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
3302 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
3303
3304 appendPrintBuf("%s lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d", printBuf,
3305 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
3306 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
3307 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
3308 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
3309 p_cur->CellInfo.lte.signalStrengthLte.cqi,
3310 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3311 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
3312 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
3313 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
3314 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
3315 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
3316 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3317 break;
3318 }
Etan Cohend3652192014-06-20 08:28:44 -07003319 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
3320 appendPrintBuf("%s TDSCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,cpid=%d,", printBuf,
3321 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc,
3322 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc,
3323 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac,
3324 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid,
3325 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3326 appendPrintBuf("%s tdscdmaSS: rscp=%d],", printBuf,
3327 p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3328
3329 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
3330 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
3331 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
3332 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
3333 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3334 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3335 break;
3336 }
Wink Saville8a9e0212013-04-09 12:11:38 -07003337 }
3338 p_cur += 1;
3339 }
3340 removeLastChar;
3341 closeResponse;
3342
3343 return 0;
3344}
3345
Sanket Padawef53c5fa2016-01-27 10:00:38 -08003346static int responseCellInfoListV12(Parcel &p, void *response, size_t responselen) {
3347 if (response == NULL && responselen != 0) {
3348 RLOGE("invalid response: NULL");
3349 return RIL_ERRNO_INVALID_RESPONSE;
3350 }
3351
3352 if (responselen % sizeof(RIL_CellInfo_v12) != 0) {
3353 RLOGE("responseCellInfoList: invalid response length %d expected multiple of %d",
3354 (int)responselen, (int)sizeof(RIL_CellInfo_v12));
3355 return RIL_ERRNO_INVALID_RESPONSE;
3356 }
3357
3358 int num = responselen / sizeof(RIL_CellInfo_v12);
3359 p.writeInt32(num);
3360
3361 RIL_CellInfo_v12 *p_cur = (RIL_CellInfo_v12 *) response;
3362 startResponse;
3363 int i;
3364 for (i = 0; i < num; i++) {
3365 appendPrintBuf("%s[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", printBuf, i,
3366 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
3367 RLOGE("[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", i,
3368 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
3369 p.writeInt32((int)p_cur->cellInfoType);
3370 p.writeInt32(p_cur->registered);
3371 p.writeInt32(p_cur->timeStampType);
3372 p.writeInt64(p_cur->timeStamp);
3373 switch(p_cur->cellInfoType) {
3374 case RIL_CELL_INFO_TYPE_GSM: {
3375 appendPrintBuf("%s GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,arfcn=%d,bsic=%x", printBuf,
3376 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
3377 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
3378 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
3379 p_cur->CellInfo.gsm.cellIdentityGsm.cid,
3380 p_cur->CellInfo.gsm.cellIdentityGsm.arfcn,
3381 p_cur->CellInfo.gsm.cellIdentityGsm.bsic);
3382 RLOGE("GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,arfcn=%d,bsic=%x",
3383 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
3384 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
3385 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
3386 p_cur->CellInfo.gsm.cellIdentityGsm.cid,
3387 p_cur->CellInfo.gsm.cellIdentityGsm.arfcn,
3388 p_cur->CellInfo.gsm.cellIdentityGsm.bsic);
3389 RLOGE("gsmSS: ss=%d,ber=%d, ta=%d],",
3390 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
3391 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate,
3392 p_cur->CellInfo.gsm.signalStrengthGsm.timingAdvance);
3393 appendPrintBuf("%s gsmSS: ss=%d,ber=%d, ta=%d],", printBuf,
3394 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
3395 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate,
3396 p_cur->CellInfo.gsm.signalStrengthGsm.timingAdvance);
3397
3398 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
3399 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
3400 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
3401 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3402 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.arfcn);
3403 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.bsic);
3404 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
3405 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3406 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.timingAdvance);
3407 break;
3408 }
3409 case RIL_CELL_INFO_TYPE_WCDMA: {
3410 RLOGE("WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,uarfcn=%d",
3411 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
3412 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
3413 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
3414 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
3415 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc,
3416 p_cur->CellInfo.wcdma.cellIdentityWcdma.uarfcn);
3417 RLOGE("wcdmaSS: ss=%d,ber=%d],",
3418 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
3419 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3420 appendPrintBuf("%s WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,uarfcn=%d", printBuf,
3421 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
3422 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
3423 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
3424 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
3425 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc,
3426 p_cur->CellInfo.wcdma.cellIdentityWcdma.uarfcn);
3427 appendPrintBuf("%s wcdmaSS: ss=%d,ber=%d],", printBuf,
3428 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
3429 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3430
3431 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
3432 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
3433 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
3434 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
3435 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3436 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.uarfcn);
3437 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
3438 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3439 break;
3440 }
3441 case RIL_CELL_INFO_TYPE_CDMA: {
3442 RLOGE("CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d",
3443 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
3444 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
3445 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
3446 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
3447 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3448
3449 appendPrintBuf("%s CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d", printBuf,
3450 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
3451 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
3452 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
3453 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
3454 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3455
3456 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
3457 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
3458 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
3459 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
3460 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3461
3462 RLOGE("cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d",
3463 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
3464 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
3465 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
3466 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
3467 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3468
3469 appendPrintBuf("%s cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d", printBuf,
3470 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
3471 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
3472 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
3473 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
3474 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3475
3476 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
3477 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
3478 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
3479 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
3480 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3481 break;
3482 }
3483 case RIL_CELL_INFO_TYPE_LTE: {
3484 RLOGE("LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d,earfcn=%d",
3485 p_cur->CellInfo.lte.cellIdentityLte.mcc,
3486 p_cur->CellInfo.lte.cellIdentityLte.mnc,
3487 p_cur->CellInfo.lte.cellIdentityLte.ci,
3488 p_cur->CellInfo.lte.cellIdentityLte.pci,
3489 p_cur->CellInfo.lte.cellIdentityLte.tac,
3490 p_cur->CellInfo.lte.cellIdentityLte.earfcn);
3491
3492 appendPrintBuf("%s LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d,earfcn=%d", printBuf,
3493 p_cur->CellInfo.lte.cellIdentityLte.mcc,
3494 p_cur->CellInfo.lte.cellIdentityLte.mnc,
3495 p_cur->CellInfo.lte.cellIdentityLte.ci,
3496 p_cur->CellInfo.lte.cellIdentityLte.pci,
3497 p_cur->CellInfo.lte.cellIdentityLte.tac,
3498 p_cur->CellInfo.lte.cellIdentityLte.earfcn);
3499
3500 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
3501 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
3502 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
3503 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
3504 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
3505 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.earfcn);
3506
3507 RLOGE("lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d",
3508 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
3509 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
3510 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
3511 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
3512 p_cur->CellInfo.lte.signalStrengthLte.cqi,
3513 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3514 appendPrintBuf("%s lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d", printBuf,
3515 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
3516 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
3517 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
3518 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
3519 p_cur->CellInfo.lte.signalStrengthLte.cqi,
3520 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3521 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
3522 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
3523 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
3524 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
3525 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
3526 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3527 break;
3528 }
3529 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
3530 appendPrintBuf("%s TDSCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,cpid=%d,", printBuf,
3531 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc,
3532 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc,
3533 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac,
3534 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid,
3535 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3536 appendPrintBuf("%s tdscdmaSS: rscp=%d],", printBuf,
3537 p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3538
3539 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
3540 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
3541 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
3542 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
3543 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3544 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3545 break;
3546 }
3547 }
3548 p_cur += 1;
3549 }
3550 removeLastChar;
3551 closeResponse;
3552 return 0;
3553}
3554
3555static int responseCellInfoList(Parcel &p, void *response, size_t responselen)
3556{
3557 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
3558 if (s_callbacks.version < 12) {
3559 RLOGD("responseCellInfoList: v6");
3560 return responseCellInfoListV6(p, response, responselen);
3561 } else {
3562 RLOGD("responseCellInfoList: v12");
3563 return responseCellInfoListV12(p, response, responselen);
3564 }
3565 } else { // RIL version >= 13
3566 if (responselen % sizeof(RIL_CellInfo_v12) != 0) {
3567 RLOGE("Data structure expected is RIL_CellInfo_v12");
3568 if (!isDebuggable()) {
3569 return RIL_ERRNO_INVALID_RESPONSE;
3570 } else {
3571 assert(0);
3572 }
3573 }
3574 return responseCellInfoListV12(p, response, responselen);
3575 }
3576
3577 return 0;
3578}
3579
Etan Cohend3652192014-06-20 08:28:44 -07003580static int responseHardwareConfig(Parcel &p, void *response, size_t responselen)
3581{
3582 if (response == NULL && responselen != 0) {
3583 RLOGE("invalid response: NULL");
3584 return RIL_ERRNO_INVALID_RESPONSE;
3585 }
3586
3587 if (responselen % sizeof(RIL_HardwareConfig) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07003588 RLOGE("responseHardwareConfig: invalid response length %d expected multiple of %d",
Etan Cohend3652192014-06-20 08:28:44 -07003589 (int)responselen, (int)sizeof(RIL_HardwareConfig));
3590 return RIL_ERRNO_INVALID_RESPONSE;
3591 }
3592
3593 int num = responselen / sizeof(RIL_HardwareConfig);
3594 int i;
3595 RIL_HardwareConfig *p_cur = (RIL_HardwareConfig *) response;
3596
3597 p.writeInt32(num);
3598
3599 startResponse;
3600 for (i = 0; i < num; i++) {
3601 switch (p_cur[i].type) {
3602 case RIL_HARDWARE_CONFIG_MODEM: {
3603 writeStringToParcel(p, p_cur[i].uuid);
3604 p.writeInt32((int)p_cur[i].state);
3605 p.writeInt32(p_cur[i].cfg.modem.rat);
3606 p.writeInt32(p_cur[i].cfg.modem.maxVoice);
3607 p.writeInt32(p_cur[i].cfg.modem.maxData);
3608 p.writeInt32(p_cur[i].cfg.modem.maxStandby);
3609
3610 appendPrintBuf("%s modem: uuid=%s,state=%d,rat=%08x,maxV=%d,maxD=%d,maxS=%d", printBuf,
3611 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.modem.rat,
3612 p_cur[i].cfg.modem.maxVoice, p_cur[i].cfg.modem.maxData, p_cur[i].cfg.modem.maxStandby);
3613 break;
3614 }
3615 case RIL_HARDWARE_CONFIG_SIM: {
3616 writeStringToParcel(p, p_cur[i].uuid);
3617 p.writeInt32((int)p_cur[i].state);
3618 writeStringToParcel(p, p_cur[i].cfg.sim.modemUuid);
3619
3620 appendPrintBuf("%s sim: uuid=%s,state=%d,modem-uuid=%s", printBuf,
3621 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.sim.modemUuid);
3622 break;
3623 }
3624 }
3625 }
3626 removeLastChar;
3627 closeResponse;
3628 return 0;
3629}
3630
Wink Saville8b4e4f72014-10-17 15:01:45 -07003631static int responseRadioCapability(Parcel &p, void *response, size_t responselen) {
3632 if (response == NULL) {
3633 RLOGE("invalid response: NULL");
3634 return RIL_ERRNO_INVALID_RESPONSE;
3635 }
3636
3637 if (responselen != sizeof (RIL_RadioCapability) ) {
3638 RLOGE("invalid response length was %d expected %d",
3639 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3640 return RIL_ERRNO_INVALID_RESPONSE;
3641 }
3642
3643 RIL_RadioCapability *p_cur = (RIL_RadioCapability *) response;
3644 p.writeInt32(p_cur->version);
3645 p.writeInt32(p_cur->session);
3646 p.writeInt32(p_cur->phase);
3647 p.writeInt32(p_cur->rat);
3648 writeStringToParcel(p, p_cur->logicalModemUuid);
3649 p.writeInt32(p_cur->status);
3650
3651 startResponse;
3652 appendPrintBuf("%s[version=%d,session=%d,phase=%d,\
Legler Wu8caf06f2014-10-29 14:02:14 +08003653 rat=%s,logicalModemUuid=%s,status=%d]",
Wink Saville8b4e4f72014-10-17 15:01:45 -07003654 printBuf,
3655 p_cur->version,
3656 p_cur->session,
3657 p_cur->phase,
3658 p_cur->rat,
Legler Wu8caf06f2014-10-29 14:02:14 +08003659 p_cur->logicalModemUuid,
Wink Saville8b4e4f72014-10-17 15:01:45 -07003660 p_cur->status);
3661 closeResponse;
3662 return 0;
3663}
3664
Amit Mahajan54563d32014-11-22 00:54:49 +00003665static int responseSSData(Parcel &p, void *response, size_t responselen) {
3666 RLOGD("In responseSSData");
3667 int num;
3668
3669 if (response == NULL && responselen != 0) {
3670 RLOGE("invalid response length was %d expected %d",
3671 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3672 return RIL_ERRNO_INVALID_RESPONSE;
3673 }
3674
3675 if (responselen != sizeof(RIL_StkCcUnsolSsResponse)) {
3676 RLOGE("invalid response length %d, expected %d",
3677 (int)responselen, (int)sizeof(RIL_StkCcUnsolSsResponse));
3678 return RIL_ERRNO_INVALID_RESPONSE;
3679 }
3680
3681 startResponse;
3682 RIL_StkCcUnsolSsResponse *p_cur = (RIL_StkCcUnsolSsResponse *) response;
3683 p.writeInt32(p_cur->serviceType);
3684 p.writeInt32(p_cur->requestType);
3685 p.writeInt32(p_cur->teleserviceType);
3686 p.writeInt32(p_cur->serviceClass);
3687 p.writeInt32(p_cur->result);
3688
3689 if (isServiceTypeCfQuery(p_cur->serviceType, p_cur->requestType)) {
3690 RLOGD("responseSSData CF type, num of Cf elements %d", p_cur->cfData.numValidIndexes);
3691 if (p_cur->cfData.numValidIndexes > NUM_SERVICE_CLASSES) {
3692 RLOGE("numValidIndexes is greater than max value %d, "
3693 "truncating it to max value", NUM_SERVICE_CLASSES);
3694 p_cur->cfData.numValidIndexes = NUM_SERVICE_CLASSES;
3695 }
3696 /* number of call info's */
3697 p.writeInt32(p_cur->cfData.numValidIndexes);
3698
3699 for (int i = 0; i < p_cur->cfData.numValidIndexes; i++) {
3700 RIL_CallForwardInfo cf = p_cur->cfData.cfInfo[i];
3701
3702 p.writeInt32(cf.status);
3703 p.writeInt32(cf.reason);
3704 p.writeInt32(cf.serviceClass);
3705 p.writeInt32(cf.toa);
3706 writeStringToParcel(p, cf.number);
3707 p.writeInt32(cf.timeSeconds);
3708 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
3709 (cf.status==1)?"enable":"disable", cf.reason, cf.serviceClass, cf.toa,
3710 (char*)cf.number, cf.timeSeconds);
3711 RLOGD("Data: %d,reason=%d,cls=%d,toa=%d,num=%s,tout=%d],", cf.status,
3712 cf.reason, cf.serviceClass, cf.toa, (char*)cf.number, cf.timeSeconds);
3713 }
3714 } else {
3715 p.writeInt32 (SS_INFO_MAX);
3716
3717 /* each int*/
3718 for (int i = 0; i < SS_INFO_MAX; i++) {
3719 appendPrintBuf("%s%d,", printBuf, p_cur->ssInfo[i]);
3720 RLOGD("Data: %d",p_cur->ssInfo[i]);
3721 p.writeInt32(p_cur->ssInfo[i]);
3722 }
3723 }
3724 removeLastChar;
3725 closeResponse;
3726
3727 return 0;
3728}
3729
3730static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType) {
3731 if ((reqType == SS_INTERROGATION) &&
3732 (serType == SS_CFU ||
3733 serType == SS_CF_BUSY ||
3734 serType == SS_CF_NO_REPLY ||
3735 serType == SS_CF_NOT_REACHABLE ||
3736 serType == SS_CF_ALL ||
3737 serType == SS_CF_ALL_CONDITIONAL)) {
3738 return true;
3739 }
3740 return false;
3741}
3742
Wink Saville3d54e742009-05-18 18:00:44 -07003743static void triggerEvLoop() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003744 int ret;
3745 if (!pthread_equal(pthread_self(), s_tid_dispatch)) {
3746 /* trigger event loop to wakeup. No reason to do this,
3747 * if we're in the event loop thread */
3748 do {
3749 ret = write (s_fdWakeupWrite, " ", 1);
3750 } while (ret < 0 && errno == EINTR);
3751 }
3752}
3753
Wink Saville3d54e742009-05-18 18:00:44 -07003754static void rilEventAddWakeup(struct ril_event *ev) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003755 ril_event_add(ev);
3756 triggerEvLoop();
3757}
3758
Wink Savillefd729372011-02-22 16:19:39 -08003759static void sendSimStatusAppInfo(Parcel &p, int num_apps, RIL_AppStatus appStatus[]) {
3760 p.writeInt32(num_apps);
3761 startResponse;
3762 for (int i = 0; i < num_apps; i++) {
3763 p.writeInt32(appStatus[i].app_type);
3764 p.writeInt32(appStatus[i].app_state);
3765 p.writeInt32(appStatus[i].perso_substate);
3766 writeStringToParcel(p, (const char*)(appStatus[i].aid_ptr));
3767 writeStringToParcel(p, (const char*)
3768 (appStatus[i].app_label_ptr));
3769 p.writeInt32(appStatus[i].pin1_replaced);
3770 p.writeInt32(appStatus[i].pin1);
3771 p.writeInt32(appStatus[i].pin2);
3772 appendPrintBuf("%s[app_type=%d,app_state=%d,perso_substate=%d,\
3773 aid_ptr=%s,app_label_ptr=%s,pin1_replaced=%d,pin1=%d,pin2=%d],",
3774 printBuf,
3775 appStatus[i].app_type,
3776 appStatus[i].app_state,
3777 appStatus[i].perso_substate,
3778 appStatus[i].aid_ptr,
3779 appStatus[i].app_label_ptr,
3780 appStatus[i].pin1_replaced,
3781 appStatus[i].pin1,
3782 appStatus[i].pin2);
3783 }
3784 closeResponse;
3785}
3786
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003787static void responseSimStatusV5(Parcel &p, void *response) {
3788 RIL_CardStatus_v5 *p_cur = ((RIL_CardStatus_v5 *) response);
3789
3790 p.writeInt32(p_cur->card_state);
3791 p.writeInt32(p_cur->universal_pin_state);
3792 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3793 p.writeInt32(p_cur->cdma_subscription_app_index);
3794
3795 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
3796}
3797
3798static void responseSimStatusV6(Parcel &p, void *response) {
3799 RIL_CardStatus_v6 *p_cur = ((RIL_CardStatus_v6 *) response);
3800
3801 p.writeInt32(p_cur->card_state);
3802 p.writeInt32(p_cur->universal_pin_state);
3803 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3804 p.writeInt32(p_cur->cdma_subscription_app_index);
3805 p.writeInt32(p_cur->ims_subscription_app_index);
3806
3807 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
3808}
3809
Wink Savillef4c4d362009-04-02 01:37:03 -07003810static int responseSimStatus(Parcel &p, void *response, size_t responselen) {
3811 int i;
3812
3813 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003814 RLOGE("invalid response: NULL");
Wink Savillef4c4d362009-04-02 01:37:03 -07003815 return RIL_ERRNO_INVALID_RESPONSE;
3816 }
3817
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003818 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
3819 if (responselen == sizeof (RIL_CardStatus_v6)) {
3820 responseSimStatusV6(p, response);
3821 } else if (responselen == sizeof (RIL_CardStatus_v5)) {
3822 responseSimStatusV5(p, response);
3823 } else {
3824 RLOGE("responseSimStatus: A RilCardStatus_v6 or _v5 expected\n");
3825 return RIL_ERRNO_INVALID_RESPONSE;
3826 }
Sanket Padawef53c5fa2016-01-27 10:00:38 -08003827 } else { // RIL version >= 13
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003828 if (responselen % sizeof(RIL_CardStatus_v6) != 0) {
3829 RLOGE("Data structure expected is RIL_CardStatus_v6");
3830 if (!isDebuggable()) {
3831 return RIL_ERRNO_INVALID_RESPONSE;
3832 } else {
3833 assert(0);
3834 }
3835 }
3836 responseSimStatusV6(p, response);
Wink Savillef4c4d362009-04-02 01:37:03 -07003837 }
Wink Savillef4c4d362009-04-02 01:37:03 -07003838
3839 return 0;
Wink Saville3d54e742009-05-18 18:00:44 -07003840}
Wink Savillef4c4d362009-04-02 01:37:03 -07003841
Wink Savillea592eeb2009-05-22 13:26:36 -07003842static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3843 int num = responselen / sizeof(RIL_GSM_BroadcastSmsConfigInfo *);
Wink Savillef4c4d362009-04-02 01:37:03 -07003844 p.writeInt32(num);
3845
Wink Savillef4c4d362009-04-02 01:37:03 -07003846 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07003847 RIL_GSM_BroadcastSmsConfigInfo **p_cur =
3848 (RIL_GSM_BroadcastSmsConfigInfo **) response;
3849 for (int i = 0; i < num; i++) {
3850 p.writeInt32(p_cur[i]->fromServiceId);
3851 p.writeInt32(p_cur[i]->toServiceId);
3852 p.writeInt32(p_cur[i]->fromCodeScheme);
3853 p.writeInt32(p_cur[i]->toCodeScheme);
3854 p.writeInt32(p_cur[i]->selected);
3855
3856 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId=%d, \
3857 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]",
3858 printBuf, i, p_cur[i]->fromServiceId, p_cur[i]->toServiceId,
3859 p_cur[i]->fromCodeScheme, p_cur[i]->toCodeScheme,
3860 p_cur[i]->selected);
3861 }
Wink Savillef4c4d362009-04-02 01:37:03 -07003862 closeResponse;
3863
3864 return 0;
3865}
3866
Wink Savillea592eeb2009-05-22 13:26:36 -07003867static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3868 RIL_CDMA_BroadcastSmsConfigInfo **p_cur =
3869 (RIL_CDMA_BroadcastSmsConfigInfo **) response;
Wink Savillef4c4d362009-04-02 01:37:03 -07003870
Wink Savillea592eeb2009-05-22 13:26:36 -07003871 int num = responselen / sizeof (RIL_CDMA_BroadcastSmsConfigInfo *);
3872 p.writeInt32(num);
Wink Savillef4c4d362009-04-02 01:37:03 -07003873
3874 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07003875 for (int i = 0 ; i < num ; i++ ) {
3876 p.writeInt32(p_cur[i]->service_category);
3877 p.writeInt32(p_cur[i]->language);
3878 p.writeInt32(p_cur[i]->selected);
Wink Savillef4c4d362009-04-02 01:37:03 -07003879
Wink Savillea592eeb2009-05-22 13:26:36 -07003880 appendPrintBuf("%s [%d: srvice_category=%d, language =%d, \
3881 selected =%d], ",
3882 printBuf, i, p_cur[i]->service_category, p_cur[i]->language,
3883 p_cur[i]->selected);
Wink Savillef5903df2009-04-24 11:54:14 -07003884 }
Wink Savillea592eeb2009-05-22 13:26:36 -07003885 closeResponse;
Wink Savillef5903df2009-04-24 11:54:14 -07003886
Wink Savillef4c4d362009-04-02 01:37:03 -07003887 return 0;
3888}
3889
3890static int responseCdmaSms(Parcel &p, void *response, size_t responselen) {
3891 int num;
3892 int digitCount;
3893 int digitLimit;
3894 uint8_t uct;
3895 void* dest;
3896
Wink Saville8eb2a122012-11-19 16:05:13 -08003897 RLOGD("Inside responseCdmaSms");
Wink Savillef5903df2009-04-24 11:54:14 -07003898
Wink Savillef4c4d362009-04-02 01:37:03 -07003899 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003900 RLOGE("invalid response: NULL");
Wink Savillef4c4d362009-04-02 01:37:03 -07003901 return RIL_ERRNO_INVALID_RESPONSE;
3902 }
3903
Wink Savillef5903df2009-04-24 11:54:14 -07003904 if (responselen != sizeof(RIL_CDMA_SMS_Message)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003905 RLOGE("invalid response length was %d expected %d",
Wink Savillef5903df2009-04-24 11:54:14 -07003906 (int)responselen, (int)sizeof(RIL_CDMA_SMS_Message));
Wink Savillef4c4d362009-04-02 01:37:03 -07003907 return RIL_ERRNO_INVALID_RESPONSE;
3908 }
3909
3910 RIL_CDMA_SMS_Message *p_cur = (RIL_CDMA_SMS_Message *) response;
3911 p.writeInt32(p_cur->uTeleserviceID);
3912 p.write(&(p_cur->bIsServicePresent),sizeof(uct));
3913 p.writeInt32(p_cur->uServicecategory);
3914 p.writeInt32(p_cur->sAddress.digit_mode);
3915 p.writeInt32(p_cur->sAddress.number_mode);
3916 p.writeInt32(p_cur->sAddress.number_type);
3917 p.writeInt32(p_cur->sAddress.number_plan);
3918 p.write(&(p_cur->sAddress.number_of_digits), sizeof(uct));
3919 digitLimit= MIN((p_cur->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
3920 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3921 p.write(&(p_cur->sAddress.digits[digitCount]),sizeof(uct));
3922 }
3923
3924 p.writeInt32(p_cur->sSubAddress.subaddressType);
3925 p.write(&(p_cur->sSubAddress.odd),sizeof(uct));
3926 p.write(&(p_cur->sSubAddress.number_of_digits),sizeof(uct));
3927 digitLimit= MIN((p_cur->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
3928 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3929 p.write(&(p_cur->sSubAddress.digits[digitCount]),sizeof(uct));
3930 }
3931
3932 digitLimit= MIN((p_cur->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
3933 p.writeInt32(p_cur->uBearerDataLen);
3934 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3935 p.write(&(p_cur->aBearerData[digitCount]), sizeof(uct));
3936 }
3937
3938 startResponse;
3939 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
Wink Saville1b5fd232009-04-22 14:50:00 -07003940 sAddress.digit_mode=%d, sAddress.number_mode=%d, sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07003941 printBuf, p_cur->uTeleserviceID,p_cur->bIsServicePresent,p_cur->uServicecategory,
3942 p_cur->sAddress.digit_mode, p_cur->sAddress.number_mode,p_cur->sAddress.number_type);
3943 closeResponse;
3944
3945 return 0;
3946}
3947
Wink Savillec29360a2014-07-13 05:17:28 -07003948static int responseDcRtInfo(Parcel &p, void *response, size_t responselen)
3949{
3950 int num = responselen / sizeof(RIL_DcRtInfo);
3951 if ((responselen % sizeof(RIL_DcRtInfo) != 0) || (num != 1)) {
Amit Mahajan52500162014-07-29 17:36:48 -07003952 RLOGE("responseDcRtInfo: invalid response length %d expected multiple of %d",
Wink Savillec29360a2014-07-13 05:17:28 -07003953 (int)responselen, (int)sizeof(RIL_DcRtInfo));
3954 return RIL_ERRNO_INVALID_RESPONSE;
3955 }
3956
3957 startResponse;
3958 RIL_DcRtInfo *pDcRtInfo = (RIL_DcRtInfo *)response;
3959 p.writeInt64(pDcRtInfo->time);
3960 p.writeInt32(pDcRtInfo->powerState);
3961 appendPrintBuf("%s[time=%d,powerState=%d]", printBuf,
3962 pDcRtInfo->time,
3963 pDcRtInfo->powerState);
3964 closeResponse;
3965
3966 return 0;
3967}
3968
fengluf7408292015-04-14 14:53:55 -07003969static int responseLceStatus(Parcel &p, void *response, size_t responselen) {
3970 if (response == NULL || responselen != sizeof(RIL_LceStatusInfo)) {
3971 if (response == NULL) {
3972 RLOGE("invalid response: NULL");
3973 }
3974 else {
3975 RLOGE("responseLceStatus: invalid response length %d expecting len: d%",
3976 sizeof(RIL_LceStatusInfo), responselen);
3977 }
3978 return RIL_ERRNO_INVALID_RESPONSE;
3979 }
3980
3981 RIL_LceStatusInfo *p_cur = (RIL_LceStatusInfo *)response;
3982 p.write((void *)p_cur, 1); // p_cur->lce_status takes one byte.
3983 p.writeInt32(p_cur->actual_interval_ms);
3984
3985 startResponse;
3986 appendPrintBuf("LCE Status: %d, actual_interval_ms: %d",
3987 p_cur->lce_status, p_cur->actual_interval_ms);
3988 closeResponse;
3989
3990 return 0;
3991}
3992
3993static int responseLceData(Parcel &p, void *response, size_t responselen) {
3994 if (response == NULL || responselen != sizeof(RIL_LceDataInfo)) {
3995 if (response == NULL) {
3996 RLOGE("invalid response: NULL");
3997 }
3998 else {
3999 RLOGE("responseLceData: invalid response length %d expecting len: d%",
4000 sizeof(RIL_LceDataInfo), responselen);
4001 }
4002 return RIL_ERRNO_INVALID_RESPONSE;
4003 }
4004
4005 RIL_LceDataInfo *p_cur = (RIL_LceDataInfo *)response;
4006 p.writeInt32(p_cur->last_hop_capacity_kbps);
4007
4008 /* p_cur->confidence_level and p_cur->lce_suspended take 1 byte each.*/
4009 p.write((void *)&(p_cur->confidence_level), 1);
4010 p.write((void *)&(p_cur->lce_suspended), 1);
4011
4012 startResponse;
4013 appendPrintBuf("LCE info received: capacity %d confidence level %d
4014 and suspended %d",
4015 p_cur->last_hop_capacity_kbps, p_cur->confidence_level,
4016 p_cur->lce_suspended);
4017 closeResponse;
4018
4019 return 0;
4020}
4021
Prerepa Viswanadham73157492015-05-28 00:37:32 -07004022static int responseActivityData(Parcel &p, void *response, size_t responselen) {
4023 if (response == NULL || responselen != sizeof(RIL_ActivityStatsInfo)) {
4024 if (response == NULL) {
4025 RLOGE("invalid response: NULL");
4026 }
4027 else {
4028 RLOGE("responseActivityData: invalid response length %d expecting len: d%",
4029 sizeof(RIL_ActivityStatsInfo), responselen);
4030 }
4031 return RIL_ERRNO_INVALID_RESPONSE;
4032 }
4033
4034 RIL_ActivityStatsInfo *p_cur = (RIL_ActivityStatsInfo *)response;
4035 p.writeInt32(p_cur->sleep_mode_time_ms);
4036 p.writeInt32(p_cur->idle_mode_time_ms);
4037 for(int i = 0; i < RIL_NUM_TX_POWER_LEVELS; i++) {
4038 p.writeInt32(p_cur->tx_mode_time_ms[i]);
4039 }
4040 p.writeInt32(p_cur->rx_mode_time_ms);
4041
4042 startResponse;
4043 appendPrintBuf("Modem activity info received: sleep_mode_time_ms %d idle_mode_time_ms %d
4044 tx_mode_time_ms %d %d %d %d %d and rx_mode_time_ms %d",
4045 p_cur->sleep_mode_time_ms, p_cur->idle_mode_time_ms, p_cur->tx_mode_time_ms[0],
4046 p_cur->tx_mode_time_ms[1], p_cur->tx_mode_time_ms[2], p_cur->tx_mode_time_ms[3],
4047 p_cur->tx_mode_time_ms[4], p_cur->rx_mode_time_ms);
4048 closeResponse;
4049
4050 return 0;
4051}
4052
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004053/**
4054 * A write on the wakeup fd is done just to pop us out of select()
4055 * We empty the buffer here and then ril_event will reset the timers on the
4056 * way back down
4057 */
Wink Savillef4c4d362009-04-02 01:37:03 -07004058static void processWakeupCallback(int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004059 char buff[16];
4060 int ret;
4061
Wink Saville8eb2a122012-11-19 16:05:13 -08004062 RLOGV("processWakeupCallback");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004063
4064 /* empty our wakeup socket out */
4065 do {
4066 ret = read(s_fdWakeupRead, &buff, sizeof(buff));
Wink Saville7f856802009-06-09 10:23:37 -07004067 } while (ret > 0 || (ret < 0 && errno == EINTR));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004068}
4069
Etan Cohend3652192014-06-20 08:28:44 -07004070static void onCommandsSocketClosed(RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004071 int ret;
4072 RequestInfo *p_cur;
Etan Cohend3652192014-06-20 08:28:44 -07004073 /* Hook for current context
4074 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
4075 pthread_mutex_t * pendingRequestsMutexHook = &s_pendingRequestsMutex;
4076 /* pendingRequestsHook refer to &s_pendingRequests */
4077 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004078
Etan Cohend3652192014-06-20 08:28:44 -07004079#if (SIM_COUNT >= 2)
4080 if (socket_id == RIL_SOCKET_2) {
4081 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
4082 pendingRequestsHook = &s_pendingRequests_socket2;
4083 }
4084#if (SIM_COUNT >= 3)
4085 else if (socket_id == RIL_SOCKET_3) {
4086 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
4087 pendingRequestsHook = &s_pendingRequests_socket3;
4088 }
4089#endif
4090#if (SIM_COUNT >= 4)
4091 else if (socket_id == RIL_SOCKET_4) {
4092 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
4093 pendingRequestsHook = &s_pendingRequests_socket4;
4094 }
4095#endif
4096#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004097 /* mark pending requests as "cancelled" so we dont report responses */
Etan Cohend3652192014-06-20 08:28:44 -07004098 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004099 assert (ret == 0);
4100
Etan Cohend3652192014-06-20 08:28:44 -07004101 p_cur = *pendingRequestsHook;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004102
Etan Cohend3652192014-06-20 08:28:44 -07004103 for (p_cur = *pendingRequestsHook
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004104 ; p_cur != NULL
4105 ; p_cur = p_cur->p_next
4106 ) {
4107 p_cur->cancelled = 1;
4108 }
4109
Etan Cohend3652192014-06-20 08:28:44 -07004110 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004111 assert (ret == 0);
4112}
4113
Wink Savillef4c4d362009-04-02 01:37:03 -07004114static void processCommandsCallback(int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004115 RecordStream *p_rs;
4116 void *p_record;
4117 size_t recordlen;
4118 int ret;
Etan Cohend3652192014-06-20 08:28:44 -07004119 SocketListenParam *p_info = (SocketListenParam *)param;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004120
Etan Cohend3652192014-06-20 08:28:44 -07004121 assert(fd == p_info->fdCommand);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004122
Etan Cohend3652192014-06-20 08:28:44 -07004123 p_rs = p_info->p_rs;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004124
4125 for (;;) {
4126 /* loop until EAGAIN/EINTR, end of stream, or other error */
4127 ret = record_stream_get_next(p_rs, &p_record, &recordlen);
4128
4129 if (ret == 0 && p_record == NULL) {
4130 /* end-of-stream */
4131 break;
4132 } else if (ret < 0) {
4133 break;
4134 } else if (ret == 0) { /* && p_record != NULL */
Etan Cohend3652192014-06-20 08:28:44 -07004135 processCommandBuffer(p_record, recordlen, p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004136 }
4137 }
4138
4139 if (ret == 0 || !(errno == EAGAIN || errno == EINTR)) {
4140 /* fatal error or end-of-stream */
4141 if (ret != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004142 RLOGE("error on reading command socket errno:%d\n", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004143 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08004144 RLOGW("EOS. Closing command socket.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004145 }
Wink Saville7f856802009-06-09 10:23:37 -07004146
Etan Cohend3652192014-06-20 08:28:44 -07004147 close(fd);
4148 p_info->fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004149
Etan Cohend3652192014-06-20 08:28:44 -07004150 ril_event_del(p_info->commands_event);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004151
4152 record_stream_free(p_rs);
4153
4154 /* start listening for new connections again */
4155 rilEventAddWakeup(&s_listen_event);
4156
Etan Cohend3652192014-06-20 08:28:44 -07004157 onCommandsSocketClosed(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004158 }
4159}
4160
4161
Etan Cohend3652192014-06-20 08:28:44 -07004162static void onNewCommandConnect(RIL_SOCKET_ID socket_id) {
Wink Saville5b9df332011-04-06 16:24:21 -07004163 // Inform we are connected and the ril version
Jake Hambya9c18d12011-04-12 23:32:08 -07004164 int rilVer = s_callbacks.version;
Etan Cohend3652192014-06-20 08:28:44 -07004165 RIL_UNSOL_RESPONSE(RIL_UNSOL_RIL_CONNECTED,
4166 &rilVer, sizeof(rilVer), socket_id);
Wink Saville5b9df332011-04-06 16:24:21 -07004167
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004168 // implicit radio state changed
Etan Cohend3652192014-06-20 08:28:44 -07004169 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
4170 NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004171
4172 // Send last NITZ time data, in case it was missed
4173 if (s_lastNITZTimeData != NULL) {
Etan Cohend3652192014-06-20 08:28:44 -07004174 sendResponseRaw(s_lastNITZTimeData, s_lastNITZTimeDataSize, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004175
4176 free(s_lastNITZTimeData);
4177 s_lastNITZTimeData = NULL;
4178 }
4179
4180 // Get version string
4181 if (s_callbacks.getVersion != NULL) {
4182 const char *version;
4183 version = s_callbacks.getVersion();
Wink Saville8eb2a122012-11-19 16:05:13 -08004184 RLOGI("RIL Daemon version: %s\n", version);
Wink Saville7f856802009-06-09 10:23:37 -07004185
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004186 property_set(PROPERTY_RIL_IMPL, version);
4187 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08004188 RLOGI("RIL Daemon version: unavailable\n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004189 property_set(PROPERTY_RIL_IMPL, "unavailable");
4190 }
4191
4192}
4193
Wink Savillef4c4d362009-04-02 01:37:03 -07004194static void listenCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004195 int ret;
4196 int err;
4197 int is_phone_socket;
Etan Cohend3652192014-06-20 08:28:44 -07004198 int fdCommand = -1;
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004199 char* processName;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004200 RecordStream *p_rs;
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004201 MySocketListenParam* listenParam;
4202 RilSocket *sapSocket = NULL;
4203 socketClient *sClient = NULL;
4204
Etan Cohend3652192014-06-20 08:28:44 -07004205 SocketListenParam *p_info = (SocketListenParam *)param;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004206
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004207 if(RIL_SAP_SOCKET == p_info->type) {
4208 listenParam = (MySocketListenParam *)param;
4209 sapSocket = listenParam->socket;
4210 }
4211
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004212 struct sockaddr_un peeraddr;
4213 socklen_t socklen = sizeof (peeraddr);
4214
4215 struct ucred creds;
4216 socklen_t szCreds = sizeof(creds);
4217
4218 struct passwd *pwd = NULL;
4219
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004220 if(NULL == sapSocket) {
4221 assert (*p_info->fdCommand < 0);
4222 assert (fd == *p_info->fdListen);
4223 processName = PHONE_PROCESS;
4224 } else {
4225 assert (sapSocket->commandFd < 0);
4226 assert (fd == sapSocket->listenFd);
4227 processName = BLUETOOTH_PROCESS;
4228 }
4229
Wink Saville7f856802009-06-09 10:23:37 -07004230
Etan Cohend3652192014-06-20 08:28:44 -07004231 fdCommand = accept(fd, (sockaddr *) &peeraddr, &socklen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004232
Etan Cohend3652192014-06-20 08:28:44 -07004233 if (fdCommand < 0 ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004234 RLOGE("Error on accept() errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004235 /* start listening for new connections again */
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004236 if(NULL == sapSocket) {
4237 rilEventAddWakeup(p_info->listen_event);
4238 } else {
4239 rilEventAddWakeup(sapSocket->getListenEvent());
4240 }
Etan Cohend3652192014-06-20 08:28:44 -07004241 return;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004242 }
4243
4244 /* check the credential of the other side and only accept socket from
4245 * phone process
Wink Saville7f856802009-06-09 10:23:37 -07004246 */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004247 errno = 0;
4248 is_phone_socket = 0;
Wink Savillef4c4d362009-04-02 01:37:03 -07004249
Etan Cohend3652192014-06-20 08:28:44 -07004250 err = getsockopt(fdCommand, SOL_SOCKET, SO_PEERCRED, &creds, &szCreds);
Wink Savillef4c4d362009-04-02 01:37:03 -07004251
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004252 if (err == 0 && szCreds > 0) {
Wink Savillef4c4d362009-04-02 01:37:03 -07004253 errno = 0;
4254 pwd = getpwuid(creds.uid);
4255 if (pwd != NULL) {
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004256 if (strcmp(pwd->pw_name, processName) == 0) {
Wink Savillef4c4d362009-04-02 01:37:03 -07004257 is_phone_socket = 1;
4258 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08004259 RLOGE("RILD can't accept socket from process %s", pwd->pw_name);
Wink Savillef4c4d362009-04-02 01:37:03 -07004260 }
4261 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08004262 RLOGE("Error on getpwuid() errno: %d", errno);
Wink Savillef4c4d362009-04-02 01:37:03 -07004263 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004264 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08004265 RLOGD("Error on getsockopt() errno: %d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004266 }
4267
Etan Cohend3652192014-06-20 08:28:44 -07004268 if (!is_phone_socket) {
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004269 RLOGE("RILD must accept socket from %s", processName);
Wink Saville7f856802009-06-09 10:23:37 -07004270
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004271 close(fdCommand);
4272 fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004273
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004274 if(NULL == sapSocket) {
4275 onCommandsSocketClosed(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004276
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004277 /* start listening for new connections again */
4278 rilEventAddWakeup(p_info->listen_event);
4279 } else {
4280 sapSocket->onCommandsSocketClosed();
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004281
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004282 /* start listening for new connections again */
4283 rilEventAddWakeup(sapSocket->getListenEvent());
4284 }
4285
4286 return;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004287 }
4288
Etan Cohend3652192014-06-20 08:28:44 -07004289 ret = fcntl(fdCommand, F_SETFL, O_NONBLOCK);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004290
4291 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004292 RLOGE ("Error setting O_NONBLOCK errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004293 }
4294
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004295 if(NULL == sapSocket) {
4296 RLOGI("libril: new connection to %s", rilSocketIdToString(p_info->socket_id));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004297
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004298 p_info->fdCommand = fdCommand;
4299 p_rs = record_stream_new(p_info->fdCommand, MAX_COMMAND_BYTES);
4300 p_info->p_rs = p_rs;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004301
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004302 ril_event_set (p_info->commands_event, p_info->fdCommand, 1,
Etan Cohend3652192014-06-20 08:28:44 -07004303 p_info->processCommandsCallback, p_info);
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004304 rilEventAddWakeup (p_info->commands_event);
Etan Cohend3652192014-06-20 08:28:44 -07004305
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004306 onNewCommandConnect(p_info->socket_id);
4307 } else {
4308 RLOGI("libril: new connection");
Etan Cohend3652192014-06-20 08:28:44 -07004309
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004310 sapSocket->setCommandFd(fdCommand);
4311 p_rs = record_stream_new(sapSocket->getCommandFd(), MAX_COMMAND_BYTES);
4312 sClient = new socketClient(sapSocket,p_rs);
4313 ril_event_set (sapSocket->getCallbackEvent(), sapSocket->getCommandFd(), 1,
4314 sapSocket->getCommandCb(), sClient);
4315
4316 rilEventAddWakeup(sapSocket->getCallbackEvent());
4317 sapSocket->onNewCommandConnect();
4318 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004319}
4320
4321static void freeDebugCallbackArgs(int number, char **args) {
4322 for (int i = 0; i < number; i++) {
4323 if (args[i] != NULL) {
4324 free(args[i]);
4325 }
4326 }
4327 free(args);
4328}
4329
Wink Savillef4c4d362009-04-02 01:37:03 -07004330static void debugCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004331 int acceptFD, option;
4332 struct sockaddr_un peeraddr;
4333 socklen_t socklen = sizeof (peeraddr);
4334 int data;
4335 unsigned int qxdm_data[6];
4336 const char *deactData[1] = {"1"};
4337 char *actData[1];
4338 RIL_Dial dialData;
4339 int hangupData[1] = {1};
4340 int number;
4341 char **args;
Etan Cohend3652192014-06-20 08:28:44 -07004342 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
4343 int sim_id = 0;
4344
4345 RLOGI("debugCallback for socket %s", rilSocketIdToString(socket_id));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004346
4347 acceptFD = accept (fd, (sockaddr *) &peeraddr, &socklen);
4348
4349 if (acceptFD < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004350 RLOGE ("error accepting on debug port: %d\n", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004351 return;
4352 }
4353
4354 if (recv(acceptFD, &number, sizeof(int), 0) != sizeof(int)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004355 RLOGE ("error reading on socket: number of Args: \n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004356 return;
4357 }
4358 args = (char **) malloc(sizeof(char*) * number);
4359
4360 for (int i = 0; i < number; i++) {
4361 int len;
4362 if (recv(acceptFD, &len, sizeof(int), 0) != sizeof(int)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004363 RLOGE ("error reading on socket: Len of Args: \n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004364 freeDebugCallbackArgs(i, args);
4365 return;
4366 }
4367 // +1 for null-term
4368 args[i] = (char *) malloc((sizeof(char) * len) + 1);
Wink Saville7f856802009-06-09 10:23:37 -07004369 if (recv(acceptFD, args[i], sizeof(char) * len, 0)
Wink Saville1b5fd232009-04-22 14:50:00 -07004370 != (int)sizeof(char) * len) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004371 RLOGE ("error reading on socket: Args[%d] \n", i);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004372 freeDebugCallbackArgs(i, args);
4373 return;
4374 }
4375 char * buf = args[i];
4376 buf[len] = 0;
Etan Cohend3652192014-06-20 08:28:44 -07004377 if ((i+1) == number) {
4378 /* The last argument should be sim id 0(SIM1)~3(SIM4) */
4379 sim_id = atoi(args[i]);
4380 switch (sim_id) {
4381 case 0:
4382 socket_id = RIL_SOCKET_1;
4383 break;
4384 #if (SIM_COUNT >= 2)
4385 case 1:
4386 socket_id = RIL_SOCKET_2;
4387 break;
4388 #endif
4389 #if (SIM_COUNT >= 3)
4390 case 2:
4391 socket_id = RIL_SOCKET_3;
4392 break;
4393 #endif
4394 #if (SIM_COUNT >= 4)
4395 case 3:
4396 socket_id = RIL_SOCKET_4;
4397 break;
4398 #endif
4399 default:
4400 socket_id = RIL_SOCKET_1;
4401 break;
4402 }
4403 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004404 }
4405
4406 switch (atoi(args[0])) {
4407 case 0:
Wink Saville8eb2a122012-11-19 16:05:13 -08004408 RLOGI ("Connection on debug port: issuing reset.");
Etan Cohend3652192014-06-20 08:28:44 -07004409 issueLocalRequest(RIL_REQUEST_RESET_RADIO, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004410 break;
4411 case 1:
Wink Saville8eb2a122012-11-19 16:05:13 -08004412 RLOGI ("Connection on debug port: issuing radio power off.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004413 data = 0;
Etan Cohend3652192014-06-20 08:28:44 -07004414 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004415 // Close the socket
Etan Cohend3652192014-06-20 08:28:44 -07004416 if (socket_id == RIL_SOCKET_1 && s_ril_param_socket.fdCommand > 0) {
4417 close(s_ril_param_socket.fdCommand);
4418 s_ril_param_socket.fdCommand = -1;
4419 }
4420 #if (SIM_COUNT == 2)
4421 else if (socket_id == RIL_SOCKET_2 && s_ril_param_socket2.fdCommand > 0) {
4422 close(s_ril_param_socket2.fdCommand);
4423 s_ril_param_socket2.fdCommand = -1;
4424 }
4425 #endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004426 break;
4427 case 2:
Wink Saville8eb2a122012-11-19 16:05:13 -08004428 RLOGI ("Debug port: issuing unsolicited voice network change.");
Etan Cohend3652192014-06-20 08:28:44 -07004429 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004430 break;
4431 case 3:
Wink Saville8eb2a122012-11-19 16:05:13 -08004432 RLOGI ("Debug port: QXDM log enable.");
Xia Wangd855ef42010-07-27 17:26:55 -07004433 qxdm_data[0] = 65536; // head.func_tag
4434 qxdm_data[1] = 16; // head.len
4435 qxdm_data[2] = 1; // mode: 1 for 'start logging'
4436 qxdm_data[3] = 32; // log_file_size: 32megabytes
4437 qxdm_data[4] = 0; // log_mask
4438 qxdm_data[5] = 8; // log_max_fileindex
Wink Saville7f856802009-06-09 10:23:37 -07004439 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Etan Cohend3652192014-06-20 08:28:44 -07004440 6 * sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004441 break;
4442 case 4:
Wink Saville8eb2a122012-11-19 16:05:13 -08004443 RLOGI ("Debug port: QXDM log disable.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004444 qxdm_data[0] = 65536;
4445 qxdm_data[1] = 16;
Xia Wangd855ef42010-07-27 17:26:55 -07004446 qxdm_data[2] = 0; // mode: 0 for 'stop logging'
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004447 qxdm_data[3] = 32;
4448 qxdm_data[4] = 0;
Xia Wangd855ef42010-07-27 17:26:55 -07004449 qxdm_data[5] = 8;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004450 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Etan Cohend3652192014-06-20 08:28:44 -07004451 6 * sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004452 break;
4453 case 5:
Wink Saville8eb2a122012-11-19 16:05:13 -08004454 RLOGI("Debug port: Radio On");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004455 data = 1;
Etan Cohend3652192014-06-20 08:28:44 -07004456 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004457 sleep(2);
4458 // Set network selection automatic.
Etan Cohend3652192014-06-20 08:28:44 -07004459 issueLocalRequest(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004460 break;
4461 case 6:
Wink Saville8eb2a122012-11-19 16:05:13 -08004462 RLOGI("Debug port: Setup Data Call, Apn :%s\n", args[1]);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004463 actData[0] = args[1];
Wink Saville7f856802009-06-09 10:23:37 -07004464 issueLocalRequest(RIL_REQUEST_SETUP_DATA_CALL, &actData,
Etan Cohend3652192014-06-20 08:28:44 -07004465 sizeof(actData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004466 break;
4467 case 7:
Wink Saville8eb2a122012-11-19 16:05:13 -08004468 RLOGI("Debug port: Deactivate Data Call");
Wink Saville7f856802009-06-09 10:23:37 -07004469 issueLocalRequest(RIL_REQUEST_DEACTIVATE_DATA_CALL, &deactData,
Etan Cohend3652192014-06-20 08:28:44 -07004470 sizeof(deactData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004471 break;
4472 case 8:
Wink Saville8eb2a122012-11-19 16:05:13 -08004473 RLOGI("Debug port: Dial Call");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004474 dialData.clir = 0;
4475 dialData.address = args[1];
Etan Cohend3652192014-06-20 08:28:44 -07004476 issueLocalRequest(RIL_REQUEST_DIAL, &dialData, sizeof(dialData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004477 break;
4478 case 9:
Wink Saville8eb2a122012-11-19 16:05:13 -08004479 RLOGI("Debug port: Answer Call");
Etan Cohend3652192014-06-20 08:28:44 -07004480 issueLocalRequest(RIL_REQUEST_ANSWER, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004481 break;
4482 case 10:
Wink Saville8eb2a122012-11-19 16:05:13 -08004483 RLOGI("Debug port: End Call");
Wink Saville7f856802009-06-09 10:23:37 -07004484 issueLocalRequest(RIL_REQUEST_HANGUP, &hangupData,
Etan Cohend3652192014-06-20 08:28:44 -07004485 sizeof(hangupData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004486 break;
4487 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004488 RLOGE ("Invalid request");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004489 break;
4490 }
4491 freeDebugCallbackArgs(number, args);
4492 close(acceptFD);
4493}
4494
4495
Wink Savillef4c4d362009-04-02 01:37:03 -07004496static void userTimerCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004497 UserCallbackInfo *p_info;
4498
4499 p_info = (UserCallbackInfo *)param;
4500
4501 p_info->p_callback(p_info->userParam);
4502
4503
4504 // FIXME generalize this...there should be a cancel mechanism
4505 if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) {
4506 s_last_wake_timeout_info = NULL;
4507 }
4508
4509 free(p_info);
4510}
4511
4512
4513static void *
Wink Savillef4c4d362009-04-02 01:37:03 -07004514eventLoop(void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004515 int ret;
4516 int filedes[2];
4517
4518 ril_event_init();
4519
4520 pthread_mutex_lock(&s_startupMutex);
4521
4522 s_started = 1;
4523 pthread_cond_broadcast(&s_startupCond);
4524
4525 pthread_mutex_unlock(&s_startupMutex);
4526
4527 ret = pipe(filedes);
4528
4529 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004530 RLOGE("Error in pipe() errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004531 return NULL;
4532 }
4533
4534 s_fdWakeupRead = filedes[0];
4535 s_fdWakeupWrite = filedes[1];
4536
4537 fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK);
4538
4539 ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,
4540 processWakeupCallback, NULL);
4541
4542 rilEventAddWakeup (&s_wakeupfd_event);
4543
4544 // Only returns on error
4545 ril_event_loop();
Wink Saville8eb2a122012-11-19 16:05:13 -08004546 RLOGE ("error in event_loop_base errno:%d", errno);
Kazuhiro Ondo5cdc1352011-10-14 17:50:58 -05004547 // kill self to restart on error
4548 kill(0, SIGKILL);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004549
4550 return NULL;
4551}
4552
Wink Saville7f856802009-06-09 10:23:37 -07004553extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07004554RIL_startEventLoop(void) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004555 /* spin up eventLoop thread and wait for it to get started */
4556 s_started = 0;
4557 pthread_mutex_lock(&s_startupMutex);
4558
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004559 pthread_attr_t attr;
4560 pthread_attr_init(&attr);
Wink Saville7f856802009-06-09 10:23:37 -07004561 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004562
Elliott Hughesfd81e712014-01-06 12:46:02 -08004563 int result = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
4564 if (result != 0) {
4565 RLOGE("Failed to create dispatch thread: %s", strerror(result));
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004566 goto done;
4567 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004568
4569 while (s_started == 0) {
4570 pthread_cond_wait(&s_startupCond, &s_startupMutex);
4571 }
4572
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004573done:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004574 pthread_mutex_unlock(&s_startupMutex);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004575}
4576
4577// Used for testing purpose only.
4578extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) {
4579 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4580}
4581
Etan Cohend3652192014-06-20 08:28:44 -07004582static void startListen(RIL_SOCKET_ID socket_id, SocketListenParam* socket_listen_p) {
4583 int fdListen = -1;
4584 int ret;
4585 char socket_name[10];
4586
4587 memset(socket_name, 0, sizeof(char)*10);
4588
4589 switch(socket_id) {
4590 case RIL_SOCKET_1:
4591 strncpy(socket_name, RIL_getRilSocketName(), 9);
4592 break;
4593 #if (SIM_COUNT >= 2)
4594 case RIL_SOCKET_2:
4595 strncpy(socket_name, SOCKET2_NAME_RIL, 9);
4596 break;
4597 #endif
4598 #if (SIM_COUNT >= 3)
4599 case RIL_SOCKET_3:
4600 strncpy(socket_name, SOCKET3_NAME_RIL, 9);
4601 break;
4602 #endif
4603 #if (SIM_COUNT >= 4)
4604 case RIL_SOCKET_4:
4605 strncpy(socket_name, SOCKET4_NAME_RIL, 9);
4606 break;
4607 #endif
4608 default:
4609 RLOGE("Socket id is wrong!!");
4610 return;
4611 }
4612
4613 RLOGI("Start to listen %s", rilSocketIdToString(socket_id));
4614
4615 fdListen = android_get_control_socket(socket_name);
4616 if (fdListen < 0) {
4617 RLOGE("Failed to get socket %s", socket_name);
4618 exit(-1);
4619 }
4620
4621 ret = listen(fdListen, 4);
4622
4623 if (ret < 0) {
4624 RLOGE("Failed to listen on control socket '%d': %s",
4625 fdListen, strerror(errno));
4626 exit(-1);
4627 }
4628 socket_listen_p->fdListen = fdListen;
4629
4630 /* note: non-persistent so we can accept only one connection at a time */
4631 ril_event_set (socket_listen_p->listen_event, fdListen, false,
4632 listenCallback, socket_listen_p);
4633
4634 rilEventAddWakeup (socket_listen_p->listen_event);
4635}
4636
Wink Saville7f856802009-06-09 10:23:37 -07004637extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07004638RIL_register (const RIL_RadioFunctions *callbacks) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004639 int ret;
4640 int flags;
4641
Etan Cohend3652192014-06-20 08:28:44 -07004642 RLOGI("SIM_COUNT: %d", SIM_COUNT);
4643
Wink Saville43808972011-01-13 17:39:51 -08004644 if (callbacks == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004645 RLOGE("RIL_register: RIL_RadioFunctions * null");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004646 return;
4647 }
Wink Saville43808972011-01-13 17:39:51 -08004648 if (callbacks->version < RIL_VERSION_MIN) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004649 RLOGE("RIL_register: version %d is to old, min version is %d",
Wink Saville43808972011-01-13 17:39:51 -08004650 callbacks->version, RIL_VERSION_MIN);
4651 return;
Wink Saville3a4840b2010-04-07 13:29:58 -07004652 }
Sanket Padawe88cf6a52016-01-11 12:45:43 -08004653
Wink Saville8eb2a122012-11-19 16:05:13 -08004654 RLOGE("RIL_register: RIL version %d", callbacks->version);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004655
4656 if (s_registerCalled > 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004657 RLOGE("RIL_register has been called more than once. "
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004658 "Subsequent call ignored");
4659 return;
4660 }
4661
4662 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4663
Etan Cohend3652192014-06-20 08:28:44 -07004664 /* Initialize socket1 parameters */
4665 s_ril_param_socket = {
4666 RIL_SOCKET_1, /* socket_id */
4667 -1, /* fdListen */
4668 -1, /* fdCommand */
4669 PHONE_PROCESS, /* processName */
4670 &s_commands_event, /* commands_event */
4671 &s_listen_event, /* listen_event */
4672 processCommandsCallback, /* processCommandsCallback */
4673 NULL /* p_rs */
4674 };
4675
4676#if (SIM_COUNT >= 2)
4677 s_ril_param_socket2 = {
4678 RIL_SOCKET_2, /* socket_id */
4679 -1, /* fdListen */
4680 -1, /* fdCommand */
4681 PHONE_PROCESS, /* processName */
4682 &s_commands_event_socket2, /* commands_event */
4683 &s_listen_event_socket2, /* listen_event */
4684 processCommandsCallback, /* processCommandsCallback */
4685 NULL /* p_rs */
4686 };
4687#endif
4688
4689#if (SIM_COUNT >= 3)
4690 s_ril_param_socket3 = {
4691 RIL_SOCKET_3, /* socket_id */
4692 -1, /* fdListen */
4693 -1, /* fdCommand */
4694 PHONE_PROCESS, /* processName */
4695 &s_commands_event_socket3, /* commands_event */
4696 &s_listen_event_socket3, /* listen_event */
4697 processCommandsCallback, /* processCommandsCallback */
4698 NULL /* p_rs */
4699 };
4700#endif
4701
4702#if (SIM_COUNT >= 4)
4703 s_ril_param_socket4 = {
4704 RIL_SOCKET_4, /* socket_id */
4705 -1, /* fdListen */
4706 -1, /* fdCommand */
4707 PHONE_PROCESS, /* processName */
4708 &s_commands_event_socket4, /* commands_event */
4709 &s_listen_event_socket4, /* listen_event */
4710 processCommandsCallback, /* processCommandsCallback */
4711 NULL /* p_rs */
4712 };
4713#endif
4714
4715
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004716 s_registerCalled = 1;
4717
Etan Cohend3652192014-06-20 08:28:44 -07004718 RLOGI("s_registerCalled flag set, %d", s_started);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004719 // Little self-check
4720
Wink Savillef4c4d362009-04-02 01:37:03 -07004721 for (int i = 0; i < (int)NUM_ELEMS(s_commands); i++) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004722 assert(i == s_commands[i].requestNumber);
4723 }
4724
Wink Savillef4c4d362009-04-02 01:37:03 -07004725 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses); i++) {
Wink Saville7f856802009-06-09 10:23:37 -07004726 assert(i + RIL_UNSOL_RESPONSE_BASE
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004727 == s_unsolResponses[i].requestNumber);
4728 }
4729
4730 // New rild impl calls RIL_startEventLoop() first
4731 // old standalone impl wants it here.
4732
4733 if (s_started == 0) {
4734 RIL_startEventLoop();
4735 }
4736
Etan Cohend3652192014-06-20 08:28:44 -07004737 // start listen socket1
4738 startListen(RIL_SOCKET_1, &s_ril_param_socket);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004739
Etan Cohend3652192014-06-20 08:28:44 -07004740#if (SIM_COUNT >= 2)
4741 // start listen socket2
4742 startListen(RIL_SOCKET_2, &s_ril_param_socket2);
4743#endif /* (SIM_COUNT == 2) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004744
Etan Cohend3652192014-06-20 08:28:44 -07004745#if (SIM_COUNT >= 3)
4746 // start listen socket3
4747 startListen(RIL_SOCKET_3, &s_ril_param_socket3);
4748#endif /* (SIM_COUNT == 3) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004749
Etan Cohend3652192014-06-20 08:28:44 -07004750#if (SIM_COUNT >= 4)
4751 // start listen socket4
4752 startListen(RIL_SOCKET_4, &s_ril_param_socket4);
4753#endif /* (SIM_COUNT == 4) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004754
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004755
4756#if 1
4757 // start debug interface socket
4758
Etan Cohend3652192014-06-20 08:28:44 -07004759 char *inst = NULL;
4760 if (strlen(RIL_getRilSocketName()) >= strlen(SOCKET_NAME_RIL)) {
4761 inst = RIL_getRilSocketName() + strlen(SOCKET_NAME_RIL);
4762 }
4763
4764 char rildebug[MAX_DEBUG_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL_DEBUG;
4765 if (inst != NULL) {
Nick Kralevichc52e45e2015-02-08 07:54:16 -08004766 strlcat(rildebug, inst, MAX_DEBUG_SOCKET_NAME_LENGTH);
Etan Cohend3652192014-06-20 08:28:44 -07004767 }
4768
4769 s_fdDebug = android_get_control_socket(rildebug);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004770 if (s_fdDebug < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07004771 RLOGE("Failed to get socket : %s errno:%d", rildebug, errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004772 exit(-1);
4773 }
4774
4775 ret = listen(s_fdDebug, 4);
4776
4777 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004778 RLOGE("Failed to listen on ril debug socket '%d': %s",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004779 s_fdDebug, strerror(errno));
4780 exit(-1);
4781 }
4782
4783 ril_event_set (&s_debug_event, s_fdDebug, true,
4784 debugCallback, NULL);
4785
4786 rilEventAddWakeup (&s_debug_event);
4787#endif
4788
4789}
4790
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004791extern "C" void
4792RIL_register_socket (RIL_RadioFunctions *(*Init)(const struct RIL_Env *, int, char **),RIL_SOCKET_TYPE socketType, int argc, char **argv) {
4793
4794 RIL_RadioFunctions* UimFuncs = NULL;
4795
4796 if(Init) {
4797 UimFuncs = Init(&RilSapSocket::uimRilEnv, argc, argv);
4798
4799 switch(socketType) {
4800 case RIL_SAP_SOCKET:
4801 RilSapSocket::initSapSocket("sap_uim_socket1", UimFuncs);
4802
4803#if (SIM_COUNT >= 2)
4804 RilSapSocket::initSapSocket("sap_uim_socket2", UimFuncs);
4805#endif
4806
4807#if (SIM_COUNT >= 3)
4808 RilSapSocket::initSapSocket("sap_uim_socket3", UimFuncs);
4809#endif
4810
4811#if (SIM_COUNT >= 4)
4812 RilSapSocket::initSapSocket("sap_uim_socket4", UimFuncs);
4813#endif
4814 }
4815 }
4816}
4817
Sanket Padawe6ff9a872016-01-27 15:09:12 -08004818// Check and remove RequestInfo if its a response and not just ack sent back
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004819static int
Sanket Padawe6ff9a872016-01-27 15:09:12 -08004820checkAndDequeueRequestInfoIfAck(struct RequestInfo *pRI, bool isAck) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004821 int ret = 0;
Etan Cohend3652192014-06-20 08:28:44 -07004822 /* Hook for current context
4823 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
4824 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
4825 /* pendingRequestsHook refer to &s_pendingRequests */
4826 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
Wink Saville7f856802009-06-09 10:23:37 -07004827
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004828 if (pRI == NULL) {
4829 return 0;
4830 }
4831
Etan Cohend3652192014-06-20 08:28:44 -07004832#if (SIM_COUNT >= 2)
4833 if (pRI->socket_id == RIL_SOCKET_2) {
4834 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
4835 pendingRequestsHook = &s_pendingRequests_socket2;
4836 }
4837#if (SIM_COUNT >= 3)
4838 if (pRI->socket_id == RIL_SOCKET_3) {
4839 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
4840 pendingRequestsHook = &s_pendingRequests_socket3;
4841 }
4842#endif
4843#if (SIM_COUNT >= 4)
4844 if (pRI->socket_id == RIL_SOCKET_4) {
4845 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
4846 pendingRequestsHook = &s_pendingRequests_socket4;
4847 }
4848#endif
4849#endif
4850 pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004851
Etan Cohend3652192014-06-20 08:28:44 -07004852 for(RequestInfo **ppCur = pendingRequestsHook
Wink Saville7f856802009-06-09 10:23:37 -07004853 ; *ppCur != NULL
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004854 ; ppCur = &((*ppCur)->p_next)
4855 ) {
4856 if (pRI == *ppCur) {
4857 ret = 1;
Sanket Padawe6ff9a872016-01-27 15:09:12 -08004858 if (isAck) { // Async ack
4859 if (pRI->wasAckSent == 1) {
4860 RLOGD("Ack was already sent for %s", requestToString(pRI->pCI->requestNumber));
4861 } else {
4862 pRI->wasAckSent = 1;
4863 }
4864 } else {
4865 *ppCur = (*ppCur)->p_next;
4866 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004867 break;
4868 }
4869 }
4870
Etan Cohend3652192014-06-20 08:28:44 -07004871 pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004872
4873 return ret;
4874}
4875
Sanket Padawe6ff9a872016-01-27 15:09:12 -08004876static int findFd(int socket_id) {
Etan Cohend3652192014-06-20 08:28:44 -07004877 int fd = s_ril_param_socket.fdCommand;
Etan Cohend3652192014-06-20 08:28:44 -07004878#if (SIM_COUNT >= 2)
4879 if (socket_id == RIL_SOCKET_2) {
4880 fd = s_ril_param_socket2.fdCommand;
4881 }
4882#if (SIM_COUNT >= 3)
Sanket Padawe6ff9a872016-01-27 15:09:12 -08004883 if (socket_id == RIL_SOCKET_3) {
4884 fd = s_ril_param_socket3.fdCommand;
4885 }
Etan Cohend3652192014-06-20 08:28:44 -07004886#endif
4887#if (SIM_COUNT >= 4)
4888 if (socket_id == RIL_SOCKET_4) {
4889 fd = s_ril_param_socket4.fdCommand;
4890 }
4891#endif
4892#endif
Sanket Padawe6ff9a872016-01-27 15:09:12 -08004893 return fd;
4894}
4895
4896extern "C" void
4897RIL_onRequestAck(RIL_Token t) {
4898 RequestInfo *pRI;
4899 int ret, fd;
4900
4901 size_t errorOffset;
4902 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
4903
4904 pRI = (RequestInfo *)t;
4905
4906 if (!checkAndDequeueRequestInfoIfAck(pRI, true)) {
4907 RLOGE ("RIL_onRequestAck: invalid RIL_Token");
4908 return;
4909 }
4910
4911 socket_id = pRI->socket_id;
4912 fd = findFd(socket_id);
4913
4914#if VDBG
4915 RLOGD("Request Ack, %s", rilSocketIdToString(socket_id));
4916#endif
4917
4918 appendPrintBuf("Ack [%04d]< %s", pRI->token, requestToString(pRI->pCI->requestNumber));
4919
4920 if (pRI->cancelled == 0) {
4921 Parcel p;
4922
4923 p.writeInt32 (RESPONSE_SOLICITED_ACK);
4924 p.writeInt32 (pRI->token);
4925
4926 if (fd < 0) {
4927 RLOGD ("RIL onRequestComplete: Command channel closed");
4928 }
4929
4930 sendResponse(p, socket_id);
4931 }
4932}
4933
4934extern "C" void
4935RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) {
4936 RequestInfo *pRI;
4937 int ret;
4938 int fd;
4939 size_t errorOffset;
4940 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
4941
4942 pRI = (RequestInfo *)t;
4943
4944 if (!checkAndDequeueRequestInfoIfAck(pRI, false)) {
4945 RLOGE ("RIL_onRequestComplete: invalid RIL_Token");
4946 return;
4947 }
4948
4949 socket_id = pRI->socket_id;
4950 fd = findFd(socket_id);
4951
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07004952#if VDBG
Etan Cohend3652192014-06-20 08:28:44 -07004953 RLOGD("RequestComplete, %s", rilSocketIdToString(socket_id));
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07004954#endif
Etan Cohend3652192014-06-20 08:28:44 -07004955
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004956 if (pRI->local > 0) {
4957 // Locally issued command...void only!
4958 // response does not go back up the command socket
Wink Saville8eb2a122012-11-19 16:05:13 -08004959 RLOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004960
4961 goto done;
4962 }
4963
4964 appendPrintBuf("[%04d]< %s",
4965 pRI->token, requestToString(pRI->pCI->requestNumber));
4966
4967 if (pRI->cancelled == 0) {
4968 Parcel p;
4969
Sanket Padawe6ff9a872016-01-27 15:09:12 -08004970 if (s_callbacks.version >= 13 && pRI->wasAckSent == 1) {
4971 // If ack was already sent, then this call is an asynchronous response. So we need to
4972 // send id indicating that we expect an ack from RIL.java as we acquire wakelock here.
4973 p.writeInt32 (RESPONSE_SOLICITED_ACK_EXP);
4974 grabPartialWakeLock();
4975 } else {
4976 p.writeInt32 (RESPONSE_SOLICITED);
4977 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004978 p.writeInt32 (pRI->token);
4979 errorOffset = p.dataPosition();
4980
4981 p.writeInt32 (e);
4982
johnwangb2a61842009-06-02 14:55:45 -07004983 if (response != NULL) {
4984 // there is a response payload, no matter success or not.
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004985 ret = pRI->pCI->responseFunction(p, response, responselen);
4986
4987 /* if an error occurred, rewind and mark it */
4988 if (ret != 0) {
Etan Cohend3652192014-06-20 08:28:44 -07004989 RLOGE ("responseFunction error, ret %d", ret);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004990 p.setDataPosition(errorOffset);
4991 p.writeInt32 (ret);
4992 }
johnwangb2a61842009-06-02 14:55:45 -07004993 }
4994
4995 if (e != RIL_E_SUCCESS) {
4996 appendPrintBuf("%s fails by %s", printBuf, failCauseToString(e));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004997 }
4998
Etan Cohend3652192014-06-20 08:28:44 -07004999 if (fd < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08005000 RLOGD ("RIL onRequestComplete: Command channel closed");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005001 }
Etan Cohend3652192014-06-20 08:28:44 -07005002 sendResponse(p, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005003 }
5004
5005done:
5006 free(pRI);
5007}
5008
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005009static void
Wink Savillef4c4d362009-04-02 01:37:03 -07005010grabPartialWakeLock() {
Sanket Padawe6ff9a872016-01-27 15:09:12 -08005011 if (s_callbacks.version >= 13) {
5012 int ret;
5013 ret = pthread_mutex_lock(&s_wakeLockCountMutex);
5014 assert(ret == 0);
5015 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
5016 s_wakelock_count++;
5017 if (s_last_wake_timeout_info != NULL) {
5018 s_last_wake_timeout_info->userParam = (void *)1;
5019 }
5020
5021 s_last_wake_timeout_info
5022 = internalRequestTimedCallback(wakeTimeoutCallback, NULL, &TIMEVAL_WAKE_TIMEOUT);
5023
5024 ret = pthread_mutex_unlock(&s_wakeLockCountMutex);
5025 assert(ret == 0);
5026 } else {
5027 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
5028 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005029}
5030
5031static void
Wink Savillef4c4d362009-04-02 01:37:03 -07005032releaseWakeLock() {
Sanket Padawe6ff9a872016-01-27 15:09:12 -08005033 if (s_callbacks.version >= 13) {
5034 int ret;
5035 ret = pthread_mutex_lock(&s_wakeLockCountMutex);
5036 assert(ret == 0);
5037
5038 if (s_wakelock_count > 1) {
5039 s_wakelock_count--;
5040 } else {
5041 s_wakelock_count = 0;
5042 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
5043 if (s_last_wake_timeout_info != NULL) {
5044 s_last_wake_timeout_info->userParam = (void *)1;
5045 }
5046 }
5047
5048 ret = pthread_mutex_unlock(&s_wakeLockCountMutex);
5049 assert(ret == 0);
5050 } else {
5051 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
5052 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005053}
5054
5055/**
5056 * Timer callback to put us back to sleep before the default timeout
5057 */
5058static void
Wink Savillef4c4d362009-04-02 01:37:03 -07005059wakeTimeoutCallback (void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005060 // We're using "param != NULL" as a cancellation mechanism
Sanket Padawe6ff9a872016-01-27 15:09:12 -08005061 if (s_callbacks.version >= 13) {
5062 if (param == NULL) {
5063 int ret;
5064 ret = pthread_mutex_lock(&s_wakeLockCountMutex);
5065 assert(ret == 0);
5066 s_wakelock_count = 0;
5067 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
5068 ret = pthread_mutex_unlock(&s_wakeLockCountMutex);
5069 assert(ret == 0);
5070 }
5071 } else {
5072 if (param == NULL) {
5073 releaseWakeLock();
5074 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005075 }
5076}
5077
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005078static int
5079decodeVoiceRadioTechnology (RIL_RadioState radioState) {
5080 switch (radioState) {
5081 case RADIO_STATE_SIM_NOT_READY:
5082 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
5083 case RADIO_STATE_SIM_READY:
5084 return RADIO_TECH_UMTS;
5085
5086 case RADIO_STATE_RUIM_NOT_READY:
5087 case RADIO_STATE_RUIM_READY:
5088 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
5089 case RADIO_STATE_NV_NOT_READY:
5090 case RADIO_STATE_NV_READY:
5091 return RADIO_TECH_1xRTT;
5092
5093 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08005094 RLOGD("decodeVoiceRadioTechnology: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005095 return -1;
5096 }
5097}
5098
5099static int
5100decodeCdmaSubscriptionSource (RIL_RadioState radioState) {
5101 switch (radioState) {
5102 case RADIO_STATE_SIM_NOT_READY:
5103 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
5104 case RADIO_STATE_SIM_READY:
5105 case RADIO_STATE_RUIM_NOT_READY:
5106 case RADIO_STATE_RUIM_READY:
5107 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
5108 return CDMA_SUBSCRIPTION_SOURCE_RUIM_SIM;
5109
5110 case RADIO_STATE_NV_NOT_READY:
5111 case RADIO_STATE_NV_READY:
5112 return CDMA_SUBSCRIPTION_SOURCE_NV;
5113
5114 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08005115 RLOGD("decodeCdmaSubscriptionSource: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005116 return -1;
5117 }
5118}
5119
5120static int
5121decodeSimStatus (RIL_RadioState radioState) {
5122 switch (radioState) {
5123 case RADIO_STATE_SIM_NOT_READY:
5124 case RADIO_STATE_RUIM_NOT_READY:
5125 case RADIO_STATE_NV_NOT_READY:
5126 case RADIO_STATE_NV_READY:
5127 return -1;
5128 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
5129 case RADIO_STATE_SIM_READY:
5130 case RADIO_STATE_RUIM_READY:
5131 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
5132 return radioState;
5133 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08005134 RLOGD("decodeSimStatus: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005135 return -1;
5136 }
5137}
5138
5139static bool is3gpp2(int radioTech) {
5140 switch (radioTech) {
5141 case RADIO_TECH_IS95A:
5142 case RADIO_TECH_IS95B:
5143 case RADIO_TECH_1xRTT:
5144 case RADIO_TECH_EVDO_0:
5145 case RADIO_TECH_EVDO_A:
5146 case RADIO_TECH_EVDO_B:
5147 case RADIO_TECH_EHRPD:
5148 return true;
5149 default:
5150 return false;
5151 }
5152}
5153
5154/* If RIL sends SIM states or RUIM states, store the voice radio
5155 * technology and subscription source information so that they can be
5156 * returned when telephony framework requests them
5157 */
5158static RIL_RadioState
Etan Cohend3652192014-06-20 08:28:44 -07005159processRadioState(RIL_RadioState newRadioState, RIL_SOCKET_ID socket_id) {
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005160
5161 if((newRadioState > RADIO_STATE_UNAVAILABLE) && (newRadioState < RADIO_STATE_ON)) {
5162 int newVoiceRadioTech;
5163 int newCdmaSubscriptionSource;
5164 int newSimStatus;
5165
5166 /* This is old RIL. Decode Subscription source and Voice Radio Technology
5167 from Radio State and send change notifications if there has been a change */
5168 newVoiceRadioTech = decodeVoiceRadioTechnology(newRadioState);
5169 if(newVoiceRadioTech != voiceRadioTech) {
5170 voiceRadioTech = newVoiceRadioTech;
Etan Cohend3652192014-06-20 08:28:44 -07005171 RIL_UNSOL_RESPONSE(RIL_UNSOL_VOICE_RADIO_TECH_CHANGED,
5172 &voiceRadioTech, sizeof(voiceRadioTech), socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005173 }
5174 if(is3gpp2(newVoiceRadioTech)) {
5175 newCdmaSubscriptionSource = decodeCdmaSubscriptionSource(newRadioState);
5176 if(newCdmaSubscriptionSource != cdmaSubscriptionSource) {
5177 cdmaSubscriptionSource = newCdmaSubscriptionSource;
Etan Cohend3652192014-06-20 08:28:44 -07005178 RIL_UNSOL_RESPONSE(RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED,
5179 &cdmaSubscriptionSource, sizeof(cdmaSubscriptionSource), socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005180 }
5181 }
5182 newSimStatus = decodeSimStatus(newRadioState);
5183 if(newSimStatus != simRuimStatus) {
5184 simRuimStatus = newSimStatus;
Etan Cohend3652192014-06-20 08:28:44 -07005185 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0, socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005186 }
5187
5188 /* Send RADIO_ON to telephony */
5189 newRadioState = RADIO_STATE_ON;
5190 }
5191
5192 return newRadioState;
5193}
5194
Etan Cohend3652192014-06-20 08:28:44 -07005195
5196#if defined(ANDROID_MULTI_SIM)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005197extern "C"
Bernhard Rosenkränzerd613b962014-11-17 20:52:09 +01005198void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Etan Cohend3652192014-06-20 08:28:44 -07005199 size_t datalen, RIL_SOCKET_ID socket_id)
5200#else
5201extern "C"
Bernhard Rosenkränzerd613b962014-11-17 20:52:09 +01005202void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005203 size_t datalen)
Etan Cohend3652192014-06-20 08:28:44 -07005204#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005205{
5206 int unsolResponseIndex;
5207 int ret;
5208 int64_t timeReceived = 0;
5209 bool shouldScheduleTimeout = false;
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005210 RIL_RadioState newState;
Etan Cohend3652192014-06-20 08:28:44 -07005211 RIL_SOCKET_ID soc_id = RIL_SOCKET_1;
5212
5213#if defined(ANDROID_MULTI_SIM)
5214 soc_id = socket_id;
5215#endif
5216
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005217
5218 if (s_registerCalled == 0) {
5219 // Ignore RIL_onUnsolicitedResponse before RIL_register
Wink Saville8eb2a122012-11-19 16:05:13 -08005220 RLOGW("RIL_onUnsolicitedResponse called before RIL_register");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005221 return;
5222 }
Wink Saville7f856802009-06-09 10:23:37 -07005223
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005224 unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
5225
5226 if ((unsolResponseIndex < 0)
5227 || (unsolResponseIndex >= (int32_t)NUM_ELEMS(s_unsolResponses))) {
Wink Saville8eb2a122012-11-19 16:05:13 -08005228 RLOGE("unsupported unsolicited response code %d", unsolResponse);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005229 return;
5230 }
5231
5232 // Grab a wake lock if needed for this reponse,
5233 // as we exit we'll either release it immediately
5234 // or set a timer to release it later.
5235 switch (s_unsolResponses[unsolResponseIndex].wakeType) {
5236 case WAKE_PARTIAL:
5237 grabPartialWakeLock();
5238 shouldScheduleTimeout = true;
5239 break;
5240
5241 case DONT_WAKE:
5242 default:
5243 // No wake lock is grabed so don't set timeout
5244 shouldScheduleTimeout = false;
5245 break;
5246 }
5247
5248 // Mark the time this was received, doing this
5249 // after grabing the wakelock incase getting
5250 // the elapsedRealTime might cause us to goto
5251 // sleep.
5252 if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
5253 timeReceived = elapsedRealtime();
5254 }
5255
5256 appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
5257
5258 Parcel p;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005259 p.writeInt32 (RESPONSE_UNSOLICITED);
5260 p.writeInt32 (unsolResponse);
5261
5262 ret = s_unsolResponses[unsolResponseIndex]
Bernhard Rosenkränzer6e7c1962013-12-12 10:01:10 +01005263 .responseFunction(p, const_cast<void*>(data), datalen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005264 if (ret != 0) {
5265 // Problem with the response. Don't continue;
5266 goto error_exit;
5267 }
5268
5269 // some things get more payload
5270 switch(unsolResponse) {
5271 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
Etan Cohend3652192014-06-20 08:28:44 -07005272 newState = processRadioState(CALL_ONSTATEREQUEST(soc_id), soc_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005273 p.writeInt32(newState);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005274 appendPrintBuf("%s {%s}", printBuf,
Etan Cohend3652192014-06-20 08:28:44 -07005275 radioStateToString(CALL_ONSTATEREQUEST(soc_id)));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005276 break;
5277
5278
5279 case RIL_UNSOL_NITZ_TIME_RECEIVED:
5280 // Store the time that this was received so the
5281 // handler of this message can account for
5282 // the time it takes to arrive and process. In
5283 // particular the system has been known to sleep
5284 // before this message can be processed.
5285 p.writeInt64(timeReceived);
5286 break;
5287 }
5288
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07005289#if VDBG
Etan Cohend3652192014-06-20 08:28:44 -07005290 RLOGI("%s UNSOLICITED: %s length:%d", rilSocketIdToString(soc_id), requestToString(unsolResponse), p.dataSize());
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07005291#endif
Etan Cohend3652192014-06-20 08:28:44 -07005292 ret = sendResponse(p, soc_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005293 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
5294
5295 // Unfortunately, NITZ time is not poll/update like everything
5296 // else in the system. So, if the upstream client isn't connected,
5297 // keep a copy of the last NITZ response (with receive time noted
5298 // above) around so we can deliver it when it is connected
5299
5300 if (s_lastNITZTimeData != NULL) {
5301 free (s_lastNITZTimeData);
5302 s_lastNITZTimeData = NULL;
5303 }
5304
5305 s_lastNITZTimeData = malloc(p.dataSize());
5306 s_lastNITZTimeDataSize = p.dataSize();
5307 memcpy(s_lastNITZTimeData, p.data(), p.dataSize());
5308 }
5309
Sanket Padawe6ff9a872016-01-27 15:09:12 -08005310 if (s_callbacks.version < 13) {
5311 if (shouldScheduleTimeout) {
5312 // Cancel the previous request
5313 if (s_last_wake_timeout_info != NULL) {
5314 s_last_wake_timeout_info->userParam = (void *)1;
5315 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005316
Sanket Padawe6ff9a872016-01-27 15:09:12 -08005317 s_last_wake_timeout_info
5318 = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
5319 &TIMEVAL_WAKE_TIMEOUT);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005320 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005321 }
5322
5323 // Normal exit
5324 return;
5325
5326error_exit:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005327 if (shouldScheduleTimeout) {
5328 releaseWakeLock();
5329 }
5330}
5331
Wink Saville7f856802009-06-09 10:23:37 -07005332/** FIXME generalize this if you track UserCAllbackInfo, clear it
5333 when the callback occurs
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005334*/
5335static UserCallbackInfo *
Wink Saville7f856802009-06-09 10:23:37 -07005336internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07005337 const struct timeval *relativeTime)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005338{
5339 struct timeval myRelativeTime;
5340 UserCallbackInfo *p_info;
5341
5342 p_info = (UserCallbackInfo *) malloc (sizeof(UserCallbackInfo));
5343
Wink Saville7f856802009-06-09 10:23:37 -07005344 p_info->p_callback = callback;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005345 p_info->userParam = param;
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07005346
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005347 if (relativeTime == NULL) {
5348 /* treat null parameter as a 0 relative time */
5349 memset (&myRelativeTime, 0, sizeof(myRelativeTime));
5350 } else {
5351 /* FIXME I think event_add's tv param is really const anyway */
5352 memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
5353 }
5354
5355 ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
5356
5357 ril_timer_add(&(p_info->event), &myRelativeTime);
5358
5359 triggerEvLoop();
5360 return p_info;
5361}
5362
Naveen Kalla7edd07c2010-06-21 18:54:47 -07005363
5364extern "C" void
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07005365RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
5366 const struct timeval *relativeTime) {
5367 internalRequestTimedCallback (callback, param, relativeTime);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005368}
5369
5370const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07005371failCauseToString(RIL_Errno e) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005372 switch(e) {
5373 case RIL_E_SUCCESS: return "E_SUCCESS";
Robert Greenwalt2126ab22013-04-09 12:20:45 -07005374 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RADIO_NOT_AVAILABLE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005375 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
5376 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
5377 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
5378 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
5379 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
5380 case RIL_E_CANCELLED: return "E_CANCELLED";
5381 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
5382 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
5383 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
Wink Savillef4c4d362009-04-02 01:37:03 -07005384 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
John Wang75534472010-04-20 15:11:42 -07005385 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
Wink Saville7f856802009-06-09 10:23:37 -07005386#ifdef FEATURE_MULTIMODE_ANDROID
Wink Savillef4c4d362009-04-02 01:37:03 -07005387 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
5388 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
5389#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005390 default: return "<unknown error>";
5391 }
5392}
5393
5394const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07005395radioStateToString(RIL_RadioState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005396 switch(s) {
5397 case RADIO_STATE_OFF: return "RADIO_OFF";
5398 case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
5399 case RADIO_STATE_SIM_NOT_READY: return "RADIO_SIM_NOT_READY";
5400 case RADIO_STATE_SIM_LOCKED_OR_ABSENT: return "RADIO_SIM_LOCKED_OR_ABSENT";
5401 case RADIO_STATE_SIM_READY: return "RADIO_SIM_READY";
Wink Savillef4c4d362009-04-02 01:37:03 -07005402 case RADIO_STATE_RUIM_NOT_READY:return"RADIO_RUIM_NOT_READY";
5403 case RADIO_STATE_RUIM_READY:return"RADIO_RUIM_READY";
5404 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:return"RADIO_RUIM_LOCKED_OR_ABSENT";
5405 case RADIO_STATE_NV_NOT_READY:return"RADIO_NV_NOT_READY";
5406 case RADIO_STATE_NV_READY:return"RADIO_NV_READY";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005407 case RADIO_STATE_ON:return"RADIO_ON";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005408 default: return "<unknown state>";
5409 }
5410}
5411
5412const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07005413callStateToString(RIL_CallState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005414 switch(s) {
5415 case RIL_CALL_ACTIVE : return "ACTIVE";
5416 case RIL_CALL_HOLDING: return "HOLDING";
5417 case RIL_CALL_DIALING: return "DIALING";
5418 case RIL_CALL_ALERTING: return "ALERTING";
5419 case RIL_CALL_INCOMING: return "INCOMING";
5420 case RIL_CALL_WAITING: return "WAITING";
5421 default: return "<unknown state>";
5422 }
5423}
5424
5425const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07005426requestToString(int request) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005427/*
5428 cat libs/telephony/ril_commands.h \
5429 | egrep "^ *{RIL_" \
5430 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
5431
5432
5433 cat libs/telephony/ril_unsol_commands.h \
5434 | egrep "^ *{RIL_" \
5435 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
5436
5437*/
5438 switch(request) {
5439 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
5440 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
5441 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
5442 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
5443 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
5444 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
5445 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
5446 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
5447 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
5448 case RIL_REQUEST_DIAL: return "DIAL";
5449 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
5450 case RIL_REQUEST_HANGUP: return "HANGUP";
5451 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
5452 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
5453 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
5454 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
5455 case RIL_REQUEST_UDUB: return "UDUB";
5456 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
5457 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
Wink Savillec0114b32011-02-18 10:14:07 -08005458 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
5459 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005460 case RIL_REQUEST_OPERATOR: return "OPERATOR";
5461 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
5462 case RIL_REQUEST_DTMF: return "DTMF";
5463 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
5464 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
Wink Savillef4c4d362009-04-02 01:37:03 -07005465 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005466 case RIL_REQUEST_SIM_IO: return "SIM_IO";
5467 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
5468 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
5469 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
5470 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
5471 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
5472 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
5473 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
5474 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
5475 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
5476 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
5477 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
5478 case RIL_REQUEST_ANSWER: return "ANSWER";
Wink Savillef4c4d362009-04-02 01:37:03 -07005479 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005480 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
5481 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
5482 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
5483 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
5484 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
5485 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
5486 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";
5487 case RIL_REQUEST_DTMF_START: return "DTMF_START";
5488 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
5489 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
5490 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
5491 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
5492 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
5493 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
5494 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
5495 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
5496 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
Wink Savillef4c4d362009-04-02 01:37:03 -07005497 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
5498 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005499 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
5500 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
5501 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
Wink Savillef4c4d362009-04-02 01:37:03 -07005502 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
5503 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005504 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
5505 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
5506 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
5507 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
5508 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
5509 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
5510 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
5511 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
Wink Savillec0114b32011-02-18 10:14:07 -08005512 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE:return"CDMA_SET_SUBSCRIPTION_SOURCE";
Wink Savillef4c4d362009-04-02 01:37:03 -07005513 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"CDMA_SET_ROAMING_PREFERENCE";
5514 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"CDMA_QUERY_ROAMING_PREFERENCE";
5515 case RIL_REQUEST_SET_TTY_MODE:return"SET_TTY_MODE";
5516 case RIL_REQUEST_QUERY_TTY_MODE:return"QUERY_TTY_MODE";
5517 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
5518 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
5519 case RIL_REQUEST_CDMA_FLASH:return"CDMA_FLASH";
5520 case RIL_REQUEST_CDMA_BURST_DTMF:return"CDMA_BURST_DTMF";
5521 case RIL_REQUEST_CDMA_SEND_SMS:return"CDMA_SEND_SMS";
5522 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:return"CDMA_SMS_ACKNOWLEDGE";
Wink Savillea592eeb2009-05-22 13:26:36 -07005523 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG:return"GSM_GET_BROADCAST_SMS_CONFIG";
5524 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG:return"GSM_SET_BROADCAST_SMS_CONFIG";
5525 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG:return "CDMA_GET_BROADCAST_SMS_CONFIG";
5526 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG:return "CDMA_SET_BROADCAST_SMS_CONFIG";
5527 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION:return "CDMA_SMS_BROADCAST_ACTIVATION";
Naveen Kalla03c1edf2009-09-23 11:18:35 -07005528 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return"CDMA_VALIDATE_AND_WRITE_AKEY";
Wink Savillef4c4d362009-04-02 01:37:03 -07005529 case RIL_REQUEST_CDMA_SUBSCRIPTION: return"CDMA_SUBSCRIPTION";
5530 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
5531 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
5532 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
jsh000a9fe2009-05-11 14:52:35 -07005533 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
5534 case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
5535 case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
jsh09a68ba2009-06-10 11:56:38 -07005536 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
jsh563fd722010-06-08 16:52:24 -07005537 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
Wink Savillec0114b32011-02-18 10:14:07 -08005538 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
Jake Hambyfa8d5842011-08-19 16:22:18 -07005539 case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
Jake Hamby300105d2011-09-26 01:01:44 -07005540 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
5541 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005542 case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
Ajay Nambic27945d2011-11-15 11:19:30 -08005543 case RIL_REQUEST_WRITE_SMS_TO_SIM: return "WRITE_SMS_TO_SIM";
Wink Saville8a9e0212013-04-09 12:11:38 -07005544 case RIL_REQUEST_GET_CELL_INFO_LIST: return"GET_CELL_INFO_LIST";
5545 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return"SET_UNSOL_CELL_INFO_LIST_RATE";
Sungmin Choi75697532013-04-26 15:04:45 -07005546 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "RIL_REQUEST_SET_INITIAL_ATTACH_APN";
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07005547 case RIL_REQUEST_IMS_REGISTRATION_STATE: return "IMS_REGISTRATION_STATE";
5548 case RIL_REQUEST_IMS_SEND_SMS: return "IMS_SEND_SMS";
Shishir Agrawal2458d8d2013-11-27 14:53:05 -08005549 case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "SIM_TRANSMIT_APDU_BASIC";
5550 case RIL_REQUEST_SIM_OPEN_CHANNEL: return "SIM_OPEN_CHANNEL";
5551 case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "SIM_CLOSE_CHANNEL";
5552 case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "SIM_TRANSMIT_APDU_CHANNEL";
Wink Saville8b4e4f72014-10-17 15:01:45 -07005553 case RIL_REQUEST_GET_RADIO_CAPABILITY: return "RIL_REQUEST_GET_RADIO_CAPABILITY";
5554 case RIL_REQUEST_SET_RADIO_CAPABILITY: return "RIL_REQUEST_SET_RADIO_CAPABILITY";
Etan Cohend3652192014-06-20 08:28:44 -07005555 case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "SET_UICC_SUBSCRIPTION";
5556 case RIL_REQUEST_ALLOW_DATA: return "ALLOW_DATA";
Amit Mahajan2b772032014-06-26 14:20:11 -07005557 case RIL_REQUEST_GET_HARDWARE_CONFIG: return "GET_HARDWARE_CONFIG";
5558 case RIL_REQUEST_SIM_AUTHENTICATION: return "SIM_AUTHENTICATION";
Wink Savillec29360a2014-07-13 05:17:28 -07005559 case RIL_REQUEST_GET_DC_RT_INFO: return "GET_DC_RT_INFO";
5560 case RIL_REQUEST_SET_DC_RT_INFO_RATE: return "SET_DC_RT_INFO_RATE";
Amit Mahajanc796e222014-08-13 16:54:01 +00005561 case RIL_REQUEST_SET_DATA_PROFILE: return "SET_DATA_PROFILE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005562 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
5563 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08005564 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 -08005565 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
5566 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
5567 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
5568 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
5569 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)";
5570 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
5571 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
Ajay Nambic27945d2011-11-15 11:19:30 -08005572 case RIL_UNSOL_SUPP_SVC_NOTIFICATION: return "UNSOL_SUPP_SVC_NOTIFICATION";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005573 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
5574 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
5575 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
5576 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
5577 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL";
5578 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
Wink Savillef4c4d362009-04-02 01:37:03 -07005579 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005580 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
Wink Savillef4c4d362009-04-02 01:37:03 -07005581 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
5582 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_NEW_CDMA_SMS";
5583 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_NEW_BROADCAST_SMS";
5584 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
Wink Saville3d54e742009-05-18 18:00:44 -07005585 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
5586 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
5587 case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
5588 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
5589 case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
Jaikumar Ganeshaf6ecbf2009-04-29 13:27:51 -07005590 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
John Wang5d621da2009-09-18 17:17:48 -07005591 case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
John Wang5909cf82010-01-29 00:18:54 -08005592 case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
Wink Savilleee274582011-04-16 15:05:49 -07005593 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08005594 case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
5595 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
Wink Saville5b9df332011-04-06 16:24:21 -07005596 case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005597 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
Wink Saville8a9e0212013-04-09 12:11:38 -07005598 case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07005599 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "RESPONSE_IMS_NETWORK_STATE_CHANGED";
Etan Cohend3652192014-06-20 08:28:44 -07005600 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return "UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED";
5601 case RIL_UNSOL_SRVCC_STATE_NOTIFY: return "UNSOL_SRVCC_STATE_NOTIFY";
5602 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return "HARDWARE_CONFIG_CHANGED";
Wink Savillec29360a2014-07-13 05:17:28 -07005603 case RIL_UNSOL_DC_RT_INFO_CHANGED: return "UNSOL_DC_RT_INFO_CHANGED";
Naveen Kallaa65a16a2014-07-31 16:48:31 -07005604 case RIL_REQUEST_SHUTDOWN: return "SHUTDOWN";
Wink Saville8b4e4f72014-10-17 15:01:45 -07005605 case RIL_UNSOL_RADIO_CAPABILITY: return "RIL_UNSOL_RADIO_CAPABILITY";
Sanket Padawe6ff9a872016-01-27 15:09:12 -08005606 case RIL_RESPONSE_ACKNOWLEDGEMENT: return "RIL_RESPONSE_ACKNOWLEDGEMENT";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005607 default: return "<unknown request>";
5608 }
5609}
5610
Etan Cohend3652192014-06-20 08:28:44 -07005611const char *
5612rilSocketIdToString(RIL_SOCKET_ID socket_id)
5613{
5614 switch(socket_id) {
5615 case RIL_SOCKET_1:
5616 return "RIL_SOCKET_1";
5617#if (SIM_COUNT >= 2)
5618 case RIL_SOCKET_2:
5619 return "RIL_SOCKET_2";
5620#endif
5621#if (SIM_COUNT >= 3)
5622 case RIL_SOCKET_3:
5623 return "RIL_SOCKET_3";
5624#endif
5625#if (SIM_COUNT >= 4)
5626 case RIL_SOCKET_4:
5627 return "RIL_SOCKET_4";
5628#endif
5629 default:
5630 return "not a valid RIL";
5631 }
5632}
5633
Sanket Padawe88cf6a52016-01-11 12:45:43 -08005634/*
5635 * Returns true for a debuggable build.
5636 */
5637static bool isDebuggable() {
5638 char debuggable[PROP_VALUE_MAX];
5639 property_get("ro.debuggable", debuggable, "0");
5640 if (strcmp(debuggable, "1") == 0) {
5641 return true;
5642 }
5643 return false;
5644}
5645
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005646} /* namespace android */
Dheeraj Shetty27976c42014-07-02 21:27:57 +02005647
5648void rilEventAddWakeup_helper(struct ril_event *ev) {
5649 android::rilEventAddWakeup(ev);
5650}
5651
5652void listenCallback_helper(int fd, short flags, void *param) {
5653 android::listenCallback(fd, flags, param);
5654}
5655
5656int blockingWrite_helper(int fd, void *buffer, size_t len) {
5657 return android::blockingWrite(fd, buffer, len);
5658}