blob: 84ed4b5e93b27be29f438b7aebad58071f6a205f [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;
Sukanya Rajkhowa605c7842013-10-29 14:55:30 +08001546 int32_t digitLimit;
Wink Savillef4c4d362009-04-02 01:37:03 -07001547
1548 memset(&rcsw, 0, sizeof(rcsw));
1549
1550 status = p.readInt32(&t);
1551 rcsw.status = t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001552
Wink Savillef4c4d362009-04-02 01:37:03 -07001553 status = p.readInt32(&t);
1554 rcsw.message.uTeleserviceID = (int) t;
1555
1556 status = p.read(&uct,sizeof(uct));
1557 rcsw.message.bIsServicePresent = (uint8_t) uct;
1558
1559 status = p.readInt32(&t);
1560 rcsw.message.uServicecategory = (int) t;
1561
1562 status = p.readInt32(&t);
1563 rcsw.message.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1564
1565 status = p.readInt32(&t);
1566 rcsw.message.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1567
1568 status = p.readInt32(&t);
1569 rcsw.message.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1570
1571 status = p.readInt32(&t);
1572 rcsw.message.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1573
1574 status = p.read(&uct,sizeof(uct));
1575 rcsw.message.sAddress.number_of_digits = (uint8_t) uct;
1576
Sukanya Rajkhowa605c7842013-10-29 14:55:30 +08001577 digitLimit = MIN((rcsw.message.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
1578
1579 for(digitCount = 0 ; digitCount < digitLimit; digitCount ++) {
Wink Savillef4c4d362009-04-02 01:37:03 -07001580 status = p.read(&uct,sizeof(uct));
1581 rcsw.message.sAddress.digits[digitCount] = (uint8_t) uct;
1582 }
1583
Wink Savillea592eeb2009-05-22 13:26:36 -07001584 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001585 rcsw.message.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1586
Wink Savillea592eeb2009-05-22 13:26:36 -07001587 status = p.read(&uct,sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001588 rcsw.message.sSubAddress.odd = (uint8_t) uct;
1589
1590 status = p.read(&uct,sizeof(uct));
1591 rcsw.message.sSubAddress.number_of_digits = (uint8_t) uct;
1592
Sukanya Rajkhowa605c7842013-10-29 14:55:30 +08001593 digitLimit = MIN((rcsw.message.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
1594
1595 for(digitCount = 0 ; digitCount < digitLimit; digitCount ++) {
Wink Savillea592eeb2009-05-22 13:26:36 -07001596 status = p.read(&uct,sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001597 rcsw.message.sSubAddress.digits[digitCount] = (uint8_t) uct;
1598 }
1599
Wink Savillea592eeb2009-05-22 13:26:36 -07001600 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001601 rcsw.message.uBearerDataLen = (int) t;
1602
Sukanya Rajkhowa605c7842013-10-29 14:55:30 +08001603 digitLimit = MIN((rcsw.message.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
1604
1605 for(digitCount = 0 ; digitCount < digitLimit; digitCount ++) {
Wink Savillea592eeb2009-05-22 13:26:36 -07001606 status = p.read(&uct, sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001607 rcsw.message.aBearerData[digitCount] = (uint8_t) uct;
1608 }
1609
1610 if (status != NO_ERROR) {
1611 goto invalid;
1612 }
1613
1614 startRequest;
Wink Saville1b5fd232009-04-22 14:50:00 -07001615 appendPrintBuf("%sstatus=%d, message.uTeleserviceID=%d, message.bIsServicePresent=%d, \
1616 message.uServicecategory=%d, message.sAddress.digit_mode=%d, \
1617 message.sAddress.number_mode=%d, \
1618 message.sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07001619 printBuf, rcsw.status, rcsw.message.uTeleserviceID, rcsw.message.bIsServicePresent,
Wink Saville1b5fd232009-04-22 14:50:00 -07001620 rcsw.message.uServicecategory, rcsw.message.sAddress.digit_mode,
1621 rcsw.message.sAddress.number_mode,
1622 rcsw.message.sAddress.number_type);
Wink Savillef4c4d362009-04-02 01:37:03 -07001623 closeRequest;
1624
1625 printRequest(pRI->token, pRI->pCI->requestNumber);
1626
Etan Cohend3652192014-06-20 08:28:44 -07001627 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsw, sizeof(rcsw),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001628
1629#ifdef MEMSET_FREED
1630 memset(&rcsw, 0, sizeof(rcsw));
1631#endif
1632
1633 return;
1634
1635invalid:
1636 invalidCommandBlock(pRI);
1637 return;
1638
1639}
1640
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -07001641// For backwards compatibility in RIL_REQUEST_SETUP_DATA_CALL.
1642// Version 4 of the RIL interface adds a new PDP type parameter to support
1643// IPv6 and dual-stack PDP contexts. When dealing with a previous version of
1644// RIL, remove the parameter from the request.
1645static void dispatchDataCall(Parcel& p, RequestInfo *pRI) {
1646 // In RIL v3, REQUEST_SETUP_DATA_CALL takes 6 parameters.
1647 const int numParamsRilV3 = 6;
1648
1649 // The first bytes of the RIL parcel contain the request number and the
1650 // serial number - see processCommandBuffer(). Copy them over too.
1651 int pos = p.dataPosition();
1652
1653 int numParams = p.readInt32();
1654 if (s_callbacks.version < 4 && numParams > numParamsRilV3) {
1655 Parcel p2;
1656 p2.appendFrom(&p, 0, pos);
1657 p2.writeInt32(numParamsRilV3);
1658 for(int i = 0; i < numParamsRilV3; i++) {
1659 p2.writeString16(p.readString16());
1660 }
1661 p2.setDataPosition(pos);
1662 dispatchStrings(p2, pRI);
1663 } else {
Lorenzo Colitti57ce1f22010-09-13 12:23:50 -07001664 p.setDataPosition(pos);
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -07001665 dispatchStrings(p, pRI);
1666 }
1667}
1668
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001669// For backwards compatibility with RILs that dont support RIL_REQUEST_VOICE_RADIO_TECH.
1670// When all RILs handle this request, this function can be removed and
1671// the request can be sent directly to the RIL using dispatchVoid.
1672static void dispatchVoiceRadioTech(Parcel& p, RequestInfo *pRI) {
Etan Cohend3652192014-06-20 08:28:44 -07001673 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001674
1675 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1676 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1677 }
1678
1679 // RILs that support RADIO_STATE_ON should support this request.
1680 if (RADIO_STATE_ON == state) {
1681 dispatchVoid(p, pRI);
1682 return;
1683 }
1684
1685 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1686 // will not support this new request either and decode Voice Radio Technology
1687 // from Radio State
1688 voiceRadioTech = decodeVoiceRadioTechnology(state);
1689
1690 if (voiceRadioTech < 0)
1691 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1692 else
1693 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &voiceRadioTech, sizeof(int));
1694}
1695
1696// For backwards compatibility in RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE:.
1697// When all RILs handle this request, this function can be removed and
1698// the request can be sent directly to the RIL using dispatchVoid.
1699static void dispatchCdmaSubscriptionSource(Parcel& p, RequestInfo *pRI) {
Etan Cohend3652192014-06-20 08:28:44 -07001700 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001701
1702 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1703 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1704 }
1705
1706 // RILs that support RADIO_STATE_ON should support this request.
1707 if (RADIO_STATE_ON == state) {
1708 dispatchVoid(p, pRI);
1709 return;
1710 }
1711
1712 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1713 // will not support this new request either and decode CDMA Subscription Source
1714 // from Radio State
1715 cdmaSubscriptionSource = decodeCdmaSubscriptionSource(state);
1716
1717 if (cdmaSubscriptionSource < 0)
1718 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1719 else
1720 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &cdmaSubscriptionSource, sizeof(int));
1721}
1722
Sungmin Choi75697532013-04-26 15:04:45 -07001723static void dispatchSetInitialAttachApn(Parcel &p, RequestInfo *pRI)
1724{
1725 RIL_InitialAttachApn pf;
1726 int32_t t;
1727 status_t status;
1728
1729 memset(&pf, 0, sizeof(pf));
1730
1731 pf.apn = strdupReadString(p);
1732 pf.protocol = strdupReadString(p);
1733
1734 status = p.readInt32(&t);
1735 pf.authtype = (int) t;
1736
1737 pf.username = strdupReadString(p);
1738 pf.password = strdupReadString(p);
1739
1740 startRequest;
Etan Cohen5d891b72014-02-27 17:25:17 -08001741 appendPrintBuf("%sapn=%s, protocol=%s, authtype=%d, username=%s, password=%s",
1742 printBuf, pf.apn, pf.protocol, pf.authtype, pf.username, pf.password);
Sungmin Choi75697532013-04-26 15:04:45 -07001743 closeRequest;
1744 printRequest(pRI->token, pRI->pCI->requestNumber);
1745
1746 if (status != NO_ERROR) {
1747 goto invalid;
1748 }
Etan Cohend3652192014-06-20 08:28:44 -07001749 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
Sungmin Choi75697532013-04-26 15:04:45 -07001750
1751#ifdef MEMSET_FREED
1752 memsetString(pf.apn);
1753 memsetString(pf.protocol);
1754 memsetString(pf.username);
1755 memsetString(pf.password);
1756#endif
1757
1758 free(pf.apn);
1759 free(pf.protocol);
1760 free(pf.username);
1761 free(pf.password);
1762
1763#ifdef MEMSET_FREED
1764 memset(&pf, 0, sizeof(pf));
1765#endif
1766
1767 return;
1768invalid:
1769 invalidCommandBlock(pRI);
1770 return;
1771}
1772
Jake Hamby8a4a2332014-01-15 13:12:05 -08001773static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI) {
1774 RIL_NV_ReadItem nvri;
1775 int32_t t;
1776 status_t status;
1777
1778 memset(&nvri, 0, sizeof(nvri));
1779
1780 status = p.readInt32(&t);
1781 nvri.itemID = (RIL_NV_Item) t;
1782
1783 if (status != NO_ERROR) {
1784 goto invalid;
1785 }
1786
1787 startRequest;
1788 appendPrintBuf("%snvri.itemID=%d, ", printBuf, nvri.itemID);
1789 closeRequest;
1790
1791 printRequest(pRI->token, pRI->pCI->requestNumber);
1792
Etan Cohend3652192014-06-20 08:28:44 -07001793 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvri, sizeof(nvri), pRI, pRI->socket_id);
Jake Hamby8a4a2332014-01-15 13:12:05 -08001794
1795#ifdef MEMSET_FREED
1796 memset(&nvri, 0, sizeof(nvri));
1797#endif
1798
1799 return;
1800
1801invalid:
1802 invalidCommandBlock(pRI);
1803 return;
1804}
1805
1806static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI) {
1807 RIL_NV_WriteItem nvwi;
1808 int32_t t;
1809 status_t status;
1810
1811 memset(&nvwi, 0, sizeof(nvwi));
1812
1813 status = p.readInt32(&t);
1814 nvwi.itemID = (RIL_NV_Item) t;
1815
1816 nvwi.value = strdupReadString(p);
1817
1818 if (status != NO_ERROR || nvwi.value == NULL) {
1819 goto invalid;
1820 }
1821
1822 startRequest;
1823 appendPrintBuf("%snvwi.itemID=%d, value=%s, ", printBuf, nvwi.itemID,
1824 nvwi.value);
1825 closeRequest;
1826
1827 printRequest(pRI->token, pRI->pCI->requestNumber);
1828
Etan Cohend3652192014-06-20 08:28:44 -07001829 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvwi, sizeof(nvwi), pRI, pRI->socket_id);
Jake Hamby8a4a2332014-01-15 13:12:05 -08001830
1831#ifdef MEMSET_FREED
1832 memsetString(nvwi.value);
1833#endif
1834
1835 free(nvwi.value);
1836
1837#ifdef MEMSET_FREED
1838 memset(&nvwi, 0, sizeof(nvwi));
1839#endif
1840
1841 return;
1842
1843invalid:
1844 invalidCommandBlock(pRI);
1845 return;
1846}
1847
1848
Etan Cohend3652192014-06-20 08:28:44 -07001849static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI) {
1850 RIL_SelectUiccSub uicc_sub;
1851 status_t status;
1852 int32_t t;
1853 memset(&uicc_sub, 0, sizeof(uicc_sub));
1854
1855 status = p.readInt32(&t);
1856 if (status != NO_ERROR) {
1857 goto invalid;
1858 }
1859 uicc_sub.slot = (int) t;
1860
1861 status = p.readInt32(&t);
1862 if (status != NO_ERROR) {
1863 goto invalid;
1864 }
1865 uicc_sub.app_index = (int) t;
1866
1867 status = p.readInt32(&t);
1868 if (status != NO_ERROR) {
1869 goto invalid;
1870 }
1871 uicc_sub.sub_type = (RIL_SubscriptionType) t;
1872
1873 status = p.readInt32(&t);
1874 if (status != NO_ERROR) {
1875 goto invalid;
1876 }
1877 uicc_sub.act_status = (RIL_UiccSubActStatus) t;
1878
1879 startRequest;
1880 appendPrintBuf("slot=%d, app_index=%d, act_status = %d", uicc_sub.slot, uicc_sub.app_index,
1881 uicc_sub.act_status);
1882 RLOGD("dispatchUiccSubscription, slot=%d, app_index=%d, act_status = %d", uicc_sub.slot,
1883 uicc_sub.app_index, uicc_sub.act_status);
1884 closeRequest;
1885 printRequest(pRI->token, pRI->pCI->requestNumber);
1886
1887 CALL_ONREQUEST(pRI->pCI->requestNumber, &uicc_sub, sizeof(uicc_sub), pRI, pRI->socket_id);
1888
1889#ifdef MEMSET_FREED
1890 memset(&uicc_sub, 0, sizeof(uicc_sub));
1891#endif
1892 return;
1893
1894invalid:
1895 invalidCommandBlock(pRI);
1896 return;
1897}
1898
Amit Mahajan90530a62014-07-01 15:54:08 -07001899static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI)
1900{
1901 RIL_SimAuthentication pf;
1902 int32_t t;
1903 status_t status;
1904
1905 memset(&pf, 0, sizeof(pf));
1906
1907 status = p.readInt32(&t);
1908 pf.authContext = (int) t;
1909 pf.authData = strdupReadString(p);
1910 pf.aid = strdupReadString(p);
1911
1912 startRequest;
1913 appendPrintBuf("authContext=%s, authData=%s, aid=%s", pf.authContext, pf.authData, pf.aid);
1914 closeRequest;
1915 printRequest(pRI->token, pRI->pCI->requestNumber);
1916
1917 if (status != NO_ERROR) {
1918 goto invalid;
1919 }
1920 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
1921
1922#ifdef MEMSET_FREED
1923 memsetString(pf.authData);
1924 memsetString(pf.aid);
1925#endif
1926
1927 free(pf.authData);
1928 free(pf.aid);
1929
1930#ifdef MEMSET_FREED
1931 memset(&pf, 0, sizeof(pf));
1932#endif
1933
1934 return;
1935invalid:
1936 invalidCommandBlock(pRI);
1937 return;
1938}
1939
Amit Mahajanc796e222014-08-13 16:54:01 +00001940static void dispatchDataProfile(Parcel &p, RequestInfo *pRI) {
1941 int32_t t;
1942 status_t status;
1943 int32_t num;
1944
1945 status = p.readInt32(&num);
1946 if (status != NO_ERROR) {
1947 goto invalid;
1948 }
1949
1950 {
1951 RIL_DataProfileInfo dataProfiles[num];
1952 RIL_DataProfileInfo *dataProfilePtrs[num];
1953
1954 startRequest;
1955 for (int i = 0 ; i < num ; i++ ) {
1956 dataProfilePtrs[i] = &dataProfiles[i];
1957
1958 status = p.readInt32(&t);
1959 dataProfiles[i].profileId = (int) t;
1960
1961 dataProfiles[i].apn = strdupReadString(p);
1962 dataProfiles[i].protocol = strdupReadString(p);
1963 status = p.readInt32(&t);
1964 dataProfiles[i].authType = (int) t;
1965
1966 dataProfiles[i].user = strdupReadString(p);
1967 dataProfiles[i].password = strdupReadString(p);
1968
1969 status = p.readInt32(&t);
1970 dataProfiles[i].type = (int) t;
1971
1972 status = p.readInt32(&t);
1973 dataProfiles[i].maxConnsTime = (int) t;
1974 status = p.readInt32(&t);
1975 dataProfiles[i].maxConns = (int) t;
1976 status = p.readInt32(&t);
1977 dataProfiles[i].waitTime = (int) t;
1978
1979 status = p.readInt32(&t);
1980 dataProfiles[i].enabled = (int) t;
1981
1982 appendPrintBuf("%s [%d: profileId=%d, apn =%s, protocol =%s, authType =%d, \
1983 user =%s, password =%s, type =%d, maxConnsTime =%d, maxConns =%d, \
1984 waitTime =%d, enabled =%d]", printBuf, i, dataProfiles[i].profileId,
1985 dataProfiles[i].apn, dataProfiles[i].protocol, dataProfiles[i].authType,
1986 dataProfiles[i].user, dataProfiles[i].password, dataProfiles[i].type,
1987 dataProfiles[i].maxConnsTime, dataProfiles[i].maxConns,
1988 dataProfiles[i].waitTime, dataProfiles[i].enabled);
1989 }
1990 closeRequest;
1991 printRequest(pRI->token, pRI->pCI->requestNumber);
1992
1993 if (status != NO_ERROR) {
1994 goto invalid;
1995 }
1996 CALL_ONREQUEST(pRI->pCI->requestNumber,
1997 dataProfilePtrs,
1998 num * sizeof(RIL_DataProfileInfo *),
1999 pRI, pRI->socket_id);
2000
2001#ifdef MEMSET_FREED
2002 memset(dataProfiles, 0, num * sizeof(RIL_DataProfileInfo));
2003 memset(dataProfilePtrs, 0, num * sizeof(RIL_DataProfileInfo *));
2004#endif
2005 }
2006
2007 return;
2008
2009invalid:
2010 invalidCommandBlock(pRI);
2011 return;
2012}
2013
Wink Saville8b4e4f72014-10-17 15:01:45 -07002014static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI){
2015 RIL_RadioCapability rc;
2016 int32_t t;
2017 status_t status;
2018
2019 memset (&rc, 0, sizeof(RIL_RadioCapability));
2020
2021 status = p.readInt32(&t);
2022 rc.version = (int)t;
2023 if (status != NO_ERROR) {
2024 goto invalid;
2025 }
2026
2027 status = p.readInt32(&t);
2028 rc.session= (int)t;
2029 if (status != NO_ERROR) {
2030 goto invalid;
2031 }
2032
2033 status = p.readInt32(&t);
2034 rc.phase= (int)t;
2035 if (status != NO_ERROR) {
2036 goto invalid;
2037 }
2038
2039 status = p.readInt32(&t);
2040 rc.rat = (int)t;
2041 if (status != NO_ERROR) {
2042 goto invalid;
2043 }
2044
2045 status = readStringFromParcelInplace(p, rc.logicalModemUuid, sizeof(rc.logicalModemUuid));
2046 if (status != NO_ERROR) {
2047 goto invalid;
2048 }
2049
2050 status = p.readInt32(&t);
2051 rc.status = (int)t;
2052
2053 if (status != NO_ERROR) {
2054 goto invalid;
2055 }
2056
2057 startRequest;
2058 appendPrintBuf("%s [version:%d, session:%d, phase:%d, rat:%d, \
Chih-Wei Huang8593f262015-10-02 15:09:52 +08002059 logicalModemUuid:%s, status:%d", printBuf, rc.version, rc.session,
Legler Wu8caf06f2014-10-29 14:02:14 +08002060 rc.phase, rc.rat, rc.logicalModemUuid, rc.session);
Wink Saville8b4e4f72014-10-17 15:01:45 -07002061
2062 closeRequest;
2063 printRequest(pRI->token, pRI->pCI->requestNumber);
2064
2065 CALL_ONREQUEST(pRI->pCI->requestNumber,
2066 &rc,
2067 sizeof(RIL_RadioCapability),
2068 pRI, pRI->socket_id);
2069 return;
2070invalid:
2071 invalidCommandBlock(pRI);
2072 return;
2073}
2074
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002075static int
Wink Savillef4c4d362009-04-02 01:37:03 -07002076blockingWrite(int fd, const void *buffer, size_t len) {
Wink Saville7f856802009-06-09 10:23:37 -07002077 size_t writeOffset = 0;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002078 const uint8_t *toWrite;
2079
2080 toWrite = (const uint8_t *)buffer;
2081
2082 while (writeOffset < len) {
2083 ssize_t written;
2084 do {
2085 written = write (fd, toWrite + writeOffset,
2086 len - writeOffset);
Banavathu, Srinivas Naik38884902011-07-05 20:04:25 +05302087 } while (written < 0 && ((errno == EINTR) || (errno == EAGAIN)));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002088
2089 if (written >= 0) {
2090 writeOffset += written;
2091 } else { // written < 0
Wink Saville8eb2a122012-11-19 16:05:13 -08002092 RLOGE ("RIL Response: unexpected error on write errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002093 close(fd);
2094 return -1;
2095 }
2096 }
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07002097#if VDBG
Dheeraj Shetty27976c42014-07-02 21:27:57 +02002098 RLOGE("RIL Response bytes written:%d", writeOffset);
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07002099#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002100 return 0;
2101}
2102
2103static int
Etan Cohend3652192014-06-20 08:28:44 -07002104sendResponseRaw (const void *data, size_t dataSize, RIL_SOCKET_ID socket_id) {
2105 int fd = s_ril_param_socket.fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002106 int ret;
2107 uint32_t header;
Etan Cohend3652192014-06-20 08:28:44 -07002108 pthread_mutex_t * writeMutexHook = &s_writeMutex;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002109
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07002110#if VDBG
Etan Cohend3652192014-06-20 08:28:44 -07002111 RLOGE("Send Response to %s", rilSocketIdToString(socket_id));
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07002112#endif
Etan Cohend3652192014-06-20 08:28:44 -07002113
2114#if (SIM_COUNT >= 2)
2115 if (socket_id == RIL_SOCKET_2) {
2116 fd = s_ril_param_socket2.fdCommand;
2117 writeMutexHook = &s_writeMutex_socket2;
2118 }
2119#if (SIM_COUNT >= 3)
2120 else if (socket_id == RIL_SOCKET_3) {
2121 fd = s_ril_param_socket3.fdCommand;
2122 writeMutexHook = &s_writeMutex_socket3;
2123 }
2124#endif
2125#if (SIM_COUNT >= 4)
2126 else if (socket_id == RIL_SOCKET_4) {
2127 fd = s_ril_param_socket4.fdCommand;
2128 writeMutexHook = &s_writeMutex_socket4;
2129 }
2130#endif
2131#endif
2132 if (fd < 0) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002133 return -1;
2134 }
2135
2136 if (dataSize > MAX_COMMAND_BYTES) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002137 RLOGE("RIL: packet larger than %u (%u)",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002138 MAX_COMMAND_BYTES, (unsigned int )dataSize);
2139
2140 return -1;
2141 }
Wink Saville7f856802009-06-09 10:23:37 -07002142
Etan Cohend3652192014-06-20 08:28:44 -07002143 pthread_mutex_lock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002144
2145 header = htonl(dataSize);
2146
2147 ret = blockingWrite(fd, (void *)&header, sizeof(header));
2148
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
Kennyee1fadc2009-08-13 00:45:53 +08002154 ret = blockingWrite(fd, data, dataSize);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002155
2156 if (ret < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002157 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002158 return ret;
2159 }
2160
Etan Cohend3652192014-06-20 08:28:44 -07002161 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002162
2163 return 0;
2164}
2165
2166static int
Etan Cohend3652192014-06-20 08:28:44 -07002167sendResponse (Parcel &p, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002168 printResponse;
Etan Cohend3652192014-06-20 08:28:44 -07002169 return sendResponseRaw(p.data(), p.dataSize(), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002170}
2171
Mohamad Ayyash74f7e662014-04-18 11:43:28 -07002172/** response is an int* pointing to an array of ints */
Wink Saville7f856802009-06-09 10:23:37 -07002173
2174static int
Wink Savillef4c4d362009-04-02 01:37:03 -07002175responseInts(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002176 int numInts;
2177
2178 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002179 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002180 return RIL_ERRNO_INVALID_RESPONSE;
2181 }
2182 if (responselen % sizeof(int) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002183 RLOGE("responseInts: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002184 (int)responselen, (int)sizeof(int));
2185 return RIL_ERRNO_INVALID_RESPONSE;
2186 }
2187
2188 int *p_int = (int *) response;
2189
Mohamad Ayyash74f7e662014-04-18 11:43:28 -07002190 numInts = responselen / sizeof(int);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002191 p.writeInt32 (numInts);
2192
2193 /* each int*/
2194 startResponse;
2195 for (int i = 0 ; i < numInts ; i++) {
2196 appendPrintBuf("%s%d,", printBuf, p_int[i]);
2197 p.writeInt32(p_int[i]);
2198 }
2199 removeLastChar;
2200 closeResponse;
2201
2202 return 0;
2203}
2204
Chao Liu548a81e2015-05-14 16:13:46 -07002205// Response is an int or RIL_LastCallFailCauseInfo.
2206// Currently, only Shamu plans to use RIL_LastCallFailCauseInfo.
2207// TODO(yjl): Let all implementations use RIL_LastCallFailCauseInfo.
2208static int responseFailCause(Parcel &p, void *response, size_t responselen) {
2209 if (response == NULL && responselen != 0) {
2210 RLOGE("invalid response: NULL");
2211 return RIL_ERRNO_INVALID_RESPONSE;
2212 }
2213
2214 if (responselen == sizeof(int)) {
Sungmin Choia408c252015-07-01 16:22:46 +09002215 startResponse;
2216 int *p_int = (int *) response;
2217 appendPrintBuf("%s%d,", printBuf, p_int[0]);
2218 p.writeInt32(p_int[0]);
2219 removeLastChar;
2220 closeResponse;
Chao Liu548a81e2015-05-14 16:13:46 -07002221 } else if (responselen == sizeof(RIL_LastCallFailCauseInfo)) {
2222 startResponse;
2223 RIL_LastCallFailCauseInfo *p_fail_cause_info = (RIL_LastCallFailCauseInfo *) response;
2224 appendPrintBuf("%s[cause_code=%d,vendor_cause=%s]", printBuf, p_fail_cause_info->cause_code,
2225 p_fail_cause_info->vendor_cause);
2226 p.writeInt32(p_fail_cause_info->cause_code);
2227 writeStringToParcel(p, p_fail_cause_info->vendor_cause);
2228 removeLastChar;
2229 closeResponse;
2230 } else {
2231 RLOGE("responseFailCause: invalid response length %d expected an int or "
2232 "RIL_LastCallFailCauseInfo", (int)responselen);
2233 return RIL_ERRNO_INVALID_RESPONSE;
2234 }
2235
2236 return 0;
2237}
2238
Wink Saville43808972011-01-13 17:39:51 -08002239/** response is a char **, pointing to an array of char *'s
2240 The parcel will begin with the version */
2241static int responseStringsWithVersion(int version, Parcel &p, void *response, size_t responselen) {
2242 p.writeInt32(version);
2243 return responseStrings(p, response, responselen);
2244}
2245
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002246/** response is a char **, pointing to an array of char *'s */
Wink Savillef4c4d362009-04-02 01:37:03 -07002247static int responseStrings(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002248 int numStrings;
Wink Saville7f856802009-06-09 10:23:37 -07002249
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002250 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002251 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002252 return RIL_ERRNO_INVALID_RESPONSE;
2253 }
2254 if (responselen % sizeof(char *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002255 RLOGE("responseStrings: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002256 (int)responselen, (int)sizeof(char *));
2257 return RIL_ERRNO_INVALID_RESPONSE;
2258 }
2259
2260 if (response == NULL) {
2261 p.writeInt32 (0);
2262 } else {
2263 char **p_cur = (char **) response;
2264
2265 numStrings = responselen / sizeof(char *);
2266 p.writeInt32 (numStrings);
2267
2268 /* each string*/
2269 startResponse;
2270 for (int i = 0 ; i < numStrings ; i++) {
2271 appendPrintBuf("%s%s,", printBuf, (char*)p_cur[i]);
2272 writeStringToParcel (p, p_cur[i]);
2273 }
2274 removeLastChar;
2275 closeResponse;
2276 }
2277 return 0;
2278}
2279
2280
2281/**
Wink Saville7f856802009-06-09 10:23:37 -07002282 * NULL strings are accepted
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002283 * FIXME currently ignores responselen
2284 */
Wink Savillef4c4d362009-04-02 01:37:03 -07002285static int responseString(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002286 /* one string only */
2287 startResponse;
2288 appendPrintBuf("%s%s", printBuf, (char*)response);
2289 closeResponse;
2290
2291 writeStringToParcel(p, (const char *)response);
2292
2293 return 0;
2294}
2295
Wink Savillef4c4d362009-04-02 01:37:03 -07002296static int responseVoid(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002297 startResponse;
2298 removeLastChar;
2299 return 0;
2300}
2301
Wink Savillef4c4d362009-04-02 01:37:03 -07002302static int responseCallList(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002303 int num;
2304
2305 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002306 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002307 return RIL_ERRNO_INVALID_RESPONSE;
2308 }
2309
2310 if (responselen % sizeof (RIL_Call *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002311 RLOGE("responseCallList: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002312 (int)responselen, (int)sizeof (RIL_Call *));
2313 return RIL_ERRNO_INVALID_RESPONSE;
2314 }
2315
2316 startResponse;
2317 /* number of call info's */
2318 num = responselen / sizeof(RIL_Call *);
2319 p.writeInt32(num);
2320
2321 for (int i = 0 ; i < num ; i++) {
2322 RIL_Call *p_cur = ((RIL_Call **) response)[i];
2323 /* each call info */
2324 p.writeInt32(p_cur->state);
2325 p.writeInt32(p_cur->index);
2326 p.writeInt32(p_cur->toa);
2327 p.writeInt32(p_cur->isMpty);
2328 p.writeInt32(p_cur->isMT);
2329 p.writeInt32(p_cur->als);
2330 p.writeInt32(p_cur->isVoice);
Wink Saville1b5fd232009-04-22 14:50:00 -07002331 p.writeInt32(p_cur->isVoicePrivacy);
2332 writeStringToParcel(p, p_cur->number);
John Wangff368742009-03-24 17:56:29 -07002333 p.writeInt32(p_cur->numberPresentation);
Wink Saville1b5fd232009-04-22 14:50:00 -07002334 writeStringToParcel(p, p_cur->name);
2335 p.writeInt32(p_cur->namePresentation);
Wink Saville3a4840b2010-04-07 13:29:58 -07002336 // Remove when partners upgrade to version 3
Wink Saville74fa3882009-12-22 15:35:41 -08002337 if ((s_callbacks.version < 3) || (p_cur->uusInfo == NULL || p_cur->uusInfo->uusData == NULL)) {
2338 p.writeInt32(0); /* UUS Information is absent */
2339 } else {
2340 RIL_UUS_Info *uusInfo = p_cur->uusInfo;
2341 p.writeInt32(1); /* UUS Information is present */
2342 p.writeInt32(uusInfo->uusType);
2343 p.writeInt32(uusInfo->uusDcs);
2344 p.writeInt32(uusInfo->uusLength);
2345 p.write(uusInfo->uusData, uusInfo->uusLength);
2346 }
Wink Saville3d54e742009-05-18 18:00:44 -07002347 appendPrintBuf("%s[id=%d,%s,toa=%d,",
John Wangff368742009-03-24 17:56:29 -07002348 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002349 p_cur->index,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002350 callStateToString(p_cur->state),
Wink Saville3d54e742009-05-18 18:00:44 -07002351 p_cur->toa);
2352 appendPrintBuf("%s%s,%s,als=%d,%s,%s,",
2353 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002354 (p_cur->isMpty)?"conf":"norm",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002355 (p_cur->isMT)?"mt":"mo",
2356 p_cur->als,
2357 (p_cur->isVoice)?"voc":"nonvoc",
Wink Saville3d54e742009-05-18 18:00:44 -07002358 (p_cur->isVoicePrivacy)?"evp":"noevp");
2359 appendPrintBuf("%s%s,cli=%d,name='%s',%d]",
2360 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002361 p_cur->number,
2362 p_cur->numberPresentation,
2363 p_cur->name,
2364 p_cur->namePresentation);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002365 }
2366 removeLastChar;
2367 closeResponse;
2368
2369 return 0;
2370}
2371
Wink Savillef4c4d362009-04-02 01:37:03 -07002372static int responseSMS(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002373 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002374 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002375 return RIL_ERRNO_INVALID_RESPONSE;
2376 }
2377
2378 if (responselen != sizeof (RIL_SMS_Response) ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002379 RLOGE("invalid response length %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002380 (int)responselen, (int)sizeof (RIL_SMS_Response));
2381 return RIL_ERRNO_INVALID_RESPONSE;
2382 }
2383
2384 RIL_SMS_Response *p_cur = (RIL_SMS_Response *) response;
2385
2386 p.writeInt32(p_cur->messageRef);
2387 writeStringToParcel(p, p_cur->ackPDU);
Jaikumar Ganesh920c78f2009-06-04 10:53:15 -07002388 p.writeInt32(p_cur->errorCode);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002389
2390 startResponse;
Jaikumar Ganesh920c78f2009-06-04 10:53:15 -07002391 appendPrintBuf("%s%d,%s,%d", printBuf, p_cur->messageRef,
2392 (char*)p_cur->ackPDU, p_cur->errorCode);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002393 closeResponse;
2394
2395 return 0;
2396}
2397
Wink Savillec0114b32011-02-18 10:14:07 -08002398static int responseDataCallListV4(Parcel &p, void *response, size_t responselen)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002399{
2400 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002401 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002402 return RIL_ERRNO_INVALID_RESPONSE;
2403 }
2404
Wink Savillec0114b32011-02-18 10:14:07 -08002405 if (responselen % sizeof(RIL_Data_Call_Response_v4) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002406 RLOGE("responseDataCallListV4: invalid response length %d expected multiple of %d",
Wink Savillec0114b32011-02-18 10:14:07 -08002407 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v4));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002408 return RIL_ERRNO_INVALID_RESPONSE;
2409 }
2410
Amit Mahajan52500162014-07-29 17:36:48 -07002411 // Write version
2412 p.writeInt32(4);
2413
Wink Savillec0114b32011-02-18 10:14:07 -08002414 int num = responselen / sizeof(RIL_Data_Call_Response_v4);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002415 p.writeInt32(num);
2416
Wink Savillec0114b32011-02-18 10:14:07 -08002417 RIL_Data_Call_Response_v4 *p_cur = (RIL_Data_Call_Response_v4 *) response;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002418 startResponse;
2419 int i;
2420 for (i = 0; i < num; i++) {
2421 p.writeInt32(p_cur[i].cid);
2422 p.writeInt32(p_cur[i].active);
2423 writeStringToParcel(p, p_cur[i].type);
Wink Savillec0114b32011-02-18 10:14:07 -08002424 // apn is not used, so don't send.
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002425 writeStringToParcel(p, p_cur[i].address);
Wink Savillec0114b32011-02-18 10:14:07 -08002426 appendPrintBuf("%s[cid=%d,%s,%s,%s],", printBuf,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002427 p_cur[i].cid,
2428 (p_cur[i].active==0)?"down":"up",
2429 (char*)p_cur[i].type,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002430 (char*)p_cur[i].address);
2431 }
2432 removeLastChar;
2433 closeResponse;
2434
2435 return 0;
2436}
2437
Etan Cohend3652192014-06-20 08:28:44 -07002438static int responseDataCallListV6(Parcel &p, void *response, size_t responselen)
2439{
Amit Mahajan52500162014-07-29 17:36:48 -07002440 if (response == NULL && responselen != 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002441 RLOGE("invalid response: NULL");
2442 return RIL_ERRNO_INVALID_RESPONSE;
2443 }
2444
2445 if (responselen % sizeof(RIL_Data_Call_Response_v6) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002446 RLOGE("responseDataCallListV6: invalid response length %d expected multiple of %d",
Etan Cohend3652192014-06-20 08:28:44 -07002447 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v6));
2448 return RIL_ERRNO_INVALID_RESPONSE;
2449 }
2450
Amit Mahajan52500162014-07-29 17:36:48 -07002451 // Write version
2452 p.writeInt32(6);
2453
Etan Cohend3652192014-06-20 08:28:44 -07002454 int num = responselen / sizeof(RIL_Data_Call_Response_v6);
2455 p.writeInt32(num);
2456
2457 RIL_Data_Call_Response_v6 *p_cur = (RIL_Data_Call_Response_v6 *) response;
2458 startResponse;
2459 int i;
2460 for (i = 0; i < num; i++) {
2461 p.writeInt32((int)p_cur[i].status);
2462 p.writeInt32(p_cur[i].suggestedRetryTime);
2463 p.writeInt32(p_cur[i].cid);
2464 p.writeInt32(p_cur[i].active);
2465 writeStringToParcel(p, p_cur[i].type);
2466 writeStringToParcel(p, p_cur[i].ifname);
2467 writeStringToParcel(p, p_cur[i].addresses);
2468 writeStringToParcel(p, p_cur[i].dnses);
2469 writeStringToParcel(p, p_cur[i].gateways);
2470 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s],", printBuf,
2471 p_cur[i].status,
2472 p_cur[i].suggestedRetryTime,
2473 p_cur[i].cid,
2474 (p_cur[i].active==0)?"down":"up",
2475 (char*)p_cur[i].type,
2476 (char*)p_cur[i].ifname,
2477 (char*)p_cur[i].addresses,
2478 (char*)p_cur[i].dnses,
2479 (char*)p_cur[i].gateways);
2480 }
2481 removeLastChar;
2482 closeResponse;
2483
2484 return 0;
2485}
2486
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002487static int responseDataCallListV9(Parcel &p, void *response, size_t responselen)
2488{
2489 if (response == NULL && responselen != 0) {
2490 RLOGE("invalid response: NULL");
2491 return RIL_ERRNO_INVALID_RESPONSE;
2492 }
2493
2494 if (responselen % sizeof(RIL_Data_Call_Response_v9) != 0) {
2495 RLOGE("responseDataCallListV9: invalid response length %d expected multiple of %d",
2496 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v9));
2497 return RIL_ERRNO_INVALID_RESPONSE;
2498 }
2499
2500 // Write version
2501 p.writeInt32(10);
2502
2503 int num = responselen / sizeof(RIL_Data_Call_Response_v9);
2504 p.writeInt32(num);
2505
2506 RIL_Data_Call_Response_v9 *p_cur = (RIL_Data_Call_Response_v9 *) response;
2507 startResponse;
2508 int i;
2509 for (i = 0; i < num; i++) {
2510 p.writeInt32((int)p_cur[i].status);
2511 p.writeInt32(p_cur[i].suggestedRetryTime);
2512 p.writeInt32(p_cur[i].cid);
2513 p.writeInt32(p_cur[i].active);
2514 writeStringToParcel(p, p_cur[i].type);
2515 writeStringToParcel(p, p_cur[i].ifname);
2516 writeStringToParcel(p, p_cur[i].addresses);
2517 writeStringToParcel(p, p_cur[i].dnses);
2518 writeStringToParcel(p, p_cur[i].gateways);
2519 writeStringToParcel(p, p_cur[i].pcscf);
2520 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s],", printBuf,
2521 p_cur[i].status,
2522 p_cur[i].suggestedRetryTime,
2523 p_cur[i].cid,
2524 (p_cur[i].active==0)?"down":"up",
2525 (char*)p_cur[i].type,
2526 (char*)p_cur[i].ifname,
2527 (char*)p_cur[i].addresses,
2528 (char*)p_cur[i].dnses,
2529 (char*)p_cur[i].gateways,
2530 (char*)p_cur[i].pcscf);
2531 }
2532 removeLastChar;
2533 closeResponse;
2534
2535 return 0;
2536}
2537
Sanket Padawe88cf6a52016-01-11 12:45:43 -08002538static int responseDataCallListV11(Parcel &p, void *response, size_t responselen) {
2539 if (response == NULL && responselen != 0) {
2540 RLOGE("invalid response: NULL");
2541 return RIL_ERRNO_INVALID_RESPONSE;
2542 }
2543
2544 if (responselen % sizeof(RIL_Data_Call_Response_v11) != 0) {
2545 RLOGE("invalid response length %d expected multiple of %d",
2546 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v11));
2547 return RIL_ERRNO_INVALID_RESPONSE;
2548 }
2549
2550 // Write version
2551 p.writeInt32(11);
2552
2553 int num = responselen / sizeof(RIL_Data_Call_Response_v11);
2554 p.writeInt32(num);
2555
2556 RIL_Data_Call_Response_v11 *p_cur = (RIL_Data_Call_Response_v11 *) response;
2557 startResponse;
2558 int i;
2559 for (i = 0; i < num; i++) {
2560 p.writeInt32((int)p_cur[i].status);
2561 p.writeInt32(p_cur[i].suggestedRetryTime);
2562 p.writeInt32(p_cur[i].cid);
2563 p.writeInt32(p_cur[i].active);
2564 writeStringToParcel(p, p_cur[i].type);
2565 writeStringToParcel(p, p_cur[i].ifname);
2566 writeStringToParcel(p, p_cur[i].addresses);
2567 writeStringToParcel(p, p_cur[i].dnses);
2568 writeStringToParcel(p, p_cur[i].gateways);
2569 writeStringToParcel(p, p_cur[i].pcscf);
2570 p.writeInt32(p_cur[i].mtu);
2571 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s,mtu=%d],", printBuf,
2572 p_cur[i].status,
2573 p_cur[i].suggestedRetryTime,
2574 p_cur[i].cid,
2575 (p_cur[i].active==0)?"down":"up",
2576 (char*)p_cur[i].type,
2577 (char*)p_cur[i].ifname,
2578 (char*)p_cur[i].addresses,
2579 (char*)p_cur[i].dnses,
2580 (char*)p_cur[i].gateways,
2581 (char*)p_cur[i].pcscf,
2582 p_cur[i].mtu);
2583 }
2584 removeLastChar;
2585 closeResponse;
2586
2587 return 0;
2588}
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002589
Wink Saville43808972011-01-13 17:39:51 -08002590static int responseDataCallList(Parcel &p, void *response, size_t responselen)
2591{
Sanket Padawe88cf6a52016-01-11 12:45:43 -08002592 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
2593 if (s_callbacks.version < 5) {
2594 RLOGD("responseDataCallList: v4");
2595 return responseDataCallListV4(p, response, responselen);
2596 } else if (responselen % sizeof(RIL_Data_Call_Response_v6) == 0) {
2597 return responseDataCallListV6(p, response, responselen);
2598 } else if (responselen % sizeof(RIL_Data_Call_Response_v9) == 0) {
2599 return responseDataCallListV9(p, response, responselen);
2600 } else {
2601 return responseDataCallListV11(p, response, responselen);
Wink Saville43808972011-01-13 17:39:51 -08002602 }
Sanket Padawef53c5fa2016-01-27 10:00:38 -08002603 } else { // RIL version >= 13
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002604 if (responselen % sizeof(RIL_Data_Call_Response_v11) != 0) {
Sanket Padawe88cf6a52016-01-11 12:45:43 -08002605 RLOGE("Data structure expected is RIL_Data_Call_Response_v11");
2606 if (!isDebuggable()) {
2607 return RIL_ERRNO_INVALID_RESPONSE;
2608 } else {
2609 assert(0);
2610 }
Wink Saville43808972011-01-13 17:39:51 -08002611 }
Sanket Padawe88cf6a52016-01-11 12:45:43 -08002612 return responseDataCallListV11(p, response, responselen);
Wink Saville43808972011-01-13 17:39:51 -08002613 }
Wink Saville43808972011-01-13 17:39:51 -08002614}
2615
2616static int responseSetupDataCall(Parcel &p, void *response, size_t responselen)
2617{
2618 if (s_callbacks.version < 5) {
2619 return responseStringsWithVersion(s_callbacks.version, p, response, responselen);
2620 } else {
2621 return responseDataCallList(p, response, responselen);
2622 }
2623}
2624
Wink Savillef4c4d362009-04-02 01:37:03 -07002625static int responseRaw(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002626 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002627 RLOGE("invalid response: NULL with responselen != 0");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002628 return RIL_ERRNO_INVALID_RESPONSE;
2629 }
2630
2631 // The java code reads -1 size as null byte array
2632 if (response == NULL) {
Wink Saville7f856802009-06-09 10:23:37 -07002633 p.writeInt32(-1);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002634 } else {
2635 p.writeInt32(responselen);
2636 p.write(response, responselen);
2637 }
2638
2639 return 0;
2640}
2641
2642
Wink Savillef4c4d362009-04-02 01:37:03 -07002643static int responseSIM_IO(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002644 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002645 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002646 return RIL_ERRNO_INVALID_RESPONSE;
2647 }
2648
2649 if (responselen != sizeof (RIL_SIM_IO_Response) ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002650 RLOGE("invalid response length was %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002651 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
2652 return RIL_ERRNO_INVALID_RESPONSE;
2653 }
2654
2655 RIL_SIM_IO_Response *p_cur = (RIL_SIM_IO_Response *) response;
2656 p.writeInt32(p_cur->sw1);
2657 p.writeInt32(p_cur->sw2);
2658 writeStringToParcel(p, p_cur->simResponse);
2659
2660 startResponse;
2661 appendPrintBuf("%ssw1=0x%X,sw2=0x%X,%s", printBuf, p_cur->sw1, p_cur->sw2,
2662 (char*)p_cur->simResponse);
2663 closeResponse;
2664
2665
2666 return 0;
2667}
2668
Wink Savillef4c4d362009-04-02 01:37:03 -07002669static int responseCallForwards(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002670 int num;
Wink Saville7f856802009-06-09 10:23:37 -07002671
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002672 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002673 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002674 return RIL_ERRNO_INVALID_RESPONSE;
2675 }
2676
2677 if (responselen % sizeof(RIL_CallForwardInfo *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002678 RLOGE("responseCallForwards: invalid response length %d expected multiple of %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002679 (int)responselen, (int)sizeof(RIL_CallForwardInfo *));
2680 return RIL_ERRNO_INVALID_RESPONSE;
2681 }
2682
2683 /* number of call info's */
2684 num = responselen / sizeof(RIL_CallForwardInfo *);
2685 p.writeInt32(num);
2686
2687 startResponse;
2688 for (int i = 0 ; i < num ; i++) {
2689 RIL_CallForwardInfo *p_cur = ((RIL_CallForwardInfo **) response)[i];
2690
2691 p.writeInt32(p_cur->status);
2692 p.writeInt32(p_cur->reason);
2693 p.writeInt32(p_cur->serviceClass);
2694 p.writeInt32(p_cur->toa);
2695 writeStringToParcel(p, p_cur->number);
2696 p.writeInt32(p_cur->timeSeconds);
2697 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
2698 (p_cur->status==1)?"enable":"disable",
2699 p_cur->reason, p_cur->serviceClass, p_cur->toa,
2700 (char*)p_cur->number,
2701 p_cur->timeSeconds);
2702 }
2703 removeLastChar;
2704 closeResponse;
Wink Saville7f856802009-06-09 10:23:37 -07002705
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002706 return 0;
2707}
2708
Wink Savillef4c4d362009-04-02 01:37:03 -07002709static int responseSsn(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002710 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002711 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002712 return RIL_ERRNO_INVALID_RESPONSE;
2713 }
2714
2715 if (responselen != sizeof(RIL_SuppSvcNotification)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002716 RLOGE("invalid response length was %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002717 (int)responselen, (int)sizeof (RIL_SuppSvcNotification));
2718 return RIL_ERRNO_INVALID_RESPONSE;
2719 }
2720
2721 RIL_SuppSvcNotification *p_cur = (RIL_SuppSvcNotification *) response;
2722 p.writeInt32(p_cur->notificationType);
2723 p.writeInt32(p_cur->code);
2724 p.writeInt32(p_cur->index);
2725 p.writeInt32(p_cur->type);
2726 writeStringToParcel(p, p_cur->number);
2727
2728 startResponse;
2729 appendPrintBuf("%s%s,code=%d,id=%d,type=%d,%s", printBuf,
2730 (p_cur->notificationType==0)?"mo":"mt",
2731 p_cur->code, p_cur->index, p_cur->type,
2732 (char*)p_cur->number);
2733 closeResponse;
2734
2735 return 0;
2736}
2737
Wink Saville3d54e742009-05-18 18:00:44 -07002738static int responseCellList(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002739 int num;
2740
2741 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002742 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002743 return RIL_ERRNO_INVALID_RESPONSE;
2744 }
2745
2746 if (responselen % sizeof (RIL_NeighboringCell *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002747 RLOGE("responseCellList: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002748 (int)responselen, (int)sizeof (RIL_NeighboringCell *));
2749 return RIL_ERRNO_INVALID_RESPONSE;
2750 }
2751
2752 startResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002753 /* number of records */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002754 num = responselen / sizeof(RIL_NeighboringCell *);
2755 p.writeInt32(num);
2756
2757 for (int i = 0 ; i < num ; i++) {
2758 RIL_NeighboringCell *p_cur = ((RIL_NeighboringCell **) response)[i];
2759
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002760 p.writeInt32(p_cur->rssi);
2761 writeStringToParcel (p, p_cur->cid);
2762
2763 appendPrintBuf("%s[cid=%s,rssi=%d],", printBuf,
2764 p_cur->cid, p_cur->rssi);
2765 }
2766 removeLastChar;
2767 closeResponse;
2768
2769 return 0;
2770}
2771
Wink Saville3d54e742009-05-18 18:00:44 -07002772/**
2773 * Marshall the signalInfoRecord into the parcel if it exists.
2774 */
Wink Savillea592eeb2009-05-22 13:26:36 -07002775static void marshallSignalInfoRecord(Parcel &p,
2776 RIL_CDMA_SignalInfoRecord &p_signalInfoRecord) {
Wink Saville3d54e742009-05-18 18:00:44 -07002777 p.writeInt32(p_signalInfoRecord.isPresent);
2778 p.writeInt32(p_signalInfoRecord.signalType);
2779 p.writeInt32(p_signalInfoRecord.alertPitch);
2780 p.writeInt32(p_signalInfoRecord.signal);
2781}
2782
Wink Savillea592eeb2009-05-22 13:26:36 -07002783static int responseCdmaInformationRecords(Parcel &p,
2784 void *response, size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07002785 int num;
Wink Savillea592eeb2009-05-22 13:26:36 -07002786 char* string8 = NULL;
2787 int buffer_lenght;
2788 RIL_CDMA_InformationRecord *infoRec;
Wink Saville3d54e742009-05-18 18:00:44 -07002789
2790 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002791 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002792 return RIL_ERRNO_INVALID_RESPONSE;
2793 }
2794
Wink Savillea592eeb2009-05-22 13:26:36 -07002795 if (responselen != sizeof (RIL_CDMA_InformationRecords)) {
Amit Mahajan52500162014-07-29 17:36:48 -07002796 RLOGE("responseCdmaInformationRecords: invalid response length %d expected multiple of %d\n",
Wink Savillea592eeb2009-05-22 13:26:36 -07002797 (int)responselen, (int)sizeof (RIL_CDMA_InformationRecords *));
Wink Saville3d54e742009-05-18 18:00:44 -07002798 return RIL_ERRNO_INVALID_RESPONSE;
2799 }
2800
Wink Savillea592eeb2009-05-22 13:26:36 -07002801 RIL_CDMA_InformationRecords *p_cur =
2802 (RIL_CDMA_InformationRecords *) response;
2803 num = MIN(p_cur->numberOfInfoRecs, RIL_CDMA_MAX_NUMBER_OF_INFO_RECS);
Wink Saville3d54e742009-05-18 18:00:44 -07002804
2805 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07002806 p.writeInt32(num);
Wink Saville3d54e742009-05-18 18:00:44 -07002807
Wink Savillea592eeb2009-05-22 13:26:36 -07002808 for (int i = 0 ; i < num ; i++) {
2809 infoRec = &p_cur->infoRec[i];
2810 p.writeInt32(infoRec->name);
2811 switch (infoRec->name) {
Wink Saville3d54e742009-05-18 18:00:44 -07002812 case RIL_CDMA_DISPLAY_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002813 case RIL_CDMA_EXTENDED_DISPLAY_INFO_REC:
2814 if (infoRec->rec.display.alpha_len >
2815 CDMA_ALPHA_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002816 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002817 expected not more than %d\n",
2818 (int)infoRec->rec.display.alpha_len,
2819 CDMA_ALPHA_INFO_BUFFER_LENGTH);
2820 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002821 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002822 string8 = (char*) malloc((infoRec->rec.display.alpha_len + 1)
2823 * sizeof(char) );
2824 for (int i = 0 ; i < infoRec->rec.display.alpha_len ; i++) {
2825 string8[i] = infoRec->rec.display.alpha_buf[i];
2826 }
Wink Saville43808972011-01-13 17:39:51 -08002827 string8[(int)infoRec->rec.display.alpha_len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002828 writeStringToParcel(p, (const char*)string8);
2829 free(string8);
2830 string8 = NULL;
Wink Saville3d54e742009-05-18 18:00:44 -07002831 break;
2832 case RIL_CDMA_CALLED_PARTY_NUMBER_INFO_REC:
Wink Saville3d54e742009-05-18 18:00:44 -07002833 case RIL_CDMA_CALLING_PARTY_NUMBER_INFO_REC:
Wink Saville3d54e742009-05-18 18:00:44 -07002834 case RIL_CDMA_CONNECTED_NUMBER_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002835 if (infoRec->rec.number.len > CDMA_NUMBER_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002836 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002837 expected not more than %d\n",
2838 (int)infoRec->rec.number.len,
2839 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2840 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002841 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002842 string8 = (char*) malloc((infoRec->rec.number.len + 1)
2843 * sizeof(char) );
2844 for (int i = 0 ; i < infoRec->rec.number.len; i++) {
2845 string8[i] = infoRec->rec.number.buf[i];
2846 }
Wink Saville43808972011-01-13 17:39:51 -08002847 string8[(int)infoRec->rec.number.len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002848 writeStringToParcel(p, (const char*)string8);
2849 free(string8);
2850 string8 = NULL;
2851 p.writeInt32(infoRec->rec.number.number_type);
2852 p.writeInt32(infoRec->rec.number.number_plan);
2853 p.writeInt32(infoRec->rec.number.pi);
2854 p.writeInt32(infoRec->rec.number.si);
Wink Saville3d54e742009-05-18 18:00:44 -07002855 break;
2856 case RIL_CDMA_SIGNAL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002857 p.writeInt32(infoRec->rec.signal.isPresent);
2858 p.writeInt32(infoRec->rec.signal.signalType);
2859 p.writeInt32(infoRec->rec.signal.alertPitch);
2860 p.writeInt32(infoRec->rec.signal.signal);
2861
2862 appendPrintBuf("%sisPresent=%X, signalType=%X, \
2863 alertPitch=%X, signal=%X, ",
2864 printBuf, (int)infoRec->rec.signal.isPresent,
2865 (int)infoRec->rec.signal.signalType,
2866 (int)infoRec->rec.signal.alertPitch,
2867 (int)infoRec->rec.signal.signal);
2868 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002869 break;
2870 case RIL_CDMA_REDIRECTING_NUMBER_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002871 if (infoRec->rec.redir.redirectingNumber.len >
2872 CDMA_NUMBER_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002873 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002874 expected not more than %d\n",
2875 (int)infoRec->rec.redir.redirectingNumber.len,
2876 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2877 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002878 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002879 string8 = (char*) malloc((infoRec->rec.redir.redirectingNumber
2880 .len + 1) * sizeof(char) );
2881 for (int i = 0;
2882 i < infoRec->rec.redir.redirectingNumber.len;
2883 i++) {
2884 string8[i] = infoRec->rec.redir.redirectingNumber.buf[i];
2885 }
Wink Saville43808972011-01-13 17:39:51 -08002886 string8[(int)infoRec->rec.redir.redirectingNumber.len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002887 writeStringToParcel(p, (const char*)string8);
2888 free(string8);
2889 string8 = NULL;
2890 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_type);
2891 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_plan);
2892 p.writeInt32(infoRec->rec.redir.redirectingNumber.pi);
2893 p.writeInt32(infoRec->rec.redir.redirectingNumber.si);
2894 p.writeInt32(infoRec->rec.redir.redirectingReason);
Wink Saville3d54e742009-05-18 18:00:44 -07002895 break;
2896 case RIL_CDMA_LINE_CONTROL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002897 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPolarityIncluded);
2898 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlToggle);
2899 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlReverse);
2900 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2901
2902 appendPrintBuf("%slineCtrlPolarityIncluded=%d, \
2903 lineCtrlToggle=%d, lineCtrlReverse=%d, \
2904 lineCtrlPowerDenial=%d, ", printBuf,
2905 (int)infoRec->rec.lineCtrl.lineCtrlPolarityIncluded,
2906 (int)infoRec->rec.lineCtrl.lineCtrlToggle,
2907 (int)infoRec->rec.lineCtrl.lineCtrlReverse,
2908 (int)infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2909 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002910 break;
2911 case RIL_CDMA_T53_CLIR_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002912 p.writeInt32((int)(infoRec->rec.clir.cause));
Wink Saville3d54e742009-05-18 18:00:44 -07002913
Wink Savillea592eeb2009-05-22 13:26:36 -07002914 appendPrintBuf("%scause%d", printBuf, infoRec->rec.clir.cause);
2915 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002916 break;
2917 case RIL_CDMA_T53_AUDIO_CONTROL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002918 p.writeInt32(infoRec->rec.audioCtrl.upLink);
2919 p.writeInt32(infoRec->rec.audioCtrl.downLink);
2920
2921 appendPrintBuf("%supLink=%d, downLink=%d, ", printBuf,
2922 infoRec->rec.audioCtrl.upLink,
2923 infoRec->rec.audioCtrl.downLink);
2924 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002925 break;
Wink Savillea592eeb2009-05-22 13:26:36 -07002926 case RIL_CDMA_T53_RELEASE_INFO_REC:
2927 // TODO(Moto): See David Krause, he has the answer:)
Wink Saville8eb2a122012-11-19 16:05:13 -08002928 RLOGE("RIL_CDMA_T53_RELEASE_INFO_REC: return INVALID_RESPONSE");
Wink Savillea592eeb2009-05-22 13:26:36 -07002929 return RIL_ERRNO_INVALID_RESPONSE;
2930 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08002931 RLOGE("Incorrect name value");
Wink Savillea592eeb2009-05-22 13:26:36 -07002932 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002933 }
2934 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002935 closeResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002936
Wink Savillea592eeb2009-05-22 13:26:36 -07002937 return 0;
Wink Saville3d54e742009-05-18 18:00:44 -07002938}
2939
Sanket Padawe88cf6a52016-01-11 12:45:43 -08002940static void responseRilSignalStrengthV5(Parcel &p, RIL_SignalStrength_v10 *p_cur) {
2941 p.writeInt32(p_cur->GW_SignalStrength.signalStrength);
2942 p.writeInt32(p_cur->GW_SignalStrength.bitErrorRate);
2943 p.writeInt32(p_cur->CDMA_SignalStrength.dbm);
2944 p.writeInt32(p_cur->CDMA_SignalStrength.ecio);
2945 p.writeInt32(p_cur->EVDO_SignalStrength.dbm);
2946 p.writeInt32(p_cur->EVDO_SignalStrength.ecio);
2947 p.writeInt32(p_cur->EVDO_SignalStrength.signalNoiseRatio);
2948}
2949
2950static void responseRilSignalStrengthV6Extra(Parcel &p, RIL_SignalStrength_v10 *p_cur) {
2951 /*
2952 * Fixup LTE for backwards compatibility
2953 */
2954 // signalStrength: -1 -> 99
2955 if (p_cur->LTE_SignalStrength.signalStrength == -1) {
2956 p_cur->LTE_SignalStrength.signalStrength = 99;
2957 }
2958 // rsrp: -1 -> INT_MAX all other negative value to positive.
2959 // So remap here
2960 if (p_cur->LTE_SignalStrength.rsrp == -1) {
2961 p_cur->LTE_SignalStrength.rsrp = INT_MAX;
2962 } else if (p_cur->LTE_SignalStrength.rsrp < -1) {
2963 p_cur->LTE_SignalStrength.rsrp = -p_cur->LTE_SignalStrength.rsrp;
2964 }
2965 // rsrq: -1 -> INT_MAX
2966 if (p_cur->LTE_SignalStrength.rsrq == -1) {
2967 p_cur->LTE_SignalStrength.rsrq = INT_MAX;
2968 }
2969 // Not remapping rssnr is already using INT_MAX
2970
2971 // cqi: -1 -> INT_MAX
2972 if (p_cur->LTE_SignalStrength.cqi == -1) {
2973 p_cur->LTE_SignalStrength.cqi = INT_MAX;
2974 }
2975
2976 p.writeInt32(p_cur->LTE_SignalStrength.signalStrength);
2977 p.writeInt32(p_cur->LTE_SignalStrength.rsrp);
2978 p.writeInt32(p_cur->LTE_SignalStrength.rsrq);
2979 p.writeInt32(p_cur->LTE_SignalStrength.rssnr);
2980 p.writeInt32(p_cur->LTE_SignalStrength.cqi);
2981}
2982
2983static void responseRilSignalStrengthV10(Parcel &p, RIL_SignalStrength_v10 *p_cur) {
2984 responseRilSignalStrengthV5(p, p_cur);
2985 responseRilSignalStrengthV6Extra(p, p_cur);
2986 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
2987}
2988
Wink Savillea592eeb2009-05-22 13:26:36 -07002989static int responseRilSignalStrength(Parcel &p,
2990 void *response, size_t responselen) {
2991 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002992 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002993 return RIL_ERRNO_INVALID_RESPONSE;
2994 }
2995
Sanket Padawe88cf6a52016-01-11 12:45:43 -08002996 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
2997 if (responselen >= sizeof (RIL_SignalStrength_v5)) {
2998 RIL_SignalStrength_v10 *p_cur = ((RIL_SignalStrength_v10 *) response);
Wink Saville3d54e742009-05-18 18:00:44 -07002999
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003000 responseRilSignalStrengthV5(p, p_cur);
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07003001
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003002 if (responselen >= sizeof (RIL_SignalStrength_v6)) {
3003 responseRilSignalStrengthV6Extra(p, p_cur);
3004 if (responselen >= sizeof (RIL_SignalStrength_v10)) {
3005 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
3006 } else {
3007 p.writeInt32(INT_MAX);
Wink Saville18e4ab12013-04-07 17:31:04 -07003008 }
Etan Cohend3652192014-06-20 08:28:44 -07003009 } else {
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003010 p.writeInt32(99);
3011 p.writeInt32(INT_MAX);
3012 p.writeInt32(INT_MAX);
3013 p.writeInt32(INT_MAX);
3014 p.writeInt32(INT_MAX);
Etan Cohend3652192014-06-20 08:28:44 -07003015 p.writeInt32(INT_MAX);
3016 }
Wink Savillec0114b32011-02-18 10:14:07 -08003017 } else {
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003018 RLOGE("invalid response length");
3019 return RIL_ERRNO_INVALID_RESPONSE;
Wink Savillec0114b32011-02-18 10:14:07 -08003020 }
Sanket Padawef53c5fa2016-01-27 10:00:38 -08003021 } else { // RIL version >= 13
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003022 if (responselen % sizeof(RIL_SignalStrength_v10) != 0) {
3023 RLOGE("Data structure expected is RIL_SignalStrength_v10");
3024 if (!isDebuggable()) {
3025 return RIL_ERRNO_INVALID_RESPONSE;
3026 } else {
3027 assert(0);
3028 }
3029 }
3030 RIL_SignalStrength_v10 *p_cur = ((RIL_SignalStrength_v10 *) response);
3031 responseRilSignalStrengthV10(p, p_cur);
Wink Saville3d54e742009-05-18 18:00:44 -07003032 }
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003033 startResponse;
3034 appendPrintBuf("%s[signalStrength=%d,bitErrorRate=%d,\
3035 CDMA_SS.dbm=%d,CDMA_SSecio=%d,\
3036 EVDO_SS.dbm=%d,EVDO_SS.ecio=%d,\
3037 EVDO_SS.signalNoiseRatio=%d,\
3038 LTE_SS.signalStrength=%d,LTE_SS.rsrp=%d,LTE_SS.rsrq=%d,\
3039 LTE_SS.rssnr=%d,LTE_SS.cqi=%d,TDSCDMA_SS.rscp=%d]",
3040 printBuf,
3041 p_cur->GW_SignalStrength.signalStrength,
3042 p_cur->GW_SignalStrength.bitErrorRate,
3043 p_cur->CDMA_SignalStrength.dbm,
3044 p_cur->CDMA_SignalStrength.ecio,
3045 p_cur->EVDO_SignalStrength.dbm,
3046 p_cur->EVDO_SignalStrength.ecio,
3047 p_cur->EVDO_SignalStrength.signalNoiseRatio,
3048 p_cur->LTE_SignalStrength.signalStrength,
3049 p_cur->LTE_SignalStrength.rsrp,
3050 p_cur->LTE_SignalStrength.rsrq,
3051 p_cur->LTE_SignalStrength.rssnr,
3052 p_cur->LTE_SignalStrength.cqi,
3053 p_cur->TD_SCDMA_SignalStrength.rscp);
3054 closeResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07003055 return 0;
3056}
3057
3058static int responseCallRing(Parcel &p, void *response, size_t responselen) {
3059 if ((response == NULL) || (responselen == 0)) {
3060 return responseVoid(p, response, responselen);
3061 } else {
3062 return responseCdmaSignalInfoRecord(p, response, responselen);
3063 }
3064}
3065
3066static int responseCdmaSignalInfoRecord(Parcel &p, void *response, size_t responselen) {
3067 if (response == NULL || responselen == 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003068 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07003069 return RIL_ERRNO_INVALID_RESPONSE;
3070 }
3071
3072 if (responselen != sizeof (RIL_CDMA_SignalInfoRecord)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003073 RLOGE("invalid response length %d expected sizeof (RIL_CDMA_SignalInfoRecord) of %d\n",
Wink Saville3d54e742009-05-18 18:00:44 -07003074 (int)responselen, (int)sizeof (RIL_CDMA_SignalInfoRecord));
3075 return RIL_ERRNO_INVALID_RESPONSE;
3076 }
3077
3078 startResponse;
3079
3080 RIL_CDMA_SignalInfoRecord *p_cur = ((RIL_CDMA_SignalInfoRecord *) response);
3081 marshallSignalInfoRecord(p, *p_cur);
3082
3083 appendPrintBuf("%s[isPresent=%d,signalType=%d,alertPitch=%d\
3084 signal=%d]",
3085 printBuf,
3086 p_cur->isPresent,
3087 p_cur->signalType,
3088 p_cur->alertPitch,
3089 p_cur->signal);
3090
3091 closeResponse;
3092 return 0;
3093}
3094
Wink Savillea592eeb2009-05-22 13:26:36 -07003095static int responseCdmaCallWaiting(Parcel &p, void *response,
3096 size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07003097 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003098 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07003099 return RIL_ERRNO_INVALID_RESPONSE;
3100 }
3101
Wink Savillec0114b32011-02-18 10:14:07 -08003102 if (responselen < sizeof(RIL_CDMA_CallWaiting_v6)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003103 RLOGW("Upgrade to ril version %d\n", RIL_VERSION);
Wink Savillec0114b32011-02-18 10:14:07 -08003104 }
3105
3106 RIL_CDMA_CallWaiting_v6 *p_cur = ((RIL_CDMA_CallWaiting_v6 *) response);
3107
3108 writeStringToParcel(p, p_cur->number);
3109 p.writeInt32(p_cur->numberPresentation);
3110 writeStringToParcel(p, p_cur->name);
3111 marshallSignalInfoRecord(p, p_cur->signalInfoRecord);
3112
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003113 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
3114 if (responselen >= sizeof(RIL_CDMA_CallWaiting_v6)) {
3115 p.writeInt32(p_cur->number_type);
3116 p.writeInt32(p_cur->number_plan);
3117 } else {
3118 p.writeInt32(0);
3119 p.writeInt32(0);
3120 }
Sanket Padawef53c5fa2016-01-27 10:00:38 -08003121 } else { // RIL version >= 13
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003122 if (responselen % sizeof(RIL_CDMA_CallWaiting_v6) != 0) {
3123 RLOGE("Data structure expected is RIL_CDMA_CallWaiting_v6");
3124 if (!isDebuggable()) {
3125 return RIL_ERRNO_INVALID_RESPONSE;
3126 } else {
3127 assert(0);
3128 }
3129 }
Wink Savillec0114b32011-02-18 10:14:07 -08003130 p.writeInt32(p_cur->number_type);
3131 p.writeInt32(p_cur->number_plan);
Wink Saville3d54e742009-05-18 18:00:44 -07003132 }
3133
3134 startResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07003135 appendPrintBuf("%snumber=%s,numberPresentation=%d, name=%s,\
3136 signalInfoRecord[isPresent=%d,signalType=%d,alertPitch=%d\
Wink Savillec0114b32011-02-18 10:14:07 -08003137 signal=%d,number_type=%d,number_plan=%d]",
Wink Saville3d54e742009-05-18 18:00:44 -07003138 printBuf,
3139 p_cur->number,
3140 p_cur->numberPresentation,
3141 p_cur->name,
3142 p_cur->signalInfoRecord.isPresent,
3143 p_cur->signalInfoRecord.signalType,
3144 p_cur->signalInfoRecord.alertPitch,
Wink Savillec0114b32011-02-18 10:14:07 -08003145 p_cur->signalInfoRecord.signal,
3146 p_cur->number_type,
3147 p_cur->number_plan);
Wink Saville3d54e742009-05-18 18:00:44 -07003148 closeResponse;
3149
3150 return 0;
3151}
3152
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003153static void responseSimRefreshV7(Parcel &p, void *response) {
3154 RIL_SimRefreshResponse_v7 *p_cur = ((RIL_SimRefreshResponse_v7 *) response);
3155 p.writeInt32(p_cur->result);
3156 p.writeInt32(p_cur->ef_id);
3157 writeStringToParcel(p, p_cur->aid);
3158
3159 appendPrintBuf("%sresult=%d, ef_id=%d, aid=%s",
3160 printBuf,
3161 p_cur->result,
3162 p_cur->ef_id,
3163 p_cur->aid);
3164
3165}
3166
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003167static int responseSimRefresh(Parcel &p, void *response, size_t responselen) {
3168 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003169 RLOGE("responseSimRefresh: invalid response: NULL");
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003170 return RIL_ERRNO_INVALID_RESPONSE;
3171 }
3172
3173 startResponse;
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003174 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
Sanket Padawe41c94d02016-01-21 15:49:33 -08003175 if (s_callbacks.version >= 7) {
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003176 responseSimRefreshV7(p, response);
3177 } else {
3178 int *p_cur = ((int *) response);
3179 p.writeInt32(p_cur[0]);
3180 p.writeInt32(p_cur[1]);
3181 writeStringToParcel(p, NULL);
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003182
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003183 appendPrintBuf("%sresult=%d, ef_id=%d",
3184 printBuf,
3185 p_cur[0],
3186 p_cur[1]);
3187 }
Sanket Padawef53c5fa2016-01-27 10:00:38 -08003188 } else { // RIL version >= 13
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003189 if (responselen % sizeof(RIL_SimRefreshResponse_v7) != 0) {
3190 RLOGE("Data structure expected is RIL_SimRefreshResponse_v7");
3191 if (!isDebuggable()) {
3192 return RIL_ERRNO_INVALID_RESPONSE;
3193 } else {
3194 assert(0);
3195 }
3196 }
3197 responseSimRefreshV7(p, response);
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003198
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003199 }
3200 closeResponse;
3201
3202 return 0;
3203}
3204
Sanket Padawef53c5fa2016-01-27 10:00:38 -08003205static int responseCellInfoListV6(Parcel &p, void *response, size_t responselen) {
Wink Saville8a9e0212013-04-09 12:11:38 -07003206 if (response == NULL && responselen != 0) {
3207 RLOGE("invalid response: NULL");
3208 return RIL_ERRNO_INVALID_RESPONSE;
3209 }
3210
3211 if (responselen % sizeof(RIL_CellInfo) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07003212 RLOGE("responseCellInfoList: invalid response length %d expected multiple of %d",
Wink Saville8a9e0212013-04-09 12:11:38 -07003213 (int)responselen, (int)sizeof(RIL_CellInfo));
3214 return RIL_ERRNO_INVALID_RESPONSE;
3215 }
3216
3217 int num = responselen / sizeof(RIL_CellInfo);
3218 p.writeInt32(num);
3219
3220 RIL_CellInfo *p_cur = (RIL_CellInfo *) response;
3221 startResponse;
3222 int i;
3223 for (i = 0; i < num; i++) {
3224 appendPrintBuf("%s[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", printBuf, i,
3225 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
3226 p.writeInt32((int)p_cur->cellInfoType);
3227 p.writeInt32(p_cur->registered);
3228 p.writeInt32(p_cur->timeStampType);
3229 p.writeInt64(p_cur->timeStamp);
3230 switch(p_cur->cellInfoType) {
3231 case RIL_CELL_INFO_TYPE_GSM: {
Wink Savillec57b3eb2013-04-17 12:51:41 -07003232 appendPrintBuf("%s GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,", printBuf,
Wink Saville8a9e0212013-04-09 12:11:38 -07003233 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
3234 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
3235 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
Wink Savillec57b3eb2013-04-17 12:51:41 -07003236 p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3237 appendPrintBuf("%s gsmSS: ss=%d,ber=%d],", printBuf,
Wink Saville8a9e0212013-04-09 12:11:38 -07003238 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
3239 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3240
3241 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
3242 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
3243 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
3244 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
Wink Saville8a9e0212013-04-09 12:11:38 -07003245 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
3246 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3247 break;
3248 }
Wink Savillec57b3eb2013-04-17 12:51:41 -07003249 case RIL_CELL_INFO_TYPE_WCDMA: {
3250 appendPrintBuf("%s WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,", printBuf,
3251 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
3252 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
3253 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
3254 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
3255 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3256 appendPrintBuf("%s wcdmaSS: ss=%d,ber=%d],", printBuf,
3257 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
3258 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3259
3260 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
3261 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
3262 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
3263 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
3264 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3265 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
3266 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3267 break;
3268 }
Wink Saville8a9e0212013-04-09 12:11:38 -07003269 case RIL_CELL_INFO_TYPE_CDMA: {
3270 appendPrintBuf("%s CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d", printBuf,
3271 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
3272 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
3273 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
3274 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
3275 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3276
3277 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
3278 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
3279 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
3280 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
3281 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3282
3283 appendPrintBuf("%s cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d", printBuf,
3284 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
3285 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
3286 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
3287 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
3288 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3289
3290 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
3291 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
3292 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
3293 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
3294 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3295 break;
3296 }
3297 case RIL_CELL_INFO_TYPE_LTE: {
3298 appendPrintBuf("%s LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d", printBuf,
3299 p_cur->CellInfo.lte.cellIdentityLte.mcc,
3300 p_cur->CellInfo.lte.cellIdentityLte.mnc,
3301 p_cur->CellInfo.lte.cellIdentityLte.ci,
3302 p_cur->CellInfo.lte.cellIdentityLte.pci,
3303 p_cur->CellInfo.lte.cellIdentityLte.tac);
3304
3305 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
3306 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
3307 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
3308 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
3309 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
3310
3311 appendPrintBuf("%s lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d", printBuf,
3312 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
3313 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
3314 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
3315 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
3316 p_cur->CellInfo.lte.signalStrengthLte.cqi,
3317 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3318 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
3319 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
3320 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
3321 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
3322 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
3323 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3324 break;
3325 }
Etan Cohend3652192014-06-20 08:28:44 -07003326 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
3327 appendPrintBuf("%s TDSCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,cpid=%d,", printBuf,
3328 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc,
3329 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc,
3330 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac,
3331 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid,
3332 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3333 appendPrintBuf("%s tdscdmaSS: rscp=%d],", printBuf,
3334 p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3335
3336 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
3337 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
3338 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
3339 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
3340 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3341 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3342 break;
3343 }
Wink Saville8a9e0212013-04-09 12:11:38 -07003344 }
3345 p_cur += 1;
3346 }
3347 removeLastChar;
3348 closeResponse;
3349
3350 return 0;
3351}
3352
Sanket Padawef53c5fa2016-01-27 10:00:38 -08003353static int responseCellInfoListV12(Parcel &p, void *response, size_t responselen) {
3354 if (response == NULL && responselen != 0) {
3355 RLOGE("invalid response: NULL");
3356 return RIL_ERRNO_INVALID_RESPONSE;
3357 }
3358
3359 if (responselen % sizeof(RIL_CellInfo_v12) != 0) {
3360 RLOGE("responseCellInfoList: invalid response length %d expected multiple of %d",
3361 (int)responselen, (int)sizeof(RIL_CellInfo_v12));
3362 return RIL_ERRNO_INVALID_RESPONSE;
3363 }
3364
3365 int num = responselen / sizeof(RIL_CellInfo_v12);
3366 p.writeInt32(num);
3367
3368 RIL_CellInfo_v12 *p_cur = (RIL_CellInfo_v12 *) response;
3369 startResponse;
3370 int i;
3371 for (i = 0; i < num; i++) {
3372 appendPrintBuf("%s[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", printBuf, i,
3373 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
3374 RLOGE("[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", i,
3375 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
3376 p.writeInt32((int)p_cur->cellInfoType);
3377 p.writeInt32(p_cur->registered);
3378 p.writeInt32(p_cur->timeStampType);
3379 p.writeInt64(p_cur->timeStamp);
3380 switch(p_cur->cellInfoType) {
3381 case RIL_CELL_INFO_TYPE_GSM: {
3382 appendPrintBuf("%s GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,arfcn=%d,bsic=%x", printBuf,
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("GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,arfcn=%d,bsic=%x",
3390 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
3391 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
3392 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
3393 p_cur->CellInfo.gsm.cellIdentityGsm.cid,
3394 p_cur->CellInfo.gsm.cellIdentityGsm.arfcn,
3395 p_cur->CellInfo.gsm.cellIdentityGsm.bsic);
3396 RLOGE("gsmSS: ss=%d,ber=%d, ta=%d],",
3397 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
3398 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate,
3399 p_cur->CellInfo.gsm.signalStrengthGsm.timingAdvance);
3400 appendPrintBuf("%s gsmSS: ss=%d,ber=%d, ta=%d],", printBuf,
3401 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
3402 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate,
3403 p_cur->CellInfo.gsm.signalStrengthGsm.timingAdvance);
3404
3405 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
3406 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
3407 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
3408 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3409 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.arfcn);
3410 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.bsic);
3411 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
3412 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3413 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.timingAdvance);
3414 break;
3415 }
3416 case RIL_CELL_INFO_TYPE_WCDMA: {
3417 RLOGE("WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,uarfcn=%d",
3418 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
3419 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
3420 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
3421 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
3422 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc,
3423 p_cur->CellInfo.wcdma.cellIdentityWcdma.uarfcn);
3424 RLOGE("wcdmaSS: ss=%d,ber=%d],",
3425 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
3426 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3427 appendPrintBuf("%s WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,uarfcn=%d", printBuf,
3428 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
3429 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
3430 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
3431 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
3432 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc,
3433 p_cur->CellInfo.wcdma.cellIdentityWcdma.uarfcn);
3434 appendPrintBuf("%s wcdmaSS: ss=%d,ber=%d],", printBuf,
3435 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
3436 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3437
3438 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
3439 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
3440 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
3441 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
3442 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3443 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.uarfcn);
3444 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
3445 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3446 break;
3447 }
3448 case RIL_CELL_INFO_TYPE_CDMA: {
3449 RLOGE("CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d",
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 appendPrintBuf("%s CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d", printBuf,
3457 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
3458 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
3459 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
3460 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
3461 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3462
3463 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
3464 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
3465 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
3466 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
3467 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3468
3469 RLOGE("cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d",
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 appendPrintBuf("%s cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d", printBuf,
3477 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
3478 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
3479 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
3480 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
3481 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3482
3483 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
3484 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
3485 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
3486 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
3487 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3488 break;
3489 }
3490 case RIL_CELL_INFO_TYPE_LTE: {
3491 RLOGE("LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d,earfcn=%d",
3492 p_cur->CellInfo.lte.cellIdentityLte.mcc,
3493 p_cur->CellInfo.lte.cellIdentityLte.mnc,
3494 p_cur->CellInfo.lte.cellIdentityLte.ci,
3495 p_cur->CellInfo.lte.cellIdentityLte.pci,
3496 p_cur->CellInfo.lte.cellIdentityLte.tac,
3497 p_cur->CellInfo.lte.cellIdentityLte.earfcn);
3498
3499 appendPrintBuf("%s LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d,earfcn=%d", printBuf,
3500 p_cur->CellInfo.lte.cellIdentityLte.mcc,
3501 p_cur->CellInfo.lte.cellIdentityLte.mnc,
3502 p_cur->CellInfo.lte.cellIdentityLte.ci,
3503 p_cur->CellInfo.lte.cellIdentityLte.pci,
3504 p_cur->CellInfo.lte.cellIdentityLte.tac,
3505 p_cur->CellInfo.lte.cellIdentityLte.earfcn);
3506
3507 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
3508 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
3509 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
3510 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
3511 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
3512 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.earfcn);
3513
3514 RLOGE("lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d",
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 appendPrintBuf("%s lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d", printBuf,
3522 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
3523 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
3524 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
3525 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
3526 p_cur->CellInfo.lte.signalStrengthLte.cqi,
3527 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3528 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
3529 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
3530 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
3531 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
3532 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
3533 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3534 break;
3535 }
3536 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
3537 appendPrintBuf("%s TDSCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,cpid=%d,", printBuf,
3538 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc,
3539 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc,
3540 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac,
3541 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid,
3542 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3543 appendPrintBuf("%s tdscdmaSS: rscp=%d],", printBuf,
3544 p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3545
3546 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
3547 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
3548 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
3549 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
3550 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3551 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3552 break;
3553 }
3554 }
3555 p_cur += 1;
3556 }
3557 removeLastChar;
3558 closeResponse;
3559 return 0;
3560}
3561
3562static int responseCellInfoList(Parcel &p, void *response, size_t responselen)
3563{
3564 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
3565 if (s_callbacks.version < 12) {
3566 RLOGD("responseCellInfoList: v6");
3567 return responseCellInfoListV6(p, response, responselen);
3568 } else {
3569 RLOGD("responseCellInfoList: v12");
3570 return responseCellInfoListV12(p, response, responselen);
3571 }
3572 } else { // RIL version >= 13
3573 if (responselen % sizeof(RIL_CellInfo_v12) != 0) {
3574 RLOGE("Data structure expected is RIL_CellInfo_v12");
3575 if (!isDebuggable()) {
3576 return RIL_ERRNO_INVALID_RESPONSE;
3577 } else {
3578 assert(0);
3579 }
3580 }
3581 return responseCellInfoListV12(p, response, responselen);
3582 }
3583
3584 return 0;
3585}
3586
Etan Cohend3652192014-06-20 08:28:44 -07003587static int responseHardwareConfig(Parcel &p, void *response, size_t responselen)
3588{
3589 if (response == NULL && responselen != 0) {
3590 RLOGE("invalid response: NULL");
3591 return RIL_ERRNO_INVALID_RESPONSE;
3592 }
3593
3594 if (responselen % sizeof(RIL_HardwareConfig) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07003595 RLOGE("responseHardwareConfig: invalid response length %d expected multiple of %d",
Etan Cohend3652192014-06-20 08:28:44 -07003596 (int)responselen, (int)sizeof(RIL_HardwareConfig));
3597 return RIL_ERRNO_INVALID_RESPONSE;
3598 }
3599
3600 int num = responselen / sizeof(RIL_HardwareConfig);
3601 int i;
3602 RIL_HardwareConfig *p_cur = (RIL_HardwareConfig *) response;
3603
3604 p.writeInt32(num);
3605
3606 startResponse;
3607 for (i = 0; i < num; i++) {
3608 switch (p_cur[i].type) {
3609 case RIL_HARDWARE_CONFIG_MODEM: {
3610 writeStringToParcel(p, p_cur[i].uuid);
3611 p.writeInt32((int)p_cur[i].state);
3612 p.writeInt32(p_cur[i].cfg.modem.rat);
3613 p.writeInt32(p_cur[i].cfg.modem.maxVoice);
3614 p.writeInt32(p_cur[i].cfg.modem.maxData);
3615 p.writeInt32(p_cur[i].cfg.modem.maxStandby);
3616
3617 appendPrintBuf("%s modem: uuid=%s,state=%d,rat=%08x,maxV=%d,maxD=%d,maxS=%d", printBuf,
3618 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.modem.rat,
3619 p_cur[i].cfg.modem.maxVoice, p_cur[i].cfg.modem.maxData, p_cur[i].cfg.modem.maxStandby);
3620 break;
3621 }
3622 case RIL_HARDWARE_CONFIG_SIM: {
3623 writeStringToParcel(p, p_cur[i].uuid);
3624 p.writeInt32((int)p_cur[i].state);
3625 writeStringToParcel(p, p_cur[i].cfg.sim.modemUuid);
3626
3627 appendPrintBuf("%s sim: uuid=%s,state=%d,modem-uuid=%s", printBuf,
3628 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.sim.modemUuid);
3629 break;
3630 }
3631 }
3632 }
3633 removeLastChar;
3634 closeResponse;
3635 return 0;
3636}
3637
Wink Saville8b4e4f72014-10-17 15:01:45 -07003638static int responseRadioCapability(Parcel &p, void *response, size_t responselen) {
3639 if (response == NULL) {
3640 RLOGE("invalid response: NULL");
3641 return RIL_ERRNO_INVALID_RESPONSE;
3642 }
3643
3644 if (responselen != sizeof (RIL_RadioCapability) ) {
3645 RLOGE("invalid response length was %d expected %d",
3646 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3647 return RIL_ERRNO_INVALID_RESPONSE;
3648 }
3649
3650 RIL_RadioCapability *p_cur = (RIL_RadioCapability *) response;
3651 p.writeInt32(p_cur->version);
3652 p.writeInt32(p_cur->session);
3653 p.writeInt32(p_cur->phase);
3654 p.writeInt32(p_cur->rat);
3655 writeStringToParcel(p, p_cur->logicalModemUuid);
3656 p.writeInt32(p_cur->status);
3657
3658 startResponse;
3659 appendPrintBuf("%s[version=%d,session=%d,phase=%d,\
Legler Wu8caf06f2014-10-29 14:02:14 +08003660 rat=%s,logicalModemUuid=%s,status=%d]",
Wink Saville8b4e4f72014-10-17 15:01:45 -07003661 printBuf,
3662 p_cur->version,
3663 p_cur->session,
3664 p_cur->phase,
3665 p_cur->rat,
Legler Wu8caf06f2014-10-29 14:02:14 +08003666 p_cur->logicalModemUuid,
Wink Saville8b4e4f72014-10-17 15:01:45 -07003667 p_cur->status);
3668 closeResponse;
3669 return 0;
3670}
3671
Amit Mahajan54563d32014-11-22 00:54:49 +00003672static int responseSSData(Parcel &p, void *response, size_t responselen) {
3673 RLOGD("In responseSSData");
3674 int num;
3675
3676 if (response == NULL && responselen != 0) {
3677 RLOGE("invalid response length was %d expected %d",
3678 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3679 return RIL_ERRNO_INVALID_RESPONSE;
3680 }
3681
3682 if (responselen != sizeof(RIL_StkCcUnsolSsResponse)) {
3683 RLOGE("invalid response length %d, expected %d",
3684 (int)responselen, (int)sizeof(RIL_StkCcUnsolSsResponse));
3685 return RIL_ERRNO_INVALID_RESPONSE;
3686 }
3687
3688 startResponse;
3689 RIL_StkCcUnsolSsResponse *p_cur = (RIL_StkCcUnsolSsResponse *) response;
3690 p.writeInt32(p_cur->serviceType);
3691 p.writeInt32(p_cur->requestType);
3692 p.writeInt32(p_cur->teleserviceType);
3693 p.writeInt32(p_cur->serviceClass);
3694 p.writeInt32(p_cur->result);
3695
3696 if (isServiceTypeCfQuery(p_cur->serviceType, p_cur->requestType)) {
3697 RLOGD("responseSSData CF type, num of Cf elements %d", p_cur->cfData.numValidIndexes);
3698 if (p_cur->cfData.numValidIndexes > NUM_SERVICE_CLASSES) {
3699 RLOGE("numValidIndexes is greater than max value %d, "
3700 "truncating it to max value", NUM_SERVICE_CLASSES);
3701 p_cur->cfData.numValidIndexes = NUM_SERVICE_CLASSES;
3702 }
3703 /* number of call info's */
3704 p.writeInt32(p_cur->cfData.numValidIndexes);
3705
3706 for (int i = 0; i < p_cur->cfData.numValidIndexes; i++) {
3707 RIL_CallForwardInfo cf = p_cur->cfData.cfInfo[i];
3708
3709 p.writeInt32(cf.status);
3710 p.writeInt32(cf.reason);
3711 p.writeInt32(cf.serviceClass);
3712 p.writeInt32(cf.toa);
3713 writeStringToParcel(p, cf.number);
3714 p.writeInt32(cf.timeSeconds);
3715 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
3716 (cf.status==1)?"enable":"disable", cf.reason, cf.serviceClass, cf.toa,
3717 (char*)cf.number, cf.timeSeconds);
3718 RLOGD("Data: %d,reason=%d,cls=%d,toa=%d,num=%s,tout=%d],", cf.status,
3719 cf.reason, cf.serviceClass, cf.toa, (char*)cf.number, cf.timeSeconds);
3720 }
3721 } else {
3722 p.writeInt32 (SS_INFO_MAX);
3723
3724 /* each int*/
3725 for (int i = 0; i < SS_INFO_MAX; i++) {
3726 appendPrintBuf("%s%d,", printBuf, p_cur->ssInfo[i]);
3727 RLOGD("Data: %d",p_cur->ssInfo[i]);
3728 p.writeInt32(p_cur->ssInfo[i]);
3729 }
3730 }
3731 removeLastChar;
3732 closeResponse;
3733
3734 return 0;
3735}
3736
3737static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType) {
3738 if ((reqType == SS_INTERROGATION) &&
3739 (serType == SS_CFU ||
3740 serType == SS_CF_BUSY ||
3741 serType == SS_CF_NO_REPLY ||
3742 serType == SS_CF_NOT_REACHABLE ||
3743 serType == SS_CF_ALL ||
3744 serType == SS_CF_ALL_CONDITIONAL)) {
3745 return true;
3746 }
3747 return false;
3748}
3749
Wink Saville3d54e742009-05-18 18:00:44 -07003750static void triggerEvLoop() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003751 int ret;
3752 if (!pthread_equal(pthread_self(), s_tid_dispatch)) {
3753 /* trigger event loop to wakeup. No reason to do this,
3754 * if we're in the event loop thread */
3755 do {
3756 ret = write (s_fdWakeupWrite, " ", 1);
3757 } while (ret < 0 && errno == EINTR);
3758 }
3759}
3760
Wink Saville3d54e742009-05-18 18:00:44 -07003761static void rilEventAddWakeup(struct ril_event *ev) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003762 ril_event_add(ev);
3763 triggerEvLoop();
3764}
3765
Wink Savillefd729372011-02-22 16:19:39 -08003766static void sendSimStatusAppInfo(Parcel &p, int num_apps, RIL_AppStatus appStatus[]) {
3767 p.writeInt32(num_apps);
3768 startResponse;
3769 for (int i = 0; i < num_apps; i++) {
3770 p.writeInt32(appStatus[i].app_type);
3771 p.writeInt32(appStatus[i].app_state);
3772 p.writeInt32(appStatus[i].perso_substate);
3773 writeStringToParcel(p, (const char*)(appStatus[i].aid_ptr));
3774 writeStringToParcel(p, (const char*)
3775 (appStatus[i].app_label_ptr));
3776 p.writeInt32(appStatus[i].pin1_replaced);
3777 p.writeInt32(appStatus[i].pin1);
3778 p.writeInt32(appStatus[i].pin2);
3779 appendPrintBuf("%s[app_type=%d,app_state=%d,perso_substate=%d,\
3780 aid_ptr=%s,app_label_ptr=%s,pin1_replaced=%d,pin1=%d,pin2=%d],",
3781 printBuf,
3782 appStatus[i].app_type,
3783 appStatus[i].app_state,
3784 appStatus[i].perso_substate,
3785 appStatus[i].aid_ptr,
3786 appStatus[i].app_label_ptr,
3787 appStatus[i].pin1_replaced,
3788 appStatus[i].pin1,
3789 appStatus[i].pin2);
3790 }
3791 closeResponse;
3792}
3793
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003794static void responseSimStatusV5(Parcel &p, void *response) {
3795 RIL_CardStatus_v5 *p_cur = ((RIL_CardStatus_v5 *) response);
3796
3797 p.writeInt32(p_cur->card_state);
3798 p.writeInt32(p_cur->universal_pin_state);
3799 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3800 p.writeInt32(p_cur->cdma_subscription_app_index);
3801
3802 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
3803}
3804
3805static void responseSimStatusV6(Parcel &p, void *response) {
3806 RIL_CardStatus_v6 *p_cur = ((RIL_CardStatus_v6 *) response);
3807
3808 p.writeInt32(p_cur->card_state);
3809 p.writeInt32(p_cur->universal_pin_state);
3810 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3811 p.writeInt32(p_cur->cdma_subscription_app_index);
3812 p.writeInt32(p_cur->ims_subscription_app_index);
3813
3814 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
3815}
3816
Wink Savillef4c4d362009-04-02 01:37:03 -07003817static int responseSimStatus(Parcel &p, void *response, size_t responselen) {
3818 int i;
3819
3820 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003821 RLOGE("invalid response: NULL");
Wink Savillef4c4d362009-04-02 01:37:03 -07003822 return RIL_ERRNO_INVALID_RESPONSE;
3823 }
3824
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003825 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
3826 if (responselen == sizeof (RIL_CardStatus_v6)) {
3827 responseSimStatusV6(p, response);
3828 } else if (responselen == sizeof (RIL_CardStatus_v5)) {
3829 responseSimStatusV5(p, response);
3830 } else {
3831 RLOGE("responseSimStatus: A RilCardStatus_v6 or _v5 expected\n");
3832 return RIL_ERRNO_INVALID_RESPONSE;
3833 }
Sanket Padawef53c5fa2016-01-27 10:00:38 -08003834 } else { // RIL version >= 13
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003835 if (responselen % sizeof(RIL_CardStatus_v6) != 0) {
3836 RLOGE("Data structure expected is RIL_CardStatus_v6");
3837 if (!isDebuggable()) {
3838 return RIL_ERRNO_INVALID_RESPONSE;
3839 } else {
3840 assert(0);
3841 }
3842 }
3843 responseSimStatusV6(p, response);
Wink Savillef4c4d362009-04-02 01:37:03 -07003844 }
Wink Savillef4c4d362009-04-02 01:37:03 -07003845
3846 return 0;
Wink Saville3d54e742009-05-18 18:00:44 -07003847}
Wink Savillef4c4d362009-04-02 01:37:03 -07003848
Wink Savillea592eeb2009-05-22 13:26:36 -07003849static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3850 int num = responselen / sizeof(RIL_GSM_BroadcastSmsConfigInfo *);
Wink Savillef4c4d362009-04-02 01:37:03 -07003851 p.writeInt32(num);
3852
Wink Savillef4c4d362009-04-02 01:37:03 -07003853 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07003854 RIL_GSM_BroadcastSmsConfigInfo **p_cur =
3855 (RIL_GSM_BroadcastSmsConfigInfo **) response;
3856 for (int i = 0; i < num; i++) {
3857 p.writeInt32(p_cur[i]->fromServiceId);
3858 p.writeInt32(p_cur[i]->toServiceId);
3859 p.writeInt32(p_cur[i]->fromCodeScheme);
3860 p.writeInt32(p_cur[i]->toCodeScheme);
3861 p.writeInt32(p_cur[i]->selected);
3862
3863 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId=%d, \
3864 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]",
3865 printBuf, i, p_cur[i]->fromServiceId, p_cur[i]->toServiceId,
3866 p_cur[i]->fromCodeScheme, p_cur[i]->toCodeScheme,
3867 p_cur[i]->selected);
3868 }
Wink Savillef4c4d362009-04-02 01:37:03 -07003869 closeResponse;
3870
3871 return 0;
3872}
3873
Wink Savillea592eeb2009-05-22 13:26:36 -07003874static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3875 RIL_CDMA_BroadcastSmsConfigInfo **p_cur =
3876 (RIL_CDMA_BroadcastSmsConfigInfo **) response;
Wink Savillef4c4d362009-04-02 01:37:03 -07003877
Wink Savillea592eeb2009-05-22 13:26:36 -07003878 int num = responselen / sizeof (RIL_CDMA_BroadcastSmsConfigInfo *);
3879 p.writeInt32(num);
Wink Savillef4c4d362009-04-02 01:37:03 -07003880
3881 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07003882 for (int i = 0 ; i < num ; i++ ) {
3883 p.writeInt32(p_cur[i]->service_category);
3884 p.writeInt32(p_cur[i]->language);
3885 p.writeInt32(p_cur[i]->selected);
Wink Savillef4c4d362009-04-02 01:37:03 -07003886
Wink Savillea592eeb2009-05-22 13:26:36 -07003887 appendPrintBuf("%s [%d: srvice_category=%d, language =%d, \
3888 selected =%d], ",
3889 printBuf, i, p_cur[i]->service_category, p_cur[i]->language,
3890 p_cur[i]->selected);
Wink Savillef5903df2009-04-24 11:54:14 -07003891 }
Wink Savillea592eeb2009-05-22 13:26:36 -07003892 closeResponse;
Wink Savillef5903df2009-04-24 11:54:14 -07003893
Wink Savillef4c4d362009-04-02 01:37:03 -07003894 return 0;
3895}
3896
3897static int responseCdmaSms(Parcel &p, void *response, size_t responselen) {
3898 int num;
3899 int digitCount;
3900 int digitLimit;
3901 uint8_t uct;
3902 void* dest;
3903
Wink Saville8eb2a122012-11-19 16:05:13 -08003904 RLOGD("Inside responseCdmaSms");
Wink Savillef5903df2009-04-24 11:54:14 -07003905
Wink Savillef4c4d362009-04-02 01:37:03 -07003906 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003907 RLOGE("invalid response: NULL");
Wink Savillef4c4d362009-04-02 01:37:03 -07003908 return RIL_ERRNO_INVALID_RESPONSE;
3909 }
3910
Wink Savillef5903df2009-04-24 11:54:14 -07003911 if (responselen != sizeof(RIL_CDMA_SMS_Message)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003912 RLOGE("invalid response length was %d expected %d",
Wink Savillef5903df2009-04-24 11:54:14 -07003913 (int)responselen, (int)sizeof(RIL_CDMA_SMS_Message));
Wink Savillef4c4d362009-04-02 01:37:03 -07003914 return RIL_ERRNO_INVALID_RESPONSE;
3915 }
3916
3917 RIL_CDMA_SMS_Message *p_cur = (RIL_CDMA_SMS_Message *) response;
3918 p.writeInt32(p_cur->uTeleserviceID);
3919 p.write(&(p_cur->bIsServicePresent),sizeof(uct));
3920 p.writeInt32(p_cur->uServicecategory);
3921 p.writeInt32(p_cur->sAddress.digit_mode);
3922 p.writeInt32(p_cur->sAddress.number_mode);
3923 p.writeInt32(p_cur->sAddress.number_type);
3924 p.writeInt32(p_cur->sAddress.number_plan);
3925 p.write(&(p_cur->sAddress.number_of_digits), sizeof(uct));
3926 digitLimit= MIN((p_cur->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
3927 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3928 p.write(&(p_cur->sAddress.digits[digitCount]),sizeof(uct));
3929 }
3930
3931 p.writeInt32(p_cur->sSubAddress.subaddressType);
3932 p.write(&(p_cur->sSubAddress.odd),sizeof(uct));
3933 p.write(&(p_cur->sSubAddress.number_of_digits),sizeof(uct));
3934 digitLimit= MIN((p_cur->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
3935 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3936 p.write(&(p_cur->sSubAddress.digits[digitCount]),sizeof(uct));
3937 }
3938
3939 digitLimit= MIN((p_cur->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
3940 p.writeInt32(p_cur->uBearerDataLen);
3941 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3942 p.write(&(p_cur->aBearerData[digitCount]), sizeof(uct));
3943 }
3944
3945 startResponse;
3946 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
Wink Saville1b5fd232009-04-22 14:50:00 -07003947 sAddress.digit_mode=%d, sAddress.number_mode=%d, sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07003948 printBuf, p_cur->uTeleserviceID,p_cur->bIsServicePresent,p_cur->uServicecategory,
3949 p_cur->sAddress.digit_mode, p_cur->sAddress.number_mode,p_cur->sAddress.number_type);
3950 closeResponse;
3951
3952 return 0;
3953}
3954
Wink Savillec29360a2014-07-13 05:17:28 -07003955static int responseDcRtInfo(Parcel &p, void *response, size_t responselen)
3956{
3957 int num = responselen / sizeof(RIL_DcRtInfo);
3958 if ((responselen % sizeof(RIL_DcRtInfo) != 0) || (num != 1)) {
Amit Mahajan52500162014-07-29 17:36:48 -07003959 RLOGE("responseDcRtInfo: invalid response length %d expected multiple of %d",
Wink Savillec29360a2014-07-13 05:17:28 -07003960 (int)responselen, (int)sizeof(RIL_DcRtInfo));
3961 return RIL_ERRNO_INVALID_RESPONSE;
3962 }
3963
3964 startResponse;
3965 RIL_DcRtInfo *pDcRtInfo = (RIL_DcRtInfo *)response;
3966 p.writeInt64(pDcRtInfo->time);
3967 p.writeInt32(pDcRtInfo->powerState);
3968 appendPrintBuf("%s[time=%d,powerState=%d]", printBuf,
3969 pDcRtInfo->time,
3970 pDcRtInfo->powerState);
3971 closeResponse;
3972
3973 return 0;
3974}
3975
fengluf7408292015-04-14 14:53:55 -07003976static int responseLceStatus(Parcel &p, void *response, size_t responselen) {
3977 if (response == NULL || responselen != sizeof(RIL_LceStatusInfo)) {
3978 if (response == NULL) {
3979 RLOGE("invalid response: NULL");
3980 }
3981 else {
3982 RLOGE("responseLceStatus: invalid response length %d expecting len: d%",
3983 sizeof(RIL_LceStatusInfo), responselen);
3984 }
3985 return RIL_ERRNO_INVALID_RESPONSE;
3986 }
3987
3988 RIL_LceStatusInfo *p_cur = (RIL_LceStatusInfo *)response;
3989 p.write((void *)p_cur, 1); // p_cur->lce_status takes one byte.
3990 p.writeInt32(p_cur->actual_interval_ms);
3991
3992 startResponse;
3993 appendPrintBuf("LCE Status: %d, actual_interval_ms: %d",
3994 p_cur->lce_status, p_cur->actual_interval_ms);
3995 closeResponse;
3996
3997 return 0;
3998}
3999
4000static int responseLceData(Parcel &p, void *response, size_t responselen) {
4001 if (response == NULL || responselen != sizeof(RIL_LceDataInfo)) {
4002 if (response == NULL) {
4003 RLOGE("invalid response: NULL");
4004 }
4005 else {
4006 RLOGE("responseLceData: invalid response length %d expecting len: d%",
4007 sizeof(RIL_LceDataInfo), responselen);
4008 }
4009 return RIL_ERRNO_INVALID_RESPONSE;
4010 }
4011
4012 RIL_LceDataInfo *p_cur = (RIL_LceDataInfo *)response;
4013 p.writeInt32(p_cur->last_hop_capacity_kbps);
4014
4015 /* p_cur->confidence_level and p_cur->lce_suspended take 1 byte each.*/
4016 p.write((void *)&(p_cur->confidence_level), 1);
4017 p.write((void *)&(p_cur->lce_suspended), 1);
4018
4019 startResponse;
4020 appendPrintBuf("LCE info received: capacity %d confidence level %d
4021 and suspended %d",
4022 p_cur->last_hop_capacity_kbps, p_cur->confidence_level,
4023 p_cur->lce_suspended);
4024 closeResponse;
4025
4026 return 0;
4027}
4028
Prerepa Viswanadham73157492015-05-28 00:37:32 -07004029static int responseActivityData(Parcel &p, void *response, size_t responselen) {
4030 if (response == NULL || responselen != sizeof(RIL_ActivityStatsInfo)) {
4031 if (response == NULL) {
4032 RLOGE("invalid response: NULL");
4033 }
4034 else {
4035 RLOGE("responseActivityData: invalid response length %d expecting len: d%",
4036 sizeof(RIL_ActivityStatsInfo), responselen);
4037 }
4038 return RIL_ERRNO_INVALID_RESPONSE;
4039 }
4040
4041 RIL_ActivityStatsInfo *p_cur = (RIL_ActivityStatsInfo *)response;
4042 p.writeInt32(p_cur->sleep_mode_time_ms);
4043 p.writeInt32(p_cur->idle_mode_time_ms);
4044 for(int i = 0; i < RIL_NUM_TX_POWER_LEVELS; i++) {
4045 p.writeInt32(p_cur->tx_mode_time_ms[i]);
4046 }
4047 p.writeInt32(p_cur->rx_mode_time_ms);
4048
4049 startResponse;
4050 appendPrintBuf("Modem activity info received: sleep_mode_time_ms %d idle_mode_time_ms %d
4051 tx_mode_time_ms %d %d %d %d %d and rx_mode_time_ms %d",
4052 p_cur->sleep_mode_time_ms, p_cur->idle_mode_time_ms, p_cur->tx_mode_time_ms[0],
4053 p_cur->tx_mode_time_ms[1], p_cur->tx_mode_time_ms[2], p_cur->tx_mode_time_ms[3],
4054 p_cur->tx_mode_time_ms[4], p_cur->rx_mode_time_ms);
4055 closeResponse;
4056
4057 return 0;
4058}
4059
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004060/**
4061 * A write on the wakeup fd is done just to pop us out of select()
4062 * We empty the buffer here and then ril_event will reset the timers on the
4063 * way back down
4064 */
Wink Savillef4c4d362009-04-02 01:37:03 -07004065static void processWakeupCallback(int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004066 char buff[16];
4067 int ret;
4068
Wink Saville8eb2a122012-11-19 16:05:13 -08004069 RLOGV("processWakeupCallback");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004070
4071 /* empty our wakeup socket out */
4072 do {
4073 ret = read(s_fdWakeupRead, &buff, sizeof(buff));
Wink Saville7f856802009-06-09 10:23:37 -07004074 } while (ret > 0 || (ret < 0 && errno == EINTR));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004075}
4076
Etan Cohend3652192014-06-20 08:28:44 -07004077static void onCommandsSocketClosed(RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004078 int ret;
4079 RequestInfo *p_cur;
Etan Cohend3652192014-06-20 08:28:44 -07004080 /* Hook for current context
4081 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
4082 pthread_mutex_t * pendingRequestsMutexHook = &s_pendingRequestsMutex;
4083 /* pendingRequestsHook refer to &s_pendingRequests */
4084 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004085
Etan Cohend3652192014-06-20 08:28:44 -07004086#if (SIM_COUNT >= 2)
4087 if (socket_id == RIL_SOCKET_2) {
4088 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
4089 pendingRequestsHook = &s_pendingRequests_socket2;
4090 }
4091#if (SIM_COUNT >= 3)
4092 else if (socket_id == RIL_SOCKET_3) {
4093 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
4094 pendingRequestsHook = &s_pendingRequests_socket3;
4095 }
4096#endif
4097#if (SIM_COUNT >= 4)
4098 else if (socket_id == RIL_SOCKET_4) {
4099 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
4100 pendingRequestsHook = &s_pendingRequests_socket4;
4101 }
4102#endif
4103#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004104 /* mark pending requests as "cancelled" so we dont report responses */
Etan Cohend3652192014-06-20 08:28:44 -07004105 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004106 assert (ret == 0);
4107
Etan Cohend3652192014-06-20 08:28:44 -07004108 p_cur = *pendingRequestsHook;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004109
Etan Cohend3652192014-06-20 08:28:44 -07004110 for (p_cur = *pendingRequestsHook
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004111 ; p_cur != NULL
4112 ; p_cur = p_cur->p_next
4113 ) {
4114 p_cur->cancelled = 1;
4115 }
4116
Etan Cohend3652192014-06-20 08:28:44 -07004117 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004118 assert (ret == 0);
4119}
4120
Wink Savillef4c4d362009-04-02 01:37:03 -07004121static void processCommandsCallback(int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004122 RecordStream *p_rs;
4123 void *p_record;
4124 size_t recordlen;
4125 int ret;
Etan Cohend3652192014-06-20 08:28:44 -07004126 SocketListenParam *p_info = (SocketListenParam *)param;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004127
Etan Cohend3652192014-06-20 08:28:44 -07004128 assert(fd == p_info->fdCommand);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004129
Etan Cohend3652192014-06-20 08:28:44 -07004130 p_rs = p_info->p_rs;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004131
4132 for (;;) {
4133 /* loop until EAGAIN/EINTR, end of stream, or other error */
4134 ret = record_stream_get_next(p_rs, &p_record, &recordlen);
4135
4136 if (ret == 0 && p_record == NULL) {
4137 /* end-of-stream */
4138 break;
4139 } else if (ret < 0) {
4140 break;
4141 } else if (ret == 0) { /* && p_record != NULL */
Etan Cohend3652192014-06-20 08:28:44 -07004142 processCommandBuffer(p_record, recordlen, p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004143 }
4144 }
4145
4146 if (ret == 0 || !(errno == EAGAIN || errno == EINTR)) {
4147 /* fatal error or end-of-stream */
4148 if (ret != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004149 RLOGE("error on reading command socket errno:%d\n", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004150 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08004151 RLOGW("EOS. Closing command socket.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004152 }
Wink Saville7f856802009-06-09 10:23:37 -07004153
Etan Cohend3652192014-06-20 08:28:44 -07004154 close(fd);
4155 p_info->fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004156
Etan Cohend3652192014-06-20 08:28:44 -07004157 ril_event_del(p_info->commands_event);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004158
4159 record_stream_free(p_rs);
4160
4161 /* start listening for new connections again */
4162 rilEventAddWakeup(&s_listen_event);
4163
Etan Cohend3652192014-06-20 08:28:44 -07004164 onCommandsSocketClosed(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004165 }
4166}
4167
4168
Etan Cohend3652192014-06-20 08:28:44 -07004169static void onNewCommandConnect(RIL_SOCKET_ID socket_id) {
Wink Saville5b9df332011-04-06 16:24:21 -07004170 // Inform we are connected and the ril version
Jake Hambya9c18d12011-04-12 23:32:08 -07004171 int rilVer = s_callbacks.version;
Etan Cohend3652192014-06-20 08:28:44 -07004172 RIL_UNSOL_RESPONSE(RIL_UNSOL_RIL_CONNECTED,
4173 &rilVer, sizeof(rilVer), socket_id);
Wink Saville5b9df332011-04-06 16:24:21 -07004174
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004175 // implicit radio state changed
Etan Cohend3652192014-06-20 08:28:44 -07004176 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
4177 NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004178
4179 // Send last NITZ time data, in case it was missed
4180 if (s_lastNITZTimeData != NULL) {
Etan Cohend3652192014-06-20 08:28:44 -07004181 sendResponseRaw(s_lastNITZTimeData, s_lastNITZTimeDataSize, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004182
4183 free(s_lastNITZTimeData);
4184 s_lastNITZTimeData = NULL;
4185 }
4186
4187 // Get version string
4188 if (s_callbacks.getVersion != NULL) {
4189 const char *version;
4190 version = s_callbacks.getVersion();
Wink Saville8eb2a122012-11-19 16:05:13 -08004191 RLOGI("RIL Daemon version: %s\n", version);
Wink Saville7f856802009-06-09 10:23:37 -07004192
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004193 property_set(PROPERTY_RIL_IMPL, version);
4194 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08004195 RLOGI("RIL Daemon version: unavailable\n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004196 property_set(PROPERTY_RIL_IMPL, "unavailable");
4197 }
4198
4199}
4200
Wink Savillef4c4d362009-04-02 01:37:03 -07004201static void listenCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004202 int ret;
4203 int err;
4204 int is_phone_socket;
Etan Cohend3652192014-06-20 08:28:44 -07004205 int fdCommand = -1;
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004206 char* processName;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004207 RecordStream *p_rs;
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004208 MySocketListenParam* listenParam;
4209 RilSocket *sapSocket = NULL;
4210 socketClient *sClient = NULL;
4211
Etan Cohend3652192014-06-20 08:28:44 -07004212 SocketListenParam *p_info = (SocketListenParam *)param;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004213
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004214 if(RIL_SAP_SOCKET == p_info->type) {
4215 listenParam = (MySocketListenParam *)param;
4216 sapSocket = listenParam->socket;
4217 }
4218
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004219 struct sockaddr_un peeraddr;
4220 socklen_t socklen = sizeof (peeraddr);
4221
4222 struct ucred creds;
4223 socklen_t szCreds = sizeof(creds);
4224
4225 struct passwd *pwd = NULL;
4226
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004227 if(NULL == sapSocket) {
4228 assert (*p_info->fdCommand < 0);
4229 assert (fd == *p_info->fdListen);
4230 processName = PHONE_PROCESS;
4231 } else {
4232 assert (sapSocket->commandFd < 0);
4233 assert (fd == sapSocket->listenFd);
4234 processName = BLUETOOTH_PROCESS;
4235 }
4236
Wink Saville7f856802009-06-09 10:23:37 -07004237
Etan Cohend3652192014-06-20 08:28:44 -07004238 fdCommand = accept(fd, (sockaddr *) &peeraddr, &socklen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004239
Etan Cohend3652192014-06-20 08:28:44 -07004240 if (fdCommand < 0 ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004241 RLOGE("Error on accept() errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004242 /* start listening for new connections again */
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004243 if(NULL == sapSocket) {
4244 rilEventAddWakeup(p_info->listen_event);
4245 } else {
4246 rilEventAddWakeup(sapSocket->getListenEvent());
4247 }
Etan Cohend3652192014-06-20 08:28:44 -07004248 return;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004249 }
4250
4251 /* check the credential of the other side and only accept socket from
4252 * phone process
Wink Saville7f856802009-06-09 10:23:37 -07004253 */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004254 errno = 0;
4255 is_phone_socket = 0;
Wink Savillef4c4d362009-04-02 01:37:03 -07004256
Etan Cohend3652192014-06-20 08:28:44 -07004257 err = getsockopt(fdCommand, SOL_SOCKET, SO_PEERCRED, &creds, &szCreds);
Wink Savillef4c4d362009-04-02 01:37:03 -07004258
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004259 if (err == 0 && szCreds > 0) {
Wink Savillef4c4d362009-04-02 01:37:03 -07004260 errno = 0;
4261 pwd = getpwuid(creds.uid);
4262 if (pwd != NULL) {
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004263 if (strcmp(pwd->pw_name, processName) == 0) {
Wink Savillef4c4d362009-04-02 01:37:03 -07004264 is_phone_socket = 1;
4265 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08004266 RLOGE("RILD can't accept socket from process %s", pwd->pw_name);
Wink Savillef4c4d362009-04-02 01:37:03 -07004267 }
4268 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08004269 RLOGE("Error on getpwuid() errno: %d", errno);
Wink Savillef4c4d362009-04-02 01:37:03 -07004270 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004271 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08004272 RLOGD("Error on getsockopt() errno: %d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004273 }
4274
Etan Cohend3652192014-06-20 08:28:44 -07004275 if (!is_phone_socket) {
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004276 RLOGE("RILD must accept socket from %s", processName);
Wink Saville7f856802009-06-09 10:23:37 -07004277
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004278 close(fdCommand);
4279 fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004280
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004281 if(NULL == sapSocket) {
4282 onCommandsSocketClosed(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004283
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004284 /* start listening for new connections again */
4285 rilEventAddWakeup(p_info->listen_event);
4286 } else {
4287 sapSocket->onCommandsSocketClosed();
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004288
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004289 /* start listening for new connections again */
4290 rilEventAddWakeup(sapSocket->getListenEvent());
4291 }
4292
4293 return;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004294 }
4295
Etan Cohend3652192014-06-20 08:28:44 -07004296 ret = fcntl(fdCommand, F_SETFL, O_NONBLOCK);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004297
4298 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004299 RLOGE ("Error setting O_NONBLOCK errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004300 }
4301
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004302 if(NULL == sapSocket) {
4303 RLOGI("libril: new connection to %s", rilSocketIdToString(p_info->socket_id));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004304
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004305 p_info->fdCommand = fdCommand;
4306 p_rs = record_stream_new(p_info->fdCommand, MAX_COMMAND_BYTES);
4307 p_info->p_rs = p_rs;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004308
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004309 ril_event_set (p_info->commands_event, p_info->fdCommand, 1,
Etan Cohend3652192014-06-20 08:28:44 -07004310 p_info->processCommandsCallback, p_info);
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004311 rilEventAddWakeup (p_info->commands_event);
Etan Cohend3652192014-06-20 08:28:44 -07004312
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004313 onNewCommandConnect(p_info->socket_id);
4314 } else {
4315 RLOGI("libril: new connection");
Etan Cohend3652192014-06-20 08:28:44 -07004316
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004317 sapSocket->setCommandFd(fdCommand);
4318 p_rs = record_stream_new(sapSocket->getCommandFd(), MAX_COMMAND_BYTES);
4319 sClient = new socketClient(sapSocket,p_rs);
4320 ril_event_set (sapSocket->getCallbackEvent(), sapSocket->getCommandFd(), 1,
4321 sapSocket->getCommandCb(), sClient);
4322
4323 rilEventAddWakeup(sapSocket->getCallbackEvent());
4324 sapSocket->onNewCommandConnect();
4325 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004326}
4327
4328static void freeDebugCallbackArgs(int number, char **args) {
4329 for (int i = 0; i < number; i++) {
4330 if (args[i] != NULL) {
4331 free(args[i]);
4332 }
4333 }
4334 free(args);
4335}
4336
Wink Savillef4c4d362009-04-02 01:37:03 -07004337static void debugCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004338 int acceptFD, option;
4339 struct sockaddr_un peeraddr;
4340 socklen_t socklen = sizeof (peeraddr);
4341 int data;
4342 unsigned int qxdm_data[6];
4343 const char *deactData[1] = {"1"};
4344 char *actData[1];
4345 RIL_Dial dialData;
4346 int hangupData[1] = {1};
4347 int number;
4348 char **args;
Etan Cohend3652192014-06-20 08:28:44 -07004349 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
4350 int sim_id = 0;
4351
4352 RLOGI("debugCallback for socket %s", rilSocketIdToString(socket_id));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004353
4354 acceptFD = accept (fd, (sockaddr *) &peeraddr, &socklen);
4355
4356 if (acceptFD < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004357 RLOGE ("error accepting on debug port: %d\n", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004358 return;
4359 }
4360
4361 if (recv(acceptFD, &number, sizeof(int), 0) != sizeof(int)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004362 RLOGE ("error reading on socket: number of Args: \n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004363 return;
4364 }
4365 args = (char **) malloc(sizeof(char*) * number);
4366
4367 for (int i = 0; i < number; i++) {
4368 int len;
4369 if (recv(acceptFD, &len, sizeof(int), 0) != sizeof(int)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004370 RLOGE ("error reading on socket: Len of Args: \n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004371 freeDebugCallbackArgs(i, args);
4372 return;
4373 }
4374 // +1 for null-term
4375 args[i] = (char *) malloc((sizeof(char) * len) + 1);
Wink Saville7f856802009-06-09 10:23:37 -07004376 if (recv(acceptFD, args[i], sizeof(char) * len, 0)
Wink Saville1b5fd232009-04-22 14:50:00 -07004377 != (int)sizeof(char) * len) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004378 RLOGE ("error reading on socket: Args[%d] \n", i);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004379 freeDebugCallbackArgs(i, args);
4380 return;
4381 }
4382 char * buf = args[i];
4383 buf[len] = 0;
Etan Cohend3652192014-06-20 08:28:44 -07004384 if ((i+1) == number) {
4385 /* The last argument should be sim id 0(SIM1)~3(SIM4) */
4386 sim_id = atoi(args[i]);
4387 switch (sim_id) {
4388 case 0:
4389 socket_id = RIL_SOCKET_1;
4390 break;
4391 #if (SIM_COUNT >= 2)
4392 case 1:
4393 socket_id = RIL_SOCKET_2;
4394 break;
4395 #endif
4396 #if (SIM_COUNT >= 3)
4397 case 2:
4398 socket_id = RIL_SOCKET_3;
4399 break;
4400 #endif
4401 #if (SIM_COUNT >= 4)
4402 case 3:
4403 socket_id = RIL_SOCKET_4;
4404 break;
4405 #endif
4406 default:
4407 socket_id = RIL_SOCKET_1;
4408 break;
4409 }
4410 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004411 }
4412
4413 switch (atoi(args[0])) {
4414 case 0:
Wink Saville8eb2a122012-11-19 16:05:13 -08004415 RLOGI ("Connection on debug port: issuing reset.");
Etan Cohend3652192014-06-20 08:28:44 -07004416 issueLocalRequest(RIL_REQUEST_RESET_RADIO, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004417 break;
4418 case 1:
Wink Saville8eb2a122012-11-19 16:05:13 -08004419 RLOGI ("Connection on debug port: issuing radio power off.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004420 data = 0;
Etan Cohend3652192014-06-20 08:28:44 -07004421 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004422 // Close the socket
Etan Cohend3652192014-06-20 08:28:44 -07004423 if (socket_id == RIL_SOCKET_1 && s_ril_param_socket.fdCommand > 0) {
4424 close(s_ril_param_socket.fdCommand);
4425 s_ril_param_socket.fdCommand = -1;
4426 }
4427 #if (SIM_COUNT == 2)
4428 else if (socket_id == RIL_SOCKET_2 && s_ril_param_socket2.fdCommand > 0) {
4429 close(s_ril_param_socket2.fdCommand);
4430 s_ril_param_socket2.fdCommand = -1;
4431 }
4432 #endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004433 break;
4434 case 2:
Wink Saville8eb2a122012-11-19 16:05:13 -08004435 RLOGI ("Debug port: issuing unsolicited voice network change.");
Etan Cohend3652192014-06-20 08:28:44 -07004436 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004437 break;
4438 case 3:
Wink Saville8eb2a122012-11-19 16:05:13 -08004439 RLOGI ("Debug port: QXDM log enable.");
Xia Wangd855ef42010-07-27 17:26:55 -07004440 qxdm_data[0] = 65536; // head.func_tag
4441 qxdm_data[1] = 16; // head.len
4442 qxdm_data[2] = 1; // mode: 1 for 'start logging'
4443 qxdm_data[3] = 32; // log_file_size: 32megabytes
4444 qxdm_data[4] = 0; // log_mask
4445 qxdm_data[5] = 8; // log_max_fileindex
Wink Saville7f856802009-06-09 10:23:37 -07004446 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Etan Cohend3652192014-06-20 08:28:44 -07004447 6 * sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004448 break;
4449 case 4:
Wink Saville8eb2a122012-11-19 16:05:13 -08004450 RLOGI ("Debug port: QXDM log disable.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004451 qxdm_data[0] = 65536;
4452 qxdm_data[1] = 16;
Xia Wangd855ef42010-07-27 17:26:55 -07004453 qxdm_data[2] = 0; // mode: 0 for 'stop logging'
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004454 qxdm_data[3] = 32;
4455 qxdm_data[4] = 0;
Xia Wangd855ef42010-07-27 17:26:55 -07004456 qxdm_data[5] = 8;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004457 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Etan Cohend3652192014-06-20 08:28:44 -07004458 6 * sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004459 break;
4460 case 5:
Wink Saville8eb2a122012-11-19 16:05:13 -08004461 RLOGI("Debug port: Radio On");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004462 data = 1;
Etan Cohend3652192014-06-20 08:28:44 -07004463 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004464 sleep(2);
4465 // Set network selection automatic.
Etan Cohend3652192014-06-20 08:28:44 -07004466 issueLocalRequest(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004467 break;
4468 case 6:
Wink Saville8eb2a122012-11-19 16:05:13 -08004469 RLOGI("Debug port: Setup Data Call, Apn :%s\n", args[1]);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004470 actData[0] = args[1];
Wink Saville7f856802009-06-09 10:23:37 -07004471 issueLocalRequest(RIL_REQUEST_SETUP_DATA_CALL, &actData,
Etan Cohend3652192014-06-20 08:28:44 -07004472 sizeof(actData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004473 break;
4474 case 7:
Wink Saville8eb2a122012-11-19 16:05:13 -08004475 RLOGI("Debug port: Deactivate Data Call");
Wink Saville7f856802009-06-09 10:23:37 -07004476 issueLocalRequest(RIL_REQUEST_DEACTIVATE_DATA_CALL, &deactData,
Etan Cohend3652192014-06-20 08:28:44 -07004477 sizeof(deactData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004478 break;
4479 case 8:
Wink Saville8eb2a122012-11-19 16:05:13 -08004480 RLOGI("Debug port: Dial Call");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004481 dialData.clir = 0;
4482 dialData.address = args[1];
Etan Cohend3652192014-06-20 08:28:44 -07004483 issueLocalRequest(RIL_REQUEST_DIAL, &dialData, sizeof(dialData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004484 break;
4485 case 9:
Wink Saville8eb2a122012-11-19 16:05:13 -08004486 RLOGI("Debug port: Answer Call");
Etan Cohend3652192014-06-20 08:28:44 -07004487 issueLocalRequest(RIL_REQUEST_ANSWER, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004488 break;
4489 case 10:
Wink Saville8eb2a122012-11-19 16:05:13 -08004490 RLOGI("Debug port: End Call");
Wink Saville7f856802009-06-09 10:23:37 -07004491 issueLocalRequest(RIL_REQUEST_HANGUP, &hangupData,
Etan Cohend3652192014-06-20 08:28:44 -07004492 sizeof(hangupData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004493 break;
4494 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004495 RLOGE ("Invalid request");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004496 break;
4497 }
4498 freeDebugCallbackArgs(number, args);
4499 close(acceptFD);
4500}
4501
4502
Wink Savillef4c4d362009-04-02 01:37:03 -07004503static void userTimerCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004504 UserCallbackInfo *p_info;
4505
4506 p_info = (UserCallbackInfo *)param;
4507
4508 p_info->p_callback(p_info->userParam);
4509
4510
4511 // FIXME generalize this...there should be a cancel mechanism
4512 if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) {
4513 s_last_wake_timeout_info = NULL;
4514 }
4515
4516 free(p_info);
4517}
4518
4519
4520static void *
Wink Savillef4c4d362009-04-02 01:37:03 -07004521eventLoop(void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004522 int ret;
4523 int filedes[2];
4524
4525 ril_event_init();
4526
4527 pthread_mutex_lock(&s_startupMutex);
4528
4529 s_started = 1;
4530 pthread_cond_broadcast(&s_startupCond);
4531
4532 pthread_mutex_unlock(&s_startupMutex);
4533
4534 ret = pipe(filedes);
4535
4536 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004537 RLOGE("Error in pipe() errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004538 return NULL;
4539 }
4540
4541 s_fdWakeupRead = filedes[0];
4542 s_fdWakeupWrite = filedes[1];
4543
4544 fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK);
4545
4546 ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,
4547 processWakeupCallback, NULL);
4548
4549 rilEventAddWakeup (&s_wakeupfd_event);
4550
4551 // Only returns on error
4552 ril_event_loop();
Wink Saville8eb2a122012-11-19 16:05:13 -08004553 RLOGE ("error in event_loop_base errno:%d", errno);
Kazuhiro Ondo5cdc1352011-10-14 17:50:58 -05004554 // kill self to restart on error
4555 kill(0, SIGKILL);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004556
4557 return NULL;
4558}
4559
Wink Saville7f856802009-06-09 10:23:37 -07004560extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07004561RIL_startEventLoop(void) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004562 /* spin up eventLoop thread and wait for it to get started */
4563 s_started = 0;
4564 pthread_mutex_lock(&s_startupMutex);
4565
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004566 pthread_attr_t attr;
4567 pthread_attr_init(&attr);
Wink Saville7f856802009-06-09 10:23:37 -07004568 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004569
Elliott Hughesfd81e712014-01-06 12:46:02 -08004570 int result = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
4571 if (result != 0) {
4572 RLOGE("Failed to create dispatch thread: %s", strerror(result));
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004573 goto done;
4574 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004575
4576 while (s_started == 0) {
4577 pthread_cond_wait(&s_startupCond, &s_startupMutex);
4578 }
4579
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004580done:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004581 pthread_mutex_unlock(&s_startupMutex);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004582}
4583
4584// Used for testing purpose only.
4585extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) {
4586 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4587}
4588
Etan Cohend3652192014-06-20 08:28:44 -07004589static void startListen(RIL_SOCKET_ID socket_id, SocketListenParam* socket_listen_p) {
4590 int fdListen = -1;
4591 int ret;
4592 char socket_name[10];
4593
4594 memset(socket_name, 0, sizeof(char)*10);
4595
4596 switch(socket_id) {
4597 case RIL_SOCKET_1:
4598 strncpy(socket_name, RIL_getRilSocketName(), 9);
4599 break;
4600 #if (SIM_COUNT >= 2)
4601 case RIL_SOCKET_2:
4602 strncpy(socket_name, SOCKET2_NAME_RIL, 9);
4603 break;
4604 #endif
4605 #if (SIM_COUNT >= 3)
4606 case RIL_SOCKET_3:
4607 strncpy(socket_name, SOCKET3_NAME_RIL, 9);
4608 break;
4609 #endif
4610 #if (SIM_COUNT >= 4)
4611 case RIL_SOCKET_4:
4612 strncpy(socket_name, SOCKET4_NAME_RIL, 9);
4613 break;
4614 #endif
4615 default:
4616 RLOGE("Socket id is wrong!!");
4617 return;
4618 }
4619
4620 RLOGI("Start to listen %s", rilSocketIdToString(socket_id));
4621
4622 fdListen = android_get_control_socket(socket_name);
4623 if (fdListen < 0) {
4624 RLOGE("Failed to get socket %s", socket_name);
4625 exit(-1);
4626 }
4627
4628 ret = listen(fdListen, 4);
4629
4630 if (ret < 0) {
4631 RLOGE("Failed to listen on control socket '%d': %s",
4632 fdListen, strerror(errno));
4633 exit(-1);
4634 }
4635 socket_listen_p->fdListen = fdListen;
4636
4637 /* note: non-persistent so we can accept only one connection at a time */
4638 ril_event_set (socket_listen_p->listen_event, fdListen, false,
4639 listenCallback, socket_listen_p);
4640
4641 rilEventAddWakeup (socket_listen_p->listen_event);
4642}
4643
Wink Saville7f856802009-06-09 10:23:37 -07004644extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07004645RIL_register (const RIL_RadioFunctions *callbacks) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004646 int ret;
4647 int flags;
4648
Etan Cohend3652192014-06-20 08:28:44 -07004649 RLOGI("SIM_COUNT: %d", SIM_COUNT);
4650
Wink Saville43808972011-01-13 17:39:51 -08004651 if (callbacks == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004652 RLOGE("RIL_register: RIL_RadioFunctions * null");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004653 return;
4654 }
Wink Saville43808972011-01-13 17:39:51 -08004655 if (callbacks->version < RIL_VERSION_MIN) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004656 RLOGE("RIL_register: version %d is to old, min version is %d",
Wink Saville43808972011-01-13 17:39:51 -08004657 callbacks->version, RIL_VERSION_MIN);
4658 return;
Wink Saville3a4840b2010-04-07 13:29:58 -07004659 }
Sanket Padawe88cf6a52016-01-11 12:45:43 -08004660
Wink Saville8eb2a122012-11-19 16:05:13 -08004661 RLOGE("RIL_register: RIL version %d", callbacks->version);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004662
4663 if (s_registerCalled > 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004664 RLOGE("RIL_register has been called more than once. "
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004665 "Subsequent call ignored");
4666 return;
4667 }
4668
4669 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4670
Etan Cohend3652192014-06-20 08:28:44 -07004671 /* Initialize socket1 parameters */
4672 s_ril_param_socket = {
4673 RIL_SOCKET_1, /* socket_id */
4674 -1, /* fdListen */
4675 -1, /* fdCommand */
4676 PHONE_PROCESS, /* processName */
4677 &s_commands_event, /* commands_event */
4678 &s_listen_event, /* listen_event */
4679 processCommandsCallback, /* processCommandsCallback */
4680 NULL /* p_rs */
4681 };
4682
4683#if (SIM_COUNT >= 2)
4684 s_ril_param_socket2 = {
4685 RIL_SOCKET_2, /* socket_id */
4686 -1, /* fdListen */
4687 -1, /* fdCommand */
4688 PHONE_PROCESS, /* processName */
4689 &s_commands_event_socket2, /* commands_event */
4690 &s_listen_event_socket2, /* listen_event */
4691 processCommandsCallback, /* processCommandsCallback */
4692 NULL /* p_rs */
4693 };
4694#endif
4695
4696#if (SIM_COUNT >= 3)
4697 s_ril_param_socket3 = {
4698 RIL_SOCKET_3, /* socket_id */
4699 -1, /* fdListen */
4700 -1, /* fdCommand */
4701 PHONE_PROCESS, /* processName */
4702 &s_commands_event_socket3, /* commands_event */
4703 &s_listen_event_socket3, /* listen_event */
4704 processCommandsCallback, /* processCommandsCallback */
4705 NULL /* p_rs */
4706 };
4707#endif
4708
4709#if (SIM_COUNT >= 4)
4710 s_ril_param_socket4 = {
4711 RIL_SOCKET_4, /* socket_id */
4712 -1, /* fdListen */
4713 -1, /* fdCommand */
4714 PHONE_PROCESS, /* processName */
4715 &s_commands_event_socket4, /* commands_event */
4716 &s_listen_event_socket4, /* listen_event */
4717 processCommandsCallback, /* processCommandsCallback */
4718 NULL /* p_rs */
4719 };
4720#endif
4721
4722
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004723 s_registerCalled = 1;
4724
Etan Cohend3652192014-06-20 08:28:44 -07004725 RLOGI("s_registerCalled flag set, %d", s_started);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004726 // Little self-check
4727
Wink Savillef4c4d362009-04-02 01:37:03 -07004728 for (int i = 0; i < (int)NUM_ELEMS(s_commands); i++) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004729 assert(i == s_commands[i].requestNumber);
4730 }
4731
Wink Savillef4c4d362009-04-02 01:37:03 -07004732 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses); i++) {
Wink Saville7f856802009-06-09 10:23:37 -07004733 assert(i + RIL_UNSOL_RESPONSE_BASE
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004734 == s_unsolResponses[i].requestNumber);
4735 }
4736
4737 // New rild impl calls RIL_startEventLoop() first
4738 // old standalone impl wants it here.
4739
4740 if (s_started == 0) {
4741 RIL_startEventLoop();
4742 }
4743
Etan Cohend3652192014-06-20 08:28:44 -07004744 // start listen socket1
4745 startListen(RIL_SOCKET_1, &s_ril_param_socket);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004746
Etan Cohend3652192014-06-20 08:28:44 -07004747#if (SIM_COUNT >= 2)
4748 // start listen socket2
4749 startListen(RIL_SOCKET_2, &s_ril_param_socket2);
4750#endif /* (SIM_COUNT == 2) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004751
Etan Cohend3652192014-06-20 08:28:44 -07004752#if (SIM_COUNT >= 3)
4753 // start listen socket3
4754 startListen(RIL_SOCKET_3, &s_ril_param_socket3);
4755#endif /* (SIM_COUNT == 3) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004756
Etan Cohend3652192014-06-20 08:28:44 -07004757#if (SIM_COUNT >= 4)
4758 // start listen socket4
4759 startListen(RIL_SOCKET_4, &s_ril_param_socket4);
4760#endif /* (SIM_COUNT == 4) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004761
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004762
4763#if 1
4764 // start debug interface socket
4765
Etan Cohend3652192014-06-20 08:28:44 -07004766 char *inst = NULL;
4767 if (strlen(RIL_getRilSocketName()) >= strlen(SOCKET_NAME_RIL)) {
4768 inst = RIL_getRilSocketName() + strlen(SOCKET_NAME_RIL);
4769 }
4770
4771 char rildebug[MAX_DEBUG_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL_DEBUG;
4772 if (inst != NULL) {
Nick Kralevichc52e45e2015-02-08 07:54:16 -08004773 strlcat(rildebug, inst, MAX_DEBUG_SOCKET_NAME_LENGTH);
Etan Cohend3652192014-06-20 08:28:44 -07004774 }
4775
4776 s_fdDebug = android_get_control_socket(rildebug);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004777 if (s_fdDebug < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07004778 RLOGE("Failed to get socket : %s errno:%d", rildebug, errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004779 exit(-1);
4780 }
4781
4782 ret = listen(s_fdDebug, 4);
4783
4784 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004785 RLOGE("Failed to listen on ril debug socket '%d': %s",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004786 s_fdDebug, strerror(errno));
4787 exit(-1);
4788 }
4789
4790 ril_event_set (&s_debug_event, s_fdDebug, true,
4791 debugCallback, NULL);
4792
4793 rilEventAddWakeup (&s_debug_event);
4794#endif
4795
4796}
4797
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004798extern "C" void
4799RIL_register_socket (RIL_RadioFunctions *(*Init)(const struct RIL_Env *, int, char **),RIL_SOCKET_TYPE socketType, int argc, char **argv) {
4800
4801 RIL_RadioFunctions* UimFuncs = NULL;
4802
4803 if(Init) {
4804 UimFuncs = Init(&RilSapSocket::uimRilEnv, argc, argv);
4805
4806 switch(socketType) {
4807 case RIL_SAP_SOCKET:
4808 RilSapSocket::initSapSocket("sap_uim_socket1", UimFuncs);
4809
4810#if (SIM_COUNT >= 2)
4811 RilSapSocket::initSapSocket("sap_uim_socket2", UimFuncs);
4812#endif
4813
4814#if (SIM_COUNT >= 3)
4815 RilSapSocket::initSapSocket("sap_uim_socket3", UimFuncs);
4816#endif
4817
4818#if (SIM_COUNT >= 4)
4819 RilSapSocket::initSapSocket("sap_uim_socket4", UimFuncs);
4820#endif
4821 }
4822 }
4823}
4824
Sanket Padawe6ff9a872016-01-27 15:09:12 -08004825// Check and remove RequestInfo if its a response and not just ack sent back
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004826static int
Sanket Padawe6ff9a872016-01-27 15:09:12 -08004827checkAndDequeueRequestInfoIfAck(struct RequestInfo *pRI, bool isAck) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004828 int ret = 0;
Etan Cohend3652192014-06-20 08:28:44 -07004829 /* Hook for current context
4830 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
4831 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
4832 /* pendingRequestsHook refer to &s_pendingRequests */
4833 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
Wink Saville7f856802009-06-09 10:23:37 -07004834
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004835 if (pRI == NULL) {
4836 return 0;
4837 }
4838
Etan Cohend3652192014-06-20 08:28:44 -07004839#if (SIM_COUNT >= 2)
4840 if (pRI->socket_id == RIL_SOCKET_2) {
4841 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
4842 pendingRequestsHook = &s_pendingRequests_socket2;
4843 }
4844#if (SIM_COUNT >= 3)
4845 if (pRI->socket_id == RIL_SOCKET_3) {
4846 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
4847 pendingRequestsHook = &s_pendingRequests_socket3;
4848 }
4849#endif
4850#if (SIM_COUNT >= 4)
4851 if (pRI->socket_id == RIL_SOCKET_4) {
4852 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
4853 pendingRequestsHook = &s_pendingRequests_socket4;
4854 }
4855#endif
4856#endif
4857 pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004858
Etan Cohend3652192014-06-20 08:28:44 -07004859 for(RequestInfo **ppCur = pendingRequestsHook
Wink Saville7f856802009-06-09 10:23:37 -07004860 ; *ppCur != NULL
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004861 ; ppCur = &((*ppCur)->p_next)
4862 ) {
4863 if (pRI == *ppCur) {
4864 ret = 1;
Sanket Padawe6ff9a872016-01-27 15:09:12 -08004865 if (isAck) { // Async ack
4866 if (pRI->wasAckSent == 1) {
4867 RLOGD("Ack was already sent for %s", requestToString(pRI->pCI->requestNumber));
4868 } else {
4869 pRI->wasAckSent = 1;
4870 }
4871 } else {
4872 *ppCur = (*ppCur)->p_next;
4873 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004874 break;
4875 }
4876 }
4877
Etan Cohend3652192014-06-20 08:28:44 -07004878 pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004879
4880 return ret;
4881}
4882
Sanket Padawe6ff9a872016-01-27 15:09:12 -08004883static int findFd(int socket_id) {
Etan Cohend3652192014-06-20 08:28:44 -07004884 int fd = s_ril_param_socket.fdCommand;
Etan Cohend3652192014-06-20 08:28:44 -07004885#if (SIM_COUNT >= 2)
4886 if (socket_id == RIL_SOCKET_2) {
4887 fd = s_ril_param_socket2.fdCommand;
4888 }
4889#if (SIM_COUNT >= 3)
Sanket Padawe6ff9a872016-01-27 15:09:12 -08004890 if (socket_id == RIL_SOCKET_3) {
4891 fd = s_ril_param_socket3.fdCommand;
4892 }
Etan Cohend3652192014-06-20 08:28:44 -07004893#endif
4894#if (SIM_COUNT >= 4)
4895 if (socket_id == RIL_SOCKET_4) {
4896 fd = s_ril_param_socket4.fdCommand;
4897 }
4898#endif
4899#endif
Sanket Padawe6ff9a872016-01-27 15:09:12 -08004900 return fd;
4901}
4902
4903extern "C" void
4904RIL_onRequestAck(RIL_Token t) {
4905 RequestInfo *pRI;
4906 int ret, fd;
4907
4908 size_t errorOffset;
4909 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
4910
4911 pRI = (RequestInfo *)t;
4912
4913 if (!checkAndDequeueRequestInfoIfAck(pRI, true)) {
4914 RLOGE ("RIL_onRequestAck: invalid RIL_Token");
4915 return;
4916 }
4917
4918 socket_id = pRI->socket_id;
4919 fd = findFd(socket_id);
4920
4921#if VDBG
4922 RLOGD("Request Ack, %s", rilSocketIdToString(socket_id));
4923#endif
4924
4925 appendPrintBuf("Ack [%04d]< %s", pRI->token, requestToString(pRI->pCI->requestNumber));
4926
4927 if (pRI->cancelled == 0) {
4928 Parcel p;
4929
4930 p.writeInt32 (RESPONSE_SOLICITED_ACK);
4931 p.writeInt32 (pRI->token);
4932
4933 if (fd < 0) {
4934 RLOGD ("RIL onRequestComplete: Command channel closed");
4935 }
4936
4937 sendResponse(p, socket_id);
4938 }
4939}
4940
4941extern "C" void
4942RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) {
4943 RequestInfo *pRI;
4944 int ret;
4945 int fd;
4946 size_t errorOffset;
4947 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
4948
4949 pRI = (RequestInfo *)t;
4950
4951 if (!checkAndDequeueRequestInfoIfAck(pRI, false)) {
4952 RLOGE ("RIL_onRequestComplete: invalid RIL_Token");
4953 return;
4954 }
4955
4956 socket_id = pRI->socket_id;
4957 fd = findFd(socket_id);
4958
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07004959#if VDBG
Etan Cohend3652192014-06-20 08:28:44 -07004960 RLOGD("RequestComplete, %s", rilSocketIdToString(socket_id));
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07004961#endif
Etan Cohend3652192014-06-20 08:28:44 -07004962
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004963 if (pRI->local > 0) {
4964 // Locally issued command...void only!
4965 // response does not go back up the command socket
Wink Saville8eb2a122012-11-19 16:05:13 -08004966 RLOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004967
4968 goto done;
4969 }
4970
4971 appendPrintBuf("[%04d]< %s",
4972 pRI->token, requestToString(pRI->pCI->requestNumber));
4973
4974 if (pRI->cancelled == 0) {
4975 Parcel p;
4976
Sanket Padawe6ff9a872016-01-27 15:09:12 -08004977 if (s_callbacks.version >= 13 && pRI->wasAckSent == 1) {
4978 // If ack was already sent, then this call is an asynchronous response. So we need to
4979 // send id indicating that we expect an ack from RIL.java as we acquire wakelock here.
4980 p.writeInt32 (RESPONSE_SOLICITED_ACK_EXP);
4981 grabPartialWakeLock();
4982 } else {
4983 p.writeInt32 (RESPONSE_SOLICITED);
4984 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004985 p.writeInt32 (pRI->token);
4986 errorOffset = p.dataPosition();
4987
4988 p.writeInt32 (e);
4989
johnwangb2a61842009-06-02 14:55:45 -07004990 if (response != NULL) {
4991 // there is a response payload, no matter success or not.
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004992 ret = pRI->pCI->responseFunction(p, response, responselen);
4993
4994 /* if an error occurred, rewind and mark it */
4995 if (ret != 0) {
Etan Cohend3652192014-06-20 08:28:44 -07004996 RLOGE ("responseFunction error, ret %d", ret);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004997 p.setDataPosition(errorOffset);
4998 p.writeInt32 (ret);
4999 }
johnwangb2a61842009-06-02 14:55:45 -07005000 }
5001
5002 if (e != RIL_E_SUCCESS) {
5003 appendPrintBuf("%s fails by %s", printBuf, failCauseToString(e));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005004 }
5005
Etan Cohend3652192014-06-20 08:28:44 -07005006 if (fd < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08005007 RLOGD ("RIL onRequestComplete: Command channel closed");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005008 }
Etan Cohend3652192014-06-20 08:28:44 -07005009 sendResponse(p, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005010 }
5011
5012done:
5013 free(pRI);
5014}
5015
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005016static void
Wink Savillef4c4d362009-04-02 01:37:03 -07005017grabPartialWakeLock() {
Sanket Padawe6ff9a872016-01-27 15:09:12 -08005018 if (s_callbacks.version >= 13) {
5019 int ret;
5020 ret = pthread_mutex_lock(&s_wakeLockCountMutex);
5021 assert(ret == 0);
5022 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
5023 s_wakelock_count++;
5024 if (s_last_wake_timeout_info != NULL) {
5025 s_last_wake_timeout_info->userParam = (void *)1;
5026 }
5027
5028 s_last_wake_timeout_info
5029 = internalRequestTimedCallback(wakeTimeoutCallback, NULL, &TIMEVAL_WAKE_TIMEOUT);
5030
5031 ret = pthread_mutex_unlock(&s_wakeLockCountMutex);
5032 assert(ret == 0);
5033 } else {
5034 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
5035 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005036}
5037
5038static void
Wink Savillef4c4d362009-04-02 01:37:03 -07005039releaseWakeLock() {
Sanket Padawe6ff9a872016-01-27 15:09:12 -08005040 if (s_callbacks.version >= 13) {
5041 int ret;
5042 ret = pthread_mutex_lock(&s_wakeLockCountMutex);
5043 assert(ret == 0);
5044
5045 if (s_wakelock_count > 1) {
5046 s_wakelock_count--;
5047 } else {
5048 s_wakelock_count = 0;
5049 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
5050 if (s_last_wake_timeout_info != NULL) {
5051 s_last_wake_timeout_info->userParam = (void *)1;
5052 }
5053 }
5054
5055 ret = pthread_mutex_unlock(&s_wakeLockCountMutex);
5056 assert(ret == 0);
5057 } else {
5058 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
5059 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005060}
5061
5062/**
5063 * Timer callback to put us back to sleep before the default timeout
5064 */
5065static void
Wink Savillef4c4d362009-04-02 01:37:03 -07005066wakeTimeoutCallback (void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005067 // We're using "param != NULL" as a cancellation mechanism
Sanket Padawe6ff9a872016-01-27 15:09:12 -08005068 if (s_callbacks.version >= 13) {
5069 if (param == NULL) {
5070 int ret;
5071 ret = pthread_mutex_lock(&s_wakeLockCountMutex);
5072 assert(ret == 0);
5073 s_wakelock_count = 0;
5074 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
5075 ret = pthread_mutex_unlock(&s_wakeLockCountMutex);
5076 assert(ret == 0);
5077 }
5078 } else {
5079 if (param == NULL) {
5080 releaseWakeLock();
5081 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005082 }
5083}
5084
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005085static int
5086decodeVoiceRadioTechnology (RIL_RadioState radioState) {
5087 switch (radioState) {
5088 case RADIO_STATE_SIM_NOT_READY:
5089 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
5090 case RADIO_STATE_SIM_READY:
5091 return RADIO_TECH_UMTS;
5092
5093 case RADIO_STATE_RUIM_NOT_READY:
5094 case RADIO_STATE_RUIM_READY:
5095 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
5096 case RADIO_STATE_NV_NOT_READY:
5097 case RADIO_STATE_NV_READY:
5098 return RADIO_TECH_1xRTT;
5099
5100 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08005101 RLOGD("decodeVoiceRadioTechnology: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005102 return -1;
5103 }
5104}
5105
5106static int
5107decodeCdmaSubscriptionSource (RIL_RadioState radioState) {
5108 switch (radioState) {
5109 case RADIO_STATE_SIM_NOT_READY:
5110 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
5111 case RADIO_STATE_SIM_READY:
5112 case RADIO_STATE_RUIM_NOT_READY:
5113 case RADIO_STATE_RUIM_READY:
5114 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
5115 return CDMA_SUBSCRIPTION_SOURCE_RUIM_SIM;
5116
5117 case RADIO_STATE_NV_NOT_READY:
5118 case RADIO_STATE_NV_READY:
5119 return CDMA_SUBSCRIPTION_SOURCE_NV;
5120
5121 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08005122 RLOGD("decodeCdmaSubscriptionSource: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005123 return -1;
5124 }
5125}
5126
5127static int
5128decodeSimStatus (RIL_RadioState radioState) {
5129 switch (radioState) {
5130 case RADIO_STATE_SIM_NOT_READY:
5131 case RADIO_STATE_RUIM_NOT_READY:
5132 case RADIO_STATE_NV_NOT_READY:
5133 case RADIO_STATE_NV_READY:
5134 return -1;
5135 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
5136 case RADIO_STATE_SIM_READY:
5137 case RADIO_STATE_RUIM_READY:
5138 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
5139 return radioState;
5140 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08005141 RLOGD("decodeSimStatus: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005142 return -1;
5143 }
5144}
5145
5146static bool is3gpp2(int radioTech) {
5147 switch (radioTech) {
5148 case RADIO_TECH_IS95A:
5149 case RADIO_TECH_IS95B:
5150 case RADIO_TECH_1xRTT:
5151 case RADIO_TECH_EVDO_0:
5152 case RADIO_TECH_EVDO_A:
5153 case RADIO_TECH_EVDO_B:
5154 case RADIO_TECH_EHRPD:
5155 return true;
5156 default:
5157 return false;
5158 }
5159}
5160
5161/* If RIL sends SIM states or RUIM states, store the voice radio
5162 * technology and subscription source information so that they can be
5163 * returned when telephony framework requests them
5164 */
5165static RIL_RadioState
Etan Cohend3652192014-06-20 08:28:44 -07005166processRadioState(RIL_RadioState newRadioState, RIL_SOCKET_ID socket_id) {
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005167
5168 if((newRadioState > RADIO_STATE_UNAVAILABLE) && (newRadioState < RADIO_STATE_ON)) {
5169 int newVoiceRadioTech;
5170 int newCdmaSubscriptionSource;
5171 int newSimStatus;
5172
5173 /* This is old RIL. Decode Subscription source and Voice Radio Technology
5174 from Radio State and send change notifications if there has been a change */
5175 newVoiceRadioTech = decodeVoiceRadioTechnology(newRadioState);
5176 if(newVoiceRadioTech != voiceRadioTech) {
5177 voiceRadioTech = newVoiceRadioTech;
Etan Cohend3652192014-06-20 08:28:44 -07005178 RIL_UNSOL_RESPONSE(RIL_UNSOL_VOICE_RADIO_TECH_CHANGED,
5179 &voiceRadioTech, sizeof(voiceRadioTech), socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005180 }
5181 if(is3gpp2(newVoiceRadioTech)) {
5182 newCdmaSubscriptionSource = decodeCdmaSubscriptionSource(newRadioState);
5183 if(newCdmaSubscriptionSource != cdmaSubscriptionSource) {
5184 cdmaSubscriptionSource = newCdmaSubscriptionSource;
Etan Cohend3652192014-06-20 08:28:44 -07005185 RIL_UNSOL_RESPONSE(RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED,
5186 &cdmaSubscriptionSource, sizeof(cdmaSubscriptionSource), socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005187 }
5188 }
5189 newSimStatus = decodeSimStatus(newRadioState);
5190 if(newSimStatus != simRuimStatus) {
5191 simRuimStatus = newSimStatus;
Etan Cohend3652192014-06-20 08:28:44 -07005192 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0, socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005193 }
5194
5195 /* Send RADIO_ON to telephony */
5196 newRadioState = RADIO_STATE_ON;
5197 }
5198
5199 return newRadioState;
5200}
5201
Etan Cohend3652192014-06-20 08:28:44 -07005202
5203#if defined(ANDROID_MULTI_SIM)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005204extern "C"
Bernhard Rosenkränzerd613b962014-11-17 20:52:09 +01005205void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Etan Cohend3652192014-06-20 08:28:44 -07005206 size_t datalen, RIL_SOCKET_ID socket_id)
5207#else
5208extern "C"
Bernhard Rosenkränzerd613b962014-11-17 20:52:09 +01005209void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005210 size_t datalen)
Etan Cohend3652192014-06-20 08:28:44 -07005211#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005212{
5213 int unsolResponseIndex;
5214 int ret;
5215 int64_t timeReceived = 0;
5216 bool shouldScheduleTimeout = false;
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005217 RIL_RadioState newState;
Etan Cohend3652192014-06-20 08:28:44 -07005218 RIL_SOCKET_ID soc_id = RIL_SOCKET_1;
5219
5220#if defined(ANDROID_MULTI_SIM)
5221 soc_id = socket_id;
5222#endif
5223
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005224
5225 if (s_registerCalled == 0) {
5226 // Ignore RIL_onUnsolicitedResponse before RIL_register
Wink Saville8eb2a122012-11-19 16:05:13 -08005227 RLOGW("RIL_onUnsolicitedResponse called before RIL_register");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005228 return;
5229 }
Wink Saville7f856802009-06-09 10:23:37 -07005230
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005231 unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
5232
5233 if ((unsolResponseIndex < 0)
5234 || (unsolResponseIndex >= (int32_t)NUM_ELEMS(s_unsolResponses))) {
Wink Saville8eb2a122012-11-19 16:05:13 -08005235 RLOGE("unsupported unsolicited response code %d", unsolResponse);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005236 return;
5237 }
5238
5239 // Grab a wake lock if needed for this reponse,
5240 // as we exit we'll either release it immediately
5241 // or set a timer to release it later.
5242 switch (s_unsolResponses[unsolResponseIndex].wakeType) {
5243 case WAKE_PARTIAL:
5244 grabPartialWakeLock();
5245 shouldScheduleTimeout = true;
5246 break;
5247
5248 case DONT_WAKE:
5249 default:
5250 // No wake lock is grabed so don't set timeout
5251 shouldScheduleTimeout = false;
5252 break;
5253 }
5254
5255 // Mark the time this was received, doing this
5256 // after grabing the wakelock incase getting
5257 // the elapsedRealTime might cause us to goto
5258 // sleep.
5259 if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
5260 timeReceived = elapsedRealtime();
5261 }
5262
5263 appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
5264
5265 Parcel p;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005266 p.writeInt32 (RESPONSE_UNSOLICITED);
5267 p.writeInt32 (unsolResponse);
5268
5269 ret = s_unsolResponses[unsolResponseIndex]
Bernhard Rosenkränzer6e7c1962013-12-12 10:01:10 +01005270 .responseFunction(p, const_cast<void*>(data), datalen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005271 if (ret != 0) {
5272 // Problem with the response. Don't continue;
5273 goto error_exit;
5274 }
5275
5276 // some things get more payload
5277 switch(unsolResponse) {
5278 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
Etan Cohend3652192014-06-20 08:28:44 -07005279 newState = processRadioState(CALL_ONSTATEREQUEST(soc_id), soc_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005280 p.writeInt32(newState);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005281 appendPrintBuf("%s {%s}", printBuf,
Etan Cohend3652192014-06-20 08:28:44 -07005282 radioStateToString(CALL_ONSTATEREQUEST(soc_id)));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005283 break;
5284
5285
5286 case RIL_UNSOL_NITZ_TIME_RECEIVED:
5287 // Store the time that this was received so the
5288 // handler of this message can account for
5289 // the time it takes to arrive and process. In
5290 // particular the system has been known to sleep
5291 // before this message can be processed.
5292 p.writeInt64(timeReceived);
5293 break;
5294 }
5295
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07005296#if VDBG
Etan Cohend3652192014-06-20 08:28:44 -07005297 RLOGI("%s UNSOLICITED: %s length:%d", rilSocketIdToString(soc_id), requestToString(unsolResponse), p.dataSize());
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07005298#endif
Etan Cohend3652192014-06-20 08:28:44 -07005299 ret = sendResponse(p, soc_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005300 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
5301
5302 // Unfortunately, NITZ time is not poll/update like everything
5303 // else in the system. So, if the upstream client isn't connected,
5304 // keep a copy of the last NITZ response (with receive time noted
5305 // above) around so we can deliver it when it is connected
5306
5307 if (s_lastNITZTimeData != NULL) {
5308 free (s_lastNITZTimeData);
5309 s_lastNITZTimeData = NULL;
5310 }
5311
5312 s_lastNITZTimeData = malloc(p.dataSize());
5313 s_lastNITZTimeDataSize = p.dataSize();
5314 memcpy(s_lastNITZTimeData, p.data(), p.dataSize());
5315 }
5316
Sanket Padawe6ff9a872016-01-27 15:09:12 -08005317 if (s_callbacks.version < 13) {
5318 if (shouldScheduleTimeout) {
5319 // Cancel the previous request
5320 if (s_last_wake_timeout_info != NULL) {
5321 s_last_wake_timeout_info->userParam = (void *)1;
5322 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005323
Sanket Padawe6ff9a872016-01-27 15:09:12 -08005324 s_last_wake_timeout_info
5325 = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
5326 &TIMEVAL_WAKE_TIMEOUT);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005327 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005328 }
5329
5330 // Normal exit
5331 return;
5332
5333error_exit:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005334 if (shouldScheduleTimeout) {
5335 releaseWakeLock();
5336 }
5337}
5338
Wink Saville7f856802009-06-09 10:23:37 -07005339/** FIXME generalize this if you track UserCAllbackInfo, clear it
5340 when the callback occurs
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005341*/
5342static UserCallbackInfo *
Wink Saville7f856802009-06-09 10:23:37 -07005343internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07005344 const struct timeval *relativeTime)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005345{
5346 struct timeval myRelativeTime;
5347 UserCallbackInfo *p_info;
5348
5349 p_info = (UserCallbackInfo *) malloc (sizeof(UserCallbackInfo));
5350
Wink Saville7f856802009-06-09 10:23:37 -07005351 p_info->p_callback = callback;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005352 p_info->userParam = param;
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07005353
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005354 if (relativeTime == NULL) {
5355 /* treat null parameter as a 0 relative time */
5356 memset (&myRelativeTime, 0, sizeof(myRelativeTime));
5357 } else {
5358 /* FIXME I think event_add's tv param is really const anyway */
5359 memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
5360 }
5361
5362 ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
5363
5364 ril_timer_add(&(p_info->event), &myRelativeTime);
5365
5366 triggerEvLoop();
5367 return p_info;
5368}
5369
Naveen Kalla7edd07c2010-06-21 18:54:47 -07005370
5371extern "C" void
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07005372RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
5373 const struct timeval *relativeTime) {
5374 internalRequestTimedCallback (callback, param, relativeTime);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005375}
5376
5377const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07005378failCauseToString(RIL_Errno e) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005379 switch(e) {
5380 case RIL_E_SUCCESS: return "E_SUCCESS";
Robert Greenwalt2126ab22013-04-09 12:20:45 -07005381 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RADIO_NOT_AVAILABLE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005382 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
5383 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
5384 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
5385 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
5386 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
5387 case RIL_E_CANCELLED: return "E_CANCELLED";
5388 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
5389 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
5390 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
Wink Savillef4c4d362009-04-02 01:37:03 -07005391 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
John Wang75534472010-04-20 15:11:42 -07005392 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
Wink Saville7f856802009-06-09 10:23:37 -07005393#ifdef FEATURE_MULTIMODE_ANDROID
Wink Savillef4c4d362009-04-02 01:37:03 -07005394 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
5395 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
5396#endif
Sanket Padaweb39e5c92016-02-08 14:28:59 -08005397 case RIL_E_FDN_CHECK_FAILURE: return "E_FDN_CHECK_FAILURE";
5398 case RIL_E_MISSING_RESOURCE: return "E_MISSING_RESOURCE";
5399 case RIL_E_NO_SUCH_ELEMENT: return "E_NO_SUCH_ELEMENT";
5400 case RIL_E_DIAL_MODIFIED_TO_USSD: return "E_DIAL_MODIFIED_TO_USSD";
5401 case RIL_E_DIAL_MODIFIED_TO_SS: return "E_DIAL_MODIFIED_TO_SS";
5402 case RIL_E_DIAL_MODIFIED_TO_DIAL: return "E_DIAL_MODIFIED_TO_DIAL";
5403 case RIL_E_USSD_MODIFIED_TO_DIAL: return "E_USSD_MODIFIED_TO_DIAL";
5404 case RIL_E_USSD_MODIFIED_TO_SS: return "E_USSD_MODIFIED_TO_SS";
5405 case RIL_E_USSD_MODIFIED_TO_USSD: return "E_USSD_MODIFIED_TO_USSD";
5406 case RIL_E_SS_MODIFIED_TO_DIAL: return "E_SS_MODIFIED_TO_DIAL";
5407 case RIL_E_SS_MODIFIED_TO_USSD: return "E_SS_MODIFIED_TO_USSD";
5408 case RIL_E_SUBSCRIPTION_NOT_SUPPORTED: return "E_SUBSCRIPTION_NOT_SUPPORTED";
5409 case RIL_E_SS_MODIFIED_TO_SS: return "E_SS_MODIFIED_TO_SS";
5410 case RIL_E_LCE_NOT_SUPPORTED: return "E_LCE_NOT_SUPPORTED";
5411 case RIL_E_NO_MEMORY: return "E_NO_MEMORY";
5412 case RIL_E_INTERNAL_ERR: return "E_INTERNAL_ERR";
5413 case RIL_E_SYSTEM_ERR: return "E_SYSTEM_ERR";
5414 case RIL_E_MODEM_ERR: return "E_MODEM_ERR";
5415 case RIL_E_INVALID_STATE: return "E_INVALID_STATE";
5416 case RIL_E_NO_RESOURCES: return "E_NO_RESOURCES";
5417 case RIL_E_SIM_ERR: return "E_SIM_ERR";
5418 case RIL_E_INVALID_ARGUMENTS: return "E_INVALID_ARGUMENTS";
5419 case RIL_E_INVALID_SIM_STATE: return "E_INVALID_SIM_STATE";
5420 case RIL_E_INVALID_MODEM_STATE: return "E_INVALID_MODEM_STATE";
5421 case RIL_E_INVALID_CALL_ID: return "E_INVALID_CALL_ID";
5422 case RIL_E_NO_SMS_TO_ACK: return "E_NO_SMS_TO_ACK";
5423 case RIL_E_NETWORK_ERR: return "E_NETWORK_ERR";
5424 case RIL_E_REQUEST_RATE_LIMITED: return "E_REQUEST_RATE_LIMITED";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005425 default: return "<unknown error>";
5426 }
5427}
5428
5429const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07005430radioStateToString(RIL_RadioState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005431 switch(s) {
5432 case RADIO_STATE_OFF: return "RADIO_OFF";
5433 case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
5434 case RADIO_STATE_SIM_NOT_READY: return "RADIO_SIM_NOT_READY";
5435 case RADIO_STATE_SIM_LOCKED_OR_ABSENT: return "RADIO_SIM_LOCKED_OR_ABSENT";
5436 case RADIO_STATE_SIM_READY: return "RADIO_SIM_READY";
Wink Savillef4c4d362009-04-02 01:37:03 -07005437 case RADIO_STATE_RUIM_NOT_READY:return"RADIO_RUIM_NOT_READY";
5438 case RADIO_STATE_RUIM_READY:return"RADIO_RUIM_READY";
5439 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:return"RADIO_RUIM_LOCKED_OR_ABSENT";
5440 case RADIO_STATE_NV_NOT_READY:return"RADIO_NV_NOT_READY";
5441 case RADIO_STATE_NV_READY:return"RADIO_NV_READY";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005442 case RADIO_STATE_ON:return"RADIO_ON";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005443 default: return "<unknown state>";
5444 }
5445}
5446
5447const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07005448callStateToString(RIL_CallState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005449 switch(s) {
5450 case RIL_CALL_ACTIVE : return "ACTIVE";
5451 case RIL_CALL_HOLDING: return "HOLDING";
5452 case RIL_CALL_DIALING: return "DIALING";
5453 case RIL_CALL_ALERTING: return "ALERTING";
5454 case RIL_CALL_INCOMING: return "INCOMING";
5455 case RIL_CALL_WAITING: return "WAITING";
5456 default: return "<unknown state>";
5457 }
5458}
5459
5460const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07005461requestToString(int request) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005462/*
5463 cat libs/telephony/ril_commands.h \
5464 | egrep "^ *{RIL_" \
5465 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
5466
5467
5468 cat libs/telephony/ril_unsol_commands.h \
5469 | egrep "^ *{RIL_" \
5470 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
5471
5472*/
5473 switch(request) {
5474 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
5475 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
5476 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
5477 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
5478 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
5479 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
5480 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
5481 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
5482 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
5483 case RIL_REQUEST_DIAL: return "DIAL";
5484 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
5485 case RIL_REQUEST_HANGUP: return "HANGUP";
5486 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
5487 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
5488 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
5489 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
5490 case RIL_REQUEST_UDUB: return "UDUB";
5491 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
5492 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
Wink Savillec0114b32011-02-18 10:14:07 -08005493 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
5494 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005495 case RIL_REQUEST_OPERATOR: return "OPERATOR";
5496 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
5497 case RIL_REQUEST_DTMF: return "DTMF";
5498 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
5499 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
Wink Savillef4c4d362009-04-02 01:37:03 -07005500 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005501 case RIL_REQUEST_SIM_IO: return "SIM_IO";
5502 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
5503 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
5504 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
5505 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
5506 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
5507 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
5508 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
5509 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
5510 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
5511 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
5512 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
5513 case RIL_REQUEST_ANSWER: return "ANSWER";
Wink Savillef4c4d362009-04-02 01:37:03 -07005514 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005515 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
5516 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
5517 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
5518 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
5519 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
5520 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
5521 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";
5522 case RIL_REQUEST_DTMF_START: return "DTMF_START";
5523 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
5524 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
5525 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
5526 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
5527 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
5528 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
5529 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
5530 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
5531 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
Wink Savillef4c4d362009-04-02 01:37:03 -07005532 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
5533 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005534 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
5535 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
5536 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
Wink Savillef4c4d362009-04-02 01:37:03 -07005537 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
5538 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005539 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
5540 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
5541 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
5542 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
5543 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
5544 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
5545 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
5546 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
Wink Savillec0114b32011-02-18 10:14:07 -08005547 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE:return"CDMA_SET_SUBSCRIPTION_SOURCE";
Wink Savillef4c4d362009-04-02 01:37:03 -07005548 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"CDMA_SET_ROAMING_PREFERENCE";
5549 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"CDMA_QUERY_ROAMING_PREFERENCE";
5550 case RIL_REQUEST_SET_TTY_MODE:return"SET_TTY_MODE";
5551 case RIL_REQUEST_QUERY_TTY_MODE:return"QUERY_TTY_MODE";
5552 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
5553 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
5554 case RIL_REQUEST_CDMA_FLASH:return"CDMA_FLASH";
5555 case RIL_REQUEST_CDMA_BURST_DTMF:return"CDMA_BURST_DTMF";
5556 case RIL_REQUEST_CDMA_SEND_SMS:return"CDMA_SEND_SMS";
5557 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:return"CDMA_SMS_ACKNOWLEDGE";
Wink Savillea592eeb2009-05-22 13:26:36 -07005558 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG:return"GSM_GET_BROADCAST_SMS_CONFIG";
5559 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG:return"GSM_SET_BROADCAST_SMS_CONFIG";
5560 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG:return "CDMA_GET_BROADCAST_SMS_CONFIG";
5561 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG:return "CDMA_SET_BROADCAST_SMS_CONFIG";
5562 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION:return "CDMA_SMS_BROADCAST_ACTIVATION";
Naveen Kalla03c1edf2009-09-23 11:18:35 -07005563 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return"CDMA_VALIDATE_AND_WRITE_AKEY";
Wink Savillef4c4d362009-04-02 01:37:03 -07005564 case RIL_REQUEST_CDMA_SUBSCRIPTION: return"CDMA_SUBSCRIPTION";
5565 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
5566 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
5567 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
jsh000a9fe2009-05-11 14:52:35 -07005568 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
5569 case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
5570 case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
jsh09a68ba2009-06-10 11:56:38 -07005571 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
jsh563fd722010-06-08 16:52:24 -07005572 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
Wink Savillec0114b32011-02-18 10:14:07 -08005573 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
Jake Hambyfa8d5842011-08-19 16:22:18 -07005574 case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
Jake Hamby300105d2011-09-26 01:01:44 -07005575 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
5576 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005577 case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
Ajay Nambic27945d2011-11-15 11:19:30 -08005578 case RIL_REQUEST_WRITE_SMS_TO_SIM: return "WRITE_SMS_TO_SIM";
Wink Saville8a9e0212013-04-09 12:11:38 -07005579 case RIL_REQUEST_GET_CELL_INFO_LIST: return"GET_CELL_INFO_LIST";
5580 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return"SET_UNSOL_CELL_INFO_LIST_RATE";
Sungmin Choi75697532013-04-26 15:04:45 -07005581 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "RIL_REQUEST_SET_INITIAL_ATTACH_APN";
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07005582 case RIL_REQUEST_IMS_REGISTRATION_STATE: return "IMS_REGISTRATION_STATE";
5583 case RIL_REQUEST_IMS_SEND_SMS: return "IMS_SEND_SMS";
Shishir Agrawal2458d8d2013-11-27 14:53:05 -08005584 case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "SIM_TRANSMIT_APDU_BASIC";
5585 case RIL_REQUEST_SIM_OPEN_CHANNEL: return "SIM_OPEN_CHANNEL";
5586 case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "SIM_CLOSE_CHANNEL";
5587 case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "SIM_TRANSMIT_APDU_CHANNEL";
Wink Saville8b4e4f72014-10-17 15:01:45 -07005588 case RIL_REQUEST_GET_RADIO_CAPABILITY: return "RIL_REQUEST_GET_RADIO_CAPABILITY";
5589 case RIL_REQUEST_SET_RADIO_CAPABILITY: return "RIL_REQUEST_SET_RADIO_CAPABILITY";
Etan Cohend3652192014-06-20 08:28:44 -07005590 case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "SET_UICC_SUBSCRIPTION";
5591 case RIL_REQUEST_ALLOW_DATA: return "ALLOW_DATA";
Amit Mahajan2b772032014-06-26 14:20:11 -07005592 case RIL_REQUEST_GET_HARDWARE_CONFIG: return "GET_HARDWARE_CONFIG";
5593 case RIL_REQUEST_SIM_AUTHENTICATION: return "SIM_AUTHENTICATION";
Wink Savillec29360a2014-07-13 05:17:28 -07005594 case RIL_REQUEST_GET_DC_RT_INFO: return "GET_DC_RT_INFO";
5595 case RIL_REQUEST_SET_DC_RT_INFO_RATE: return "SET_DC_RT_INFO_RATE";
Amit Mahajanc796e222014-08-13 16:54:01 +00005596 case RIL_REQUEST_SET_DATA_PROFILE: return "SET_DATA_PROFILE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005597 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
5598 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08005599 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 -08005600 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
5601 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
5602 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
5603 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
5604 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)";
5605 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
5606 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
Ajay Nambic27945d2011-11-15 11:19:30 -08005607 case RIL_UNSOL_SUPP_SVC_NOTIFICATION: return "UNSOL_SUPP_SVC_NOTIFICATION";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005608 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
5609 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
5610 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
5611 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
5612 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL";
5613 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
Wink Savillef4c4d362009-04-02 01:37:03 -07005614 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005615 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
Wink Savillef4c4d362009-04-02 01:37:03 -07005616 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
5617 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_NEW_CDMA_SMS";
5618 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_NEW_BROADCAST_SMS";
5619 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
Wink Saville3d54e742009-05-18 18:00:44 -07005620 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
5621 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
5622 case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
5623 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
5624 case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
Jaikumar Ganeshaf6ecbf2009-04-29 13:27:51 -07005625 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
John Wang5d621da2009-09-18 17:17:48 -07005626 case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
John Wang5909cf82010-01-29 00:18:54 -08005627 case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
Wink Savilleee274582011-04-16 15:05:49 -07005628 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08005629 case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
5630 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
Wink Saville5b9df332011-04-06 16:24:21 -07005631 case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005632 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
Wink Saville8a9e0212013-04-09 12:11:38 -07005633 case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07005634 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "RESPONSE_IMS_NETWORK_STATE_CHANGED";
Etan Cohend3652192014-06-20 08:28:44 -07005635 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return "UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED";
5636 case RIL_UNSOL_SRVCC_STATE_NOTIFY: return "UNSOL_SRVCC_STATE_NOTIFY";
5637 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return "HARDWARE_CONFIG_CHANGED";
Wink Savillec29360a2014-07-13 05:17:28 -07005638 case RIL_UNSOL_DC_RT_INFO_CHANGED: return "UNSOL_DC_RT_INFO_CHANGED";
Naveen Kallaa65a16a2014-07-31 16:48:31 -07005639 case RIL_REQUEST_SHUTDOWN: return "SHUTDOWN";
Wink Saville8b4e4f72014-10-17 15:01:45 -07005640 case RIL_UNSOL_RADIO_CAPABILITY: return "RIL_UNSOL_RADIO_CAPABILITY";
Sanket Padawe6ff9a872016-01-27 15:09:12 -08005641 case RIL_RESPONSE_ACKNOWLEDGEMENT: return "RIL_RESPONSE_ACKNOWLEDGEMENT";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005642 default: return "<unknown request>";
5643 }
5644}
5645
Etan Cohend3652192014-06-20 08:28:44 -07005646const char *
5647rilSocketIdToString(RIL_SOCKET_ID socket_id)
5648{
5649 switch(socket_id) {
5650 case RIL_SOCKET_1:
5651 return "RIL_SOCKET_1";
5652#if (SIM_COUNT >= 2)
5653 case RIL_SOCKET_2:
5654 return "RIL_SOCKET_2";
5655#endif
5656#if (SIM_COUNT >= 3)
5657 case RIL_SOCKET_3:
5658 return "RIL_SOCKET_3";
5659#endif
5660#if (SIM_COUNT >= 4)
5661 case RIL_SOCKET_4:
5662 return "RIL_SOCKET_4";
5663#endif
5664 default:
5665 return "not a valid RIL";
5666 }
5667}
5668
Sanket Padawe88cf6a52016-01-11 12:45:43 -08005669/*
5670 * Returns true for a debuggable build.
5671 */
5672static bool isDebuggable() {
5673 char debuggable[PROP_VALUE_MAX];
5674 property_get("ro.debuggable", debuggable, "0");
5675 if (strcmp(debuggable, "1") == 0) {
5676 return true;
5677 }
5678 return false;
5679}
5680
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005681} /* namespace android */
Dheeraj Shetty27976c42014-07-02 21:27:57 +02005682
5683void rilEventAddWakeup_helper(struct ril_event *ev) {
5684 android::rilEventAddWakeup(ev);
5685}
5686
5687void listenCallback_helper(int fd, short flags, void *param) {
5688 android::listenCallback(fd, flags, param);
5689}
5690
5691int blockingWrite_helper(int fd, void *buffer, size_t len) {
5692 return android::blockingWrite(fd, buffer, len);
5693}