blob: 8cb66ac2af8e7a5521d1597e5a388d7433b15ccd [file] [log] [blame]
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001/* //device/libs/telephony/ril.cpp
2**
3** Copyright 2006, The Android Open Source Project
4**
Wink Saville7f856802009-06-09 10:23:37 -07005** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08008**
Wink Saville7f856802009-06-09 10:23:37 -07009** http://www.apache.org/licenses/LICENSE-2.0
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080010**
Wink Saville7f856802009-06-09 10:23:37 -070011** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080015** limitations under the License.
16*/
17
18#define LOG_TAG "RILC"
19
20#include <hardware_legacy/power.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080021#include <telephony/ril.h>
Wink Savillef4c4d362009-04-02 01:37:03 -070022#include <telephony/ril_cdma_sms.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080023#include <cutils/sockets.h>
24#include <cutils/jstring.h>
Dima Zavin622bf2b2013-05-22 11:29:34 -070025#include <telephony/record_stream.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080026#include <utils/Log.h>
27#include <utils/SystemClock.h>
28#include <pthread.h>
Mathias Agopian8a3c48c2009-05-19 19:11:50 -070029#include <binder/Parcel.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080030#include <cutils/jstring.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080031#include <sys/types.h>
Wink Saville18e4ab12013-04-07 17:31:04 -070032#include <sys/limits.h>
Sanket Padawe88cf6a52016-01-11 12:45:43 -080033#include <sys/system_properties.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080034#include <pwd.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080035#include <stdio.h>
36#include <stdlib.h>
37#include <stdarg.h>
38#include <string.h>
39#include <unistd.h>
40#include <fcntl.h>
41#include <time.h>
42#include <errno.h>
43#include <assert.h>
44#include <ctype.h>
45#include <alloca.h>
46#include <sys/un.h>
47#include <assert.h>
48#include <netinet/in.h>
49#include <cutils/properties.h>
Dheeraj Shetty27976c42014-07-02 21:27:57 +020050#include <RilSapSocket.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080051
Dheeraj Shetty27976c42014-07-02 21:27:57 +020052extern "C" void
53RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen);
Sanket Padawe6ff9a872016-01-27 15:09:12 -080054
55extern "C" void
56RIL_onRequestAck(RIL_Token t);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080057namespace android {
58
59#define PHONE_PROCESS "radio"
Dheeraj Shetty27976c42014-07-02 21:27:57 +020060#define BLUETOOTH_PROCESS "bluetooth"
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080061
62#define SOCKET_NAME_RIL "rild"
Etan Cohend3652192014-06-20 08:28:44 -070063#define SOCKET2_NAME_RIL "rild2"
64#define SOCKET3_NAME_RIL "rild3"
65#define SOCKET4_NAME_RIL "rild4"
66
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080067#define SOCKET_NAME_RIL_DEBUG "rild-debug"
68
69#define ANDROID_WAKE_LOCK_NAME "radio-interface"
70
Nathan Harolda0153392015-07-28 14:54:58 -070071#define ANDROID_WAKE_LOCK_SECS 0
72#define ANDROID_WAKE_LOCK_USECS 200000
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080073
74#define PROPERTY_RIL_IMPL "gsm.version.ril-impl"
75
76// match with constant in RIL.java
77#define MAX_COMMAND_BYTES (8 * 1024)
78
79// Basically: memset buffers that the client library
80// shouldn't be using anymore in an attempt to find
81// memory usage issues sooner.
82#define MEMSET_FREED 1
83
84#define NUM_ELEMS(a) (sizeof (a) / sizeof (a)[0])
85
Wink Savillef4c4d362009-04-02 01:37:03 -070086#define MIN(a,b) ((a)<(b) ? (a) : (b))
87
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080088/* Constants for response types */
89#define RESPONSE_SOLICITED 0
90#define RESPONSE_UNSOLICITED 1
Sanket Padawe6ff9a872016-01-27 15:09:12 -080091#define RESPONSE_SOLICITED_ACK 2
92#define RESPONSE_SOLICITED_ACK_EXP 3
Sanket Padawed8c0b462016-02-03 11:46:02 -080093#define RESPONSE_UNSOLICITED_ACK_EXP 4
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080094
95/* Negative values for private RIL errno's */
96#define RIL_ERRNO_INVALID_RESPONSE -1
97
98// request, response, and unsolicited msg print macro
99#define PRINTBUF_SIZE 8096
100
Robert Greenwalt191e4dc2015-04-29 16:57:39 -0700101// Enable verbose logging
102#define VDBG 0
103
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800104// Enable RILC log
105#define RILC_LOG 0
106
107#if RILC_LOG
108 #define startRequest sprintf(printBuf, "(")
109 #define closeRequest sprintf(printBuf, "%s)", printBuf)
110 #define printRequest(token, req) \
Wink Saville8eb2a122012-11-19 16:05:13 -0800111 RLOGD("[%04d]> %s %s", token, requestToString(req), printBuf)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800112
113 #define startResponse sprintf(printBuf, "%s {", printBuf)
114 #define closeResponse sprintf(printBuf, "%s}", printBuf)
Wink Saville8eb2a122012-11-19 16:05:13 -0800115 #define printResponse RLOGD("%s", printBuf)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800116
117 #define clearPrintBuf printBuf[0] = 0
118 #define removeLastChar printBuf[strlen(printBuf)-1] = 0
119 #define appendPrintBuf(x...) sprintf(printBuf, x)
120#else
121 #define startRequest
122 #define closeRequest
123 #define printRequest(token, req)
124 #define startResponse
125 #define closeResponse
126 #define printResponse
127 #define clearPrintBuf
128 #define removeLastChar
129 #define appendPrintBuf(x...)
130#endif
131
132enum WakeType {DONT_WAKE, WAKE_PARTIAL};
133
134typedef struct {
135 int requestNumber;
136 void (*dispatchFunction) (Parcel &p, struct RequestInfo *pRI);
137 int(*responseFunction) (Parcel &p, void *response, size_t responselen);
138} CommandInfo;
139
140typedef struct {
141 int requestNumber;
142 int (*responseFunction) (Parcel &p, void *response, size_t responselen);
143 WakeType wakeType;
144} UnsolResponseInfo;
145
146typedef struct RequestInfo {
Wink Saville7f856802009-06-09 10:23:37 -0700147 int32_t token; //this is not RIL_Token
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800148 CommandInfo *pCI;
149 struct RequestInfo *p_next;
150 char cancelled;
151 char local; // responses to local commands do not go back to command process
Etan Cohend3652192014-06-20 08:28:44 -0700152 RIL_SOCKET_ID socket_id;
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800153 int wasAckSent; // Indicates whether an ack was sent earlier
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800154} RequestInfo;
155
Wink Saville3d54e742009-05-18 18:00:44 -0700156typedef struct UserCallbackInfo {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800157 RIL_TimedCallback p_callback;
158 void *userParam;
159 struct ril_event event;
160 struct UserCallbackInfo *p_next;
161} UserCallbackInfo;
162
Etan Cohend3652192014-06-20 08:28:44 -0700163extern "C" const char * requestToString(int request);
164extern "C" const char * failCauseToString(RIL_Errno);
165extern "C" const char * callStateToString(RIL_CallState);
166extern "C" const char * radioStateToString(RIL_RadioState);
167extern "C" const char * rilSocketIdToString(RIL_SOCKET_ID socket_id);
168
169extern "C"
170char rild[MAX_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800171/*******************************************************************/
172
173RIL_RadioFunctions s_callbacks = {0, NULL, NULL, NULL, NULL, NULL};
174static int s_registerCalled = 0;
175
176static pthread_t s_tid_dispatch;
177static pthread_t s_tid_reader;
178static int s_started = 0;
179
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800180static int s_fdDebug = -1;
Etan Cohend3652192014-06-20 08:28:44 -0700181static int s_fdDebug_socket2 = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800182
183static int s_fdWakeupRead;
184static int s_fdWakeupWrite;
185
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800186int s_wakelock_count = 0;
187
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800188static struct ril_event s_commands_event;
189static struct ril_event s_wakeupfd_event;
190static struct ril_event s_listen_event;
Etan Cohend3652192014-06-20 08:28:44 -0700191static SocketListenParam s_ril_param_socket;
192
193static pthread_mutex_t s_pendingRequestsMutex = PTHREAD_MUTEX_INITIALIZER;
194static pthread_mutex_t s_writeMutex = PTHREAD_MUTEX_INITIALIZER;
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800195static pthread_mutex_t s_wakeLockCountMutex = PTHREAD_MUTEX_INITIALIZER;
Etan Cohend3652192014-06-20 08:28:44 -0700196static RequestInfo *s_pendingRequests = NULL;
197
198#if (SIM_COUNT >= 2)
199static struct ril_event s_commands_event_socket2;
200static struct ril_event s_listen_event_socket2;
201static SocketListenParam s_ril_param_socket2;
202
203static pthread_mutex_t s_pendingRequestsMutex_socket2 = PTHREAD_MUTEX_INITIALIZER;
204static pthread_mutex_t s_writeMutex_socket2 = PTHREAD_MUTEX_INITIALIZER;
205static RequestInfo *s_pendingRequests_socket2 = NULL;
206#endif
207
208#if (SIM_COUNT >= 3)
209static struct ril_event s_commands_event_socket3;
210static struct ril_event s_listen_event_socket3;
211static SocketListenParam s_ril_param_socket3;
212
213static pthread_mutex_t s_pendingRequestsMutex_socket3 = PTHREAD_MUTEX_INITIALIZER;
214static pthread_mutex_t s_writeMutex_socket3 = PTHREAD_MUTEX_INITIALIZER;
215static RequestInfo *s_pendingRequests_socket3 = NULL;
216#endif
217
218#if (SIM_COUNT >= 4)
219static struct ril_event s_commands_event_socket4;
220static struct ril_event s_listen_event_socket4;
221static SocketListenParam s_ril_param_socket4;
222
223static pthread_mutex_t s_pendingRequestsMutex_socket4 = PTHREAD_MUTEX_INITIALIZER;
224static pthread_mutex_t s_writeMutex_socket4 = PTHREAD_MUTEX_INITIALIZER;
225static RequestInfo *s_pendingRequests_socket4 = NULL;
226#endif
227
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800228static struct ril_event s_wake_timeout_event;
229static struct ril_event s_debug_event;
230
231
Nathan Harolda0153392015-07-28 14:54:58 -0700232static const struct timeval TIMEVAL_WAKE_TIMEOUT = {ANDROID_WAKE_LOCK_SECS,ANDROID_WAKE_LOCK_USECS};
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800233
Etan Cohend3652192014-06-20 08:28:44 -0700234
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800235static pthread_mutex_t s_startupMutex = PTHREAD_MUTEX_INITIALIZER;
236static pthread_cond_t s_startupCond = PTHREAD_COND_INITIALIZER;
237
238static pthread_mutex_t s_dispatchMutex = PTHREAD_MUTEX_INITIALIZER;
239static pthread_cond_t s_dispatchCond = PTHREAD_COND_INITIALIZER;
240
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800241static RequestInfo *s_toDispatchHead = NULL;
242static RequestInfo *s_toDispatchTail = NULL;
243
244static UserCallbackInfo *s_last_wake_timeout_info = NULL;
245
246static void *s_lastNITZTimeData = NULL;
247static size_t s_lastNITZTimeDataSize;
248
249#if RILC_LOG
250 static char printBuf[PRINTBUF_SIZE];
251#endif
252
253/*******************************************************************/
Etan Cohend3652192014-06-20 08:28:44 -0700254static int sendResponse (Parcel &p, RIL_SOCKET_ID socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800255
256static void dispatchVoid (Parcel& p, RequestInfo *pRI);
257static void dispatchString (Parcel& p, RequestInfo *pRI);
258static void dispatchStrings (Parcel& p, RequestInfo *pRI);
259static void dispatchInts (Parcel& p, RequestInfo *pRI);
260static void dispatchDial (Parcel& p, RequestInfo *pRI);
261static void dispatchSIM_IO (Parcel& p, RequestInfo *pRI);
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800262static void dispatchSIM_APDU (Parcel& p, RequestInfo *pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800263static void dispatchCallForward(Parcel& p, RequestInfo *pRI);
264static void dispatchRaw(Parcel& p, RequestInfo *pRI);
265static void dispatchSmsWrite (Parcel &p, RequestInfo *pRI);
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -0700266static void dispatchDataCall (Parcel& p, RequestInfo *pRI);
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800267static void dispatchVoiceRadioTech (Parcel& p, RequestInfo *pRI);
Sungmin Choi75697532013-04-26 15:04:45 -0700268static void dispatchSetInitialAttachApn (Parcel& p, RequestInfo *pRI);
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800269static void dispatchCdmaSubscriptionSource (Parcel& p, RequestInfo *pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800270
Wink Savillef4c4d362009-04-02 01:37:03 -0700271static void dispatchCdmaSms(Parcel &p, RequestInfo *pRI);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -0700272static void dispatchImsSms(Parcel &p, RequestInfo *pRI);
273static void dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
274static void dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
Wink Savillef4c4d362009-04-02 01:37:03 -0700275static void dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI);
Wink Savillea592eeb2009-05-22 13:26:36 -0700276static void dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI);
Wink Savillef4c4d362009-04-02 01:37:03 -0700277static void dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI);
278static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI);
Jake Hamby8a4a2332014-01-15 13:12:05 -0800279static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI);
280static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI);
Etan Cohend3652192014-06-20 08:28:44 -0700281static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI);
Amit Mahajan90530a62014-07-01 15:54:08 -0700282static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI);
Amit Mahajanc796e222014-08-13 16:54:01 +0000283static void dispatchDataProfile(Parcel &p, RequestInfo *pRI);
Wink Saville8b4e4f72014-10-17 15:01:45 -0700284static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800285static int responseInts(Parcel &p, void *response, size_t responselen);
Chao Liu548a81e2015-05-14 16:13:46 -0700286static int responseFailCause(Parcel &p, void *response, size_t responselen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800287static int responseStrings(Parcel &p, void *response, size_t responselen);
288static int responseString(Parcel &p, void *response, size_t responselen);
289static int responseVoid(Parcel &p, void *response, size_t responselen);
290static int responseCallList(Parcel &p, void *response, size_t responselen);
291static int responseSMS(Parcel &p, void *response, size_t responselen);
292static int responseSIM_IO(Parcel &p, void *response, size_t responselen);
293static int responseCallForwards(Parcel &p, void *response, size_t responselen);
Wink Savillef4c4d362009-04-02 01:37:03 -0700294static int responseDataCallList(Parcel &p, void *response, size_t responselen);
Wink Saville43808972011-01-13 17:39:51 -0800295static int responseSetupDataCall(Parcel &p, void *response, size_t responselen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800296static int responseRaw(Parcel &p, void *response, size_t responselen);
297static int responseSsn(Parcel &p, void *response, size_t responselen);
Wink Savillef4c4d362009-04-02 01:37:03 -0700298static int responseSimStatus(Parcel &p, void *response, size_t responselen);
Wink Savillea592eeb2009-05-22 13:26:36 -0700299static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen);
300static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen);
Wink Savillef4c4d362009-04-02 01:37:03 -0700301static int responseCdmaSms(Parcel &p, void *response, size_t responselen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800302static int responseCellList(Parcel &p, void *response, size_t responselen);
Wink Saville3d54e742009-05-18 18:00:44 -0700303static int responseCdmaInformationRecords(Parcel &p,void *response, size_t responselen);
304static int responseRilSignalStrength(Parcel &p,void *response, size_t responselen);
305static int responseCallRing(Parcel &p, void *response, size_t responselen);
306static int responseCdmaSignalInfoRecord(Parcel &p,void *response, size_t responselen);
307static int responseCdmaCallWaiting(Parcel &p,void *response, size_t responselen);
Alex Yakavenka45e740e2012-01-31 11:48:27 -0800308static int responseSimRefresh(Parcel &p, void *response, size_t responselen);
Wink Saville8a9e0212013-04-09 12:11:38 -0700309static int responseCellInfoList(Parcel &p, void *response, size_t responselen);
Etan Cohend3652192014-06-20 08:28:44 -0700310static int responseHardwareConfig(Parcel &p, void *response, size_t responselen);
Wink Savillec29360a2014-07-13 05:17:28 -0700311static int responseDcRtInfo(Parcel &p, void *response, size_t responselen);
Wink Saville8b4e4f72014-10-17 15:01:45 -0700312static int responseRadioCapability(Parcel &p, void *response, size_t responselen);
Amit Mahajan54563d32014-11-22 00:54:49 +0000313static int responseSSData(Parcel &p, void *response, size_t responselen);
fengluf7408292015-04-14 14:53:55 -0700314static int responseLceStatus(Parcel &p, void *response, size_t responselen);
315static int responseLceData(Parcel &p, void *response, size_t responselen);
Prerepa Viswanadham73157492015-05-28 00:37:32 -0700316static int responseActivityData(Parcel &p, void *response, size_t responselen);
Amit Mahajan54563d32014-11-22 00:54:49 +0000317
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800318static int decodeVoiceRadioTechnology (RIL_RadioState radioState);
319static int decodeCdmaSubscriptionSource (RIL_RadioState radioState);
320static RIL_RadioState processRadioState(RIL_RadioState newRadioState);
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800321static void grabPartialWakeLock();
322static void releaseWakeLock();
323static void wakeTimeoutCallback(void *);
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800324
Amit Mahajan54563d32014-11-22 00:54:49 +0000325static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType);
326
Sanket Padawe88cf6a52016-01-11 12:45:43 -0800327static bool isDebuggable();
328
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800329#ifdef RIL_SHLIB
Etan Cohend3652192014-06-20 08:28:44 -0700330#if defined(ANDROID_MULTI_SIM)
Vinit Deshpande1b1ec2d2015-04-15 13:31:05 -0700331extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Etan Cohend3652192014-06-20 08:28:44 -0700332 size_t datalen, RIL_SOCKET_ID socket_id);
333#else
Vinit Deshpande1b1ec2d2015-04-15 13:31:05 -0700334extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800335 size_t datalen);
336#endif
Etan Cohend3652192014-06-20 08:28:44 -0700337#endif
338
339#if defined(ANDROID_MULTI_SIM)
340#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c), (d))
341#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d), (e))
342#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest(a)
343#else
344#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c))
345#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d))
346#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest()
347#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800348
Wink Saville7f856802009-06-09 10:23:37 -0700349static UserCallbackInfo * internalRequestTimedCallback
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -0700350 (RIL_TimedCallback callback, void *param,
351 const struct timeval *relativeTime);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800352
353/** Index == requestNumber */
354static CommandInfo s_commands[] = {
355#include "ril_commands.h"
356};
357
358static UnsolResponseInfo s_unsolResponses[] = {
359#include "ril_unsol_commands.h"
360};
361
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800362/* For older RILs that do not support new commands RIL_REQUEST_VOICE_RADIO_TECH and
363 RIL_UNSOL_VOICE_RADIO_TECH_CHANGED messages, decode the voice radio tech from
364 radio state message and store it. Every time there is a change in Radio State
365 check to see if voice radio tech changes and notify telephony
366 */
367int voiceRadioTech = -1;
368
369/* For older RILs that do not support new commands RIL_REQUEST_GET_CDMA_SUBSCRIPTION_SOURCE
370 and RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED messages, decode the subscription
371 source from radio state and store it. Every time there is a change in Radio State
372 check to see if subscription source changed and notify telephony
373 */
374int cdmaSubscriptionSource = -1;
375
376/* For older RILs that do not send RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, decode the
377 SIM/RUIM state from radio state and store it. Every time there is a change in Radio State,
378 check to see if SIM/RUIM status changed and notify telephony
379 */
380int simRuimStatus = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800381
Etan Cohend3652192014-06-20 08:28:44 -0700382static char * RIL_getRilSocketName() {
383 return rild;
384}
385
386extern "C"
Dheeraj Shetty27976c42014-07-02 21:27:57 +0200387void RIL_setRilSocketName(const char * s) {
Etan Cohend3652192014-06-20 08:28:44 -0700388 strncpy(rild, s, MAX_SOCKET_NAME_LENGTH);
389}
390
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800391static char *
Wink Savillef4c4d362009-04-02 01:37:03 -0700392strdupReadString(Parcel &p) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800393 size_t stringlen;
394 const char16_t *s16;
Wink Saville7f856802009-06-09 10:23:37 -0700395
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800396 s16 = p.readString16Inplace(&stringlen);
Wink Saville7f856802009-06-09 10:23:37 -0700397
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800398 return strndup16to8(s16, stringlen);
399}
400
Wink Saville8b4e4f72014-10-17 15:01:45 -0700401static status_t
402readStringFromParcelInplace(Parcel &p, char *str, size_t maxLen) {
403 size_t s16Len;
404 const char16_t *s16;
405
406 s16 = p.readString16Inplace(&s16Len);
407 if (s16 == NULL) {
408 return NO_MEMORY;
409 }
410 size_t strLen = strnlen16to8(s16, s16Len);
411 if ((strLen + 1) > maxLen) {
412 return NO_MEMORY;
413 }
414 if (strncpy16to8(str, s16, strLen) == NULL) {
415 return NO_MEMORY;
416 } else {
417 return NO_ERROR;
418 }
419}
420
Wink Savillef4c4d362009-04-02 01:37:03 -0700421static void writeStringToParcel(Parcel &p, const char *s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800422 char16_t *s16;
423 size_t s16_len;
424 s16 = strdup8to16(s, &s16_len);
425 p.writeString16(s16, s16_len);
426 free(s16);
427}
428
429
430static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700431memsetString (char *s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800432 if (s != NULL) {
433 memset (s, 0, strlen(s));
434 }
435}
436
437void nullParcelReleaseFunction (const uint8_t* data, size_t dataSize,
438 const size_t* objects, size_t objectsSize,
Wink Savillef4c4d362009-04-02 01:37:03 -0700439 void* cookie) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800440 // do nothing -- the data reference lives longer than the Parcel object
441}
442
Wink Saville7f856802009-06-09 10:23:37 -0700443/**
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800444 * To be called from dispatch thread
445 * Issue a single local request, ensuring that the response
Wink Saville7f856802009-06-09 10:23:37 -0700446 * is not sent back up to the command process
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800447 */
448static void
Etan Cohend3652192014-06-20 08:28:44 -0700449issueLocalRequest(int request, void *data, int len, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800450 RequestInfo *pRI;
451 int ret;
Etan Cohend3652192014-06-20 08:28:44 -0700452 /* Hook for current context */
453 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
454 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
455 /* pendingRequestsHook refer to &s_pendingRequests */
456 RequestInfo** pendingRequestsHook = &s_pendingRequests;
457
458#if (SIM_COUNT == 2)
459 if (socket_id == RIL_SOCKET_2) {
460 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
461 pendingRequestsHook = &s_pendingRequests_socket2;
462 }
463#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800464
465 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
466
467 pRI->local = 1;
468 pRI->token = 0xffffffff; // token is not used in this context
469 pRI->pCI = &(s_commands[request]);
Etan Cohend3652192014-06-20 08:28:44 -0700470 pRI->socket_id = socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800471
Etan Cohend3652192014-06-20 08:28:44 -0700472 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800473 assert (ret == 0);
474
Etan Cohend3652192014-06-20 08:28:44 -0700475 pRI->p_next = *pendingRequestsHook;
476 *pendingRequestsHook = pRI;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800477
Etan Cohend3652192014-06-20 08:28:44 -0700478 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800479 assert (ret == 0);
480
Wink Saville8eb2a122012-11-19 16:05:13 -0800481 RLOGD("C[locl]> %s", requestToString(request));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800482
Etan Cohend3652192014-06-20 08:28:44 -0700483 CALL_ONREQUEST(request, data, len, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800484}
485
486
487
488static int
Etan Cohend3652192014-06-20 08:28:44 -0700489processCommandBuffer(void *buffer, size_t buflen, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800490 Parcel p;
491 status_t status;
492 int32_t request;
493 int32_t token;
494 RequestInfo *pRI;
495 int ret;
Etan Cohend3652192014-06-20 08:28:44 -0700496 /* Hook for current context */
497 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
498 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
499 /* pendingRequestsHook refer to &s_pendingRequests */
500 RequestInfo** pendingRequestsHook = &s_pendingRequests;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800501
502 p.setData((uint8_t *) buffer, buflen);
503
504 // status checked at end
505 status = p.readInt32(&request);
506 status = p.readInt32 (&token);
507
Etan Cohend3652192014-06-20 08:28:44 -0700508#if (SIM_COUNT >= 2)
509 if (socket_id == RIL_SOCKET_2) {
510 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
511 pendingRequestsHook = &s_pendingRequests_socket2;
512 }
513#if (SIM_COUNT >= 3)
514 else if (socket_id == RIL_SOCKET_3) {
515 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
516 pendingRequestsHook = &s_pendingRequests_socket3;
517 }
518#endif
519#if (SIM_COUNT >= 4)
520 else if (socket_id == RIL_SOCKET_4) {
521 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
522 pendingRequestsHook = &s_pendingRequests_socket4;
523 }
524#endif
525#endif
526
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800527 if (status != NO_ERROR) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800528 RLOGE("invalid request block");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800529 return 0;
530 }
531
532 if (request < 1 || request >= (int32_t)NUM_ELEMS(s_commands)) {
Etan Cohend3652192014-06-20 08:28:44 -0700533 Parcel pErr;
Wink Saville8eb2a122012-11-19 16:05:13 -0800534 RLOGE("unsupported request code %d token %d", request, token);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800535 // FIXME this should perhaps return a response
Etan Cohend3652192014-06-20 08:28:44 -0700536 pErr.writeInt32 (RESPONSE_SOLICITED);
537 pErr.writeInt32 (token);
538 pErr.writeInt32 (RIL_E_GENERIC_FAILURE);
539
540 sendResponse(pErr, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800541 return 0;
542 }
543
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800544 // Received an Ack for the previous result sent to RIL.java,
545 // so release wakelock and exit
546 if (request == RIL_RESPONSE_ACKNOWLEDGEMENT) {
547 releaseWakeLock();
548 return 0;
549 }
550
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800551
552 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
553
554 pRI->token = token;
555 pRI->pCI = &(s_commands[request]);
Etan Cohend3652192014-06-20 08:28:44 -0700556 pRI->socket_id = socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800557
Etan Cohend3652192014-06-20 08:28:44 -0700558 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800559 assert (ret == 0);
560
Etan Cohend3652192014-06-20 08:28:44 -0700561 pRI->p_next = *pendingRequestsHook;
562 *pendingRequestsHook = pRI;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800563
Etan Cohend3652192014-06-20 08:28:44 -0700564 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800565 assert (ret == 0);
566
567/* sLastDispatchedToken = token; */
568
Wink Saville7f856802009-06-09 10:23:37 -0700569 pRI->pCI->dispatchFunction(p, pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800570
571 return 0;
572}
573
574static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700575invalidCommandBlock (RequestInfo *pRI) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800576 RLOGE("invalid command block for token %d request %s",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800577 pRI->token, requestToString(pRI->pCI->requestNumber));
578}
579
580/** Callee expects NULL */
Wink Saville7f856802009-06-09 10:23:37 -0700581static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700582dispatchVoid (Parcel& p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800583 clearPrintBuf;
584 printRequest(pRI->token, pRI->pCI->requestNumber);
Etan Cohend3652192014-06-20 08:28:44 -0700585 CALL_ONREQUEST(pRI->pCI->requestNumber, NULL, 0, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800586}
587
588/** Callee expects const char * */
589static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700590dispatchString (Parcel& p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800591 status_t status;
592 size_t datalen;
593 size_t stringlen;
594 char *string8 = NULL;
595
596 string8 = strdupReadString(p);
597
598 startRequest;
599 appendPrintBuf("%s%s", printBuf, string8);
600 closeRequest;
601 printRequest(pRI->token, pRI->pCI->requestNumber);
602
Etan Cohend3652192014-06-20 08:28:44 -0700603 CALL_ONREQUEST(pRI->pCI->requestNumber, string8,
604 sizeof(char *), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800605
606#ifdef MEMSET_FREED
607 memsetString(string8);
608#endif
609
610 free(string8);
611 return;
612invalid:
613 invalidCommandBlock(pRI);
614 return;
615}
616
617/** Callee expects const char ** */
618static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700619dispatchStrings (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800620 int32_t countStrings;
621 status_t status;
622 size_t datalen;
623 char **pStrings;
624
625 status = p.readInt32 (&countStrings);
626
627 if (status != NO_ERROR) {
628 goto invalid;
629 }
630
631 startRequest;
632 if (countStrings == 0) {
633 // just some non-null pointer
634 pStrings = (char **)alloca(sizeof(char *));
635 datalen = 0;
636 } else if (((int)countStrings) == -1) {
637 pStrings = NULL;
638 datalen = 0;
639 } else {
640 datalen = sizeof(char *) * countStrings;
Wink Saville7f856802009-06-09 10:23:37 -0700641
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800642 pStrings = (char **)alloca(datalen);
643
644 for (int i = 0 ; i < countStrings ; i++) {
645 pStrings[i] = strdupReadString(p);
646 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
647 }
648 }
649 removeLastChar;
650 closeRequest;
651 printRequest(pRI->token, pRI->pCI->requestNumber);
652
Etan Cohend3652192014-06-20 08:28:44 -0700653 CALL_ONREQUEST(pRI->pCI->requestNumber, pStrings, datalen, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800654
655 if (pStrings != NULL) {
656 for (int i = 0 ; i < countStrings ; i++) {
657#ifdef MEMSET_FREED
658 memsetString (pStrings[i]);
659#endif
660 free(pStrings[i]);
661 }
662
663#ifdef MEMSET_FREED
664 memset(pStrings, 0, datalen);
665#endif
666 }
Wink Saville7f856802009-06-09 10:23:37 -0700667
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800668 return;
669invalid:
670 invalidCommandBlock(pRI);
671 return;
672}
673
674/** Callee expects const int * */
675static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700676dispatchInts (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800677 int32_t count;
678 status_t status;
679 size_t datalen;
680 int *pInts;
681
682 status = p.readInt32 (&count);
683
684 if (status != NO_ERROR || count == 0) {
685 goto invalid;
686 }
687
688 datalen = sizeof(int) * count;
689 pInts = (int *)alloca(datalen);
690
691 startRequest;
692 for (int i = 0 ; i < count ; i++) {
693 int32_t t;
694
695 status = p.readInt32(&t);
696 pInts[i] = (int)t;
697 appendPrintBuf("%s%d,", printBuf, t);
698
699 if (status != NO_ERROR) {
700 goto invalid;
701 }
702 }
703 removeLastChar;
704 closeRequest;
705 printRequest(pRI->token, pRI->pCI->requestNumber);
706
Etan Cohend3652192014-06-20 08:28:44 -0700707 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<int *>(pInts),
708 datalen, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800709
710#ifdef MEMSET_FREED
711 memset(pInts, 0, datalen);
712#endif
713
714 return;
715invalid:
716 invalidCommandBlock(pRI);
717 return;
718}
719
720
Wink Saville7f856802009-06-09 10:23:37 -0700721/**
722 * Callee expects const RIL_SMS_WriteArgs *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800723 * Payload is:
724 * int32_t status
725 * String pdu
726 */
727static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700728dispatchSmsWrite (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800729 RIL_SMS_WriteArgs args;
730 int32_t t;
731 status_t status;
732
Mark Salyzyndba25612015-04-09 07:18:35 -0700733 RLOGD("dispatchSmsWrite");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800734 memset (&args, 0, sizeof(args));
735
736 status = p.readInt32(&t);
737 args.status = (int)t;
738
739 args.pdu = strdupReadString(p);
740
741 if (status != NO_ERROR || args.pdu == NULL) {
742 goto invalid;
743 }
744
745 args.smsc = strdupReadString(p);
746
747 startRequest;
748 appendPrintBuf("%s%d,%s,smsc=%s", printBuf, args.status,
749 (char*)args.pdu, (char*)args.smsc);
750 closeRequest;
751 printRequest(pRI->token, pRI->pCI->requestNumber);
Wink Saville7f856802009-06-09 10:23:37 -0700752
Etan Cohend3652192014-06-20 08:28:44 -0700753 CALL_ONREQUEST(pRI->pCI->requestNumber, &args, sizeof(args), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800754
755#ifdef MEMSET_FREED
756 memsetString (args.pdu);
757#endif
758
759 free (args.pdu);
Wink Saville7f856802009-06-09 10:23:37 -0700760
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800761#ifdef MEMSET_FREED
762 memset(&args, 0, sizeof(args));
763#endif
764
765 return;
766invalid:
767 invalidCommandBlock(pRI);
768 return;
769}
770
Wink Saville7f856802009-06-09 10:23:37 -0700771/**
772 * Callee expects const RIL_Dial *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800773 * Payload is:
774 * String address
775 * int32_t clir
776 */
777static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700778dispatchDial (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800779 RIL_Dial dial;
Wink Saville74fa3882009-12-22 15:35:41 -0800780 RIL_UUS_Info uusInfo;
Wink Saville7bce0822010-01-08 15:20:12 -0800781 int32_t sizeOfDial;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800782 int32_t t;
Wink Saville74fa3882009-12-22 15:35:41 -0800783 int32_t uusPresent;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800784 status_t status;
785
Mark Salyzyndba25612015-04-09 07:18:35 -0700786 RLOGD("dispatchDial");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800787 memset (&dial, 0, sizeof(dial));
788
789 dial.address = strdupReadString(p);
790
791 status = p.readInt32(&t);
792 dial.clir = (int)t;
793
794 if (status != NO_ERROR || dial.address == NULL) {
795 goto invalid;
796 }
797
Wink Saville3a4840b2010-04-07 13:29:58 -0700798 if (s_callbacks.version < 3) { // Remove when partners upgrade to version 3
Wink Saville74fa3882009-12-22 15:35:41 -0800799 uusPresent = 0;
Wink Saville7bce0822010-01-08 15:20:12 -0800800 sizeOfDial = sizeof(dial) - sizeof(RIL_UUS_Info *);
Wink Saville74fa3882009-12-22 15:35:41 -0800801 } else {
802 status = p.readInt32(&uusPresent);
803
804 if (status != NO_ERROR) {
805 goto invalid;
806 }
807
808 if (uusPresent == 0) {
809 dial.uusInfo = NULL;
810 } else {
811 int32_t len;
812
813 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
814
815 status = p.readInt32(&t);
816 uusInfo.uusType = (RIL_UUS_Type) t;
817
818 status = p.readInt32(&t);
819 uusInfo.uusDcs = (RIL_UUS_DCS) t;
820
821 status = p.readInt32(&len);
822 if (status != NO_ERROR) {
823 goto invalid;
824 }
825
826 // The java code writes -1 for null arrays
827 if (((int) len) == -1) {
828 uusInfo.uusData = NULL;
829 len = 0;
830 } else {
831 uusInfo.uusData = (char*) p.readInplace(len);
832 }
833
834 uusInfo.uusLength = len;
835 dial.uusInfo = &uusInfo;
836 }
Wink Saville7bce0822010-01-08 15:20:12 -0800837 sizeOfDial = sizeof(dial);
Wink Saville74fa3882009-12-22 15:35:41 -0800838 }
839
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800840 startRequest;
841 appendPrintBuf("%snum=%s,clir=%d", printBuf, dial.address, dial.clir);
Wink Saville74fa3882009-12-22 15:35:41 -0800842 if (uusPresent) {
843 appendPrintBuf("%s,uusType=%d,uusDcs=%d,uusLen=%d", printBuf,
844 dial.uusInfo->uusType, dial.uusInfo->uusDcs,
845 dial.uusInfo->uusLength);
846 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800847 closeRequest;
848 printRequest(pRI->token, pRI->pCI->requestNumber);
849
Etan Cohend3652192014-06-20 08:28:44 -0700850 CALL_ONREQUEST(pRI->pCI->requestNumber, &dial, sizeOfDial, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800851
852#ifdef MEMSET_FREED
853 memsetString (dial.address);
854#endif
855
856 free (dial.address);
Wink Saville7f856802009-06-09 10:23:37 -0700857
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800858#ifdef MEMSET_FREED
Wink Saville74fa3882009-12-22 15:35:41 -0800859 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800860 memset(&dial, 0, sizeof(dial));
861#endif
862
863 return;
864invalid:
865 invalidCommandBlock(pRI);
866 return;
867}
868
Wink Saville7f856802009-06-09 10:23:37 -0700869/**
870 * Callee expects const RIL_SIM_IO *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800871 * Payload is:
872 * int32_t command
873 * int32_t fileid
874 * String path
875 * int32_t p1, p2, p3
Wink Saville7f856802009-06-09 10:23:37 -0700876 * String data
877 * String pin2
Wink Savillec0114b32011-02-18 10:14:07 -0800878 * String aidPtr
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800879 */
880static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700881dispatchSIM_IO (Parcel &p, RequestInfo *pRI) {
Wink Savillec0114b32011-02-18 10:14:07 -0800882 union RIL_SIM_IO {
883 RIL_SIM_IO_v6 v6;
884 RIL_SIM_IO_v5 v5;
885 } simIO;
886
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800887 int32_t t;
Wink Savillec0114b32011-02-18 10:14:07 -0800888 int size;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800889 status_t status;
890
Robert Greenwalt191e4dc2015-04-29 16:57:39 -0700891#if VDBG
Mark Salyzyndba25612015-04-09 07:18:35 -0700892 RLOGD("dispatchSIM_IO");
Robert Greenwalt191e4dc2015-04-29 16:57:39 -0700893#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800894 memset (&simIO, 0, sizeof(simIO));
895
Wink Saville7f856802009-06-09 10:23:37 -0700896 // note we only check status at the end
897
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800898 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800899 simIO.v6.command = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800900
901 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800902 simIO.v6.fileid = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800903
Wink Savillec0114b32011-02-18 10:14:07 -0800904 simIO.v6.path = strdupReadString(p);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800905
906 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800907 simIO.v6.p1 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800908
909 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800910 simIO.v6.p2 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800911
912 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800913 simIO.v6.p3 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800914
Wink Savillec0114b32011-02-18 10:14:07 -0800915 simIO.v6.data = strdupReadString(p);
916 simIO.v6.pin2 = strdupReadString(p);
917 simIO.v6.aidPtr = strdupReadString(p);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800918
919 startRequest;
Wink Savillec0114b32011-02-18 10:14:07 -0800920 appendPrintBuf("%scmd=0x%X,efid=0x%X,path=%s,%d,%d,%d,%s,pin2=%s,aid=%s", printBuf,
921 simIO.v6.command, simIO.v6.fileid, (char*)simIO.v6.path,
922 simIO.v6.p1, simIO.v6.p2, simIO.v6.p3,
923 (char*)simIO.v6.data, (char*)simIO.v6.pin2, simIO.v6.aidPtr);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800924 closeRequest;
925 printRequest(pRI->token, pRI->pCI->requestNumber);
Wink Saville7f856802009-06-09 10:23:37 -0700926
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800927 if (status != NO_ERROR) {
928 goto invalid;
929 }
930
Wink Savillec0114b32011-02-18 10:14:07 -0800931 size = (s_callbacks.version < 6) ? sizeof(simIO.v5) : sizeof(simIO.v6);
Etan Cohend3652192014-06-20 08:28:44 -0700932 CALL_ONREQUEST(pRI->pCI->requestNumber, &simIO, size, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800933
934#ifdef MEMSET_FREED
Wink Savillec0114b32011-02-18 10:14:07 -0800935 memsetString (simIO.v6.path);
936 memsetString (simIO.v6.data);
937 memsetString (simIO.v6.pin2);
938 memsetString (simIO.v6.aidPtr);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800939#endif
940
Wink Savillec0114b32011-02-18 10:14:07 -0800941 free (simIO.v6.path);
942 free (simIO.v6.data);
943 free (simIO.v6.pin2);
944 free (simIO.v6.aidPtr);
Wink Saville7f856802009-06-09 10:23:37 -0700945
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800946#ifdef MEMSET_FREED
947 memset(&simIO, 0, sizeof(simIO));
948#endif
949
950 return;
951invalid:
952 invalidCommandBlock(pRI);
953 return;
954}
955
956/**
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800957 * Callee expects const RIL_SIM_APDU *
958 * Payload is:
959 * int32_t sessionid
960 * int32_t cla
961 * int32_t instruction
962 * int32_t p1, p2, p3
963 * String data
964 */
965static void
966dispatchSIM_APDU (Parcel &p, RequestInfo *pRI) {
967 int32_t t;
968 status_t status;
969 RIL_SIM_APDU apdu;
970
Robert Greenwalt191e4dc2015-04-29 16:57:39 -0700971#if VDBG
Mark Salyzyndba25612015-04-09 07:18:35 -0700972 RLOGD("dispatchSIM_APDU");
Robert Greenwalt191e4dc2015-04-29 16:57:39 -0700973#endif
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800974 memset (&apdu, 0, sizeof(RIL_SIM_APDU));
975
976 // Note we only check status at the end. Any single failure leads to
977 // subsequent reads filing.
978 status = p.readInt32(&t);
979 apdu.sessionid = (int)t;
980
981 status = p.readInt32(&t);
982 apdu.cla = (int)t;
983
984 status = p.readInt32(&t);
985 apdu.instruction = (int)t;
986
987 status = p.readInt32(&t);
988 apdu.p1 = (int)t;
989
990 status = p.readInt32(&t);
991 apdu.p2 = (int)t;
992
993 status = p.readInt32(&t);
994 apdu.p3 = (int)t;
995
996 apdu.data = strdupReadString(p);
997
998 startRequest;
999 appendPrintBuf("%ssessionid=%d,cla=%d,ins=%d,p1=%d,p2=%d,p3=%d,data=%s",
1000 printBuf, apdu.sessionid, apdu.cla, apdu.instruction, apdu.p1, apdu.p2,
1001 apdu.p3, (char*)apdu.data);
1002 closeRequest;
1003 printRequest(pRI->token, pRI->pCI->requestNumber);
1004
1005 if (status != NO_ERROR) {
1006 goto invalid;
1007 }
1008
Etan Cohend3652192014-06-20 08:28:44 -07001009 CALL_ONREQUEST(pRI->pCI->requestNumber, &apdu, sizeof(RIL_SIM_APDU), pRI, pRI->socket_id);
Shishir Agrawal2458d8d2013-11-27 14:53:05 -08001010
1011#ifdef MEMSET_FREED
1012 memsetString(apdu.data);
1013#endif
1014 free(apdu.data);
1015
1016#ifdef MEMSET_FREED
1017 memset(&apdu, 0, sizeof(RIL_SIM_APDU));
1018#endif
1019
1020 return;
1021invalid:
1022 invalidCommandBlock(pRI);
1023 return;
1024}
1025
1026
1027/**
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001028 * Callee expects const RIL_CallForwardInfo *
1029 * Payload is:
1030 * int32_t status/action
1031 * int32_t reason
1032 * int32_t serviceCode
1033 * int32_t toa
1034 * String number (0 length -> null)
1035 * int32_t timeSeconds
1036 */
Wink Saville7f856802009-06-09 10:23:37 -07001037static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001038dispatchCallForward(Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001039 RIL_CallForwardInfo cff;
1040 int32_t t;
1041 status_t status;
1042
Mark Salyzyndba25612015-04-09 07:18:35 -07001043 RLOGD("dispatchCallForward");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001044 memset (&cff, 0, sizeof(cff));
1045
Wink Saville7f856802009-06-09 10:23:37 -07001046 // note we only check status at the end
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001047
1048 status = p.readInt32(&t);
1049 cff.status = (int)t;
Wink Saville7f856802009-06-09 10:23:37 -07001050
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001051 status = p.readInt32(&t);
1052 cff.reason = (int)t;
1053
1054 status = p.readInt32(&t);
1055 cff.serviceClass = (int)t;
1056
1057 status = p.readInt32(&t);
1058 cff.toa = (int)t;
1059
1060 cff.number = strdupReadString(p);
1061
1062 status = p.readInt32(&t);
1063 cff.timeSeconds = (int)t;
1064
1065 if (status != NO_ERROR) {
1066 goto invalid;
1067 }
1068
1069 // special case: number 0-length fields is null
1070
1071 if (cff.number != NULL && strlen (cff.number) == 0) {
1072 cff.number = NULL;
1073 }
1074
1075 startRequest;
1076 appendPrintBuf("%sstat=%d,reason=%d,serv=%d,toa=%d,%s,tout=%d", printBuf,
1077 cff.status, cff.reason, cff.serviceClass, cff.toa,
1078 (char*)cff.number, cff.timeSeconds);
1079 closeRequest;
1080 printRequest(pRI->token, pRI->pCI->requestNumber);
1081
Etan Cohend3652192014-06-20 08:28:44 -07001082 CALL_ONREQUEST(pRI->pCI->requestNumber, &cff, sizeof(cff), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001083
1084#ifdef MEMSET_FREED
1085 memsetString(cff.number);
1086#endif
1087
1088 free (cff.number);
1089
1090#ifdef MEMSET_FREED
1091 memset(&cff, 0, sizeof(cff));
1092#endif
1093
1094 return;
1095invalid:
1096 invalidCommandBlock(pRI);
1097 return;
1098}
1099
1100
Wink Saville7f856802009-06-09 10:23:37 -07001101static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001102dispatchRaw(Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001103 int32_t len;
1104 status_t status;
1105 const void *data;
1106
1107 status = p.readInt32(&len);
1108
1109 if (status != NO_ERROR) {
1110 goto invalid;
1111 }
1112
1113 // The java code writes -1 for null arrays
1114 if (((int)len) == -1) {
1115 data = NULL;
1116 len = 0;
Wink Saville7f856802009-06-09 10:23:37 -07001117 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001118
1119 data = p.readInplace(len);
1120
1121 startRequest;
1122 appendPrintBuf("%sraw_size=%d", printBuf, len);
1123 closeRequest;
1124 printRequest(pRI->token, pRI->pCI->requestNumber);
1125
Etan Cohend3652192014-06-20 08:28:44 -07001126 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<void *>(data), len, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001127
1128 return;
1129invalid:
1130 invalidCommandBlock(pRI);
1131 return;
1132}
1133
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001134static status_t
1135constructCdmaSms(Parcel &p, RequestInfo *pRI, RIL_CDMA_SMS_Message& rcsm) {
Wink Savillef4c4d362009-04-02 01:37:03 -07001136 int32_t t;
1137 uint8_t ut;
1138 status_t status;
1139 int32_t digitCount;
1140 int digitLimit;
Wink Saville7f856802009-06-09 10:23:37 -07001141
Wink Savillef4c4d362009-04-02 01:37:03 -07001142 memset(&rcsm, 0, sizeof(rcsm));
1143
1144 status = p.readInt32(&t);
1145 rcsm.uTeleserviceID = (int) t;
1146
1147 status = p.read(&ut,sizeof(ut));
1148 rcsm.bIsServicePresent = (uint8_t) ut;
1149
1150 status = p.readInt32(&t);
1151 rcsm.uServicecategory = (int) t;
1152
1153 status = p.readInt32(&t);
1154 rcsm.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1155
1156 status = p.readInt32(&t);
1157 rcsm.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1158
1159 status = p.readInt32(&t);
1160 rcsm.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1161
1162 status = p.readInt32(&t);
1163 rcsm.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1164
1165 status = p.read(&ut,sizeof(ut));
1166 rcsm.sAddress.number_of_digits= (uint8_t) ut;
1167
1168 digitLimit= MIN((rcsm.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
1169 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1170 status = p.read(&ut,sizeof(ut));
1171 rcsm.sAddress.digits[digitCount] = (uint8_t) ut;
1172 }
1173
Wink Saville7f856802009-06-09 10:23:37 -07001174 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001175 rcsm.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1176
Wink Saville7f856802009-06-09 10:23:37 -07001177 status = p.read(&ut,sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001178 rcsm.sSubAddress.odd = (uint8_t) ut;
1179
1180 status = p.read(&ut,sizeof(ut));
1181 rcsm.sSubAddress.number_of_digits = (uint8_t) ut;
1182
1183 digitLimit= MIN((rcsm.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
Wink Saville7f856802009-06-09 10:23:37 -07001184 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1185 status = p.read(&ut,sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001186 rcsm.sSubAddress.digits[digitCount] = (uint8_t) ut;
1187 }
1188
Wink Saville7f856802009-06-09 10:23:37 -07001189 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001190 rcsm.uBearerDataLen = (int) t;
1191
1192 digitLimit= MIN((rcsm.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
Wink Saville7f856802009-06-09 10:23:37 -07001193 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1194 status = p.read(&ut, sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001195 rcsm.aBearerData[digitCount] = (uint8_t) ut;
1196 }
1197
1198 if (status != NO_ERROR) {
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001199 return status;
Wink Savillef4c4d362009-04-02 01:37:03 -07001200 }
1201
1202 startRequest;
1203 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
Wink Saville1b5fd232009-04-22 14:50:00 -07001204 sAddress.digit_mode=%d, sAddress.Number_mode=%d, sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07001205 printBuf, rcsm.uTeleserviceID,rcsm.bIsServicePresent,rcsm.uServicecategory,
Wink Saville1b5fd232009-04-22 14:50:00 -07001206 rcsm.sAddress.digit_mode, rcsm.sAddress.number_mode,rcsm.sAddress.number_type);
Wink Savillef4c4d362009-04-02 01:37:03 -07001207 closeRequest;
Wink Saville7f856802009-06-09 10:23:37 -07001208
Wink Savillef4c4d362009-04-02 01:37:03 -07001209 printRequest(pRI->token, pRI->pCI->requestNumber);
1210
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001211 return status;
1212}
1213
1214static void
1215dispatchCdmaSms(Parcel &p, RequestInfo *pRI) {
1216 RIL_CDMA_SMS_Message rcsm;
1217
Mark Salyzyndba25612015-04-09 07:18:35 -07001218 RLOGD("dispatchCdmaSms");
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001219 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1220 goto invalid;
1221 }
1222
Etan Cohend3652192014-06-20 08:28:44 -07001223 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001224
1225#ifdef MEMSET_FREED
1226 memset(&rcsm, 0, sizeof(rcsm));
1227#endif
1228
1229 return;
1230
1231invalid:
1232 invalidCommandBlock(pRI);
1233 return;
1234}
1235
Wink Saville7f856802009-06-09 10:23:37 -07001236static void
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001237dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1238 RIL_IMS_SMS_Message rism;
1239 RIL_CDMA_SMS_Message rcsm;
1240
Mark Salyzyndba25612015-04-09 07:18:35 -07001241 RLOGD("dispatchImsCdmaSms: retry=%d, messageRef=%d", retry, messageRef);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001242
1243 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1244 goto invalid;
1245 }
1246 memset(&rism, 0, sizeof(rism));
1247 rism.tech = RADIO_TECH_3GPP2;
1248 rism.retry = retry;
1249 rism.messageRef = messageRef;
1250 rism.message.cdmaMessage = &rcsm;
1251
Etan Cohend3652192014-06-20 08:28:44 -07001252 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001253 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Etan Cohend3652192014-06-20 08:28:44 -07001254 +sizeof(rcsm),pRI, pRI->socket_id);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001255
1256#ifdef MEMSET_FREED
1257 memset(&rcsm, 0, sizeof(rcsm));
1258 memset(&rism, 0, sizeof(rism));
1259#endif
1260
1261 return;
1262
1263invalid:
1264 invalidCommandBlock(pRI);
1265 return;
1266}
1267
1268static void
1269dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1270 RIL_IMS_SMS_Message rism;
1271 int32_t countStrings;
1272 status_t status;
1273 size_t datalen;
1274 char **pStrings;
Mark Salyzyndba25612015-04-09 07:18:35 -07001275 RLOGD("dispatchImsGsmSms: retry=%d, messageRef=%d", retry, messageRef);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001276
1277 status = p.readInt32 (&countStrings);
1278
1279 if (status != NO_ERROR) {
1280 goto invalid;
1281 }
1282
1283 memset(&rism, 0, sizeof(rism));
1284 rism.tech = RADIO_TECH_3GPP;
1285 rism.retry = retry;
1286 rism.messageRef = messageRef;
1287
1288 startRequest;
Etan Cohen5d891b72014-02-27 17:25:17 -08001289 appendPrintBuf("%stech=%d, retry=%d, messageRef=%d, ", printBuf,
1290 (int)rism.tech, (int)rism.retry, rism.messageRef);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001291 if (countStrings == 0) {
1292 // just some non-null pointer
1293 pStrings = (char **)alloca(sizeof(char *));
1294 datalen = 0;
1295 } else if (((int)countStrings) == -1) {
1296 pStrings = NULL;
1297 datalen = 0;
1298 } else {
1299 datalen = sizeof(char *) * countStrings;
1300
1301 pStrings = (char **)alloca(datalen);
1302
1303 for (int i = 0 ; i < countStrings ; i++) {
1304 pStrings[i] = strdupReadString(p);
1305 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
1306 }
1307 }
1308 removeLastChar;
1309 closeRequest;
1310 printRequest(pRI->token, pRI->pCI->requestNumber);
1311
1312 rism.message.gsmMessage = pStrings;
Etan Cohend3652192014-06-20 08:28:44 -07001313 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001314 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Etan Cohend3652192014-06-20 08:28:44 -07001315 +datalen, pRI, pRI->socket_id);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001316
1317 if (pStrings != NULL) {
1318 for (int i = 0 ; i < countStrings ; i++) {
1319#ifdef MEMSET_FREED
1320 memsetString (pStrings[i]);
1321#endif
1322 free(pStrings[i]);
1323 }
1324
1325#ifdef MEMSET_FREED
1326 memset(pStrings, 0, datalen);
1327#endif
1328 }
1329
1330#ifdef MEMSET_FREED
1331 memset(&rism, 0, sizeof(rism));
1332#endif
1333 return;
1334invalid:
1335 ALOGE("dispatchImsGsmSms invalid block");
1336 invalidCommandBlock(pRI);
1337 return;
1338}
1339
1340static void
1341dispatchImsSms(Parcel &p, RequestInfo *pRI) {
1342 int32_t t;
1343 status_t status = p.readInt32(&t);
1344 RIL_RadioTechnologyFamily format;
1345 uint8_t retry;
1346 int32_t messageRef;
1347
Mark Salyzyndba25612015-04-09 07:18:35 -07001348 RLOGD("dispatchImsSms");
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001349 if (status != NO_ERROR) {
1350 goto invalid;
1351 }
1352 format = (RIL_RadioTechnologyFamily) t;
1353
1354 // read retry field
1355 status = p.read(&retry,sizeof(retry));
1356 if (status != NO_ERROR) {
1357 goto invalid;
1358 }
1359 // read messageRef field
1360 status = p.read(&messageRef,sizeof(messageRef));
1361 if (status != NO_ERROR) {
1362 goto invalid;
1363 }
1364
1365 if (RADIO_TECH_3GPP == format) {
1366 dispatchImsGsmSms(p, pRI, retry, messageRef);
1367 } else if (RADIO_TECH_3GPP2 == format) {
1368 dispatchImsCdmaSms(p, pRI, retry, messageRef);
1369 } else {
1370 ALOGE("requestImsSendSMS invalid format value =%d", format);
1371 }
1372
1373 return;
1374
1375invalid:
1376 invalidCommandBlock(pRI);
1377 return;
1378}
1379
1380static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001381dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI) {
1382 RIL_CDMA_SMS_Ack rcsa;
1383 int32_t t;
1384 status_t status;
1385 int32_t digitCount;
1386
Mark Salyzyndba25612015-04-09 07:18:35 -07001387 RLOGD("dispatchCdmaSmsAck");
Wink Savillef4c4d362009-04-02 01:37:03 -07001388 memset(&rcsa, 0, sizeof(rcsa));
1389
1390 status = p.readInt32(&t);
1391 rcsa.uErrorClass = (RIL_CDMA_SMS_ErrorClass) t;
1392
1393 status = p.readInt32(&t);
1394 rcsa.uSMSCauseCode = (int) t;
1395
1396 if (status != NO_ERROR) {
1397 goto invalid;
1398 }
1399
1400 startRequest;
Wink Saville1b5fd232009-04-22 14:50:00 -07001401 appendPrintBuf("%suErrorClass=%d, uTLStatus=%d, ",
1402 printBuf, rcsa.uErrorClass, rcsa.uSMSCauseCode);
Wink Savillef4c4d362009-04-02 01:37:03 -07001403 closeRequest;
1404
1405 printRequest(pRI->token, pRI->pCI->requestNumber);
1406
Etan Cohend3652192014-06-20 08:28:44 -07001407 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsa, sizeof(rcsa),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001408
1409#ifdef MEMSET_FREED
1410 memset(&rcsa, 0, sizeof(rcsa));
1411#endif
1412
1413 return;
1414
1415invalid:
1416 invalidCommandBlock(pRI);
1417 return;
1418}
1419
Wink Savillea592eeb2009-05-22 13:26:36 -07001420static void
1421dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1422 int32_t t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001423 status_t status;
Wink Savillea592eeb2009-05-22 13:26:36 -07001424 int32_t num;
Wink Savillef4c4d362009-04-02 01:37:03 -07001425
Wink Savillea592eeb2009-05-22 13:26:36 -07001426 status = p.readInt32(&num);
Wink Savillef4c4d362009-04-02 01:37:03 -07001427 if (status != NO_ERROR) {
1428 goto invalid;
1429 }
1430
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001431 {
1432 RIL_GSM_BroadcastSmsConfigInfo gsmBci[num];
1433 RIL_GSM_BroadcastSmsConfigInfo *gsmBciPtrs[num];
Wink Savillea592eeb2009-05-22 13:26:36 -07001434
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001435 startRequest;
1436 for (int i = 0 ; i < num ; i++ ) {
1437 gsmBciPtrs[i] = &gsmBci[i];
Wink Savillef4c4d362009-04-02 01:37:03 -07001438
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001439 status = p.readInt32(&t);
1440 gsmBci[i].fromServiceId = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001441
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001442 status = p.readInt32(&t);
1443 gsmBci[i].toServiceId = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001444
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001445 status = p.readInt32(&t);
1446 gsmBci[i].fromCodeScheme = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001447
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001448 status = p.readInt32(&t);
1449 gsmBci[i].toCodeScheme = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001450
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001451 status = p.readInt32(&t);
1452 gsmBci[i].selected = (uint8_t) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001453
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001454 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId =%d, \
1455 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]", printBuf, i,
1456 gsmBci[i].fromServiceId, gsmBci[i].toServiceId,
1457 gsmBci[i].fromCodeScheme, gsmBci[i].toCodeScheme,
1458 gsmBci[i].selected);
1459 }
1460 closeRequest;
Wink Savillef4c4d362009-04-02 01:37:03 -07001461
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001462 if (status != NO_ERROR) {
1463 goto invalid;
1464 }
Wink Savillef4c4d362009-04-02 01:37:03 -07001465
Etan Cohend3652192014-06-20 08:28:44 -07001466 CALL_ONREQUEST(pRI->pCI->requestNumber,
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001467 gsmBciPtrs,
1468 num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *),
Etan Cohend3652192014-06-20 08:28:44 -07001469 pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001470
1471#ifdef MEMSET_FREED
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001472 memset(gsmBci, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo));
1473 memset(gsmBciPtrs, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *));
Wink Savillef4c4d362009-04-02 01:37:03 -07001474#endif
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001475 }
Wink Savillef4c4d362009-04-02 01:37:03 -07001476
1477 return;
1478
1479invalid:
1480 invalidCommandBlock(pRI);
1481 return;
Wink Savillea592eeb2009-05-22 13:26:36 -07001482}
Wink Savillef4c4d362009-04-02 01:37:03 -07001483
Wink Savillea592eeb2009-05-22 13:26:36 -07001484static void
1485dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1486 int32_t t;
1487 status_t status;
1488 int32_t num;
1489
1490 status = p.readInt32(&num);
1491 if (status != NO_ERROR) {
1492 goto invalid;
1493 }
1494
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001495 {
1496 RIL_CDMA_BroadcastSmsConfigInfo cdmaBci[num];
1497 RIL_CDMA_BroadcastSmsConfigInfo *cdmaBciPtrs[num];
Wink Savillea592eeb2009-05-22 13:26:36 -07001498
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001499 startRequest;
1500 for (int i = 0 ; i < num ; i++ ) {
1501 cdmaBciPtrs[i] = &cdmaBci[i];
Wink Savillea592eeb2009-05-22 13:26:36 -07001502
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001503 status = p.readInt32(&t);
1504 cdmaBci[i].service_category = (int) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001505
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001506 status = p.readInt32(&t);
1507 cdmaBci[i].language = (int) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001508
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001509 status = p.readInt32(&t);
1510 cdmaBci[i].selected = (uint8_t) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001511
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001512 appendPrintBuf("%s [%d: service_category=%d, language =%d, \
1513 entries.bSelected =%d]", printBuf, i, cdmaBci[i].service_category,
1514 cdmaBci[i].language, cdmaBci[i].selected);
1515 }
1516 closeRequest;
Wink Savillea592eeb2009-05-22 13:26:36 -07001517
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001518 if (status != NO_ERROR) {
1519 goto invalid;
1520 }
Wink Savillea592eeb2009-05-22 13:26:36 -07001521
Etan Cohend3652192014-06-20 08:28:44 -07001522 CALL_ONREQUEST(pRI->pCI->requestNumber,
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001523 cdmaBciPtrs,
1524 num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *),
Etan Cohend3652192014-06-20 08:28:44 -07001525 pRI, pRI->socket_id);
Wink Savillea592eeb2009-05-22 13:26:36 -07001526
1527#ifdef MEMSET_FREED
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001528 memset(cdmaBci, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo));
1529 memset(cdmaBciPtrs, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *));
Wink Savillea592eeb2009-05-22 13:26:36 -07001530#endif
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001531 }
Wink Savillea592eeb2009-05-22 13:26:36 -07001532
1533 return;
1534
1535invalid:
1536 invalidCommandBlock(pRI);
1537 return;
Wink Savillef4c4d362009-04-02 01:37:03 -07001538}
1539
1540static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI) {
1541 RIL_CDMA_SMS_WriteArgs rcsw;
1542 int32_t t;
1543 uint32_t ut;
1544 uint8_t uct;
1545 status_t status;
1546 int32_t digitCount;
Sukanya Rajkhowa605c7842013-10-29 14:55:30 +08001547 int32_t digitLimit;
Wink Savillef4c4d362009-04-02 01:37:03 -07001548
1549 memset(&rcsw, 0, sizeof(rcsw));
1550
1551 status = p.readInt32(&t);
1552 rcsw.status = t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001553
Wink Savillef4c4d362009-04-02 01:37:03 -07001554 status = p.readInt32(&t);
1555 rcsw.message.uTeleserviceID = (int) t;
1556
1557 status = p.read(&uct,sizeof(uct));
1558 rcsw.message.bIsServicePresent = (uint8_t) uct;
1559
1560 status = p.readInt32(&t);
1561 rcsw.message.uServicecategory = (int) t;
1562
1563 status = p.readInt32(&t);
1564 rcsw.message.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1565
1566 status = p.readInt32(&t);
1567 rcsw.message.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1568
1569 status = p.readInt32(&t);
1570 rcsw.message.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1571
1572 status = p.readInt32(&t);
1573 rcsw.message.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1574
1575 status = p.read(&uct,sizeof(uct));
1576 rcsw.message.sAddress.number_of_digits = (uint8_t) uct;
1577
Sukanya Rajkhowa605c7842013-10-29 14:55:30 +08001578 digitLimit = MIN((rcsw.message.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
1579
1580 for(digitCount = 0 ; digitCount < digitLimit; digitCount ++) {
Wink Savillef4c4d362009-04-02 01:37:03 -07001581 status = p.read(&uct,sizeof(uct));
1582 rcsw.message.sAddress.digits[digitCount] = (uint8_t) uct;
1583 }
1584
Wink Savillea592eeb2009-05-22 13:26:36 -07001585 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001586 rcsw.message.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1587
Wink Savillea592eeb2009-05-22 13:26:36 -07001588 status = p.read(&uct,sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001589 rcsw.message.sSubAddress.odd = (uint8_t) uct;
1590
1591 status = p.read(&uct,sizeof(uct));
1592 rcsw.message.sSubAddress.number_of_digits = (uint8_t) uct;
1593
Sukanya Rajkhowa605c7842013-10-29 14:55:30 +08001594 digitLimit = MIN((rcsw.message.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
1595
1596 for(digitCount = 0 ; digitCount < digitLimit; digitCount ++) {
Wink Savillea592eeb2009-05-22 13:26:36 -07001597 status = p.read(&uct,sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001598 rcsw.message.sSubAddress.digits[digitCount] = (uint8_t) uct;
1599 }
1600
Wink Savillea592eeb2009-05-22 13:26:36 -07001601 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001602 rcsw.message.uBearerDataLen = (int) t;
1603
Sukanya Rajkhowa605c7842013-10-29 14:55:30 +08001604 digitLimit = MIN((rcsw.message.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
1605
1606 for(digitCount = 0 ; digitCount < digitLimit; digitCount ++) {
Wink Savillea592eeb2009-05-22 13:26:36 -07001607 status = p.read(&uct, sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001608 rcsw.message.aBearerData[digitCount] = (uint8_t) uct;
1609 }
1610
1611 if (status != NO_ERROR) {
1612 goto invalid;
1613 }
1614
1615 startRequest;
Wink Saville1b5fd232009-04-22 14:50:00 -07001616 appendPrintBuf("%sstatus=%d, message.uTeleserviceID=%d, message.bIsServicePresent=%d, \
1617 message.uServicecategory=%d, message.sAddress.digit_mode=%d, \
1618 message.sAddress.number_mode=%d, \
1619 message.sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07001620 printBuf, rcsw.status, rcsw.message.uTeleserviceID, rcsw.message.bIsServicePresent,
Wink Saville1b5fd232009-04-22 14:50:00 -07001621 rcsw.message.uServicecategory, rcsw.message.sAddress.digit_mode,
1622 rcsw.message.sAddress.number_mode,
1623 rcsw.message.sAddress.number_type);
Wink Savillef4c4d362009-04-02 01:37:03 -07001624 closeRequest;
1625
1626 printRequest(pRI->token, pRI->pCI->requestNumber);
1627
Etan Cohend3652192014-06-20 08:28:44 -07001628 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsw, sizeof(rcsw),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001629
1630#ifdef MEMSET_FREED
1631 memset(&rcsw, 0, sizeof(rcsw));
1632#endif
1633
1634 return;
1635
1636invalid:
1637 invalidCommandBlock(pRI);
1638 return;
1639
1640}
1641
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -07001642// For backwards compatibility in RIL_REQUEST_SETUP_DATA_CALL.
1643// Version 4 of the RIL interface adds a new PDP type parameter to support
1644// IPv6 and dual-stack PDP contexts. When dealing with a previous version of
1645// RIL, remove the parameter from the request.
1646static void dispatchDataCall(Parcel& p, RequestInfo *pRI) {
1647 // In RIL v3, REQUEST_SETUP_DATA_CALL takes 6 parameters.
1648 const int numParamsRilV3 = 6;
1649
1650 // The first bytes of the RIL parcel contain the request number and the
1651 // serial number - see processCommandBuffer(). Copy them over too.
1652 int pos = p.dataPosition();
1653
1654 int numParams = p.readInt32();
1655 if (s_callbacks.version < 4 && numParams > numParamsRilV3) {
1656 Parcel p2;
1657 p2.appendFrom(&p, 0, pos);
1658 p2.writeInt32(numParamsRilV3);
1659 for(int i = 0; i < numParamsRilV3; i++) {
1660 p2.writeString16(p.readString16());
1661 }
1662 p2.setDataPosition(pos);
1663 dispatchStrings(p2, pRI);
1664 } else {
Lorenzo Colitti57ce1f22010-09-13 12:23:50 -07001665 p.setDataPosition(pos);
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -07001666 dispatchStrings(p, pRI);
1667 }
1668}
1669
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001670// For backwards compatibility with RILs that dont support RIL_REQUEST_VOICE_RADIO_TECH.
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 dispatchVoiceRadioTech(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 Voice Radio Technology
1688 // from Radio State
1689 voiceRadioTech = decodeVoiceRadioTechnology(state);
1690
1691 if (voiceRadioTech < 0)
1692 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1693 else
1694 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &voiceRadioTech, sizeof(int));
1695}
1696
1697// For backwards compatibility in RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE:.
1698// When all RILs handle this request, this function can be removed and
1699// the request can be sent directly to the RIL using dispatchVoid.
1700static void dispatchCdmaSubscriptionSource(Parcel& p, RequestInfo *pRI) {
Etan Cohend3652192014-06-20 08:28:44 -07001701 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001702
1703 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1704 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1705 }
1706
1707 // RILs that support RADIO_STATE_ON should support this request.
1708 if (RADIO_STATE_ON == state) {
1709 dispatchVoid(p, pRI);
1710 return;
1711 }
1712
1713 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1714 // will not support this new request either and decode CDMA Subscription Source
1715 // from Radio State
1716 cdmaSubscriptionSource = decodeCdmaSubscriptionSource(state);
1717
1718 if (cdmaSubscriptionSource < 0)
1719 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1720 else
1721 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &cdmaSubscriptionSource, sizeof(int));
1722}
1723
Sungmin Choi75697532013-04-26 15:04:45 -07001724static void dispatchSetInitialAttachApn(Parcel &p, RequestInfo *pRI)
1725{
1726 RIL_InitialAttachApn pf;
1727 int32_t t;
1728 status_t status;
1729
1730 memset(&pf, 0, sizeof(pf));
1731
1732 pf.apn = strdupReadString(p);
1733 pf.protocol = strdupReadString(p);
1734
1735 status = p.readInt32(&t);
1736 pf.authtype = (int) t;
1737
1738 pf.username = strdupReadString(p);
1739 pf.password = strdupReadString(p);
1740
1741 startRequest;
Etan Cohen5d891b72014-02-27 17:25:17 -08001742 appendPrintBuf("%sapn=%s, protocol=%s, authtype=%d, username=%s, password=%s",
1743 printBuf, pf.apn, pf.protocol, pf.authtype, pf.username, pf.password);
Sungmin Choi75697532013-04-26 15:04:45 -07001744 closeRequest;
1745 printRequest(pRI->token, pRI->pCI->requestNumber);
1746
1747 if (status != NO_ERROR) {
1748 goto invalid;
1749 }
Etan Cohend3652192014-06-20 08:28:44 -07001750 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
Sungmin Choi75697532013-04-26 15:04:45 -07001751
1752#ifdef MEMSET_FREED
1753 memsetString(pf.apn);
1754 memsetString(pf.protocol);
1755 memsetString(pf.username);
1756 memsetString(pf.password);
1757#endif
1758
1759 free(pf.apn);
1760 free(pf.protocol);
1761 free(pf.username);
1762 free(pf.password);
1763
1764#ifdef MEMSET_FREED
1765 memset(&pf, 0, sizeof(pf));
1766#endif
1767
1768 return;
1769invalid:
1770 invalidCommandBlock(pRI);
1771 return;
1772}
1773
Jake Hamby8a4a2332014-01-15 13:12:05 -08001774static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI) {
1775 RIL_NV_ReadItem nvri;
1776 int32_t t;
1777 status_t status;
1778
1779 memset(&nvri, 0, sizeof(nvri));
1780
1781 status = p.readInt32(&t);
1782 nvri.itemID = (RIL_NV_Item) t;
1783
1784 if (status != NO_ERROR) {
1785 goto invalid;
1786 }
1787
1788 startRequest;
1789 appendPrintBuf("%snvri.itemID=%d, ", printBuf, nvri.itemID);
1790 closeRequest;
1791
1792 printRequest(pRI->token, pRI->pCI->requestNumber);
1793
Etan Cohend3652192014-06-20 08:28:44 -07001794 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvri, sizeof(nvri), pRI, pRI->socket_id);
Jake Hamby8a4a2332014-01-15 13:12:05 -08001795
1796#ifdef MEMSET_FREED
1797 memset(&nvri, 0, sizeof(nvri));
1798#endif
1799
1800 return;
1801
1802invalid:
1803 invalidCommandBlock(pRI);
1804 return;
1805}
1806
1807static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI) {
1808 RIL_NV_WriteItem nvwi;
1809 int32_t t;
1810 status_t status;
1811
1812 memset(&nvwi, 0, sizeof(nvwi));
1813
1814 status = p.readInt32(&t);
1815 nvwi.itemID = (RIL_NV_Item) t;
1816
1817 nvwi.value = strdupReadString(p);
1818
1819 if (status != NO_ERROR || nvwi.value == NULL) {
1820 goto invalid;
1821 }
1822
1823 startRequest;
1824 appendPrintBuf("%snvwi.itemID=%d, value=%s, ", printBuf, nvwi.itemID,
1825 nvwi.value);
1826 closeRequest;
1827
1828 printRequest(pRI->token, pRI->pCI->requestNumber);
1829
Etan Cohend3652192014-06-20 08:28:44 -07001830 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvwi, sizeof(nvwi), pRI, pRI->socket_id);
Jake Hamby8a4a2332014-01-15 13:12:05 -08001831
1832#ifdef MEMSET_FREED
1833 memsetString(nvwi.value);
1834#endif
1835
1836 free(nvwi.value);
1837
1838#ifdef MEMSET_FREED
1839 memset(&nvwi, 0, sizeof(nvwi));
1840#endif
1841
1842 return;
1843
1844invalid:
1845 invalidCommandBlock(pRI);
1846 return;
1847}
1848
1849
Etan Cohend3652192014-06-20 08:28:44 -07001850static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI) {
1851 RIL_SelectUiccSub uicc_sub;
1852 status_t status;
1853 int32_t t;
1854 memset(&uicc_sub, 0, sizeof(uicc_sub));
1855
1856 status = p.readInt32(&t);
1857 if (status != NO_ERROR) {
1858 goto invalid;
1859 }
1860 uicc_sub.slot = (int) t;
1861
1862 status = p.readInt32(&t);
1863 if (status != NO_ERROR) {
1864 goto invalid;
1865 }
1866 uicc_sub.app_index = (int) t;
1867
1868 status = p.readInt32(&t);
1869 if (status != NO_ERROR) {
1870 goto invalid;
1871 }
1872 uicc_sub.sub_type = (RIL_SubscriptionType) t;
1873
1874 status = p.readInt32(&t);
1875 if (status != NO_ERROR) {
1876 goto invalid;
1877 }
1878 uicc_sub.act_status = (RIL_UiccSubActStatus) t;
1879
1880 startRequest;
1881 appendPrintBuf("slot=%d, app_index=%d, act_status = %d", uicc_sub.slot, uicc_sub.app_index,
1882 uicc_sub.act_status);
1883 RLOGD("dispatchUiccSubscription, slot=%d, app_index=%d, act_status = %d", uicc_sub.slot,
1884 uicc_sub.app_index, uicc_sub.act_status);
1885 closeRequest;
1886 printRequest(pRI->token, pRI->pCI->requestNumber);
1887
1888 CALL_ONREQUEST(pRI->pCI->requestNumber, &uicc_sub, sizeof(uicc_sub), pRI, pRI->socket_id);
1889
1890#ifdef MEMSET_FREED
1891 memset(&uicc_sub, 0, sizeof(uicc_sub));
1892#endif
1893 return;
1894
1895invalid:
1896 invalidCommandBlock(pRI);
1897 return;
1898}
1899
Amit Mahajan90530a62014-07-01 15:54:08 -07001900static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI)
1901{
1902 RIL_SimAuthentication pf;
1903 int32_t t;
1904 status_t status;
1905
1906 memset(&pf, 0, sizeof(pf));
1907
1908 status = p.readInt32(&t);
1909 pf.authContext = (int) t;
1910 pf.authData = strdupReadString(p);
1911 pf.aid = strdupReadString(p);
1912
1913 startRequest;
1914 appendPrintBuf("authContext=%s, authData=%s, aid=%s", pf.authContext, pf.authData, pf.aid);
1915 closeRequest;
1916 printRequest(pRI->token, pRI->pCI->requestNumber);
1917
1918 if (status != NO_ERROR) {
1919 goto invalid;
1920 }
1921 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
1922
1923#ifdef MEMSET_FREED
1924 memsetString(pf.authData);
1925 memsetString(pf.aid);
1926#endif
1927
1928 free(pf.authData);
1929 free(pf.aid);
1930
1931#ifdef MEMSET_FREED
1932 memset(&pf, 0, sizeof(pf));
1933#endif
1934
1935 return;
1936invalid:
1937 invalidCommandBlock(pRI);
1938 return;
1939}
1940
Amit Mahajanc796e222014-08-13 16:54:01 +00001941static void dispatchDataProfile(Parcel &p, RequestInfo *pRI) {
1942 int32_t t;
1943 status_t status;
1944 int32_t num;
1945
1946 status = p.readInt32(&num);
1947 if (status != NO_ERROR) {
1948 goto invalid;
1949 }
1950
1951 {
1952 RIL_DataProfileInfo dataProfiles[num];
1953 RIL_DataProfileInfo *dataProfilePtrs[num];
1954
1955 startRequest;
1956 for (int i = 0 ; i < num ; i++ ) {
1957 dataProfilePtrs[i] = &dataProfiles[i];
1958
1959 status = p.readInt32(&t);
1960 dataProfiles[i].profileId = (int) t;
1961
1962 dataProfiles[i].apn = strdupReadString(p);
1963 dataProfiles[i].protocol = strdupReadString(p);
1964 status = p.readInt32(&t);
1965 dataProfiles[i].authType = (int) t;
1966
1967 dataProfiles[i].user = strdupReadString(p);
1968 dataProfiles[i].password = strdupReadString(p);
1969
1970 status = p.readInt32(&t);
1971 dataProfiles[i].type = (int) t;
1972
1973 status = p.readInt32(&t);
1974 dataProfiles[i].maxConnsTime = (int) t;
1975 status = p.readInt32(&t);
1976 dataProfiles[i].maxConns = (int) t;
1977 status = p.readInt32(&t);
1978 dataProfiles[i].waitTime = (int) t;
1979
1980 status = p.readInt32(&t);
1981 dataProfiles[i].enabled = (int) t;
1982
1983 appendPrintBuf("%s [%d: profileId=%d, apn =%s, protocol =%s, authType =%d, \
1984 user =%s, password =%s, type =%d, maxConnsTime =%d, maxConns =%d, \
1985 waitTime =%d, enabled =%d]", printBuf, i, dataProfiles[i].profileId,
1986 dataProfiles[i].apn, dataProfiles[i].protocol, dataProfiles[i].authType,
1987 dataProfiles[i].user, dataProfiles[i].password, dataProfiles[i].type,
1988 dataProfiles[i].maxConnsTime, dataProfiles[i].maxConns,
1989 dataProfiles[i].waitTime, dataProfiles[i].enabled);
1990 }
1991 closeRequest;
1992 printRequest(pRI->token, pRI->pCI->requestNumber);
1993
1994 if (status != NO_ERROR) {
1995 goto invalid;
1996 }
1997 CALL_ONREQUEST(pRI->pCI->requestNumber,
1998 dataProfilePtrs,
1999 num * sizeof(RIL_DataProfileInfo *),
2000 pRI, pRI->socket_id);
2001
2002#ifdef MEMSET_FREED
2003 memset(dataProfiles, 0, num * sizeof(RIL_DataProfileInfo));
2004 memset(dataProfilePtrs, 0, num * sizeof(RIL_DataProfileInfo *));
2005#endif
2006 }
2007
2008 return;
2009
2010invalid:
2011 invalidCommandBlock(pRI);
2012 return;
2013}
2014
Wink Saville8b4e4f72014-10-17 15:01:45 -07002015static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI){
2016 RIL_RadioCapability rc;
2017 int32_t t;
2018 status_t status;
2019
2020 memset (&rc, 0, sizeof(RIL_RadioCapability));
2021
2022 status = p.readInt32(&t);
2023 rc.version = (int)t;
2024 if (status != NO_ERROR) {
2025 goto invalid;
2026 }
2027
2028 status = p.readInt32(&t);
2029 rc.session= (int)t;
2030 if (status != NO_ERROR) {
2031 goto invalid;
2032 }
2033
2034 status = p.readInt32(&t);
2035 rc.phase= (int)t;
2036 if (status != NO_ERROR) {
2037 goto invalid;
2038 }
2039
2040 status = p.readInt32(&t);
2041 rc.rat = (int)t;
2042 if (status != NO_ERROR) {
2043 goto invalid;
2044 }
2045
2046 status = readStringFromParcelInplace(p, rc.logicalModemUuid, sizeof(rc.logicalModemUuid));
2047 if (status != NO_ERROR) {
2048 goto invalid;
2049 }
2050
2051 status = p.readInt32(&t);
2052 rc.status = (int)t;
2053
2054 if (status != NO_ERROR) {
2055 goto invalid;
2056 }
2057
2058 startRequest;
2059 appendPrintBuf("%s [version:%d, session:%d, phase:%d, rat:%d, \
Chih-Wei Huang8593f262015-10-02 15:09:52 +08002060 logicalModemUuid:%s, status:%d", printBuf, rc.version, rc.session,
Legler Wu8caf06f2014-10-29 14:02:14 +08002061 rc.phase, rc.rat, rc.logicalModemUuid, rc.session);
Wink Saville8b4e4f72014-10-17 15:01:45 -07002062
2063 closeRequest;
2064 printRequest(pRI->token, pRI->pCI->requestNumber);
2065
2066 CALL_ONREQUEST(pRI->pCI->requestNumber,
2067 &rc,
2068 sizeof(RIL_RadioCapability),
2069 pRI, pRI->socket_id);
2070 return;
2071invalid:
2072 invalidCommandBlock(pRI);
2073 return;
2074}
2075
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002076static int
Wink Savillef4c4d362009-04-02 01:37:03 -07002077blockingWrite(int fd, const void *buffer, size_t len) {
Wink Saville7f856802009-06-09 10:23:37 -07002078 size_t writeOffset = 0;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002079 const uint8_t *toWrite;
2080
2081 toWrite = (const uint8_t *)buffer;
2082
2083 while (writeOffset < len) {
2084 ssize_t written;
2085 do {
2086 written = write (fd, toWrite + writeOffset,
2087 len - writeOffset);
Banavathu, Srinivas Naik38884902011-07-05 20:04:25 +05302088 } while (written < 0 && ((errno == EINTR) || (errno == EAGAIN)));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002089
2090 if (written >= 0) {
2091 writeOffset += written;
2092 } else { // written < 0
Wink Saville8eb2a122012-11-19 16:05:13 -08002093 RLOGE ("RIL Response: unexpected error on write errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002094 close(fd);
2095 return -1;
2096 }
2097 }
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07002098#if VDBG
Dheeraj Shetty27976c42014-07-02 21:27:57 +02002099 RLOGE("RIL Response bytes written:%d", writeOffset);
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07002100#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002101 return 0;
2102}
2103
2104static int
Etan Cohend3652192014-06-20 08:28:44 -07002105sendResponseRaw (const void *data, size_t dataSize, RIL_SOCKET_ID socket_id) {
2106 int fd = s_ril_param_socket.fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002107 int ret;
2108 uint32_t header;
Etan Cohend3652192014-06-20 08:28:44 -07002109 pthread_mutex_t * writeMutexHook = &s_writeMutex;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002110
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07002111#if VDBG
Etan Cohend3652192014-06-20 08:28:44 -07002112 RLOGE("Send Response to %s", rilSocketIdToString(socket_id));
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07002113#endif
Etan Cohend3652192014-06-20 08:28:44 -07002114
2115#if (SIM_COUNT >= 2)
2116 if (socket_id == RIL_SOCKET_2) {
2117 fd = s_ril_param_socket2.fdCommand;
2118 writeMutexHook = &s_writeMutex_socket2;
2119 }
2120#if (SIM_COUNT >= 3)
2121 else if (socket_id == RIL_SOCKET_3) {
2122 fd = s_ril_param_socket3.fdCommand;
2123 writeMutexHook = &s_writeMutex_socket3;
2124 }
2125#endif
2126#if (SIM_COUNT >= 4)
2127 else if (socket_id == RIL_SOCKET_4) {
2128 fd = s_ril_param_socket4.fdCommand;
2129 writeMutexHook = &s_writeMutex_socket4;
2130 }
2131#endif
2132#endif
2133 if (fd < 0) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002134 return -1;
2135 }
2136
2137 if (dataSize > MAX_COMMAND_BYTES) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002138 RLOGE("RIL: packet larger than %u (%u)",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002139 MAX_COMMAND_BYTES, (unsigned int )dataSize);
2140
2141 return -1;
2142 }
Wink Saville7f856802009-06-09 10:23:37 -07002143
Etan Cohend3652192014-06-20 08:28:44 -07002144 pthread_mutex_lock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002145
2146 header = htonl(dataSize);
2147
2148 ret = blockingWrite(fd, (void *)&header, sizeof(header));
2149
2150 if (ret < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002151 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002152 return ret;
2153 }
2154
Kennyee1fadc2009-08-13 00:45:53 +08002155 ret = blockingWrite(fd, data, dataSize);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002156
2157 if (ret < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002158 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002159 return ret;
2160 }
2161
Etan Cohend3652192014-06-20 08:28:44 -07002162 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002163
2164 return 0;
2165}
2166
2167static int
Etan Cohend3652192014-06-20 08:28:44 -07002168sendResponse (Parcel &p, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002169 printResponse;
Etan Cohend3652192014-06-20 08:28:44 -07002170 return sendResponseRaw(p.data(), p.dataSize(), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002171}
2172
Mohamad Ayyash74f7e662014-04-18 11:43:28 -07002173/** response is an int* pointing to an array of ints */
Wink Saville7f856802009-06-09 10:23:37 -07002174
2175static int
Wink Savillef4c4d362009-04-02 01:37:03 -07002176responseInts(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002177 int numInts;
2178
2179 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002180 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002181 return RIL_ERRNO_INVALID_RESPONSE;
2182 }
2183 if (responselen % sizeof(int) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002184 RLOGE("responseInts: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002185 (int)responselen, (int)sizeof(int));
2186 return RIL_ERRNO_INVALID_RESPONSE;
2187 }
2188
2189 int *p_int = (int *) response;
2190
Mohamad Ayyash74f7e662014-04-18 11:43:28 -07002191 numInts = responselen / sizeof(int);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002192 p.writeInt32 (numInts);
2193
2194 /* each int*/
2195 startResponse;
2196 for (int i = 0 ; i < numInts ; i++) {
2197 appendPrintBuf("%s%d,", printBuf, p_int[i]);
2198 p.writeInt32(p_int[i]);
2199 }
2200 removeLastChar;
2201 closeResponse;
2202
2203 return 0;
2204}
2205
Chao Liu548a81e2015-05-14 16:13:46 -07002206// Response is an int or RIL_LastCallFailCauseInfo.
2207// Currently, only Shamu plans to use RIL_LastCallFailCauseInfo.
2208// TODO(yjl): Let all implementations use RIL_LastCallFailCauseInfo.
2209static int responseFailCause(Parcel &p, void *response, size_t responselen) {
2210 if (response == NULL && responselen != 0) {
2211 RLOGE("invalid response: NULL");
2212 return RIL_ERRNO_INVALID_RESPONSE;
2213 }
2214
2215 if (responselen == sizeof(int)) {
Sungmin Choia408c252015-07-01 16:22:46 +09002216 startResponse;
2217 int *p_int = (int *) response;
2218 appendPrintBuf("%s%d,", printBuf, p_int[0]);
2219 p.writeInt32(p_int[0]);
2220 removeLastChar;
2221 closeResponse;
Chao Liu548a81e2015-05-14 16:13:46 -07002222 } else if (responselen == sizeof(RIL_LastCallFailCauseInfo)) {
2223 startResponse;
2224 RIL_LastCallFailCauseInfo *p_fail_cause_info = (RIL_LastCallFailCauseInfo *) response;
2225 appendPrintBuf("%s[cause_code=%d,vendor_cause=%s]", printBuf, p_fail_cause_info->cause_code,
2226 p_fail_cause_info->vendor_cause);
2227 p.writeInt32(p_fail_cause_info->cause_code);
2228 writeStringToParcel(p, p_fail_cause_info->vendor_cause);
2229 removeLastChar;
2230 closeResponse;
2231 } else {
2232 RLOGE("responseFailCause: invalid response length %d expected an int or "
2233 "RIL_LastCallFailCauseInfo", (int)responselen);
2234 return RIL_ERRNO_INVALID_RESPONSE;
2235 }
2236
2237 return 0;
2238}
2239
Wink Saville43808972011-01-13 17:39:51 -08002240/** response is a char **, pointing to an array of char *'s
2241 The parcel will begin with the version */
2242static int responseStringsWithVersion(int version, Parcel &p, void *response, size_t responselen) {
2243 p.writeInt32(version);
2244 return responseStrings(p, response, responselen);
2245}
2246
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002247/** response is a char **, pointing to an array of char *'s */
Wink Savillef4c4d362009-04-02 01:37:03 -07002248static int responseStrings(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002249 int numStrings;
Wink Saville7f856802009-06-09 10:23:37 -07002250
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002251 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002252 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002253 return RIL_ERRNO_INVALID_RESPONSE;
2254 }
2255 if (responselen % sizeof(char *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002256 RLOGE("responseStrings: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002257 (int)responselen, (int)sizeof(char *));
2258 return RIL_ERRNO_INVALID_RESPONSE;
2259 }
2260
2261 if (response == NULL) {
2262 p.writeInt32 (0);
2263 } else {
2264 char **p_cur = (char **) response;
2265
2266 numStrings = responselen / sizeof(char *);
2267 p.writeInt32 (numStrings);
2268
2269 /* each string*/
2270 startResponse;
2271 for (int i = 0 ; i < numStrings ; i++) {
2272 appendPrintBuf("%s%s,", printBuf, (char*)p_cur[i]);
2273 writeStringToParcel (p, p_cur[i]);
2274 }
2275 removeLastChar;
2276 closeResponse;
2277 }
2278 return 0;
2279}
2280
2281
2282/**
Wink Saville7f856802009-06-09 10:23:37 -07002283 * NULL strings are accepted
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002284 * FIXME currently ignores responselen
2285 */
Wink Savillef4c4d362009-04-02 01:37:03 -07002286static int responseString(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002287 /* one string only */
2288 startResponse;
2289 appendPrintBuf("%s%s", printBuf, (char*)response);
2290 closeResponse;
2291
2292 writeStringToParcel(p, (const char *)response);
2293
2294 return 0;
2295}
2296
Wink Savillef4c4d362009-04-02 01:37:03 -07002297static int responseVoid(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002298 startResponse;
2299 removeLastChar;
2300 return 0;
2301}
2302
Wink Savillef4c4d362009-04-02 01:37:03 -07002303static int responseCallList(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002304 int num;
2305
2306 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002307 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002308 return RIL_ERRNO_INVALID_RESPONSE;
2309 }
2310
2311 if (responselen % sizeof (RIL_Call *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002312 RLOGE("responseCallList: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002313 (int)responselen, (int)sizeof (RIL_Call *));
2314 return RIL_ERRNO_INVALID_RESPONSE;
2315 }
2316
2317 startResponse;
2318 /* number of call info's */
2319 num = responselen / sizeof(RIL_Call *);
2320 p.writeInt32(num);
2321
2322 for (int i = 0 ; i < num ; i++) {
2323 RIL_Call *p_cur = ((RIL_Call **) response)[i];
2324 /* each call info */
2325 p.writeInt32(p_cur->state);
2326 p.writeInt32(p_cur->index);
2327 p.writeInt32(p_cur->toa);
2328 p.writeInt32(p_cur->isMpty);
2329 p.writeInt32(p_cur->isMT);
2330 p.writeInt32(p_cur->als);
2331 p.writeInt32(p_cur->isVoice);
Wink Saville1b5fd232009-04-22 14:50:00 -07002332 p.writeInt32(p_cur->isVoicePrivacy);
2333 writeStringToParcel(p, p_cur->number);
John Wangff368742009-03-24 17:56:29 -07002334 p.writeInt32(p_cur->numberPresentation);
Wink Saville1b5fd232009-04-22 14:50:00 -07002335 writeStringToParcel(p, p_cur->name);
2336 p.writeInt32(p_cur->namePresentation);
Wink Saville3a4840b2010-04-07 13:29:58 -07002337 // Remove when partners upgrade to version 3
Wink Saville74fa3882009-12-22 15:35:41 -08002338 if ((s_callbacks.version < 3) || (p_cur->uusInfo == NULL || p_cur->uusInfo->uusData == NULL)) {
2339 p.writeInt32(0); /* UUS Information is absent */
2340 } else {
2341 RIL_UUS_Info *uusInfo = p_cur->uusInfo;
2342 p.writeInt32(1); /* UUS Information is present */
2343 p.writeInt32(uusInfo->uusType);
2344 p.writeInt32(uusInfo->uusDcs);
2345 p.writeInt32(uusInfo->uusLength);
2346 p.write(uusInfo->uusData, uusInfo->uusLength);
2347 }
Wink Saville3d54e742009-05-18 18:00:44 -07002348 appendPrintBuf("%s[id=%d,%s,toa=%d,",
John Wangff368742009-03-24 17:56:29 -07002349 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002350 p_cur->index,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002351 callStateToString(p_cur->state),
Wink Saville3d54e742009-05-18 18:00:44 -07002352 p_cur->toa);
2353 appendPrintBuf("%s%s,%s,als=%d,%s,%s,",
2354 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002355 (p_cur->isMpty)?"conf":"norm",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002356 (p_cur->isMT)?"mt":"mo",
2357 p_cur->als,
2358 (p_cur->isVoice)?"voc":"nonvoc",
Wink Saville3d54e742009-05-18 18:00:44 -07002359 (p_cur->isVoicePrivacy)?"evp":"noevp");
2360 appendPrintBuf("%s%s,cli=%d,name='%s',%d]",
2361 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002362 p_cur->number,
2363 p_cur->numberPresentation,
2364 p_cur->name,
2365 p_cur->namePresentation);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002366 }
2367 removeLastChar;
2368 closeResponse;
2369
2370 return 0;
2371}
2372
Wink Savillef4c4d362009-04-02 01:37:03 -07002373static int responseSMS(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002374 if (response == NULL) {
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
2379 if (responselen != sizeof (RIL_SMS_Response) ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002380 RLOGE("invalid response length %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002381 (int)responselen, (int)sizeof (RIL_SMS_Response));
2382 return RIL_ERRNO_INVALID_RESPONSE;
2383 }
2384
2385 RIL_SMS_Response *p_cur = (RIL_SMS_Response *) response;
2386
2387 p.writeInt32(p_cur->messageRef);
2388 writeStringToParcel(p, p_cur->ackPDU);
Jaikumar Ganesh920c78f2009-06-04 10:53:15 -07002389 p.writeInt32(p_cur->errorCode);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002390
2391 startResponse;
Jaikumar Ganesh920c78f2009-06-04 10:53:15 -07002392 appendPrintBuf("%s%d,%s,%d", printBuf, p_cur->messageRef,
2393 (char*)p_cur->ackPDU, p_cur->errorCode);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002394 closeResponse;
2395
2396 return 0;
2397}
2398
Wink Savillec0114b32011-02-18 10:14:07 -08002399static int responseDataCallListV4(Parcel &p, void *response, size_t responselen)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002400{
2401 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002402 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002403 return RIL_ERRNO_INVALID_RESPONSE;
2404 }
2405
Wink Savillec0114b32011-02-18 10:14:07 -08002406 if (responselen % sizeof(RIL_Data_Call_Response_v4) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002407 RLOGE("responseDataCallListV4: invalid response length %d expected multiple of %d",
Wink Savillec0114b32011-02-18 10:14:07 -08002408 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v4));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002409 return RIL_ERRNO_INVALID_RESPONSE;
2410 }
2411
Amit Mahajan52500162014-07-29 17:36:48 -07002412 // Write version
2413 p.writeInt32(4);
2414
Wink Savillec0114b32011-02-18 10:14:07 -08002415 int num = responselen / sizeof(RIL_Data_Call_Response_v4);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002416 p.writeInt32(num);
2417
Wink Savillec0114b32011-02-18 10:14:07 -08002418 RIL_Data_Call_Response_v4 *p_cur = (RIL_Data_Call_Response_v4 *) response;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002419 startResponse;
2420 int i;
2421 for (i = 0; i < num; i++) {
2422 p.writeInt32(p_cur[i].cid);
2423 p.writeInt32(p_cur[i].active);
2424 writeStringToParcel(p, p_cur[i].type);
Wink Savillec0114b32011-02-18 10:14:07 -08002425 // apn is not used, so don't send.
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002426 writeStringToParcel(p, p_cur[i].address);
Wink Savillec0114b32011-02-18 10:14:07 -08002427 appendPrintBuf("%s[cid=%d,%s,%s,%s],", printBuf,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002428 p_cur[i].cid,
2429 (p_cur[i].active==0)?"down":"up",
2430 (char*)p_cur[i].type,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002431 (char*)p_cur[i].address);
2432 }
2433 removeLastChar;
2434 closeResponse;
2435
2436 return 0;
2437}
2438
Etan Cohend3652192014-06-20 08:28:44 -07002439static int responseDataCallListV6(Parcel &p, void *response, size_t responselen)
2440{
Amit Mahajan52500162014-07-29 17:36:48 -07002441 if (response == NULL && responselen != 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002442 RLOGE("invalid response: NULL");
2443 return RIL_ERRNO_INVALID_RESPONSE;
2444 }
2445
2446 if (responselen % sizeof(RIL_Data_Call_Response_v6) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002447 RLOGE("responseDataCallListV6: invalid response length %d expected multiple of %d",
Etan Cohend3652192014-06-20 08:28:44 -07002448 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v6));
2449 return RIL_ERRNO_INVALID_RESPONSE;
2450 }
2451
Amit Mahajan52500162014-07-29 17:36:48 -07002452 // Write version
2453 p.writeInt32(6);
2454
Etan Cohend3652192014-06-20 08:28:44 -07002455 int num = responselen / sizeof(RIL_Data_Call_Response_v6);
2456 p.writeInt32(num);
2457
2458 RIL_Data_Call_Response_v6 *p_cur = (RIL_Data_Call_Response_v6 *) response;
2459 startResponse;
2460 int i;
2461 for (i = 0; i < num; i++) {
2462 p.writeInt32((int)p_cur[i].status);
2463 p.writeInt32(p_cur[i].suggestedRetryTime);
2464 p.writeInt32(p_cur[i].cid);
2465 p.writeInt32(p_cur[i].active);
2466 writeStringToParcel(p, p_cur[i].type);
2467 writeStringToParcel(p, p_cur[i].ifname);
2468 writeStringToParcel(p, p_cur[i].addresses);
2469 writeStringToParcel(p, p_cur[i].dnses);
2470 writeStringToParcel(p, p_cur[i].gateways);
2471 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s],", printBuf,
2472 p_cur[i].status,
2473 p_cur[i].suggestedRetryTime,
2474 p_cur[i].cid,
2475 (p_cur[i].active==0)?"down":"up",
2476 (char*)p_cur[i].type,
2477 (char*)p_cur[i].ifname,
2478 (char*)p_cur[i].addresses,
2479 (char*)p_cur[i].dnses,
2480 (char*)p_cur[i].gateways);
2481 }
2482 removeLastChar;
2483 closeResponse;
2484
2485 return 0;
2486}
2487
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002488static int responseDataCallListV9(Parcel &p, void *response, size_t responselen)
2489{
2490 if (response == NULL && responselen != 0) {
2491 RLOGE("invalid response: NULL");
2492 return RIL_ERRNO_INVALID_RESPONSE;
2493 }
2494
2495 if (responselen % sizeof(RIL_Data_Call_Response_v9) != 0) {
2496 RLOGE("responseDataCallListV9: invalid response length %d expected multiple of %d",
2497 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v9));
2498 return RIL_ERRNO_INVALID_RESPONSE;
2499 }
2500
2501 // Write version
2502 p.writeInt32(10);
2503
2504 int num = responselen / sizeof(RIL_Data_Call_Response_v9);
2505 p.writeInt32(num);
2506
2507 RIL_Data_Call_Response_v9 *p_cur = (RIL_Data_Call_Response_v9 *) response;
2508 startResponse;
2509 int i;
2510 for (i = 0; i < num; i++) {
2511 p.writeInt32((int)p_cur[i].status);
2512 p.writeInt32(p_cur[i].suggestedRetryTime);
2513 p.writeInt32(p_cur[i].cid);
2514 p.writeInt32(p_cur[i].active);
2515 writeStringToParcel(p, p_cur[i].type);
2516 writeStringToParcel(p, p_cur[i].ifname);
2517 writeStringToParcel(p, p_cur[i].addresses);
2518 writeStringToParcel(p, p_cur[i].dnses);
2519 writeStringToParcel(p, p_cur[i].gateways);
2520 writeStringToParcel(p, p_cur[i].pcscf);
2521 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s],", printBuf,
2522 p_cur[i].status,
2523 p_cur[i].suggestedRetryTime,
2524 p_cur[i].cid,
2525 (p_cur[i].active==0)?"down":"up",
2526 (char*)p_cur[i].type,
2527 (char*)p_cur[i].ifname,
2528 (char*)p_cur[i].addresses,
2529 (char*)p_cur[i].dnses,
2530 (char*)p_cur[i].gateways,
2531 (char*)p_cur[i].pcscf);
2532 }
2533 removeLastChar;
2534 closeResponse;
2535
2536 return 0;
2537}
2538
Sanket Padawe88cf6a52016-01-11 12:45:43 -08002539static int responseDataCallListV11(Parcel &p, void *response, size_t responselen) {
2540 if (response == NULL && responselen != 0) {
2541 RLOGE("invalid response: NULL");
2542 return RIL_ERRNO_INVALID_RESPONSE;
2543 }
2544
2545 if (responselen % sizeof(RIL_Data_Call_Response_v11) != 0) {
2546 RLOGE("invalid response length %d expected multiple of %d",
2547 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v11));
2548 return RIL_ERRNO_INVALID_RESPONSE;
2549 }
2550
2551 // Write version
2552 p.writeInt32(11);
2553
2554 int num = responselen / sizeof(RIL_Data_Call_Response_v11);
2555 p.writeInt32(num);
2556
2557 RIL_Data_Call_Response_v11 *p_cur = (RIL_Data_Call_Response_v11 *) response;
2558 startResponse;
2559 int i;
2560 for (i = 0; i < num; i++) {
2561 p.writeInt32((int)p_cur[i].status);
2562 p.writeInt32(p_cur[i].suggestedRetryTime);
2563 p.writeInt32(p_cur[i].cid);
2564 p.writeInt32(p_cur[i].active);
2565 writeStringToParcel(p, p_cur[i].type);
2566 writeStringToParcel(p, p_cur[i].ifname);
2567 writeStringToParcel(p, p_cur[i].addresses);
2568 writeStringToParcel(p, p_cur[i].dnses);
2569 writeStringToParcel(p, p_cur[i].gateways);
2570 writeStringToParcel(p, p_cur[i].pcscf);
2571 p.writeInt32(p_cur[i].mtu);
2572 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s,mtu=%d],", printBuf,
2573 p_cur[i].status,
2574 p_cur[i].suggestedRetryTime,
2575 p_cur[i].cid,
2576 (p_cur[i].active==0)?"down":"up",
2577 (char*)p_cur[i].type,
2578 (char*)p_cur[i].ifname,
2579 (char*)p_cur[i].addresses,
2580 (char*)p_cur[i].dnses,
2581 (char*)p_cur[i].gateways,
2582 (char*)p_cur[i].pcscf,
2583 p_cur[i].mtu);
2584 }
2585 removeLastChar;
2586 closeResponse;
2587
2588 return 0;
2589}
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002590
Wink Saville43808972011-01-13 17:39:51 -08002591static int responseDataCallList(Parcel &p, void *response, size_t responselen)
2592{
Sanket Padawe88cf6a52016-01-11 12:45:43 -08002593 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
2594 if (s_callbacks.version < 5) {
2595 RLOGD("responseDataCallList: v4");
2596 return responseDataCallListV4(p, response, responselen);
2597 } else if (responselen % sizeof(RIL_Data_Call_Response_v6) == 0) {
2598 return responseDataCallListV6(p, response, responselen);
2599 } else if (responselen % sizeof(RIL_Data_Call_Response_v9) == 0) {
2600 return responseDataCallListV9(p, response, responselen);
2601 } else {
2602 return responseDataCallListV11(p, response, responselen);
Wink Saville43808972011-01-13 17:39:51 -08002603 }
Sanket Padawef53c5fa2016-01-27 10:00:38 -08002604 } else { // RIL version >= 13
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002605 if (responselen % sizeof(RIL_Data_Call_Response_v11) != 0) {
Sanket Padawe88cf6a52016-01-11 12:45:43 -08002606 RLOGE("Data structure expected is RIL_Data_Call_Response_v11");
2607 if (!isDebuggable()) {
2608 return RIL_ERRNO_INVALID_RESPONSE;
2609 } else {
2610 assert(0);
2611 }
Wink Saville43808972011-01-13 17:39:51 -08002612 }
Sanket Padawe88cf6a52016-01-11 12:45:43 -08002613 return responseDataCallListV11(p, response, responselen);
Wink Saville43808972011-01-13 17:39:51 -08002614 }
Wink Saville43808972011-01-13 17:39:51 -08002615}
2616
2617static int responseSetupDataCall(Parcel &p, void *response, size_t responselen)
2618{
2619 if (s_callbacks.version < 5) {
2620 return responseStringsWithVersion(s_callbacks.version, p, response, responselen);
2621 } else {
2622 return responseDataCallList(p, response, responselen);
2623 }
2624}
2625
Wink Savillef4c4d362009-04-02 01:37:03 -07002626static int responseRaw(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002627 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002628 RLOGE("invalid response: NULL with responselen != 0");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002629 return RIL_ERRNO_INVALID_RESPONSE;
2630 }
2631
2632 // The java code reads -1 size as null byte array
2633 if (response == NULL) {
Wink Saville7f856802009-06-09 10:23:37 -07002634 p.writeInt32(-1);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002635 } else {
2636 p.writeInt32(responselen);
2637 p.write(response, responselen);
2638 }
2639
2640 return 0;
2641}
2642
2643
Wink Savillef4c4d362009-04-02 01:37:03 -07002644static int responseSIM_IO(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002645 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002646 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002647 return RIL_ERRNO_INVALID_RESPONSE;
2648 }
2649
2650 if (responselen != sizeof (RIL_SIM_IO_Response) ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002651 RLOGE("invalid response length was %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002652 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
2653 return RIL_ERRNO_INVALID_RESPONSE;
2654 }
2655
2656 RIL_SIM_IO_Response *p_cur = (RIL_SIM_IO_Response *) response;
2657 p.writeInt32(p_cur->sw1);
2658 p.writeInt32(p_cur->sw2);
2659 writeStringToParcel(p, p_cur->simResponse);
2660
2661 startResponse;
2662 appendPrintBuf("%ssw1=0x%X,sw2=0x%X,%s", printBuf, p_cur->sw1, p_cur->sw2,
2663 (char*)p_cur->simResponse);
2664 closeResponse;
2665
2666
2667 return 0;
2668}
2669
Wink Savillef4c4d362009-04-02 01:37:03 -07002670static int responseCallForwards(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002671 int num;
Wink Saville7f856802009-06-09 10:23:37 -07002672
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002673 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002674 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002675 return RIL_ERRNO_INVALID_RESPONSE;
2676 }
2677
2678 if (responselen % sizeof(RIL_CallForwardInfo *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002679 RLOGE("responseCallForwards: invalid response length %d expected multiple of %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002680 (int)responselen, (int)sizeof(RIL_CallForwardInfo *));
2681 return RIL_ERRNO_INVALID_RESPONSE;
2682 }
2683
2684 /* number of call info's */
2685 num = responselen / sizeof(RIL_CallForwardInfo *);
2686 p.writeInt32(num);
2687
2688 startResponse;
2689 for (int i = 0 ; i < num ; i++) {
2690 RIL_CallForwardInfo *p_cur = ((RIL_CallForwardInfo **) response)[i];
2691
2692 p.writeInt32(p_cur->status);
2693 p.writeInt32(p_cur->reason);
2694 p.writeInt32(p_cur->serviceClass);
2695 p.writeInt32(p_cur->toa);
2696 writeStringToParcel(p, p_cur->number);
2697 p.writeInt32(p_cur->timeSeconds);
2698 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
2699 (p_cur->status==1)?"enable":"disable",
2700 p_cur->reason, p_cur->serviceClass, p_cur->toa,
2701 (char*)p_cur->number,
2702 p_cur->timeSeconds);
2703 }
2704 removeLastChar;
2705 closeResponse;
Wink Saville7f856802009-06-09 10:23:37 -07002706
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002707 return 0;
2708}
2709
Wink Savillef4c4d362009-04-02 01:37:03 -07002710static int responseSsn(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002711 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002712 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002713 return RIL_ERRNO_INVALID_RESPONSE;
2714 }
2715
2716 if (responselen != sizeof(RIL_SuppSvcNotification)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002717 RLOGE("invalid response length was %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002718 (int)responselen, (int)sizeof (RIL_SuppSvcNotification));
2719 return RIL_ERRNO_INVALID_RESPONSE;
2720 }
2721
2722 RIL_SuppSvcNotification *p_cur = (RIL_SuppSvcNotification *) response;
2723 p.writeInt32(p_cur->notificationType);
2724 p.writeInt32(p_cur->code);
2725 p.writeInt32(p_cur->index);
2726 p.writeInt32(p_cur->type);
2727 writeStringToParcel(p, p_cur->number);
2728
2729 startResponse;
2730 appendPrintBuf("%s%s,code=%d,id=%d,type=%d,%s", printBuf,
2731 (p_cur->notificationType==0)?"mo":"mt",
2732 p_cur->code, p_cur->index, p_cur->type,
2733 (char*)p_cur->number);
2734 closeResponse;
2735
2736 return 0;
2737}
2738
Wink Saville3d54e742009-05-18 18:00:44 -07002739static int responseCellList(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002740 int num;
2741
2742 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002743 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002744 return RIL_ERRNO_INVALID_RESPONSE;
2745 }
2746
2747 if (responselen % sizeof (RIL_NeighboringCell *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002748 RLOGE("responseCellList: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002749 (int)responselen, (int)sizeof (RIL_NeighboringCell *));
2750 return RIL_ERRNO_INVALID_RESPONSE;
2751 }
2752
2753 startResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002754 /* number of records */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002755 num = responselen / sizeof(RIL_NeighboringCell *);
2756 p.writeInt32(num);
2757
2758 for (int i = 0 ; i < num ; i++) {
2759 RIL_NeighboringCell *p_cur = ((RIL_NeighboringCell **) response)[i];
2760
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002761 p.writeInt32(p_cur->rssi);
2762 writeStringToParcel (p, p_cur->cid);
2763
2764 appendPrintBuf("%s[cid=%s,rssi=%d],", printBuf,
2765 p_cur->cid, p_cur->rssi);
2766 }
2767 removeLastChar;
2768 closeResponse;
2769
2770 return 0;
2771}
2772
Wink Saville3d54e742009-05-18 18:00:44 -07002773/**
2774 * Marshall the signalInfoRecord into the parcel if it exists.
2775 */
Wink Savillea592eeb2009-05-22 13:26:36 -07002776static void marshallSignalInfoRecord(Parcel &p,
2777 RIL_CDMA_SignalInfoRecord &p_signalInfoRecord) {
Wink Saville3d54e742009-05-18 18:00:44 -07002778 p.writeInt32(p_signalInfoRecord.isPresent);
2779 p.writeInt32(p_signalInfoRecord.signalType);
2780 p.writeInt32(p_signalInfoRecord.alertPitch);
2781 p.writeInt32(p_signalInfoRecord.signal);
2782}
2783
Wink Savillea592eeb2009-05-22 13:26:36 -07002784static int responseCdmaInformationRecords(Parcel &p,
2785 void *response, size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07002786 int num;
Wink Savillea592eeb2009-05-22 13:26:36 -07002787 char* string8 = NULL;
2788 int buffer_lenght;
2789 RIL_CDMA_InformationRecord *infoRec;
Wink Saville3d54e742009-05-18 18:00:44 -07002790
2791 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002792 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002793 return RIL_ERRNO_INVALID_RESPONSE;
2794 }
2795
Wink Savillea592eeb2009-05-22 13:26:36 -07002796 if (responselen != sizeof (RIL_CDMA_InformationRecords)) {
Amit Mahajan52500162014-07-29 17:36:48 -07002797 RLOGE("responseCdmaInformationRecords: invalid response length %d expected multiple of %d\n",
Wink Savillea592eeb2009-05-22 13:26:36 -07002798 (int)responselen, (int)sizeof (RIL_CDMA_InformationRecords *));
Wink Saville3d54e742009-05-18 18:00:44 -07002799 return RIL_ERRNO_INVALID_RESPONSE;
2800 }
2801
Wink Savillea592eeb2009-05-22 13:26:36 -07002802 RIL_CDMA_InformationRecords *p_cur =
2803 (RIL_CDMA_InformationRecords *) response;
2804 num = MIN(p_cur->numberOfInfoRecs, RIL_CDMA_MAX_NUMBER_OF_INFO_RECS);
Wink Saville3d54e742009-05-18 18:00:44 -07002805
2806 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07002807 p.writeInt32(num);
Wink Saville3d54e742009-05-18 18:00:44 -07002808
Wink Savillea592eeb2009-05-22 13:26:36 -07002809 for (int i = 0 ; i < num ; i++) {
2810 infoRec = &p_cur->infoRec[i];
2811 p.writeInt32(infoRec->name);
2812 switch (infoRec->name) {
Wink Saville3d54e742009-05-18 18:00:44 -07002813 case RIL_CDMA_DISPLAY_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002814 case RIL_CDMA_EXTENDED_DISPLAY_INFO_REC:
2815 if (infoRec->rec.display.alpha_len >
2816 CDMA_ALPHA_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002817 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002818 expected not more than %d\n",
2819 (int)infoRec->rec.display.alpha_len,
2820 CDMA_ALPHA_INFO_BUFFER_LENGTH);
2821 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002822 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002823 string8 = (char*) malloc((infoRec->rec.display.alpha_len + 1)
2824 * sizeof(char) );
2825 for (int i = 0 ; i < infoRec->rec.display.alpha_len ; i++) {
2826 string8[i] = infoRec->rec.display.alpha_buf[i];
2827 }
Wink Saville43808972011-01-13 17:39:51 -08002828 string8[(int)infoRec->rec.display.alpha_len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002829 writeStringToParcel(p, (const char*)string8);
2830 free(string8);
2831 string8 = NULL;
Wink Saville3d54e742009-05-18 18:00:44 -07002832 break;
2833 case RIL_CDMA_CALLED_PARTY_NUMBER_INFO_REC:
Wink Saville3d54e742009-05-18 18:00:44 -07002834 case RIL_CDMA_CALLING_PARTY_NUMBER_INFO_REC:
Wink Saville3d54e742009-05-18 18:00:44 -07002835 case RIL_CDMA_CONNECTED_NUMBER_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002836 if (infoRec->rec.number.len > CDMA_NUMBER_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002837 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002838 expected not more than %d\n",
2839 (int)infoRec->rec.number.len,
2840 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2841 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002842 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002843 string8 = (char*) malloc((infoRec->rec.number.len + 1)
2844 * sizeof(char) );
2845 for (int i = 0 ; i < infoRec->rec.number.len; i++) {
2846 string8[i] = infoRec->rec.number.buf[i];
2847 }
Wink Saville43808972011-01-13 17:39:51 -08002848 string8[(int)infoRec->rec.number.len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002849 writeStringToParcel(p, (const char*)string8);
2850 free(string8);
2851 string8 = NULL;
2852 p.writeInt32(infoRec->rec.number.number_type);
2853 p.writeInt32(infoRec->rec.number.number_plan);
2854 p.writeInt32(infoRec->rec.number.pi);
2855 p.writeInt32(infoRec->rec.number.si);
Wink Saville3d54e742009-05-18 18:00:44 -07002856 break;
2857 case RIL_CDMA_SIGNAL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002858 p.writeInt32(infoRec->rec.signal.isPresent);
2859 p.writeInt32(infoRec->rec.signal.signalType);
2860 p.writeInt32(infoRec->rec.signal.alertPitch);
2861 p.writeInt32(infoRec->rec.signal.signal);
2862
2863 appendPrintBuf("%sisPresent=%X, signalType=%X, \
2864 alertPitch=%X, signal=%X, ",
2865 printBuf, (int)infoRec->rec.signal.isPresent,
2866 (int)infoRec->rec.signal.signalType,
2867 (int)infoRec->rec.signal.alertPitch,
2868 (int)infoRec->rec.signal.signal);
2869 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002870 break;
2871 case RIL_CDMA_REDIRECTING_NUMBER_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002872 if (infoRec->rec.redir.redirectingNumber.len >
2873 CDMA_NUMBER_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002874 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002875 expected not more than %d\n",
2876 (int)infoRec->rec.redir.redirectingNumber.len,
2877 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2878 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002879 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002880 string8 = (char*) malloc((infoRec->rec.redir.redirectingNumber
2881 .len + 1) * sizeof(char) );
2882 for (int i = 0;
2883 i < infoRec->rec.redir.redirectingNumber.len;
2884 i++) {
2885 string8[i] = infoRec->rec.redir.redirectingNumber.buf[i];
2886 }
Wink Saville43808972011-01-13 17:39:51 -08002887 string8[(int)infoRec->rec.redir.redirectingNumber.len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002888 writeStringToParcel(p, (const char*)string8);
2889 free(string8);
2890 string8 = NULL;
2891 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_type);
2892 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_plan);
2893 p.writeInt32(infoRec->rec.redir.redirectingNumber.pi);
2894 p.writeInt32(infoRec->rec.redir.redirectingNumber.si);
2895 p.writeInt32(infoRec->rec.redir.redirectingReason);
Wink Saville3d54e742009-05-18 18:00:44 -07002896 break;
2897 case RIL_CDMA_LINE_CONTROL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002898 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPolarityIncluded);
2899 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlToggle);
2900 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlReverse);
2901 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2902
2903 appendPrintBuf("%slineCtrlPolarityIncluded=%d, \
2904 lineCtrlToggle=%d, lineCtrlReverse=%d, \
2905 lineCtrlPowerDenial=%d, ", printBuf,
2906 (int)infoRec->rec.lineCtrl.lineCtrlPolarityIncluded,
2907 (int)infoRec->rec.lineCtrl.lineCtrlToggle,
2908 (int)infoRec->rec.lineCtrl.lineCtrlReverse,
2909 (int)infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2910 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002911 break;
2912 case RIL_CDMA_T53_CLIR_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002913 p.writeInt32((int)(infoRec->rec.clir.cause));
Wink Saville3d54e742009-05-18 18:00:44 -07002914
Wink Savillea592eeb2009-05-22 13:26:36 -07002915 appendPrintBuf("%scause%d", printBuf, infoRec->rec.clir.cause);
2916 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002917 break;
2918 case RIL_CDMA_T53_AUDIO_CONTROL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002919 p.writeInt32(infoRec->rec.audioCtrl.upLink);
2920 p.writeInt32(infoRec->rec.audioCtrl.downLink);
2921
2922 appendPrintBuf("%supLink=%d, downLink=%d, ", printBuf,
2923 infoRec->rec.audioCtrl.upLink,
2924 infoRec->rec.audioCtrl.downLink);
2925 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002926 break;
Wink Savillea592eeb2009-05-22 13:26:36 -07002927 case RIL_CDMA_T53_RELEASE_INFO_REC:
2928 // TODO(Moto): See David Krause, he has the answer:)
Wink Saville8eb2a122012-11-19 16:05:13 -08002929 RLOGE("RIL_CDMA_T53_RELEASE_INFO_REC: return INVALID_RESPONSE");
Wink Savillea592eeb2009-05-22 13:26:36 -07002930 return RIL_ERRNO_INVALID_RESPONSE;
2931 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08002932 RLOGE("Incorrect name value");
Wink Savillea592eeb2009-05-22 13:26:36 -07002933 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002934 }
2935 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002936 closeResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002937
Wink Savillea592eeb2009-05-22 13:26:36 -07002938 return 0;
Wink Saville3d54e742009-05-18 18:00:44 -07002939}
2940
Sanket Padawe88cf6a52016-01-11 12:45:43 -08002941static void responseRilSignalStrengthV5(Parcel &p, RIL_SignalStrength_v10 *p_cur) {
2942 p.writeInt32(p_cur->GW_SignalStrength.signalStrength);
2943 p.writeInt32(p_cur->GW_SignalStrength.bitErrorRate);
2944 p.writeInt32(p_cur->CDMA_SignalStrength.dbm);
2945 p.writeInt32(p_cur->CDMA_SignalStrength.ecio);
2946 p.writeInt32(p_cur->EVDO_SignalStrength.dbm);
2947 p.writeInt32(p_cur->EVDO_SignalStrength.ecio);
2948 p.writeInt32(p_cur->EVDO_SignalStrength.signalNoiseRatio);
2949}
2950
2951static void responseRilSignalStrengthV6Extra(Parcel &p, RIL_SignalStrength_v10 *p_cur) {
2952 /*
2953 * Fixup LTE for backwards compatibility
2954 */
2955 // signalStrength: -1 -> 99
2956 if (p_cur->LTE_SignalStrength.signalStrength == -1) {
2957 p_cur->LTE_SignalStrength.signalStrength = 99;
2958 }
2959 // rsrp: -1 -> INT_MAX all other negative value to positive.
2960 // So remap here
2961 if (p_cur->LTE_SignalStrength.rsrp == -1) {
2962 p_cur->LTE_SignalStrength.rsrp = INT_MAX;
2963 } else if (p_cur->LTE_SignalStrength.rsrp < -1) {
2964 p_cur->LTE_SignalStrength.rsrp = -p_cur->LTE_SignalStrength.rsrp;
2965 }
2966 // rsrq: -1 -> INT_MAX
2967 if (p_cur->LTE_SignalStrength.rsrq == -1) {
2968 p_cur->LTE_SignalStrength.rsrq = INT_MAX;
2969 }
2970 // Not remapping rssnr is already using INT_MAX
2971
2972 // cqi: -1 -> INT_MAX
2973 if (p_cur->LTE_SignalStrength.cqi == -1) {
2974 p_cur->LTE_SignalStrength.cqi = INT_MAX;
2975 }
2976
2977 p.writeInt32(p_cur->LTE_SignalStrength.signalStrength);
2978 p.writeInt32(p_cur->LTE_SignalStrength.rsrp);
2979 p.writeInt32(p_cur->LTE_SignalStrength.rsrq);
2980 p.writeInt32(p_cur->LTE_SignalStrength.rssnr);
2981 p.writeInt32(p_cur->LTE_SignalStrength.cqi);
2982}
2983
2984static void responseRilSignalStrengthV10(Parcel &p, RIL_SignalStrength_v10 *p_cur) {
2985 responseRilSignalStrengthV5(p, p_cur);
2986 responseRilSignalStrengthV6Extra(p, p_cur);
2987 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
2988}
2989
Wink Savillea592eeb2009-05-22 13:26:36 -07002990static int responseRilSignalStrength(Parcel &p,
2991 void *response, size_t responselen) {
2992 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002993 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002994 return RIL_ERRNO_INVALID_RESPONSE;
2995 }
2996
Sanket Padawe88cf6a52016-01-11 12:45:43 -08002997 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
2998 if (responselen >= sizeof (RIL_SignalStrength_v5)) {
2999 RIL_SignalStrength_v10 *p_cur = ((RIL_SignalStrength_v10 *) response);
Wink Saville3d54e742009-05-18 18:00:44 -07003000
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003001 responseRilSignalStrengthV5(p, p_cur);
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07003002
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003003 if (responselen >= sizeof (RIL_SignalStrength_v6)) {
3004 responseRilSignalStrengthV6Extra(p, p_cur);
3005 if (responselen >= sizeof (RIL_SignalStrength_v10)) {
3006 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
3007 } else {
3008 p.writeInt32(INT_MAX);
Wink Saville18e4ab12013-04-07 17:31:04 -07003009 }
Etan Cohend3652192014-06-20 08:28:44 -07003010 } else {
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003011 p.writeInt32(99);
3012 p.writeInt32(INT_MAX);
3013 p.writeInt32(INT_MAX);
3014 p.writeInt32(INT_MAX);
3015 p.writeInt32(INT_MAX);
Etan Cohend3652192014-06-20 08:28:44 -07003016 p.writeInt32(INT_MAX);
3017 }
Wink Savillec0114b32011-02-18 10:14:07 -08003018 } else {
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003019 RLOGE("invalid response length");
3020 return RIL_ERRNO_INVALID_RESPONSE;
Wink Savillec0114b32011-02-18 10:14:07 -08003021 }
Sanket Padawef53c5fa2016-01-27 10:00:38 -08003022 } else { // RIL version >= 13
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003023 if (responselen % sizeof(RIL_SignalStrength_v10) != 0) {
3024 RLOGE("Data structure expected is RIL_SignalStrength_v10");
3025 if (!isDebuggable()) {
3026 return RIL_ERRNO_INVALID_RESPONSE;
3027 } else {
3028 assert(0);
3029 }
3030 }
3031 RIL_SignalStrength_v10 *p_cur = ((RIL_SignalStrength_v10 *) response);
3032 responseRilSignalStrengthV10(p, p_cur);
Wink Saville3d54e742009-05-18 18:00:44 -07003033 }
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003034 startResponse;
3035 appendPrintBuf("%s[signalStrength=%d,bitErrorRate=%d,\
3036 CDMA_SS.dbm=%d,CDMA_SSecio=%d,\
3037 EVDO_SS.dbm=%d,EVDO_SS.ecio=%d,\
3038 EVDO_SS.signalNoiseRatio=%d,\
3039 LTE_SS.signalStrength=%d,LTE_SS.rsrp=%d,LTE_SS.rsrq=%d,\
3040 LTE_SS.rssnr=%d,LTE_SS.cqi=%d,TDSCDMA_SS.rscp=%d]",
3041 printBuf,
3042 p_cur->GW_SignalStrength.signalStrength,
3043 p_cur->GW_SignalStrength.bitErrorRate,
3044 p_cur->CDMA_SignalStrength.dbm,
3045 p_cur->CDMA_SignalStrength.ecio,
3046 p_cur->EVDO_SignalStrength.dbm,
3047 p_cur->EVDO_SignalStrength.ecio,
3048 p_cur->EVDO_SignalStrength.signalNoiseRatio,
3049 p_cur->LTE_SignalStrength.signalStrength,
3050 p_cur->LTE_SignalStrength.rsrp,
3051 p_cur->LTE_SignalStrength.rsrq,
3052 p_cur->LTE_SignalStrength.rssnr,
3053 p_cur->LTE_SignalStrength.cqi,
3054 p_cur->TD_SCDMA_SignalStrength.rscp);
3055 closeResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07003056 return 0;
3057}
3058
3059static int responseCallRing(Parcel &p, void *response, size_t responselen) {
3060 if ((response == NULL) || (responselen == 0)) {
3061 return responseVoid(p, response, responselen);
3062 } else {
3063 return responseCdmaSignalInfoRecord(p, response, responselen);
3064 }
3065}
3066
3067static int responseCdmaSignalInfoRecord(Parcel &p, void *response, size_t responselen) {
3068 if (response == NULL || responselen == 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003069 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07003070 return RIL_ERRNO_INVALID_RESPONSE;
3071 }
3072
3073 if (responselen != sizeof (RIL_CDMA_SignalInfoRecord)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003074 RLOGE("invalid response length %d expected sizeof (RIL_CDMA_SignalInfoRecord) of %d\n",
Wink Saville3d54e742009-05-18 18:00:44 -07003075 (int)responselen, (int)sizeof (RIL_CDMA_SignalInfoRecord));
3076 return RIL_ERRNO_INVALID_RESPONSE;
3077 }
3078
3079 startResponse;
3080
3081 RIL_CDMA_SignalInfoRecord *p_cur = ((RIL_CDMA_SignalInfoRecord *) response);
3082 marshallSignalInfoRecord(p, *p_cur);
3083
3084 appendPrintBuf("%s[isPresent=%d,signalType=%d,alertPitch=%d\
3085 signal=%d]",
3086 printBuf,
3087 p_cur->isPresent,
3088 p_cur->signalType,
3089 p_cur->alertPitch,
3090 p_cur->signal);
3091
3092 closeResponse;
3093 return 0;
3094}
3095
Wink Savillea592eeb2009-05-22 13:26:36 -07003096static int responseCdmaCallWaiting(Parcel &p, void *response,
3097 size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07003098 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003099 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07003100 return RIL_ERRNO_INVALID_RESPONSE;
3101 }
3102
Wink Savillec0114b32011-02-18 10:14:07 -08003103 if (responselen < sizeof(RIL_CDMA_CallWaiting_v6)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003104 RLOGW("Upgrade to ril version %d\n", RIL_VERSION);
Wink Savillec0114b32011-02-18 10:14:07 -08003105 }
3106
3107 RIL_CDMA_CallWaiting_v6 *p_cur = ((RIL_CDMA_CallWaiting_v6 *) response);
3108
3109 writeStringToParcel(p, p_cur->number);
3110 p.writeInt32(p_cur->numberPresentation);
3111 writeStringToParcel(p, p_cur->name);
3112 marshallSignalInfoRecord(p, p_cur->signalInfoRecord);
3113
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003114 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
3115 if (responselen >= sizeof(RIL_CDMA_CallWaiting_v6)) {
3116 p.writeInt32(p_cur->number_type);
3117 p.writeInt32(p_cur->number_plan);
3118 } else {
3119 p.writeInt32(0);
3120 p.writeInt32(0);
3121 }
Sanket Padawef53c5fa2016-01-27 10:00:38 -08003122 } else { // RIL version >= 13
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003123 if (responselen % sizeof(RIL_CDMA_CallWaiting_v6) != 0) {
3124 RLOGE("Data structure expected is RIL_CDMA_CallWaiting_v6");
3125 if (!isDebuggable()) {
3126 return RIL_ERRNO_INVALID_RESPONSE;
3127 } else {
3128 assert(0);
3129 }
3130 }
Wink Savillec0114b32011-02-18 10:14:07 -08003131 p.writeInt32(p_cur->number_type);
3132 p.writeInt32(p_cur->number_plan);
Wink Saville3d54e742009-05-18 18:00:44 -07003133 }
3134
3135 startResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07003136 appendPrintBuf("%snumber=%s,numberPresentation=%d, name=%s,\
3137 signalInfoRecord[isPresent=%d,signalType=%d,alertPitch=%d\
Wink Savillec0114b32011-02-18 10:14:07 -08003138 signal=%d,number_type=%d,number_plan=%d]",
Wink Saville3d54e742009-05-18 18:00:44 -07003139 printBuf,
3140 p_cur->number,
3141 p_cur->numberPresentation,
3142 p_cur->name,
3143 p_cur->signalInfoRecord.isPresent,
3144 p_cur->signalInfoRecord.signalType,
3145 p_cur->signalInfoRecord.alertPitch,
Wink Savillec0114b32011-02-18 10:14:07 -08003146 p_cur->signalInfoRecord.signal,
3147 p_cur->number_type,
3148 p_cur->number_plan);
Wink Saville3d54e742009-05-18 18:00:44 -07003149 closeResponse;
3150
3151 return 0;
3152}
3153
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003154static void responseSimRefreshV7(Parcel &p, void *response) {
3155 RIL_SimRefreshResponse_v7 *p_cur = ((RIL_SimRefreshResponse_v7 *) response);
3156 p.writeInt32(p_cur->result);
3157 p.writeInt32(p_cur->ef_id);
3158 writeStringToParcel(p, p_cur->aid);
3159
3160 appendPrintBuf("%sresult=%d, ef_id=%d, aid=%s",
3161 printBuf,
3162 p_cur->result,
3163 p_cur->ef_id,
3164 p_cur->aid);
3165
3166}
3167
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003168static int responseSimRefresh(Parcel &p, void *response, size_t responselen) {
3169 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003170 RLOGE("responseSimRefresh: invalid response: NULL");
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003171 return RIL_ERRNO_INVALID_RESPONSE;
3172 }
3173
3174 startResponse;
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003175 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
Sanket Padawe41c94d02016-01-21 15:49:33 -08003176 if (s_callbacks.version >= 7) {
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003177 responseSimRefreshV7(p, response);
3178 } else {
3179 int *p_cur = ((int *) response);
3180 p.writeInt32(p_cur[0]);
3181 p.writeInt32(p_cur[1]);
3182 writeStringToParcel(p, NULL);
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003183
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003184 appendPrintBuf("%sresult=%d, ef_id=%d",
3185 printBuf,
3186 p_cur[0],
3187 p_cur[1]);
3188 }
Sanket Padawef53c5fa2016-01-27 10:00:38 -08003189 } else { // RIL version >= 13
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003190 if (responselen % sizeof(RIL_SimRefreshResponse_v7) != 0) {
3191 RLOGE("Data structure expected is RIL_SimRefreshResponse_v7");
3192 if (!isDebuggable()) {
3193 return RIL_ERRNO_INVALID_RESPONSE;
3194 } else {
3195 assert(0);
3196 }
3197 }
3198 responseSimRefreshV7(p, response);
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003199
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003200 }
3201 closeResponse;
3202
3203 return 0;
3204}
3205
Sanket Padawef53c5fa2016-01-27 10:00:38 -08003206static int responseCellInfoListV6(Parcel &p, void *response, size_t responselen) {
Wink Saville8a9e0212013-04-09 12:11:38 -07003207 if (response == NULL && responselen != 0) {
3208 RLOGE("invalid response: NULL");
3209 return RIL_ERRNO_INVALID_RESPONSE;
3210 }
3211
3212 if (responselen % sizeof(RIL_CellInfo) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07003213 RLOGE("responseCellInfoList: invalid response length %d expected multiple of %d",
Wink Saville8a9e0212013-04-09 12:11:38 -07003214 (int)responselen, (int)sizeof(RIL_CellInfo));
3215 return RIL_ERRNO_INVALID_RESPONSE;
3216 }
3217
3218 int num = responselen / sizeof(RIL_CellInfo);
3219 p.writeInt32(num);
3220
3221 RIL_CellInfo *p_cur = (RIL_CellInfo *) response;
3222 startResponse;
3223 int i;
3224 for (i = 0; i < num; i++) {
3225 appendPrintBuf("%s[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", printBuf, i,
3226 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
3227 p.writeInt32((int)p_cur->cellInfoType);
3228 p.writeInt32(p_cur->registered);
3229 p.writeInt32(p_cur->timeStampType);
3230 p.writeInt64(p_cur->timeStamp);
3231 switch(p_cur->cellInfoType) {
3232 case RIL_CELL_INFO_TYPE_GSM: {
Wink Savillec57b3eb2013-04-17 12:51:41 -07003233 appendPrintBuf("%s GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,", printBuf,
Wink Saville8a9e0212013-04-09 12:11:38 -07003234 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
3235 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
3236 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
Wink Savillec57b3eb2013-04-17 12:51:41 -07003237 p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3238 appendPrintBuf("%s gsmSS: ss=%d,ber=%d],", printBuf,
Wink Saville8a9e0212013-04-09 12:11:38 -07003239 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
3240 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3241
3242 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
3243 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
3244 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
3245 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
Wink Saville8a9e0212013-04-09 12:11:38 -07003246 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
3247 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3248 break;
3249 }
Wink Savillec57b3eb2013-04-17 12:51:41 -07003250 case RIL_CELL_INFO_TYPE_WCDMA: {
3251 appendPrintBuf("%s WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,", printBuf,
3252 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
3253 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
3254 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
3255 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
3256 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3257 appendPrintBuf("%s wcdmaSS: ss=%d,ber=%d],", printBuf,
3258 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
3259 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3260
3261 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
3262 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
3263 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
3264 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
3265 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3266 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
3267 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3268 break;
3269 }
Wink Saville8a9e0212013-04-09 12:11:38 -07003270 case RIL_CELL_INFO_TYPE_CDMA: {
3271 appendPrintBuf("%s CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d", printBuf,
3272 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
3273 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
3274 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
3275 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
3276 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3277
3278 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
3279 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
3280 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
3281 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
3282 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3283
3284 appendPrintBuf("%s cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d", printBuf,
3285 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
3286 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
3287 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
3288 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
3289 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3290
3291 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
3292 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
3293 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
3294 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
3295 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3296 break;
3297 }
3298 case RIL_CELL_INFO_TYPE_LTE: {
3299 appendPrintBuf("%s LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d", printBuf,
3300 p_cur->CellInfo.lte.cellIdentityLte.mcc,
3301 p_cur->CellInfo.lte.cellIdentityLte.mnc,
3302 p_cur->CellInfo.lte.cellIdentityLte.ci,
3303 p_cur->CellInfo.lte.cellIdentityLte.pci,
3304 p_cur->CellInfo.lte.cellIdentityLte.tac);
3305
3306 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
3307 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
3308 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
3309 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
3310 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
3311
3312 appendPrintBuf("%s lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d", printBuf,
3313 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
3314 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
3315 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
3316 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
3317 p_cur->CellInfo.lte.signalStrengthLte.cqi,
3318 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3319 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
3320 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
3321 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
3322 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
3323 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
3324 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3325 break;
3326 }
Etan Cohend3652192014-06-20 08:28:44 -07003327 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
3328 appendPrintBuf("%s TDSCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,cpid=%d,", printBuf,
3329 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc,
3330 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc,
3331 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac,
3332 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid,
3333 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3334 appendPrintBuf("%s tdscdmaSS: rscp=%d],", printBuf,
3335 p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3336
3337 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
3338 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
3339 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
3340 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
3341 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3342 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3343 break;
3344 }
Wink Saville8a9e0212013-04-09 12:11:38 -07003345 }
3346 p_cur += 1;
3347 }
3348 removeLastChar;
3349 closeResponse;
3350
3351 return 0;
3352}
3353
Sanket Padawef53c5fa2016-01-27 10:00:38 -08003354static int responseCellInfoListV12(Parcel &p, void *response, size_t responselen) {
3355 if (response == NULL && responselen != 0) {
3356 RLOGE("invalid response: NULL");
3357 return RIL_ERRNO_INVALID_RESPONSE;
3358 }
3359
3360 if (responselen % sizeof(RIL_CellInfo_v12) != 0) {
3361 RLOGE("responseCellInfoList: invalid response length %d expected multiple of %d",
3362 (int)responselen, (int)sizeof(RIL_CellInfo_v12));
3363 return RIL_ERRNO_INVALID_RESPONSE;
3364 }
3365
3366 int num = responselen / sizeof(RIL_CellInfo_v12);
3367 p.writeInt32(num);
3368
3369 RIL_CellInfo_v12 *p_cur = (RIL_CellInfo_v12 *) response;
3370 startResponse;
3371 int i;
3372 for (i = 0; i < num; i++) {
3373 appendPrintBuf("%s[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", printBuf, i,
3374 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
3375 RLOGE("[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", i,
3376 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
3377 p.writeInt32((int)p_cur->cellInfoType);
3378 p.writeInt32(p_cur->registered);
3379 p.writeInt32(p_cur->timeStampType);
3380 p.writeInt64(p_cur->timeStamp);
3381 switch(p_cur->cellInfoType) {
3382 case RIL_CELL_INFO_TYPE_GSM: {
3383 appendPrintBuf("%s GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,arfcn=%d,bsic=%x", printBuf,
3384 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
3385 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
3386 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
3387 p_cur->CellInfo.gsm.cellIdentityGsm.cid,
3388 p_cur->CellInfo.gsm.cellIdentityGsm.arfcn,
3389 p_cur->CellInfo.gsm.cellIdentityGsm.bsic);
3390 RLOGE("GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,arfcn=%d,bsic=%x",
3391 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
3392 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
3393 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
3394 p_cur->CellInfo.gsm.cellIdentityGsm.cid,
3395 p_cur->CellInfo.gsm.cellIdentityGsm.arfcn,
3396 p_cur->CellInfo.gsm.cellIdentityGsm.bsic);
3397 RLOGE("gsmSS: ss=%d,ber=%d, ta=%d],",
3398 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
3399 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate,
3400 p_cur->CellInfo.gsm.signalStrengthGsm.timingAdvance);
3401 appendPrintBuf("%s gsmSS: ss=%d,ber=%d, ta=%d],", printBuf,
3402 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
3403 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate,
3404 p_cur->CellInfo.gsm.signalStrengthGsm.timingAdvance);
3405
3406 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
3407 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
3408 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
3409 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3410 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.arfcn);
3411 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.bsic);
3412 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
3413 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3414 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.timingAdvance);
3415 break;
3416 }
3417 case RIL_CELL_INFO_TYPE_WCDMA: {
3418 RLOGE("WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,uarfcn=%d",
3419 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
3420 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
3421 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
3422 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
3423 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc,
3424 p_cur->CellInfo.wcdma.cellIdentityWcdma.uarfcn);
3425 RLOGE("wcdmaSS: ss=%d,ber=%d],",
3426 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
3427 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3428 appendPrintBuf("%s WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,uarfcn=%d", printBuf,
3429 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
3430 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
3431 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
3432 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
3433 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc,
3434 p_cur->CellInfo.wcdma.cellIdentityWcdma.uarfcn);
3435 appendPrintBuf("%s wcdmaSS: ss=%d,ber=%d],", printBuf,
3436 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
3437 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3438
3439 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
3440 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
3441 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
3442 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
3443 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3444 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.uarfcn);
3445 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
3446 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3447 break;
3448 }
3449 case RIL_CELL_INFO_TYPE_CDMA: {
3450 RLOGE("CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d",
3451 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
3452 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
3453 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
3454 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
3455 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3456
3457 appendPrintBuf("%s CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d", printBuf,
3458 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
3459 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
3460 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
3461 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
3462 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3463
3464 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
3465 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
3466 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
3467 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
3468 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3469
3470 RLOGE("cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d",
3471 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
3472 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
3473 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
3474 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
3475 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3476
3477 appendPrintBuf("%s cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d", printBuf,
3478 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
3479 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
3480 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
3481 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
3482 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3483
3484 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
3485 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
3486 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
3487 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
3488 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3489 break;
3490 }
3491 case RIL_CELL_INFO_TYPE_LTE: {
3492 RLOGE("LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d,earfcn=%d",
3493 p_cur->CellInfo.lte.cellIdentityLte.mcc,
3494 p_cur->CellInfo.lte.cellIdentityLte.mnc,
3495 p_cur->CellInfo.lte.cellIdentityLte.ci,
3496 p_cur->CellInfo.lte.cellIdentityLte.pci,
3497 p_cur->CellInfo.lte.cellIdentityLte.tac,
3498 p_cur->CellInfo.lte.cellIdentityLte.earfcn);
3499
3500 appendPrintBuf("%s LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d,earfcn=%d", printBuf,
3501 p_cur->CellInfo.lte.cellIdentityLte.mcc,
3502 p_cur->CellInfo.lte.cellIdentityLte.mnc,
3503 p_cur->CellInfo.lte.cellIdentityLte.ci,
3504 p_cur->CellInfo.lte.cellIdentityLte.pci,
3505 p_cur->CellInfo.lte.cellIdentityLte.tac,
3506 p_cur->CellInfo.lte.cellIdentityLte.earfcn);
3507
3508 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
3509 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
3510 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
3511 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
3512 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
3513 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.earfcn);
3514
3515 RLOGE("lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d",
3516 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
3517 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
3518 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
3519 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
3520 p_cur->CellInfo.lte.signalStrengthLte.cqi,
3521 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3522 appendPrintBuf("%s lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d", printBuf,
3523 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
3524 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
3525 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
3526 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
3527 p_cur->CellInfo.lte.signalStrengthLte.cqi,
3528 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3529 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
3530 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
3531 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
3532 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
3533 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
3534 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3535 break;
3536 }
3537 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
3538 appendPrintBuf("%s TDSCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,cpid=%d,", printBuf,
3539 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc,
3540 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc,
3541 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac,
3542 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid,
3543 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3544 appendPrintBuf("%s tdscdmaSS: rscp=%d],", printBuf,
3545 p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3546
3547 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
3548 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
3549 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
3550 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
3551 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3552 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3553 break;
3554 }
3555 }
3556 p_cur += 1;
3557 }
3558 removeLastChar;
3559 closeResponse;
3560 return 0;
3561}
3562
3563static int responseCellInfoList(Parcel &p, void *response, size_t responselen)
3564{
3565 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
3566 if (s_callbacks.version < 12) {
3567 RLOGD("responseCellInfoList: v6");
3568 return responseCellInfoListV6(p, response, responselen);
3569 } else {
3570 RLOGD("responseCellInfoList: v12");
3571 return responseCellInfoListV12(p, response, responselen);
3572 }
3573 } else { // RIL version >= 13
3574 if (responselen % sizeof(RIL_CellInfo_v12) != 0) {
3575 RLOGE("Data structure expected is RIL_CellInfo_v12");
3576 if (!isDebuggable()) {
3577 return RIL_ERRNO_INVALID_RESPONSE;
3578 } else {
3579 assert(0);
3580 }
3581 }
3582 return responseCellInfoListV12(p, response, responselen);
3583 }
3584
3585 return 0;
3586}
3587
Etan Cohend3652192014-06-20 08:28:44 -07003588static int responseHardwareConfig(Parcel &p, void *response, size_t responselen)
3589{
3590 if (response == NULL && responselen != 0) {
3591 RLOGE("invalid response: NULL");
3592 return RIL_ERRNO_INVALID_RESPONSE;
3593 }
3594
3595 if (responselen % sizeof(RIL_HardwareConfig) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07003596 RLOGE("responseHardwareConfig: invalid response length %d expected multiple of %d",
Etan Cohend3652192014-06-20 08:28:44 -07003597 (int)responselen, (int)sizeof(RIL_HardwareConfig));
3598 return RIL_ERRNO_INVALID_RESPONSE;
3599 }
3600
3601 int num = responselen / sizeof(RIL_HardwareConfig);
3602 int i;
3603 RIL_HardwareConfig *p_cur = (RIL_HardwareConfig *) response;
3604
3605 p.writeInt32(num);
3606
3607 startResponse;
3608 for (i = 0; i < num; i++) {
3609 switch (p_cur[i].type) {
3610 case RIL_HARDWARE_CONFIG_MODEM: {
3611 writeStringToParcel(p, p_cur[i].uuid);
3612 p.writeInt32((int)p_cur[i].state);
3613 p.writeInt32(p_cur[i].cfg.modem.rat);
3614 p.writeInt32(p_cur[i].cfg.modem.maxVoice);
3615 p.writeInt32(p_cur[i].cfg.modem.maxData);
3616 p.writeInt32(p_cur[i].cfg.modem.maxStandby);
3617
3618 appendPrintBuf("%s modem: uuid=%s,state=%d,rat=%08x,maxV=%d,maxD=%d,maxS=%d", printBuf,
3619 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.modem.rat,
3620 p_cur[i].cfg.modem.maxVoice, p_cur[i].cfg.modem.maxData, p_cur[i].cfg.modem.maxStandby);
3621 break;
3622 }
3623 case RIL_HARDWARE_CONFIG_SIM: {
3624 writeStringToParcel(p, p_cur[i].uuid);
3625 p.writeInt32((int)p_cur[i].state);
3626 writeStringToParcel(p, p_cur[i].cfg.sim.modemUuid);
3627
3628 appendPrintBuf("%s sim: uuid=%s,state=%d,modem-uuid=%s", printBuf,
3629 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.sim.modemUuid);
3630 break;
3631 }
3632 }
3633 }
3634 removeLastChar;
3635 closeResponse;
3636 return 0;
3637}
3638
Wink Saville8b4e4f72014-10-17 15:01:45 -07003639static int responseRadioCapability(Parcel &p, void *response, size_t responselen) {
3640 if (response == NULL) {
3641 RLOGE("invalid response: NULL");
3642 return RIL_ERRNO_INVALID_RESPONSE;
3643 }
3644
3645 if (responselen != sizeof (RIL_RadioCapability) ) {
3646 RLOGE("invalid response length was %d expected %d",
3647 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3648 return RIL_ERRNO_INVALID_RESPONSE;
3649 }
3650
3651 RIL_RadioCapability *p_cur = (RIL_RadioCapability *) response;
3652 p.writeInt32(p_cur->version);
3653 p.writeInt32(p_cur->session);
3654 p.writeInt32(p_cur->phase);
3655 p.writeInt32(p_cur->rat);
3656 writeStringToParcel(p, p_cur->logicalModemUuid);
3657 p.writeInt32(p_cur->status);
3658
3659 startResponse;
3660 appendPrintBuf("%s[version=%d,session=%d,phase=%d,\
Legler Wu8caf06f2014-10-29 14:02:14 +08003661 rat=%s,logicalModemUuid=%s,status=%d]",
Wink Saville8b4e4f72014-10-17 15:01:45 -07003662 printBuf,
3663 p_cur->version,
3664 p_cur->session,
3665 p_cur->phase,
3666 p_cur->rat,
Legler Wu8caf06f2014-10-29 14:02:14 +08003667 p_cur->logicalModemUuid,
Wink Saville8b4e4f72014-10-17 15:01:45 -07003668 p_cur->status);
3669 closeResponse;
3670 return 0;
3671}
3672
Amit Mahajan54563d32014-11-22 00:54:49 +00003673static int responseSSData(Parcel &p, void *response, size_t responselen) {
3674 RLOGD("In responseSSData");
3675 int num;
3676
3677 if (response == NULL && responselen != 0) {
3678 RLOGE("invalid response length was %d expected %d",
3679 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3680 return RIL_ERRNO_INVALID_RESPONSE;
3681 }
3682
3683 if (responselen != sizeof(RIL_StkCcUnsolSsResponse)) {
3684 RLOGE("invalid response length %d, expected %d",
3685 (int)responselen, (int)sizeof(RIL_StkCcUnsolSsResponse));
3686 return RIL_ERRNO_INVALID_RESPONSE;
3687 }
3688
3689 startResponse;
3690 RIL_StkCcUnsolSsResponse *p_cur = (RIL_StkCcUnsolSsResponse *) response;
3691 p.writeInt32(p_cur->serviceType);
3692 p.writeInt32(p_cur->requestType);
3693 p.writeInt32(p_cur->teleserviceType);
3694 p.writeInt32(p_cur->serviceClass);
3695 p.writeInt32(p_cur->result);
3696
3697 if (isServiceTypeCfQuery(p_cur->serviceType, p_cur->requestType)) {
3698 RLOGD("responseSSData CF type, num of Cf elements %d", p_cur->cfData.numValidIndexes);
3699 if (p_cur->cfData.numValidIndexes > NUM_SERVICE_CLASSES) {
3700 RLOGE("numValidIndexes is greater than max value %d, "
3701 "truncating it to max value", NUM_SERVICE_CLASSES);
3702 p_cur->cfData.numValidIndexes = NUM_SERVICE_CLASSES;
3703 }
3704 /* number of call info's */
3705 p.writeInt32(p_cur->cfData.numValidIndexes);
3706
3707 for (int i = 0; i < p_cur->cfData.numValidIndexes; i++) {
3708 RIL_CallForwardInfo cf = p_cur->cfData.cfInfo[i];
3709
3710 p.writeInt32(cf.status);
3711 p.writeInt32(cf.reason);
3712 p.writeInt32(cf.serviceClass);
3713 p.writeInt32(cf.toa);
3714 writeStringToParcel(p, cf.number);
3715 p.writeInt32(cf.timeSeconds);
3716 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
3717 (cf.status==1)?"enable":"disable", cf.reason, cf.serviceClass, cf.toa,
3718 (char*)cf.number, cf.timeSeconds);
3719 RLOGD("Data: %d,reason=%d,cls=%d,toa=%d,num=%s,tout=%d],", cf.status,
3720 cf.reason, cf.serviceClass, cf.toa, (char*)cf.number, cf.timeSeconds);
3721 }
3722 } else {
3723 p.writeInt32 (SS_INFO_MAX);
3724
3725 /* each int*/
3726 for (int i = 0; i < SS_INFO_MAX; i++) {
3727 appendPrintBuf("%s%d,", printBuf, p_cur->ssInfo[i]);
3728 RLOGD("Data: %d",p_cur->ssInfo[i]);
3729 p.writeInt32(p_cur->ssInfo[i]);
3730 }
3731 }
3732 removeLastChar;
3733 closeResponse;
3734
3735 return 0;
3736}
3737
3738static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType) {
3739 if ((reqType == SS_INTERROGATION) &&
3740 (serType == SS_CFU ||
3741 serType == SS_CF_BUSY ||
3742 serType == SS_CF_NO_REPLY ||
3743 serType == SS_CF_NOT_REACHABLE ||
3744 serType == SS_CF_ALL ||
3745 serType == SS_CF_ALL_CONDITIONAL)) {
3746 return true;
3747 }
3748 return false;
3749}
3750
Wink Saville3d54e742009-05-18 18:00:44 -07003751static void triggerEvLoop() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003752 int ret;
3753 if (!pthread_equal(pthread_self(), s_tid_dispatch)) {
3754 /* trigger event loop to wakeup. No reason to do this,
3755 * if we're in the event loop thread */
3756 do {
3757 ret = write (s_fdWakeupWrite, " ", 1);
3758 } while (ret < 0 && errno == EINTR);
3759 }
3760}
3761
Wink Saville3d54e742009-05-18 18:00:44 -07003762static void rilEventAddWakeup(struct ril_event *ev) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003763 ril_event_add(ev);
3764 triggerEvLoop();
3765}
3766
Wink Savillefd729372011-02-22 16:19:39 -08003767static void sendSimStatusAppInfo(Parcel &p, int num_apps, RIL_AppStatus appStatus[]) {
3768 p.writeInt32(num_apps);
3769 startResponse;
3770 for (int i = 0; i < num_apps; i++) {
3771 p.writeInt32(appStatus[i].app_type);
3772 p.writeInt32(appStatus[i].app_state);
3773 p.writeInt32(appStatus[i].perso_substate);
3774 writeStringToParcel(p, (const char*)(appStatus[i].aid_ptr));
3775 writeStringToParcel(p, (const char*)
3776 (appStatus[i].app_label_ptr));
3777 p.writeInt32(appStatus[i].pin1_replaced);
3778 p.writeInt32(appStatus[i].pin1);
3779 p.writeInt32(appStatus[i].pin2);
3780 appendPrintBuf("%s[app_type=%d,app_state=%d,perso_substate=%d,\
3781 aid_ptr=%s,app_label_ptr=%s,pin1_replaced=%d,pin1=%d,pin2=%d],",
3782 printBuf,
3783 appStatus[i].app_type,
3784 appStatus[i].app_state,
3785 appStatus[i].perso_substate,
3786 appStatus[i].aid_ptr,
3787 appStatus[i].app_label_ptr,
3788 appStatus[i].pin1_replaced,
3789 appStatus[i].pin1,
3790 appStatus[i].pin2);
3791 }
3792 closeResponse;
3793}
3794
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003795static void responseSimStatusV5(Parcel &p, void *response) {
3796 RIL_CardStatus_v5 *p_cur = ((RIL_CardStatus_v5 *) response);
3797
3798 p.writeInt32(p_cur->card_state);
3799 p.writeInt32(p_cur->universal_pin_state);
3800 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3801 p.writeInt32(p_cur->cdma_subscription_app_index);
3802
3803 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
3804}
3805
3806static void responseSimStatusV6(Parcel &p, void *response) {
3807 RIL_CardStatus_v6 *p_cur = ((RIL_CardStatus_v6 *) response);
3808
3809 p.writeInt32(p_cur->card_state);
3810 p.writeInt32(p_cur->universal_pin_state);
3811 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3812 p.writeInt32(p_cur->cdma_subscription_app_index);
3813 p.writeInt32(p_cur->ims_subscription_app_index);
3814
3815 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
3816}
3817
Wink Savillef4c4d362009-04-02 01:37:03 -07003818static int responseSimStatus(Parcel &p, void *response, size_t responselen) {
3819 int i;
3820
3821 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003822 RLOGE("invalid response: NULL");
Wink Savillef4c4d362009-04-02 01:37:03 -07003823 return RIL_ERRNO_INVALID_RESPONSE;
3824 }
3825
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003826 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
3827 if (responselen == sizeof (RIL_CardStatus_v6)) {
3828 responseSimStatusV6(p, response);
3829 } else if (responselen == sizeof (RIL_CardStatus_v5)) {
3830 responseSimStatusV5(p, response);
3831 } else {
3832 RLOGE("responseSimStatus: A RilCardStatus_v6 or _v5 expected\n");
3833 return RIL_ERRNO_INVALID_RESPONSE;
3834 }
Sanket Padawef53c5fa2016-01-27 10:00:38 -08003835 } else { // RIL version >= 13
Sanket Padawe88cf6a52016-01-11 12:45:43 -08003836 if (responselen % sizeof(RIL_CardStatus_v6) != 0) {
3837 RLOGE("Data structure expected is RIL_CardStatus_v6");
3838 if (!isDebuggable()) {
3839 return RIL_ERRNO_INVALID_RESPONSE;
3840 } else {
3841 assert(0);
3842 }
3843 }
3844 responseSimStatusV6(p, response);
Wink Savillef4c4d362009-04-02 01:37:03 -07003845 }
Wink Savillef4c4d362009-04-02 01:37:03 -07003846
3847 return 0;
Wink Saville3d54e742009-05-18 18:00:44 -07003848}
Wink Savillef4c4d362009-04-02 01:37:03 -07003849
Wink Savillea592eeb2009-05-22 13:26:36 -07003850static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3851 int num = responselen / sizeof(RIL_GSM_BroadcastSmsConfigInfo *);
Wink Savillef4c4d362009-04-02 01:37:03 -07003852 p.writeInt32(num);
3853
Wink Savillef4c4d362009-04-02 01:37:03 -07003854 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07003855 RIL_GSM_BroadcastSmsConfigInfo **p_cur =
3856 (RIL_GSM_BroadcastSmsConfigInfo **) response;
3857 for (int i = 0; i < num; i++) {
3858 p.writeInt32(p_cur[i]->fromServiceId);
3859 p.writeInt32(p_cur[i]->toServiceId);
3860 p.writeInt32(p_cur[i]->fromCodeScheme);
3861 p.writeInt32(p_cur[i]->toCodeScheme);
3862 p.writeInt32(p_cur[i]->selected);
3863
3864 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId=%d, \
3865 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]",
3866 printBuf, i, p_cur[i]->fromServiceId, p_cur[i]->toServiceId,
3867 p_cur[i]->fromCodeScheme, p_cur[i]->toCodeScheme,
3868 p_cur[i]->selected);
3869 }
Wink Savillef4c4d362009-04-02 01:37:03 -07003870 closeResponse;
3871
3872 return 0;
3873}
3874
Wink Savillea592eeb2009-05-22 13:26:36 -07003875static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3876 RIL_CDMA_BroadcastSmsConfigInfo **p_cur =
3877 (RIL_CDMA_BroadcastSmsConfigInfo **) response;
Wink Savillef4c4d362009-04-02 01:37:03 -07003878
Wink Savillea592eeb2009-05-22 13:26:36 -07003879 int num = responselen / sizeof (RIL_CDMA_BroadcastSmsConfigInfo *);
3880 p.writeInt32(num);
Wink Savillef4c4d362009-04-02 01:37:03 -07003881
3882 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07003883 for (int i = 0 ; i < num ; i++ ) {
3884 p.writeInt32(p_cur[i]->service_category);
3885 p.writeInt32(p_cur[i]->language);
3886 p.writeInt32(p_cur[i]->selected);
Wink Savillef4c4d362009-04-02 01:37:03 -07003887
Wink Savillea592eeb2009-05-22 13:26:36 -07003888 appendPrintBuf("%s [%d: srvice_category=%d, language =%d, \
3889 selected =%d], ",
3890 printBuf, i, p_cur[i]->service_category, p_cur[i]->language,
3891 p_cur[i]->selected);
Wink Savillef5903df2009-04-24 11:54:14 -07003892 }
Wink Savillea592eeb2009-05-22 13:26:36 -07003893 closeResponse;
Wink Savillef5903df2009-04-24 11:54:14 -07003894
Wink Savillef4c4d362009-04-02 01:37:03 -07003895 return 0;
3896}
3897
3898static int responseCdmaSms(Parcel &p, void *response, size_t responselen) {
3899 int num;
3900 int digitCount;
3901 int digitLimit;
3902 uint8_t uct;
3903 void* dest;
3904
Wink Saville8eb2a122012-11-19 16:05:13 -08003905 RLOGD("Inside responseCdmaSms");
Wink Savillef5903df2009-04-24 11:54:14 -07003906
Wink Savillef4c4d362009-04-02 01:37:03 -07003907 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003908 RLOGE("invalid response: NULL");
Wink Savillef4c4d362009-04-02 01:37:03 -07003909 return RIL_ERRNO_INVALID_RESPONSE;
3910 }
3911
Wink Savillef5903df2009-04-24 11:54:14 -07003912 if (responselen != sizeof(RIL_CDMA_SMS_Message)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003913 RLOGE("invalid response length was %d expected %d",
Wink Savillef5903df2009-04-24 11:54:14 -07003914 (int)responselen, (int)sizeof(RIL_CDMA_SMS_Message));
Wink Savillef4c4d362009-04-02 01:37:03 -07003915 return RIL_ERRNO_INVALID_RESPONSE;
3916 }
3917
3918 RIL_CDMA_SMS_Message *p_cur = (RIL_CDMA_SMS_Message *) response;
3919 p.writeInt32(p_cur->uTeleserviceID);
3920 p.write(&(p_cur->bIsServicePresent),sizeof(uct));
3921 p.writeInt32(p_cur->uServicecategory);
3922 p.writeInt32(p_cur->sAddress.digit_mode);
3923 p.writeInt32(p_cur->sAddress.number_mode);
3924 p.writeInt32(p_cur->sAddress.number_type);
3925 p.writeInt32(p_cur->sAddress.number_plan);
3926 p.write(&(p_cur->sAddress.number_of_digits), sizeof(uct));
3927 digitLimit= MIN((p_cur->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
3928 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3929 p.write(&(p_cur->sAddress.digits[digitCount]),sizeof(uct));
3930 }
3931
3932 p.writeInt32(p_cur->sSubAddress.subaddressType);
3933 p.write(&(p_cur->sSubAddress.odd),sizeof(uct));
3934 p.write(&(p_cur->sSubAddress.number_of_digits),sizeof(uct));
3935 digitLimit= MIN((p_cur->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
3936 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3937 p.write(&(p_cur->sSubAddress.digits[digitCount]),sizeof(uct));
3938 }
3939
3940 digitLimit= MIN((p_cur->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
3941 p.writeInt32(p_cur->uBearerDataLen);
3942 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3943 p.write(&(p_cur->aBearerData[digitCount]), sizeof(uct));
3944 }
3945
3946 startResponse;
3947 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
Wink Saville1b5fd232009-04-22 14:50:00 -07003948 sAddress.digit_mode=%d, sAddress.number_mode=%d, sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07003949 printBuf, p_cur->uTeleserviceID,p_cur->bIsServicePresent,p_cur->uServicecategory,
3950 p_cur->sAddress.digit_mode, p_cur->sAddress.number_mode,p_cur->sAddress.number_type);
3951 closeResponse;
3952
3953 return 0;
3954}
3955
Wink Savillec29360a2014-07-13 05:17:28 -07003956static int responseDcRtInfo(Parcel &p, void *response, size_t responselen)
3957{
3958 int num = responselen / sizeof(RIL_DcRtInfo);
3959 if ((responselen % sizeof(RIL_DcRtInfo) != 0) || (num != 1)) {
Amit Mahajan52500162014-07-29 17:36:48 -07003960 RLOGE("responseDcRtInfo: invalid response length %d expected multiple of %d",
Wink Savillec29360a2014-07-13 05:17:28 -07003961 (int)responselen, (int)sizeof(RIL_DcRtInfo));
3962 return RIL_ERRNO_INVALID_RESPONSE;
3963 }
3964
3965 startResponse;
3966 RIL_DcRtInfo *pDcRtInfo = (RIL_DcRtInfo *)response;
3967 p.writeInt64(pDcRtInfo->time);
3968 p.writeInt32(pDcRtInfo->powerState);
3969 appendPrintBuf("%s[time=%d,powerState=%d]", printBuf,
3970 pDcRtInfo->time,
3971 pDcRtInfo->powerState);
3972 closeResponse;
3973
3974 return 0;
3975}
3976
fengluf7408292015-04-14 14:53:55 -07003977static int responseLceStatus(Parcel &p, void *response, size_t responselen) {
3978 if (response == NULL || responselen != sizeof(RIL_LceStatusInfo)) {
3979 if (response == NULL) {
3980 RLOGE("invalid response: NULL");
3981 }
3982 else {
3983 RLOGE("responseLceStatus: invalid response length %d expecting len: d%",
3984 sizeof(RIL_LceStatusInfo), responselen);
3985 }
3986 return RIL_ERRNO_INVALID_RESPONSE;
3987 }
3988
3989 RIL_LceStatusInfo *p_cur = (RIL_LceStatusInfo *)response;
3990 p.write((void *)p_cur, 1); // p_cur->lce_status takes one byte.
3991 p.writeInt32(p_cur->actual_interval_ms);
3992
3993 startResponse;
3994 appendPrintBuf("LCE Status: %d, actual_interval_ms: %d",
3995 p_cur->lce_status, p_cur->actual_interval_ms);
3996 closeResponse;
3997
3998 return 0;
3999}
4000
4001static int responseLceData(Parcel &p, void *response, size_t responselen) {
4002 if (response == NULL || responselen != sizeof(RIL_LceDataInfo)) {
4003 if (response == NULL) {
4004 RLOGE("invalid response: NULL");
4005 }
4006 else {
4007 RLOGE("responseLceData: invalid response length %d expecting len: d%",
4008 sizeof(RIL_LceDataInfo), responselen);
4009 }
4010 return RIL_ERRNO_INVALID_RESPONSE;
4011 }
4012
4013 RIL_LceDataInfo *p_cur = (RIL_LceDataInfo *)response;
4014 p.writeInt32(p_cur->last_hop_capacity_kbps);
4015
4016 /* p_cur->confidence_level and p_cur->lce_suspended take 1 byte each.*/
4017 p.write((void *)&(p_cur->confidence_level), 1);
4018 p.write((void *)&(p_cur->lce_suspended), 1);
4019
4020 startResponse;
4021 appendPrintBuf("LCE info received: capacity %d confidence level %d
4022 and suspended %d",
4023 p_cur->last_hop_capacity_kbps, p_cur->confidence_level,
4024 p_cur->lce_suspended);
4025 closeResponse;
4026
4027 return 0;
4028}
4029
Prerepa Viswanadham73157492015-05-28 00:37:32 -07004030static int responseActivityData(Parcel &p, void *response, size_t responselen) {
4031 if (response == NULL || responselen != sizeof(RIL_ActivityStatsInfo)) {
4032 if (response == NULL) {
4033 RLOGE("invalid response: NULL");
4034 }
4035 else {
4036 RLOGE("responseActivityData: invalid response length %d expecting len: d%",
4037 sizeof(RIL_ActivityStatsInfo), responselen);
4038 }
4039 return RIL_ERRNO_INVALID_RESPONSE;
4040 }
4041
4042 RIL_ActivityStatsInfo *p_cur = (RIL_ActivityStatsInfo *)response;
4043 p.writeInt32(p_cur->sleep_mode_time_ms);
4044 p.writeInt32(p_cur->idle_mode_time_ms);
4045 for(int i = 0; i < RIL_NUM_TX_POWER_LEVELS; i++) {
4046 p.writeInt32(p_cur->tx_mode_time_ms[i]);
4047 }
4048 p.writeInt32(p_cur->rx_mode_time_ms);
4049
4050 startResponse;
4051 appendPrintBuf("Modem activity info received: sleep_mode_time_ms %d idle_mode_time_ms %d
4052 tx_mode_time_ms %d %d %d %d %d and rx_mode_time_ms %d",
4053 p_cur->sleep_mode_time_ms, p_cur->idle_mode_time_ms, p_cur->tx_mode_time_ms[0],
4054 p_cur->tx_mode_time_ms[1], p_cur->tx_mode_time_ms[2], p_cur->tx_mode_time_ms[3],
4055 p_cur->tx_mode_time_ms[4], p_cur->rx_mode_time_ms);
4056 closeResponse;
4057
4058 return 0;
4059}
4060
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004061/**
4062 * A write on the wakeup fd is done just to pop us out of select()
4063 * We empty the buffer here and then ril_event will reset the timers on the
4064 * way back down
4065 */
Wink Savillef4c4d362009-04-02 01:37:03 -07004066static void processWakeupCallback(int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004067 char buff[16];
4068 int ret;
4069
Wink Saville8eb2a122012-11-19 16:05:13 -08004070 RLOGV("processWakeupCallback");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004071
4072 /* empty our wakeup socket out */
4073 do {
4074 ret = read(s_fdWakeupRead, &buff, sizeof(buff));
Wink Saville7f856802009-06-09 10:23:37 -07004075 } while (ret > 0 || (ret < 0 && errno == EINTR));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004076}
4077
Etan Cohend3652192014-06-20 08:28:44 -07004078static void onCommandsSocketClosed(RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004079 int ret;
4080 RequestInfo *p_cur;
Etan Cohend3652192014-06-20 08:28:44 -07004081 /* Hook for current context
4082 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
4083 pthread_mutex_t * pendingRequestsMutexHook = &s_pendingRequestsMutex;
4084 /* pendingRequestsHook refer to &s_pendingRequests */
4085 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004086
Etan Cohend3652192014-06-20 08:28:44 -07004087#if (SIM_COUNT >= 2)
4088 if (socket_id == RIL_SOCKET_2) {
4089 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
4090 pendingRequestsHook = &s_pendingRequests_socket2;
4091 }
4092#if (SIM_COUNT >= 3)
4093 else if (socket_id == RIL_SOCKET_3) {
4094 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
4095 pendingRequestsHook = &s_pendingRequests_socket3;
4096 }
4097#endif
4098#if (SIM_COUNT >= 4)
4099 else if (socket_id == RIL_SOCKET_4) {
4100 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
4101 pendingRequestsHook = &s_pendingRequests_socket4;
4102 }
4103#endif
4104#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004105 /* mark pending requests as "cancelled" so we dont report responses */
Etan Cohend3652192014-06-20 08:28:44 -07004106 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004107 assert (ret == 0);
4108
Etan Cohend3652192014-06-20 08:28:44 -07004109 p_cur = *pendingRequestsHook;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004110
Etan Cohend3652192014-06-20 08:28:44 -07004111 for (p_cur = *pendingRequestsHook
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004112 ; p_cur != NULL
4113 ; p_cur = p_cur->p_next
4114 ) {
4115 p_cur->cancelled = 1;
4116 }
4117
Etan Cohend3652192014-06-20 08:28:44 -07004118 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004119 assert (ret == 0);
4120}
4121
Wink Savillef4c4d362009-04-02 01:37:03 -07004122static void processCommandsCallback(int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004123 RecordStream *p_rs;
4124 void *p_record;
4125 size_t recordlen;
4126 int ret;
Etan Cohend3652192014-06-20 08:28:44 -07004127 SocketListenParam *p_info = (SocketListenParam *)param;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004128
Etan Cohend3652192014-06-20 08:28:44 -07004129 assert(fd == p_info->fdCommand);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004130
Etan Cohend3652192014-06-20 08:28:44 -07004131 p_rs = p_info->p_rs;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004132
4133 for (;;) {
4134 /* loop until EAGAIN/EINTR, end of stream, or other error */
4135 ret = record_stream_get_next(p_rs, &p_record, &recordlen);
4136
4137 if (ret == 0 && p_record == NULL) {
4138 /* end-of-stream */
4139 break;
4140 } else if (ret < 0) {
4141 break;
4142 } else if (ret == 0) { /* && p_record != NULL */
Etan Cohend3652192014-06-20 08:28:44 -07004143 processCommandBuffer(p_record, recordlen, p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004144 }
4145 }
4146
4147 if (ret == 0 || !(errno == EAGAIN || errno == EINTR)) {
4148 /* fatal error or end-of-stream */
4149 if (ret != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004150 RLOGE("error on reading command socket errno:%d\n", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004151 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08004152 RLOGW("EOS. Closing command socket.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004153 }
Wink Saville7f856802009-06-09 10:23:37 -07004154
Etan Cohend3652192014-06-20 08:28:44 -07004155 close(fd);
4156 p_info->fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004157
Etan Cohend3652192014-06-20 08:28:44 -07004158 ril_event_del(p_info->commands_event);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004159
4160 record_stream_free(p_rs);
4161
4162 /* start listening for new connections again */
4163 rilEventAddWakeup(&s_listen_event);
4164
Etan Cohend3652192014-06-20 08:28:44 -07004165 onCommandsSocketClosed(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004166 }
4167}
4168
4169
Etan Cohend3652192014-06-20 08:28:44 -07004170static void onNewCommandConnect(RIL_SOCKET_ID socket_id) {
Wink Saville5b9df332011-04-06 16:24:21 -07004171 // Inform we are connected and the ril version
Jake Hambya9c18d12011-04-12 23:32:08 -07004172 int rilVer = s_callbacks.version;
Etan Cohend3652192014-06-20 08:28:44 -07004173 RIL_UNSOL_RESPONSE(RIL_UNSOL_RIL_CONNECTED,
4174 &rilVer, sizeof(rilVer), socket_id);
Wink Saville5b9df332011-04-06 16:24:21 -07004175
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004176 // implicit radio state changed
Etan Cohend3652192014-06-20 08:28:44 -07004177 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
4178 NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004179
4180 // Send last NITZ time data, in case it was missed
4181 if (s_lastNITZTimeData != NULL) {
Etan Cohend3652192014-06-20 08:28:44 -07004182 sendResponseRaw(s_lastNITZTimeData, s_lastNITZTimeDataSize, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004183
4184 free(s_lastNITZTimeData);
4185 s_lastNITZTimeData = NULL;
4186 }
4187
4188 // Get version string
4189 if (s_callbacks.getVersion != NULL) {
4190 const char *version;
4191 version = s_callbacks.getVersion();
Wink Saville8eb2a122012-11-19 16:05:13 -08004192 RLOGI("RIL Daemon version: %s\n", version);
Wink Saville7f856802009-06-09 10:23:37 -07004193
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004194 property_set(PROPERTY_RIL_IMPL, version);
4195 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08004196 RLOGI("RIL Daemon version: unavailable\n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004197 property_set(PROPERTY_RIL_IMPL, "unavailable");
4198 }
4199
4200}
4201
Wink Savillef4c4d362009-04-02 01:37:03 -07004202static void listenCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004203 int ret;
4204 int err;
4205 int is_phone_socket;
Etan Cohend3652192014-06-20 08:28:44 -07004206 int fdCommand = -1;
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004207 char* processName;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004208 RecordStream *p_rs;
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004209 MySocketListenParam* listenParam;
4210 RilSocket *sapSocket = NULL;
4211 socketClient *sClient = NULL;
4212
Etan Cohend3652192014-06-20 08:28:44 -07004213 SocketListenParam *p_info = (SocketListenParam *)param;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004214
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004215 if(RIL_SAP_SOCKET == p_info->type) {
4216 listenParam = (MySocketListenParam *)param;
4217 sapSocket = listenParam->socket;
4218 }
4219
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004220 struct sockaddr_un peeraddr;
4221 socklen_t socklen = sizeof (peeraddr);
4222
4223 struct ucred creds;
4224 socklen_t szCreds = sizeof(creds);
4225
4226 struct passwd *pwd = NULL;
4227
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004228 if(NULL == sapSocket) {
4229 assert (*p_info->fdCommand < 0);
4230 assert (fd == *p_info->fdListen);
4231 processName = PHONE_PROCESS;
4232 } else {
4233 assert (sapSocket->commandFd < 0);
4234 assert (fd == sapSocket->listenFd);
4235 processName = BLUETOOTH_PROCESS;
4236 }
4237
Wink Saville7f856802009-06-09 10:23:37 -07004238
Etan Cohend3652192014-06-20 08:28:44 -07004239 fdCommand = accept(fd, (sockaddr *) &peeraddr, &socklen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004240
Etan Cohend3652192014-06-20 08:28:44 -07004241 if (fdCommand < 0 ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004242 RLOGE("Error on accept() errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004243 /* start listening for new connections again */
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004244 if(NULL == sapSocket) {
4245 rilEventAddWakeup(p_info->listen_event);
4246 } else {
4247 rilEventAddWakeup(sapSocket->getListenEvent());
4248 }
Etan Cohend3652192014-06-20 08:28:44 -07004249 return;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004250 }
4251
4252 /* check the credential of the other side and only accept socket from
4253 * phone process
Wink Saville7f856802009-06-09 10:23:37 -07004254 */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004255 errno = 0;
4256 is_phone_socket = 0;
Wink Savillef4c4d362009-04-02 01:37:03 -07004257
Etan Cohend3652192014-06-20 08:28:44 -07004258 err = getsockopt(fdCommand, SOL_SOCKET, SO_PEERCRED, &creds, &szCreds);
Wink Savillef4c4d362009-04-02 01:37:03 -07004259
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004260 if (err == 0 && szCreds > 0) {
Wink Savillef4c4d362009-04-02 01:37:03 -07004261 errno = 0;
4262 pwd = getpwuid(creds.uid);
4263 if (pwd != NULL) {
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004264 if (strcmp(pwd->pw_name, processName) == 0) {
Wink Savillef4c4d362009-04-02 01:37:03 -07004265 is_phone_socket = 1;
4266 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08004267 RLOGE("RILD can't accept socket from process %s", pwd->pw_name);
Wink Savillef4c4d362009-04-02 01:37:03 -07004268 }
4269 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08004270 RLOGE("Error on getpwuid() errno: %d", errno);
Wink Savillef4c4d362009-04-02 01:37:03 -07004271 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004272 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08004273 RLOGD("Error on getsockopt() errno: %d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004274 }
4275
Etan Cohend3652192014-06-20 08:28:44 -07004276 if (!is_phone_socket) {
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004277 RLOGE("RILD must accept socket from %s", processName);
Wink Saville7f856802009-06-09 10:23:37 -07004278
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004279 close(fdCommand);
4280 fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004281
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004282 if(NULL == sapSocket) {
4283 onCommandsSocketClosed(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004284
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004285 /* start listening for new connections again */
4286 rilEventAddWakeup(p_info->listen_event);
4287 } else {
4288 sapSocket->onCommandsSocketClosed();
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004289
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004290 /* start listening for new connections again */
4291 rilEventAddWakeup(sapSocket->getListenEvent());
4292 }
4293
4294 return;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004295 }
4296
Etan Cohend3652192014-06-20 08:28:44 -07004297 ret = fcntl(fdCommand, F_SETFL, O_NONBLOCK);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004298
4299 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004300 RLOGE ("Error setting O_NONBLOCK errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004301 }
4302
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004303 if(NULL == sapSocket) {
4304 RLOGI("libril: new connection to %s", rilSocketIdToString(p_info->socket_id));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004305
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004306 p_info->fdCommand = fdCommand;
4307 p_rs = record_stream_new(p_info->fdCommand, MAX_COMMAND_BYTES);
4308 p_info->p_rs = p_rs;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004309
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004310 ril_event_set (p_info->commands_event, p_info->fdCommand, 1,
Etan Cohend3652192014-06-20 08:28:44 -07004311 p_info->processCommandsCallback, p_info);
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004312 rilEventAddWakeup (p_info->commands_event);
Etan Cohend3652192014-06-20 08:28:44 -07004313
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004314 onNewCommandConnect(p_info->socket_id);
4315 } else {
4316 RLOGI("libril: new connection");
Etan Cohend3652192014-06-20 08:28:44 -07004317
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004318 sapSocket->setCommandFd(fdCommand);
4319 p_rs = record_stream_new(sapSocket->getCommandFd(), MAX_COMMAND_BYTES);
4320 sClient = new socketClient(sapSocket,p_rs);
4321 ril_event_set (sapSocket->getCallbackEvent(), sapSocket->getCommandFd(), 1,
4322 sapSocket->getCommandCb(), sClient);
4323
4324 rilEventAddWakeup(sapSocket->getCallbackEvent());
4325 sapSocket->onNewCommandConnect();
4326 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004327}
4328
4329static void freeDebugCallbackArgs(int number, char **args) {
4330 for (int i = 0; i < number; i++) {
4331 if (args[i] != NULL) {
4332 free(args[i]);
4333 }
4334 }
4335 free(args);
4336}
4337
Wink Savillef4c4d362009-04-02 01:37:03 -07004338static void debugCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004339 int acceptFD, option;
4340 struct sockaddr_un peeraddr;
4341 socklen_t socklen = sizeof (peeraddr);
4342 int data;
4343 unsigned int qxdm_data[6];
4344 const char *deactData[1] = {"1"};
4345 char *actData[1];
4346 RIL_Dial dialData;
4347 int hangupData[1] = {1};
4348 int number;
4349 char **args;
Etan Cohend3652192014-06-20 08:28:44 -07004350 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
4351 int sim_id = 0;
4352
4353 RLOGI("debugCallback for socket %s", rilSocketIdToString(socket_id));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004354
4355 acceptFD = accept (fd, (sockaddr *) &peeraddr, &socklen);
4356
4357 if (acceptFD < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004358 RLOGE ("error accepting on debug port: %d\n", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004359 return;
4360 }
4361
4362 if (recv(acceptFD, &number, sizeof(int), 0) != sizeof(int)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004363 RLOGE ("error reading on socket: number of Args: \n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004364 return;
4365 }
4366 args = (char **) malloc(sizeof(char*) * number);
4367
4368 for (int i = 0; i < number; i++) {
4369 int len;
4370 if (recv(acceptFD, &len, sizeof(int), 0) != sizeof(int)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004371 RLOGE ("error reading on socket: Len of Args: \n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004372 freeDebugCallbackArgs(i, args);
4373 return;
4374 }
4375 // +1 for null-term
4376 args[i] = (char *) malloc((sizeof(char) * len) + 1);
Wink Saville7f856802009-06-09 10:23:37 -07004377 if (recv(acceptFD, args[i], sizeof(char) * len, 0)
Wink Saville1b5fd232009-04-22 14:50:00 -07004378 != (int)sizeof(char) * len) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004379 RLOGE ("error reading on socket: Args[%d] \n", i);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004380 freeDebugCallbackArgs(i, args);
4381 return;
4382 }
4383 char * buf = args[i];
4384 buf[len] = 0;
Etan Cohend3652192014-06-20 08:28:44 -07004385 if ((i+1) == number) {
4386 /* The last argument should be sim id 0(SIM1)~3(SIM4) */
4387 sim_id = atoi(args[i]);
4388 switch (sim_id) {
4389 case 0:
4390 socket_id = RIL_SOCKET_1;
4391 break;
4392 #if (SIM_COUNT >= 2)
4393 case 1:
4394 socket_id = RIL_SOCKET_2;
4395 break;
4396 #endif
4397 #if (SIM_COUNT >= 3)
4398 case 2:
4399 socket_id = RIL_SOCKET_3;
4400 break;
4401 #endif
4402 #if (SIM_COUNT >= 4)
4403 case 3:
4404 socket_id = RIL_SOCKET_4;
4405 break;
4406 #endif
4407 default:
4408 socket_id = RIL_SOCKET_1;
4409 break;
4410 }
4411 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004412 }
4413
4414 switch (atoi(args[0])) {
4415 case 0:
Wink Saville8eb2a122012-11-19 16:05:13 -08004416 RLOGI ("Connection on debug port: issuing reset.");
Etan Cohend3652192014-06-20 08:28:44 -07004417 issueLocalRequest(RIL_REQUEST_RESET_RADIO, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004418 break;
4419 case 1:
Wink Saville8eb2a122012-11-19 16:05:13 -08004420 RLOGI ("Connection on debug port: issuing radio power off.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004421 data = 0;
Etan Cohend3652192014-06-20 08:28:44 -07004422 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004423 // Close the socket
Etan Cohend3652192014-06-20 08:28:44 -07004424 if (socket_id == RIL_SOCKET_1 && s_ril_param_socket.fdCommand > 0) {
4425 close(s_ril_param_socket.fdCommand);
4426 s_ril_param_socket.fdCommand = -1;
4427 }
4428 #if (SIM_COUNT == 2)
4429 else if (socket_id == RIL_SOCKET_2 && s_ril_param_socket2.fdCommand > 0) {
4430 close(s_ril_param_socket2.fdCommand);
4431 s_ril_param_socket2.fdCommand = -1;
4432 }
4433 #endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004434 break;
4435 case 2:
Wink Saville8eb2a122012-11-19 16:05:13 -08004436 RLOGI ("Debug port: issuing unsolicited voice network change.");
Etan Cohend3652192014-06-20 08:28:44 -07004437 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004438 break;
4439 case 3:
Wink Saville8eb2a122012-11-19 16:05:13 -08004440 RLOGI ("Debug port: QXDM log enable.");
Xia Wangd855ef42010-07-27 17:26:55 -07004441 qxdm_data[0] = 65536; // head.func_tag
4442 qxdm_data[1] = 16; // head.len
4443 qxdm_data[2] = 1; // mode: 1 for 'start logging'
4444 qxdm_data[3] = 32; // log_file_size: 32megabytes
4445 qxdm_data[4] = 0; // log_mask
4446 qxdm_data[5] = 8; // log_max_fileindex
Wink Saville7f856802009-06-09 10:23:37 -07004447 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Etan Cohend3652192014-06-20 08:28:44 -07004448 6 * sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004449 break;
4450 case 4:
Wink Saville8eb2a122012-11-19 16:05:13 -08004451 RLOGI ("Debug port: QXDM log disable.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004452 qxdm_data[0] = 65536;
4453 qxdm_data[1] = 16;
Xia Wangd855ef42010-07-27 17:26:55 -07004454 qxdm_data[2] = 0; // mode: 0 for 'stop logging'
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004455 qxdm_data[3] = 32;
4456 qxdm_data[4] = 0;
Xia Wangd855ef42010-07-27 17:26:55 -07004457 qxdm_data[5] = 8;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004458 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Etan Cohend3652192014-06-20 08:28:44 -07004459 6 * sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004460 break;
4461 case 5:
Wink Saville8eb2a122012-11-19 16:05:13 -08004462 RLOGI("Debug port: Radio On");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004463 data = 1;
Etan Cohend3652192014-06-20 08:28:44 -07004464 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004465 sleep(2);
4466 // Set network selection automatic.
Etan Cohend3652192014-06-20 08:28:44 -07004467 issueLocalRequest(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004468 break;
4469 case 6:
Wink Saville8eb2a122012-11-19 16:05:13 -08004470 RLOGI("Debug port: Setup Data Call, Apn :%s\n", args[1]);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004471 actData[0] = args[1];
Wink Saville7f856802009-06-09 10:23:37 -07004472 issueLocalRequest(RIL_REQUEST_SETUP_DATA_CALL, &actData,
Etan Cohend3652192014-06-20 08:28:44 -07004473 sizeof(actData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004474 break;
4475 case 7:
Wink Saville8eb2a122012-11-19 16:05:13 -08004476 RLOGI("Debug port: Deactivate Data Call");
Wink Saville7f856802009-06-09 10:23:37 -07004477 issueLocalRequest(RIL_REQUEST_DEACTIVATE_DATA_CALL, &deactData,
Etan Cohend3652192014-06-20 08:28:44 -07004478 sizeof(deactData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004479 break;
4480 case 8:
Wink Saville8eb2a122012-11-19 16:05:13 -08004481 RLOGI("Debug port: Dial Call");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004482 dialData.clir = 0;
4483 dialData.address = args[1];
Etan Cohend3652192014-06-20 08:28:44 -07004484 issueLocalRequest(RIL_REQUEST_DIAL, &dialData, sizeof(dialData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004485 break;
4486 case 9:
Wink Saville8eb2a122012-11-19 16:05:13 -08004487 RLOGI("Debug port: Answer Call");
Etan Cohend3652192014-06-20 08:28:44 -07004488 issueLocalRequest(RIL_REQUEST_ANSWER, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004489 break;
4490 case 10:
Wink Saville8eb2a122012-11-19 16:05:13 -08004491 RLOGI("Debug port: End Call");
Wink Saville7f856802009-06-09 10:23:37 -07004492 issueLocalRequest(RIL_REQUEST_HANGUP, &hangupData,
Etan Cohend3652192014-06-20 08:28:44 -07004493 sizeof(hangupData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004494 break;
4495 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004496 RLOGE ("Invalid request");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004497 break;
4498 }
4499 freeDebugCallbackArgs(number, args);
4500 close(acceptFD);
4501}
4502
4503
Wink Savillef4c4d362009-04-02 01:37:03 -07004504static void userTimerCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004505 UserCallbackInfo *p_info;
4506
4507 p_info = (UserCallbackInfo *)param;
4508
4509 p_info->p_callback(p_info->userParam);
4510
4511
4512 // FIXME generalize this...there should be a cancel mechanism
4513 if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) {
4514 s_last_wake_timeout_info = NULL;
4515 }
4516
4517 free(p_info);
4518}
4519
4520
4521static void *
Wink Savillef4c4d362009-04-02 01:37:03 -07004522eventLoop(void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004523 int ret;
4524 int filedes[2];
4525
4526 ril_event_init();
4527
4528 pthread_mutex_lock(&s_startupMutex);
4529
4530 s_started = 1;
4531 pthread_cond_broadcast(&s_startupCond);
4532
4533 pthread_mutex_unlock(&s_startupMutex);
4534
4535 ret = pipe(filedes);
4536
4537 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004538 RLOGE("Error in pipe() errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004539 return NULL;
4540 }
4541
4542 s_fdWakeupRead = filedes[0];
4543 s_fdWakeupWrite = filedes[1];
4544
4545 fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK);
4546
4547 ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,
4548 processWakeupCallback, NULL);
4549
4550 rilEventAddWakeup (&s_wakeupfd_event);
4551
4552 // Only returns on error
4553 ril_event_loop();
Wink Saville8eb2a122012-11-19 16:05:13 -08004554 RLOGE ("error in event_loop_base errno:%d", errno);
Kazuhiro Ondo5cdc1352011-10-14 17:50:58 -05004555 // kill self to restart on error
4556 kill(0, SIGKILL);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004557
4558 return NULL;
4559}
4560
Wink Saville7f856802009-06-09 10:23:37 -07004561extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07004562RIL_startEventLoop(void) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004563 /* spin up eventLoop thread and wait for it to get started */
4564 s_started = 0;
4565 pthread_mutex_lock(&s_startupMutex);
4566
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004567 pthread_attr_t attr;
4568 pthread_attr_init(&attr);
Wink Saville7f856802009-06-09 10:23:37 -07004569 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004570
Elliott Hughesfd81e712014-01-06 12:46:02 -08004571 int result = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
4572 if (result != 0) {
4573 RLOGE("Failed to create dispatch thread: %s", strerror(result));
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004574 goto done;
4575 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004576
4577 while (s_started == 0) {
4578 pthread_cond_wait(&s_startupCond, &s_startupMutex);
4579 }
4580
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004581done:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004582 pthread_mutex_unlock(&s_startupMutex);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004583}
4584
4585// Used for testing purpose only.
4586extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) {
4587 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4588}
4589
Etan Cohend3652192014-06-20 08:28:44 -07004590static void startListen(RIL_SOCKET_ID socket_id, SocketListenParam* socket_listen_p) {
4591 int fdListen = -1;
4592 int ret;
4593 char socket_name[10];
4594
4595 memset(socket_name, 0, sizeof(char)*10);
4596
4597 switch(socket_id) {
4598 case RIL_SOCKET_1:
4599 strncpy(socket_name, RIL_getRilSocketName(), 9);
4600 break;
4601 #if (SIM_COUNT >= 2)
4602 case RIL_SOCKET_2:
4603 strncpy(socket_name, SOCKET2_NAME_RIL, 9);
4604 break;
4605 #endif
4606 #if (SIM_COUNT >= 3)
4607 case RIL_SOCKET_3:
4608 strncpy(socket_name, SOCKET3_NAME_RIL, 9);
4609 break;
4610 #endif
4611 #if (SIM_COUNT >= 4)
4612 case RIL_SOCKET_4:
4613 strncpy(socket_name, SOCKET4_NAME_RIL, 9);
4614 break;
4615 #endif
4616 default:
4617 RLOGE("Socket id is wrong!!");
4618 return;
4619 }
4620
4621 RLOGI("Start to listen %s", rilSocketIdToString(socket_id));
4622
4623 fdListen = android_get_control_socket(socket_name);
4624 if (fdListen < 0) {
4625 RLOGE("Failed to get socket %s", socket_name);
4626 exit(-1);
4627 }
4628
4629 ret = listen(fdListen, 4);
4630
4631 if (ret < 0) {
4632 RLOGE("Failed to listen on control socket '%d': %s",
4633 fdListen, strerror(errno));
4634 exit(-1);
4635 }
4636 socket_listen_p->fdListen = fdListen;
4637
4638 /* note: non-persistent so we can accept only one connection at a time */
4639 ril_event_set (socket_listen_p->listen_event, fdListen, false,
4640 listenCallback, socket_listen_p);
4641
4642 rilEventAddWakeup (socket_listen_p->listen_event);
4643}
4644
Wink Saville7f856802009-06-09 10:23:37 -07004645extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07004646RIL_register (const RIL_RadioFunctions *callbacks) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004647 int ret;
4648 int flags;
4649
Etan Cohend3652192014-06-20 08:28:44 -07004650 RLOGI("SIM_COUNT: %d", SIM_COUNT);
4651
Wink Saville43808972011-01-13 17:39:51 -08004652 if (callbacks == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004653 RLOGE("RIL_register: RIL_RadioFunctions * null");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004654 return;
4655 }
Wink Saville43808972011-01-13 17:39:51 -08004656 if (callbacks->version < RIL_VERSION_MIN) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004657 RLOGE("RIL_register: version %d is to old, min version is %d",
Wink Saville43808972011-01-13 17:39:51 -08004658 callbacks->version, RIL_VERSION_MIN);
4659 return;
Wink Saville3a4840b2010-04-07 13:29:58 -07004660 }
Sanket Padawe88cf6a52016-01-11 12:45:43 -08004661
Wink Saville8eb2a122012-11-19 16:05:13 -08004662 RLOGE("RIL_register: RIL version %d", callbacks->version);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004663
4664 if (s_registerCalled > 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004665 RLOGE("RIL_register has been called more than once. "
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004666 "Subsequent call ignored");
4667 return;
4668 }
4669
4670 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4671
Etan Cohend3652192014-06-20 08:28:44 -07004672 /* Initialize socket1 parameters */
4673 s_ril_param_socket = {
4674 RIL_SOCKET_1, /* socket_id */
4675 -1, /* fdListen */
4676 -1, /* fdCommand */
4677 PHONE_PROCESS, /* processName */
4678 &s_commands_event, /* commands_event */
4679 &s_listen_event, /* listen_event */
4680 processCommandsCallback, /* processCommandsCallback */
4681 NULL /* p_rs */
4682 };
4683
4684#if (SIM_COUNT >= 2)
4685 s_ril_param_socket2 = {
4686 RIL_SOCKET_2, /* socket_id */
4687 -1, /* fdListen */
4688 -1, /* fdCommand */
4689 PHONE_PROCESS, /* processName */
4690 &s_commands_event_socket2, /* commands_event */
4691 &s_listen_event_socket2, /* listen_event */
4692 processCommandsCallback, /* processCommandsCallback */
4693 NULL /* p_rs */
4694 };
4695#endif
4696
4697#if (SIM_COUNT >= 3)
4698 s_ril_param_socket3 = {
4699 RIL_SOCKET_3, /* socket_id */
4700 -1, /* fdListen */
4701 -1, /* fdCommand */
4702 PHONE_PROCESS, /* processName */
4703 &s_commands_event_socket3, /* commands_event */
4704 &s_listen_event_socket3, /* listen_event */
4705 processCommandsCallback, /* processCommandsCallback */
4706 NULL /* p_rs */
4707 };
4708#endif
4709
4710#if (SIM_COUNT >= 4)
4711 s_ril_param_socket4 = {
4712 RIL_SOCKET_4, /* socket_id */
4713 -1, /* fdListen */
4714 -1, /* fdCommand */
4715 PHONE_PROCESS, /* processName */
4716 &s_commands_event_socket4, /* commands_event */
4717 &s_listen_event_socket4, /* listen_event */
4718 processCommandsCallback, /* processCommandsCallback */
4719 NULL /* p_rs */
4720 };
4721#endif
4722
4723
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004724 s_registerCalled = 1;
4725
Etan Cohend3652192014-06-20 08:28:44 -07004726 RLOGI("s_registerCalled flag set, %d", s_started);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004727 // Little self-check
4728
Wink Savillef4c4d362009-04-02 01:37:03 -07004729 for (int i = 0; i < (int)NUM_ELEMS(s_commands); i++) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004730 assert(i == s_commands[i].requestNumber);
4731 }
4732
Wink Savillef4c4d362009-04-02 01:37:03 -07004733 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses); i++) {
Wink Saville7f856802009-06-09 10:23:37 -07004734 assert(i + RIL_UNSOL_RESPONSE_BASE
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004735 == s_unsolResponses[i].requestNumber);
4736 }
4737
4738 // New rild impl calls RIL_startEventLoop() first
4739 // old standalone impl wants it here.
4740
4741 if (s_started == 0) {
4742 RIL_startEventLoop();
4743 }
4744
Etan Cohend3652192014-06-20 08:28:44 -07004745 // start listen socket1
4746 startListen(RIL_SOCKET_1, &s_ril_param_socket);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004747
Etan Cohend3652192014-06-20 08:28:44 -07004748#if (SIM_COUNT >= 2)
4749 // start listen socket2
4750 startListen(RIL_SOCKET_2, &s_ril_param_socket2);
4751#endif /* (SIM_COUNT == 2) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004752
Etan Cohend3652192014-06-20 08:28:44 -07004753#if (SIM_COUNT >= 3)
4754 // start listen socket3
4755 startListen(RIL_SOCKET_3, &s_ril_param_socket3);
4756#endif /* (SIM_COUNT == 3) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004757
Etan Cohend3652192014-06-20 08:28:44 -07004758#if (SIM_COUNT >= 4)
4759 // start listen socket4
4760 startListen(RIL_SOCKET_4, &s_ril_param_socket4);
4761#endif /* (SIM_COUNT == 4) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004762
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004763
4764#if 1
4765 // start debug interface socket
4766
Etan Cohend3652192014-06-20 08:28:44 -07004767 char *inst = NULL;
4768 if (strlen(RIL_getRilSocketName()) >= strlen(SOCKET_NAME_RIL)) {
4769 inst = RIL_getRilSocketName() + strlen(SOCKET_NAME_RIL);
4770 }
4771
4772 char rildebug[MAX_DEBUG_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL_DEBUG;
4773 if (inst != NULL) {
Nick Kralevichc52e45e2015-02-08 07:54:16 -08004774 strlcat(rildebug, inst, MAX_DEBUG_SOCKET_NAME_LENGTH);
Etan Cohend3652192014-06-20 08:28:44 -07004775 }
4776
4777 s_fdDebug = android_get_control_socket(rildebug);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004778 if (s_fdDebug < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07004779 RLOGE("Failed to get socket : %s errno:%d", rildebug, errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004780 exit(-1);
4781 }
4782
4783 ret = listen(s_fdDebug, 4);
4784
4785 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004786 RLOGE("Failed to listen on ril debug socket '%d': %s",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004787 s_fdDebug, strerror(errno));
4788 exit(-1);
4789 }
4790
4791 ril_event_set (&s_debug_event, s_fdDebug, true,
4792 debugCallback, NULL);
4793
4794 rilEventAddWakeup (&s_debug_event);
4795#endif
4796
4797}
4798
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004799extern "C" void
4800RIL_register_socket (RIL_RadioFunctions *(*Init)(const struct RIL_Env *, int, char **),RIL_SOCKET_TYPE socketType, int argc, char **argv) {
4801
4802 RIL_RadioFunctions* UimFuncs = NULL;
4803
4804 if(Init) {
4805 UimFuncs = Init(&RilSapSocket::uimRilEnv, argc, argv);
4806
4807 switch(socketType) {
4808 case RIL_SAP_SOCKET:
4809 RilSapSocket::initSapSocket("sap_uim_socket1", UimFuncs);
4810
4811#if (SIM_COUNT >= 2)
4812 RilSapSocket::initSapSocket("sap_uim_socket2", UimFuncs);
4813#endif
4814
4815#if (SIM_COUNT >= 3)
4816 RilSapSocket::initSapSocket("sap_uim_socket3", UimFuncs);
4817#endif
4818
4819#if (SIM_COUNT >= 4)
4820 RilSapSocket::initSapSocket("sap_uim_socket4", UimFuncs);
4821#endif
4822 }
4823 }
4824}
4825
Sanket Padawe6ff9a872016-01-27 15:09:12 -08004826// Check and remove RequestInfo if its a response and not just ack sent back
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004827static int
Sanket Padawe6ff9a872016-01-27 15:09:12 -08004828checkAndDequeueRequestInfoIfAck(struct RequestInfo *pRI, bool isAck) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004829 int ret = 0;
Etan Cohend3652192014-06-20 08:28:44 -07004830 /* Hook for current context
4831 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
4832 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
4833 /* pendingRequestsHook refer to &s_pendingRequests */
4834 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
Wink Saville7f856802009-06-09 10:23:37 -07004835
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004836 if (pRI == NULL) {
4837 return 0;
4838 }
4839
Etan Cohend3652192014-06-20 08:28:44 -07004840#if (SIM_COUNT >= 2)
4841 if (pRI->socket_id == RIL_SOCKET_2) {
4842 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
4843 pendingRequestsHook = &s_pendingRequests_socket2;
4844 }
4845#if (SIM_COUNT >= 3)
4846 if (pRI->socket_id == RIL_SOCKET_3) {
4847 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
4848 pendingRequestsHook = &s_pendingRequests_socket3;
4849 }
4850#endif
4851#if (SIM_COUNT >= 4)
4852 if (pRI->socket_id == RIL_SOCKET_4) {
4853 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
4854 pendingRequestsHook = &s_pendingRequests_socket4;
4855 }
4856#endif
4857#endif
4858 pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004859
Etan Cohend3652192014-06-20 08:28:44 -07004860 for(RequestInfo **ppCur = pendingRequestsHook
Wink Saville7f856802009-06-09 10:23:37 -07004861 ; *ppCur != NULL
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004862 ; ppCur = &((*ppCur)->p_next)
4863 ) {
4864 if (pRI == *ppCur) {
4865 ret = 1;
Sanket Padawe6ff9a872016-01-27 15:09:12 -08004866 if (isAck) { // Async ack
4867 if (pRI->wasAckSent == 1) {
4868 RLOGD("Ack was already sent for %s", requestToString(pRI->pCI->requestNumber));
4869 } else {
4870 pRI->wasAckSent = 1;
4871 }
4872 } else {
4873 *ppCur = (*ppCur)->p_next;
4874 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004875 break;
4876 }
4877 }
4878
Etan Cohend3652192014-06-20 08:28:44 -07004879 pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004880
4881 return ret;
4882}
4883
Sanket Padawe6ff9a872016-01-27 15:09:12 -08004884static int findFd(int socket_id) {
Etan Cohend3652192014-06-20 08:28:44 -07004885 int fd = s_ril_param_socket.fdCommand;
Etan Cohend3652192014-06-20 08:28:44 -07004886#if (SIM_COUNT >= 2)
4887 if (socket_id == RIL_SOCKET_2) {
4888 fd = s_ril_param_socket2.fdCommand;
4889 }
4890#if (SIM_COUNT >= 3)
Sanket Padawe6ff9a872016-01-27 15:09:12 -08004891 if (socket_id == RIL_SOCKET_3) {
4892 fd = s_ril_param_socket3.fdCommand;
4893 }
Etan Cohend3652192014-06-20 08:28:44 -07004894#endif
4895#if (SIM_COUNT >= 4)
4896 if (socket_id == RIL_SOCKET_4) {
4897 fd = s_ril_param_socket4.fdCommand;
4898 }
4899#endif
4900#endif
Sanket Padawe6ff9a872016-01-27 15:09:12 -08004901 return fd;
4902}
4903
4904extern "C" void
4905RIL_onRequestAck(RIL_Token t) {
4906 RequestInfo *pRI;
4907 int ret, fd;
4908
4909 size_t errorOffset;
4910 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
4911
4912 pRI = (RequestInfo *)t;
4913
4914 if (!checkAndDequeueRequestInfoIfAck(pRI, true)) {
4915 RLOGE ("RIL_onRequestAck: invalid RIL_Token");
4916 return;
4917 }
4918
4919 socket_id = pRI->socket_id;
4920 fd = findFd(socket_id);
4921
4922#if VDBG
4923 RLOGD("Request Ack, %s", rilSocketIdToString(socket_id));
4924#endif
4925
4926 appendPrintBuf("Ack [%04d]< %s", pRI->token, requestToString(pRI->pCI->requestNumber));
4927
4928 if (pRI->cancelled == 0) {
4929 Parcel p;
4930
4931 p.writeInt32 (RESPONSE_SOLICITED_ACK);
4932 p.writeInt32 (pRI->token);
4933
4934 if (fd < 0) {
4935 RLOGD ("RIL onRequestComplete: Command channel closed");
4936 }
4937
4938 sendResponse(p, socket_id);
4939 }
4940}
4941
4942extern "C" void
4943RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) {
4944 RequestInfo *pRI;
4945 int ret;
4946 int fd;
4947 size_t errorOffset;
4948 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
4949
4950 pRI = (RequestInfo *)t;
4951
4952 if (!checkAndDequeueRequestInfoIfAck(pRI, false)) {
4953 RLOGE ("RIL_onRequestComplete: invalid RIL_Token");
4954 return;
4955 }
4956
4957 socket_id = pRI->socket_id;
4958 fd = findFd(socket_id);
4959
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07004960#if VDBG
Etan Cohend3652192014-06-20 08:28:44 -07004961 RLOGD("RequestComplete, %s", rilSocketIdToString(socket_id));
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07004962#endif
Etan Cohend3652192014-06-20 08:28:44 -07004963
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004964 if (pRI->local > 0) {
4965 // Locally issued command...void only!
4966 // response does not go back up the command socket
Wink Saville8eb2a122012-11-19 16:05:13 -08004967 RLOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004968
4969 goto done;
4970 }
4971
4972 appendPrintBuf("[%04d]< %s",
4973 pRI->token, requestToString(pRI->pCI->requestNumber));
4974
4975 if (pRI->cancelled == 0) {
4976 Parcel p;
4977
Sanket Padawe6ff9a872016-01-27 15:09:12 -08004978 if (s_callbacks.version >= 13 && pRI->wasAckSent == 1) {
4979 // If ack was already sent, then this call is an asynchronous response. So we need to
4980 // send id indicating that we expect an ack from RIL.java as we acquire wakelock here.
4981 p.writeInt32 (RESPONSE_SOLICITED_ACK_EXP);
4982 grabPartialWakeLock();
4983 } else {
4984 p.writeInt32 (RESPONSE_SOLICITED);
4985 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004986 p.writeInt32 (pRI->token);
4987 errorOffset = p.dataPosition();
4988
4989 p.writeInt32 (e);
4990
johnwangb2a61842009-06-02 14:55:45 -07004991 if (response != NULL) {
4992 // there is a response payload, no matter success or not.
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004993 ret = pRI->pCI->responseFunction(p, response, responselen);
4994
4995 /* if an error occurred, rewind and mark it */
4996 if (ret != 0) {
Etan Cohend3652192014-06-20 08:28:44 -07004997 RLOGE ("responseFunction error, ret %d", ret);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004998 p.setDataPosition(errorOffset);
4999 p.writeInt32 (ret);
5000 }
johnwangb2a61842009-06-02 14:55:45 -07005001 }
5002
5003 if (e != RIL_E_SUCCESS) {
5004 appendPrintBuf("%s fails by %s", printBuf, failCauseToString(e));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005005 }
5006
Etan Cohend3652192014-06-20 08:28:44 -07005007 if (fd < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08005008 RLOGD ("RIL onRequestComplete: Command channel closed");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005009 }
Etan Cohend3652192014-06-20 08:28:44 -07005010 sendResponse(p, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005011 }
5012
5013done:
5014 free(pRI);
5015}
5016
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005017static void
Wink Savillef4c4d362009-04-02 01:37:03 -07005018grabPartialWakeLock() {
Sanket Padawe6ff9a872016-01-27 15:09:12 -08005019 if (s_callbacks.version >= 13) {
5020 int ret;
5021 ret = pthread_mutex_lock(&s_wakeLockCountMutex);
5022 assert(ret == 0);
5023 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
5024 s_wakelock_count++;
5025 if (s_last_wake_timeout_info != NULL) {
5026 s_last_wake_timeout_info->userParam = (void *)1;
5027 }
5028
5029 s_last_wake_timeout_info
5030 = internalRequestTimedCallback(wakeTimeoutCallback, NULL, &TIMEVAL_WAKE_TIMEOUT);
5031
5032 ret = pthread_mutex_unlock(&s_wakeLockCountMutex);
5033 assert(ret == 0);
5034 } else {
5035 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
5036 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005037}
5038
5039static void
Wink Savillef4c4d362009-04-02 01:37:03 -07005040releaseWakeLock() {
Sanket Padawe6ff9a872016-01-27 15:09:12 -08005041 if (s_callbacks.version >= 13) {
5042 int ret;
5043 ret = pthread_mutex_lock(&s_wakeLockCountMutex);
5044 assert(ret == 0);
5045
5046 if (s_wakelock_count > 1) {
5047 s_wakelock_count--;
5048 } else {
5049 s_wakelock_count = 0;
5050 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
5051 if (s_last_wake_timeout_info != NULL) {
5052 s_last_wake_timeout_info->userParam = (void *)1;
5053 }
5054 }
5055
5056 ret = pthread_mutex_unlock(&s_wakeLockCountMutex);
5057 assert(ret == 0);
5058 } else {
5059 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
5060 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005061}
5062
5063/**
5064 * Timer callback to put us back to sleep before the default timeout
5065 */
5066static void
Wink Savillef4c4d362009-04-02 01:37:03 -07005067wakeTimeoutCallback (void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005068 // We're using "param != NULL" as a cancellation mechanism
Sanket Padawe6ff9a872016-01-27 15:09:12 -08005069 if (s_callbacks.version >= 13) {
5070 if (param == NULL) {
5071 int ret;
5072 ret = pthread_mutex_lock(&s_wakeLockCountMutex);
5073 assert(ret == 0);
5074 s_wakelock_count = 0;
5075 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
5076 ret = pthread_mutex_unlock(&s_wakeLockCountMutex);
5077 assert(ret == 0);
5078 }
5079 } else {
5080 if (param == NULL) {
5081 releaseWakeLock();
5082 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005083 }
5084}
5085
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005086static int
5087decodeVoiceRadioTechnology (RIL_RadioState radioState) {
5088 switch (radioState) {
5089 case RADIO_STATE_SIM_NOT_READY:
5090 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
5091 case RADIO_STATE_SIM_READY:
5092 return RADIO_TECH_UMTS;
5093
5094 case RADIO_STATE_RUIM_NOT_READY:
5095 case RADIO_STATE_RUIM_READY:
5096 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
5097 case RADIO_STATE_NV_NOT_READY:
5098 case RADIO_STATE_NV_READY:
5099 return RADIO_TECH_1xRTT;
5100
5101 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08005102 RLOGD("decodeVoiceRadioTechnology: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005103 return -1;
5104 }
5105}
5106
5107static int
5108decodeCdmaSubscriptionSource (RIL_RadioState radioState) {
5109 switch (radioState) {
5110 case RADIO_STATE_SIM_NOT_READY:
5111 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
5112 case RADIO_STATE_SIM_READY:
5113 case RADIO_STATE_RUIM_NOT_READY:
5114 case RADIO_STATE_RUIM_READY:
5115 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
5116 return CDMA_SUBSCRIPTION_SOURCE_RUIM_SIM;
5117
5118 case RADIO_STATE_NV_NOT_READY:
5119 case RADIO_STATE_NV_READY:
5120 return CDMA_SUBSCRIPTION_SOURCE_NV;
5121
5122 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08005123 RLOGD("decodeCdmaSubscriptionSource: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005124 return -1;
5125 }
5126}
5127
5128static int
5129decodeSimStatus (RIL_RadioState radioState) {
5130 switch (radioState) {
5131 case RADIO_STATE_SIM_NOT_READY:
5132 case RADIO_STATE_RUIM_NOT_READY:
5133 case RADIO_STATE_NV_NOT_READY:
5134 case RADIO_STATE_NV_READY:
5135 return -1;
5136 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
5137 case RADIO_STATE_SIM_READY:
5138 case RADIO_STATE_RUIM_READY:
5139 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
5140 return radioState;
5141 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08005142 RLOGD("decodeSimStatus: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005143 return -1;
5144 }
5145}
5146
5147static bool is3gpp2(int radioTech) {
5148 switch (radioTech) {
5149 case RADIO_TECH_IS95A:
5150 case RADIO_TECH_IS95B:
5151 case RADIO_TECH_1xRTT:
5152 case RADIO_TECH_EVDO_0:
5153 case RADIO_TECH_EVDO_A:
5154 case RADIO_TECH_EVDO_B:
5155 case RADIO_TECH_EHRPD:
5156 return true;
5157 default:
5158 return false;
5159 }
5160}
5161
5162/* If RIL sends SIM states or RUIM states, store the voice radio
5163 * technology and subscription source information so that they can be
5164 * returned when telephony framework requests them
5165 */
5166static RIL_RadioState
Etan Cohend3652192014-06-20 08:28:44 -07005167processRadioState(RIL_RadioState newRadioState, RIL_SOCKET_ID socket_id) {
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005168
5169 if((newRadioState > RADIO_STATE_UNAVAILABLE) && (newRadioState < RADIO_STATE_ON)) {
5170 int newVoiceRadioTech;
5171 int newCdmaSubscriptionSource;
5172 int newSimStatus;
5173
5174 /* This is old RIL. Decode Subscription source and Voice Radio Technology
5175 from Radio State and send change notifications if there has been a change */
5176 newVoiceRadioTech = decodeVoiceRadioTechnology(newRadioState);
5177 if(newVoiceRadioTech != voiceRadioTech) {
5178 voiceRadioTech = newVoiceRadioTech;
Etan Cohend3652192014-06-20 08:28:44 -07005179 RIL_UNSOL_RESPONSE(RIL_UNSOL_VOICE_RADIO_TECH_CHANGED,
5180 &voiceRadioTech, sizeof(voiceRadioTech), socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005181 }
5182 if(is3gpp2(newVoiceRadioTech)) {
5183 newCdmaSubscriptionSource = decodeCdmaSubscriptionSource(newRadioState);
5184 if(newCdmaSubscriptionSource != cdmaSubscriptionSource) {
5185 cdmaSubscriptionSource = newCdmaSubscriptionSource;
Etan Cohend3652192014-06-20 08:28:44 -07005186 RIL_UNSOL_RESPONSE(RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED,
5187 &cdmaSubscriptionSource, sizeof(cdmaSubscriptionSource), socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005188 }
5189 }
5190 newSimStatus = decodeSimStatus(newRadioState);
5191 if(newSimStatus != simRuimStatus) {
5192 simRuimStatus = newSimStatus;
Etan Cohend3652192014-06-20 08:28:44 -07005193 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0, socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005194 }
5195
5196 /* Send RADIO_ON to telephony */
5197 newRadioState = RADIO_STATE_ON;
5198 }
5199
5200 return newRadioState;
5201}
5202
Etan Cohend3652192014-06-20 08:28:44 -07005203
5204#if defined(ANDROID_MULTI_SIM)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005205extern "C"
Bernhard Rosenkränzerd613b962014-11-17 20:52:09 +01005206void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Etan Cohend3652192014-06-20 08:28:44 -07005207 size_t datalen, RIL_SOCKET_ID socket_id)
5208#else
5209extern "C"
Bernhard Rosenkränzerd613b962014-11-17 20:52:09 +01005210void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005211 size_t datalen)
Etan Cohend3652192014-06-20 08:28:44 -07005212#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005213{
5214 int unsolResponseIndex;
5215 int ret;
5216 int64_t timeReceived = 0;
5217 bool shouldScheduleTimeout = false;
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005218 RIL_RadioState newState;
Etan Cohend3652192014-06-20 08:28:44 -07005219 RIL_SOCKET_ID soc_id = RIL_SOCKET_1;
5220
5221#if defined(ANDROID_MULTI_SIM)
5222 soc_id = socket_id;
5223#endif
5224
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005225
5226 if (s_registerCalled == 0) {
5227 // Ignore RIL_onUnsolicitedResponse before RIL_register
Wink Saville8eb2a122012-11-19 16:05:13 -08005228 RLOGW("RIL_onUnsolicitedResponse called before RIL_register");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005229 return;
5230 }
Wink Saville7f856802009-06-09 10:23:37 -07005231
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005232 unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
5233
5234 if ((unsolResponseIndex < 0)
5235 || (unsolResponseIndex >= (int32_t)NUM_ELEMS(s_unsolResponses))) {
Wink Saville8eb2a122012-11-19 16:05:13 -08005236 RLOGE("unsupported unsolicited response code %d", unsolResponse);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005237 return;
5238 }
5239
5240 // Grab a wake lock if needed for this reponse,
5241 // as we exit we'll either release it immediately
5242 // or set a timer to release it later.
5243 switch (s_unsolResponses[unsolResponseIndex].wakeType) {
5244 case WAKE_PARTIAL:
5245 grabPartialWakeLock();
5246 shouldScheduleTimeout = true;
5247 break;
5248
5249 case DONT_WAKE:
5250 default:
5251 // No wake lock is grabed so don't set timeout
5252 shouldScheduleTimeout = false;
5253 break;
5254 }
5255
5256 // Mark the time this was received, doing this
5257 // after grabing the wakelock incase getting
5258 // the elapsedRealTime might cause us to goto
5259 // sleep.
5260 if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
5261 timeReceived = elapsedRealtime();
5262 }
5263
5264 appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
5265
5266 Parcel p;
Sanket Padawed8c0b462016-02-03 11:46:02 -08005267 if (s_callbacks.version >= 13
5268 && s_unsolResponses[unsolResponseIndex].wakeType == WAKE_PARTIAL) {
5269 p.writeInt32 (RESPONSE_UNSOLICITED_ACK_EXP);
5270 } else {
5271 p.writeInt32 (RESPONSE_UNSOLICITED);
5272 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005273 p.writeInt32 (unsolResponse);
5274
5275 ret = s_unsolResponses[unsolResponseIndex]
Bernhard Rosenkränzer6e7c1962013-12-12 10:01:10 +01005276 .responseFunction(p, const_cast<void*>(data), datalen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005277 if (ret != 0) {
5278 // Problem with the response. Don't continue;
5279 goto error_exit;
5280 }
5281
5282 // some things get more payload
5283 switch(unsolResponse) {
5284 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
Etan Cohend3652192014-06-20 08:28:44 -07005285 newState = processRadioState(CALL_ONSTATEREQUEST(soc_id), soc_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005286 p.writeInt32(newState);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005287 appendPrintBuf("%s {%s}", printBuf,
Etan Cohend3652192014-06-20 08:28:44 -07005288 radioStateToString(CALL_ONSTATEREQUEST(soc_id)));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005289 break;
5290
5291
5292 case RIL_UNSOL_NITZ_TIME_RECEIVED:
5293 // Store the time that this was received so the
5294 // handler of this message can account for
5295 // the time it takes to arrive and process. In
5296 // particular the system has been known to sleep
5297 // before this message can be processed.
5298 p.writeInt64(timeReceived);
5299 break;
5300 }
5301
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07005302#if VDBG
Etan Cohend3652192014-06-20 08:28:44 -07005303 RLOGI("%s UNSOLICITED: %s length:%d", rilSocketIdToString(soc_id), requestToString(unsolResponse), p.dataSize());
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07005304#endif
Etan Cohend3652192014-06-20 08:28:44 -07005305 ret = sendResponse(p, soc_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005306 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
5307
5308 // Unfortunately, NITZ time is not poll/update like everything
5309 // else in the system. So, if the upstream client isn't connected,
5310 // keep a copy of the last NITZ response (with receive time noted
5311 // above) around so we can deliver it when it is connected
5312
5313 if (s_lastNITZTimeData != NULL) {
5314 free (s_lastNITZTimeData);
5315 s_lastNITZTimeData = NULL;
5316 }
5317
5318 s_lastNITZTimeData = malloc(p.dataSize());
5319 s_lastNITZTimeDataSize = p.dataSize();
5320 memcpy(s_lastNITZTimeData, p.data(), p.dataSize());
5321 }
5322
Sanket Padawe6ff9a872016-01-27 15:09:12 -08005323 if (s_callbacks.version < 13) {
5324 if (shouldScheduleTimeout) {
5325 // Cancel the previous request
5326 if (s_last_wake_timeout_info != NULL) {
5327 s_last_wake_timeout_info->userParam = (void *)1;
5328 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005329
Sanket Padawe6ff9a872016-01-27 15:09:12 -08005330 s_last_wake_timeout_info
5331 = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
5332 &TIMEVAL_WAKE_TIMEOUT);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005333 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005334 }
5335
5336 // Normal exit
5337 return;
5338
5339error_exit:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005340 if (shouldScheduleTimeout) {
5341 releaseWakeLock();
5342 }
5343}
5344
Wink Saville7f856802009-06-09 10:23:37 -07005345/** FIXME generalize this if you track UserCAllbackInfo, clear it
5346 when the callback occurs
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005347*/
5348static UserCallbackInfo *
Wink Saville7f856802009-06-09 10:23:37 -07005349internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07005350 const struct timeval *relativeTime)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005351{
5352 struct timeval myRelativeTime;
5353 UserCallbackInfo *p_info;
5354
5355 p_info = (UserCallbackInfo *) malloc (sizeof(UserCallbackInfo));
5356
Wink Saville7f856802009-06-09 10:23:37 -07005357 p_info->p_callback = callback;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005358 p_info->userParam = param;
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07005359
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005360 if (relativeTime == NULL) {
5361 /* treat null parameter as a 0 relative time */
5362 memset (&myRelativeTime, 0, sizeof(myRelativeTime));
5363 } else {
5364 /* FIXME I think event_add's tv param is really const anyway */
5365 memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
5366 }
5367
5368 ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
5369
5370 ril_timer_add(&(p_info->event), &myRelativeTime);
5371
5372 triggerEvLoop();
5373 return p_info;
5374}
5375
Naveen Kalla7edd07c2010-06-21 18:54:47 -07005376
5377extern "C" void
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07005378RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
5379 const struct timeval *relativeTime) {
5380 internalRequestTimedCallback (callback, param, relativeTime);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005381}
5382
5383const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07005384failCauseToString(RIL_Errno e) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005385 switch(e) {
5386 case RIL_E_SUCCESS: return "E_SUCCESS";
Robert Greenwalt2126ab22013-04-09 12:20:45 -07005387 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RADIO_NOT_AVAILABLE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005388 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
5389 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
5390 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
5391 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
5392 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
5393 case RIL_E_CANCELLED: return "E_CANCELLED";
5394 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
5395 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
5396 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
Wink Savillef4c4d362009-04-02 01:37:03 -07005397 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
John Wang75534472010-04-20 15:11:42 -07005398 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
Wink Saville7f856802009-06-09 10:23:37 -07005399#ifdef FEATURE_MULTIMODE_ANDROID
Wink Savillef4c4d362009-04-02 01:37:03 -07005400 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
5401 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
5402#endif
Sanket Padaweb39e5c92016-02-08 14:28:59 -08005403 case RIL_E_FDN_CHECK_FAILURE: return "E_FDN_CHECK_FAILURE";
5404 case RIL_E_MISSING_RESOURCE: return "E_MISSING_RESOURCE";
5405 case RIL_E_NO_SUCH_ELEMENT: return "E_NO_SUCH_ELEMENT";
5406 case RIL_E_DIAL_MODIFIED_TO_USSD: return "E_DIAL_MODIFIED_TO_USSD";
5407 case RIL_E_DIAL_MODIFIED_TO_SS: return "E_DIAL_MODIFIED_TO_SS";
5408 case RIL_E_DIAL_MODIFIED_TO_DIAL: return "E_DIAL_MODIFIED_TO_DIAL";
5409 case RIL_E_USSD_MODIFIED_TO_DIAL: return "E_USSD_MODIFIED_TO_DIAL";
5410 case RIL_E_USSD_MODIFIED_TO_SS: return "E_USSD_MODIFIED_TO_SS";
5411 case RIL_E_USSD_MODIFIED_TO_USSD: return "E_USSD_MODIFIED_TO_USSD";
5412 case RIL_E_SS_MODIFIED_TO_DIAL: return "E_SS_MODIFIED_TO_DIAL";
5413 case RIL_E_SS_MODIFIED_TO_USSD: return "E_SS_MODIFIED_TO_USSD";
5414 case RIL_E_SUBSCRIPTION_NOT_SUPPORTED: return "E_SUBSCRIPTION_NOT_SUPPORTED";
5415 case RIL_E_SS_MODIFIED_TO_SS: return "E_SS_MODIFIED_TO_SS";
5416 case RIL_E_LCE_NOT_SUPPORTED: return "E_LCE_NOT_SUPPORTED";
5417 case RIL_E_NO_MEMORY: return "E_NO_MEMORY";
5418 case RIL_E_INTERNAL_ERR: return "E_INTERNAL_ERR";
5419 case RIL_E_SYSTEM_ERR: return "E_SYSTEM_ERR";
5420 case RIL_E_MODEM_ERR: return "E_MODEM_ERR";
5421 case RIL_E_INVALID_STATE: return "E_INVALID_STATE";
5422 case RIL_E_NO_RESOURCES: return "E_NO_RESOURCES";
5423 case RIL_E_SIM_ERR: return "E_SIM_ERR";
5424 case RIL_E_INVALID_ARGUMENTS: return "E_INVALID_ARGUMENTS";
5425 case RIL_E_INVALID_SIM_STATE: return "E_INVALID_SIM_STATE";
5426 case RIL_E_INVALID_MODEM_STATE: return "E_INVALID_MODEM_STATE";
5427 case RIL_E_INVALID_CALL_ID: return "E_INVALID_CALL_ID";
5428 case RIL_E_NO_SMS_TO_ACK: return "E_NO_SMS_TO_ACK";
5429 case RIL_E_NETWORK_ERR: return "E_NETWORK_ERR";
5430 case RIL_E_REQUEST_RATE_LIMITED: return "E_REQUEST_RATE_LIMITED";
twen.changdf7add02016-03-04 18:27:48 +08005431 case RIL_E_SIM_BUSY: return "E_SIM_BUSY";
5432 case RIL_E_SIM_FULL: return "E_SIM_FULL";
5433 case RIL_E_NETWORK_REJECT: return "E_NETWORK_REJECT";
5434 case RIL_E_OPERATION_NOT_ALLOWED: return "E_OPERATION_NOT_ALLOWED";
5435 case RIL_E_EMPTY_RECORD: "E_EMPTY_RECORD";
Sanket Padawe0106aed2016-02-09 09:56:31 -08005436 case RIL_E_OEM_ERROR_1: return "E_OEM_ERROR_1";
5437 case RIL_E_OEM_ERROR_2: return "E_OEM_ERROR_2";
5438 case RIL_E_OEM_ERROR_3: return "E_OEM_ERROR_3";
5439 case RIL_E_OEM_ERROR_4: return "E_OEM_ERROR_4";
5440 case RIL_E_OEM_ERROR_5: return "E_OEM_ERROR_5";
5441 case RIL_E_OEM_ERROR_6: return "E_OEM_ERROR_6";
5442 case RIL_E_OEM_ERROR_7: return "E_OEM_ERROR_7";
5443 case RIL_E_OEM_ERROR_8: return "E_OEM_ERROR_8";
5444 case RIL_E_OEM_ERROR_9: return "E_OEM_ERROR_9";
5445 case RIL_E_OEM_ERROR_10: return "E_OEM_ERROR_10";
5446 case RIL_E_OEM_ERROR_11: return "E_OEM_ERROR_11";
5447 case RIL_E_OEM_ERROR_12: return "E_OEM_ERROR_12";
5448 case RIL_E_OEM_ERROR_13: return "E_OEM_ERROR_13";
5449 case RIL_E_OEM_ERROR_14: return "E_OEM_ERROR_14";
5450 case RIL_E_OEM_ERROR_15: return "E_OEM_ERROR_15";
5451 case RIL_E_OEM_ERROR_16: return "E_OEM_ERROR_16";
5452 case RIL_E_OEM_ERROR_17: return "E_OEM_ERROR_17";
5453 case RIL_E_OEM_ERROR_18: return "E_OEM_ERROR_18";
5454 case RIL_E_OEM_ERROR_19: return "E_OEM_ERROR_19";
5455 case RIL_E_OEM_ERROR_20: return "E_OEM_ERROR_20";
5456 case RIL_E_OEM_ERROR_21: return "E_OEM_ERROR_21";
5457 case RIL_E_OEM_ERROR_22: return "E_OEM_ERROR_22";
5458 case RIL_E_OEM_ERROR_23: return "E_OEM_ERROR_23";
5459 case RIL_E_OEM_ERROR_24: return "E_OEM_ERROR_24";
5460 case RIL_E_OEM_ERROR_25: return "E_OEM_ERROR_25";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005461 default: return "<unknown error>";
5462 }
5463}
5464
5465const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07005466radioStateToString(RIL_RadioState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005467 switch(s) {
5468 case RADIO_STATE_OFF: return "RADIO_OFF";
5469 case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
5470 case RADIO_STATE_SIM_NOT_READY: return "RADIO_SIM_NOT_READY";
5471 case RADIO_STATE_SIM_LOCKED_OR_ABSENT: return "RADIO_SIM_LOCKED_OR_ABSENT";
5472 case RADIO_STATE_SIM_READY: return "RADIO_SIM_READY";
Wink Savillef4c4d362009-04-02 01:37:03 -07005473 case RADIO_STATE_RUIM_NOT_READY:return"RADIO_RUIM_NOT_READY";
5474 case RADIO_STATE_RUIM_READY:return"RADIO_RUIM_READY";
5475 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:return"RADIO_RUIM_LOCKED_OR_ABSENT";
5476 case RADIO_STATE_NV_NOT_READY:return"RADIO_NV_NOT_READY";
5477 case RADIO_STATE_NV_READY:return"RADIO_NV_READY";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005478 case RADIO_STATE_ON:return"RADIO_ON";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005479 default: return "<unknown state>";
5480 }
5481}
5482
5483const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07005484callStateToString(RIL_CallState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005485 switch(s) {
5486 case RIL_CALL_ACTIVE : return "ACTIVE";
5487 case RIL_CALL_HOLDING: return "HOLDING";
5488 case RIL_CALL_DIALING: return "DIALING";
5489 case RIL_CALL_ALERTING: return "ALERTING";
5490 case RIL_CALL_INCOMING: return "INCOMING";
5491 case RIL_CALL_WAITING: return "WAITING";
5492 default: return "<unknown state>";
5493 }
5494}
5495
5496const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07005497requestToString(int request) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005498/*
5499 cat libs/telephony/ril_commands.h \
5500 | egrep "^ *{RIL_" \
5501 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
5502
5503
5504 cat libs/telephony/ril_unsol_commands.h \
5505 | egrep "^ *{RIL_" \
5506 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
5507
5508*/
5509 switch(request) {
5510 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
5511 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
5512 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
5513 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
5514 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
5515 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
5516 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
5517 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
5518 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
5519 case RIL_REQUEST_DIAL: return "DIAL";
5520 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
5521 case RIL_REQUEST_HANGUP: return "HANGUP";
5522 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
5523 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
5524 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
5525 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
5526 case RIL_REQUEST_UDUB: return "UDUB";
5527 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
5528 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
Wink Savillec0114b32011-02-18 10:14:07 -08005529 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
5530 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005531 case RIL_REQUEST_OPERATOR: return "OPERATOR";
5532 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
5533 case RIL_REQUEST_DTMF: return "DTMF";
5534 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
5535 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
Wink Savillef4c4d362009-04-02 01:37:03 -07005536 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005537 case RIL_REQUEST_SIM_IO: return "SIM_IO";
5538 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
5539 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
5540 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
5541 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
5542 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
5543 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
5544 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
5545 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
5546 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
5547 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
5548 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
5549 case RIL_REQUEST_ANSWER: return "ANSWER";
Wink Savillef4c4d362009-04-02 01:37:03 -07005550 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005551 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
5552 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
5553 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
5554 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
5555 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
5556 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
5557 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";
5558 case RIL_REQUEST_DTMF_START: return "DTMF_START";
5559 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
5560 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
5561 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
5562 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
5563 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
5564 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
5565 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
5566 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
5567 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
Wink Savillef4c4d362009-04-02 01:37:03 -07005568 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
5569 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005570 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
5571 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
5572 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
Wink Savillef4c4d362009-04-02 01:37:03 -07005573 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
5574 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005575 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
5576 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
5577 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
5578 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
5579 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
5580 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
5581 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
5582 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
Wink Savillec0114b32011-02-18 10:14:07 -08005583 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE:return"CDMA_SET_SUBSCRIPTION_SOURCE";
Wink Savillef4c4d362009-04-02 01:37:03 -07005584 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"CDMA_SET_ROAMING_PREFERENCE";
5585 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"CDMA_QUERY_ROAMING_PREFERENCE";
5586 case RIL_REQUEST_SET_TTY_MODE:return"SET_TTY_MODE";
5587 case RIL_REQUEST_QUERY_TTY_MODE:return"QUERY_TTY_MODE";
5588 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
5589 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
5590 case RIL_REQUEST_CDMA_FLASH:return"CDMA_FLASH";
5591 case RIL_REQUEST_CDMA_BURST_DTMF:return"CDMA_BURST_DTMF";
5592 case RIL_REQUEST_CDMA_SEND_SMS:return"CDMA_SEND_SMS";
5593 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:return"CDMA_SMS_ACKNOWLEDGE";
Wink Savillea592eeb2009-05-22 13:26:36 -07005594 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG:return"GSM_GET_BROADCAST_SMS_CONFIG";
5595 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG:return"GSM_SET_BROADCAST_SMS_CONFIG";
5596 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG:return "CDMA_GET_BROADCAST_SMS_CONFIG";
5597 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG:return "CDMA_SET_BROADCAST_SMS_CONFIG";
5598 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION:return "CDMA_SMS_BROADCAST_ACTIVATION";
Naveen Kalla03c1edf2009-09-23 11:18:35 -07005599 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return"CDMA_VALIDATE_AND_WRITE_AKEY";
Wink Savillef4c4d362009-04-02 01:37:03 -07005600 case RIL_REQUEST_CDMA_SUBSCRIPTION: return"CDMA_SUBSCRIPTION";
5601 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
5602 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
5603 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
jsh000a9fe2009-05-11 14:52:35 -07005604 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
5605 case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
5606 case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
jsh09a68ba2009-06-10 11:56:38 -07005607 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
jsh563fd722010-06-08 16:52:24 -07005608 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
Wink Savillec0114b32011-02-18 10:14:07 -08005609 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
Jake Hambyfa8d5842011-08-19 16:22:18 -07005610 case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
Jake Hamby300105d2011-09-26 01:01:44 -07005611 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
5612 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005613 case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
Ajay Nambic27945d2011-11-15 11:19:30 -08005614 case RIL_REQUEST_WRITE_SMS_TO_SIM: return "WRITE_SMS_TO_SIM";
Wink Saville8a9e0212013-04-09 12:11:38 -07005615 case RIL_REQUEST_GET_CELL_INFO_LIST: return"GET_CELL_INFO_LIST";
5616 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return"SET_UNSOL_CELL_INFO_LIST_RATE";
Sungmin Choi75697532013-04-26 15:04:45 -07005617 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "RIL_REQUEST_SET_INITIAL_ATTACH_APN";
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07005618 case RIL_REQUEST_IMS_REGISTRATION_STATE: return "IMS_REGISTRATION_STATE";
5619 case RIL_REQUEST_IMS_SEND_SMS: return "IMS_SEND_SMS";
Shishir Agrawal2458d8d2013-11-27 14:53:05 -08005620 case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "SIM_TRANSMIT_APDU_BASIC";
5621 case RIL_REQUEST_SIM_OPEN_CHANNEL: return "SIM_OPEN_CHANNEL";
5622 case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "SIM_CLOSE_CHANNEL";
5623 case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "SIM_TRANSMIT_APDU_CHANNEL";
Wink Saville8b4e4f72014-10-17 15:01:45 -07005624 case RIL_REQUEST_GET_RADIO_CAPABILITY: return "RIL_REQUEST_GET_RADIO_CAPABILITY";
5625 case RIL_REQUEST_SET_RADIO_CAPABILITY: return "RIL_REQUEST_SET_RADIO_CAPABILITY";
Etan Cohend3652192014-06-20 08:28:44 -07005626 case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "SET_UICC_SUBSCRIPTION";
5627 case RIL_REQUEST_ALLOW_DATA: return "ALLOW_DATA";
Amit Mahajan2b772032014-06-26 14:20:11 -07005628 case RIL_REQUEST_GET_HARDWARE_CONFIG: return "GET_HARDWARE_CONFIG";
5629 case RIL_REQUEST_SIM_AUTHENTICATION: return "SIM_AUTHENTICATION";
Wink Savillec29360a2014-07-13 05:17:28 -07005630 case RIL_REQUEST_GET_DC_RT_INFO: return "GET_DC_RT_INFO";
5631 case RIL_REQUEST_SET_DC_RT_INFO_RATE: return "SET_DC_RT_INFO_RATE";
Amit Mahajanc796e222014-08-13 16:54:01 +00005632 case RIL_REQUEST_SET_DATA_PROFILE: return "SET_DATA_PROFILE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005633 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
5634 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08005635 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 -08005636 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
5637 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
5638 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
5639 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
5640 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)";
5641 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
5642 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
Ajay Nambic27945d2011-11-15 11:19:30 -08005643 case RIL_UNSOL_SUPP_SVC_NOTIFICATION: return "UNSOL_SUPP_SVC_NOTIFICATION";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005644 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
5645 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
5646 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
5647 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
5648 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL";
5649 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
Wink Savillef4c4d362009-04-02 01:37:03 -07005650 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005651 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
Wink Savillef4c4d362009-04-02 01:37:03 -07005652 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
5653 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_NEW_CDMA_SMS";
5654 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_NEW_BROADCAST_SMS";
5655 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
Wink Saville3d54e742009-05-18 18:00:44 -07005656 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
5657 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
5658 case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
5659 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
5660 case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
Jaikumar Ganeshaf6ecbf2009-04-29 13:27:51 -07005661 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
John Wang5d621da2009-09-18 17:17:48 -07005662 case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
John Wang5909cf82010-01-29 00:18:54 -08005663 case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
Wink Savilleee274582011-04-16 15:05:49 -07005664 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08005665 case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
5666 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
Wink Saville5b9df332011-04-06 16:24:21 -07005667 case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005668 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
Wink Saville8a9e0212013-04-09 12:11:38 -07005669 case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07005670 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "RESPONSE_IMS_NETWORK_STATE_CHANGED";
Etan Cohend3652192014-06-20 08:28:44 -07005671 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return "UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED";
5672 case RIL_UNSOL_SRVCC_STATE_NOTIFY: return "UNSOL_SRVCC_STATE_NOTIFY";
5673 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return "HARDWARE_CONFIG_CHANGED";
Wink Savillec29360a2014-07-13 05:17:28 -07005674 case RIL_UNSOL_DC_RT_INFO_CHANGED: return "UNSOL_DC_RT_INFO_CHANGED";
Naveen Kallaa65a16a2014-07-31 16:48:31 -07005675 case RIL_REQUEST_SHUTDOWN: return "SHUTDOWN";
Wink Saville8b4e4f72014-10-17 15:01:45 -07005676 case RIL_UNSOL_RADIO_CAPABILITY: return "RIL_UNSOL_RADIO_CAPABILITY";
Sanket Padawe6ff9a872016-01-27 15:09:12 -08005677 case RIL_RESPONSE_ACKNOWLEDGEMENT: return "RIL_RESPONSE_ACKNOWLEDGEMENT";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005678 default: return "<unknown request>";
5679 }
5680}
5681
Etan Cohend3652192014-06-20 08:28:44 -07005682const char *
5683rilSocketIdToString(RIL_SOCKET_ID socket_id)
5684{
5685 switch(socket_id) {
5686 case RIL_SOCKET_1:
5687 return "RIL_SOCKET_1";
5688#if (SIM_COUNT >= 2)
5689 case RIL_SOCKET_2:
5690 return "RIL_SOCKET_2";
5691#endif
5692#if (SIM_COUNT >= 3)
5693 case RIL_SOCKET_3:
5694 return "RIL_SOCKET_3";
5695#endif
5696#if (SIM_COUNT >= 4)
5697 case RIL_SOCKET_4:
5698 return "RIL_SOCKET_4";
5699#endif
5700 default:
5701 return "not a valid RIL";
5702 }
5703}
5704
Sanket Padawe88cf6a52016-01-11 12:45:43 -08005705/*
5706 * Returns true for a debuggable build.
5707 */
5708static bool isDebuggable() {
5709 char debuggable[PROP_VALUE_MAX];
5710 property_get("ro.debuggable", debuggable, "0");
5711 if (strcmp(debuggable, "1") == 0) {
5712 return true;
5713 }
5714 return false;
5715}
5716
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005717} /* namespace android */
Dheeraj Shetty27976c42014-07-02 21:27:57 +02005718
5719void rilEventAddWakeup_helper(struct ril_event *ev) {
5720 android::rilEventAddWakeup(ev);
5721}
5722
5723void listenCallback_helper(int fd, short flags, void *param) {
5724 android::listenCallback(fd, flags, param);
5725}
5726
5727int blockingWrite_helper(int fd, void *buffer, size_t len) {
5728 return android::blockingWrite(fd, buffer, len);
5729}