blob: dce489d05d315acc5556f497a9e6f414b4582c9e [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 Padawe4c05f352016-01-26 16:19:00 -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);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080054namespace android {
55
56#define PHONE_PROCESS "radio"
Dheeraj Shetty27976c42014-07-02 21:27:57 +020057#define BLUETOOTH_PROCESS "bluetooth"
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080058
59#define SOCKET_NAME_RIL "rild"
Etan Cohend3652192014-06-20 08:28:44 -070060#define SOCKET2_NAME_RIL "rild2"
61#define SOCKET3_NAME_RIL "rild3"
62#define SOCKET4_NAME_RIL "rild4"
63
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080064#define SOCKET_NAME_RIL_DEBUG "rild-debug"
65
66#define ANDROID_WAKE_LOCK_NAME "radio-interface"
67
Nathan Harolda0153392015-07-28 14:54:58 -070068#define ANDROID_WAKE_LOCK_SECS 0
69#define ANDROID_WAKE_LOCK_USECS 200000
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080070
71#define PROPERTY_RIL_IMPL "gsm.version.ril-impl"
72
73// match with constant in RIL.java
74#define MAX_COMMAND_BYTES (8 * 1024)
75
76// Basically: memset buffers that the client library
77// shouldn't be using anymore in an attempt to find
78// memory usage issues sooner.
79#define MEMSET_FREED 1
80
81#define NUM_ELEMS(a) (sizeof (a) / sizeof (a)[0])
82
Wink Savillef4c4d362009-04-02 01:37:03 -070083#define MIN(a,b) ((a)<(b) ? (a) : (b))
84
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080085/* Constants for response types */
86#define RESPONSE_SOLICITED 0
87#define RESPONSE_UNSOLICITED 1
88
89/* Negative values for private RIL errno's */
90#define RIL_ERRNO_INVALID_RESPONSE -1
91
92// request, response, and unsolicited msg print macro
93#define PRINTBUF_SIZE 8096
94
Robert Greenwalt191e4dc2015-04-29 16:57:39 -070095// Enable verbose logging
96#define VDBG 0
97
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080098// Enable RILC log
99#define RILC_LOG 0
100
101#if RILC_LOG
102 #define startRequest sprintf(printBuf, "(")
103 #define closeRequest sprintf(printBuf, "%s)", printBuf)
104 #define printRequest(token, req) \
Wink Saville8eb2a122012-11-19 16:05:13 -0800105 RLOGD("[%04d]> %s %s", token, requestToString(req), printBuf)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800106
107 #define startResponse sprintf(printBuf, "%s {", printBuf)
108 #define closeResponse sprintf(printBuf, "%s}", printBuf)
Wink Saville8eb2a122012-11-19 16:05:13 -0800109 #define printResponse RLOGD("%s", printBuf)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800110
111 #define clearPrintBuf printBuf[0] = 0
112 #define removeLastChar printBuf[strlen(printBuf)-1] = 0
Ajay Nambifa49a7f2015-08-05 14:53:50 +0530113 #define appendPrintBuf(x...) snprintf(printBuf, PRINTBUF_SIZE, x)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800114#else
115 #define startRequest
116 #define closeRequest
117 #define printRequest(token, req)
118 #define startResponse
119 #define closeResponse
120 #define printResponse
121 #define clearPrintBuf
122 #define removeLastChar
123 #define appendPrintBuf(x...)
124#endif
125
126enum WakeType {DONT_WAKE, WAKE_PARTIAL};
127
128typedef struct {
129 int requestNumber;
130 void (*dispatchFunction) (Parcel &p, struct RequestInfo *pRI);
131 int(*responseFunction) (Parcel &p, void *response, size_t responselen);
132} CommandInfo;
133
134typedef struct {
135 int requestNumber;
136 int (*responseFunction) (Parcel &p, void *response, size_t responselen);
137 WakeType wakeType;
138} UnsolResponseInfo;
139
140typedef struct RequestInfo {
Wink Saville7f856802009-06-09 10:23:37 -0700141 int32_t token; //this is not RIL_Token
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800142 CommandInfo *pCI;
143 struct RequestInfo *p_next;
144 char cancelled;
145 char local; // responses to local commands do not go back to command process
Etan Cohend3652192014-06-20 08:28:44 -0700146 RIL_SOCKET_ID socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800147} RequestInfo;
148
Wink Saville3d54e742009-05-18 18:00:44 -0700149typedef struct UserCallbackInfo {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800150 RIL_TimedCallback p_callback;
151 void *userParam;
152 struct ril_event event;
153 struct UserCallbackInfo *p_next;
154} UserCallbackInfo;
155
Etan Cohend3652192014-06-20 08:28:44 -0700156extern "C" const char * requestToString(int request);
157extern "C" const char * failCauseToString(RIL_Errno);
158extern "C" const char * callStateToString(RIL_CallState);
159extern "C" const char * radioStateToString(RIL_RadioState);
160extern "C" const char * rilSocketIdToString(RIL_SOCKET_ID socket_id);
161
162extern "C"
163char rild[MAX_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800164/*******************************************************************/
165
166RIL_RadioFunctions s_callbacks = {0, NULL, NULL, NULL, NULL, NULL};
167static int s_registerCalled = 0;
168
169static pthread_t s_tid_dispatch;
170static pthread_t s_tid_reader;
171static int s_started = 0;
172
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800173static int s_fdDebug = -1;
Etan Cohend3652192014-06-20 08:28:44 -0700174static int s_fdDebug_socket2 = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800175
176static int s_fdWakeupRead;
177static int s_fdWakeupWrite;
178
179static struct ril_event s_commands_event;
180static struct ril_event s_wakeupfd_event;
181static struct ril_event s_listen_event;
Etan Cohend3652192014-06-20 08:28:44 -0700182static SocketListenParam s_ril_param_socket;
183
184static pthread_mutex_t s_pendingRequestsMutex = PTHREAD_MUTEX_INITIALIZER;
185static pthread_mutex_t s_writeMutex = PTHREAD_MUTEX_INITIALIZER;
186static RequestInfo *s_pendingRequests = NULL;
187
188#if (SIM_COUNT >= 2)
189static struct ril_event s_commands_event_socket2;
190static struct ril_event s_listen_event_socket2;
191static SocketListenParam s_ril_param_socket2;
192
193static pthread_mutex_t s_pendingRequestsMutex_socket2 = PTHREAD_MUTEX_INITIALIZER;
194static pthread_mutex_t s_writeMutex_socket2 = PTHREAD_MUTEX_INITIALIZER;
195static RequestInfo *s_pendingRequests_socket2 = NULL;
196#endif
197
198#if (SIM_COUNT >= 3)
199static struct ril_event s_commands_event_socket3;
200static struct ril_event s_listen_event_socket3;
201static SocketListenParam s_ril_param_socket3;
202
203static pthread_mutex_t s_pendingRequestsMutex_socket3 = PTHREAD_MUTEX_INITIALIZER;
204static pthread_mutex_t s_writeMutex_socket3 = PTHREAD_MUTEX_INITIALIZER;
205static RequestInfo *s_pendingRequests_socket3 = NULL;
206#endif
207
208#if (SIM_COUNT >= 4)
209static struct ril_event s_commands_event_socket4;
210static struct ril_event s_listen_event_socket4;
211static SocketListenParam s_ril_param_socket4;
212
213static pthread_mutex_t s_pendingRequestsMutex_socket4 = PTHREAD_MUTEX_INITIALIZER;
214static pthread_mutex_t s_writeMutex_socket4 = PTHREAD_MUTEX_INITIALIZER;
215static RequestInfo *s_pendingRequests_socket4 = NULL;
216#endif
217
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800218static struct ril_event s_wake_timeout_event;
219static struct ril_event s_debug_event;
220
221
Nathan Harolda0153392015-07-28 14:54:58 -0700222static const struct timeval TIMEVAL_WAKE_TIMEOUT = {ANDROID_WAKE_LOCK_SECS,ANDROID_WAKE_LOCK_USECS};
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800223
Etan Cohend3652192014-06-20 08:28:44 -0700224
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800225static pthread_mutex_t s_startupMutex = PTHREAD_MUTEX_INITIALIZER;
226static pthread_cond_t s_startupCond = PTHREAD_COND_INITIALIZER;
227
228static pthread_mutex_t s_dispatchMutex = PTHREAD_MUTEX_INITIALIZER;
229static pthread_cond_t s_dispatchCond = PTHREAD_COND_INITIALIZER;
230
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800231static RequestInfo *s_toDispatchHead = NULL;
232static RequestInfo *s_toDispatchTail = NULL;
233
234static UserCallbackInfo *s_last_wake_timeout_info = NULL;
235
236static void *s_lastNITZTimeData = NULL;
237static size_t s_lastNITZTimeDataSize;
238
239#if RILC_LOG
240 static char printBuf[PRINTBUF_SIZE];
241#endif
242
243/*******************************************************************/
Etan Cohend3652192014-06-20 08:28:44 -0700244static int sendResponse (Parcel &p, RIL_SOCKET_ID socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800245
246static void dispatchVoid (Parcel& p, RequestInfo *pRI);
247static void dispatchString (Parcel& p, RequestInfo *pRI);
248static void dispatchStrings (Parcel& p, RequestInfo *pRI);
249static void dispatchInts (Parcel& p, RequestInfo *pRI);
250static void dispatchDial (Parcel& p, RequestInfo *pRI);
251static void dispatchSIM_IO (Parcel& p, RequestInfo *pRI);
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800252static void dispatchSIM_APDU (Parcel& p, RequestInfo *pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800253static void dispatchCallForward(Parcel& p, RequestInfo *pRI);
254static void dispatchRaw(Parcel& p, RequestInfo *pRI);
255static void dispatchSmsWrite (Parcel &p, RequestInfo *pRI);
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -0700256static void dispatchDataCall (Parcel& p, RequestInfo *pRI);
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800257static void dispatchVoiceRadioTech (Parcel& p, RequestInfo *pRI);
Sungmin Choi75697532013-04-26 15:04:45 -0700258static void dispatchSetInitialAttachApn (Parcel& p, RequestInfo *pRI);
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800259static void dispatchCdmaSubscriptionSource (Parcel& p, RequestInfo *pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800260
Wink Savillef4c4d362009-04-02 01:37:03 -0700261static void dispatchCdmaSms(Parcel &p, RequestInfo *pRI);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -0700262static void dispatchImsSms(Parcel &p, RequestInfo *pRI);
263static void dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
264static void dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
Wink Savillef4c4d362009-04-02 01:37:03 -0700265static void dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI);
Wink Savillea592eeb2009-05-22 13:26:36 -0700266static void dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI);
Wink Savillef4c4d362009-04-02 01:37:03 -0700267static void dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI);
268static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI);
Jake Hamby8a4a2332014-01-15 13:12:05 -0800269static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI);
270static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI);
Etan Cohend3652192014-06-20 08:28:44 -0700271static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI);
Amit Mahajan90530a62014-07-01 15:54:08 -0700272static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI);
Amit Mahajanc796e222014-08-13 16:54:01 +0000273static void dispatchDataProfile(Parcel &p, RequestInfo *pRI);
Wink Saville8b4e4f72014-10-17 15:01:45 -0700274static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800275static int responseInts(Parcel &p, void *response, size_t responselen);
Chao Liu548a81e2015-05-14 16:13:46 -0700276static int responseFailCause(Parcel &p, void *response, size_t responselen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800277static int responseStrings(Parcel &p, void *response, size_t responselen);
278static int responseString(Parcel &p, void *response, size_t responselen);
279static int responseVoid(Parcel &p, void *response, size_t responselen);
280static int responseCallList(Parcel &p, void *response, size_t responselen);
281static int responseSMS(Parcel &p, void *response, size_t responselen);
282static int responseSIM_IO(Parcel &p, void *response, size_t responselen);
283static int responseCallForwards(Parcel &p, void *response, size_t responselen);
Wink Savillef4c4d362009-04-02 01:37:03 -0700284static int responseDataCallList(Parcel &p, void *response, size_t responselen);
Wink Saville43808972011-01-13 17:39:51 -0800285static int responseSetupDataCall(Parcel &p, void *response, size_t responselen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800286static int responseRaw(Parcel &p, void *response, size_t responselen);
287static int responseSsn(Parcel &p, void *response, size_t responselen);
Wink Savillef4c4d362009-04-02 01:37:03 -0700288static int responseSimStatus(Parcel &p, void *response, size_t responselen);
Wink Savillea592eeb2009-05-22 13:26:36 -0700289static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen);
290static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen);
Wink Savillef4c4d362009-04-02 01:37:03 -0700291static int responseCdmaSms(Parcel &p, void *response, size_t responselen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800292static int responseCellList(Parcel &p, void *response, size_t responselen);
Wink Saville3d54e742009-05-18 18:00:44 -0700293static int responseCdmaInformationRecords(Parcel &p,void *response, size_t responselen);
294static int responseRilSignalStrength(Parcel &p,void *response, size_t responselen);
295static int responseCallRing(Parcel &p, void *response, size_t responselen);
296static int responseCdmaSignalInfoRecord(Parcel &p,void *response, size_t responselen);
297static int responseCdmaCallWaiting(Parcel &p,void *response, size_t responselen);
Alex Yakavenka45e740e2012-01-31 11:48:27 -0800298static int responseSimRefresh(Parcel &p, void *response, size_t responselen);
Wink Saville8a9e0212013-04-09 12:11:38 -0700299static int responseCellInfoList(Parcel &p, void *response, size_t responselen);
Etan Cohend3652192014-06-20 08:28:44 -0700300static int responseHardwareConfig(Parcel &p, void *response, size_t responselen);
Wink Savillec29360a2014-07-13 05:17:28 -0700301static int responseDcRtInfo(Parcel &p, void *response, size_t responselen);
Wink Saville8b4e4f72014-10-17 15:01:45 -0700302static int responseRadioCapability(Parcel &p, void *response, size_t responselen);
Amit Mahajan54563d32014-11-22 00:54:49 +0000303static int responseSSData(Parcel &p, void *response, size_t responselen);
fengluf7408292015-04-14 14:53:55 -0700304static int responseLceStatus(Parcel &p, void *response, size_t responselen);
305static int responseLceData(Parcel &p, void *response, size_t responselen);
Prerepa Viswanadham73157492015-05-28 00:37:32 -0700306static int responseActivityData(Parcel &p, void *response, size_t responselen);
Amit Mahajan54563d32014-11-22 00:54:49 +0000307
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800308static int decodeVoiceRadioTechnology (RIL_RadioState radioState);
309static int decodeCdmaSubscriptionSource (RIL_RadioState radioState);
310static RIL_RadioState processRadioState(RIL_RadioState newRadioState);
311
Amit Mahajan54563d32014-11-22 00:54:49 +0000312static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType);
313
Sanket Padawe4c05f352016-01-26 16:19:00 -0800314static bool isDebuggable();
315
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800316#ifdef RIL_SHLIB
Etan Cohend3652192014-06-20 08:28:44 -0700317#if defined(ANDROID_MULTI_SIM)
Vinit Deshpande1b1ec2d2015-04-15 13:31:05 -0700318extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Etan Cohend3652192014-06-20 08:28:44 -0700319 size_t datalen, RIL_SOCKET_ID socket_id);
320#else
Vinit Deshpande1b1ec2d2015-04-15 13:31:05 -0700321extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800322 size_t datalen);
323#endif
Etan Cohend3652192014-06-20 08:28:44 -0700324#endif
325
326#if defined(ANDROID_MULTI_SIM)
327#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c), (d))
328#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d), (e))
329#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest(a)
330#else
331#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c))
332#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d))
333#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest()
334#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800335
Wink Saville7f856802009-06-09 10:23:37 -0700336static UserCallbackInfo * internalRequestTimedCallback
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -0700337 (RIL_TimedCallback callback, void *param,
338 const struct timeval *relativeTime);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800339
340/** Index == requestNumber */
341static CommandInfo s_commands[] = {
342#include "ril_commands.h"
343};
344
345static UnsolResponseInfo s_unsolResponses[] = {
346#include "ril_unsol_commands.h"
347};
348
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800349/* For older RILs that do not support new commands RIL_REQUEST_VOICE_RADIO_TECH and
350 RIL_UNSOL_VOICE_RADIO_TECH_CHANGED messages, decode the voice radio tech from
351 radio state message and store it. Every time there is a change in Radio State
352 check to see if voice radio tech changes and notify telephony
353 */
354int voiceRadioTech = -1;
355
356/* For older RILs that do not support new commands RIL_REQUEST_GET_CDMA_SUBSCRIPTION_SOURCE
357 and RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED messages, decode the subscription
358 source from radio state and store it. Every time there is a change in Radio State
359 check to see if subscription source changed and notify telephony
360 */
361int cdmaSubscriptionSource = -1;
362
363/* For older RILs that do not send RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, decode the
364 SIM/RUIM state from radio state and store it. Every time there is a change in Radio State,
365 check to see if SIM/RUIM status changed and notify telephony
366 */
367int simRuimStatus = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800368
Etan Cohend3652192014-06-20 08:28:44 -0700369static char * RIL_getRilSocketName() {
370 return rild;
371}
372
373extern "C"
Dheeraj Shetty27976c42014-07-02 21:27:57 +0200374void RIL_setRilSocketName(const char * s) {
Etan Cohend3652192014-06-20 08:28:44 -0700375 strncpy(rild, s, MAX_SOCKET_NAME_LENGTH);
376}
377
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800378static char *
Wink Savillef4c4d362009-04-02 01:37:03 -0700379strdupReadString(Parcel &p) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800380 size_t stringlen;
381 const char16_t *s16;
Wink Saville7f856802009-06-09 10:23:37 -0700382
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800383 s16 = p.readString16Inplace(&stringlen);
Wink Saville7f856802009-06-09 10:23:37 -0700384
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800385 return strndup16to8(s16, stringlen);
386}
387
Wink Saville8b4e4f72014-10-17 15:01:45 -0700388static status_t
389readStringFromParcelInplace(Parcel &p, char *str, size_t maxLen) {
390 size_t s16Len;
391 const char16_t *s16;
392
393 s16 = p.readString16Inplace(&s16Len);
394 if (s16 == NULL) {
395 return NO_MEMORY;
396 }
397 size_t strLen = strnlen16to8(s16, s16Len);
398 if ((strLen + 1) > maxLen) {
399 return NO_MEMORY;
400 }
401 if (strncpy16to8(str, s16, strLen) == NULL) {
402 return NO_MEMORY;
403 } else {
404 return NO_ERROR;
405 }
406}
407
Wink Savillef4c4d362009-04-02 01:37:03 -0700408static void writeStringToParcel(Parcel &p, const char *s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800409 char16_t *s16;
410 size_t s16_len;
411 s16 = strdup8to16(s, &s16_len);
412 p.writeString16(s16, s16_len);
413 free(s16);
414}
415
416
417static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700418memsetString (char *s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800419 if (s != NULL) {
420 memset (s, 0, strlen(s));
421 }
422}
423
424void nullParcelReleaseFunction (const uint8_t* data, size_t dataSize,
425 const size_t* objects, size_t objectsSize,
Wink Savillef4c4d362009-04-02 01:37:03 -0700426 void* cookie) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800427 // do nothing -- the data reference lives longer than the Parcel object
428}
429
Wink Saville7f856802009-06-09 10:23:37 -0700430/**
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800431 * To be called from dispatch thread
432 * Issue a single local request, ensuring that the response
Wink Saville7f856802009-06-09 10:23:37 -0700433 * is not sent back up to the command process
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800434 */
435static void
Etan Cohend3652192014-06-20 08:28:44 -0700436issueLocalRequest(int request, void *data, int len, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800437 RequestInfo *pRI;
438 int ret;
Etan Cohend3652192014-06-20 08:28:44 -0700439 /* Hook for current context */
440 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
441 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
442 /* pendingRequestsHook refer to &s_pendingRequests */
443 RequestInfo** pendingRequestsHook = &s_pendingRequests;
444
445#if (SIM_COUNT == 2)
446 if (socket_id == RIL_SOCKET_2) {
447 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
448 pendingRequestsHook = &s_pendingRequests_socket2;
449 }
450#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800451
452 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
453
454 pRI->local = 1;
455 pRI->token = 0xffffffff; // token is not used in this context
456 pRI->pCI = &(s_commands[request]);
Etan Cohend3652192014-06-20 08:28:44 -0700457 pRI->socket_id = socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800458
Etan Cohend3652192014-06-20 08:28:44 -0700459 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800460 assert (ret == 0);
461
Etan Cohend3652192014-06-20 08:28:44 -0700462 pRI->p_next = *pendingRequestsHook;
463 *pendingRequestsHook = pRI;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800464
Etan Cohend3652192014-06-20 08:28:44 -0700465 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800466 assert (ret == 0);
467
Wink Saville8eb2a122012-11-19 16:05:13 -0800468 RLOGD("C[locl]> %s", requestToString(request));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800469
Etan Cohend3652192014-06-20 08:28:44 -0700470 CALL_ONREQUEST(request, data, len, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800471}
472
473
474
475static int
Etan Cohend3652192014-06-20 08:28:44 -0700476processCommandBuffer(void *buffer, size_t buflen, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800477 Parcel p;
478 status_t status;
479 int32_t request;
480 int32_t token;
481 RequestInfo *pRI;
482 int ret;
Etan Cohend3652192014-06-20 08:28:44 -0700483 /* Hook for current context */
484 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
485 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
486 /* pendingRequestsHook refer to &s_pendingRequests */
487 RequestInfo** pendingRequestsHook = &s_pendingRequests;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800488
489 p.setData((uint8_t *) buffer, buflen);
490
491 // status checked at end
492 status = p.readInt32(&request);
493 status = p.readInt32 (&token);
494
Etan Cohend3652192014-06-20 08:28:44 -0700495#if (SIM_COUNT >= 2)
496 if (socket_id == RIL_SOCKET_2) {
497 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
498 pendingRequestsHook = &s_pendingRequests_socket2;
499 }
500#if (SIM_COUNT >= 3)
501 else if (socket_id == RIL_SOCKET_3) {
502 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
503 pendingRequestsHook = &s_pendingRequests_socket3;
504 }
505#endif
506#if (SIM_COUNT >= 4)
507 else if (socket_id == RIL_SOCKET_4) {
508 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
509 pendingRequestsHook = &s_pendingRequests_socket4;
510 }
511#endif
512#endif
513
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800514 if (status != NO_ERROR) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800515 RLOGE("invalid request block");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800516 return 0;
517 }
518
519 if (request < 1 || request >= (int32_t)NUM_ELEMS(s_commands)) {
Etan Cohend3652192014-06-20 08:28:44 -0700520 Parcel pErr;
Wink Saville8eb2a122012-11-19 16:05:13 -0800521 RLOGE("unsupported request code %d token %d", request, token);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800522 // FIXME this should perhaps return a response
Etan Cohend3652192014-06-20 08:28:44 -0700523 pErr.writeInt32 (RESPONSE_SOLICITED);
524 pErr.writeInt32 (token);
525 pErr.writeInt32 (RIL_E_GENERIC_FAILURE);
526
527 sendResponse(pErr, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800528 return 0;
529 }
530
531
532 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
533
534 pRI->token = token;
535 pRI->pCI = &(s_commands[request]);
Etan Cohend3652192014-06-20 08:28:44 -0700536 pRI->socket_id = socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800537
Etan Cohend3652192014-06-20 08:28:44 -0700538 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800539 assert (ret == 0);
540
Etan Cohend3652192014-06-20 08:28:44 -0700541 pRI->p_next = *pendingRequestsHook;
542 *pendingRequestsHook = pRI;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800543
Etan Cohend3652192014-06-20 08:28:44 -0700544 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800545 assert (ret == 0);
546
547/* sLastDispatchedToken = token; */
548
Wink Saville7f856802009-06-09 10:23:37 -0700549 pRI->pCI->dispatchFunction(p, pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800550
551 return 0;
552}
553
554static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700555invalidCommandBlock (RequestInfo *pRI) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800556 RLOGE("invalid command block for token %d request %s",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800557 pRI->token, requestToString(pRI->pCI->requestNumber));
558}
559
560/** Callee expects NULL */
Wink Saville7f856802009-06-09 10:23:37 -0700561static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700562dispatchVoid (Parcel& p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800563 clearPrintBuf;
564 printRequest(pRI->token, pRI->pCI->requestNumber);
Etan Cohend3652192014-06-20 08:28:44 -0700565 CALL_ONREQUEST(pRI->pCI->requestNumber, NULL, 0, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800566}
567
568/** Callee expects const char * */
569static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700570dispatchString (Parcel& p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800571 status_t status;
572 size_t datalen;
573 size_t stringlen;
574 char *string8 = NULL;
575
576 string8 = strdupReadString(p);
577
578 startRequest;
579 appendPrintBuf("%s%s", printBuf, string8);
580 closeRequest;
581 printRequest(pRI->token, pRI->pCI->requestNumber);
582
Etan Cohend3652192014-06-20 08:28:44 -0700583 CALL_ONREQUEST(pRI->pCI->requestNumber, string8,
584 sizeof(char *), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800585
586#ifdef MEMSET_FREED
587 memsetString(string8);
588#endif
589
590 free(string8);
591 return;
592invalid:
593 invalidCommandBlock(pRI);
594 return;
595}
596
597/** Callee expects const char ** */
598static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700599dispatchStrings (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800600 int32_t countStrings;
601 status_t status;
602 size_t datalen;
603 char **pStrings;
604
605 status = p.readInt32 (&countStrings);
606
607 if (status != NO_ERROR) {
608 goto invalid;
609 }
610
611 startRequest;
612 if (countStrings == 0) {
613 // just some non-null pointer
614 pStrings = (char **)alloca(sizeof(char *));
615 datalen = 0;
616 } else if (((int)countStrings) == -1) {
617 pStrings = NULL;
618 datalen = 0;
619 } else {
620 datalen = sizeof(char *) * countStrings;
Wink Saville7f856802009-06-09 10:23:37 -0700621
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800622 pStrings = (char **)alloca(datalen);
623
624 for (int i = 0 ; i < countStrings ; i++) {
625 pStrings[i] = strdupReadString(p);
626 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
627 }
628 }
629 removeLastChar;
630 closeRequest;
631 printRequest(pRI->token, pRI->pCI->requestNumber);
632
Etan Cohend3652192014-06-20 08:28:44 -0700633 CALL_ONREQUEST(pRI->pCI->requestNumber, pStrings, datalen, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800634
635 if (pStrings != NULL) {
636 for (int i = 0 ; i < countStrings ; i++) {
637#ifdef MEMSET_FREED
638 memsetString (pStrings[i]);
639#endif
640 free(pStrings[i]);
641 }
642
643#ifdef MEMSET_FREED
644 memset(pStrings, 0, datalen);
645#endif
646 }
Wink Saville7f856802009-06-09 10:23:37 -0700647
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800648 return;
649invalid:
650 invalidCommandBlock(pRI);
651 return;
652}
653
654/** Callee expects const int * */
655static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700656dispatchInts (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800657 int32_t count;
658 status_t status;
659 size_t datalen;
660 int *pInts;
661
662 status = p.readInt32 (&count);
663
664 if (status != NO_ERROR || count == 0) {
665 goto invalid;
666 }
667
668 datalen = sizeof(int) * count;
669 pInts = (int *)alloca(datalen);
670
671 startRequest;
672 for (int i = 0 ; i < count ; i++) {
673 int32_t t;
674
675 status = p.readInt32(&t);
676 pInts[i] = (int)t;
677 appendPrintBuf("%s%d,", printBuf, t);
678
679 if (status != NO_ERROR) {
680 goto invalid;
681 }
682 }
683 removeLastChar;
684 closeRequest;
685 printRequest(pRI->token, pRI->pCI->requestNumber);
686
Etan Cohend3652192014-06-20 08:28:44 -0700687 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<int *>(pInts),
688 datalen, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800689
690#ifdef MEMSET_FREED
691 memset(pInts, 0, datalen);
692#endif
693
694 return;
695invalid:
696 invalidCommandBlock(pRI);
697 return;
698}
699
700
Wink Saville7f856802009-06-09 10:23:37 -0700701/**
702 * Callee expects const RIL_SMS_WriteArgs *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800703 * Payload is:
704 * int32_t status
705 * String pdu
706 */
707static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700708dispatchSmsWrite (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800709 RIL_SMS_WriteArgs args;
710 int32_t t;
711 status_t status;
712
Mark Salyzyndba25612015-04-09 07:18:35 -0700713 RLOGD("dispatchSmsWrite");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800714 memset (&args, 0, sizeof(args));
715
716 status = p.readInt32(&t);
717 args.status = (int)t;
718
719 args.pdu = strdupReadString(p);
720
721 if (status != NO_ERROR || args.pdu == NULL) {
722 goto invalid;
723 }
724
725 args.smsc = strdupReadString(p);
726
727 startRequest;
728 appendPrintBuf("%s%d,%s,smsc=%s", printBuf, args.status,
729 (char*)args.pdu, (char*)args.smsc);
730 closeRequest;
731 printRequest(pRI->token, pRI->pCI->requestNumber);
Wink Saville7f856802009-06-09 10:23:37 -0700732
Etan Cohend3652192014-06-20 08:28:44 -0700733 CALL_ONREQUEST(pRI->pCI->requestNumber, &args, sizeof(args), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800734
735#ifdef MEMSET_FREED
736 memsetString (args.pdu);
737#endif
738
739 free (args.pdu);
Wink Saville7f856802009-06-09 10:23:37 -0700740
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800741#ifdef MEMSET_FREED
742 memset(&args, 0, sizeof(args));
743#endif
744
745 return;
746invalid:
747 invalidCommandBlock(pRI);
748 return;
749}
750
Wink Saville7f856802009-06-09 10:23:37 -0700751/**
752 * Callee expects const RIL_Dial *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800753 * Payload is:
754 * String address
755 * int32_t clir
756 */
757static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700758dispatchDial (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800759 RIL_Dial dial;
Wink Saville74fa3882009-12-22 15:35:41 -0800760 RIL_UUS_Info uusInfo;
Wink Saville7bce0822010-01-08 15:20:12 -0800761 int32_t sizeOfDial;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800762 int32_t t;
Wink Saville74fa3882009-12-22 15:35:41 -0800763 int32_t uusPresent;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800764 status_t status;
765
Mark Salyzyndba25612015-04-09 07:18:35 -0700766 RLOGD("dispatchDial");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800767 memset (&dial, 0, sizeof(dial));
768
769 dial.address = strdupReadString(p);
770
771 status = p.readInt32(&t);
772 dial.clir = (int)t;
773
774 if (status != NO_ERROR || dial.address == NULL) {
775 goto invalid;
776 }
777
Wink Saville3a4840b2010-04-07 13:29:58 -0700778 if (s_callbacks.version < 3) { // Remove when partners upgrade to version 3
Wink Saville74fa3882009-12-22 15:35:41 -0800779 uusPresent = 0;
Wink Saville7bce0822010-01-08 15:20:12 -0800780 sizeOfDial = sizeof(dial) - sizeof(RIL_UUS_Info *);
Wink Saville74fa3882009-12-22 15:35:41 -0800781 } else {
782 status = p.readInt32(&uusPresent);
783
784 if (status != NO_ERROR) {
785 goto invalid;
786 }
787
788 if (uusPresent == 0) {
789 dial.uusInfo = NULL;
790 } else {
791 int32_t len;
792
793 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
794
795 status = p.readInt32(&t);
796 uusInfo.uusType = (RIL_UUS_Type) t;
797
798 status = p.readInt32(&t);
799 uusInfo.uusDcs = (RIL_UUS_DCS) t;
800
801 status = p.readInt32(&len);
802 if (status != NO_ERROR) {
803 goto invalid;
804 }
805
806 // The java code writes -1 for null arrays
807 if (((int) len) == -1) {
808 uusInfo.uusData = NULL;
809 len = 0;
810 } else {
811 uusInfo.uusData = (char*) p.readInplace(len);
812 }
813
814 uusInfo.uusLength = len;
815 dial.uusInfo = &uusInfo;
816 }
Wink Saville7bce0822010-01-08 15:20:12 -0800817 sizeOfDial = sizeof(dial);
Wink Saville74fa3882009-12-22 15:35:41 -0800818 }
819
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800820 startRequest;
821 appendPrintBuf("%snum=%s,clir=%d", printBuf, dial.address, dial.clir);
Wink Saville74fa3882009-12-22 15:35:41 -0800822 if (uusPresent) {
823 appendPrintBuf("%s,uusType=%d,uusDcs=%d,uusLen=%d", printBuf,
824 dial.uusInfo->uusType, dial.uusInfo->uusDcs,
825 dial.uusInfo->uusLength);
826 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800827 closeRequest;
828 printRequest(pRI->token, pRI->pCI->requestNumber);
829
Etan Cohend3652192014-06-20 08:28:44 -0700830 CALL_ONREQUEST(pRI->pCI->requestNumber, &dial, sizeOfDial, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800831
832#ifdef MEMSET_FREED
833 memsetString (dial.address);
834#endif
835
836 free (dial.address);
Wink Saville7f856802009-06-09 10:23:37 -0700837
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800838#ifdef MEMSET_FREED
Wink Saville74fa3882009-12-22 15:35:41 -0800839 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800840 memset(&dial, 0, sizeof(dial));
841#endif
842
843 return;
844invalid:
845 invalidCommandBlock(pRI);
846 return;
847}
848
Wink Saville7f856802009-06-09 10:23:37 -0700849/**
850 * Callee expects const RIL_SIM_IO *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800851 * Payload is:
852 * int32_t command
853 * int32_t fileid
854 * String path
855 * int32_t p1, p2, p3
Wink Saville7f856802009-06-09 10:23:37 -0700856 * String data
857 * String pin2
Wink Savillec0114b32011-02-18 10:14:07 -0800858 * String aidPtr
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800859 */
860static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700861dispatchSIM_IO (Parcel &p, RequestInfo *pRI) {
Wink Savillec0114b32011-02-18 10:14:07 -0800862 union RIL_SIM_IO {
863 RIL_SIM_IO_v6 v6;
864 RIL_SIM_IO_v5 v5;
865 } simIO;
866
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800867 int32_t t;
Wink Savillec0114b32011-02-18 10:14:07 -0800868 int size;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800869 status_t status;
870
Robert Greenwalt191e4dc2015-04-29 16:57:39 -0700871#if VDBG
Mark Salyzyndba25612015-04-09 07:18:35 -0700872 RLOGD("dispatchSIM_IO");
Robert Greenwalt191e4dc2015-04-29 16:57:39 -0700873#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800874 memset (&simIO, 0, sizeof(simIO));
875
Wink Saville7f856802009-06-09 10:23:37 -0700876 // note we only check status at the end
877
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800878 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800879 simIO.v6.command = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800880
881 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800882 simIO.v6.fileid = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800883
Wink Savillec0114b32011-02-18 10:14:07 -0800884 simIO.v6.path = strdupReadString(p);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800885
886 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800887 simIO.v6.p1 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800888
889 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800890 simIO.v6.p2 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800891
892 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800893 simIO.v6.p3 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800894
Wink Savillec0114b32011-02-18 10:14:07 -0800895 simIO.v6.data = strdupReadString(p);
896 simIO.v6.pin2 = strdupReadString(p);
897 simIO.v6.aidPtr = strdupReadString(p);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800898
899 startRequest;
Wink Savillec0114b32011-02-18 10:14:07 -0800900 appendPrintBuf("%scmd=0x%X,efid=0x%X,path=%s,%d,%d,%d,%s,pin2=%s,aid=%s", printBuf,
901 simIO.v6.command, simIO.v6.fileid, (char*)simIO.v6.path,
902 simIO.v6.p1, simIO.v6.p2, simIO.v6.p3,
903 (char*)simIO.v6.data, (char*)simIO.v6.pin2, simIO.v6.aidPtr);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800904 closeRequest;
905 printRequest(pRI->token, pRI->pCI->requestNumber);
Wink Saville7f856802009-06-09 10:23:37 -0700906
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800907 if (status != NO_ERROR) {
908 goto invalid;
909 }
910
Wink Savillec0114b32011-02-18 10:14:07 -0800911 size = (s_callbacks.version < 6) ? sizeof(simIO.v5) : sizeof(simIO.v6);
Etan Cohend3652192014-06-20 08:28:44 -0700912 CALL_ONREQUEST(pRI->pCI->requestNumber, &simIO, size, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800913
914#ifdef MEMSET_FREED
Wink Savillec0114b32011-02-18 10:14:07 -0800915 memsetString (simIO.v6.path);
916 memsetString (simIO.v6.data);
917 memsetString (simIO.v6.pin2);
918 memsetString (simIO.v6.aidPtr);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800919#endif
920
Wink Savillec0114b32011-02-18 10:14:07 -0800921 free (simIO.v6.path);
922 free (simIO.v6.data);
923 free (simIO.v6.pin2);
924 free (simIO.v6.aidPtr);
Wink Saville7f856802009-06-09 10:23:37 -0700925
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800926#ifdef MEMSET_FREED
927 memset(&simIO, 0, sizeof(simIO));
928#endif
929
930 return;
931invalid:
932 invalidCommandBlock(pRI);
933 return;
934}
935
936/**
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800937 * Callee expects const RIL_SIM_APDU *
938 * Payload is:
939 * int32_t sessionid
940 * int32_t cla
941 * int32_t instruction
942 * int32_t p1, p2, p3
943 * String data
944 */
945static void
946dispatchSIM_APDU (Parcel &p, RequestInfo *pRI) {
947 int32_t t;
948 status_t status;
949 RIL_SIM_APDU apdu;
950
Robert Greenwalt191e4dc2015-04-29 16:57:39 -0700951#if VDBG
Mark Salyzyndba25612015-04-09 07:18:35 -0700952 RLOGD("dispatchSIM_APDU");
Robert Greenwalt191e4dc2015-04-29 16:57:39 -0700953#endif
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800954 memset (&apdu, 0, sizeof(RIL_SIM_APDU));
955
956 // Note we only check status at the end. Any single failure leads to
957 // subsequent reads filing.
958 status = p.readInt32(&t);
959 apdu.sessionid = (int)t;
960
961 status = p.readInt32(&t);
962 apdu.cla = (int)t;
963
964 status = p.readInt32(&t);
965 apdu.instruction = (int)t;
966
967 status = p.readInt32(&t);
968 apdu.p1 = (int)t;
969
970 status = p.readInt32(&t);
971 apdu.p2 = (int)t;
972
973 status = p.readInt32(&t);
974 apdu.p3 = (int)t;
975
976 apdu.data = strdupReadString(p);
977
978 startRequest;
979 appendPrintBuf("%ssessionid=%d,cla=%d,ins=%d,p1=%d,p2=%d,p3=%d,data=%s",
980 printBuf, apdu.sessionid, apdu.cla, apdu.instruction, apdu.p1, apdu.p2,
981 apdu.p3, (char*)apdu.data);
982 closeRequest;
983 printRequest(pRI->token, pRI->pCI->requestNumber);
984
985 if (status != NO_ERROR) {
986 goto invalid;
987 }
988
Etan Cohend3652192014-06-20 08:28:44 -0700989 CALL_ONREQUEST(pRI->pCI->requestNumber, &apdu, sizeof(RIL_SIM_APDU), pRI, pRI->socket_id);
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800990
991#ifdef MEMSET_FREED
992 memsetString(apdu.data);
993#endif
994 free(apdu.data);
995
996#ifdef MEMSET_FREED
997 memset(&apdu, 0, sizeof(RIL_SIM_APDU));
998#endif
999
1000 return;
1001invalid:
1002 invalidCommandBlock(pRI);
1003 return;
1004}
1005
1006
1007/**
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001008 * Callee expects const RIL_CallForwardInfo *
1009 * Payload is:
1010 * int32_t status/action
1011 * int32_t reason
1012 * int32_t serviceCode
1013 * int32_t toa
1014 * String number (0 length -> null)
1015 * int32_t timeSeconds
1016 */
Wink Saville7f856802009-06-09 10:23:37 -07001017static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001018dispatchCallForward(Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001019 RIL_CallForwardInfo cff;
1020 int32_t t;
1021 status_t status;
1022
Mark Salyzyndba25612015-04-09 07:18:35 -07001023 RLOGD("dispatchCallForward");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001024 memset (&cff, 0, sizeof(cff));
1025
Wink Saville7f856802009-06-09 10:23:37 -07001026 // note we only check status at the end
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001027
1028 status = p.readInt32(&t);
1029 cff.status = (int)t;
Wink Saville7f856802009-06-09 10:23:37 -07001030
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001031 status = p.readInt32(&t);
1032 cff.reason = (int)t;
1033
1034 status = p.readInt32(&t);
1035 cff.serviceClass = (int)t;
1036
1037 status = p.readInt32(&t);
1038 cff.toa = (int)t;
1039
1040 cff.number = strdupReadString(p);
1041
1042 status = p.readInt32(&t);
1043 cff.timeSeconds = (int)t;
1044
1045 if (status != NO_ERROR) {
1046 goto invalid;
1047 }
1048
1049 // special case: number 0-length fields is null
1050
1051 if (cff.number != NULL && strlen (cff.number) == 0) {
1052 cff.number = NULL;
1053 }
1054
1055 startRequest;
1056 appendPrintBuf("%sstat=%d,reason=%d,serv=%d,toa=%d,%s,tout=%d", printBuf,
1057 cff.status, cff.reason, cff.serviceClass, cff.toa,
1058 (char*)cff.number, cff.timeSeconds);
1059 closeRequest;
1060 printRequest(pRI->token, pRI->pCI->requestNumber);
1061
Etan Cohend3652192014-06-20 08:28:44 -07001062 CALL_ONREQUEST(pRI->pCI->requestNumber, &cff, sizeof(cff), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001063
1064#ifdef MEMSET_FREED
1065 memsetString(cff.number);
1066#endif
1067
1068 free (cff.number);
1069
1070#ifdef MEMSET_FREED
1071 memset(&cff, 0, sizeof(cff));
1072#endif
1073
1074 return;
1075invalid:
1076 invalidCommandBlock(pRI);
1077 return;
1078}
1079
1080
Wink Saville7f856802009-06-09 10:23:37 -07001081static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001082dispatchRaw(Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001083 int32_t len;
1084 status_t status;
1085 const void *data;
1086
1087 status = p.readInt32(&len);
1088
1089 if (status != NO_ERROR) {
1090 goto invalid;
1091 }
1092
1093 // The java code writes -1 for null arrays
1094 if (((int)len) == -1) {
1095 data = NULL;
1096 len = 0;
Wink Saville7f856802009-06-09 10:23:37 -07001097 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001098
1099 data = p.readInplace(len);
1100
1101 startRequest;
1102 appendPrintBuf("%sraw_size=%d", printBuf, len);
1103 closeRequest;
1104 printRequest(pRI->token, pRI->pCI->requestNumber);
1105
Etan Cohend3652192014-06-20 08:28:44 -07001106 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<void *>(data), len, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001107
1108 return;
1109invalid:
1110 invalidCommandBlock(pRI);
1111 return;
1112}
1113
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001114static status_t
1115constructCdmaSms(Parcel &p, RequestInfo *pRI, RIL_CDMA_SMS_Message& rcsm) {
Wink Savillef4c4d362009-04-02 01:37:03 -07001116 int32_t t;
1117 uint8_t ut;
1118 status_t status;
1119 int32_t digitCount;
1120 int digitLimit;
Wink Saville7f856802009-06-09 10:23:37 -07001121
Wink Savillef4c4d362009-04-02 01:37:03 -07001122 memset(&rcsm, 0, sizeof(rcsm));
1123
1124 status = p.readInt32(&t);
1125 rcsm.uTeleserviceID = (int) t;
1126
1127 status = p.read(&ut,sizeof(ut));
1128 rcsm.bIsServicePresent = (uint8_t) ut;
1129
1130 status = p.readInt32(&t);
1131 rcsm.uServicecategory = (int) t;
1132
1133 status = p.readInt32(&t);
1134 rcsm.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1135
1136 status = p.readInt32(&t);
1137 rcsm.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1138
1139 status = p.readInt32(&t);
1140 rcsm.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1141
1142 status = p.readInt32(&t);
1143 rcsm.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1144
1145 status = p.read(&ut,sizeof(ut));
1146 rcsm.sAddress.number_of_digits= (uint8_t) ut;
1147
1148 digitLimit= MIN((rcsm.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
1149 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1150 status = p.read(&ut,sizeof(ut));
1151 rcsm.sAddress.digits[digitCount] = (uint8_t) ut;
1152 }
1153
Wink Saville7f856802009-06-09 10:23:37 -07001154 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001155 rcsm.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1156
Wink Saville7f856802009-06-09 10:23:37 -07001157 status = p.read(&ut,sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001158 rcsm.sSubAddress.odd = (uint8_t) ut;
1159
1160 status = p.read(&ut,sizeof(ut));
1161 rcsm.sSubAddress.number_of_digits = (uint8_t) ut;
1162
1163 digitLimit= MIN((rcsm.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
Wink Saville7f856802009-06-09 10:23:37 -07001164 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1165 status = p.read(&ut,sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001166 rcsm.sSubAddress.digits[digitCount] = (uint8_t) ut;
1167 }
1168
Wink Saville7f856802009-06-09 10:23:37 -07001169 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001170 rcsm.uBearerDataLen = (int) t;
1171
1172 digitLimit= MIN((rcsm.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
Wink Saville7f856802009-06-09 10:23:37 -07001173 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1174 status = p.read(&ut, sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001175 rcsm.aBearerData[digitCount] = (uint8_t) ut;
1176 }
1177
1178 if (status != NO_ERROR) {
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001179 return status;
Wink Savillef4c4d362009-04-02 01:37:03 -07001180 }
1181
1182 startRequest;
1183 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
Wink Saville1b5fd232009-04-22 14:50:00 -07001184 sAddress.digit_mode=%d, sAddress.Number_mode=%d, sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07001185 printBuf, rcsm.uTeleserviceID,rcsm.bIsServicePresent,rcsm.uServicecategory,
Wink Saville1b5fd232009-04-22 14:50:00 -07001186 rcsm.sAddress.digit_mode, rcsm.sAddress.number_mode,rcsm.sAddress.number_type);
Wink Savillef4c4d362009-04-02 01:37:03 -07001187 closeRequest;
Wink Saville7f856802009-06-09 10:23:37 -07001188
Wink Savillef4c4d362009-04-02 01:37:03 -07001189 printRequest(pRI->token, pRI->pCI->requestNumber);
1190
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001191 return status;
1192}
1193
1194static void
1195dispatchCdmaSms(Parcel &p, RequestInfo *pRI) {
1196 RIL_CDMA_SMS_Message rcsm;
1197
Mark Salyzyndba25612015-04-09 07:18:35 -07001198 RLOGD("dispatchCdmaSms");
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001199 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1200 goto invalid;
1201 }
1202
Etan Cohend3652192014-06-20 08:28:44 -07001203 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001204
1205#ifdef MEMSET_FREED
1206 memset(&rcsm, 0, sizeof(rcsm));
1207#endif
1208
1209 return;
1210
1211invalid:
1212 invalidCommandBlock(pRI);
1213 return;
1214}
1215
Wink Saville7f856802009-06-09 10:23:37 -07001216static void
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001217dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1218 RIL_IMS_SMS_Message rism;
1219 RIL_CDMA_SMS_Message rcsm;
1220
Mark Salyzyndba25612015-04-09 07:18:35 -07001221 RLOGD("dispatchImsCdmaSms: retry=%d, messageRef=%d", retry, messageRef);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001222
1223 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1224 goto invalid;
1225 }
1226 memset(&rism, 0, sizeof(rism));
1227 rism.tech = RADIO_TECH_3GPP2;
1228 rism.retry = retry;
1229 rism.messageRef = messageRef;
1230 rism.message.cdmaMessage = &rcsm;
1231
Etan Cohend3652192014-06-20 08:28:44 -07001232 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001233 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Etan Cohend3652192014-06-20 08:28:44 -07001234 +sizeof(rcsm),pRI, pRI->socket_id);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001235
1236#ifdef MEMSET_FREED
1237 memset(&rcsm, 0, sizeof(rcsm));
1238 memset(&rism, 0, sizeof(rism));
1239#endif
1240
1241 return;
1242
1243invalid:
1244 invalidCommandBlock(pRI);
1245 return;
1246}
1247
1248static void
1249dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1250 RIL_IMS_SMS_Message rism;
1251 int32_t countStrings;
1252 status_t status;
1253 size_t datalen;
1254 char **pStrings;
Mark Salyzyndba25612015-04-09 07:18:35 -07001255 RLOGD("dispatchImsGsmSms: retry=%d, messageRef=%d", retry, messageRef);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001256
1257 status = p.readInt32 (&countStrings);
1258
1259 if (status != NO_ERROR) {
1260 goto invalid;
1261 }
1262
1263 memset(&rism, 0, sizeof(rism));
1264 rism.tech = RADIO_TECH_3GPP;
1265 rism.retry = retry;
1266 rism.messageRef = messageRef;
1267
1268 startRequest;
Etan Cohen5d891b72014-02-27 17:25:17 -08001269 appendPrintBuf("%stech=%d, retry=%d, messageRef=%d, ", printBuf,
1270 (int)rism.tech, (int)rism.retry, rism.messageRef);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001271 if (countStrings == 0) {
1272 // just some non-null pointer
1273 pStrings = (char **)alloca(sizeof(char *));
1274 datalen = 0;
1275 } else if (((int)countStrings) == -1) {
1276 pStrings = NULL;
1277 datalen = 0;
1278 } else {
1279 datalen = sizeof(char *) * countStrings;
1280
1281 pStrings = (char **)alloca(datalen);
1282
1283 for (int i = 0 ; i < countStrings ; i++) {
1284 pStrings[i] = strdupReadString(p);
1285 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
1286 }
1287 }
1288 removeLastChar;
1289 closeRequest;
1290 printRequest(pRI->token, pRI->pCI->requestNumber);
1291
1292 rism.message.gsmMessage = pStrings;
Etan Cohend3652192014-06-20 08:28:44 -07001293 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001294 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Etan Cohend3652192014-06-20 08:28:44 -07001295 +datalen, pRI, pRI->socket_id);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001296
1297 if (pStrings != NULL) {
1298 for (int i = 0 ; i < countStrings ; i++) {
1299#ifdef MEMSET_FREED
1300 memsetString (pStrings[i]);
1301#endif
1302 free(pStrings[i]);
1303 }
1304
1305#ifdef MEMSET_FREED
1306 memset(pStrings, 0, datalen);
1307#endif
1308 }
1309
1310#ifdef MEMSET_FREED
1311 memset(&rism, 0, sizeof(rism));
1312#endif
1313 return;
1314invalid:
1315 ALOGE("dispatchImsGsmSms invalid block");
1316 invalidCommandBlock(pRI);
1317 return;
1318}
1319
1320static void
1321dispatchImsSms(Parcel &p, RequestInfo *pRI) {
1322 int32_t t;
1323 status_t status = p.readInt32(&t);
1324 RIL_RadioTechnologyFamily format;
1325 uint8_t retry;
1326 int32_t messageRef;
1327
Mark Salyzyndba25612015-04-09 07:18:35 -07001328 RLOGD("dispatchImsSms");
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001329 if (status != NO_ERROR) {
1330 goto invalid;
1331 }
1332 format = (RIL_RadioTechnologyFamily) t;
1333
1334 // read retry field
1335 status = p.read(&retry,sizeof(retry));
1336 if (status != NO_ERROR) {
1337 goto invalid;
1338 }
1339 // read messageRef field
1340 status = p.read(&messageRef,sizeof(messageRef));
1341 if (status != NO_ERROR) {
1342 goto invalid;
1343 }
1344
1345 if (RADIO_TECH_3GPP == format) {
1346 dispatchImsGsmSms(p, pRI, retry, messageRef);
1347 } else if (RADIO_TECH_3GPP2 == format) {
1348 dispatchImsCdmaSms(p, pRI, retry, messageRef);
1349 } else {
1350 ALOGE("requestImsSendSMS invalid format value =%d", format);
1351 }
1352
1353 return;
1354
1355invalid:
1356 invalidCommandBlock(pRI);
1357 return;
1358}
1359
1360static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001361dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI) {
1362 RIL_CDMA_SMS_Ack rcsa;
1363 int32_t t;
1364 status_t status;
1365 int32_t digitCount;
1366
Mark Salyzyndba25612015-04-09 07:18:35 -07001367 RLOGD("dispatchCdmaSmsAck");
Wink Savillef4c4d362009-04-02 01:37:03 -07001368 memset(&rcsa, 0, sizeof(rcsa));
1369
1370 status = p.readInt32(&t);
1371 rcsa.uErrorClass = (RIL_CDMA_SMS_ErrorClass) t;
1372
1373 status = p.readInt32(&t);
1374 rcsa.uSMSCauseCode = (int) t;
1375
1376 if (status != NO_ERROR) {
1377 goto invalid;
1378 }
1379
1380 startRequest;
Wink Saville1b5fd232009-04-22 14:50:00 -07001381 appendPrintBuf("%suErrorClass=%d, uTLStatus=%d, ",
1382 printBuf, rcsa.uErrorClass, rcsa.uSMSCauseCode);
Wink Savillef4c4d362009-04-02 01:37:03 -07001383 closeRequest;
1384
1385 printRequest(pRI->token, pRI->pCI->requestNumber);
1386
Etan Cohend3652192014-06-20 08:28:44 -07001387 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsa, sizeof(rcsa),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001388
1389#ifdef MEMSET_FREED
1390 memset(&rcsa, 0, sizeof(rcsa));
1391#endif
1392
1393 return;
1394
1395invalid:
1396 invalidCommandBlock(pRI);
1397 return;
1398}
1399
Wink Savillea592eeb2009-05-22 13:26:36 -07001400static void
1401dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1402 int32_t t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001403 status_t status;
Wink Savillea592eeb2009-05-22 13:26:36 -07001404 int32_t num;
Wink Savillef4c4d362009-04-02 01:37:03 -07001405
Wink Savillea592eeb2009-05-22 13:26:36 -07001406 status = p.readInt32(&num);
Wink Savillef4c4d362009-04-02 01:37:03 -07001407 if (status != NO_ERROR) {
1408 goto invalid;
1409 }
1410
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001411 {
1412 RIL_GSM_BroadcastSmsConfigInfo gsmBci[num];
1413 RIL_GSM_BroadcastSmsConfigInfo *gsmBciPtrs[num];
Wink Savillea592eeb2009-05-22 13:26:36 -07001414
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001415 startRequest;
1416 for (int i = 0 ; i < num ; i++ ) {
1417 gsmBciPtrs[i] = &gsmBci[i];
Wink Savillef4c4d362009-04-02 01:37:03 -07001418
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001419 status = p.readInt32(&t);
1420 gsmBci[i].fromServiceId = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001421
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001422 status = p.readInt32(&t);
1423 gsmBci[i].toServiceId = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001424
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001425 status = p.readInt32(&t);
1426 gsmBci[i].fromCodeScheme = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001427
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001428 status = p.readInt32(&t);
1429 gsmBci[i].toCodeScheme = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001430
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001431 status = p.readInt32(&t);
1432 gsmBci[i].selected = (uint8_t) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001433
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001434 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId =%d, \
1435 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]", printBuf, i,
1436 gsmBci[i].fromServiceId, gsmBci[i].toServiceId,
1437 gsmBci[i].fromCodeScheme, gsmBci[i].toCodeScheme,
1438 gsmBci[i].selected);
1439 }
1440 closeRequest;
Wink Savillef4c4d362009-04-02 01:37:03 -07001441
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001442 if (status != NO_ERROR) {
1443 goto invalid;
1444 }
Wink Savillef4c4d362009-04-02 01:37:03 -07001445
Etan Cohend3652192014-06-20 08:28:44 -07001446 CALL_ONREQUEST(pRI->pCI->requestNumber,
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001447 gsmBciPtrs,
1448 num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *),
Etan Cohend3652192014-06-20 08:28:44 -07001449 pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001450
1451#ifdef MEMSET_FREED
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001452 memset(gsmBci, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo));
1453 memset(gsmBciPtrs, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *));
Wink Savillef4c4d362009-04-02 01:37:03 -07001454#endif
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001455 }
Wink Savillef4c4d362009-04-02 01:37:03 -07001456
1457 return;
1458
1459invalid:
1460 invalidCommandBlock(pRI);
1461 return;
Wink Savillea592eeb2009-05-22 13:26:36 -07001462}
Wink Savillef4c4d362009-04-02 01:37:03 -07001463
Wink Savillea592eeb2009-05-22 13:26:36 -07001464static void
1465dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1466 int32_t t;
1467 status_t status;
1468 int32_t num;
1469
1470 status = p.readInt32(&num);
1471 if (status != NO_ERROR) {
1472 goto invalid;
1473 }
1474
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001475 {
1476 RIL_CDMA_BroadcastSmsConfigInfo cdmaBci[num];
1477 RIL_CDMA_BroadcastSmsConfigInfo *cdmaBciPtrs[num];
Wink Savillea592eeb2009-05-22 13:26:36 -07001478
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001479 startRequest;
1480 for (int i = 0 ; i < num ; i++ ) {
1481 cdmaBciPtrs[i] = &cdmaBci[i];
Wink Savillea592eeb2009-05-22 13:26:36 -07001482
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001483 status = p.readInt32(&t);
1484 cdmaBci[i].service_category = (int) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001485
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001486 status = p.readInt32(&t);
1487 cdmaBci[i].language = (int) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001488
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001489 status = p.readInt32(&t);
1490 cdmaBci[i].selected = (uint8_t) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001491
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001492 appendPrintBuf("%s [%d: service_category=%d, language =%d, \
1493 entries.bSelected =%d]", printBuf, i, cdmaBci[i].service_category,
1494 cdmaBci[i].language, cdmaBci[i].selected);
1495 }
1496 closeRequest;
Wink Savillea592eeb2009-05-22 13:26:36 -07001497
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001498 if (status != NO_ERROR) {
1499 goto invalid;
1500 }
Wink Savillea592eeb2009-05-22 13:26:36 -07001501
Etan Cohend3652192014-06-20 08:28:44 -07001502 CALL_ONREQUEST(pRI->pCI->requestNumber,
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001503 cdmaBciPtrs,
1504 num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *),
Etan Cohend3652192014-06-20 08:28:44 -07001505 pRI, pRI->socket_id);
Wink Savillea592eeb2009-05-22 13:26:36 -07001506
1507#ifdef MEMSET_FREED
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001508 memset(cdmaBci, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo));
1509 memset(cdmaBciPtrs, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *));
Wink Savillea592eeb2009-05-22 13:26:36 -07001510#endif
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001511 }
Wink Savillea592eeb2009-05-22 13:26:36 -07001512
1513 return;
1514
1515invalid:
1516 invalidCommandBlock(pRI);
1517 return;
Wink Savillef4c4d362009-04-02 01:37:03 -07001518}
1519
1520static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI) {
1521 RIL_CDMA_SMS_WriteArgs rcsw;
1522 int32_t t;
1523 uint32_t ut;
1524 uint8_t uct;
1525 status_t status;
1526 int32_t digitCount;
1527
1528 memset(&rcsw, 0, sizeof(rcsw));
1529
1530 status = p.readInt32(&t);
1531 rcsw.status = t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001532
Wink Savillef4c4d362009-04-02 01:37:03 -07001533 status = p.readInt32(&t);
1534 rcsw.message.uTeleserviceID = (int) t;
1535
1536 status = p.read(&uct,sizeof(uct));
1537 rcsw.message.bIsServicePresent = (uint8_t) uct;
1538
1539 status = p.readInt32(&t);
1540 rcsw.message.uServicecategory = (int) t;
1541
1542 status = p.readInt32(&t);
1543 rcsw.message.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1544
1545 status = p.readInt32(&t);
1546 rcsw.message.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1547
1548 status = p.readInt32(&t);
1549 rcsw.message.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1550
1551 status = p.readInt32(&t);
1552 rcsw.message.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1553
1554 status = p.read(&uct,sizeof(uct));
1555 rcsw.message.sAddress.number_of_digits = (uint8_t) uct;
1556
1557 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_ADDRESS_MAX; digitCount ++) {
1558 status = p.read(&uct,sizeof(uct));
1559 rcsw.message.sAddress.digits[digitCount] = (uint8_t) uct;
1560 }
1561
Wink Savillea592eeb2009-05-22 13:26:36 -07001562 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001563 rcsw.message.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1564
Wink Savillea592eeb2009-05-22 13:26:36 -07001565 status = p.read(&uct,sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001566 rcsw.message.sSubAddress.odd = (uint8_t) uct;
1567
1568 status = p.read(&uct,sizeof(uct));
1569 rcsw.message.sSubAddress.number_of_digits = (uint8_t) uct;
1570
1571 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_SUBADDRESS_MAX; digitCount ++) {
Wink Savillea592eeb2009-05-22 13:26:36 -07001572 status = p.read(&uct,sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001573 rcsw.message.sSubAddress.digits[digitCount] = (uint8_t) uct;
1574 }
1575
Wink Savillea592eeb2009-05-22 13:26:36 -07001576 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001577 rcsw.message.uBearerDataLen = (int) t;
1578
1579 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_BEARER_DATA_MAX; digitCount ++) {
Wink Savillea592eeb2009-05-22 13:26:36 -07001580 status = p.read(&uct, sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001581 rcsw.message.aBearerData[digitCount] = (uint8_t) uct;
1582 }
1583
1584 if (status != NO_ERROR) {
1585 goto invalid;
1586 }
1587
1588 startRequest;
Wink Saville1b5fd232009-04-22 14:50:00 -07001589 appendPrintBuf("%sstatus=%d, message.uTeleserviceID=%d, message.bIsServicePresent=%d, \
1590 message.uServicecategory=%d, message.sAddress.digit_mode=%d, \
1591 message.sAddress.number_mode=%d, \
1592 message.sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07001593 printBuf, rcsw.status, rcsw.message.uTeleserviceID, rcsw.message.bIsServicePresent,
Wink Saville1b5fd232009-04-22 14:50:00 -07001594 rcsw.message.uServicecategory, rcsw.message.sAddress.digit_mode,
1595 rcsw.message.sAddress.number_mode,
1596 rcsw.message.sAddress.number_type);
Wink Savillef4c4d362009-04-02 01:37:03 -07001597 closeRequest;
1598
1599 printRequest(pRI->token, pRI->pCI->requestNumber);
1600
Etan Cohend3652192014-06-20 08:28:44 -07001601 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsw, sizeof(rcsw),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001602
1603#ifdef MEMSET_FREED
1604 memset(&rcsw, 0, sizeof(rcsw));
1605#endif
1606
1607 return;
1608
1609invalid:
1610 invalidCommandBlock(pRI);
1611 return;
1612
1613}
1614
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -07001615// For backwards compatibility in RIL_REQUEST_SETUP_DATA_CALL.
1616// Version 4 of the RIL interface adds a new PDP type parameter to support
1617// IPv6 and dual-stack PDP contexts. When dealing with a previous version of
1618// RIL, remove the parameter from the request.
1619static void dispatchDataCall(Parcel& p, RequestInfo *pRI) {
1620 // In RIL v3, REQUEST_SETUP_DATA_CALL takes 6 parameters.
1621 const int numParamsRilV3 = 6;
1622
1623 // The first bytes of the RIL parcel contain the request number and the
1624 // serial number - see processCommandBuffer(). Copy them over too.
1625 int pos = p.dataPosition();
1626
1627 int numParams = p.readInt32();
1628 if (s_callbacks.version < 4 && numParams > numParamsRilV3) {
1629 Parcel p2;
1630 p2.appendFrom(&p, 0, pos);
1631 p2.writeInt32(numParamsRilV3);
1632 for(int i = 0; i < numParamsRilV3; i++) {
1633 p2.writeString16(p.readString16());
1634 }
1635 p2.setDataPosition(pos);
1636 dispatchStrings(p2, pRI);
1637 } else {
Lorenzo Colitti57ce1f22010-09-13 12:23:50 -07001638 p.setDataPosition(pos);
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -07001639 dispatchStrings(p, pRI);
1640 }
1641}
1642
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001643// For backwards compatibility with RILs that dont support RIL_REQUEST_VOICE_RADIO_TECH.
1644// When all RILs handle this request, this function can be removed and
1645// the request can be sent directly to the RIL using dispatchVoid.
1646static void dispatchVoiceRadioTech(Parcel& p, RequestInfo *pRI) {
Etan Cohend3652192014-06-20 08:28:44 -07001647 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001648
1649 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1650 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1651 }
1652
1653 // RILs that support RADIO_STATE_ON should support this request.
1654 if (RADIO_STATE_ON == state) {
1655 dispatchVoid(p, pRI);
1656 return;
1657 }
1658
1659 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1660 // will not support this new request either and decode Voice Radio Technology
1661 // from Radio State
1662 voiceRadioTech = decodeVoiceRadioTechnology(state);
1663
1664 if (voiceRadioTech < 0)
1665 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1666 else
1667 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &voiceRadioTech, sizeof(int));
1668}
1669
1670// For backwards compatibility in RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE:.
1671// When all RILs handle this request, this function can be removed and
1672// the request can be sent directly to the RIL using dispatchVoid.
1673static void dispatchCdmaSubscriptionSource(Parcel& p, RequestInfo *pRI) {
Etan Cohend3652192014-06-20 08:28:44 -07001674 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001675
1676 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1677 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1678 }
1679
1680 // RILs that support RADIO_STATE_ON should support this request.
1681 if (RADIO_STATE_ON == state) {
1682 dispatchVoid(p, pRI);
1683 return;
1684 }
1685
1686 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1687 // will not support this new request either and decode CDMA Subscription Source
1688 // from Radio State
1689 cdmaSubscriptionSource = decodeCdmaSubscriptionSource(state);
1690
1691 if (cdmaSubscriptionSource < 0)
1692 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1693 else
1694 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &cdmaSubscriptionSource, sizeof(int));
1695}
1696
Sungmin Choi75697532013-04-26 15:04:45 -07001697static void dispatchSetInitialAttachApn(Parcel &p, RequestInfo *pRI)
1698{
1699 RIL_InitialAttachApn pf;
1700 int32_t t;
1701 status_t status;
1702
1703 memset(&pf, 0, sizeof(pf));
1704
1705 pf.apn = strdupReadString(p);
1706 pf.protocol = strdupReadString(p);
1707
1708 status = p.readInt32(&t);
1709 pf.authtype = (int) t;
1710
1711 pf.username = strdupReadString(p);
1712 pf.password = strdupReadString(p);
1713
1714 startRequest;
Etan Cohen5d891b72014-02-27 17:25:17 -08001715 appendPrintBuf("%sapn=%s, protocol=%s, authtype=%d, username=%s, password=%s",
1716 printBuf, pf.apn, pf.protocol, pf.authtype, pf.username, pf.password);
Sungmin Choi75697532013-04-26 15:04:45 -07001717 closeRequest;
1718 printRequest(pRI->token, pRI->pCI->requestNumber);
1719
1720 if (status != NO_ERROR) {
1721 goto invalid;
1722 }
Etan Cohend3652192014-06-20 08:28:44 -07001723 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
Sungmin Choi75697532013-04-26 15:04:45 -07001724
1725#ifdef MEMSET_FREED
1726 memsetString(pf.apn);
1727 memsetString(pf.protocol);
1728 memsetString(pf.username);
1729 memsetString(pf.password);
1730#endif
1731
1732 free(pf.apn);
1733 free(pf.protocol);
1734 free(pf.username);
1735 free(pf.password);
1736
1737#ifdef MEMSET_FREED
1738 memset(&pf, 0, sizeof(pf));
1739#endif
1740
1741 return;
1742invalid:
1743 invalidCommandBlock(pRI);
1744 return;
1745}
1746
Jake Hamby8a4a2332014-01-15 13:12:05 -08001747static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI) {
1748 RIL_NV_ReadItem nvri;
1749 int32_t t;
1750 status_t status;
1751
1752 memset(&nvri, 0, sizeof(nvri));
1753
1754 status = p.readInt32(&t);
1755 nvri.itemID = (RIL_NV_Item) t;
1756
1757 if (status != NO_ERROR) {
1758 goto invalid;
1759 }
1760
1761 startRequest;
1762 appendPrintBuf("%snvri.itemID=%d, ", printBuf, nvri.itemID);
1763 closeRequest;
1764
1765 printRequest(pRI->token, pRI->pCI->requestNumber);
1766
Etan Cohend3652192014-06-20 08:28:44 -07001767 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvri, sizeof(nvri), pRI, pRI->socket_id);
Jake Hamby8a4a2332014-01-15 13:12:05 -08001768
1769#ifdef MEMSET_FREED
1770 memset(&nvri, 0, sizeof(nvri));
1771#endif
1772
1773 return;
1774
1775invalid:
1776 invalidCommandBlock(pRI);
1777 return;
1778}
1779
1780static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI) {
1781 RIL_NV_WriteItem nvwi;
1782 int32_t t;
1783 status_t status;
1784
1785 memset(&nvwi, 0, sizeof(nvwi));
1786
1787 status = p.readInt32(&t);
1788 nvwi.itemID = (RIL_NV_Item) t;
1789
1790 nvwi.value = strdupReadString(p);
1791
1792 if (status != NO_ERROR || nvwi.value == NULL) {
1793 goto invalid;
1794 }
1795
1796 startRequest;
1797 appendPrintBuf("%snvwi.itemID=%d, value=%s, ", printBuf, nvwi.itemID,
1798 nvwi.value);
1799 closeRequest;
1800
1801 printRequest(pRI->token, pRI->pCI->requestNumber);
1802
Etan Cohend3652192014-06-20 08:28:44 -07001803 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvwi, sizeof(nvwi), pRI, pRI->socket_id);
Jake Hamby8a4a2332014-01-15 13:12:05 -08001804
1805#ifdef MEMSET_FREED
1806 memsetString(nvwi.value);
1807#endif
1808
1809 free(nvwi.value);
1810
1811#ifdef MEMSET_FREED
1812 memset(&nvwi, 0, sizeof(nvwi));
1813#endif
1814
1815 return;
1816
1817invalid:
1818 invalidCommandBlock(pRI);
1819 return;
1820}
1821
1822
Etan Cohend3652192014-06-20 08:28:44 -07001823static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI) {
1824 RIL_SelectUiccSub uicc_sub;
1825 status_t status;
1826 int32_t t;
1827 memset(&uicc_sub, 0, sizeof(uicc_sub));
1828
1829 status = p.readInt32(&t);
1830 if (status != NO_ERROR) {
1831 goto invalid;
1832 }
1833 uicc_sub.slot = (int) t;
1834
1835 status = p.readInt32(&t);
1836 if (status != NO_ERROR) {
1837 goto invalid;
1838 }
1839 uicc_sub.app_index = (int) t;
1840
1841 status = p.readInt32(&t);
1842 if (status != NO_ERROR) {
1843 goto invalid;
1844 }
1845 uicc_sub.sub_type = (RIL_SubscriptionType) t;
1846
1847 status = p.readInt32(&t);
1848 if (status != NO_ERROR) {
1849 goto invalid;
1850 }
1851 uicc_sub.act_status = (RIL_UiccSubActStatus) t;
1852
1853 startRequest;
1854 appendPrintBuf("slot=%d, app_index=%d, act_status = %d", uicc_sub.slot, uicc_sub.app_index,
1855 uicc_sub.act_status);
1856 RLOGD("dispatchUiccSubscription, slot=%d, app_index=%d, act_status = %d", uicc_sub.slot,
1857 uicc_sub.app_index, uicc_sub.act_status);
1858 closeRequest;
1859 printRequest(pRI->token, pRI->pCI->requestNumber);
1860
1861 CALL_ONREQUEST(pRI->pCI->requestNumber, &uicc_sub, sizeof(uicc_sub), pRI, pRI->socket_id);
1862
1863#ifdef MEMSET_FREED
1864 memset(&uicc_sub, 0, sizeof(uicc_sub));
1865#endif
1866 return;
1867
1868invalid:
1869 invalidCommandBlock(pRI);
1870 return;
1871}
1872
Amit Mahajan90530a62014-07-01 15:54:08 -07001873static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI)
1874{
1875 RIL_SimAuthentication pf;
1876 int32_t t;
1877 status_t status;
1878
1879 memset(&pf, 0, sizeof(pf));
1880
1881 status = p.readInt32(&t);
1882 pf.authContext = (int) t;
1883 pf.authData = strdupReadString(p);
1884 pf.aid = strdupReadString(p);
1885
1886 startRequest;
1887 appendPrintBuf("authContext=%s, authData=%s, aid=%s", pf.authContext, pf.authData, pf.aid);
1888 closeRequest;
1889 printRequest(pRI->token, pRI->pCI->requestNumber);
1890
1891 if (status != NO_ERROR) {
1892 goto invalid;
1893 }
1894 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
1895
1896#ifdef MEMSET_FREED
1897 memsetString(pf.authData);
1898 memsetString(pf.aid);
1899#endif
1900
1901 free(pf.authData);
1902 free(pf.aid);
1903
1904#ifdef MEMSET_FREED
1905 memset(&pf, 0, sizeof(pf));
1906#endif
1907
1908 return;
1909invalid:
1910 invalidCommandBlock(pRI);
1911 return;
1912}
1913
Amit Mahajanc796e222014-08-13 16:54:01 +00001914static void dispatchDataProfile(Parcel &p, RequestInfo *pRI) {
1915 int32_t t;
1916 status_t status;
1917 int32_t num;
1918
1919 status = p.readInt32(&num);
1920 if (status != NO_ERROR) {
1921 goto invalid;
1922 }
1923
1924 {
1925 RIL_DataProfileInfo dataProfiles[num];
1926 RIL_DataProfileInfo *dataProfilePtrs[num];
1927
1928 startRequest;
1929 for (int i = 0 ; i < num ; i++ ) {
1930 dataProfilePtrs[i] = &dataProfiles[i];
1931
1932 status = p.readInt32(&t);
1933 dataProfiles[i].profileId = (int) t;
1934
1935 dataProfiles[i].apn = strdupReadString(p);
1936 dataProfiles[i].protocol = strdupReadString(p);
1937 status = p.readInt32(&t);
1938 dataProfiles[i].authType = (int) t;
1939
1940 dataProfiles[i].user = strdupReadString(p);
1941 dataProfiles[i].password = strdupReadString(p);
1942
1943 status = p.readInt32(&t);
1944 dataProfiles[i].type = (int) t;
1945
1946 status = p.readInt32(&t);
1947 dataProfiles[i].maxConnsTime = (int) t;
1948 status = p.readInt32(&t);
1949 dataProfiles[i].maxConns = (int) t;
1950 status = p.readInt32(&t);
1951 dataProfiles[i].waitTime = (int) t;
1952
1953 status = p.readInt32(&t);
1954 dataProfiles[i].enabled = (int) t;
1955
1956 appendPrintBuf("%s [%d: profileId=%d, apn =%s, protocol =%s, authType =%d, \
1957 user =%s, password =%s, type =%d, maxConnsTime =%d, maxConns =%d, \
1958 waitTime =%d, enabled =%d]", printBuf, i, dataProfiles[i].profileId,
1959 dataProfiles[i].apn, dataProfiles[i].protocol, dataProfiles[i].authType,
1960 dataProfiles[i].user, dataProfiles[i].password, dataProfiles[i].type,
1961 dataProfiles[i].maxConnsTime, dataProfiles[i].maxConns,
1962 dataProfiles[i].waitTime, dataProfiles[i].enabled);
1963 }
1964 closeRequest;
1965 printRequest(pRI->token, pRI->pCI->requestNumber);
1966
1967 if (status != NO_ERROR) {
1968 goto invalid;
1969 }
1970 CALL_ONREQUEST(pRI->pCI->requestNumber,
1971 dataProfilePtrs,
1972 num * sizeof(RIL_DataProfileInfo *),
1973 pRI, pRI->socket_id);
1974
1975#ifdef MEMSET_FREED
1976 memset(dataProfiles, 0, num * sizeof(RIL_DataProfileInfo));
1977 memset(dataProfilePtrs, 0, num * sizeof(RIL_DataProfileInfo *));
1978#endif
1979 }
1980
1981 return;
1982
1983invalid:
1984 invalidCommandBlock(pRI);
1985 return;
1986}
1987
Wink Saville8b4e4f72014-10-17 15:01:45 -07001988static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI){
1989 RIL_RadioCapability rc;
1990 int32_t t;
1991 status_t status;
1992
1993 memset (&rc, 0, sizeof(RIL_RadioCapability));
1994
1995 status = p.readInt32(&t);
1996 rc.version = (int)t;
1997 if (status != NO_ERROR) {
1998 goto invalid;
1999 }
2000
2001 status = p.readInt32(&t);
2002 rc.session= (int)t;
2003 if (status != NO_ERROR) {
2004 goto invalid;
2005 }
2006
2007 status = p.readInt32(&t);
2008 rc.phase= (int)t;
2009 if (status != NO_ERROR) {
2010 goto invalid;
2011 }
2012
2013 status = p.readInt32(&t);
2014 rc.rat = (int)t;
2015 if (status != NO_ERROR) {
2016 goto invalid;
2017 }
2018
2019 status = readStringFromParcelInplace(p, rc.logicalModemUuid, sizeof(rc.logicalModemUuid));
2020 if (status != NO_ERROR) {
2021 goto invalid;
2022 }
2023
2024 status = p.readInt32(&t);
2025 rc.status = (int)t;
2026
2027 if (status != NO_ERROR) {
2028 goto invalid;
2029 }
2030
2031 startRequest;
2032 appendPrintBuf("%s [version:%d, session:%d, phase:%d, rat:%d, \
Chih-Wei Huang8593f262015-10-02 15:09:52 +08002033 logicalModemUuid:%s, status:%d", printBuf, rc.version, rc.session,
Legler Wu8caf06f2014-10-29 14:02:14 +08002034 rc.phase, rc.rat, rc.logicalModemUuid, rc.session);
Wink Saville8b4e4f72014-10-17 15:01:45 -07002035
2036 closeRequest;
2037 printRequest(pRI->token, pRI->pCI->requestNumber);
2038
2039 CALL_ONREQUEST(pRI->pCI->requestNumber,
2040 &rc,
2041 sizeof(RIL_RadioCapability),
2042 pRI, pRI->socket_id);
2043 return;
2044invalid:
2045 invalidCommandBlock(pRI);
2046 return;
2047}
2048
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002049static int
Wink Savillef4c4d362009-04-02 01:37:03 -07002050blockingWrite(int fd, const void *buffer, size_t len) {
Wink Saville7f856802009-06-09 10:23:37 -07002051 size_t writeOffset = 0;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002052 const uint8_t *toWrite;
2053
2054 toWrite = (const uint8_t *)buffer;
2055
2056 while (writeOffset < len) {
2057 ssize_t written;
2058 do {
2059 written = write (fd, toWrite + writeOffset,
2060 len - writeOffset);
Banavathu, Srinivas Naik38884902011-07-05 20:04:25 +05302061 } while (written < 0 && ((errno == EINTR) || (errno == EAGAIN)));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002062
2063 if (written >= 0) {
2064 writeOffset += written;
2065 } else { // written < 0
Wink Saville8eb2a122012-11-19 16:05:13 -08002066 RLOGE ("RIL Response: unexpected error on write errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002067 close(fd);
2068 return -1;
2069 }
2070 }
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07002071#if VDBG
Dheeraj Shetty27976c42014-07-02 21:27:57 +02002072 RLOGE("RIL Response bytes written:%d", writeOffset);
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07002073#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002074 return 0;
2075}
2076
2077static int
Etan Cohend3652192014-06-20 08:28:44 -07002078sendResponseRaw (const void *data, size_t dataSize, RIL_SOCKET_ID socket_id) {
2079 int fd = s_ril_param_socket.fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002080 int ret;
2081 uint32_t header;
Etan Cohend3652192014-06-20 08:28:44 -07002082 pthread_mutex_t * writeMutexHook = &s_writeMutex;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002083
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07002084#if VDBG
Etan Cohend3652192014-06-20 08:28:44 -07002085 RLOGE("Send Response to %s", rilSocketIdToString(socket_id));
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07002086#endif
Etan Cohend3652192014-06-20 08:28:44 -07002087
2088#if (SIM_COUNT >= 2)
2089 if (socket_id == RIL_SOCKET_2) {
2090 fd = s_ril_param_socket2.fdCommand;
2091 writeMutexHook = &s_writeMutex_socket2;
2092 }
2093#if (SIM_COUNT >= 3)
2094 else if (socket_id == RIL_SOCKET_3) {
2095 fd = s_ril_param_socket3.fdCommand;
2096 writeMutexHook = &s_writeMutex_socket3;
2097 }
2098#endif
2099#if (SIM_COUNT >= 4)
2100 else if (socket_id == RIL_SOCKET_4) {
2101 fd = s_ril_param_socket4.fdCommand;
2102 writeMutexHook = &s_writeMutex_socket4;
2103 }
2104#endif
2105#endif
2106 if (fd < 0) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002107 return -1;
2108 }
2109
2110 if (dataSize > MAX_COMMAND_BYTES) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002111 RLOGE("RIL: packet larger than %u (%u)",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002112 MAX_COMMAND_BYTES, (unsigned int )dataSize);
2113
2114 return -1;
2115 }
Wink Saville7f856802009-06-09 10:23:37 -07002116
Etan Cohend3652192014-06-20 08:28:44 -07002117 pthread_mutex_lock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002118
2119 header = htonl(dataSize);
2120
2121 ret = blockingWrite(fd, (void *)&header, sizeof(header));
2122
2123 if (ret < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002124 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002125 return ret;
2126 }
2127
Kennyee1fadc2009-08-13 00:45:53 +08002128 ret = blockingWrite(fd, data, dataSize);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002129
2130 if (ret < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002131 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002132 return ret;
2133 }
2134
Etan Cohend3652192014-06-20 08:28:44 -07002135 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002136
2137 return 0;
2138}
2139
2140static int
Etan Cohend3652192014-06-20 08:28:44 -07002141sendResponse (Parcel &p, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002142 printResponse;
Etan Cohend3652192014-06-20 08:28:44 -07002143 return sendResponseRaw(p.data(), p.dataSize(), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002144}
2145
Mohamad Ayyash74f7e662014-04-18 11:43:28 -07002146/** response is an int* pointing to an array of ints */
Wink Saville7f856802009-06-09 10:23:37 -07002147
2148static int
Wink Savillef4c4d362009-04-02 01:37:03 -07002149responseInts(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002150 int numInts;
2151
2152 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002153 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002154 return RIL_ERRNO_INVALID_RESPONSE;
2155 }
2156 if (responselen % sizeof(int) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002157 RLOGE("responseInts: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002158 (int)responselen, (int)sizeof(int));
2159 return RIL_ERRNO_INVALID_RESPONSE;
2160 }
2161
2162 int *p_int = (int *) response;
2163
Mohamad Ayyash74f7e662014-04-18 11:43:28 -07002164 numInts = responselen / sizeof(int);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002165 p.writeInt32 (numInts);
2166
2167 /* each int*/
2168 startResponse;
2169 for (int i = 0 ; i < numInts ; i++) {
2170 appendPrintBuf("%s%d,", printBuf, p_int[i]);
2171 p.writeInt32(p_int[i]);
2172 }
2173 removeLastChar;
2174 closeResponse;
2175
2176 return 0;
2177}
2178
Chao Liu548a81e2015-05-14 16:13:46 -07002179// Response is an int or RIL_LastCallFailCauseInfo.
2180// Currently, only Shamu plans to use RIL_LastCallFailCauseInfo.
2181// TODO(yjl): Let all implementations use RIL_LastCallFailCauseInfo.
2182static int responseFailCause(Parcel &p, void *response, size_t responselen) {
2183 if (response == NULL && responselen != 0) {
2184 RLOGE("invalid response: NULL");
2185 return RIL_ERRNO_INVALID_RESPONSE;
2186 }
2187
2188 if (responselen == sizeof(int)) {
Sungmin Choia408c252015-07-01 16:22:46 +09002189 startResponse;
2190 int *p_int = (int *) response;
2191 appendPrintBuf("%s%d,", printBuf, p_int[0]);
2192 p.writeInt32(p_int[0]);
2193 removeLastChar;
2194 closeResponse;
Chao Liu548a81e2015-05-14 16:13:46 -07002195 } else if (responselen == sizeof(RIL_LastCallFailCauseInfo)) {
2196 startResponse;
2197 RIL_LastCallFailCauseInfo *p_fail_cause_info = (RIL_LastCallFailCauseInfo *) response;
2198 appendPrintBuf("%s[cause_code=%d,vendor_cause=%s]", printBuf, p_fail_cause_info->cause_code,
2199 p_fail_cause_info->vendor_cause);
2200 p.writeInt32(p_fail_cause_info->cause_code);
2201 writeStringToParcel(p, p_fail_cause_info->vendor_cause);
2202 removeLastChar;
2203 closeResponse;
2204 } else {
2205 RLOGE("responseFailCause: invalid response length %d expected an int or "
2206 "RIL_LastCallFailCauseInfo", (int)responselen);
2207 return RIL_ERRNO_INVALID_RESPONSE;
2208 }
2209
2210 return 0;
2211}
2212
Wink Saville43808972011-01-13 17:39:51 -08002213/** response is a char **, pointing to an array of char *'s
2214 The parcel will begin with the version */
2215static int responseStringsWithVersion(int version, Parcel &p, void *response, size_t responselen) {
2216 p.writeInt32(version);
2217 return responseStrings(p, response, responselen);
2218}
2219
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002220/** response is a char **, pointing to an array of char *'s */
Wink Savillef4c4d362009-04-02 01:37:03 -07002221static int responseStrings(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002222 int numStrings;
Wink Saville7f856802009-06-09 10:23:37 -07002223
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002224 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002225 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002226 return RIL_ERRNO_INVALID_RESPONSE;
2227 }
2228 if (responselen % sizeof(char *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002229 RLOGE("responseStrings: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002230 (int)responselen, (int)sizeof(char *));
2231 return RIL_ERRNO_INVALID_RESPONSE;
2232 }
2233
2234 if (response == NULL) {
2235 p.writeInt32 (0);
2236 } else {
2237 char **p_cur = (char **) response;
2238
2239 numStrings = responselen / sizeof(char *);
2240 p.writeInt32 (numStrings);
2241
2242 /* each string*/
2243 startResponse;
2244 for (int i = 0 ; i < numStrings ; i++) {
2245 appendPrintBuf("%s%s,", printBuf, (char*)p_cur[i]);
2246 writeStringToParcel (p, p_cur[i]);
2247 }
2248 removeLastChar;
2249 closeResponse;
2250 }
2251 return 0;
2252}
2253
2254
2255/**
Wink Saville7f856802009-06-09 10:23:37 -07002256 * NULL strings are accepted
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002257 * FIXME currently ignores responselen
2258 */
Wink Savillef4c4d362009-04-02 01:37:03 -07002259static int responseString(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002260 /* one string only */
2261 startResponse;
2262 appendPrintBuf("%s%s", printBuf, (char*)response);
2263 closeResponse;
2264
2265 writeStringToParcel(p, (const char *)response);
2266
2267 return 0;
2268}
2269
Wink Savillef4c4d362009-04-02 01:37:03 -07002270static int responseVoid(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002271 startResponse;
2272 removeLastChar;
2273 return 0;
2274}
2275
Wink Savillef4c4d362009-04-02 01:37:03 -07002276static int responseCallList(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002277 int num;
2278
2279 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002280 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002281 return RIL_ERRNO_INVALID_RESPONSE;
2282 }
2283
2284 if (responselen % sizeof (RIL_Call *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002285 RLOGE("responseCallList: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002286 (int)responselen, (int)sizeof (RIL_Call *));
2287 return RIL_ERRNO_INVALID_RESPONSE;
2288 }
2289
2290 startResponse;
2291 /* number of call info's */
2292 num = responselen / sizeof(RIL_Call *);
2293 p.writeInt32(num);
2294
2295 for (int i = 0 ; i < num ; i++) {
2296 RIL_Call *p_cur = ((RIL_Call **) response)[i];
2297 /* each call info */
2298 p.writeInt32(p_cur->state);
2299 p.writeInt32(p_cur->index);
2300 p.writeInt32(p_cur->toa);
2301 p.writeInt32(p_cur->isMpty);
2302 p.writeInt32(p_cur->isMT);
2303 p.writeInt32(p_cur->als);
2304 p.writeInt32(p_cur->isVoice);
Wink Saville1b5fd232009-04-22 14:50:00 -07002305 p.writeInt32(p_cur->isVoicePrivacy);
2306 writeStringToParcel(p, p_cur->number);
John Wangff368742009-03-24 17:56:29 -07002307 p.writeInt32(p_cur->numberPresentation);
Wink Saville1b5fd232009-04-22 14:50:00 -07002308 writeStringToParcel(p, p_cur->name);
2309 p.writeInt32(p_cur->namePresentation);
Wink Saville3a4840b2010-04-07 13:29:58 -07002310 // Remove when partners upgrade to version 3
Wink Saville74fa3882009-12-22 15:35:41 -08002311 if ((s_callbacks.version < 3) || (p_cur->uusInfo == NULL || p_cur->uusInfo->uusData == NULL)) {
2312 p.writeInt32(0); /* UUS Information is absent */
2313 } else {
2314 RIL_UUS_Info *uusInfo = p_cur->uusInfo;
2315 p.writeInt32(1); /* UUS Information is present */
2316 p.writeInt32(uusInfo->uusType);
2317 p.writeInt32(uusInfo->uusDcs);
2318 p.writeInt32(uusInfo->uusLength);
2319 p.write(uusInfo->uusData, uusInfo->uusLength);
2320 }
Wink Saville3d54e742009-05-18 18:00:44 -07002321 appendPrintBuf("%s[id=%d,%s,toa=%d,",
John Wangff368742009-03-24 17:56:29 -07002322 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002323 p_cur->index,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002324 callStateToString(p_cur->state),
Wink Saville3d54e742009-05-18 18:00:44 -07002325 p_cur->toa);
2326 appendPrintBuf("%s%s,%s,als=%d,%s,%s,",
2327 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002328 (p_cur->isMpty)?"conf":"norm",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002329 (p_cur->isMT)?"mt":"mo",
2330 p_cur->als,
2331 (p_cur->isVoice)?"voc":"nonvoc",
Wink Saville3d54e742009-05-18 18:00:44 -07002332 (p_cur->isVoicePrivacy)?"evp":"noevp");
2333 appendPrintBuf("%s%s,cli=%d,name='%s',%d]",
2334 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002335 p_cur->number,
2336 p_cur->numberPresentation,
2337 p_cur->name,
2338 p_cur->namePresentation);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002339 }
2340 removeLastChar;
2341 closeResponse;
2342
2343 return 0;
2344}
2345
Wink Savillef4c4d362009-04-02 01:37:03 -07002346static int responseSMS(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002347 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002348 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002349 return RIL_ERRNO_INVALID_RESPONSE;
2350 }
2351
2352 if (responselen != sizeof (RIL_SMS_Response) ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002353 RLOGE("invalid response length %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002354 (int)responselen, (int)sizeof (RIL_SMS_Response));
2355 return RIL_ERRNO_INVALID_RESPONSE;
2356 }
2357
2358 RIL_SMS_Response *p_cur = (RIL_SMS_Response *) response;
2359
2360 p.writeInt32(p_cur->messageRef);
2361 writeStringToParcel(p, p_cur->ackPDU);
Jaikumar Ganesh920c78f2009-06-04 10:53:15 -07002362 p.writeInt32(p_cur->errorCode);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002363
2364 startResponse;
Jaikumar Ganesh920c78f2009-06-04 10:53:15 -07002365 appendPrintBuf("%s%d,%s,%d", printBuf, p_cur->messageRef,
2366 (char*)p_cur->ackPDU, p_cur->errorCode);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002367 closeResponse;
2368
2369 return 0;
2370}
2371
Wink Savillec0114b32011-02-18 10:14:07 -08002372static int responseDataCallListV4(Parcel &p, void *response, size_t responselen)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002373{
2374 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002375 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002376 return RIL_ERRNO_INVALID_RESPONSE;
2377 }
2378
Wink Savillec0114b32011-02-18 10:14:07 -08002379 if (responselen % sizeof(RIL_Data_Call_Response_v4) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002380 RLOGE("responseDataCallListV4: invalid response length %d expected multiple of %d",
Wink Savillec0114b32011-02-18 10:14:07 -08002381 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v4));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002382 return RIL_ERRNO_INVALID_RESPONSE;
2383 }
2384
Amit Mahajan52500162014-07-29 17:36:48 -07002385 // Write version
2386 p.writeInt32(4);
2387
Wink Savillec0114b32011-02-18 10:14:07 -08002388 int num = responselen / sizeof(RIL_Data_Call_Response_v4);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002389 p.writeInt32(num);
2390
Wink Savillec0114b32011-02-18 10:14:07 -08002391 RIL_Data_Call_Response_v4 *p_cur = (RIL_Data_Call_Response_v4 *) response;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002392 startResponse;
2393 int i;
2394 for (i = 0; i < num; i++) {
2395 p.writeInt32(p_cur[i].cid);
2396 p.writeInt32(p_cur[i].active);
2397 writeStringToParcel(p, p_cur[i].type);
Wink Savillec0114b32011-02-18 10:14:07 -08002398 // apn is not used, so don't send.
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002399 writeStringToParcel(p, p_cur[i].address);
Wink Savillec0114b32011-02-18 10:14:07 -08002400 appendPrintBuf("%s[cid=%d,%s,%s,%s],", printBuf,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002401 p_cur[i].cid,
2402 (p_cur[i].active==0)?"down":"up",
2403 (char*)p_cur[i].type,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002404 (char*)p_cur[i].address);
2405 }
2406 removeLastChar;
2407 closeResponse;
2408
2409 return 0;
2410}
2411
Etan Cohend3652192014-06-20 08:28:44 -07002412static int responseDataCallListV6(Parcel &p, void *response, size_t responselen)
2413{
Amit Mahajan52500162014-07-29 17:36:48 -07002414 if (response == NULL && responselen != 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002415 RLOGE("invalid response: NULL");
2416 return RIL_ERRNO_INVALID_RESPONSE;
2417 }
2418
2419 if (responselen % sizeof(RIL_Data_Call_Response_v6) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002420 RLOGE("responseDataCallListV6: invalid response length %d expected multiple of %d",
Etan Cohend3652192014-06-20 08:28:44 -07002421 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v6));
2422 return RIL_ERRNO_INVALID_RESPONSE;
2423 }
2424
Amit Mahajan52500162014-07-29 17:36:48 -07002425 // Write version
2426 p.writeInt32(6);
2427
Etan Cohend3652192014-06-20 08:28:44 -07002428 int num = responselen / sizeof(RIL_Data_Call_Response_v6);
2429 p.writeInt32(num);
2430
2431 RIL_Data_Call_Response_v6 *p_cur = (RIL_Data_Call_Response_v6 *) response;
2432 startResponse;
2433 int i;
2434 for (i = 0; i < num; i++) {
2435 p.writeInt32((int)p_cur[i].status);
2436 p.writeInt32(p_cur[i].suggestedRetryTime);
2437 p.writeInt32(p_cur[i].cid);
2438 p.writeInt32(p_cur[i].active);
2439 writeStringToParcel(p, p_cur[i].type);
2440 writeStringToParcel(p, p_cur[i].ifname);
2441 writeStringToParcel(p, p_cur[i].addresses);
2442 writeStringToParcel(p, p_cur[i].dnses);
2443 writeStringToParcel(p, p_cur[i].gateways);
2444 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s],", printBuf,
2445 p_cur[i].status,
2446 p_cur[i].suggestedRetryTime,
2447 p_cur[i].cid,
2448 (p_cur[i].active==0)?"down":"up",
2449 (char*)p_cur[i].type,
2450 (char*)p_cur[i].ifname,
2451 (char*)p_cur[i].addresses,
2452 (char*)p_cur[i].dnses,
2453 (char*)p_cur[i].gateways);
2454 }
2455 removeLastChar;
2456 closeResponse;
2457
2458 return 0;
2459}
2460
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002461static int responseDataCallListV9(Parcel &p, void *response, size_t responselen)
2462{
2463 if (response == NULL && responselen != 0) {
2464 RLOGE("invalid response: NULL");
2465 return RIL_ERRNO_INVALID_RESPONSE;
2466 }
2467
2468 if (responselen % sizeof(RIL_Data_Call_Response_v9) != 0) {
2469 RLOGE("responseDataCallListV9: invalid response length %d expected multiple of %d",
2470 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v9));
2471 return RIL_ERRNO_INVALID_RESPONSE;
2472 }
2473
2474 // Write version
2475 p.writeInt32(10);
2476
2477 int num = responselen / sizeof(RIL_Data_Call_Response_v9);
2478 p.writeInt32(num);
2479
2480 RIL_Data_Call_Response_v9 *p_cur = (RIL_Data_Call_Response_v9 *) response;
2481 startResponse;
2482 int i;
2483 for (i = 0; i < num; i++) {
2484 p.writeInt32((int)p_cur[i].status);
2485 p.writeInt32(p_cur[i].suggestedRetryTime);
2486 p.writeInt32(p_cur[i].cid);
2487 p.writeInt32(p_cur[i].active);
2488 writeStringToParcel(p, p_cur[i].type);
2489 writeStringToParcel(p, p_cur[i].ifname);
2490 writeStringToParcel(p, p_cur[i].addresses);
2491 writeStringToParcel(p, p_cur[i].dnses);
2492 writeStringToParcel(p, p_cur[i].gateways);
2493 writeStringToParcel(p, p_cur[i].pcscf);
2494 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s],", printBuf,
2495 p_cur[i].status,
2496 p_cur[i].suggestedRetryTime,
2497 p_cur[i].cid,
2498 (p_cur[i].active==0)?"down":"up",
2499 (char*)p_cur[i].type,
2500 (char*)p_cur[i].ifname,
2501 (char*)p_cur[i].addresses,
2502 (char*)p_cur[i].dnses,
2503 (char*)p_cur[i].gateways,
2504 (char*)p_cur[i].pcscf);
2505 }
2506 removeLastChar;
2507 closeResponse;
2508
2509 return 0;
2510}
2511
Sanket Padawe4c05f352016-01-26 16:19:00 -08002512static int responseDataCallListV11(Parcel &p, void *response, size_t responselen) {
2513 if (response == NULL && responselen != 0) {
2514 RLOGE("invalid response: NULL");
2515 return RIL_ERRNO_INVALID_RESPONSE;
2516 }
2517
2518 if (responselen % sizeof(RIL_Data_Call_Response_v11) != 0) {
2519 RLOGE("invalid response length %d expected multiple of %d",
2520 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v11));
2521 return RIL_ERRNO_INVALID_RESPONSE;
2522 }
2523
2524 // Write version
2525 p.writeInt32(11);
2526
2527 int num = responselen / sizeof(RIL_Data_Call_Response_v11);
2528 p.writeInt32(num);
2529
2530 RIL_Data_Call_Response_v11 *p_cur = (RIL_Data_Call_Response_v11 *) response;
2531 startResponse;
2532 int i;
2533 for (i = 0; i < num; i++) {
2534 p.writeInt32((int)p_cur[i].status);
2535 p.writeInt32(p_cur[i].suggestedRetryTime);
2536 p.writeInt32(p_cur[i].cid);
2537 p.writeInt32(p_cur[i].active);
2538 writeStringToParcel(p, p_cur[i].type);
2539 writeStringToParcel(p, p_cur[i].ifname);
2540 writeStringToParcel(p, p_cur[i].addresses);
2541 writeStringToParcel(p, p_cur[i].dnses);
2542 writeStringToParcel(p, p_cur[i].gateways);
2543 writeStringToParcel(p, p_cur[i].pcscf);
2544 p.writeInt32(p_cur[i].mtu);
2545 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s,mtu=%d],", printBuf,
2546 p_cur[i].status,
2547 p_cur[i].suggestedRetryTime,
2548 p_cur[i].cid,
2549 (p_cur[i].active==0)?"down":"up",
2550 (char*)p_cur[i].type,
2551 (char*)p_cur[i].ifname,
2552 (char*)p_cur[i].addresses,
2553 (char*)p_cur[i].dnses,
2554 (char*)p_cur[i].gateways,
2555 (char*)p_cur[i].pcscf,
2556 p_cur[i].mtu);
2557 }
2558 removeLastChar;
2559 closeResponse;
2560
2561 return 0;
2562}
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002563
Wink Saville43808972011-01-13 17:39:51 -08002564static int responseDataCallList(Parcel &p, void *response, size_t responselen)
2565{
Sanket Padawe4c05f352016-01-26 16:19:00 -08002566 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
2567 if (s_callbacks.version < 5) {
2568 RLOGD("responseDataCallList: v4");
2569 return responseDataCallListV4(p, response, responselen);
2570 } else if (responselen % sizeof(RIL_Data_Call_Response_v6) == 0) {
2571 return responseDataCallListV6(p, response, responselen);
2572 } else if (responselen % sizeof(RIL_Data_Call_Response_v9) == 0) {
2573 return responseDataCallListV9(p, response, responselen);
2574 } else {
2575 return responseDataCallListV11(p, response, responselen);
Wink Saville43808972011-01-13 17:39:51 -08002576 }
Sanket Padawe4c05f352016-01-26 16:19:00 -08002577 } else { // RIL version >= 12
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002578 if (responselen % sizeof(RIL_Data_Call_Response_v11) != 0) {
Sanket Padawe4c05f352016-01-26 16:19:00 -08002579 RLOGE("Data structure expected is RIL_Data_Call_Response_v11");
2580 if (!isDebuggable()) {
2581 return RIL_ERRNO_INVALID_RESPONSE;
2582 } else {
2583 assert(0);
2584 }
Wink Saville43808972011-01-13 17:39:51 -08002585 }
Sanket Padawe4c05f352016-01-26 16:19:00 -08002586 return responseDataCallListV11(p, response, responselen);
Wink Saville43808972011-01-13 17:39:51 -08002587 }
Wink Saville43808972011-01-13 17:39:51 -08002588}
2589
2590static int responseSetupDataCall(Parcel &p, void *response, size_t responselen)
2591{
2592 if (s_callbacks.version < 5) {
2593 return responseStringsWithVersion(s_callbacks.version, p, response, responselen);
2594 } else {
2595 return responseDataCallList(p, response, responselen);
2596 }
2597}
2598
Wink Savillef4c4d362009-04-02 01:37:03 -07002599static int responseRaw(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002600 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002601 RLOGE("invalid response: NULL with responselen != 0");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002602 return RIL_ERRNO_INVALID_RESPONSE;
2603 }
2604
2605 // The java code reads -1 size as null byte array
2606 if (response == NULL) {
Wink Saville7f856802009-06-09 10:23:37 -07002607 p.writeInt32(-1);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002608 } else {
2609 p.writeInt32(responselen);
2610 p.write(response, responselen);
2611 }
2612
2613 return 0;
2614}
2615
2616
Wink Savillef4c4d362009-04-02 01:37:03 -07002617static int responseSIM_IO(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002618 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002619 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002620 return RIL_ERRNO_INVALID_RESPONSE;
2621 }
2622
2623 if (responselen != sizeof (RIL_SIM_IO_Response) ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002624 RLOGE("invalid response length was %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002625 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
2626 return RIL_ERRNO_INVALID_RESPONSE;
2627 }
2628
2629 RIL_SIM_IO_Response *p_cur = (RIL_SIM_IO_Response *) response;
2630 p.writeInt32(p_cur->sw1);
2631 p.writeInt32(p_cur->sw2);
2632 writeStringToParcel(p, p_cur->simResponse);
2633
2634 startResponse;
2635 appendPrintBuf("%ssw1=0x%X,sw2=0x%X,%s", printBuf, p_cur->sw1, p_cur->sw2,
2636 (char*)p_cur->simResponse);
2637 closeResponse;
2638
2639
2640 return 0;
2641}
2642
Wink Savillef4c4d362009-04-02 01:37:03 -07002643static int responseCallForwards(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002644 int num;
Wink Saville7f856802009-06-09 10:23:37 -07002645
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002646 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002647 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002648 return RIL_ERRNO_INVALID_RESPONSE;
2649 }
2650
2651 if (responselen % sizeof(RIL_CallForwardInfo *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002652 RLOGE("responseCallForwards: invalid response length %d expected multiple of %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002653 (int)responselen, (int)sizeof(RIL_CallForwardInfo *));
2654 return RIL_ERRNO_INVALID_RESPONSE;
2655 }
2656
2657 /* number of call info's */
2658 num = responselen / sizeof(RIL_CallForwardInfo *);
2659 p.writeInt32(num);
2660
2661 startResponse;
2662 for (int i = 0 ; i < num ; i++) {
2663 RIL_CallForwardInfo *p_cur = ((RIL_CallForwardInfo **) response)[i];
2664
2665 p.writeInt32(p_cur->status);
2666 p.writeInt32(p_cur->reason);
2667 p.writeInt32(p_cur->serviceClass);
2668 p.writeInt32(p_cur->toa);
2669 writeStringToParcel(p, p_cur->number);
2670 p.writeInt32(p_cur->timeSeconds);
2671 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
2672 (p_cur->status==1)?"enable":"disable",
2673 p_cur->reason, p_cur->serviceClass, p_cur->toa,
2674 (char*)p_cur->number,
2675 p_cur->timeSeconds);
2676 }
2677 removeLastChar;
2678 closeResponse;
Wink Saville7f856802009-06-09 10:23:37 -07002679
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002680 return 0;
2681}
2682
Wink Savillef4c4d362009-04-02 01:37:03 -07002683static int responseSsn(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002684 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002685 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002686 return RIL_ERRNO_INVALID_RESPONSE;
2687 }
2688
2689 if (responselen != sizeof(RIL_SuppSvcNotification)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002690 RLOGE("invalid response length was %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002691 (int)responselen, (int)sizeof (RIL_SuppSvcNotification));
2692 return RIL_ERRNO_INVALID_RESPONSE;
2693 }
2694
2695 RIL_SuppSvcNotification *p_cur = (RIL_SuppSvcNotification *) response;
2696 p.writeInt32(p_cur->notificationType);
2697 p.writeInt32(p_cur->code);
2698 p.writeInt32(p_cur->index);
2699 p.writeInt32(p_cur->type);
2700 writeStringToParcel(p, p_cur->number);
2701
2702 startResponse;
2703 appendPrintBuf("%s%s,code=%d,id=%d,type=%d,%s", printBuf,
2704 (p_cur->notificationType==0)?"mo":"mt",
2705 p_cur->code, p_cur->index, p_cur->type,
2706 (char*)p_cur->number);
2707 closeResponse;
2708
2709 return 0;
2710}
2711
Wink Saville3d54e742009-05-18 18:00:44 -07002712static int responseCellList(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002713 int num;
2714
2715 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002716 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002717 return RIL_ERRNO_INVALID_RESPONSE;
2718 }
2719
2720 if (responselen % sizeof (RIL_NeighboringCell *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002721 RLOGE("responseCellList: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002722 (int)responselen, (int)sizeof (RIL_NeighboringCell *));
2723 return RIL_ERRNO_INVALID_RESPONSE;
2724 }
2725
2726 startResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002727 /* number of records */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002728 num = responselen / sizeof(RIL_NeighboringCell *);
2729 p.writeInt32(num);
2730
2731 for (int i = 0 ; i < num ; i++) {
2732 RIL_NeighboringCell *p_cur = ((RIL_NeighboringCell **) response)[i];
2733
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002734 p.writeInt32(p_cur->rssi);
2735 writeStringToParcel (p, p_cur->cid);
2736
2737 appendPrintBuf("%s[cid=%s,rssi=%d],", printBuf,
2738 p_cur->cid, p_cur->rssi);
2739 }
2740 removeLastChar;
2741 closeResponse;
2742
2743 return 0;
2744}
2745
Wink Saville3d54e742009-05-18 18:00:44 -07002746/**
2747 * Marshall the signalInfoRecord into the parcel if it exists.
2748 */
Wink Savillea592eeb2009-05-22 13:26:36 -07002749static void marshallSignalInfoRecord(Parcel &p,
2750 RIL_CDMA_SignalInfoRecord &p_signalInfoRecord) {
Wink Saville3d54e742009-05-18 18:00:44 -07002751 p.writeInt32(p_signalInfoRecord.isPresent);
2752 p.writeInt32(p_signalInfoRecord.signalType);
2753 p.writeInt32(p_signalInfoRecord.alertPitch);
2754 p.writeInt32(p_signalInfoRecord.signal);
2755}
2756
Wink Savillea592eeb2009-05-22 13:26:36 -07002757static int responseCdmaInformationRecords(Parcel &p,
2758 void *response, size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07002759 int num;
Wink Savillea592eeb2009-05-22 13:26:36 -07002760 char* string8 = NULL;
2761 int buffer_lenght;
2762 RIL_CDMA_InformationRecord *infoRec;
Wink Saville3d54e742009-05-18 18:00:44 -07002763
2764 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002765 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002766 return RIL_ERRNO_INVALID_RESPONSE;
2767 }
2768
Wink Savillea592eeb2009-05-22 13:26:36 -07002769 if (responselen != sizeof (RIL_CDMA_InformationRecords)) {
Amit Mahajan52500162014-07-29 17:36:48 -07002770 RLOGE("responseCdmaInformationRecords: invalid response length %d expected multiple of %d\n",
Wink Savillea592eeb2009-05-22 13:26:36 -07002771 (int)responselen, (int)sizeof (RIL_CDMA_InformationRecords *));
Wink Saville3d54e742009-05-18 18:00:44 -07002772 return RIL_ERRNO_INVALID_RESPONSE;
2773 }
2774
Wink Savillea592eeb2009-05-22 13:26:36 -07002775 RIL_CDMA_InformationRecords *p_cur =
2776 (RIL_CDMA_InformationRecords *) response;
2777 num = MIN(p_cur->numberOfInfoRecs, RIL_CDMA_MAX_NUMBER_OF_INFO_RECS);
Wink Saville3d54e742009-05-18 18:00:44 -07002778
2779 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07002780 p.writeInt32(num);
Wink Saville3d54e742009-05-18 18:00:44 -07002781
Wink Savillea592eeb2009-05-22 13:26:36 -07002782 for (int i = 0 ; i < num ; i++) {
2783 infoRec = &p_cur->infoRec[i];
2784 p.writeInt32(infoRec->name);
2785 switch (infoRec->name) {
Wink Saville3d54e742009-05-18 18:00:44 -07002786 case RIL_CDMA_DISPLAY_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002787 case RIL_CDMA_EXTENDED_DISPLAY_INFO_REC:
2788 if (infoRec->rec.display.alpha_len >
2789 CDMA_ALPHA_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002790 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002791 expected not more than %d\n",
2792 (int)infoRec->rec.display.alpha_len,
2793 CDMA_ALPHA_INFO_BUFFER_LENGTH);
2794 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002795 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002796 string8 = (char*) malloc((infoRec->rec.display.alpha_len + 1)
2797 * sizeof(char) );
2798 for (int i = 0 ; i < infoRec->rec.display.alpha_len ; i++) {
2799 string8[i] = infoRec->rec.display.alpha_buf[i];
2800 }
Wink Saville43808972011-01-13 17:39:51 -08002801 string8[(int)infoRec->rec.display.alpha_len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002802 writeStringToParcel(p, (const char*)string8);
2803 free(string8);
2804 string8 = NULL;
Wink Saville3d54e742009-05-18 18:00:44 -07002805 break;
2806 case RIL_CDMA_CALLED_PARTY_NUMBER_INFO_REC:
Wink Saville3d54e742009-05-18 18:00:44 -07002807 case RIL_CDMA_CALLING_PARTY_NUMBER_INFO_REC:
Wink Saville3d54e742009-05-18 18:00:44 -07002808 case RIL_CDMA_CONNECTED_NUMBER_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002809 if (infoRec->rec.number.len > CDMA_NUMBER_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002810 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002811 expected not more than %d\n",
2812 (int)infoRec->rec.number.len,
2813 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2814 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002815 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002816 string8 = (char*) malloc((infoRec->rec.number.len + 1)
2817 * sizeof(char) );
2818 for (int i = 0 ; i < infoRec->rec.number.len; i++) {
2819 string8[i] = infoRec->rec.number.buf[i];
2820 }
Wink Saville43808972011-01-13 17:39:51 -08002821 string8[(int)infoRec->rec.number.len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002822 writeStringToParcel(p, (const char*)string8);
2823 free(string8);
2824 string8 = NULL;
2825 p.writeInt32(infoRec->rec.number.number_type);
2826 p.writeInt32(infoRec->rec.number.number_plan);
2827 p.writeInt32(infoRec->rec.number.pi);
2828 p.writeInt32(infoRec->rec.number.si);
Wink Saville3d54e742009-05-18 18:00:44 -07002829 break;
2830 case RIL_CDMA_SIGNAL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002831 p.writeInt32(infoRec->rec.signal.isPresent);
2832 p.writeInt32(infoRec->rec.signal.signalType);
2833 p.writeInt32(infoRec->rec.signal.alertPitch);
2834 p.writeInt32(infoRec->rec.signal.signal);
2835
2836 appendPrintBuf("%sisPresent=%X, signalType=%X, \
2837 alertPitch=%X, signal=%X, ",
2838 printBuf, (int)infoRec->rec.signal.isPresent,
2839 (int)infoRec->rec.signal.signalType,
2840 (int)infoRec->rec.signal.alertPitch,
2841 (int)infoRec->rec.signal.signal);
2842 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002843 break;
2844 case RIL_CDMA_REDIRECTING_NUMBER_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002845 if (infoRec->rec.redir.redirectingNumber.len >
2846 CDMA_NUMBER_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002847 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002848 expected not more than %d\n",
2849 (int)infoRec->rec.redir.redirectingNumber.len,
2850 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2851 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002852 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002853 string8 = (char*) malloc((infoRec->rec.redir.redirectingNumber
2854 .len + 1) * sizeof(char) );
2855 for (int i = 0;
2856 i < infoRec->rec.redir.redirectingNumber.len;
2857 i++) {
2858 string8[i] = infoRec->rec.redir.redirectingNumber.buf[i];
2859 }
Wink Saville43808972011-01-13 17:39:51 -08002860 string8[(int)infoRec->rec.redir.redirectingNumber.len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002861 writeStringToParcel(p, (const char*)string8);
2862 free(string8);
2863 string8 = NULL;
2864 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_type);
2865 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_plan);
2866 p.writeInt32(infoRec->rec.redir.redirectingNumber.pi);
2867 p.writeInt32(infoRec->rec.redir.redirectingNumber.si);
2868 p.writeInt32(infoRec->rec.redir.redirectingReason);
Wink Saville3d54e742009-05-18 18:00:44 -07002869 break;
2870 case RIL_CDMA_LINE_CONTROL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002871 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPolarityIncluded);
2872 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlToggle);
2873 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlReverse);
2874 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2875
2876 appendPrintBuf("%slineCtrlPolarityIncluded=%d, \
2877 lineCtrlToggle=%d, lineCtrlReverse=%d, \
2878 lineCtrlPowerDenial=%d, ", printBuf,
2879 (int)infoRec->rec.lineCtrl.lineCtrlPolarityIncluded,
2880 (int)infoRec->rec.lineCtrl.lineCtrlToggle,
2881 (int)infoRec->rec.lineCtrl.lineCtrlReverse,
2882 (int)infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2883 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002884 break;
2885 case RIL_CDMA_T53_CLIR_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002886 p.writeInt32((int)(infoRec->rec.clir.cause));
Wink Saville3d54e742009-05-18 18:00:44 -07002887
Wink Savillea592eeb2009-05-22 13:26:36 -07002888 appendPrintBuf("%scause%d", printBuf, infoRec->rec.clir.cause);
2889 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002890 break;
2891 case RIL_CDMA_T53_AUDIO_CONTROL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002892 p.writeInt32(infoRec->rec.audioCtrl.upLink);
2893 p.writeInt32(infoRec->rec.audioCtrl.downLink);
2894
2895 appendPrintBuf("%supLink=%d, downLink=%d, ", printBuf,
2896 infoRec->rec.audioCtrl.upLink,
2897 infoRec->rec.audioCtrl.downLink);
2898 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002899 break;
Wink Savillea592eeb2009-05-22 13:26:36 -07002900 case RIL_CDMA_T53_RELEASE_INFO_REC:
2901 // TODO(Moto): See David Krause, he has the answer:)
Wink Saville8eb2a122012-11-19 16:05:13 -08002902 RLOGE("RIL_CDMA_T53_RELEASE_INFO_REC: return INVALID_RESPONSE");
Wink Savillea592eeb2009-05-22 13:26:36 -07002903 return RIL_ERRNO_INVALID_RESPONSE;
2904 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08002905 RLOGE("Incorrect name value");
Wink Savillea592eeb2009-05-22 13:26:36 -07002906 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002907 }
2908 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002909 closeResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002910
Wink Savillea592eeb2009-05-22 13:26:36 -07002911 return 0;
Wink Saville3d54e742009-05-18 18:00:44 -07002912}
2913
Sanket Padawe4c05f352016-01-26 16:19:00 -08002914static void responseRilSignalStrengthV5(Parcel &p, RIL_SignalStrength_v10 *p_cur) {
2915 p.writeInt32(p_cur->GW_SignalStrength.signalStrength);
2916 p.writeInt32(p_cur->GW_SignalStrength.bitErrorRate);
2917 p.writeInt32(p_cur->CDMA_SignalStrength.dbm);
2918 p.writeInt32(p_cur->CDMA_SignalStrength.ecio);
2919 p.writeInt32(p_cur->EVDO_SignalStrength.dbm);
2920 p.writeInt32(p_cur->EVDO_SignalStrength.ecio);
2921 p.writeInt32(p_cur->EVDO_SignalStrength.signalNoiseRatio);
2922}
2923
2924static void responseRilSignalStrengthV6Extra(Parcel &p, RIL_SignalStrength_v10 *p_cur) {
2925 /*
2926 * Fixup LTE for backwards compatibility
2927 */
2928 // signalStrength: -1 -> 99
2929 if (p_cur->LTE_SignalStrength.signalStrength == -1) {
2930 p_cur->LTE_SignalStrength.signalStrength = 99;
2931 }
2932 // rsrp: -1 -> INT_MAX all other negative value to positive.
2933 // So remap here
2934 if (p_cur->LTE_SignalStrength.rsrp == -1) {
2935 p_cur->LTE_SignalStrength.rsrp = INT_MAX;
2936 } else if (p_cur->LTE_SignalStrength.rsrp < -1) {
2937 p_cur->LTE_SignalStrength.rsrp = -p_cur->LTE_SignalStrength.rsrp;
2938 }
2939 // rsrq: -1 -> INT_MAX
2940 if (p_cur->LTE_SignalStrength.rsrq == -1) {
2941 p_cur->LTE_SignalStrength.rsrq = INT_MAX;
2942 }
2943 // Not remapping rssnr is already using INT_MAX
2944
2945 // cqi: -1 -> INT_MAX
2946 if (p_cur->LTE_SignalStrength.cqi == -1) {
2947 p_cur->LTE_SignalStrength.cqi = INT_MAX;
2948 }
2949
2950 p.writeInt32(p_cur->LTE_SignalStrength.signalStrength);
2951 p.writeInt32(p_cur->LTE_SignalStrength.rsrp);
2952 p.writeInt32(p_cur->LTE_SignalStrength.rsrq);
2953 p.writeInt32(p_cur->LTE_SignalStrength.rssnr);
2954 p.writeInt32(p_cur->LTE_SignalStrength.cqi);
2955}
2956
2957static void responseRilSignalStrengthV10(Parcel &p, RIL_SignalStrength_v10 *p_cur) {
2958 responseRilSignalStrengthV5(p, p_cur);
2959 responseRilSignalStrengthV6Extra(p, p_cur);
2960 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
2961}
2962
Wink Savillea592eeb2009-05-22 13:26:36 -07002963static int responseRilSignalStrength(Parcel &p,
2964 void *response, size_t responselen) {
2965 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002966 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002967 return RIL_ERRNO_INVALID_RESPONSE;
2968 }
2969
Sanket Padawe4c05f352016-01-26 16:19:00 -08002970 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
2971 if (responselen >= sizeof (RIL_SignalStrength_v5)) {
2972 RIL_SignalStrength_v10 *p_cur = ((RIL_SignalStrength_v10 *) response);
Wink Saville3d54e742009-05-18 18:00:44 -07002973
Sanket Padawe4c05f352016-01-26 16:19:00 -08002974 responseRilSignalStrengthV5(p, p_cur);
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002975
Sanket Padawe4c05f352016-01-26 16:19:00 -08002976 if (responselen >= sizeof (RIL_SignalStrength_v6)) {
2977 responseRilSignalStrengthV6Extra(p, p_cur);
2978 if (responselen >= sizeof (RIL_SignalStrength_v10)) {
2979 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
2980 } else {
2981 p.writeInt32(INT_MAX);
Wink Saville18e4ab12013-04-07 17:31:04 -07002982 }
Etan Cohend3652192014-06-20 08:28:44 -07002983 } else {
Sanket Padawe4c05f352016-01-26 16:19:00 -08002984 p.writeInt32(99);
2985 p.writeInt32(INT_MAX);
2986 p.writeInt32(INT_MAX);
2987 p.writeInt32(INT_MAX);
2988 p.writeInt32(INT_MAX);
Etan Cohend3652192014-06-20 08:28:44 -07002989 p.writeInt32(INT_MAX);
2990 }
Wink Savillec0114b32011-02-18 10:14:07 -08002991 } else {
Sanket Padawe4c05f352016-01-26 16:19:00 -08002992 RLOGE("invalid response length");
2993 return RIL_ERRNO_INVALID_RESPONSE;
Wink Savillec0114b32011-02-18 10:14:07 -08002994 }
Sanket Padawe4c05f352016-01-26 16:19:00 -08002995 } else { // RIL version >= 12
2996 if (responselen % sizeof(RIL_SignalStrength_v10) != 0) {
2997 RLOGE("Data structure expected is RIL_SignalStrength_v10");
2998 if (!isDebuggable()) {
2999 return RIL_ERRNO_INVALID_RESPONSE;
3000 } else {
3001 assert(0);
3002 }
3003 }
3004 RIL_SignalStrength_v10 *p_cur = ((RIL_SignalStrength_v10 *) response);
3005 responseRilSignalStrengthV10(p, p_cur);
Wink Saville3d54e742009-05-18 18:00:44 -07003006 }
Sanket Padawe4c05f352016-01-26 16:19:00 -08003007 startResponse;
3008 appendPrintBuf("%s[signalStrength=%d,bitErrorRate=%d,\
3009 CDMA_SS.dbm=%d,CDMA_SSecio=%d,\
3010 EVDO_SS.dbm=%d,EVDO_SS.ecio=%d,\
3011 EVDO_SS.signalNoiseRatio=%d,\
3012 LTE_SS.signalStrength=%d,LTE_SS.rsrp=%d,LTE_SS.rsrq=%d,\
3013 LTE_SS.rssnr=%d,LTE_SS.cqi=%d,TDSCDMA_SS.rscp=%d]",
3014 printBuf,
3015 p_cur->GW_SignalStrength.signalStrength,
3016 p_cur->GW_SignalStrength.bitErrorRate,
3017 p_cur->CDMA_SignalStrength.dbm,
3018 p_cur->CDMA_SignalStrength.ecio,
3019 p_cur->EVDO_SignalStrength.dbm,
3020 p_cur->EVDO_SignalStrength.ecio,
3021 p_cur->EVDO_SignalStrength.signalNoiseRatio,
3022 p_cur->LTE_SignalStrength.signalStrength,
3023 p_cur->LTE_SignalStrength.rsrp,
3024 p_cur->LTE_SignalStrength.rsrq,
3025 p_cur->LTE_SignalStrength.rssnr,
3026 p_cur->LTE_SignalStrength.cqi,
3027 p_cur->TD_SCDMA_SignalStrength.rscp);
3028 closeResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07003029 return 0;
3030}
3031
3032static int responseCallRing(Parcel &p, void *response, size_t responselen) {
3033 if ((response == NULL) || (responselen == 0)) {
3034 return responseVoid(p, response, responselen);
3035 } else {
3036 return responseCdmaSignalInfoRecord(p, response, responselen);
3037 }
3038}
3039
3040static int responseCdmaSignalInfoRecord(Parcel &p, void *response, size_t responselen) {
3041 if (response == NULL || responselen == 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003042 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07003043 return RIL_ERRNO_INVALID_RESPONSE;
3044 }
3045
3046 if (responselen != sizeof (RIL_CDMA_SignalInfoRecord)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003047 RLOGE("invalid response length %d expected sizeof (RIL_CDMA_SignalInfoRecord) of %d\n",
Wink Saville3d54e742009-05-18 18:00:44 -07003048 (int)responselen, (int)sizeof (RIL_CDMA_SignalInfoRecord));
3049 return RIL_ERRNO_INVALID_RESPONSE;
3050 }
3051
3052 startResponse;
3053
3054 RIL_CDMA_SignalInfoRecord *p_cur = ((RIL_CDMA_SignalInfoRecord *) response);
3055 marshallSignalInfoRecord(p, *p_cur);
3056
3057 appendPrintBuf("%s[isPresent=%d,signalType=%d,alertPitch=%d\
3058 signal=%d]",
3059 printBuf,
3060 p_cur->isPresent,
3061 p_cur->signalType,
3062 p_cur->alertPitch,
3063 p_cur->signal);
3064
3065 closeResponse;
3066 return 0;
3067}
3068
Wink Savillea592eeb2009-05-22 13:26:36 -07003069static int responseCdmaCallWaiting(Parcel &p, void *response,
3070 size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07003071 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003072 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07003073 return RIL_ERRNO_INVALID_RESPONSE;
3074 }
3075
Wink Savillec0114b32011-02-18 10:14:07 -08003076 if (responselen < sizeof(RIL_CDMA_CallWaiting_v6)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003077 RLOGW("Upgrade to ril version %d\n", RIL_VERSION);
Wink Savillec0114b32011-02-18 10:14:07 -08003078 }
3079
3080 RIL_CDMA_CallWaiting_v6 *p_cur = ((RIL_CDMA_CallWaiting_v6 *) response);
3081
3082 writeStringToParcel(p, p_cur->number);
3083 p.writeInt32(p_cur->numberPresentation);
3084 writeStringToParcel(p, p_cur->name);
3085 marshallSignalInfoRecord(p, p_cur->signalInfoRecord);
3086
Sanket Padawe4c05f352016-01-26 16:19:00 -08003087 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
3088 if (responselen >= sizeof(RIL_CDMA_CallWaiting_v6)) {
3089 p.writeInt32(p_cur->number_type);
3090 p.writeInt32(p_cur->number_plan);
3091 } else {
3092 p.writeInt32(0);
3093 p.writeInt32(0);
3094 }
3095 } else { // RIL version >= 12
3096 if (responselen % sizeof(RIL_CDMA_CallWaiting_v6) != 0) {
3097 RLOGE("Data structure expected is RIL_CDMA_CallWaiting_v6");
3098 if (!isDebuggable()) {
3099 return RIL_ERRNO_INVALID_RESPONSE;
3100 } else {
3101 assert(0);
3102 }
3103 }
Wink Savillec0114b32011-02-18 10:14:07 -08003104 p.writeInt32(p_cur->number_type);
3105 p.writeInt32(p_cur->number_plan);
Wink Saville3d54e742009-05-18 18:00:44 -07003106 }
3107
3108 startResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07003109 appendPrintBuf("%snumber=%s,numberPresentation=%d, name=%s,\
3110 signalInfoRecord[isPresent=%d,signalType=%d,alertPitch=%d\
Wink Savillec0114b32011-02-18 10:14:07 -08003111 signal=%d,number_type=%d,number_plan=%d]",
Wink Saville3d54e742009-05-18 18:00:44 -07003112 printBuf,
3113 p_cur->number,
3114 p_cur->numberPresentation,
3115 p_cur->name,
3116 p_cur->signalInfoRecord.isPresent,
3117 p_cur->signalInfoRecord.signalType,
3118 p_cur->signalInfoRecord.alertPitch,
Wink Savillec0114b32011-02-18 10:14:07 -08003119 p_cur->signalInfoRecord.signal,
3120 p_cur->number_type,
3121 p_cur->number_plan);
Wink Saville3d54e742009-05-18 18:00:44 -07003122 closeResponse;
3123
3124 return 0;
3125}
3126
Sanket Padawe4c05f352016-01-26 16:19:00 -08003127static void responseSimRefreshV7(Parcel &p, void *response) {
3128 RIL_SimRefreshResponse_v7 *p_cur = ((RIL_SimRefreshResponse_v7 *) response);
3129 p.writeInt32(p_cur->result);
3130 p.writeInt32(p_cur->ef_id);
3131 writeStringToParcel(p, p_cur->aid);
3132
3133 appendPrintBuf("%sresult=%d, ef_id=%d, aid=%s",
3134 printBuf,
3135 p_cur->result,
3136 p_cur->ef_id,
3137 p_cur->aid);
3138
3139}
3140
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003141static int responseSimRefresh(Parcel &p, void *response, size_t responselen) {
3142 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003143 RLOGE("responseSimRefresh: invalid response: NULL");
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003144 return RIL_ERRNO_INVALID_RESPONSE;
3145 }
3146
3147 startResponse;
Sanket Padawe4c05f352016-01-26 16:19:00 -08003148 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
3149 if (s_callbacks.version == 7) {
3150 responseSimRefreshV7(p, response);
3151 } else {
3152 int *p_cur = ((int *) response);
3153 p.writeInt32(p_cur[0]);
3154 p.writeInt32(p_cur[1]);
3155 writeStringToParcel(p, NULL);
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003156
Sanket Padawe4c05f352016-01-26 16:19:00 -08003157 appendPrintBuf("%sresult=%d, ef_id=%d",
3158 printBuf,
3159 p_cur[0],
3160 p_cur[1]);
3161 }
3162 } else { // RIL version >= 12
3163 if (responselen % sizeof(RIL_SimRefreshResponse_v7) != 0) {
3164 RLOGE("Data structure expected is RIL_SimRefreshResponse_v7");
3165 if (!isDebuggable()) {
3166 return RIL_ERRNO_INVALID_RESPONSE;
3167 } else {
3168 assert(0);
3169 }
3170 }
3171 responseSimRefreshV7(p, response);
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003172
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003173 }
3174 closeResponse;
3175
3176 return 0;
3177}
3178
Wink Saville8a9e0212013-04-09 12:11:38 -07003179static int responseCellInfoList(Parcel &p, void *response, size_t responselen)
3180{
3181 if (response == NULL && responselen != 0) {
3182 RLOGE("invalid response: NULL");
3183 return RIL_ERRNO_INVALID_RESPONSE;
3184 }
3185
3186 if (responselen % sizeof(RIL_CellInfo) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07003187 RLOGE("responseCellInfoList: invalid response length %d expected multiple of %d",
Wink Saville8a9e0212013-04-09 12:11:38 -07003188 (int)responselen, (int)sizeof(RIL_CellInfo));
3189 return RIL_ERRNO_INVALID_RESPONSE;
3190 }
3191
3192 int num = responselen / sizeof(RIL_CellInfo);
3193 p.writeInt32(num);
3194
3195 RIL_CellInfo *p_cur = (RIL_CellInfo *) response;
3196 startResponse;
3197 int i;
3198 for (i = 0; i < num; i++) {
3199 appendPrintBuf("%s[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", printBuf, i,
3200 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
3201 p.writeInt32((int)p_cur->cellInfoType);
3202 p.writeInt32(p_cur->registered);
3203 p.writeInt32(p_cur->timeStampType);
3204 p.writeInt64(p_cur->timeStamp);
3205 switch(p_cur->cellInfoType) {
3206 case RIL_CELL_INFO_TYPE_GSM: {
Wink Savillec57b3eb2013-04-17 12:51:41 -07003207 appendPrintBuf("%s GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,", printBuf,
Wink Saville8a9e0212013-04-09 12:11:38 -07003208 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
3209 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
3210 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
Wink Savillec57b3eb2013-04-17 12:51:41 -07003211 p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3212 appendPrintBuf("%s gsmSS: ss=%d,ber=%d],", printBuf,
Wink Saville8a9e0212013-04-09 12:11:38 -07003213 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
3214 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3215
3216 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
3217 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
3218 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
3219 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
Wink Saville8a9e0212013-04-09 12:11:38 -07003220 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
3221 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3222 break;
3223 }
Wink Savillec57b3eb2013-04-17 12:51:41 -07003224 case RIL_CELL_INFO_TYPE_WCDMA: {
3225 appendPrintBuf("%s WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,", printBuf,
3226 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
3227 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
3228 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
3229 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
3230 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3231 appendPrintBuf("%s wcdmaSS: ss=%d,ber=%d],", printBuf,
3232 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
3233 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3234
3235 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
3236 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
3237 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
3238 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
3239 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3240 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
3241 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3242 break;
3243 }
Wink Saville8a9e0212013-04-09 12:11:38 -07003244 case RIL_CELL_INFO_TYPE_CDMA: {
3245 appendPrintBuf("%s CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d", printBuf,
3246 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
3247 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
3248 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
3249 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
3250 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3251
3252 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
3253 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
3254 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
3255 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
3256 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3257
3258 appendPrintBuf("%s cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d", printBuf,
3259 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
3260 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
3261 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
3262 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
3263 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3264
3265 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
3266 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
3267 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
3268 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
3269 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3270 break;
3271 }
3272 case RIL_CELL_INFO_TYPE_LTE: {
3273 appendPrintBuf("%s LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d", printBuf,
3274 p_cur->CellInfo.lte.cellIdentityLte.mcc,
3275 p_cur->CellInfo.lte.cellIdentityLte.mnc,
3276 p_cur->CellInfo.lte.cellIdentityLte.ci,
3277 p_cur->CellInfo.lte.cellIdentityLte.pci,
3278 p_cur->CellInfo.lte.cellIdentityLte.tac);
3279
3280 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
3281 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
3282 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
3283 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
3284 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
3285
3286 appendPrintBuf("%s lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d", printBuf,
3287 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
3288 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
3289 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
3290 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
3291 p_cur->CellInfo.lte.signalStrengthLte.cqi,
3292 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3293 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
3294 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
3295 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
3296 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
3297 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
3298 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3299 break;
3300 }
Etan Cohend3652192014-06-20 08:28:44 -07003301 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
3302 appendPrintBuf("%s TDSCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,cpid=%d,", printBuf,
3303 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc,
3304 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc,
3305 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac,
3306 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid,
3307 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3308 appendPrintBuf("%s tdscdmaSS: rscp=%d],", printBuf,
3309 p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3310
3311 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
3312 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
3313 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
3314 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
3315 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3316 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3317 break;
3318 }
Wink Saville8a9e0212013-04-09 12:11:38 -07003319 }
3320 p_cur += 1;
3321 }
3322 removeLastChar;
3323 closeResponse;
3324
3325 return 0;
3326}
3327
Etan Cohend3652192014-06-20 08:28:44 -07003328static int responseHardwareConfig(Parcel &p, void *response, size_t responselen)
3329{
3330 if (response == NULL && responselen != 0) {
3331 RLOGE("invalid response: NULL");
3332 return RIL_ERRNO_INVALID_RESPONSE;
3333 }
3334
3335 if (responselen % sizeof(RIL_HardwareConfig) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07003336 RLOGE("responseHardwareConfig: invalid response length %d expected multiple of %d",
Etan Cohend3652192014-06-20 08:28:44 -07003337 (int)responselen, (int)sizeof(RIL_HardwareConfig));
3338 return RIL_ERRNO_INVALID_RESPONSE;
3339 }
3340
3341 int num = responselen / sizeof(RIL_HardwareConfig);
3342 int i;
3343 RIL_HardwareConfig *p_cur = (RIL_HardwareConfig *) response;
3344
3345 p.writeInt32(num);
3346
3347 startResponse;
3348 for (i = 0; i < num; i++) {
3349 switch (p_cur[i].type) {
3350 case RIL_HARDWARE_CONFIG_MODEM: {
3351 writeStringToParcel(p, p_cur[i].uuid);
3352 p.writeInt32((int)p_cur[i].state);
3353 p.writeInt32(p_cur[i].cfg.modem.rat);
3354 p.writeInt32(p_cur[i].cfg.modem.maxVoice);
3355 p.writeInt32(p_cur[i].cfg.modem.maxData);
3356 p.writeInt32(p_cur[i].cfg.modem.maxStandby);
3357
3358 appendPrintBuf("%s modem: uuid=%s,state=%d,rat=%08x,maxV=%d,maxD=%d,maxS=%d", printBuf,
3359 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.modem.rat,
3360 p_cur[i].cfg.modem.maxVoice, p_cur[i].cfg.modem.maxData, p_cur[i].cfg.modem.maxStandby);
3361 break;
3362 }
3363 case RIL_HARDWARE_CONFIG_SIM: {
3364 writeStringToParcel(p, p_cur[i].uuid);
3365 p.writeInt32((int)p_cur[i].state);
3366 writeStringToParcel(p, p_cur[i].cfg.sim.modemUuid);
3367
3368 appendPrintBuf("%s sim: uuid=%s,state=%d,modem-uuid=%s", printBuf,
3369 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.sim.modemUuid);
3370 break;
3371 }
3372 }
3373 }
3374 removeLastChar;
3375 closeResponse;
3376 return 0;
3377}
3378
Wink Saville8b4e4f72014-10-17 15:01:45 -07003379static int responseRadioCapability(Parcel &p, void *response, size_t responselen) {
3380 if (response == NULL) {
3381 RLOGE("invalid response: NULL");
3382 return RIL_ERRNO_INVALID_RESPONSE;
3383 }
3384
3385 if (responselen != sizeof (RIL_RadioCapability) ) {
3386 RLOGE("invalid response length was %d expected %d",
3387 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3388 return RIL_ERRNO_INVALID_RESPONSE;
3389 }
3390
3391 RIL_RadioCapability *p_cur = (RIL_RadioCapability *) response;
3392 p.writeInt32(p_cur->version);
3393 p.writeInt32(p_cur->session);
3394 p.writeInt32(p_cur->phase);
3395 p.writeInt32(p_cur->rat);
3396 writeStringToParcel(p, p_cur->logicalModemUuid);
3397 p.writeInt32(p_cur->status);
3398
3399 startResponse;
3400 appendPrintBuf("%s[version=%d,session=%d,phase=%d,\
Legler Wu8caf06f2014-10-29 14:02:14 +08003401 rat=%s,logicalModemUuid=%s,status=%d]",
Wink Saville8b4e4f72014-10-17 15:01:45 -07003402 printBuf,
3403 p_cur->version,
3404 p_cur->session,
3405 p_cur->phase,
3406 p_cur->rat,
Legler Wu8caf06f2014-10-29 14:02:14 +08003407 p_cur->logicalModemUuid,
Wink Saville8b4e4f72014-10-17 15:01:45 -07003408 p_cur->status);
3409 closeResponse;
3410 return 0;
3411}
3412
Amit Mahajan54563d32014-11-22 00:54:49 +00003413static int responseSSData(Parcel &p, void *response, size_t responselen) {
3414 RLOGD("In responseSSData");
3415 int num;
3416
3417 if (response == NULL && responselen != 0) {
3418 RLOGE("invalid response length was %d expected %d",
3419 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3420 return RIL_ERRNO_INVALID_RESPONSE;
3421 }
3422
3423 if (responselen != sizeof(RIL_StkCcUnsolSsResponse)) {
3424 RLOGE("invalid response length %d, expected %d",
3425 (int)responselen, (int)sizeof(RIL_StkCcUnsolSsResponse));
3426 return RIL_ERRNO_INVALID_RESPONSE;
3427 }
3428
3429 startResponse;
3430 RIL_StkCcUnsolSsResponse *p_cur = (RIL_StkCcUnsolSsResponse *) response;
3431 p.writeInt32(p_cur->serviceType);
3432 p.writeInt32(p_cur->requestType);
3433 p.writeInt32(p_cur->teleserviceType);
3434 p.writeInt32(p_cur->serviceClass);
3435 p.writeInt32(p_cur->result);
3436
3437 if (isServiceTypeCfQuery(p_cur->serviceType, p_cur->requestType)) {
3438 RLOGD("responseSSData CF type, num of Cf elements %d", p_cur->cfData.numValidIndexes);
3439 if (p_cur->cfData.numValidIndexes > NUM_SERVICE_CLASSES) {
3440 RLOGE("numValidIndexes is greater than max value %d, "
3441 "truncating it to max value", NUM_SERVICE_CLASSES);
3442 p_cur->cfData.numValidIndexes = NUM_SERVICE_CLASSES;
3443 }
3444 /* number of call info's */
3445 p.writeInt32(p_cur->cfData.numValidIndexes);
3446
3447 for (int i = 0; i < p_cur->cfData.numValidIndexes; i++) {
3448 RIL_CallForwardInfo cf = p_cur->cfData.cfInfo[i];
3449
3450 p.writeInt32(cf.status);
3451 p.writeInt32(cf.reason);
3452 p.writeInt32(cf.serviceClass);
3453 p.writeInt32(cf.toa);
3454 writeStringToParcel(p, cf.number);
3455 p.writeInt32(cf.timeSeconds);
3456 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
3457 (cf.status==1)?"enable":"disable", cf.reason, cf.serviceClass, cf.toa,
3458 (char*)cf.number, cf.timeSeconds);
3459 RLOGD("Data: %d,reason=%d,cls=%d,toa=%d,num=%s,tout=%d],", cf.status,
3460 cf.reason, cf.serviceClass, cf.toa, (char*)cf.number, cf.timeSeconds);
3461 }
3462 } else {
3463 p.writeInt32 (SS_INFO_MAX);
3464
3465 /* each int*/
3466 for (int i = 0; i < SS_INFO_MAX; i++) {
3467 appendPrintBuf("%s%d,", printBuf, p_cur->ssInfo[i]);
3468 RLOGD("Data: %d",p_cur->ssInfo[i]);
3469 p.writeInt32(p_cur->ssInfo[i]);
3470 }
3471 }
3472 removeLastChar;
3473 closeResponse;
3474
3475 return 0;
3476}
3477
3478static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType) {
3479 if ((reqType == SS_INTERROGATION) &&
3480 (serType == SS_CFU ||
3481 serType == SS_CF_BUSY ||
3482 serType == SS_CF_NO_REPLY ||
3483 serType == SS_CF_NOT_REACHABLE ||
3484 serType == SS_CF_ALL ||
3485 serType == SS_CF_ALL_CONDITIONAL)) {
3486 return true;
3487 }
3488 return false;
3489}
3490
Wink Saville3d54e742009-05-18 18:00:44 -07003491static void triggerEvLoop() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003492 int ret;
3493 if (!pthread_equal(pthread_self(), s_tid_dispatch)) {
3494 /* trigger event loop to wakeup. No reason to do this,
3495 * if we're in the event loop thread */
3496 do {
3497 ret = write (s_fdWakeupWrite, " ", 1);
3498 } while (ret < 0 && errno == EINTR);
3499 }
3500}
3501
Wink Saville3d54e742009-05-18 18:00:44 -07003502static void rilEventAddWakeup(struct ril_event *ev) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003503 ril_event_add(ev);
3504 triggerEvLoop();
3505}
3506
Wink Savillefd729372011-02-22 16:19:39 -08003507static void sendSimStatusAppInfo(Parcel &p, int num_apps, RIL_AppStatus appStatus[]) {
3508 p.writeInt32(num_apps);
3509 startResponse;
3510 for (int i = 0; i < num_apps; i++) {
3511 p.writeInt32(appStatus[i].app_type);
3512 p.writeInt32(appStatus[i].app_state);
3513 p.writeInt32(appStatus[i].perso_substate);
3514 writeStringToParcel(p, (const char*)(appStatus[i].aid_ptr));
3515 writeStringToParcel(p, (const char*)
3516 (appStatus[i].app_label_ptr));
3517 p.writeInt32(appStatus[i].pin1_replaced);
3518 p.writeInt32(appStatus[i].pin1);
3519 p.writeInt32(appStatus[i].pin2);
3520 appendPrintBuf("%s[app_type=%d,app_state=%d,perso_substate=%d,\
3521 aid_ptr=%s,app_label_ptr=%s,pin1_replaced=%d,pin1=%d,pin2=%d],",
3522 printBuf,
3523 appStatus[i].app_type,
3524 appStatus[i].app_state,
3525 appStatus[i].perso_substate,
3526 appStatus[i].aid_ptr,
3527 appStatus[i].app_label_ptr,
3528 appStatus[i].pin1_replaced,
3529 appStatus[i].pin1,
3530 appStatus[i].pin2);
3531 }
3532 closeResponse;
3533}
3534
Sanket Padawe4c05f352016-01-26 16:19:00 -08003535static void responseSimStatusV5(Parcel &p, void *response) {
3536 RIL_CardStatus_v5 *p_cur = ((RIL_CardStatus_v5 *) response);
3537
3538 p.writeInt32(p_cur->card_state);
3539 p.writeInt32(p_cur->universal_pin_state);
3540 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3541 p.writeInt32(p_cur->cdma_subscription_app_index);
3542
3543 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
3544}
3545
3546static void responseSimStatusV6(Parcel &p, void *response) {
3547 RIL_CardStatus_v6 *p_cur = ((RIL_CardStatus_v6 *) response);
3548
3549 p.writeInt32(p_cur->card_state);
3550 p.writeInt32(p_cur->universal_pin_state);
3551 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3552 p.writeInt32(p_cur->cdma_subscription_app_index);
3553 p.writeInt32(p_cur->ims_subscription_app_index);
3554
3555 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
3556}
3557
Wink Savillef4c4d362009-04-02 01:37:03 -07003558static int responseSimStatus(Parcel &p, void *response, size_t responselen) {
3559 int i;
3560
3561 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003562 RLOGE("invalid response: NULL");
Wink Savillef4c4d362009-04-02 01:37:03 -07003563 return RIL_ERRNO_INVALID_RESPONSE;
3564 }
3565
Sanket Padawe4c05f352016-01-26 16:19:00 -08003566 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
3567 if (responselen == sizeof (RIL_CardStatus_v6)) {
3568 responseSimStatusV6(p, response);
3569 } else if (responselen == sizeof (RIL_CardStatus_v5)) {
3570 responseSimStatusV5(p, response);
3571 } else {
3572 RLOGE("responseSimStatus: A RilCardStatus_v6 or _v5 expected\n");
3573 return RIL_ERRNO_INVALID_RESPONSE;
3574 }
3575 } else { // RIL version >= 12
3576 if (responselen % sizeof(RIL_CardStatus_v6) != 0) {
3577 RLOGE("Data structure expected is RIL_CardStatus_v6");
3578 if (!isDebuggable()) {
3579 return RIL_ERRNO_INVALID_RESPONSE;
3580 } else {
3581 assert(0);
3582 }
3583 }
3584 responseSimStatusV6(p, response);
Wink Savillef4c4d362009-04-02 01:37:03 -07003585 }
Wink Savillef4c4d362009-04-02 01:37:03 -07003586
3587 return 0;
Wink Saville3d54e742009-05-18 18:00:44 -07003588}
Wink Savillef4c4d362009-04-02 01:37:03 -07003589
Wink Savillea592eeb2009-05-22 13:26:36 -07003590static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3591 int num = responselen / sizeof(RIL_GSM_BroadcastSmsConfigInfo *);
Wink Savillef4c4d362009-04-02 01:37:03 -07003592 p.writeInt32(num);
3593
Wink Savillef4c4d362009-04-02 01:37:03 -07003594 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07003595 RIL_GSM_BroadcastSmsConfigInfo **p_cur =
3596 (RIL_GSM_BroadcastSmsConfigInfo **) response;
3597 for (int i = 0; i < num; i++) {
3598 p.writeInt32(p_cur[i]->fromServiceId);
3599 p.writeInt32(p_cur[i]->toServiceId);
3600 p.writeInt32(p_cur[i]->fromCodeScheme);
3601 p.writeInt32(p_cur[i]->toCodeScheme);
3602 p.writeInt32(p_cur[i]->selected);
3603
3604 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId=%d, \
3605 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]",
3606 printBuf, i, p_cur[i]->fromServiceId, p_cur[i]->toServiceId,
3607 p_cur[i]->fromCodeScheme, p_cur[i]->toCodeScheme,
3608 p_cur[i]->selected);
3609 }
Wink Savillef4c4d362009-04-02 01:37:03 -07003610 closeResponse;
3611
3612 return 0;
3613}
3614
Wink Savillea592eeb2009-05-22 13:26:36 -07003615static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3616 RIL_CDMA_BroadcastSmsConfigInfo **p_cur =
3617 (RIL_CDMA_BroadcastSmsConfigInfo **) response;
Wink Savillef4c4d362009-04-02 01:37:03 -07003618
Wink Savillea592eeb2009-05-22 13:26:36 -07003619 int num = responselen / sizeof (RIL_CDMA_BroadcastSmsConfigInfo *);
3620 p.writeInt32(num);
Wink Savillef4c4d362009-04-02 01:37:03 -07003621
3622 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07003623 for (int i = 0 ; i < num ; i++ ) {
3624 p.writeInt32(p_cur[i]->service_category);
3625 p.writeInt32(p_cur[i]->language);
3626 p.writeInt32(p_cur[i]->selected);
Wink Savillef4c4d362009-04-02 01:37:03 -07003627
Wink Savillea592eeb2009-05-22 13:26:36 -07003628 appendPrintBuf("%s [%d: srvice_category=%d, language =%d, \
3629 selected =%d], ",
3630 printBuf, i, p_cur[i]->service_category, p_cur[i]->language,
3631 p_cur[i]->selected);
Wink Savillef5903df2009-04-24 11:54:14 -07003632 }
Wink Savillea592eeb2009-05-22 13:26:36 -07003633 closeResponse;
Wink Savillef5903df2009-04-24 11:54:14 -07003634
Wink Savillef4c4d362009-04-02 01:37:03 -07003635 return 0;
3636}
3637
3638static int responseCdmaSms(Parcel &p, void *response, size_t responselen) {
3639 int num;
3640 int digitCount;
3641 int digitLimit;
3642 uint8_t uct;
3643 void* dest;
3644
Wink Saville8eb2a122012-11-19 16:05:13 -08003645 RLOGD("Inside responseCdmaSms");
Wink Savillef5903df2009-04-24 11:54:14 -07003646
Wink Savillef4c4d362009-04-02 01:37:03 -07003647 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003648 RLOGE("invalid response: NULL");
Wink Savillef4c4d362009-04-02 01:37:03 -07003649 return RIL_ERRNO_INVALID_RESPONSE;
3650 }
3651
Wink Savillef5903df2009-04-24 11:54:14 -07003652 if (responselen != sizeof(RIL_CDMA_SMS_Message)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003653 RLOGE("invalid response length was %d expected %d",
Wink Savillef5903df2009-04-24 11:54:14 -07003654 (int)responselen, (int)sizeof(RIL_CDMA_SMS_Message));
Wink Savillef4c4d362009-04-02 01:37:03 -07003655 return RIL_ERRNO_INVALID_RESPONSE;
3656 }
3657
3658 RIL_CDMA_SMS_Message *p_cur = (RIL_CDMA_SMS_Message *) response;
3659 p.writeInt32(p_cur->uTeleserviceID);
3660 p.write(&(p_cur->bIsServicePresent),sizeof(uct));
3661 p.writeInt32(p_cur->uServicecategory);
3662 p.writeInt32(p_cur->sAddress.digit_mode);
3663 p.writeInt32(p_cur->sAddress.number_mode);
3664 p.writeInt32(p_cur->sAddress.number_type);
3665 p.writeInt32(p_cur->sAddress.number_plan);
3666 p.write(&(p_cur->sAddress.number_of_digits), sizeof(uct));
3667 digitLimit= MIN((p_cur->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
3668 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3669 p.write(&(p_cur->sAddress.digits[digitCount]),sizeof(uct));
3670 }
3671
3672 p.writeInt32(p_cur->sSubAddress.subaddressType);
3673 p.write(&(p_cur->sSubAddress.odd),sizeof(uct));
3674 p.write(&(p_cur->sSubAddress.number_of_digits),sizeof(uct));
3675 digitLimit= MIN((p_cur->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
3676 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3677 p.write(&(p_cur->sSubAddress.digits[digitCount]),sizeof(uct));
3678 }
3679
3680 digitLimit= MIN((p_cur->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
3681 p.writeInt32(p_cur->uBearerDataLen);
3682 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3683 p.write(&(p_cur->aBearerData[digitCount]), sizeof(uct));
3684 }
3685
3686 startResponse;
3687 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
Wink Saville1b5fd232009-04-22 14:50:00 -07003688 sAddress.digit_mode=%d, sAddress.number_mode=%d, sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07003689 printBuf, p_cur->uTeleserviceID,p_cur->bIsServicePresent,p_cur->uServicecategory,
3690 p_cur->sAddress.digit_mode, p_cur->sAddress.number_mode,p_cur->sAddress.number_type);
3691 closeResponse;
3692
3693 return 0;
3694}
3695
Wink Savillec29360a2014-07-13 05:17:28 -07003696static int responseDcRtInfo(Parcel &p, void *response, size_t responselen)
3697{
3698 int num = responselen / sizeof(RIL_DcRtInfo);
3699 if ((responselen % sizeof(RIL_DcRtInfo) != 0) || (num != 1)) {
Amit Mahajan52500162014-07-29 17:36:48 -07003700 RLOGE("responseDcRtInfo: invalid response length %d expected multiple of %d",
Wink Savillec29360a2014-07-13 05:17:28 -07003701 (int)responselen, (int)sizeof(RIL_DcRtInfo));
3702 return RIL_ERRNO_INVALID_RESPONSE;
3703 }
3704
3705 startResponse;
3706 RIL_DcRtInfo *pDcRtInfo = (RIL_DcRtInfo *)response;
3707 p.writeInt64(pDcRtInfo->time);
3708 p.writeInt32(pDcRtInfo->powerState);
3709 appendPrintBuf("%s[time=%d,powerState=%d]", printBuf,
3710 pDcRtInfo->time,
3711 pDcRtInfo->powerState);
3712 closeResponse;
3713
3714 return 0;
3715}
3716
fengluf7408292015-04-14 14:53:55 -07003717static int responseLceStatus(Parcel &p, void *response, size_t responselen) {
3718 if (response == NULL || responselen != sizeof(RIL_LceStatusInfo)) {
3719 if (response == NULL) {
3720 RLOGE("invalid response: NULL");
3721 }
3722 else {
3723 RLOGE("responseLceStatus: invalid response length %d expecting len: d%",
3724 sizeof(RIL_LceStatusInfo), responselen);
3725 }
3726 return RIL_ERRNO_INVALID_RESPONSE;
3727 }
3728
3729 RIL_LceStatusInfo *p_cur = (RIL_LceStatusInfo *)response;
3730 p.write((void *)p_cur, 1); // p_cur->lce_status takes one byte.
3731 p.writeInt32(p_cur->actual_interval_ms);
3732
3733 startResponse;
3734 appendPrintBuf("LCE Status: %d, actual_interval_ms: %d",
3735 p_cur->lce_status, p_cur->actual_interval_ms);
3736 closeResponse;
3737
3738 return 0;
3739}
3740
3741static int responseLceData(Parcel &p, void *response, size_t responselen) {
3742 if (response == NULL || responselen != sizeof(RIL_LceDataInfo)) {
3743 if (response == NULL) {
3744 RLOGE("invalid response: NULL");
3745 }
3746 else {
3747 RLOGE("responseLceData: invalid response length %d expecting len: d%",
3748 sizeof(RIL_LceDataInfo), responselen);
3749 }
3750 return RIL_ERRNO_INVALID_RESPONSE;
3751 }
3752
3753 RIL_LceDataInfo *p_cur = (RIL_LceDataInfo *)response;
3754 p.writeInt32(p_cur->last_hop_capacity_kbps);
3755
3756 /* p_cur->confidence_level and p_cur->lce_suspended take 1 byte each.*/
3757 p.write((void *)&(p_cur->confidence_level), 1);
3758 p.write((void *)&(p_cur->lce_suspended), 1);
3759
3760 startResponse;
Hyejin606dd672015-09-14 16:27:28 -07003761 appendPrintBuf("LCE info received: capacity %d confidence level %d \
fengluf7408292015-04-14 14:53:55 -07003762 and suspended %d",
3763 p_cur->last_hop_capacity_kbps, p_cur->confidence_level,
3764 p_cur->lce_suspended);
3765 closeResponse;
3766
3767 return 0;
3768}
3769
Prerepa Viswanadham73157492015-05-28 00:37:32 -07003770static int responseActivityData(Parcel &p, void *response, size_t responselen) {
3771 if (response == NULL || responselen != sizeof(RIL_ActivityStatsInfo)) {
3772 if (response == NULL) {
3773 RLOGE("invalid response: NULL");
3774 }
3775 else {
3776 RLOGE("responseActivityData: invalid response length %d expecting len: d%",
3777 sizeof(RIL_ActivityStatsInfo), responselen);
3778 }
3779 return RIL_ERRNO_INVALID_RESPONSE;
3780 }
3781
3782 RIL_ActivityStatsInfo *p_cur = (RIL_ActivityStatsInfo *)response;
3783 p.writeInt32(p_cur->sleep_mode_time_ms);
3784 p.writeInt32(p_cur->idle_mode_time_ms);
3785 for(int i = 0; i < RIL_NUM_TX_POWER_LEVELS; i++) {
3786 p.writeInt32(p_cur->tx_mode_time_ms[i]);
3787 }
3788 p.writeInt32(p_cur->rx_mode_time_ms);
3789
3790 startResponse;
Hyejin606dd672015-09-14 16:27:28 -07003791 appendPrintBuf("Modem activity info received: sleep_mode_time_ms %d idle_mode_time_ms %d \
Prerepa Viswanadham73157492015-05-28 00:37:32 -07003792 tx_mode_time_ms %d %d %d %d %d and rx_mode_time_ms %d",
3793 p_cur->sleep_mode_time_ms, p_cur->idle_mode_time_ms, p_cur->tx_mode_time_ms[0],
3794 p_cur->tx_mode_time_ms[1], p_cur->tx_mode_time_ms[2], p_cur->tx_mode_time_ms[3],
3795 p_cur->tx_mode_time_ms[4], p_cur->rx_mode_time_ms);
3796 closeResponse;
3797
3798 return 0;
3799}
3800
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003801/**
3802 * A write on the wakeup fd is done just to pop us out of select()
3803 * We empty the buffer here and then ril_event will reset the timers on the
3804 * way back down
3805 */
Wink Savillef4c4d362009-04-02 01:37:03 -07003806static void processWakeupCallback(int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003807 char buff[16];
3808 int ret;
3809
Wink Saville8eb2a122012-11-19 16:05:13 -08003810 RLOGV("processWakeupCallback");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003811
3812 /* empty our wakeup socket out */
3813 do {
3814 ret = read(s_fdWakeupRead, &buff, sizeof(buff));
Wink Saville7f856802009-06-09 10:23:37 -07003815 } while (ret > 0 || (ret < 0 && errno == EINTR));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003816}
3817
Etan Cohend3652192014-06-20 08:28:44 -07003818static void onCommandsSocketClosed(RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003819 int ret;
3820 RequestInfo *p_cur;
Etan Cohend3652192014-06-20 08:28:44 -07003821 /* Hook for current context
3822 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
3823 pthread_mutex_t * pendingRequestsMutexHook = &s_pendingRequestsMutex;
3824 /* pendingRequestsHook refer to &s_pendingRequests */
3825 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003826
Etan Cohend3652192014-06-20 08:28:44 -07003827#if (SIM_COUNT >= 2)
3828 if (socket_id == RIL_SOCKET_2) {
3829 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
3830 pendingRequestsHook = &s_pendingRequests_socket2;
3831 }
3832#if (SIM_COUNT >= 3)
3833 else if (socket_id == RIL_SOCKET_3) {
3834 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
3835 pendingRequestsHook = &s_pendingRequests_socket3;
3836 }
3837#endif
3838#if (SIM_COUNT >= 4)
3839 else if (socket_id == RIL_SOCKET_4) {
3840 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
3841 pendingRequestsHook = &s_pendingRequests_socket4;
3842 }
3843#endif
3844#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003845 /* mark pending requests as "cancelled" so we dont report responses */
Etan Cohend3652192014-06-20 08:28:44 -07003846 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003847 assert (ret == 0);
3848
Etan Cohend3652192014-06-20 08:28:44 -07003849 p_cur = *pendingRequestsHook;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003850
Etan Cohend3652192014-06-20 08:28:44 -07003851 for (p_cur = *pendingRequestsHook
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003852 ; p_cur != NULL
3853 ; p_cur = p_cur->p_next
3854 ) {
3855 p_cur->cancelled = 1;
3856 }
3857
Etan Cohend3652192014-06-20 08:28:44 -07003858 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003859 assert (ret == 0);
3860}
3861
Wink Savillef4c4d362009-04-02 01:37:03 -07003862static void processCommandsCallback(int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003863 RecordStream *p_rs;
3864 void *p_record;
3865 size_t recordlen;
3866 int ret;
Etan Cohend3652192014-06-20 08:28:44 -07003867 SocketListenParam *p_info = (SocketListenParam *)param;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003868
Etan Cohend3652192014-06-20 08:28:44 -07003869 assert(fd == p_info->fdCommand);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003870
Etan Cohend3652192014-06-20 08:28:44 -07003871 p_rs = p_info->p_rs;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003872
3873 for (;;) {
3874 /* loop until EAGAIN/EINTR, end of stream, or other error */
3875 ret = record_stream_get_next(p_rs, &p_record, &recordlen);
3876
3877 if (ret == 0 && p_record == NULL) {
3878 /* end-of-stream */
3879 break;
3880 } else if (ret < 0) {
3881 break;
3882 } else if (ret == 0) { /* && p_record != NULL */
Etan Cohend3652192014-06-20 08:28:44 -07003883 processCommandBuffer(p_record, recordlen, p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003884 }
3885 }
3886
3887 if (ret == 0 || !(errno == EAGAIN || errno == EINTR)) {
3888 /* fatal error or end-of-stream */
3889 if (ret != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003890 RLOGE("error on reading command socket errno:%d\n", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003891 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003892 RLOGW("EOS. Closing command socket.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003893 }
Wink Saville7f856802009-06-09 10:23:37 -07003894
Etan Cohend3652192014-06-20 08:28:44 -07003895 close(fd);
3896 p_info->fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003897
Etan Cohend3652192014-06-20 08:28:44 -07003898 ril_event_del(p_info->commands_event);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003899
3900 record_stream_free(p_rs);
3901
3902 /* start listening for new connections again */
3903 rilEventAddWakeup(&s_listen_event);
3904
Etan Cohend3652192014-06-20 08:28:44 -07003905 onCommandsSocketClosed(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003906 }
3907}
3908
3909
Etan Cohend3652192014-06-20 08:28:44 -07003910static void onNewCommandConnect(RIL_SOCKET_ID socket_id) {
Wink Saville5b9df332011-04-06 16:24:21 -07003911 // Inform we are connected and the ril version
Jake Hambya9c18d12011-04-12 23:32:08 -07003912 int rilVer = s_callbacks.version;
Etan Cohend3652192014-06-20 08:28:44 -07003913 RIL_UNSOL_RESPONSE(RIL_UNSOL_RIL_CONNECTED,
3914 &rilVer, sizeof(rilVer), socket_id);
Wink Saville5b9df332011-04-06 16:24:21 -07003915
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003916 // implicit radio state changed
Etan Cohend3652192014-06-20 08:28:44 -07003917 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
3918 NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003919
3920 // Send last NITZ time data, in case it was missed
3921 if (s_lastNITZTimeData != NULL) {
Etan Cohend3652192014-06-20 08:28:44 -07003922 sendResponseRaw(s_lastNITZTimeData, s_lastNITZTimeDataSize, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003923
3924 free(s_lastNITZTimeData);
3925 s_lastNITZTimeData = NULL;
3926 }
3927
3928 // Get version string
3929 if (s_callbacks.getVersion != NULL) {
3930 const char *version;
3931 version = s_callbacks.getVersion();
Wink Saville8eb2a122012-11-19 16:05:13 -08003932 RLOGI("RIL Daemon version: %s\n", version);
Wink Saville7f856802009-06-09 10:23:37 -07003933
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003934 property_set(PROPERTY_RIL_IMPL, version);
3935 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003936 RLOGI("RIL Daemon version: unavailable\n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003937 property_set(PROPERTY_RIL_IMPL, "unavailable");
3938 }
3939
3940}
3941
Wink Savillef4c4d362009-04-02 01:37:03 -07003942static void listenCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003943 int ret;
3944 int err;
3945 int is_phone_socket;
Etan Cohend3652192014-06-20 08:28:44 -07003946 int fdCommand = -1;
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003947 char* processName;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003948 RecordStream *p_rs;
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003949 MySocketListenParam* listenParam;
3950 RilSocket *sapSocket = NULL;
3951 socketClient *sClient = NULL;
3952
Etan Cohend3652192014-06-20 08:28:44 -07003953 SocketListenParam *p_info = (SocketListenParam *)param;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003954
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003955 if(RIL_SAP_SOCKET == p_info->type) {
3956 listenParam = (MySocketListenParam *)param;
3957 sapSocket = listenParam->socket;
3958 }
3959
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003960 struct sockaddr_un peeraddr;
3961 socklen_t socklen = sizeof (peeraddr);
3962
3963 struct ucred creds;
3964 socklen_t szCreds = sizeof(creds);
3965
3966 struct passwd *pwd = NULL;
3967
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003968 if(NULL == sapSocket) {
3969 assert (*p_info->fdCommand < 0);
3970 assert (fd == *p_info->fdListen);
3971 processName = PHONE_PROCESS;
3972 } else {
3973 assert (sapSocket->commandFd < 0);
3974 assert (fd == sapSocket->listenFd);
3975 processName = BLUETOOTH_PROCESS;
3976 }
3977
Wink Saville7f856802009-06-09 10:23:37 -07003978
Etan Cohend3652192014-06-20 08:28:44 -07003979 fdCommand = accept(fd, (sockaddr *) &peeraddr, &socklen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003980
Etan Cohend3652192014-06-20 08:28:44 -07003981 if (fdCommand < 0 ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003982 RLOGE("Error on accept() errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003983 /* start listening for new connections again */
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003984 if(NULL == sapSocket) {
3985 rilEventAddWakeup(p_info->listen_event);
3986 } else {
3987 rilEventAddWakeup(sapSocket->getListenEvent());
3988 }
Etan Cohend3652192014-06-20 08:28:44 -07003989 return;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003990 }
3991
3992 /* check the credential of the other side and only accept socket from
3993 * phone process
Wink Saville7f856802009-06-09 10:23:37 -07003994 */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003995 errno = 0;
3996 is_phone_socket = 0;
Wink Savillef4c4d362009-04-02 01:37:03 -07003997
Etan Cohend3652192014-06-20 08:28:44 -07003998 err = getsockopt(fdCommand, SOL_SOCKET, SO_PEERCRED, &creds, &szCreds);
Wink Savillef4c4d362009-04-02 01:37:03 -07003999
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004000 if (err == 0 && szCreds > 0) {
Wink Savillef4c4d362009-04-02 01:37:03 -07004001 errno = 0;
4002 pwd = getpwuid(creds.uid);
4003 if (pwd != NULL) {
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004004 if (strcmp(pwd->pw_name, processName) == 0) {
Wink Savillef4c4d362009-04-02 01:37:03 -07004005 is_phone_socket = 1;
4006 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08004007 RLOGE("RILD can't accept socket from process %s", pwd->pw_name);
Wink Savillef4c4d362009-04-02 01:37:03 -07004008 }
4009 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08004010 RLOGE("Error on getpwuid() errno: %d", errno);
Wink Savillef4c4d362009-04-02 01:37:03 -07004011 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004012 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08004013 RLOGD("Error on getsockopt() errno: %d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004014 }
4015
Etan Cohend3652192014-06-20 08:28:44 -07004016 if (!is_phone_socket) {
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004017 RLOGE("RILD must accept socket from %s", processName);
Wink Saville7f856802009-06-09 10:23:37 -07004018
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004019 close(fdCommand);
4020 fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004021
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004022 if(NULL == sapSocket) {
4023 onCommandsSocketClosed(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004024
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004025 /* start listening for new connections again */
4026 rilEventAddWakeup(p_info->listen_event);
4027 } else {
4028 sapSocket->onCommandsSocketClosed();
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004029
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004030 /* start listening for new connections again */
4031 rilEventAddWakeup(sapSocket->getListenEvent());
4032 }
4033
4034 return;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004035 }
4036
Etan Cohend3652192014-06-20 08:28:44 -07004037 ret = fcntl(fdCommand, F_SETFL, O_NONBLOCK);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004038
4039 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004040 RLOGE ("Error setting O_NONBLOCK errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004041 }
4042
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004043 if(NULL == sapSocket) {
4044 RLOGI("libril: new connection to %s", rilSocketIdToString(p_info->socket_id));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004045
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004046 p_info->fdCommand = fdCommand;
4047 p_rs = record_stream_new(p_info->fdCommand, MAX_COMMAND_BYTES);
4048 p_info->p_rs = p_rs;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004049
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004050 ril_event_set (p_info->commands_event, p_info->fdCommand, 1,
Etan Cohend3652192014-06-20 08:28:44 -07004051 p_info->processCommandsCallback, p_info);
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004052 rilEventAddWakeup (p_info->commands_event);
Etan Cohend3652192014-06-20 08:28:44 -07004053
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004054 onNewCommandConnect(p_info->socket_id);
4055 } else {
4056 RLOGI("libril: new connection");
Etan Cohend3652192014-06-20 08:28:44 -07004057
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004058 sapSocket->setCommandFd(fdCommand);
4059 p_rs = record_stream_new(sapSocket->getCommandFd(), MAX_COMMAND_BYTES);
4060 sClient = new socketClient(sapSocket,p_rs);
4061 ril_event_set (sapSocket->getCallbackEvent(), sapSocket->getCommandFd(), 1,
4062 sapSocket->getCommandCb(), sClient);
4063
4064 rilEventAddWakeup(sapSocket->getCallbackEvent());
4065 sapSocket->onNewCommandConnect();
4066 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004067}
4068
4069static void freeDebugCallbackArgs(int number, char **args) {
4070 for (int i = 0; i < number; i++) {
4071 if (args[i] != NULL) {
4072 free(args[i]);
4073 }
4074 }
4075 free(args);
4076}
4077
Wink Savillef4c4d362009-04-02 01:37:03 -07004078static void debugCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004079 int acceptFD, option;
4080 struct sockaddr_un peeraddr;
4081 socklen_t socklen = sizeof (peeraddr);
4082 int data;
4083 unsigned int qxdm_data[6];
4084 const char *deactData[1] = {"1"};
4085 char *actData[1];
4086 RIL_Dial dialData;
4087 int hangupData[1] = {1};
4088 int number;
4089 char **args;
Etan Cohend3652192014-06-20 08:28:44 -07004090 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
4091 int sim_id = 0;
4092
4093 RLOGI("debugCallback for socket %s", rilSocketIdToString(socket_id));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004094
4095 acceptFD = accept (fd, (sockaddr *) &peeraddr, &socklen);
4096
4097 if (acceptFD < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004098 RLOGE ("error accepting on debug port: %d\n", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004099 return;
4100 }
4101
4102 if (recv(acceptFD, &number, sizeof(int), 0) != sizeof(int)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004103 RLOGE ("error reading on socket: number of Args: \n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004104 return;
4105 }
4106 args = (char **) malloc(sizeof(char*) * number);
4107
4108 for (int i = 0; i < number; i++) {
4109 int len;
4110 if (recv(acceptFD, &len, sizeof(int), 0) != sizeof(int)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004111 RLOGE ("error reading on socket: Len of Args: \n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004112 freeDebugCallbackArgs(i, args);
4113 return;
4114 }
4115 // +1 for null-term
4116 args[i] = (char *) malloc((sizeof(char) * len) + 1);
Wink Saville7f856802009-06-09 10:23:37 -07004117 if (recv(acceptFD, args[i], sizeof(char) * len, 0)
Wink Saville1b5fd232009-04-22 14:50:00 -07004118 != (int)sizeof(char) * len) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004119 RLOGE ("error reading on socket: Args[%d] \n", i);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004120 freeDebugCallbackArgs(i, args);
4121 return;
4122 }
4123 char * buf = args[i];
4124 buf[len] = 0;
Etan Cohend3652192014-06-20 08:28:44 -07004125 if ((i+1) == number) {
4126 /* The last argument should be sim id 0(SIM1)~3(SIM4) */
4127 sim_id = atoi(args[i]);
4128 switch (sim_id) {
4129 case 0:
4130 socket_id = RIL_SOCKET_1;
4131 break;
4132 #if (SIM_COUNT >= 2)
4133 case 1:
4134 socket_id = RIL_SOCKET_2;
4135 break;
4136 #endif
4137 #if (SIM_COUNT >= 3)
4138 case 2:
4139 socket_id = RIL_SOCKET_3;
4140 break;
4141 #endif
4142 #if (SIM_COUNT >= 4)
4143 case 3:
4144 socket_id = RIL_SOCKET_4;
4145 break;
4146 #endif
4147 default:
4148 socket_id = RIL_SOCKET_1;
4149 break;
4150 }
4151 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004152 }
4153
4154 switch (atoi(args[0])) {
4155 case 0:
Wink Saville8eb2a122012-11-19 16:05:13 -08004156 RLOGI ("Connection on debug port: issuing reset.");
Etan Cohend3652192014-06-20 08:28:44 -07004157 issueLocalRequest(RIL_REQUEST_RESET_RADIO, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004158 break;
4159 case 1:
Wink Saville8eb2a122012-11-19 16:05:13 -08004160 RLOGI ("Connection on debug port: issuing radio power off.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004161 data = 0;
Etan Cohend3652192014-06-20 08:28:44 -07004162 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004163 // Close the socket
Etan Cohend3652192014-06-20 08:28:44 -07004164 if (socket_id == RIL_SOCKET_1 && s_ril_param_socket.fdCommand > 0) {
4165 close(s_ril_param_socket.fdCommand);
4166 s_ril_param_socket.fdCommand = -1;
4167 }
4168 #if (SIM_COUNT == 2)
4169 else if (socket_id == RIL_SOCKET_2 && s_ril_param_socket2.fdCommand > 0) {
4170 close(s_ril_param_socket2.fdCommand);
4171 s_ril_param_socket2.fdCommand = -1;
4172 }
4173 #endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004174 break;
4175 case 2:
Wink Saville8eb2a122012-11-19 16:05:13 -08004176 RLOGI ("Debug port: issuing unsolicited voice network change.");
Etan Cohend3652192014-06-20 08:28:44 -07004177 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004178 break;
4179 case 3:
Wink Saville8eb2a122012-11-19 16:05:13 -08004180 RLOGI ("Debug port: QXDM log enable.");
Xia Wangd855ef42010-07-27 17:26:55 -07004181 qxdm_data[0] = 65536; // head.func_tag
4182 qxdm_data[1] = 16; // head.len
4183 qxdm_data[2] = 1; // mode: 1 for 'start logging'
4184 qxdm_data[3] = 32; // log_file_size: 32megabytes
4185 qxdm_data[4] = 0; // log_mask
4186 qxdm_data[5] = 8; // log_max_fileindex
Wink Saville7f856802009-06-09 10:23:37 -07004187 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Etan Cohend3652192014-06-20 08:28:44 -07004188 6 * sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004189 break;
4190 case 4:
Wink Saville8eb2a122012-11-19 16:05:13 -08004191 RLOGI ("Debug port: QXDM log disable.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004192 qxdm_data[0] = 65536;
4193 qxdm_data[1] = 16;
Xia Wangd855ef42010-07-27 17:26:55 -07004194 qxdm_data[2] = 0; // mode: 0 for 'stop logging'
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004195 qxdm_data[3] = 32;
4196 qxdm_data[4] = 0;
Xia Wangd855ef42010-07-27 17:26:55 -07004197 qxdm_data[5] = 8;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004198 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Etan Cohend3652192014-06-20 08:28:44 -07004199 6 * sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004200 break;
4201 case 5:
Wink Saville8eb2a122012-11-19 16:05:13 -08004202 RLOGI("Debug port: Radio On");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004203 data = 1;
Etan Cohend3652192014-06-20 08:28:44 -07004204 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004205 sleep(2);
4206 // Set network selection automatic.
Etan Cohend3652192014-06-20 08:28:44 -07004207 issueLocalRequest(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004208 break;
4209 case 6:
Wink Saville8eb2a122012-11-19 16:05:13 -08004210 RLOGI("Debug port: Setup Data Call, Apn :%s\n", args[1]);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004211 actData[0] = args[1];
Wink Saville7f856802009-06-09 10:23:37 -07004212 issueLocalRequest(RIL_REQUEST_SETUP_DATA_CALL, &actData,
Etan Cohend3652192014-06-20 08:28:44 -07004213 sizeof(actData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004214 break;
4215 case 7:
Wink Saville8eb2a122012-11-19 16:05:13 -08004216 RLOGI("Debug port: Deactivate Data Call");
Wink Saville7f856802009-06-09 10:23:37 -07004217 issueLocalRequest(RIL_REQUEST_DEACTIVATE_DATA_CALL, &deactData,
Etan Cohend3652192014-06-20 08:28:44 -07004218 sizeof(deactData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004219 break;
4220 case 8:
Wink Saville8eb2a122012-11-19 16:05:13 -08004221 RLOGI("Debug port: Dial Call");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004222 dialData.clir = 0;
4223 dialData.address = args[1];
Etan Cohend3652192014-06-20 08:28:44 -07004224 issueLocalRequest(RIL_REQUEST_DIAL, &dialData, sizeof(dialData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004225 break;
4226 case 9:
Wink Saville8eb2a122012-11-19 16:05:13 -08004227 RLOGI("Debug port: Answer Call");
Etan Cohend3652192014-06-20 08:28:44 -07004228 issueLocalRequest(RIL_REQUEST_ANSWER, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004229 break;
4230 case 10:
Wink Saville8eb2a122012-11-19 16:05:13 -08004231 RLOGI("Debug port: End Call");
Wink Saville7f856802009-06-09 10:23:37 -07004232 issueLocalRequest(RIL_REQUEST_HANGUP, &hangupData,
Etan Cohend3652192014-06-20 08:28:44 -07004233 sizeof(hangupData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004234 break;
4235 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004236 RLOGE ("Invalid request");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004237 break;
4238 }
4239 freeDebugCallbackArgs(number, args);
4240 close(acceptFD);
4241}
4242
4243
Wink Savillef4c4d362009-04-02 01:37:03 -07004244static void userTimerCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004245 UserCallbackInfo *p_info;
4246
4247 p_info = (UserCallbackInfo *)param;
4248
4249 p_info->p_callback(p_info->userParam);
4250
4251
4252 // FIXME generalize this...there should be a cancel mechanism
4253 if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) {
4254 s_last_wake_timeout_info = NULL;
4255 }
4256
4257 free(p_info);
4258}
4259
4260
4261static void *
Wink Savillef4c4d362009-04-02 01:37:03 -07004262eventLoop(void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004263 int ret;
4264 int filedes[2];
4265
4266 ril_event_init();
4267
4268 pthread_mutex_lock(&s_startupMutex);
4269
4270 s_started = 1;
4271 pthread_cond_broadcast(&s_startupCond);
4272
4273 pthread_mutex_unlock(&s_startupMutex);
4274
4275 ret = pipe(filedes);
4276
4277 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004278 RLOGE("Error in pipe() errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004279 return NULL;
4280 }
4281
4282 s_fdWakeupRead = filedes[0];
4283 s_fdWakeupWrite = filedes[1];
4284
4285 fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK);
4286
4287 ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,
4288 processWakeupCallback, NULL);
4289
4290 rilEventAddWakeup (&s_wakeupfd_event);
4291
4292 // Only returns on error
4293 ril_event_loop();
Wink Saville8eb2a122012-11-19 16:05:13 -08004294 RLOGE ("error in event_loop_base errno:%d", errno);
Kazuhiro Ondo5cdc1352011-10-14 17:50:58 -05004295 // kill self to restart on error
4296 kill(0, SIGKILL);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004297
4298 return NULL;
4299}
4300
Wink Saville7f856802009-06-09 10:23:37 -07004301extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07004302RIL_startEventLoop(void) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004303 /* spin up eventLoop thread and wait for it to get started */
4304 s_started = 0;
4305 pthread_mutex_lock(&s_startupMutex);
4306
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004307 pthread_attr_t attr;
4308 pthread_attr_init(&attr);
Wink Saville7f856802009-06-09 10:23:37 -07004309 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004310
Elliott Hughesfd81e712014-01-06 12:46:02 -08004311 int result = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
4312 if (result != 0) {
4313 RLOGE("Failed to create dispatch thread: %s", strerror(result));
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004314 goto done;
4315 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004316
4317 while (s_started == 0) {
4318 pthread_cond_wait(&s_startupCond, &s_startupMutex);
4319 }
4320
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004321done:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004322 pthread_mutex_unlock(&s_startupMutex);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004323}
4324
4325// Used for testing purpose only.
4326extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) {
4327 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4328}
4329
Etan Cohend3652192014-06-20 08:28:44 -07004330static void startListen(RIL_SOCKET_ID socket_id, SocketListenParam* socket_listen_p) {
4331 int fdListen = -1;
4332 int ret;
4333 char socket_name[10];
4334
4335 memset(socket_name, 0, sizeof(char)*10);
4336
4337 switch(socket_id) {
4338 case RIL_SOCKET_1:
4339 strncpy(socket_name, RIL_getRilSocketName(), 9);
4340 break;
4341 #if (SIM_COUNT >= 2)
4342 case RIL_SOCKET_2:
4343 strncpy(socket_name, SOCKET2_NAME_RIL, 9);
4344 break;
4345 #endif
4346 #if (SIM_COUNT >= 3)
4347 case RIL_SOCKET_3:
4348 strncpy(socket_name, SOCKET3_NAME_RIL, 9);
4349 break;
4350 #endif
4351 #if (SIM_COUNT >= 4)
4352 case RIL_SOCKET_4:
4353 strncpy(socket_name, SOCKET4_NAME_RIL, 9);
4354 break;
4355 #endif
4356 default:
4357 RLOGE("Socket id is wrong!!");
4358 return;
4359 }
4360
4361 RLOGI("Start to listen %s", rilSocketIdToString(socket_id));
4362
4363 fdListen = android_get_control_socket(socket_name);
4364 if (fdListen < 0) {
4365 RLOGE("Failed to get socket %s", socket_name);
4366 exit(-1);
4367 }
4368
4369 ret = listen(fdListen, 4);
4370
4371 if (ret < 0) {
4372 RLOGE("Failed to listen on control socket '%d': %s",
4373 fdListen, strerror(errno));
4374 exit(-1);
4375 }
4376 socket_listen_p->fdListen = fdListen;
4377
4378 /* note: non-persistent so we can accept only one connection at a time */
4379 ril_event_set (socket_listen_p->listen_event, fdListen, false,
4380 listenCallback, socket_listen_p);
4381
4382 rilEventAddWakeup (socket_listen_p->listen_event);
4383}
4384
Wink Saville7f856802009-06-09 10:23:37 -07004385extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07004386RIL_register (const RIL_RadioFunctions *callbacks) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004387 int ret;
4388 int flags;
4389
Etan Cohend3652192014-06-20 08:28:44 -07004390 RLOGI("SIM_COUNT: %d", SIM_COUNT);
4391
Wink Saville43808972011-01-13 17:39:51 -08004392 if (callbacks == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004393 RLOGE("RIL_register: RIL_RadioFunctions * null");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004394 return;
4395 }
Wink Saville43808972011-01-13 17:39:51 -08004396 if (callbacks->version < RIL_VERSION_MIN) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004397 RLOGE("RIL_register: version %d is to old, min version is %d",
Wink Saville43808972011-01-13 17:39:51 -08004398 callbacks->version, RIL_VERSION_MIN);
4399 return;
Wink Saville3a4840b2010-04-07 13:29:58 -07004400 }
Sanket Padawe4c05f352016-01-26 16:19:00 -08004401
Wink Saville8eb2a122012-11-19 16:05:13 -08004402 RLOGE("RIL_register: RIL version %d", callbacks->version);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004403
4404 if (s_registerCalled > 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004405 RLOGE("RIL_register has been called more than once. "
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004406 "Subsequent call ignored");
4407 return;
4408 }
4409
4410 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4411
Etan Cohend3652192014-06-20 08:28:44 -07004412 /* Initialize socket1 parameters */
4413 s_ril_param_socket = {
4414 RIL_SOCKET_1, /* socket_id */
4415 -1, /* fdListen */
4416 -1, /* fdCommand */
4417 PHONE_PROCESS, /* processName */
4418 &s_commands_event, /* commands_event */
4419 &s_listen_event, /* listen_event */
4420 processCommandsCallback, /* processCommandsCallback */
4421 NULL /* p_rs */
4422 };
4423
4424#if (SIM_COUNT >= 2)
4425 s_ril_param_socket2 = {
4426 RIL_SOCKET_2, /* socket_id */
4427 -1, /* fdListen */
4428 -1, /* fdCommand */
4429 PHONE_PROCESS, /* processName */
4430 &s_commands_event_socket2, /* commands_event */
4431 &s_listen_event_socket2, /* listen_event */
4432 processCommandsCallback, /* processCommandsCallback */
4433 NULL /* p_rs */
4434 };
4435#endif
4436
4437#if (SIM_COUNT >= 3)
4438 s_ril_param_socket3 = {
4439 RIL_SOCKET_3, /* socket_id */
4440 -1, /* fdListen */
4441 -1, /* fdCommand */
4442 PHONE_PROCESS, /* processName */
4443 &s_commands_event_socket3, /* commands_event */
4444 &s_listen_event_socket3, /* listen_event */
4445 processCommandsCallback, /* processCommandsCallback */
4446 NULL /* p_rs */
4447 };
4448#endif
4449
4450#if (SIM_COUNT >= 4)
4451 s_ril_param_socket4 = {
4452 RIL_SOCKET_4, /* socket_id */
4453 -1, /* fdListen */
4454 -1, /* fdCommand */
4455 PHONE_PROCESS, /* processName */
4456 &s_commands_event_socket4, /* commands_event */
4457 &s_listen_event_socket4, /* listen_event */
4458 processCommandsCallback, /* processCommandsCallback */
4459 NULL /* p_rs */
4460 };
4461#endif
4462
4463
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004464 s_registerCalled = 1;
4465
Etan Cohend3652192014-06-20 08:28:44 -07004466 RLOGI("s_registerCalled flag set, %d", s_started);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004467 // Little self-check
4468
Wink Savillef4c4d362009-04-02 01:37:03 -07004469 for (int i = 0; i < (int)NUM_ELEMS(s_commands); i++) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004470 assert(i == s_commands[i].requestNumber);
4471 }
4472
Wink Savillef4c4d362009-04-02 01:37:03 -07004473 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses); i++) {
Wink Saville7f856802009-06-09 10:23:37 -07004474 assert(i + RIL_UNSOL_RESPONSE_BASE
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004475 == s_unsolResponses[i].requestNumber);
4476 }
4477
4478 // New rild impl calls RIL_startEventLoop() first
4479 // old standalone impl wants it here.
4480
4481 if (s_started == 0) {
4482 RIL_startEventLoop();
4483 }
4484
Etan Cohend3652192014-06-20 08:28:44 -07004485 // start listen socket1
4486 startListen(RIL_SOCKET_1, &s_ril_param_socket);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004487
Etan Cohend3652192014-06-20 08:28:44 -07004488#if (SIM_COUNT >= 2)
4489 // start listen socket2
4490 startListen(RIL_SOCKET_2, &s_ril_param_socket2);
4491#endif /* (SIM_COUNT == 2) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004492
Etan Cohend3652192014-06-20 08:28:44 -07004493#if (SIM_COUNT >= 3)
4494 // start listen socket3
4495 startListen(RIL_SOCKET_3, &s_ril_param_socket3);
4496#endif /* (SIM_COUNT == 3) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004497
Etan Cohend3652192014-06-20 08:28:44 -07004498#if (SIM_COUNT >= 4)
4499 // start listen socket4
4500 startListen(RIL_SOCKET_4, &s_ril_param_socket4);
4501#endif /* (SIM_COUNT == 4) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004502
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004503
4504#if 1
4505 // start debug interface socket
4506
Etan Cohend3652192014-06-20 08:28:44 -07004507 char *inst = NULL;
4508 if (strlen(RIL_getRilSocketName()) >= strlen(SOCKET_NAME_RIL)) {
4509 inst = RIL_getRilSocketName() + strlen(SOCKET_NAME_RIL);
4510 }
4511
4512 char rildebug[MAX_DEBUG_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL_DEBUG;
4513 if (inst != NULL) {
Nick Kralevichc52e45e2015-02-08 07:54:16 -08004514 strlcat(rildebug, inst, MAX_DEBUG_SOCKET_NAME_LENGTH);
Etan Cohend3652192014-06-20 08:28:44 -07004515 }
4516
4517 s_fdDebug = android_get_control_socket(rildebug);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004518 if (s_fdDebug < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07004519 RLOGE("Failed to get socket : %s errno:%d", rildebug, errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004520 exit(-1);
4521 }
4522
4523 ret = listen(s_fdDebug, 4);
4524
4525 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004526 RLOGE("Failed to listen on ril debug socket '%d': %s",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004527 s_fdDebug, strerror(errno));
4528 exit(-1);
4529 }
4530
4531 ril_event_set (&s_debug_event, s_fdDebug, true,
4532 debugCallback, NULL);
4533
4534 rilEventAddWakeup (&s_debug_event);
4535#endif
4536
4537}
4538
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004539extern "C" void
4540RIL_register_socket (RIL_RadioFunctions *(*Init)(const struct RIL_Env *, int, char **),RIL_SOCKET_TYPE socketType, int argc, char **argv) {
4541
4542 RIL_RadioFunctions* UimFuncs = NULL;
4543
4544 if(Init) {
4545 UimFuncs = Init(&RilSapSocket::uimRilEnv, argc, argv);
4546
4547 switch(socketType) {
4548 case RIL_SAP_SOCKET:
4549 RilSapSocket::initSapSocket("sap_uim_socket1", UimFuncs);
4550
4551#if (SIM_COUNT >= 2)
4552 RilSapSocket::initSapSocket("sap_uim_socket2", UimFuncs);
4553#endif
4554
4555#if (SIM_COUNT >= 3)
4556 RilSapSocket::initSapSocket("sap_uim_socket3", UimFuncs);
4557#endif
4558
4559#if (SIM_COUNT >= 4)
4560 RilSapSocket::initSapSocket("sap_uim_socket4", UimFuncs);
4561#endif
4562 }
4563 }
4564}
4565
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004566static int
Wink Savillef4c4d362009-04-02 01:37:03 -07004567checkAndDequeueRequestInfo(struct RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004568 int ret = 0;
Etan Cohend3652192014-06-20 08:28:44 -07004569 /* Hook for current context
4570 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
4571 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
4572 /* pendingRequestsHook refer to &s_pendingRequests */
4573 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
Wink Saville7f856802009-06-09 10:23:37 -07004574
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004575 if (pRI == NULL) {
4576 return 0;
4577 }
4578
Etan Cohend3652192014-06-20 08:28:44 -07004579#if (SIM_COUNT >= 2)
4580 if (pRI->socket_id == RIL_SOCKET_2) {
4581 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
4582 pendingRequestsHook = &s_pendingRequests_socket2;
4583 }
4584#if (SIM_COUNT >= 3)
4585 if (pRI->socket_id == RIL_SOCKET_3) {
4586 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
4587 pendingRequestsHook = &s_pendingRequests_socket3;
4588 }
4589#endif
4590#if (SIM_COUNT >= 4)
4591 if (pRI->socket_id == RIL_SOCKET_4) {
4592 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
4593 pendingRequestsHook = &s_pendingRequests_socket4;
4594 }
4595#endif
4596#endif
4597 pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004598
Etan Cohend3652192014-06-20 08:28:44 -07004599 for(RequestInfo **ppCur = pendingRequestsHook
Wink Saville7f856802009-06-09 10:23:37 -07004600 ; *ppCur != NULL
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004601 ; ppCur = &((*ppCur)->p_next)
4602 ) {
4603 if (pRI == *ppCur) {
4604 ret = 1;
4605
4606 *ppCur = (*ppCur)->p_next;
4607 break;
4608 }
4609 }
4610
Etan Cohend3652192014-06-20 08:28:44 -07004611 pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004612
4613 return ret;
4614}
4615
4616
4617extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07004618RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004619 RequestInfo *pRI;
4620 int ret;
Etan Cohend3652192014-06-20 08:28:44 -07004621 int fd = s_ril_param_socket.fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004622 size_t errorOffset;
Etan Cohend3652192014-06-20 08:28:44 -07004623 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004624
4625 pRI = (RequestInfo *)t;
4626
Jayachandran C6c607592014-08-04 15:48:01 -07004627 if (!checkAndDequeueRequestInfo(pRI)) {
4628 RLOGE ("RIL_onRequestComplete: invalid RIL_Token");
4629 return;
4630 }
4631
Etan Cohend3652192014-06-20 08:28:44 -07004632 socket_id = pRI->socket_id;
4633#if (SIM_COUNT >= 2)
4634 if (socket_id == RIL_SOCKET_2) {
4635 fd = s_ril_param_socket2.fdCommand;
4636 }
4637#if (SIM_COUNT >= 3)
4638 if (socket_id == RIL_SOCKET_3) {
4639 fd = s_ril_param_socket3.fdCommand;
4640 }
4641#endif
4642#if (SIM_COUNT >= 4)
4643 if (socket_id == RIL_SOCKET_4) {
4644 fd = s_ril_param_socket4.fdCommand;
4645 }
4646#endif
4647#endif
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07004648#if VDBG
Etan Cohend3652192014-06-20 08:28:44 -07004649 RLOGD("RequestComplete, %s", rilSocketIdToString(socket_id));
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07004650#endif
Etan Cohend3652192014-06-20 08:28:44 -07004651
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004652 if (pRI->local > 0) {
4653 // Locally issued command...void only!
4654 // response does not go back up the command socket
Wink Saville8eb2a122012-11-19 16:05:13 -08004655 RLOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004656
4657 goto done;
4658 }
4659
4660 appendPrintBuf("[%04d]< %s",
4661 pRI->token, requestToString(pRI->pCI->requestNumber));
4662
4663 if (pRI->cancelled == 0) {
4664 Parcel p;
4665
4666 p.writeInt32 (RESPONSE_SOLICITED);
4667 p.writeInt32 (pRI->token);
4668 errorOffset = p.dataPosition();
4669
4670 p.writeInt32 (e);
4671
johnwangb2a61842009-06-02 14:55:45 -07004672 if (response != NULL) {
4673 // there is a response payload, no matter success or not.
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004674 ret = pRI->pCI->responseFunction(p, response, responselen);
4675
4676 /* if an error occurred, rewind and mark it */
4677 if (ret != 0) {
Etan Cohend3652192014-06-20 08:28:44 -07004678 RLOGE ("responseFunction error, ret %d", ret);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004679 p.setDataPosition(errorOffset);
4680 p.writeInt32 (ret);
4681 }
johnwangb2a61842009-06-02 14:55:45 -07004682 }
4683
4684 if (e != RIL_E_SUCCESS) {
4685 appendPrintBuf("%s fails by %s", printBuf, failCauseToString(e));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004686 }
4687
Etan Cohend3652192014-06-20 08:28:44 -07004688 if (fd < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004689 RLOGD ("RIL onRequestComplete: Command channel closed");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004690 }
Etan Cohend3652192014-06-20 08:28:44 -07004691 sendResponse(p, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004692 }
4693
4694done:
4695 free(pRI);
4696}
4697
4698
4699static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004700grabPartialWakeLock() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004701 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
4702}
4703
4704static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004705releaseWakeLock() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004706 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
4707}
4708
4709/**
4710 * Timer callback to put us back to sleep before the default timeout
4711 */
4712static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004713wakeTimeoutCallback (void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004714 // We're using "param != NULL" as a cancellation mechanism
4715 if (param == NULL) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004716 releaseWakeLock();
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004717 }
4718}
4719
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004720static int
4721decodeVoiceRadioTechnology (RIL_RadioState radioState) {
4722 switch (radioState) {
4723 case RADIO_STATE_SIM_NOT_READY:
4724 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4725 case RADIO_STATE_SIM_READY:
4726 return RADIO_TECH_UMTS;
4727
4728 case RADIO_STATE_RUIM_NOT_READY:
4729 case RADIO_STATE_RUIM_READY:
4730 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4731 case RADIO_STATE_NV_NOT_READY:
4732 case RADIO_STATE_NV_READY:
4733 return RADIO_TECH_1xRTT;
4734
4735 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004736 RLOGD("decodeVoiceRadioTechnology: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004737 return -1;
4738 }
4739}
4740
4741static int
4742decodeCdmaSubscriptionSource (RIL_RadioState radioState) {
4743 switch (radioState) {
4744 case RADIO_STATE_SIM_NOT_READY:
4745 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4746 case RADIO_STATE_SIM_READY:
4747 case RADIO_STATE_RUIM_NOT_READY:
4748 case RADIO_STATE_RUIM_READY:
4749 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4750 return CDMA_SUBSCRIPTION_SOURCE_RUIM_SIM;
4751
4752 case RADIO_STATE_NV_NOT_READY:
4753 case RADIO_STATE_NV_READY:
4754 return CDMA_SUBSCRIPTION_SOURCE_NV;
4755
4756 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004757 RLOGD("decodeCdmaSubscriptionSource: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004758 return -1;
4759 }
4760}
4761
4762static int
4763decodeSimStatus (RIL_RadioState radioState) {
4764 switch (radioState) {
4765 case RADIO_STATE_SIM_NOT_READY:
4766 case RADIO_STATE_RUIM_NOT_READY:
4767 case RADIO_STATE_NV_NOT_READY:
4768 case RADIO_STATE_NV_READY:
4769 return -1;
4770 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4771 case RADIO_STATE_SIM_READY:
4772 case RADIO_STATE_RUIM_READY:
4773 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4774 return radioState;
4775 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004776 RLOGD("decodeSimStatus: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004777 return -1;
4778 }
4779}
4780
4781static bool is3gpp2(int radioTech) {
4782 switch (radioTech) {
4783 case RADIO_TECH_IS95A:
4784 case RADIO_TECH_IS95B:
4785 case RADIO_TECH_1xRTT:
4786 case RADIO_TECH_EVDO_0:
4787 case RADIO_TECH_EVDO_A:
4788 case RADIO_TECH_EVDO_B:
4789 case RADIO_TECH_EHRPD:
4790 return true;
4791 default:
4792 return false;
4793 }
4794}
4795
4796/* If RIL sends SIM states or RUIM states, store the voice radio
4797 * technology and subscription source information so that they can be
4798 * returned when telephony framework requests them
4799 */
4800static RIL_RadioState
Etan Cohend3652192014-06-20 08:28:44 -07004801processRadioState(RIL_RadioState newRadioState, RIL_SOCKET_ID socket_id) {
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004802
4803 if((newRadioState > RADIO_STATE_UNAVAILABLE) && (newRadioState < RADIO_STATE_ON)) {
4804 int newVoiceRadioTech;
4805 int newCdmaSubscriptionSource;
4806 int newSimStatus;
4807
4808 /* This is old RIL. Decode Subscription source and Voice Radio Technology
4809 from Radio State and send change notifications if there has been a change */
4810 newVoiceRadioTech = decodeVoiceRadioTechnology(newRadioState);
4811 if(newVoiceRadioTech != voiceRadioTech) {
4812 voiceRadioTech = newVoiceRadioTech;
Etan Cohend3652192014-06-20 08:28:44 -07004813 RIL_UNSOL_RESPONSE(RIL_UNSOL_VOICE_RADIO_TECH_CHANGED,
4814 &voiceRadioTech, sizeof(voiceRadioTech), socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004815 }
4816 if(is3gpp2(newVoiceRadioTech)) {
4817 newCdmaSubscriptionSource = decodeCdmaSubscriptionSource(newRadioState);
4818 if(newCdmaSubscriptionSource != cdmaSubscriptionSource) {
4819 cdmaSubscriptionSource = newCdmaSubscriptionSource;
Etan Cohend3652192014-06-20 08:28:44 -07004820 RIL_UNSOL_RESPONSE(RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED,
4821 &cdmaSubscriptionSource, sizeof(cdmaSubscriptionSource), socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004822 }
4823 }
4824 newSimStatus = decodeSimStatus(newRadioState);
4825 if(newSimStatus != simRuimStatus) {
4826 simRuimStatus = newSimStatus;
Etan Cohend3652192014-06-20 08:28:44 -07004827 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0, socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004828 }
4829
4830 /* Send RADIO_ON to telephony */
4831 newRadioState = RADIO_STATE_ON;
4832 }
4833
4834 return newRadioState;
4835}
4836
Etan Cohend3652192014-06-20 08:28:44 -07004837
4838#if defined(ANDROID_MULTI_SIM)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004839extern "C"
Bernhard Rosenkränzerd613b962014-11-17 20:52:09 +01004840void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Etan Cohend3652192014-06-20 08:28:44 -07004841 size_t datalen, RIL_SOCKET_ID socket_id)
4842#else
4843extern "C"
Bernhard Rosenkränzerd613b962014-11-17 20:52:09 +01004844void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004845 size_t datalen)
Etan Cohend3652192014-06-20 08:28:44 -07004846#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004847{
4848 int unsolResponseIndex;
4849 int ret;
4850 int64_t timeReceived = 0;
4851 bool shouldScheduleTimeout = false;
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004852 RIL_RadioState newState;
Etan Cohend3652192014-06-20 08:28:44 -07004853 RIL_SOCKET_ID soc_id = RIL_SOCKET_1;
4854
4855#if defined(ANDROID_MULTI_SIM)
4856 soc_id = socket_id;
4857#endif
4858
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004859
4860 if (s_registerCalled == 0) {
4861 // Ignore RIL_onUnsolicitedResponse before RIL_register
Wink Saville8eb2a122012-11-19 16:05:13 -08004862 RLOGW("RIL_onUnsolicitedResponse called before RIL_register");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004863 return;
4864 }
Wink Saville7f856802009-06-09 10:23:37 -07004865
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004866 unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
4867
4868 if ((unsolResponseIndex < 0)
4869 || (unsolResponseIndex >= (int32_t)NUM_ELEMS(s_unsolResponses))) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004870 RLOGE("unsupported unsolicited response code %d", unsolResponse);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004871 return;
4872 }
4873
4874 // Grab a wake lock if needed for this reponse,
4875 // as we exit we'll either release it immediately
4876 // or set a timer to release it later.
4877 switch (s_unsolResponses[unsolResponseIndex].wakeType) {
4878 case WAKE_PARTIAL:
4879 grabPartialWakeLock();
4880 shouldScheduleTimeout = true;
4881 break;
4882
4883 case DONT_WAKE:
4884 default:
4885 // No wake lock is grabed so don't set timeout
4886 shouldScheduleTimeout = false;
4887 break;
4888 }
4889
4890 // Mark the time this was received, doing this
4891 // after grabing the wakelock incase getting
4892 // the elapsedRealTime might cause us to goto
4893 // sleep.
4894 if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4895 timeReceived = elapsedRealtime();
4896 }
4897
4898 appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
4899
4900 Parcel p;
4901
4902 p.writeInt32 (RESPONSE_UNSOLICITED);
4903 p.writeInt32 (unsolResponse);
4904
4905 ret = s_unsolResponses[unsolResponseIndex]
Bernhard Rosenkränzer6e7c1962013-12-12 10:01:10 +01004906 .responseFunction(p, const_cast<void*>(data), datalen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004907 if (ret != 0) {
4908 // Problem with the response. Don't continue;
4909 goto error_exit;
4910 }
4911
4912 // some things get more payload
4913 switch(unsolResponse) {
4914 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
Etan Cohend3652192014-06-20 08:28:44 -07004915 newState = processRadioState(CALL_ONSTATEREQUEST(soc_id), soc_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004916 p.writeInt32(newState);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004917 appendPrintBuf("%s {%s}", printBuf,
Etan Cohend3652192014-06-20 08:28:44 -07004918 radioStateToString(CALL_ONSTATEREQUEST(soc_id)));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004919 break;
4920
4921
4922 case RIL_UNSOL_NITZ_TIME_RECEIVED:
4923 // Store the time that this was received so the
4924 // handler of this message can account for
4925 // the time it takes to arrive and process. In
4926 // particular the system has been known to sleep
4927 // before this message can be processed.
4928 p.writeInt64(timeReceived);
4929 break;
4930 }
4931
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07004932#if VDBG
Etan Cohend3652192014-06-20 08:28:44 -07004933 RLOGI("%s UNSOLICITED: %s length:%d", rilSocketIdToString(soc_id), requestToString(unsolResponse), p.dataSize());
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07004934#endif
Etan Cohend3652192014-06-20 08:28:44 -07004935 ret = sendResponse(p, soc_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004936 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4937
4938 // Unfortunately, NITZ time is not poll/update like everything
4939 // else in the system. So, if the upstream client isn't connected,
4940 // keep a copy of the last NITZ response (with receive time noted
4941 // above) around so we can deliver it when it is connected
4942
4943 if (s_lastNITZTimeData != NULL) {
4944 free (s_lastNITZTimeData);
4945 s_lastNITZTimeData = NULL;
4946 }
4947
4948 s_lastNITZTimeData = malloc(p.dataSize());
4949 s_lastNITZTimeDataSize = p.dataSize();
4950 memcpy(s_lastNITZTimeData, p.data(), p.dataSize());
4951 }
4952
4953 // For now, we automatically go back to sleep after TIMEVAL_WAKE_TIMEOUT
4954 // FIXME The java code should handshake here to release wake lock
4955
4956 if (shouldScheduleTimeout) {
4957 // Cancel the previous request
4958 if (s_last_wake_timeout_info != NULL) {
4959 s_last_wake_timeout_info->userParam = (void *)1;
4960 }
4961
4962 s_last_wake_timeout_info
4963 = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
4964 &TIMEVAL_WAKE_TIMEOUT);
4965 }
4966
4967 // Normal exit
4968 return;
4969
4970error_exit:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004971 if (shouldScheduleTimeout) {
4972 releaseWakeLock();
4973 }
4974}
4975
Wink Saville7f856802009-06-09 10:23:37 -07004976/** FIXME generalize this if you track UserCAllbackInfo, clear it
4977 when the callback occurs
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004978*/
4979static UserCallbackInfo *
Wink Saville7f856802009-06-09 10:23:37 -07004980internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004981 const struct timeval *relativeTime)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004982{
4983 struct timeval myRelativeTime;
4984 UserCallbackInfo *p_info;
4985
4986 p_info = (UserCallbackInfo *) malloc (sizeof(UserCallbackInfo));
4987
Wink Saville7f856802009-06-09 10:23:37 -07004988 p_info->p_callback = callback;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004989 p_info->userParam = param;
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004990
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004991 if (relativeTime == NULL) {
4992 /* treat null parameter as a 0 relative time */
4993 memset (&myRelativeTime, 0, sizeof(myRelativeTime));
4994 } else {
4995 /* FIXME I think event_add's tv param is really const anyway */
4996 memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
4997 }
4998
4999 ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
5000
5001 ril_timer_add(&(p_info->event), &myRelativeTime);
5002
5003 triggerEvLoop();
5004 return p_info;
5005}
5006
Naveen Kalla7edd07c2010-06-21 18:54:47 -07005007
5008extern "C" void
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07005009RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
5010 const struct timeval *relativeTime) {
5011 internalRequestTimedCallback (callback, param, relativeTime);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005012}
5013
5014const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07005015failCauseToString(RIL_Errno e) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005016 switch(e) {
5017 case RIL_E_SUCCESS: return "E_SUCCESS";
Robert Greenwalt2126ab22013-04-09 12:20:45 -07005018 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RADIO_NOT_AVAILABLE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005019 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
5020 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
5021 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
5022 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
5023 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
5024 case RIL_E_CANCELLED: return "E_CANCELLED";
5025 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
5026 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
5027 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
Wink Savillef4c4d362009-04-02 01:37:03 -07005028 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
John Wang75534472010-04-20 15:11:42 -07005029 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
Wink Saville7f856802009-06-09 10:23:37 -07005030#ifdef FEATURE_MULTIMODE_ANDROID
Wink Savillef4c4d362009-04-02 01:37:03 -07005031 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
5032 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
5033#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005034 default: return "<unknown error>";
5035 }
5036}
5037
5038const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07005039radioStateToString(RIL_RadioState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005040 switch(s) {
5041 case RADIO_STATE_OFF: return "RADIO_OFF";
5042 case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
5043 case RADIO_STATE_SIM_NOT_READY: return "RADIO_SIM_NOT_READY";
5044 case RADIO_STATE_SIM_LOCKED_OR_ABSENT: return "RADIO_SIM_LOCKED_OR_ABSENT";
5045 case RADIO_STATE_SIM_READY: return "RADIO_SIM_READY";
Wink Savillef4c4d362009-04-02 01:37:03 -07005046 case RADIO_STATE_RUIM_NOT_READY:return"RADIO_RUIM_NOT_READY";
5047 case RADIO_STATE_RUIM_READY:return"RADIO_RUIM_READY";
5048 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:return"RADIO_RUIM_LOCKED_OR_ABSENT";
5049 case RADIO_STATE_NV_NOT_READY:return"RADIO_NV_NOT_READY";
5050 case RADIO_STATE_NV_READY:return"RADIO_NV_READY";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005051 case RADIO_STATE_ON:return"RADIO_ON";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005052 default: return "<unknown state>";
5053 }
5054}
5055
5056const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07005057callStateToString(RIL_CallState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005058 switch(s) {
5059 case RIL_CALL_ACTIVE : return "ACTIVE";
5060 case RIL_CALL_HOLDING: return "HOLDING";
5061 case RIL_CALL_DIALING: return "DIALING";
5062 case RIL_CALL_ALERTING: return "ALERTING";
5063 case RIL_CALL_INCOMING: return "INCOMING";
5064 case RIL_CALL_WAITING: return "WAITING";
5065 default: return "<unknown state>";
5066 }
5067}
5068
5069const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07005070requestToString(int request) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005071/*
5072 cat libs/telephony/ril_commands.h \
5073 | egrep "^ *{RIL_" \
5074 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
5075
5076
5077 cat libs/telephony/ril_unsol_commands.h \
5078 | egrep "^ *{RIL_" \
5079 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
5080
5081*/
5082 switch(request) {
5083 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
5084 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
5085 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
5086 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
5087 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
5088 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
5089 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
5090 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
5091 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
5092 case RIL_REQUEST_DIAL: return "DIAL";
5093 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
5094 case RIL_REQUEST_HANGUP: return "HANGUP";
5095 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
5096 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
5097 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
5098 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
5099 case RIL_REQUEST_UDUB: return "UDUB";
5100 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
5101 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
Wink Savillec0114b32011-02-18 10:14:07 -08005102 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
5103 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005104 case RIL_REQUEST_OPERATOR: return "OPERATOR";
5105 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
5106 case RIL_REQUEST_DTMF: return "DTMF";
5107 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
5108 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
Wink Savillef4c4d362009-04-02 01:37:03 -07005109 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005110 case RIL_REQUEST_SIM_IO: return "SIM_IO";
5111 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
5112 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
5113 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
5114 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
5115 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
5116 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
5117 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
5118 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
5119 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
5120 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
5121 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
5122 case RIL_REQUEST_ANSWER: return "ANSWER";
Wink Savillef4c4d362009-04-02 01:37:03 -07005123 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005124 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
5125 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
5126 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
5127 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
5128 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
5129 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
5130 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";
5131 case RIL_REQUEST_DTMF_START: return "DTMF_START";
5132 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
5133 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
5134 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
5135 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
5136 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
5137 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
5138 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
5139 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
5140 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
Wink Savillef4c4d362009-04-02 01:37:03 -07005141 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
5142 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005143 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
5144 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
5145 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
Wink Savillef4c4d362009-04-02 01:37:03 -07005146 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
5147 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005148 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
5149 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
5150 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
5151 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
5152 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
5153 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
5154 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
5155 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
Wink Savillec0114b32011-02-18 10:14:07 -08005156 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE:return"CDMA_SET_SUBSCRIPTION_SOURCE";
Wink Savillef4c4d362009-04-02 01:37:03 -07005157 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"CDMA_SET_ROAMING_PREFERENCE";
5158 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"CDMA_QUERY_ROAMING_PREFERENCE";
5159 case RIL_REQUEST_SET_TTY_MODE:return"SET_TTY_MODE";
5160 case RIL_REQUEST_QUERY_TTY_MODE:return"QUERY_TTY_MODE";
5161 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
5162 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
5163 case RIL_REQUEST_CDMA_FLASH:return"CDMA_FLASH";
5164 case RIL_REQUEST_CDMA_BURST_DTMF:return"CDMA_BURST_DTMF";
5165 case RIL_REQUEST_CDMA_SEND_SMS:return"CDMA_SEND_SMS";
5166 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:return"CDMA_SMS_ACKNOWLEDGE";
Wink Savillea592eeb2009-05-22 13:26:36 -07005167 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG:return"GSM_GET_BROADCAST_SMS_CONFIG";
5168 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG:return"GSM_SET_BROADCAST_SMS_CONFIG";
5169 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG:return "CDMA_GET_BROADCAST_SMS_CONFIG";
5170 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG:return "CDMA_SET_BROADCAST_SMS_CONFIG";
5171 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION:return "CDMA_SMS_BROADCAST_ACTIVATION";
Naveen Kalla03c1edf2009-09-23 11:18:35 -07005172 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return"CDMA_VALIDATE_AND_WRITE_AKEY";
Wink Savillef4c4d362009-04-02 01:37:03 -07005173 case RIL_REQUEST_CDMA_SUBSCRIPTION: return"CDMA_SUBSCRIPTION";
5174 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
5175 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
5176 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
jsh000a9fe2009-05-11 14:52:35 -07005177 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
5178 case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
5179 case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
jsh09a68ba2009-06-10 11:56:38 -07005180 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
jsh563fd722010-06-08 16:52:24 -07005181 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
Wink Savillec0114b32011-02-18 10:14:07 -08005182 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
Jake Hambyfa8d5842011-08-19 16:22:18 -07005183 case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
Jake Hamby300105d2011-09-26 01:01:44 -07005184 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
5185 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005186 case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
Sanket Padawe0eb4fba2016-01-26 17:28:38 -08005187 case RIL_REQUEST_WRITE_SMS_TO_SIM: return "WRITE_SMS_TO_SIM";
Wink Saville8a9e0212013-04-09 12:11:38 -07005188 case RIL_REQUEST_GET_CELL_INFO_LIST: return"GET_CELL_INFO_LIST";
5189 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return"SET_UNSOL_CELL_INFO_LIST_RATE";
Sungmin Choi75697532013-04-26 15:04:45 -07005190 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "RIL_REQUEST_SET_INITIAL_ATTACH_APN";
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07005191 case RIL_REQUEST_IMS_REGISTRATION_STATE: return "IMS_REGISTRATION_STATE";
5192 case RIL_REQUEST_IMS_SEND_SMS: return "IMS_SEND_SMS";
Shishir Agrawal2458d8d2013-11-27 14:53:05 -08005193 case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "SIM_TRANSMIT_APDU_BASIC";
5194 case RIL_REQUEST_SIM_OPEN_CHANNEL: return "SIM_OPEN_CHANNEL";
5195 case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "SIM_CLOSE_CHANNEL";
5196 case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "SIM_TRANSMIT_APDU_CHANNEL";
Wink Saville8b4e4f72014-10-17 15:01:45 -07005197 case RIL_REQUEST_GET_RADIO_CAPABILITY: return "RIL_REQUEST_GET_RADIO_CAPABILITY";
5198 case RIL_REQUEST_SET_RADIO_CAPABILITY: return "RIL_REQUEST_SET_RADIO_CAPABILITY";
Etan Cohend3652192014-06-20 08:28:44 -07005199 case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "SET_UICC_SUBSCRIPTION";
5200 case RIL_REQUEST_ALLOW_DATA: return "ALLOW_DATA";
Amit Mahajan2b772032014-06-26 14:20:11 -07005201 case RIL_REQUEST_GET_HARDWARE_CONFIG: return "GET_HARDWARE_CONFIG";
5202 case RIL_REQUEST_SIM_AUTHENTICATION: return "SIM_AUTHENTICATION";
Wink Savillec29360a2014-07-13 05:17:28 -07005203 case RIL_REQUEST_GET_DC_RT_INFO: return "GET_DC_RT_INFO";
5204 case RIL_REQUEST_SET_DC_RT_INFO_RATE: return "SET_DC_RT_INFO_RATE";
Amit Mahajanc796e222014-08-13 16:54:01 +00005205 case RIL_REQUEST_SET_DATA_PROFILE: return "SET_DATA_PROFILE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005206 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
5207 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08005208 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 -08005209 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
5210 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
5211 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
5212 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
5213 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)";
5214 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
5215 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
Sanket Padawe0eb4fba2016-01-26 17:28:38 -08005216 case RIL_UNSOL_SUPP_SVC_NOTIFICATION: return "UNSOL_SUPP_SVC_NOTIFICATION";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005217 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
5218 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
5219 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
5220 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
5221 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL";
5222 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
Wink Savillef4c4d362009-04-02 01:37:03 -07005223 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005224 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
Wink Savillef4c4d362009-04-02 01:37:03 -07005225 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
5226 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_NEW_CDMA_SMS";
5227 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_NEW_BROADCAST_SMS";
5228 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
Wink Saville3d54e742009-05-18 18:00:44 -07005229 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
5230 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
5231 case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
5232 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
5233 case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
Jaikumar Ganeshaf6ecbf2009-04-29 13:27:51 -07005234 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
John Wang5d621da2009-09-18 17:17:48 -07005235 case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
John Wang5909cf82010-01-29 00:18:54 -08005236 case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
Wink Savilleee274582011-04-16 15:05:49 -07005237 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08005238 case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
5239 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
Wink Saville5b9df332011-04-06 16:24:21 -07005240 case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005241 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
Wink Saville8a9e0212013-04-09 12:11:38 -07005242 case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07005243 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "RESPONSE_IMS_NETWORK_STATE_CHANGED";
Etan Cohend3652192014-06-20 08:28:44 -07005244 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return "UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED";
5245 case RIL_UNSOL_SRVCC_STATE_NOTIFY: return "UNSOL_SRVCC_STATE_NOTIFY";
5246 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return "HARDWARE_CONFIG_CHANGED";
Wink Savillec29360a2014-07-13 05:17:28 -07005247 case RIL_UNSOL_DC_RT_INFO_CHANGED: return "UNSOL_DC_RT_INFO_CHANGED";
Naveen Kallaa65a16a2014-07-31 16:48:31 -07005248 case RIL_REQUEST_SHUTDOWN: return "SHUTDOWN";
Wink Saville8b4e4f72014-10-17 15:01:45 -07005249 case RIL_UNSOL_RADIO_CAPABILITY: return "RIL_UNSOL_RADIO_CAPABILITY";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005250 default: return "<unknown request>";
5251 }
5252}
5253
Etan Cohend3652192014-06-20 08:28:44 -07005254const char *
5255rilSocketIdToString(RIL_SOCKET_ID socket_id)
5256{
5257 switch(socket_id) {
5258 case RIL_SOCKET_1:
5259 return "RIL_SOCKET_1";
5260#if (SIM_COUNT >= 2)
5261 case RIL_SOCKET_2:
5262 return "RIL_SOCKET_2";
5263#endif
5264#if (SIM_COUNT >= 3)
5265 case RIL_SOCKET_3:
5266 return "RIL_SOCKET_3";
5267#endif
5268#if (SIM_COUNT >= 4)
5269 case RIL_SOCKET_4:
5270 return "RIL_SOCKET_4";
5271#endif
5272 default:
5273 return "not a valid RIL";
5274 }
5275}
5276
Sanket Padawe4c05f352016-01-26 16:19:00 -08005277/*
5278 * Returns true for a debuggable build.
5279 */
5280static bool isDebuggable() {
5281 char debuggable[PROP_VALUE_MAX];
5282 property_get("ro.debuggable", debuggable, "0");
5283 if (strcmp(debuggable, "1") == 0) {
5284 return true;
5285 }
5286 return false;
5287}
5288
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005289} /* namespace android */
Dheeraj Shetty27976c42014-07-02 21:27:57 +02005290
5291void rilEventAddWakeup_helper(struct ril_event *ev) {
5292 android::rilEventAddWakeup(ev);
5293}
5294
5295void listenCallback_helper(int fd, short flags, void *param) {
5296 android::listenCallback(fd, flags, param);
5297}
5298
5299int blockingWrite_helper(int fd, void *buffer, size_t len) {
5300 return android::blockingWrite(fd, buffer, len);
5301}