blob: f2631944d083644524586aeff9d34026421e4a42 [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>
21
22#include <telephony/ril.h>
Wink Savillef4c4d362009-04-02 01:37:03 -070023#include <telephony/ril_cdma_sms.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080024#include <cutils/sockets.h>
25#include <cutils/jstring.h>
Dima Zavin622bf2b2013-05-22 11:29:34 -070026#include <telephony/record_stream.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080027#include <utils/Log.h>
28#include <utils/SystemClock.h>
29#include <pthread.h>
Mathias Agopian8a3c48c2009-05-19 19:11:50 -070030#include <binder/Parcel.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080031#include <cutils/jstring.h>
32
33#include <sys/types.h>
Wink Saville18e4ab12013-04-07 17:31:04 -070034#include <sys/limits.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080035#include <pwd.h>
36
37#include <stdio.h>
38#include <stdlib.h>
39#include <stdarg.h>
40#include <string.h>
41#include <unistd.h>
42#include <fcntl.h>
43#include <time.h>
44#include <errno.h>
45#include <assert.h>
46#include <ctype.h>
47#include <alloca.h>
48#include <sys/un.h>
49#include <assert.h>
50#include <netinet/in.h>
51#include <cutils/properties.h>
52
53#include <ril_event.h>
54
55namespace android {
56
57#define PHONE_PROCESS "radio"
58
59#define SOCKET_NAME_RIL "rild"
Etan Cohend3652192014-06-20 08:28:44 -070060#define SOCKET2_NAME_RIL "rild2"
61#define SOCKET3_NAME_RIL "rild3"
62#define SOCKET4_NAME_RIL "rild4"
63
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080064#define SOCKET_NAME_RIL_DEBUG "rild-debug"
65
66#define ANDROID_WAKE_LOCK_NAME "radio-interface"
67
68
69#define PROPERTY_RIL_IMPL "gsm.version.ril-impl"
70
71// match with constant in RIL.java
72#define MAX_COMMAND_BYTES (8 * 1024)
73
74// Basically: memset buffers that the client library
75// shouldn't be using anymore in an attempt to find
76// memory usage issues sooner.
77#define MEMSET_FREED 1
78
79#define NUM_ELEMS(a) (sizeof (a) / sizeof (a)[0])
80
Wink Savillef4c4d362009-04-02 01:37:03 -070081#define MIN(a,b) ((a)<(b) ? (a) : (b))
82
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080083/* Constants for response types */
84#define RESPONSE_SOLICITED 0
85#define RESPONSE_UNSOLICITED 1
86
87/* Negative values for private RIL errno's */
88#define RIL_ERRNO_INVALID_RESPONSE -1
89
90// request, response, and unsolicited msg print macro
91#define PRINTBUF_SIZE 8096
92
93// Enable RILC log
94#define RILC_LOG 0
95
96#if RILC_LOG
97 #define startRequest sprintf(printBuf, "(")
98 #define closeRequest sprintf(printBuf, "%s)", printBuf)
99 #define printRequest(token, req) \
Wink Saville8eb2a122012-11-19 16:05:13 -0800100 RLOGD("[%04d]> %s %s", token, requestToString(req), printBuf)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800101
102 #define startResponse sprintf(printBuf, "%s {", printBuf)
103 #define closeResponse sprintf(printBuf, "%s}", printBuf)
Wink Saville8eb2a122012-11-19 16:05:13 -0800104 #define printResponse RLOGD("%s", printBuf)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800105
106 #define clearPrintBuf printBuf[0] = 0
107 #define removeLastChar printBuf[strlen(printBuf)-1] = 0
108 #define appendPrintBuf(x...) sprintf(printBuf, x)
109#else
110 #define startRequest
111 #define closeRequest
112 #define printRequest(token, req)
113 #define startResponse
114 #define closeResponse
115 #define printResponse
116 #define clearPrintBuf
117 #define removeLastChar
118 #define appendPrintBuf(x...)
119#endif
120
121enum WakeType {DONT_WAKE, WAKE_PARTIAL};
122
123typedef struct {
124 int requestNumber;
125 void (*dispatchFunction) (Parcel &p, struct RequestInfo *pRI);
126 int(*responseFunction) (Parcel &p, void *response, size_t responselen);
127} CommandInfo;
128
129typedef struct {
130 int requestNumber;
131 int (*responseFunction) (Parcel &p, void *response, size_t responselen);
132 WakeType wakeType;
133} UnsolResponseInfo;
134
135typedef struct RequestInfo {
Wink Saville7f856802009-06-09 10:23:37 -0700136 int32_t token; //this is not RIL_Token
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800137 CommandInfo *pCI;
138 struct RequestInfo *p_next;
139 char cancelled;
140 char local; // responses to local commands do not go back to command process
Etan Cohend3652192014-06-20 08:28:44 -0700141 RIL_SOCKET_ID socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800142} RequestInfo;
143
Wink Saville3d54e742009-05-18 18:00:44 -0700144typedef struct UserCallbackInfo {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800145 RIL_TimedCallback p_callback;
146 void *userParam;
147 struct ril_event event;
148 struct UserCallbackInfo *p_next;
149} UserCallbackInfo;
150
Etan Cohend3652192014-06-20 08:28:44 -0700151typedef struct SocketListenParam {
152 RIL_SOCKET_ID socket_id;
153 int fdListen;
154 int fdCommand;
155 char* processName;
156 struct ril_event* commands_event;
157 struct ril_event* listen_event;
158 void (*processCommandsCallback)(int fd, short flags, void *param);
159 RecordStream *p_rs;
160} SocketListenParam;
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -0700161
Etan Cohend3652192014-06-20 08:28:44 -0700162extern "C" const char * requestToString(int request);
163extern "C" const char * failCauseToString(RIL_Errno);
164extern "C" const char * callStateToString(RIL_CallState);
165extern "C" const char * radioStateToString(RIL_RadioState);
166extern "C" const char * rilSocketIdToString(RIL_SOCKET_ID socket_id);
167
168extern "C"
169char rild[MAX_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800170/*******************************************************************/
171
172RIL_RadioFunctions s_callbacks = {0, NULL, NULL, NULL, NULL, NULL};
173static int s_registerCalled = 0;
174
175static pthread_t s_tid_dispatch;
176static pthread_t s_tid_reader;
177static int s_started = 0;
178
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800179static int s_fdDebug = -1;
Etan Cohend3652192014-06-20 08:28:44 -0700180static int s_fdDebug_socket2 = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800181
182static int s_fdWakeupRead;
183static int s_fdWakeupWrite;
184
185static struct ril_event s_commands_event;
186static struct ril_event s_wakeupfd_event;
187static struct ril_event s_listen_event;
Etan Cohend3652192014-06-20 08:28:44 -0700188static SocketListenParam s_ril_param_socket;
189
190static pthread_mutex_t s_pendingRequestsMutex = PTHREAD_MUTEX_INITIALIZER;
191static pthread_mutex_t s_writeMutex = PTHREAD_MUTEX_INITIALIZER;
192static RequestInfo *s_pendingRequests = NULL;
193
194#if (SIM_COUNT >= 2)
195static struct ril_event s_commands_event_socket2;
196static struct ril_event s_listen_event_socket2;
197static SocketListenParam s_ril_param_socket2;
198
199static pthread_mutex_t s_pendingRequestsMutex_socket2 = PTHREAD_MUTEX_INITIALIZER;
200static pthread_mutex_t s_writeMutex_socket2 = PTHREAD_MUTEX_INITIALIZER;
201static RequestInfo *s_pendingRequests_socket2 = NULL;
202#endif
203
204#if (SIM_COUNT >= 3)
205static struct ril_event s_commands_event_socket3;
206static struct ril_event s_listen_event_socket3;
207static SocketListenParam s_ril_param_socket3;
208
209static pthread_mutex_t s_pendingRequestsMutex_socket3 = PTHREAD_MUTEX_INITIALIZER;
210static pthread_mutex_t s_writeMutex_socket3 = PTHREAD_MUTEX_INITIALIZER;
211static RequestInfo *s_pendingRequests_socket3 = NULL;
212#endif
213
214#if (SIM_COUNT >= 4)
215static struct ril_event s_commands_event_socket4;
216static struct ril_event s_listen_event_socket4;
217static SocketListenParam s_ril_param_socket4;
218
219static pthread_mutex_t s_pendingRequestsMutex_socket4 = PTHREAD_MUTEX_INITIALIZER;
220static pthread_mutex_t s_writeMutex_socket4 = PTHREAD_MUTEX_INITIALIZER;
221static RequestInfo *s_pendingRequests_socket4 = NULL;
222#endif
223
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800224static struct ril_event s_wake_timeout_event;
225static struct ril_event s_debug_event;
226
227
228static const struct timeval TIMEVAL_WAKE_TIMEOUT = {1,0};
229
Etan Cohend3652192014-06-20 08:28:44 -0700230
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800231static pthread_mutex_t s_startupMutex = PTHREAD_MUTEX_INITIALIZER;
232static pthread_cond_t s_startupCond = PTHREAD_COND_INITIALIZER;
233
234static pthread_mutex_t s_dispatchMutex = PTHREAD_MUTEX_INITIALIZER;
235static pthread_cond_t s_dispatchCond = PTHREAD_COND_INITIALIZER;
236
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800237static RequestInfo *s_toDispatchHead = NULL;
238static RequestInfo *s_toDispatchTail = NULL;
239
240static UserCallbackInfo *s_last_wake_timeout_info = NULL;
241
242static void *s_lastNITZTimeData = NULL;
243static size_t s_lastNITZTimeDataSize;
244
245#if RILC_LOG
246 static char printBuf[PRINTBUF_SIZE];
247#endif
248
249/*******************************************************************/
Etan Cohend3652192014-06-20 08:28:44 -0700250static int sendResponse (Parcel &p, RIL_SOCKET_ID socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800251
252static void dispatchVoid (Parcel& p, RequestInfo *pRI);
253static void dispatchString (Parcel& p, RequestInfo *pRI);
254static void dispatchStrings (Parcel& p, RequestInfo *pRI);
255static void dispatchInts (Parcel& p, RequestInfo *pRI);
256static void dispatchDial (Parcel& p, RequestInfo *pRI);
257static void dispatchSIM_IO (Parcel& p, RequestInfo *pRI);
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800258static void dispatchSIM_APDU (Parcel& p, RequestInfo *pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800259static void dispatchCallForward(Parcel& p, RequestInfo *pRI);
260static void dispatchRaw(Parcel& p, RequestInfo *pRI);
261static void dispatchSmsWrite (Parcel &p, RequestInfo *pRI);
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -0700262static void dispatchDataCall (Parcel& p, RequestInfo *pRI);
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800263static void dispatchVoiceRadioTech (Parcel& p, RequestInfo *pRI);
Sungmin Choi75697532013-04-26 15:04:45 -0700264static void dispatchSetInitialAttachApn (Parcel& p, RequestInfo *pRI);
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800265static void dispatchCdmaSubscriptionSource (Parcel& p, RequestInfo *pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800266
Wink Savillef4c4d362009-04-02 01:37:03 -0700267static void dispatchCdmaSms(Parcel &p, RequestInfo *pRI);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -0700268static void dispatchImsSms(Parcel &p, RequestInfo *pRI);
269static void dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
270static void dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
Wink Savillef4c4d362009-04-02 01:37:03 -0700271static void dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI);
Wink Savillea592eeb2009-05-22 13:26:36 -0700272static void dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI);
Wink Savillef4c4d362009-04-02 01:37:03 -0700273static void dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI);
274static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI);
Jake Hamby8a4a2332014-01-15 13:12:05 -0800275static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI);
276static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI);
Etan Cohend3652192014-06-20 08:28:44 -0700277static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI);
Amit Mahajan90530a62014-07-01 15:54:08 -0700278static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI);
Amit Mahajanc796e222014-08-13 16:54:01 +0000279static void dispatchDataProfile(Parcel &p, RequestInfo *pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800280static int responseInts(Parcel &p, void *response, size_t responselen);
281static int responseStrings(Parcel &p, void *response, size_t responselen);
282static int responseString(Parcel &p, void *response, size_t responselen);
283static int responseVoid(Parcel &p, void *response, size_t responselen);
284static int responseCallList(Parcel &p, void *response, size_t responselen);
285static int responseSMS(Parcel &p, void *response, size_t responselen);
286static int responseSIM_IO(Parcel &p, void *response, size_t responselen);
287static int responseCallForwards(Parcel &p, void *response, size_t responselen);
Wink Savillef4c4d362009-04-02 01:37:03 -0700288static int responseDataCallList(Parcel &p, void *response, size_t responselen);
Wink Saville43808972011-01-13 17:39:51 -0800289static int responseSetupDataCall(Parcel &p, void *response, size_t responselen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800290static int responseRaw(Parcel &p, void *response, size_t responselen);
291static int responseSsn(Parcel &p, void *response, size_t responselen);
Wink Savillef4c4d362009-04-02 01:37:03 -0700292static int responseSimStatus(Parcel &p, void *response, size_t responselen);
Wink Savillea592eeb2009-05-22 13:26:36 -0700293static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen);
294static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen);
Wink Savillef4c4d362009-04-02 01:37:03 -0700295static int responseCdmaSms(Parcel &p, void *response, size_t responselen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800296static int responseCellList(Parcel &p, void *response, size_t responselen);
Wink Saville3d54e742009-05-18 18:00:44 -0700297static int responseCdmaInformationRecords(Parcel &p,void *response, size_t responselen);
298static int responseRilSignalStrength(Parcel &p,void *response, size_t responselen);
299static int responseCallRing(Parcel &p, void *response, size_t responselen);
300static int responseCdmaSignalInfoRecord(Parcel &p,void *response, size_t responselen);
301static int responseCdmaCallWaiting(Parcel &p,void *response, size_t responselen);
Alex Yakavenka45e740e2012-01-31 11:48:27 -0800302static int responseSimRefresh(Parcel &p, void *response, size_t responselen);
Wink Saville8a9e0212013-04-09 12:11:38 -0700303static int responseCellInfoList(Parcel &p, void *response, size_t responselen);
Etan Cohend3652192014-06-20 08:28:44 -0700304static int responseHardwareConfig(Parcel &p, void *response, size_t responselen);
Naveen Kalla0ec0bc72011-11-15 12:52:06 -0800305static int responseSSData(Parcel &p, void *response, size_t responselen);
Wink Savillec29360a2014-07-13 05:17:28 -0700306static int responseDcRtInfo(Parcel &p, void *response, size_t responselen);
Naveen Kalla41c1c0b2011-11-15 12:48:22 -0800307static int responseGetDataCallProfile(Parcel &p, void *response, size_t responselen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800308
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800309static int decodeVoiceRadioTechnology (RIL_RadioState radioState);
310static int decodeCdmaSubscriptionSource (RIL_RadioState radioState);
311static RIL_RadioState processRadioState(RIL_RadioState newRadioState);
312
Naveen Kalla0ec0bc72011-11-15 12:52:06 -0800313static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType);
314
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800315#ifdef RIL_SHLIB
Etan Cohend3652192014-06-20 08:28:44 -0700316#if defined(ANDROID_MULTI_SIM)
317extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
318 size_t datalen, RIL_SOCKET_ID socket_id);
319#else
Wink Saville7f856802009-06-09 10:23:37 -0700320extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800321 size_t datalen);
322#endif
Etan Cohend3652192014-06-20 08:28:44 -0700323#endif
324
325#if defined(ANDROID_MULTI_SIM)
326#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c), (d))
327#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d), (e))
328#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest(a)
329#else
330#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c))
331#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d))
332#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest()
333#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800334
Wink Saville7f856802009-06-09 10:23:37 -0700335static UserCallbackInfo * internalRequestTimedCallback
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -0700336 (RIL_TimedCallback callback, void *param,
337 const struct timeval *relativeTime);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800338
339/** Index == requestNumber */
340static CommandInfo s_commands[] = {
341#include "ril_commands.h"
342};
343
344static UnsolResponseInfo s_unsolResponses[] = {
345#include "ril_unsol_commands.h"
346};
347
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800348/* For older RILs that do not support new commands RIL_REQUEST_VOICE_RADIO_TECH and
349 RIL_UNSOL_VOICE_RADIO_TECH_CHANGED messages, decode the voice radio tech from
350 radio state message and store it. Every time there is a change in Radio State
351 check to see if voice radio tech changes and notify telephony
352 */
353int voiceRadioTech = -1;
354
355/* For older RILs that do not support new commands RIL_REQUEST_GET_CDMA_SUBSCRIPTION_SOURCE
356 and RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED messages, decode the subscription
357 source from radio state and store it. Every time there is a change in Radio State
358 check to see if subscription source changed and notify telephony
359 */
360int cdmaSubscriptionSource = -1;
361
362/* For older RILs that do not send RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, decode the
363 SIM/RUIM state from radio state and store it. Every time there is a change in Radio State,
364 check to see if SIM/RUIM status changed and notify telephony
365 */
366int simRuimStatus = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800367
Etan Cohend3652192014-06-20 08:28:44 -0700368static char * RIL_getRilSocketName() {
369 return rild;
370}
371
372extern "C"
373void RIL_setRilSocketName(char * s) {
374 strncpy(rild, s, MAX_SOCKET_NAME_LENGTH);
375}
376
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800377static char *
Wink Savillef4c4d362009-04-02 01:37:03 -0700378strdupReadString(Parcel &p) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800379 size_t stringlen;
380 const char16_t *s16;
Wink Saville7f856802009-06-09 10:23:37 -0700381
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800382 s16 = p.readString16Inplace(&stringlen);
Wink Saville7f856802009-06-09 10:23:37 -0700383
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800384 return strndup16to8(s16, stringlen);
385}
386
Wink Savillef4c4d362009-04-02 01:37:03 -0700387static void writeStringToParcel(Parcel &p, const char *s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800388 char16_t *s16;
389 size_t s16_len;
390 s16 = strdup8to16(s, &s16_len);
391 p.writeString16(s16, s16_len);
392 free(s16);
393}
394
395
396static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700397memsetString (char *s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800398 if (s != NULL) {
399 memset (s, 0, strlen(s));
400 }
401}
402
403void nullParcelReleaseFunction (const uint8_t* data, size_t dataSize,
404 const size_t* objects, size_t objectsSize,
Wink Savillef4c4d362009-04-02 01:37:03 -0700405 void* cookie) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800406 // do nothing -- the data reference lives longer than the Parcel object
407}
408
Wink Saville7f856802009-06-09 10:23:37 -0700409/**
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800410 * To be called from dispatch thread
411 * Issue a single local request, ensuring that the response
Wink Saville7f856802009-06-09 10:23:37 -0700412 * is not sent back up to the command process
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800413 */
414static void
Etan Cohend3652192014-06-20 08:28:44 -0700415issueLocalRequest(int request, void *data, int len, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800416 RequestInfo *pRI;
417 int ret;
Etan Cohend3652192014-06-20 08:28:44 -0700418 /* Hook for current context */
419 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
420 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
421 /* pendingRequestsHook refer to &s_pendingRequests */
422 RequestInfo** pendingRequestsHook = &s_pendingRequests;
423
424#if (SIM_COUNT == 2)
425 if (socket_id == RIL_SOCKET_2) {
426 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
427 pendingRequestsHook = &s_pendingRequests_socket2;
428 }
429#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800430
431 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
432
433 pRI->local = 1;
434 pRI->token = 0xffffffff; // token is not used in this context
435 pRI->pCI = &(s_commands[request]);
Etan Cohend3652192014-06-20 08:28:44 -0700436 pRI->socket_id = socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800437
Etan Cohend3652192014-06-20 08:28:44 -0700438 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800439 assert (ret == 0);
440
Etan Cohend3652192014-06-20 08:28:44 -0700441 pRI->p_next = *pendingRequestsHook;
442 *pendingRequestsHook = pRI;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800443
Etan Cohend3652192014-06-20 08:28:44 -0700444 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800445 assert (ret == 0);
446
Wink Saville8eb2a122012-11-19 16:05:13 -0800447 RLOGD("C[locl]> %s", requestToString(request));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800448
Etan Cohend3652192014-06-20 08:28:44 -0700449 CALL_ONREQUEST(request, data, len, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800450}
451
452
453
454static int
Etan Cohend3652192014-06-20 08:28:44 -0700455processCommandBuffer(void *buffer, size_t buflen, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800456 Parcel p;
457 status_t status;
458 int32_t request;
459 int32_t token;
460 RequestInfo *pRI;
461 int ret;
Etan Cohend3652192014-06-20 08:28:44 -0700462 /* Hook for current context */
463 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
464 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
465 /* pendingRequestsHook refer to &s_pendingRequests */
466 RequestInfo** pendingRequestsHook = &s_pendingRequests;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800467
468 p.setData((uint8_t *) buffer, buflen);
469
470 // status checked at end
471 status = p.readInt32(&request);
472 status = p.readInt32 (&token);
473
Etan Cohend3652192014-06-20 08:28:44 -0700474 RLOGD("SOCKET %s REQUEST: %s length:%d", rilSocketIdToString(socket_id), requestToString(request), buflen);
475
476#if (SIM_COUNT >= 2)
477 if (socket_id == RIL_SOCKET_2) {
478 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
479 pendingRequestsHook = &s_pendingRequests_socket2;
480 }
481#if (SIM_COUNT >= 3)
482 else if (socket_id == RIL_SOCKET_3) {
483 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
484 pendingRequestsHook = &s_pendingRequests_socket3;
485 }
486#endif
487#if (SIM_COUNT >= 4)
488 else if (socket_id == RIL_SOCKET_4) {
489 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
490 pendingRequestsHook = &s_pendingRequests_socket4;
491 }
492#endif
493#endif
494
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800495 if (status != NO_ERROR) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800496 RLOGE("invalid request block");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800497 return 0;
498 }
499
500 if (request < 1 || request >= (int32_t)NUM_ELEMS(s_commands)) {
Etan Cohend3652192014-06-20 08:28:44 -0700501 Parcel pErr;
Wink Saville8eb2a122012-11-19 16:05:13 -0800502 RLOGE("unsupported request code %d token %d", request, token);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800503 // FIXME this should perhaps return a response
Etan Cohend3652192014-06-20 08:28:44 -0700504 pErr.writeInt32 (RESPONSE_SOLICITED);
505 pErr.writeInt32 (token);
506 pErr.writeInt32 (RIL_E_GENERIC_FAILURE);
507
508 sendResponse(pErr, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800509 return 0;
510 }
511
512
513 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
514
515 pRI->token = token;
516 pRI->pCI = &(s_commands[request]);
Etan Cohend3652192014-06-20 08:28:44 -0700517 pRI->socket_id = socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800518
Etan Cohend3652192014-06-20 08:28:44 -0700519 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800520 assert (ret == 0);
521
Etan Cohend3652192014-06-20 08:28:44 -0700522 pRI->p_next = *pendingRequestsHook;
523 *pendingRequestsHook = pRI;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800524
Etan Cohend3652192014-06-20 08:28:44 -0700525 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800526 assert (ret == 0);
527
528/* sLastDispatchedToken = token; */
529
Wink Saville7f856802009-06-09 10:23:37 -0700530 pRI->pCI->dispatchFunction(p, pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800531
532 return 0;
533}
534
535static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700536invalidCommandBlock (RequestInfo *pRI) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800537 RLOGE("invalid command block for token %d request %s",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800538 pRI->token, requestToString(pRI->pCI->requestNumber));
539}
540
541/** Callee expects NULL */
Wink Saville7f856802009-06-09 10:23:37 -0700542static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700543dispatchVoid (Parcel& p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800544 clearPrintBuf;
545 printRequest(pRI->token, pRI->pCI->requestNumber);
Etan Cohend3652192014-06-20 08:28:44 -0700546 CALL_ONREQUEST(pRI->pCI->requestNumber, NULL, 0, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800547}
548
549/** Callee expects const char * */
550static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700551dispatchString (Parcel& p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800552 status_t status;
553 size_t datalen;
554 size_t stringlen;
555 char *string8 = NULL;
556
557 string8 = strdupReadString(p);
558
559 startRequest;
560 appendPrintBuf("%s%s", printBuf, string8);
561 closeRequest;
562 printRequest(pRI->token, pRI->pCI->requestNumber);
563
Etan Cohend3652192014-06-20 08:28:44 -0700564 CALL_ONREQUEST(pRI->pCI->requestNumber, string8,
565 sizeof(char *), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800566
567#ifdef MEMSET_FREED
568 memsetString(string8);
569#endif
570
571 free(string8);
572 return;
573invalid:
574 invalidCommandBlock(pRI);
575 return;
576}
577
578/** Callee expects const char ** */
579static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700580dispatchStrings (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800581 int32_t countStrings;
582 status_t status;
583 size_t datalen;
584 char **pStrings;
585
586 status = p.readInt32 (&countStrings);
587
588 if (status != NO_ERROR) {
589 goto invalid;
590 }
591
592 startRequest;
593 if (countStrings == 0) {
594 // just some non-null pointer
595 pStrings = (char **)alloca(sizeof(char *));
596 datalen = 0;
597 } else if (((int)countStrings) == -1) {
598 pStrings = NULL;
599 datalen = 0;
600 } else {
601 datalen = sizeof(char *) * countStrings;
Wink Saville7f856802009-06-09 10:23:37 -0700602
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800603 pStrings = (char **)alloca(datalen);
604
605 for (int i = 0 ; i < countStrings ; i++) {
606 pStrings[i] = strdupReadString(p);
607 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
608 }
609 }
610 removeLastChar;
611 closeRequest;
612 printRequest(pRI->token, pRI->pCI->requestNumber);
613
Etan Cohend3652192014-06-20 08:28:44 -0700614 CALL_ONREQUEST(pRI->pCI->requestNumber, pStrings, datalen, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800615
616 if (pStrings != NULL) {
617 for (int i = 0 ; i < countStrings ; i++) {
618#ifdef MEMSET_FREED
619 memsetString (pStrings[i]);
620#endif
621 free(pStrings[i]);
622 }
623
624#ifdef MEMSET_FREED
625 memset(pStrings, 0, datalen);
626#endif
627 }
Wink Saville7f856802009-06-09 10:23:37 -0700628
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800629 return;
630invalid:
631 invalidCommandBlock(pRI);
632 return;
633}
634
635/** Callee expects const int * */
636static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700637dispatchInts (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800638 int32_t count;
639 status_t status;
640 size_t datalen;
641 int *pInts;
642
643 status = p.readInt32 (&count);
644
645 if (status != NO_ERROR || count == 0) {
646 goto invalid;
647 }
648
649 datalen = sizeof(int) * count;
650 pInts = (int *)alloca(datalen);
651
652 startRequest;
653 for (int i = 0 ; i < count ; i++) {
654 int32_t t;
655
656 status = p.readInt32(&t);
657 pInts[i] = (int)t;
658 appendPrintBuf("%s%d,", printBuf, t);
659
660 if (status != NO_ERROR) {
661 goto invalid;
662 }
663 }
664 removeLastChar;
665 closeRequest;
666 printRequest(pRI->token, pRI->pCI->requestNumber);
667
Etan Cohend3652192014-06-20 08:28:44 -0700668 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<int *>(pInts),
669 datalen, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800670
671#ifdef MEMSET_FREED
672 memset(pInts, 0, datalen);
673#endif
674
675 return;
676invalid:
677 invalidCommandBlock(pRI);
678 return;
679}
680
681
Wink Saville7f856802009-06-09 10:23:37 -0700682/**
683 * Callee expects const RIL_SMS_WriteArgs *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800684 * Payload is:
685 * int32_t status
686 * String pdu
687 */
688static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700689dispatchSmsWrite (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800690 RIL_SMS_WriteArgs args;
691 int32_t t;
692 status_t status;
693
694 memset (&args, 0, sizeof(args));
695
696 status = p.readInt32(&t);
697 args.status = (int)t;
698
699 args.pdu = strdupReadString(p);
700
701 if (status != NO_ERROR || args.pdu == NULL) {
702 goto invalid;
703 }
704
705 args.smsc = strdupReadString(p);
706
707 startRequest;
708 appendPrintBuf("%s%d,%s,smsc=%s", printBuf, args.status,
709 (char*)args.pdu, (char*)args.smsc);
710 closeRequest;
711 printRequest(pRI->token, pRI->pCI->requestNumber);
Wink Saville7f856802009-06-09 10:23:37 -0700712
Etan Cohend3652192014-06-20 08:28:44 -0700713 CALL_ONREQUEST(pRI->pCI->requestNumber, &args, sizeof(args), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800714
715#ifdef MEMSET_FREED
716 memsetString (args.pdu);
717#endif
718
719 free (args.pdu);
Wink Saville7f856802009-06-09 10:23:37 -0700720
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800721#ifdef MEMSET_FREED
722 memset(&args, 0, sizeof(args));
723#endif
724
725 return;
726invalid:
727 invalidCommandBlock(pRI);
728 return;
729}
730
Wink Saville7f856802009-06-09 10:23:37 -0700731/**
732 * Callee expects const RIL_Dial *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800733 * Payload is:
734 * String address
735 * int32_t clir
736 */
737static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700738dispatchDial (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800739 RIL_Dial dial;
Wink Saville74fa3882009-12-22 15:35:41 -0800740 RIL_UUS_Info uusInfo;
Wink Saville7bce0822010-01-08 15:20:12 -0800741 int32_t sizeOfDial;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800742 int32_t t;
Wink Saville74fa3882009-12-22 15:35:41 -0800743 int32_t uusPresent;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800744 status_t status;
745
746 memset (&dial, 0, sizeof(dial));
747
748 dial.address = strdupReadString(p);
749
750 status = p.readInt32(&t);
751 dial.clir = (int)t;
752
753 if (status != NO_ERROR || dial.address == NULL) {
754 goto invalid;
755 }
756
Wink Saville3a4840b2010-04-07 13:29:58 -0700757 if (s_callbacks.version < 3) { // Remove when partners upgrade to version 3
Wink Saville74fa3882009-12-22 15:35:41 -0800758 uusPresent = 0;
Wink Saville7bce0822010-01-08 15:20:12 -0800759 sizeOfDial = sizeof(dial) - sizeof(RIL_UUS_Info *);
Wink Saville74fa3882009-12-22 15:35:41 -0800760 } else {
761 status = p.readInt32(&uusPresent);
762
763 if (status != NO_ERROR) {
764 goto invalid;
765 }
766
767 if (uusPresent == 0) {
768 dial.uusInfo = NULL;
769 } else {
770 int32_t len;
771
772 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
773
774 status = p.readInt32(&t);
775 uusInfo.uusType = (RIL_UUS_Type) t;
776
777 status = p.readInt32(&t);
778 uusInfo.uusDcs = (RIL_UUS_DCS) t;
779
780 status = p.readInt32(&len);
781 if (status != NO_ERROR) {
782 goto invalid;
783 }
784
785 // The java code writes -1 for null arrays
786 if (((int) len) == -1) {
787 uusInfo.uusData = NULL;
788 len = 0;
789 } else {
790 uusInfo.uusData = (char*) p.readInplace(len);
791 }
792
793 uusInfo.uusLength = len;
794 dial.uusInfo = &uusInfo;
795 }
Wink Saville7bce0822010-01-08 15:20:12 -0800796 sizeOfDial = sizeof(dial);
Wink Saville74fa3882009-12-22 15:35:41 -0800797 }
798
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800799 startRequest;
800 appendPrintBuf("%snum=%s,clir=%d", printBuf, dial.address, dial.clir);
Wink Saville74fa3882009-12-22 15:35:41 -0800801 if (uusPresent) {
802 appendPrintBuf("%s,uusType=%d,uusDcs=%d,uusLen=%d", printBuf,
803 dial.uusInfo->uusType, dial.uusInfo->uusDcs,
804 dial.uusInfo->uusLength);
805 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800806 closeRequest;
807 printRequest(pRI->token, pRI->pCI->requestNumber);
808
Etan Cohend3652192014-06-20 08:28:44 -0700809 CALL_ONREQUEST(pRI->pCI->requestNumber, &dial, sizeOfDial, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800810
811#ifdef MEMSET_FREED
812 memsetString (dial.address);
813#endif
814
815 free (dial.address);
Wink Saville7f856802009-06-09 10:23:37 -0700816
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800817#ifdef MEMSET_FREED
Wink Saville74fa3882009-12-22 15:35:41 -0800818 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800819 memset(&dial, 0, sizeof(dial));
820#endif
821
822 return;
823invalid:
824 invalidCommandBlock(pRI);
825 return;
826}
827
Wink Saville7f856802009-06-09 10:23:37 -0700828/**
829 * Callee expects const RIL_SIM_IO *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800830 * Payload is:
831 * int32_t command
832 * int32_t fileid
833 * String path
834 * int32_t p1, p2, p3
Wink Saville7f856802009-06-09 10:23:37 -0700835 * String data
836 * String pin2
Wink Savillec0114b32011-02-18 10:14:07 -0800837 * String aidPtr
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800838 */
839static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700840dispatchSIM_IO (Parcel &p, RequestInfo *pRI) {
Wink Savillec0114b32011-02-18 10:14:07 -0800841 union RIL_SIM_IO {
842 RIL_SIM_IO_v6 v6;
843 RIL_SIM_IO_v5 v5;
844 } simIO;
845
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800846 int32_t t;
Wink Savillec0114b32011-02-18 10:14:07 -0800847 int size;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800848 status_t status;
849
850 memset (&simIO, 0, sizeof(simIO));
851
Wink Saville7f856802009-06-09 10:23:37 -0700852 // note we only check status at the end
853
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800854 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800855 simIO.v6.command = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800856
857 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800858 simIO.v6.fileid = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800859
Wink Savillec0114b32011-02-18 10:14:07 -0800860 simIO.v6.path = strdupReadString(p);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800861
862 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800863 simIO.v6.p1 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800864
865 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800866 simIO.v6.p2 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800867
868 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800869 simIO.v6.p3 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800870
Wink Savillec0114b32011-02-18 10:14:07 -0800871 simIO.v6.data = strdupReadString(p);
872 simIO.v6.pin2 = strdupReadString(p);
873 simIO.v6.aidPtr = strdupReadString(p);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800874
875 startRequest;
Wink Savillec0114b32011-02-18 10:14:07 -0800876 appendPrintBuf("%scmd=0x%X,efid=0x%X,path=%s,%d,%d,%d,%s,pin2=%s,aid=%s", printBuf,
877 simIO.v6.command, simIO.v6.fileid, (char*)simIO.v6.path,
878 simIO.v6.p1, simIO.v6.p2, simIO.v6.p3,
879 (char*)simIO.v6.data, (char*)simIO.v6.pin2, simIO.v6.aidPtr);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800880 closeRequest;
881 printRequest(pRI->token, pRI->pCI->requestNumber);
Wink Saville7f856802009-06-09 10:23:37 -0700882
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800883 if (status != NO_ERROR) {
884 goto invalid;
885 }
886
Wink Savillec0114b32011-02-18 10:14:07 -0800887 size = (s_callbacks.version < 6) ? sizeof(simIO.v5) : sizeof(simIO.v6);
Etan Cohend3652192014-06-20 08:28:44 -0700888 CALL_ONREQUEST(pRI->pCI->requestNumber, &simIO, size, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800889
890#ifdef MEMSET_FREED
Wink Savillec0114b32011-02-18 10:14:07 -0800891 memsetString (simIO.v6.path);
892 memsetString (simIO.v6.data);
893 memsetString (simIO.v6.pin2);
894 memsetString (simIO.v6.aidPtr);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800895#endif
896
Wink Savillec0114b32011-02-18 10:14:07 -0800897 free (simIO.v6.path);
898 free (simIO.v6.data);
899 free (simIO.v6.pin2);
900 free (simIO.v6.aidPtr);
Wink Saville7f856802009-06-09 10:23:37 -0700901
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800902#ifdef MEMSET_FREED
903 memset(&simIO, 0, sizeof(simIO));
904#endif
905
906 return;
907invalid:
908 invalidCommandBlock(pRI);
909 return;
910}
911
912/**
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800913 * Callee expects const RIL_SIM_APDU *
914 * Payload is:
915 * int32_t sessionid
916 * int32_t cla
917 * int32_t instruction
918 * int32_t p1, p2, p3
919 * String data
920 */
921static void
922dispatchSIM_APDU (Parcel &p, RequestInfo *pRI) {
923 int32_t t;
924 status_t status;
925 RIL_SIM_APDU apdu;
926
927 memset (&apdu, 0, sizeof(RIL_SIM_APDU));
928
929 // Note we only check status at the end. Any single failure leads to
930 // subsequent reads filing.
931 status = p.readInt32(&t);
932 apdu.sessionid = (int)t;
933
934 status = p.readInt32(&t);
935 apdu.cla = (int)t;
936
937 status = p.readInt32(&t);
938 apdu.instruction = (int)t;
939
940 status = p.readInt32(&t);
941 apdu.p1 = (int)t;
942
943 status = p.readInt32(&t);
944 apdu.p2 = (int)t;
945
946 status = p.readInt32(&t);
947 apdu.p3 = (int)t;
948
949 apdu.data = strdupReadString(p);
950
951 startRequest;
952 appendPrintBuf("%ssessionid=%d,cla=%d,ins=%d,p1=%d,p2=%d,p3=%d,data=%s",
953 printBuf, apdu.sessionid, apdu.cla, apdu.instruction, apdu.p1, apdu.p2,
954 apdu.p3, (char*)apdu.data);
955 closeRequest;
956 printRequest(pRI->token, pRI->pCI->requestNumber);
957
958 if (status != NO_ERROR) {
959 goto invalid;
960 }
961
Etan Cohend3652192014-06-20 08:28:44 -0700962 CALL_ONREQUEST(pRI->pCI->requestNumber, &apdu, sizeof(RIL_SIM_APDU), pRI, pRI->socket_id);
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800963
964#ifdef MEMSET_FREED
965 memsetString(apdu.data);
966#endif
967 free(apdu.data);
968
969#ifdef MEMSET_FREED
970 memset(&apdu, 0, sizeof(RIL_SIM_APDU));
971#endif
972
973 return;
974invalid:
975 invalidCommandBlock(pRI);
976 return;
977}
978
979
980/**
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800981 * Callee expects const RIL_CallForwardInfo *
982 * Payload is:
983 * int32_t status/action
984 * int32_t reason
985 * int32_t serviceCode
986 * int32_t toa
987 * String number (0 length -> null)
988 * int32_t timeSeconds
989 */
Wink Saville7f856802009-06-09 10:23:37 -0700990static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700991dispatchCallForward(Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800992 RIL_CallForwardInfo cff;
993 int32_t t;
994 status_t status;
995
996 memset (&cff, 0, sizeof(cff));
997
Wink Saville7f856802009-06-09 10:23:37 -0700998 // note we only check status at the end
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800999
1000 status = p.readInt32(&t);
1001 cff.status = (int)t;
Wink Saville7f856802009-06-09 10:23:37 -07001002
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001003 status = p.readInt32(&t);
1004 cff.reason = (int)t;
1005
1006 status = p.readInt32(&t);
1007 cff.serviceClass = (int)t;
1008
1009 status = p.readInt32(&t);
1010 cff.toa = (int)t;
1011
1012 cff.number = strdupReadString(p);
1013
1014 status = p.readInt32(&t);
1015 cff.timeSeconds = (int)t;
1016
1017 if (status != NO_ERROR) {
1018 goto invalid;
1019 }
1020
1021 // special case: number 0-length fields is null
1022
1023 if (cff.number != NULL && strlen (cff.number) == 0) {
1024 cff.number = NULL;
1025 }
1026
1027 startRequest;
1028 appendPrintBuf("%sstat=%d,reason=%d,serv=%d,toa=%d,%s,tout=%d", printBuf,
1029 cff.status, cff.reason, cff.serviceClass, cff.toa,
1030 (char*)cff.number, cff.timeSeconds);
1031 closeRequest;
1032 printRequest(pRI->token, pRI->pCI->requestNumber);
1033
Etan Cohend3652192014-06-20 08:28:44 -07001034 CALL_ONREQUEST(pRI->pCI->requestNumber, &cff, sizeof(cff), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001035
1036#ifdef MEMSET_FREED
1037 memsetString(cff.number);
1038#endif
1039
1040 free (cff.number);
1041
1042#ifdef MEMSET_FREED
1043 memset(&cff, 0, sizeof(cff));
1044#endif
1045
1046 return;
1047invalid:
1048 invalidCommandBlock(pRI);
1049 return;
1050}
1051
1052
Wink Saville7f856802009-06-09 10:23:37 -07001053static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001054dispatchRaw(Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001055 int32_t len;
1056 status_t status;
1057 const void *data;
1058
1059 status = p.readInt32(&len);
1060
1061 if (status != NO_ERROR) {
1062 goto invalid;
1063 }
1064
1065 // The java code writes -1 for null arrays
1066 if (((int)len) == -1) {
1067 data = NULL;
1068 len = 0;
Wink Saville7f856802009-06-09 10:23:37 -07001069 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001070
1071 data = p.readInplace(len);
1072
1073 startRequest;
1074 appendPrintBuf("%sraw_size=%d", printBuf, len);
1075 closeRequest;
1076 printRequest(pRI->token, pRI->pCI->requestNumber);
1077
Etan Cohend3652192014-06-20 08:28:44 -07001078 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<void *>(data), len, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001079
1080 return;
1081invalid:
1082 invalidCommandBlock(pRI);
1083 return;
1084}
1085
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001086static status_t
1087constructCdmaSms(Parcel &p, RequestInfo *pRI, RIL_CDMA_SMS_Message& rcsm) {
Wink Savillef4c4d362009-04-02 01:37:03 -07001088 int32_t t;
1089 uint8_t ut;
1090 status_t status;
1091 int32_t digitCount;
1092 int digitLimit;
Wink Saville7f856802009-06-09 10:23:37 -07001093
Wink Savillef4c4d362009-04-02 01:37:03 -07001094 memset(&rcsm, 0, sizeof(rcsm));
1095
1096 status = p.readInt32(&t);
1097 rcsm.uTeleserviceID = (int) t;
1098
1099 status = p.read(&ut,sizeof(ut));
1100 rcsm.bIsServicePresent = (uint8_t) ut;
1101
1102 status = p.readInt32(&t);
1103 rcsm.uServicecategory = (int) t;
1104
1105 status = p.readInt32(&t);
1106 rcsm.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1107
1108 status = p.readInt32(&t);
1109 rcsm.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1110
1111 status = p.readInt32(&t);
1112 rcsm.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1113
1114 status = p.readInt32(&t);
1115 rcsm.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1116
1117 status = p.read(&ut,sizeof(ut));
1118 rcsm.sAddress.number_of_digits= (uint8_t) ut;
1119
1120 digitLimit= MIN((rcsm.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
1121 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1122 status = p.read(&ut,sizeof(ut));
1123 rcsm.sAddress.digits[digitCount] = (uint8_t) ut;
1124 }
1125
Wink Saville7f856802009-06-09 10:23:37 -07001126 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001127 rcsm.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1128
Wink Saville7f856802009-06-09 10:23:37 -07001129 status = p.read(&ut,sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001130 rcsm.sSubAddress.odd = (uint8_t) ut;
1131
1132 status = p.read(&ut,sizeof(ut));
1133 rcsm.sSubAddress.number_of_digits = (uint8_t) ut;
1134
1135 digitLimit= MIN((rcsm.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
Wink Saville7f856802009-06-09 10:23:37 -07001136 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1137 status = p.read(&ut,sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001138 rcsm.sSubAddress.digits[digitCount] = (uint8_t) ut;
1139 }
1140
Wink Saville7f856802009-06-09 10:23:37 -07001141 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001142 rcsm.uBearerDataLen = (int) t;
1143
1144 digitLimit= MIN((rcsm.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
Wink Saville7f856802009-06-09 10:23:37 -07001145 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1146 status = p.read(&ut, sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001147 rcsm.aBearerData[digitCount] = (uint8_t) ut;
1148 }
1149
1150 if (status != NO_ERROR) {
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001151 return status;
Wink Savillef4c4d362009-04-02 01:37:03 -07001152 }
1153
1154 startRequest;
1155 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
Wink Saville1b5fd232009-04-22 14:50:00 -07001156 sAddress.digit_mode=%d, sAddress.Number_mode=%d, sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07001157 printBuf, rcsm.uTeleserviceID,rcsm.bIsServicePresent,rcsm.uServicecategory,
Wink Saville1b5fd232009-04-22 14:50:00 -07001158 rcsm.sAddress.digit_mode, rcsm.sAddress.number_mode,rcsm.sAddress.number_type);
Wink Savillef4c4d362009-04-02 01:37:03 -07001159 closeRequest;
Wink Saville7f856802009-06-09 10:23:37 -07001160
Wink Savillef4c4d362009-04-02 01:37:03 -07001161 printRequest(pRI->token, pRI->pCI->requestNumber);
1162
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001163 return status;
1164}
1165
1166static void
1167dispatchCdmaSms(Parcel &p, RequestInfo *pRI) {
1168 RIL_CDMA_SMS_Message rcsm;
1169
1170 ALOGD("dispatchCdmaSms");
1171 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1172 goto invalid;
1173 }
1174
Etan Cohend3652192014-06-20 08:28:44 -07001175 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001176
1177#ifdef MEMSET_FREED
1178 memset(&rcsm, 0, sizeof(rcsm));
1179#endif
1180
1181 return;
1182
1183invalid:
1184 invalidCommandBlock(pRI);
1185 return;
1186}
1187
Wink Saville7f856802009-06-09 10:23:37 -07001188static void
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001189dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1190 RIL_IMS_SMS_Message rism;
1191 RIL_CDMA_SMS_Message rcsm;
1192
1193 ALOGD("dispatchImsCdmaSms: retry=%d, messageRef=%d", retry, messageRef);
1194
1195 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1196 goto invalid;
1197 }
1198 memset(&rism, 0, sizeof(rism));
1199 rism.tech = RADIO_TECH_3GPP2;
1200 rism.retry = retry;
1201 rism.messageRef = messageRef;
1202 rism.message.cdmaMessage = &rcsm;
1203
Etan Cohend3652192014-06-20 08:28:44 -07001204 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001205 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Etan Cohend3652192014-06-20 08:28:44 -07001206 +sizeof(rcsm),pRI, pRI->socket_id);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001207
1208#ifdef MEMSET_FREED
1209 memset(&rcsm, 0, sizeof(rcsm));
1210 memset(&rism, 0, sizeof(rism));
1211#endif
1212
1213 return;
1214
1215invalid:
1216 invalidCommandBlock(pRI);
1217 return;
1218}
1219
1220static void
1221dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1222 RIL_IMS_SMS_Message rism;
1223 int32_t countStrings;
1224 status_t status;
1225 size_t datalen;
1226 char **pStrings;
1227 ALOGD("dispatchImsGsmSms: retry=%d, messageRef=%d", retry, messageRef);
1228
1229 status = p.readInt32 (&countStrings);
1230
1231 if (status != NO_ERROR) {
1232 goto invalid;
1233 }
1234
1235 memset(&rism, 0, sizeof(rism));
1236 rism.tech = RADIO_TECH_3GPP;
1237 rism.retry = retry;
1238 rism.messageRef = messageRef;
1239
1240 startRequest;
Etan Cohen5d891b72014-02-27 17:25:17 -08001241 appendPrintBuf("%stech=%d, retry=%d, messageRef=%d, ", printBuf,
1242 (int)rism.tech, (int)rism.retry, rism.messageRef);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001243 if (countStrings == 0) {
1244 // just some non-null pointer
1245 pStrings = (char **)alloca(sizeof(char *));
1246 datalen = 0;
1247 } else if (((int)countStrings) == -1) {
1248 pStrings = NULL;
1249 datalen = 0;
1250 } else {
1251 datalen = sizeof(char *) * countStrings;
1252
1253 pStrings = (char **)alloca(datalen);
1254
1255 for (int i = 0 ; i < countStrings ; i++) {
1256 pStrings[i] = strdupReadString(p);
1257 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
1258 }
1259 }
1260 removeLastChar;
1261 closeRequest;
1262 printRequest(pRI->token, pRI->pCI->requestNumber);
1263
1264 rism.message.gsmMessage = pStrings;
Etan Cohend3652192014-06-20 08:28:44 -07001265 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001266 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Etan Cohend3652192014-06-20 08:28:44 -07001267 +datalen, pRI, pRI->socket_id);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001268
1269 if (pStrings != NULL) {
1270 for (int i = 0 ; i < countStrings ; i++) {
1271#ifdef MEMSET_FREED
1272 memsetString (pStrings[i]);
1273#endif
1274 free(pStrings[i]);
1275 }
1276
1277#ifdef MEMSET_FREED
1278 memset(pStrings, 0, datalen);
1279#endif
1280 }
1281
1282#ifdef MEMSET_FREED
1283 memset(&rism, 0, sizeof(rism));
1284#endif
1285 return;
1286invalid:
1287 ALOGE("dispatchImsGsmSms invalid block");
1288 invalidCommandBlock(pRI);
1289 return;
1290}
1291
1292static void
1293dispatchImsSms(Parcel &p, RequestInfo *pRI) {
1294 int32_t t;
1295 status_t status = p.readInt32(&t);
1296 RIL_RadioTechnologyFamily format;
1297 uint8_t retry;
1298 int32_t messageRef;
1299
1300 ALOGD("dispatchImsSms");
1301 if (status != NO_ERROR) {
1302 goto invalid;
1303 }
1304 format = (RIL_RadioTechnologyFamily) t;
1305
1306 // read retry field
1307 status = p.read(&retry,sizeof(retry));
1308 if (status != NO_ERROR) {
1309 goto invalid;
1310 }
1311 // read messageRef field
1312 status = p.read(&messageRef,sizeof(messageRef));
1313 if (status != NO_ERROR) {
1314 goto invalid;
1315 }
1316
1317 if (RADIO_TECH_3GPP == format) {
1318 dispatchImsGsmSms(p, pRI, retry, messageRef);
1319 } else if (RADIO_TECH_3GPP2 == format) {
1320 dispatchImsCdmaSms(p, pRI, retry, messageRef);
1321 } else {
1322 ALOGE("requestImsSendSMS invalid format value =%d", format);
1323 }
1324
1325 return;
1326
1327invalid:
1328 invalidCommandBlock(pRI);
1329 return;
1330}
1331
1332static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001333dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI) {
1334 RIL_CDMA_SMS_Ack rcsa;
1335 int32_t t;
1336 status_t status;
1337 int32_t digitCount;
1338
1339 memset(&rcsa, 0, sizeof(rcsa));
1340
1341 status = p.readInt32(&t);
1342 rcsa.uErrorClass = (RIL_CDMA_SMS_ErrorClass) t;
1343
1344 status = p.readInt32(&t);
1345 rcsa.uSMSCauseCode = (int) t;
1346
1347 if (status != NO_ERROR) {
1348 goto invalid;
1349 }
1350
1351 startRequest;
Wink Saville1b5fd232009-04-22 14:50:00 -07001352 appendPrintBuf("%suErrorClass=%d, uTLStatus=%d, ",
1353 printBuf, rcsa.uErrorClass, rcsa.uSMSCauseCode);
Wink Savillef4c4d362009-04-02 01:37:03 -07001354 closeRequest;
1355
1356 printRequest(pRI->token, pRI->pCI->requestNumber);
1357
Etan Cohend3652192014-06-20 08:28:44 -07001358 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsa, sizeof(rcsa),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001359
1360#ifdef MEMSET_FREED
1361 memset(&rcsa, 0, sizeof(rcsa));
1362#endif
1363
1364 return;
1365
1366invalid:
1367 invalidCommandBlock(pRI);
1368 return;
1369}
1370
Wink Savillea592eeb2009-05-22 13:26:36 -07001371static void
1372dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1373 int32_t t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001374 status_t status;
Wink Savillea592eeb2009-05-22 13:26:36 -07001375 int32_t num;
Wink Savillef4c4d362009-04-02 01:37:03 -07001376
Wink Savillea592eeb2009-05-22 13:26:36 -07001377 status = p.readInt32(&num);
Wink Savillef4c4d362009-04-02 01:37:03 -07001378 if (status != NO_ERROR) {
1379 goto invalid;
1380 }
1381
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001382 {
1383 RIL_GSM_BroadcastSmsConfigInfo gsmBci[num];
1384 RIL_GSM_BroadcastSmsConfigInfo *gsmBciPtrs[num];
Wink Savillea592eeb2009-05-22 13:26:36 -07001385
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001386 startRequest;
1387 for (int i = 0 ; i < num ; i++ ) {
1388 gsmBciPtrs[i] = &gsmBci[i];
Wink Savillef4c4d362009-04-02 01:37:03 -07001389
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001390 status = p.readInt32(&t);
1391 gsmBci[i].fromServiceId = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001392
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001393 status = p.readInt32(&t);
1394 gsmBci[i].toServiceId = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001395
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001396 status = p.readInt32(&t);
1397 gsmBci[i].fromCodeScheme = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001398
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001399 status = p.readInt32(&t);
1400 gsmBci[i].toCodeScheme = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001401
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001402 status = p.readInt32(&t);
1403 gsmBci[i].selected = (uint8_t) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001404
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001405 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId =%d, \
1406 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]", printBuf, i,
1407 gsmBci[i].fromServiceId, gsmBci[i].toServiceId,
1408 gsmBci[i].fromCodeScheme, gsmBci[i].toCodeScheme,
1409 gsmBci[i].selected);
1410 }
1411 closeRequest;
Wink Savillef4c4d362009-04-02 01:37:03 -07001412
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001413 if (status != NO_ERROR) {
1414 goto invalid;
1415 }
Wink Savillef4c4d362009-04-02 01:37:03 -07001416
Etan Cohend3652192014-06-20 08:28:44 -07001417 CALL_ONREQUEST(pRI->pCI->requestNumber,
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001418 gsmBciPtrs,
1419 num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *),
Etan Cohend3652192014-06-20 08:28:44 -07001420 pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001421
1422#ifdef MEMSET_FREED
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001423 memset(gsmBci, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo));
1424 memset(gsmBciPtrs, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *));
Wink Savillef4c4d362009-04-02 01:37:03 -07001425#endif
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001426 }
Wink Savillef4c4d362009-04-02 01:37:03 -07001427
1428 return;
1429
1430invalid:
1431 invalidCommandBlock(pRI);
1432 return;
Wink Savillea592eeb2009-05-22 13:26:36 -07001433}
Wink Savillef4c4d362009-04-02 01:37:03 -07001434
Wink Savillea592eeb2009-05-22 13:26:36 -07001435static void
1436dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1437 int32_t t;
1438 status_t status;
1439 int32_t num;
1440
1441 status = p.readInt32(&num);
1442 if (status != NO_ERROR) {
1443 goto invalid;
1444 }
1445
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001446 {
1447 RIL_CDMA_BroadcastSmsConfigInfo cdmaBci[num];
1448 RIL_CDMA_BroadcastSmsConfigInfo *cdmaBciPtrs[num];
Wink Savillea592eeb2009-05-22 13:26:36 -07001449
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001450 startRequest;
1451 for (int i = 0 ; i < num ; i++ ) {
1452 cdmaBciPtrs[i] = &cdmaBci[i];
Wink Savillea592eeb2009-05-22 13:26:36 -07001453
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001454 status = p.readInt32(&t);
1455 cdmaBci[i].service_category = (int) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001456
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001457 status = p.readInt32(&t);
1458 cdmaBci[i].language = (int) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001459
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001460 status = p.readInt32(&t);
1461 cdmaBci[i].selected = (uint8_t) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001462
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001463 appendPrintBuf("%s [%d: service_category=%d, language =%d, \
1464 entries.bSelected =%d]", printBuf, i, cdmaBci[i].service_category,
1465 cdmaBci[i].language, cdmaBci[i].selected);
1466 }
1467 closeRequest;
Wink Savillea592eeb2009-05-22 13:26:36 -07001468
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001469 if (status != NO_ERROR) {
1470 goto invalid;
1471 }
Wink Savillea592eeb2009-05-22 13:26:36 -07001472
Etan Cohend3652192014-06-20 08:28:44 -07001473 CALL_ONREQUEST(pRI->pCI->requestNumber,
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001474 cdmaBciPtrs,
1475 num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *),
Etan Cohend3652192014-06-20 08:28:44 -07001476 pRI, pRI->socket_id);
Wink Savillea592eeb2009-05-22 13:26:36 -07001477
1478#ifdef MEMSET_FREED
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001479 memset(cdmaBci, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo));
1480 memset(cdmaBciPtrs, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *));
Wink Savillea592eeb2009-05-22 13:26:36 -07001481#endif
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001482 }
Wink Savillea592eeb2009-05-22 13:26:36 -07001483
1484 return;
1485
1486invalid:
1487 invalidCommandBlock(pRI);
1488 return;
Wink Savillef4c4d362009-04-02 01:37:03 -07001489}
1490
1491static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI) {
1492 RIL_CDMA_SMS_WriteArgs rcsw;
1493 int32_t t;
1494 uint32_t ut;
1495 uint8_t uct;
1496 status_t status;
1497 int32_t digitCount;
lricharde1c9b132013-10-29 14:55:30 +08001498 int32_t digitLimit;
Wink Savillef4c4d362009-04-02 01:37:03 -07001499
1500 memset(&rcsw, 0, sizeof(rcsw));
1501
1502 status = p.readInt32(&t);
1503 rcsw.status = t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001504
Wink Savillef4c4d362009-04-02 01:37:03 -07001505 status = p.readInt32(&t);
1506 rcsw.message.uTeleserviceID = (int) t;
1507
1508 status = p.read(&uct,sizeof(uct));
1509 rcsw.message.bIsServicePresent = (uint8_t) uct;
1510
1511 status = p.readInt32(&t);
1512 rcsw.message.uServicecategory = (int) t;
1513
1514 status = p.readInt32(&t);
1515 rcsw.message.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1516
1517 status = p.readInt32(&t);
1518 rcsw.message.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1519
1520 status = p.readInt32(&t);
1521 rcsw.message.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1522
1523 status = p.readInt32(&t);
1524 rcsw.message.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1525
1526 status = p.read(&uct,sizeof(uct));
1527 rcsw.message.sAddress.number_of_digits = (uint8_t) uct;
1528
lricharde1c9b132013-10-29 14:55:30 +08001529 digitLimit = MIN((rcsw.message.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
1530
1531 for(digitCount = 0 ; digitCount < digitLimit; digitCount ++) {
Wink Savillef4c4d362009-04-02 01:37:03 -07001532 status = p.read(&uct,sizeof(uct));
1533 rcsw.message.sAddress.digits[digitCount] = (uint8_t) uct;
1534 }
1535
Wink Savillea592eeb2009-05-22 13:26:36 -07001536 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001537 rcsw.message.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1538
Wink Savillea592eeb2009-05-22 13:26:36 -07001539 status = p.read(&uct,sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001540 rcsw.message.sSubAddress.odd = (uint8_t) uct;
1541
1542 status = p.read(&uct,sizeof(uct));
1543 rcsw.message.sSubAddress.number_of_digits = (uint8_t) uct;
1544
lricharde1c9b132013-10-29 14:55:30 +08001545 digitLimit = MIN((rcsw.message.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
1546
1547 for(digitCount = 0 ; digitCount < digitLimit; digitCount ++) {
Wink Savillea592eeb2009-05-22 13:26:36 -07001548 status = p.read(&uct,sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001549 rcsw.message.sSubAddress.digits[digitCount] = (uint8_t) uct;
1550 }
1551
Wink Savillea592eeb2009-05-22 13:26:36 -07001552 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001553 rcsw.message.uBearerDataLen = (int) t;
1554
lricharde1c9b132013-10-29 14:55:30 +08001555 digitLimit = MIN((rcsw.message.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
1556
1557 for(digitCount = 0 ; digitCount < digitLimit; digitCount ++) {
Wink Savillea592eeb2009-05-22 13:26:36 -07001558 status = p.read(&uct, sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001559 rcsw.message.aBearerData[digitCount] = (uint8_t) uct;
1560 }
1561
1562 if (status != NO_ERROR) {
1563 goto invalid;
1564 }
1565
1566 startRequest;
Wink Saville1b5fd232009-04-22 14:50:00 -07001567 appendPrintBuf("%sstatus=%d, message.uTeleserviceID=%d, message.bIsServicePresent=%d, \
1568 message.uServicecategory=%d, message.sAddress.digit_mode=%d, \
1569 message.sAddress.number_mode=%d, \
1570 message.sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07001571 printBuf, rcsw.status, rcsw.message.uTeleserviceID, rcsw.message.bIsServicePresent,
Wink Saville1b5fd232009-04-22 14:50:00 -07001572 rcsw.message.uServicecategory, rcsw.message.sAddress.digit_mode,
1573 rcsw.message.sAddress.number_mode,
1574 rcsw.message.sAddress.number_type);
Wink Savillef4c4d362009-04-02 01:37:03 -07001575 closeRequest;
1576
1577 printRequest(pRI->token, pRI->pCI->requestNumber);
1578
Etan Cohend3652192014-06-20 08:28:44 -07001579 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsw, sizeof(rcsw),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001580
1581#ifdef MEMSET_FREED
1582 memset(&rcsw, 0, sizeof(rcsw));
1583#endif
1584
1585 return;
1586
1587invalid:
1588 invalidCommandBlock(pRI);
1589 return;
1590
1591}
1592
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -07001593// For backwards compatibility in RIL_REQUEST_SETUP_DATA_CALL.
1594// Version 4 of the RIL interface adds a new PDP type parameter to support
1595// IPv6 and dual-stack PDP contexts. When dealing with a previous version of
1596// RIL, remove the parameter from the request.
1597static void dispatchDataCall(Parcel& p, RequestInfo *pRI) {
1598 // In RIL v3, REQUEST_SETUP_DATA_CALL takes 6 parameters.
1599 const int numParamsRilV3 = 6;
1600
1601 // The first bytes of the RIL parcel contain the request number and the
1602 // serial number - see processCommandBuffer(). Copy them over too.
1603 int pos = p.dataPosition();
1604
1605 int numParams = p.readInt32();
1606 if (s_callbacks.version < 4 && numParams > numParamsRilV3) {
1607 Parcel p2;
1608 p2.appendFrom(&p, 0, pos);
1609 p2.writeInt32(numParamsRilV3);
1610 for(int i = 0; i < numParamsRilV3; i++) {
1611 p2.writeString16(p.readString16());
1612 }
1613 p2.setDataPosition(pos);
1614 dispatchStrings(p2, pRI);
1615 } else {
Lorenzo Colitti57ce1f22010-09-13 12:23:50 -07001616 p.setDataPosition(pos);
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -07001617 dispatchStrings(p, pRI);
1618 }
1619}
1620
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001621// For backwards compatibility with RILs that dont support RIL_REQUEST_VOICE_RADIO_TECH.
1622// When all RILs handle this request, this function can be removed and
1623// the request can be sent directly to the RIL using dispatchVoid.
1624static void dispatchVoiceRadioTech(Parcel& p, RequestInfo *pRI) {
Etan Cohend3652192014-06-20 08:28:44 -07001625 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001626
1627 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1628 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1629 }
1630
1631 // RILs that support RADIO_STATE_ON should support this request.
1632 if (RADIO_STATE_ON == state) {
1633 dispatchVoid(p, pRI);
1634 return;
1635 }
1636
1637 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1638 // will not support this new request either and decode Voice Radio Technology
1639 // from Radio State
1640 voiceRadioTech = decodeVoiceRadioTechnology(state);
1641
1642 if (voiceRadioTech < 0)
1643 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1644 else
1645 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &voiceRadioTech, sizeof(int));
1646}
1647
1648// For backwards compatibility in RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE:.
1649// When all RILs handle this request, this function can be removed and
1650// the request can be sent directly to the RIL using dispatchVoid.
1651static void dispatchCdmaSubscriptionSource(Parcel& p, RequestInfo *pRI) {
Etan Cohend3652192014-06-20 08:28:44 -07001652 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001653
1654 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1655 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1656 }
1657
1658 // RILs that support RADIO_STATE_ON should support this request.
1659 if (RADIO_STATE_ON == state) {
1660 dispatchVoid(p, pRI);
1661 return;
1662 }
1663
1664 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1665 // will not support this new request either and decode CDMA Subscription Source
1666 // from Radio State
1667 cdmaSubscriptionSource = decodeCdmaSubscriptionSource(state);
1668
1669 if (cdmaSubscriptionSource < 0)
1670 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1671 else
1672 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &cdmaSubscriptionSource, sizeof(int));
1673}
1674
Sungmin Choi75697532013-04-26 15:04:45 -07001675static void dispatchSetInitialAttachApn(Parcel &p, RequestInfo *pRI)
1676{
1677 RIL_InitialAttachApn pf;
1678 int32_t t;
1679 status_t status;
1680
1681 memset(&pf, 0, sizeof(pf));
1682
1683 pf.apn = strdupReadString(p);
1684 pf.protocol = strdupReadString(p);
1685
1686 status = p.readInt32(&t);
1687 pf.authtype = (int) t;
1688
1689 pf.username = strdupReadString(p);
1690 pf.password = strdupReadString(p);
1691
1692 startRequest;
Etan Cohen5d891b72014-02-27 17:25:17 -08001693 appendPrintBuf("%sapn=%s, protocol=%s, authtype=%d, username=%s, password=%s",
1694 printBuf, pf.apn, pf.protocol, pf.authtype, pf.username, pf.password);
Sungmin Choi75697532013-04-26 15:04:45 -07001695 closeRequest;
1696 printRequest(pRI->token, pRI->pCI->requestNumber);
1697
1698 if (status != NO_ERROR) {
1699 goto invalid;
1700 }
Etan Cohend3652192014-06-20 08:28:44 -07001701 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
Sungmin Choi75697532013-04-26 15:04:45 -07001702
1703#ifdef MEMSET_FREED
1704 memsetString(pf.apn);
1705 memsetString(pf.protocol);
1706 memsetString(pf.username);
1707 memsetString(pf.password);
1708#endif
1709
1710 free(pf.apn);
1711 free(pf.protocol);
1712 free(pf.username);
1713 free(pf.password);
1714
1715#ifdef MEMSET_FREED
1716 memset(&pf, 0, sizeof(pf));
1717#endif
1718
1719 return;
1720invalid:
1721 invalidCommandBlock(pRI);
1722 return;
1723}
1724
Jake Hamby8a4a2332014-01-15 13:12:05 -08001725static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI) {
1726 RIL_NV_ReadItem nvri;
1727 int32_t t;
1728 status_t status;
1729
1730 memset(&nvri, 0, sizeof(nvri));
1731
1732 status = p.readInt32(&t);
1733 nvri.itemID = (RIL_NV_Item) t;
1734
1735 if (status != NO_ERROR) {
1736 goto invalid;
1737 }
1738
1739 startRequest;
1740 appendPrintBuf("%snvri.itemID=%d, ", printBuf, nvri.itemID);
1741 closeRequest;
1742
1743 printRequest(pRI->token, pRI->pCI->requestNumber);
1744
Etan Cohend3652192014-06-20 08:28:44 -07001745 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvri, sizeof(nvri), pRI, pRI->socket_id);
Jake Hamby8a4a2332014-01-15 13:12:05 -08001746
1747#ifdef MEMSET_FREED
1748 memset(&nvri, 0, sizeof(nvri));
1749#endif
1750
1751 return;
1752
1753invalid:
1754 invalidCommandBlock(pRI);
1755 return;
1756}
1757
1758static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI) {
1759 RIL_NV_WriteItem nvwi;
1760 int32_t t;
1761 status_t status;
1762
1763 memset(&nvwi, 0, sizeof(nvwi));
1764
1765 status = p.readInt32(&t);
1766 nvwi.itemID = (RIL_NV_Item) t;
1767
1768 nvwi.value = strdupReadString(p);
1769
1770 if (status != NO_ERROR || nvwi.value == NULL) {
1771 goto invalid;
1772 }
1773
1774 startRequest;
1775 appendPrintBuf("%snvwi.itemID=%d, value=%s, ", printBuf, nvwi.itemID,
1776 nvwi.value);
1777 closeRequest;
1778
1779 printRequest(pRI->token, pRI->pCI->requestNumber);
1780
Etan Cohend3652192014-06-20 08:28:44 -07001781 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvwi, sizeof(nvwi), pRI, pRI->socket_id);
Jake Hamby8a4a2332014-01-15 13:12:05 -08001782
1783#ifdef MEMSET_FREED
1784 memsetString(nvwi.value);
1785#endif
1786
1787 free(nvwi.value);
1788
1789#ifdef MEMSET_FREED
1790 memset(&nvwi, 0, sizeof(nvwi));
1791#endif
1792
1793 return;
1794
1795invalid:
1796 invalidCommandBlock(pRI);
1797 return;
1798}
1799
1800
Etan Cohend3652192014-06-20 08:28:44 -07001801static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI) {
1802 RIL_SelectUiccSub uicc_sub;
1803 status_t status;
1804 int32_t t;
1805 memset(&uicc_sub, 0, sizeof(uicc_sub));
1806
1807 status = p.readInt32(&t);
1808 if (status != NO_ERROR) {
1809 goto invalid;
1810 }
1811 uicc_sub.slot = (int) t;
1812
1813 status = p.readInt32(&t);
1814 if (status != NO_ERROR) {
1815 goto invalid;
1816 }
1817 uicc_sub.app_index = (int) t;
1818
1819 status = p.readInt32(&t);
1820 if (status != NO_ERROR) {
1821 goto invalid;
1822 }
1823 uicc_sub.sub_type = (RIL_SubscriptionType) t;
1824
1825 status = p.readInt32(&t);
1826 if (status != NO_ERROR) {
1827 goto invalid;
1828 }
1829 uicc_sub.act_status = (RIL_UiccSubActStatus) t;
1830
1831 startRequest;
1832 appendPrintBuf("slot=%d, app_index=%d, act_status = %d", uicc_sub.slot, uicc_sub.app_index,
1833 uicc_sub.act_status);
1834 RLOGD("dispatchUiccSubscription, slot=%d, app_index=%d, act_status = %d", uicc_sub.slot,
1835 uicc_sub.app_index, uicc_sub.act_status);
1836 closeRequest;
1837 printRequest(pRI->token, pRI->pCI->requestNumber);
1838
1839 CALL_ONREQUEST(pRI->pCI->requestNumber, &uicc_sub, sizeof(uicc_sub), pRI, pRI->socket_id);
1840
1841#ifdef MEMSET_FREED
1842 memset(&uicc_sub, 0, sizeof(uicc_sub));
1843#endif
1844 return;
1845
1846invalid:
1847 invalidCommandBlock(pRI);
1848 return;
1849}
1850
Amit Mahajan90530a62014-07-01 15:54:08 -07001851static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI)
1852{
1853 RIL_SimAuthentication pf;
1854 int32_t t;
1855 status_t status;
1856
1857 memset(&pf, 0, sizeof(pf));
1858
1859 status = p.readInt32(&t);
1860 pf.authContext = (int) t;
1861 pf.authData = strdupReadString(p);
1862 pf.aid = strdupReadString(p);
1863
1864 startRequest;
1865 appendPrintBuf("authContext=%s, authData=%s, aid=%s", pf.authContext, pf.authData, pf.aid);
1866 closeRequest;
1867 printRequest(pRI->token, pRI->pCI->requestNumber);
1868
1869 if (status != NO_ERROR) {
1870 goto invalid;
1871 }
1872 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
1873
1874#ifdef MEMSET_FREED
1875 memsetString(pf.authData);
1876 memsetString(pf.aid);
1877#endif
1878
1879 free(pf.authData);
1880 free(pf.aid);
1881
1882#ifdef MEMSET_FREED
1883 memset(&pf, 0, sizeof(pf));
1884#endif
1885
1886 return;
1887invalid:
1888 invalidCommandBlock(pRI);
1889 return;
1890}
1891
Amit Mahajanc796e222014-08-13 16:54:01 +00001892static void dispatchDataProfile(Parcel &p, RequestInfo *pRI) {
1893 int32_t t;
1894 status_t status;
1895 int32_t num;
1896
1897 status = p.readInt32(&num);
1898 if (status != NO_ERROR) {
1899 goto invalid;
1900 }
1901
1902 {
1903 RIL_DataProfileInfo dataProfiles[num];
1904 RIL_DataProfileInfo *dataProfilePtrs[num];
1905
1906 startRequest;
1907 for (int i = 0 ; i < num ; i++ ) {
1908 dataProfilePtrs[i] = &dataProfiles[i];
1909
1910 status = p.readInt32(&t);
1911 dataProfiles[i].profileId = (int) t;
1912
1913 dataProfiles[i].apn = strdupReadString(p);
1914 dataProfiles[i].protocol = strdupReadString(p);
1915 status = p.readInt32(&t);
1916 dataProfiles[i].authType = (int) t;
1917
1918 dataProfiles[i].user = strdupReadString(p);
1919 dataProfiles[i].password = strdupReadString(p);
1920
1921 status = p.readInt32(&t);
1922 dataProfiles[i].type = (int) t;
1923
1924 status = p.readInt32(&t);
1925 dataProfiles[i].maxConnsTime = (int) t;
1926 status = p.readInt32(&t);
1927 dataProfiles[i].maxConns = (int) t;
1928 status = p.readInt32(&t);
1929 dataProfiles[i].waitTime = (int) t;
1930
1931 status = p.readInt32(&t);
1932 dataProfiles[i].enabled = (int) t;
1933
1934 appendPrintBuf("%s [%d: profileId=%d, apn =%s, protocol =%s, authType =%d, \
1935 user =%s, password =%s, type =%d, maxConnsTime =%d, maxConns =%d, \
1936 waitTime =%d, enabled =%d]", printBuf, i, dataProfiles[i].profileId,
1937 dataProfiles[i].apn, dataProfiles[i].protocol, dataProfiles[i].authType,
1938 dataProfiles[i].user, dataProfiles[i].password, dataProfiles[i].type,
1939 dataProfiles[i].maxConnsTime, dataProfiles[i].maxConns,
1940 dataProfiles[i].waitTime, dataProfiles[i].enabled);
1941 }
1942 closeRequest;
1943 printRequest(pRI->token, pRI->pCI->requestNumber);
1944
1945 if (status != NO_ERROR) {
1946 goto invalid;
1947 }
1948 CALL_ONREQUEST(pRI->pCI->requestNumber,
1949 dataProfilePtrs,
1950 num * sizeof(RIL_DataProfileInfo *),
1951 pRI, pRI->socket_id);
1952
1953#ifdef MEMSET_FREED
1954 memset(dataProfiles, 0, num * sizeof(RIL_DataProfileInfo));
1955 memset(dataProfilePtrs, 0, num * sizeof(RIL_DataProfileInfo *));
1956#endif
1957 }
1958
1959 return;
1960
1961invalid:
1962 invalidCommandBlock(pRI);
1963 return;
1964}
1965
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001966static int
Wink Savillef4c4d362009-04-02 01:37:03 -07001967blockingWrite(int fd, const void *buffer, size_t len) {
Wink Saville7f856802009-06-09 10:23:37 -07001968 size_t writeOffset = 0;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001969 const uint8_t *toWrite;
1970
1971 toWrite = (const uint8_t *)buffer;
1972
1973 while (writeOffset < len) {
1974 ssize_t written;
1975 do {
1976 written = write (fd, toWrite + writeOffset,
1977 len - writeOffset);
Banavathu, Srinivas Naik38884902011-07-05 20:04:25 +05301978 } while (written < 0 && ((errno == EINTR) || (errno == EAGAIN)));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001979
1980 if (written >= 0) {
1981 writeOffset += written;
1982 } else { // written < 0
Wink Saville8eb2a122012-11-19 16:05:13 -08001983 RLOGE ("RIL Response: unexpected error on write errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001984 close(fd);
1985 return -1;
1986 }
1987 }
1988
1989 return 0;
1990}
1991
1992static int
Etan Cohend3652192014-06-20 08:28:44 -07001993sendResponseRaw (const void *data, size_t dataSize, RIL_SOCKET_ID socket_id) {
1994 int fd = s_ril_param_socket.fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001995 int ret;
1996 uint32_t header;
Etan Cohend3652192014-06-20 08:28:44 -07001997 pthread_mutex_t * writeMutexHook = &s_writeMutex;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001998
Etan Cohend3652192014-06-20 08:28:44 -07001999 RLOGE("Send Response to %s", rilSocketIdToString(socket_id));
2000
2001#if (SIM_COUNT >= 2)
2002 if (socket_id == RIL_SOCKET_2) {
2003 fd = s_ril_param_socket2.fdCommand;
2004 writeMutexHook = &s_writeMutex_socket2;
2005 }
2006#if (SIM_COUNT >= 3)
2007 else if (socket_id == RIL_SOCKET_3) {
2008 fd = s_ril_param_socket3.fdCommand;
2009 writeMutexHook = &s_writeMutex_socket3;
2010 }
2011#endif
2012#if (SIM_COUNT >= 4)
2013 else if (socket_id == RIL_SOCKET_4) {
2014 fd = s_ril_param_socket4.fdCommand;
2015 writeMutexHook = &s_writeMutex_socket4;
2016 }
2017#endif
2018#endif
2019 if (fd < 0) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002020 return -1;
2021 }
2022
2023 if (dataSize > MAX_COMMAND_BYTES) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002024 RLOGE("RIL: packet larger than %u (%u)",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002025 MAX_COMMAND_BYTES, (unsigned int )dataSize);
2026
2027 return -1;
2028 }
Wink Saville7f856802009-06-09 10:23:37 -07002029
Etan Cohend3652192014-06-20 08:28:44 -07002030 pthread_mutex_lock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002031
2032 header = htonl(dataSize);
2033
2034 ret = blockingWrite(fd, (void *)&header, sizeof(header));
2035
2036 if (ret < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002037 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002038 return ret;
2039 }
2040
Kennyee1fadc2009-08-13 00:45:53 +08002041 ret = blockingWrite(fd, data, dataSize);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002042
2043 if (ret < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002044 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002045 return ret;
2046 }
2047
Etan Cohend3652192014-06-20 08:28:44 -07002048 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002049
2050 return 0;
2051}
2052
2053static int
Etan Cohend3652192014-06-20 08:28:44 -07002054sendResponse (Parcel &p, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002055 printResponse;
Etan Cohend3652192014-06-20 08:28:44 -07002056 return sendResponseRaw(p.data(), p.dataSize(), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002057}
2058
Mohamad Ayyash74f7e662014-04-18 11:43:28 -07002059/** response is an int* pointing to an array of ints */
Wink Saville7f856802009-06-09 10:23:37 -07002060
2061static int
Wink Savillef4c4d362009-04-02 01:37:03 -07002062responseInts(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002063 int numInts;
2064
2065 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002066 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002067 return RIL_ERRNO_INVALID_RESPONSE;
2068 }
2069 if (responselen % sizeof(int) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002070 RLOGE("responseInts: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002071 (int)responselen, (int)sizeof(int));
2072 return RIL_ERRNO_INVALID_RESPONSE;
2073 }
2074
2075 int *p_int = (int *) response;
2076
Mohamad Ayyash74f7e662014-04-18 11:43:28 -07002077 numInts = responselen / sizeof(int);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002078 p.writeInt32 (numInts);
2079
2080 /* each int*/
2081 startResponse;
2082 for (int i = 0 ; i < numInts ; i++) {
2083 appendPrintBuf("%s%d,", printBuf, p_int[i]);
2084 p.writeInt32(p_int[i]);
2085 }
2086 removeLastChar;
2087 closeResponse;
2088
2089 return 0;
2090}
2091
Wink Saville43808972011-01-13 17:39:51 -08002092/** response is a char **, pointing to an array of char *'s
2093 The parcel will begin with the version */
2094static int responseStringsWithVersion(int version, Parcel &p, void *response, size_t responselen) {
2095 p.writeInt32(version);
2096 return responseStrings(p, response, responselen);
2097}
2098
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002099/** response is a char **, pointing to an array of char *'s */
Wink Savillef4c4d362009-04-02 01:37:03 -07002100static int responseStrings(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002101 int numStrings;
Wink Saville7f856802009-06-09 10:23:37 -07002102
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002103 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002104 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002105 return RIL_ERRNO_INVALID_RESPONSE;
2106 }
2107 if (responselen % sizeof(char *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002108 RLOGE("responseStrings: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002109 (int)responselen, (int)sizeof(char *));
2110 return RIL_ERRNO_INVALID_RESPONSE;
2111 }
2112
2113 if (response == NULL) {
2114 p.writeInt32 (0);
2115 } else {
2116 char **p_cur = (char **) response;
2117
2118 numStrings = responselen / sizeof(char *);
2119 p.writeInt32 (numStrings);
2120
2121 /* each string*/
2122 startResponse;
2123 for (int i = 0 ; i < numStrings ; i++) {
2124 appendPrintBuf("%s%s,", printBuf, (char*)p_cur[i]);
2125 writeStringToParcel (p, p_cur[i]);
2126 }
2127 removeLastChar;
2128 closeResponse;
2129 }
2130 return 0;
2131}
2132
2133
2134/**
Wink Saville7f856802009-06-09 10:23:37 -07002135 * NULL strings are accepted
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002136 * FIXME currently ignores responselen
2137 */
Wink Savillef4c4d362009-04-02 01:37:03 -07002138static int responseString(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002139 /* one string only */
2140 startResponse;
2141 appendPrintBuf("%s%s", printBuf, (char*)response);
2142 closeResponse;
2143
2144 writeStringToParcel(p, (const char *)response);
2145
2146 return 0;
2147}
2148
Wink Savillef4c4d362009-04-02 01:37:03 -07002149static int responseVoid(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002150 startResponse;
2151 removeLastChar;
2152 return 0;
2153}
2154
Wink Savillef4c4d362009-04-02 01:37:03 -07002155static int responseCallList(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002156 int num;
2157
2158 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002159 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002160 return RIL_ERRNO_INVALID_RESPONSE;
2161 }
2162
2163 if (responselen % sizeof (RIL_Call *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002164 RLOGE("responseCallList: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002165 (int)responselen, (int)sizeof (RIL_Call *));
2166 return RIL_ERRNO_INVALID_RESPONSE;
2167 }
2168
2169 startResponse;
2170 /* number of call info's */
2171 num = responselen / sizeof(RIL_Call *);
2172 p.writeInt32(num);
2173
2174 for (int i = 0 ; i < num ; i++) {
2175 RIL_Call *p_cur = ((RIL_Call **) response)[i];
2176 /* each call info */
2177 p.writeInt32(p_cur->state);
2178 p.writeInt32(p_cur->index);
2179 p.writeInt32(p_cur->toa);
2180 p.writeInt32(p_cur->isMpty);
2181 p.writeInt32(p_cur->isMT);
2182 p.writeInt32(p_cur->als);
2183 p.writeInt32(p_cur->isVoice);
Wink Saville1b5fd232009-04-22 14:50:00 -07002184 p.writeInt32(p_cur->isVoicePrivacy);
2185 writeStringToParcel(p, p_cur->number);
John Wangff368742009-03-24 17:56:29 -07002186 p.writeInt32(p_cur->numberPresentation);
Wink Saville1b5fd232009-04-22 14:50:00 -07002187 writeStringToParcel(p, p_cur->name);
2188 p.writeInt32(p_cur->namePresentation);
Wink Saville3a4840b2010-04-07 13:29:58 -07002189 // Remove when partners upgrade to version 3
Wink Saville74fa3882009-12-22 15:35:41 -08002190 if ((s_callbacks.version < 3) || (p_cur->uusInfo == NULL || p_cur->uusInfo->uusData == NULL)) {
2191 p.writeInt32(0); /* UUS Information is absent */
2192 } else {
2193 RIL_UUS_Info *uusInfo = p_cur->uusInfo;
2194 p.writeInt32(1); /* UUS Information is present */
2195 p.writeInt32(uusInfo->uusType);
2196 p.writeInt32(uusInfo->uusDcs);
2197 p.writeInt32(uusInfo->uusLength);
2198 p.write(uusInfo->uusData, uusInfo->uusLength);
2199 }
Wink Saville3d54e742009-05-18 18:00:44 -07002200 appendPrintBuf("%s[id=%d,%s,toa=%d,",
John Wangff368742009-03-24 17:56:29 -07002201 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002202 p_cur->index,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002203 callStateToString(p_cur->state),
Wink Saville3d54e742009-05-18 18:00:44 -07002204 p_cur->toa);
2205 appendPrintBuf("%s%s,%s,als=%d,%s,%s,",
2206 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002207 (p_cur->isMpty)?"conf":"norm",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002208 (p_cur->isMT)?"mt":"mo",
2209 p_cur->als,
2210 (p_cur->isVoice)?"voc":"nonvoc",
Wink Saville3d54e742009-05-18 18:00:44 -07002211 (p_cur->isVoicePrivacy)?"evp":"noevp");
2212 appendPrintBuf("%s%s,cli=%d,name='%s',%d]",
2213 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002214 p_cur->number,
2215 p_cur->numberPresentation,
2216 p_cur->name,
2217 p_cur->namePresentation);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002218 }
2219 removeLastChar;
2220 closeResponse;
2221
2222 return 0;
2223}
2224
Wink Savillef4c4d362009-04-02 01:37:03 -07002225static int responseSMS(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002226 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002227 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002228 return RIL_ERRNO_INVALID_RESPONSE;
2229 }
2230
2231 if (responselen != sizeof (RIL_SMS_Response) ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002232 RLOGE("invalid response length %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002233 (int)responselen, (int)sizeof (RIL_SMS_Response));
2234 return RIL_ERRNO_INVALID_RESPONSE;
2235 }
2236
2237 RIL_SMS_Response *p_cur = (RIL_SMS_Response *) response;
2238
2239 p.writeInt32(p_cur->messageRef);
2240 writeStringToParcel(p, p_cur->ackPDU);
Jaikumar Ganesh920c78f2009-06-04 10:53:15 -07002241 p.writeInt32(p_cur->errorCode);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002242
2243 startResponse;
Jaikumar Ganesh920c78f2009-06-04 10:53:15 -07002244 appendPrintBuf("%s%d,%s,%d", printBuf, p_cur->messageRef,
2245 (char*)p_cur->ackPDU, p_cur->errorCode);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002246 closeResponse;
2247
2248 return 0;
2249}
2250
Wink Savillec0114b32011-02-18 10:14:07 -08002251static int responseDataCallListV4(Parcel &p, void *response, size_t responselen)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002252{
2253 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002254 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002255 return RIL_ERRNO_INVALID_RESPONSE;
2256 }
2257
Wink Savillec0114b32011-02-18 10:14:07 -08002258 if (responselen % sizeof(RIL_Data_Call_Response_v4) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002259 RLOGE("responseDataCallListV4: invalid response length %d expected multiple of %d",
Wink Savillec0114b32011-02-18 10:14:07 -08002260 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v4));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002261 return RIL_ERRNO_INVALID_RESPONSE;
2262 }
2263
Amit Mahajan52500162014-07-29 17:36:48 -07002264 // Write version
2265 p.writeInt32(4);
2266
Wink Savillec0114b32011-02-18 10:14:07 -08002267 int num = responselen / sizeof(RIL_Data_Call_Response_v4);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002268 p.writeInt32(num);
2269
Wink Savillec0114b32011-02-18 10:14:07 -08002270 RIL_Data_Call_Response_v4 *p_cur = (RIL_Data_Call_Response_v4 *) response;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002271 startResponse;
2272 int i;
2273 for (i = 0; i < num; i++) {
2274 p.writeInt32(p_cur[i].cid);
2275 p.writeInt32(p_cur[i].active);
2276 writeStringToParcel(p, p_cur[i].type);
Wink Savillec0114b32011-02-18 10:14:07 -08002277 // apn is not used, so don't send.
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002278 writeStringToParcel(p, p_cur[i].address);
Wink Savillec0114b32011-02-18 10:14:07 -08002279 appendPrintBuf("%s[cid=%d,%s,%s,%s],", printBuf,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002280 p_cur[i].cid,
2281 (p_cur[i].active==0)?"down":"up",
2282 (char*)p_cur[i].type,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002283 (char*)p_cur[i].address);
2284 }
2285 removeLastChar;
2286 closeResponse;
2287
2288 return 0;
2289}
2290
Etan Cohend3652192014-06-20 08:28:44 -07002291static int responseDataCallListV6(Parcel &p, void *response, size_t responselen)
2292{
Amit Mahajan52500162014-07-29 17:36:48 -07002293 if (response == NULL && responselen != 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002294 RLOGE("invalid response: NULL");
2295 return RIL_ERRNO_INVALID_RESPONSE;
2296 }
2297
2298 if (responselen % sizeof(RIL_Data_Call_Response_v6) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002299 RLOGE("responseDataCallListV6: invalid response length %d expected multiple of %d",
Etan Cohend3652192014-06-20 08:28:44 -07002300 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v6));
2301 return RIL_ERRNO_INVALID_RESPONSE;
2302 }
2303
Amit Mahajan52500162014-07-29 17:36:48 -07002304 // Write version
2305 p.writeInt32(6);
2306
Etan Cohend3652192014-06-20 08:28:44 -07002307 int num = responselen / sizeof(RIL_Data_Call_Response_v6);
2308 p.writeInt32(num);
2309
2310 RIL_Data_Call_Response_v6 *p_cur = (RIL_Data_Call_Response_v6 *) response;
2311 startResponse;
2312 int i;
2313 for (i = 0; i < num; i++) {
2314 p.writeInt32((int)p_cur[i].status);
2315 p.writeInt32(p_cur[i].suggestedRetryTime);
2316 p.writeInt32(p_cur[i].cid);
2317 p.writeInt32(p_cur[i].active);
2318 writeStringToParcel(p, p_cur[i].type);
2319 writeStringToParcel(p, p_cur[i].ifname);
2320 writeStringToParcel(p, p_cur[i].addresses);
2321 writeStringToParcel(p, p_cur[i].dnses);
2322 writeStringToParcel(p, p_cur[i].gateways);
2323 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s],", printBuf,
2324 p_cur[i].status,
2325 p_cur[i].suggestedRetryTime,
2326 p_cur[i].cid,
2327 (p_cur[i].active==0)?"down":"up",
2328 (char*)p_cur[i].type,
2329 (char*)p_cur[i].ifname,
2330 (char*)p_cur[i].addresses,
2331 (char*)p_cur[i].dnses,
2332 (char*)p_cur[i].gateways);
2333 }
2334 removeLastChar;
2335 closeResponse;
2336
2337 return 0;
2338}
2339
Sukanya Rajkhowa30387ea2014-11-12 15:59:03 -08002340static int responseDataCallListV9CAF(Parcel &p, void *response, size_t responselen)
2341{
2342 if (response == NULL && responselen != 0) {
2343 RLOGE("invalid response: NULL");
2344 return RIL_ERRNO_INVALID_RESPONSE;
2345 }
2346
2347 // Write version
2348 p.writeInt32(10);
2349
2350 int num = responselen / sizeof(RIL_Data_Call_Response_v9_CAF);
2351 p.writeInt32(num);
2352
2353 RIL_Data_Call_Response_v9_CAF *p_cur = (RIL_Data_Call_Response_v9_CAF *) response;
2354 startResponse;
2355 int i;
2356 for (i = 0; i < num; i++) {
2357 p.writeInt32((int)p_cur[i].status);
2358 p.writeInt32(p_cur[i].suggestedRetryTime);
2359 p.writeInt32(p_cur[i].cid);
2360 p.writeInt32(p_cur[i].active);
2361 writeStringToParcel(p, p_cur[i].type);
2362 writeStringToParcel(p, p_cur[i].ifname);
2363 writeStringToParcel(p, p_cur[i].addresses);
2364 writeStringToParcel(p, p_cur[i].dnses);
2365 writeStringToParcel(p, p_cur[i].gateways);
2366 writeStringToParcel(p, p_cur[i].pcscf);
2367 p.writeInt32(p_cur[i].mtu);
2368 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s,mtu=%d],", printBuf,
2369 p_cur[i].status,
2370 p_cur[i].suggestedRetryTime,
2371 p_cur[i].cid,
2372 (p_cur[i].active==0)?"down":"up",
2373 (char*)p_cur[i].type,
2374 (char*)p_cur[i].ifname,
2375 (char*)p_cur[i].addresses,
2376 (char*)p_cur[i].dnses,
2377 (char*)p_cur[i].gateways,
2378 (char*)p_cur[i].pcscf,
2379 p_cur[i].mtu);
2380 }
2381
2382 removeLastChar;
2383 closeResponse;
2384
2385 return 0;
2386}
2387
Wink Saville43808972011-01-13 17:39:51 -08002388static int responseDataCallList(Parcel &p, void *response, size_t responselen)
2389{
Wink Saville43808972011-01-13 17:39:51 -08002390 if (s_callbacks.version < 5) {
Amit Mahajan52500162014-07-29 17:36:48 -07002391 RLOGD("responseDataCallList: v4");
Wink Savillec0114b32011-02-18 10:14:07 -08002392 return responseDataCallListV4(p, response, responselen);
Wink Saville43808972011-01-13 17:39:51 -08002393 } else {
2394 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002395 RLOGE("invalid response: NULL");
Wink Saville43808972011-01-13 17:39:51 -08002396 return RIL_ERRNO_INVALID_RESPONSE;
2397 }
2398
Sukanya Rajkhowa19938c32014-09-25 15:47:26 -07002399 // Support v6 only in ril version < 10
2400 if (s_callbacks.version < 10) {
Amit Mahajan52500162014-07-29 17:36:48 -07002401 RLOGD("responseDataCallList: v6");
Etan Cohend3652192014-06-20 08:28:44 -07002402 return responseDataCallListV6(p, response, responselen);
2403 }
2404
Sukanya Rajkhowa30387ea2014-11-12 15:59:03 -08002405 if (responselen % sizeof(RIL_Data_Call_Response_v9_CAF) == 0) {
2406 RLOGD("responseDataCallList: v9CAF");
2407 return responseDataCallListV9CAF(p, response, responselen);
2408 }
2409
Etan Cohend3652192014-06-20 08:28:44 -07002410 if (responselen % sizeof(RIL_Data_Call_Response_v9) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002411 RLOGE("responseDataCallList: invalid response length %d expected multiple of %d",
Etan Cohend3652192014-06-20 08:28:44 -07002412 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v9));
Wink Saville43808972011-01-13 17:39:51 -08002413 return RIL_ERRNO_INVALID_RESPONSE;
2414 }
2415
Amit Mahajan52500162014-07-29 17:36:48 -07002416 // Write version
2417 p.writeInt32(10);
2418
Etan Cohend3652192014-06-20 08:28:44 -07002419 int num = responselen / sizeof(RIL_Data_Call_Response_v9);
Wink Saville43808972011-01-13 17:39:51 -08002420 p.writeInt32(num);
2421
Etan Cohend3652192014-06-20 08:28:44 -07002422 RIL_Data_Call_Response_v9 *p_cur = (RIL_Data_Call_Response_v9 *) response;
Wink Saville43808972011-01-13 17:39:51 -08002423 startResponse;
2424 int i;
2425 for (i = 0; i < num; i++) {
2426 p.writeInt32((int)p_cur[i].status);
Kazuhiro Ondobeb25b52011-06-17 16:26:45 -05002427 p.writeInt32(p_cur[i].suggestedRetryTime);
Wink Saville43808972011-01-13 17:39:51 -08002428 p.writeInt32(p_cur[i].cid);
2429 p.writeInt32(p_cur[i].active);
David 'Digit' Turneraf1298d2011-02-04 13:36:47 +01002430 writeStringToParcel(p, p_cur[i].type);
Wink Saville43808972011-01-13 17:39:51 -08002431 writeStringToParcel(p, p_cur[i].ifname);
2432 writeStringToParcel(p, p_cur[i].addresses);
2433 writeStringToParcel(p, p_cur[i].dnses);
Wink Savillec0114b32011-02-18 10:14:07 -08002434 writeStringToParcel(p, p_cur[i].gateways);
Etan Cohend3652192014-06-20 08:28:44 -07002435 writeStringToParcel(p, p_cur[i].pcscf);
Sukanya Rajkhowa30387ea2014-11-12 15:59:03 -08002436 //Did not get MTU value in data call response. Send value=0 to framework
2437 p.writeInt32(0);
Etan Cohend3652192014-06-20 08:28:44 -07002438 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s],", printBuf,
Wink Saville43808972011-01-13 17:39:51 -08002439 p_cur[i].status,
Kazuhiro Ondobeb25b52011-06-17 16:26:45 -05002440 p_cur[i].suggestedRetryTime,
Wink Saville43808972011-01-13 17:39:51 -08002441 p_cur[i].cid,
2442 (p_cur[i].active==0)?"down":"up",
Naveen Kalla56384152011-11-16 11:12:37 -08002443 (char*)p_cur[i].type,
Wink Saville43808972011-01-13 17:39:51 -08002444 (char*)p_cur[i].ifname,
2445 (char*)p_cur[i].addresses,
Wink Savillec0114b32011-02-18 10:14:07 -08002446 (char*)p_cur[i].dnses,
Etan Cohend3652192014-06-20 08:28:44 -07002447 (char*)p_cur[i].gateways,
2448 (char*)p_cur[i].pcscf);
Wink Saville43808972011-01-13 17:39:51 -08002449 }
2450 removeLastChar;
2451 closeResponse;
2452 }
2453
2454 return 0;
2455}
2456
2457static int responseSetupDataCall(Parcel &p, void *response, size_t responselen)
2458{
2459 if (s_callbacks.version < 5) {
2460 return responseStringsWithVersion(s_callbacks.version, p, response, responselen);
2461 } else {
2462 return responseDataCallList(p, response, responselen);
2463 }
2464}
2465
Wink Savillef4c4d362009-04-02 01:37:03 -07002466static int responseRaw(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002467 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002468 RLOGE("invalid response: NULL with responselen != 0");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002469 return RIL_ERRNO_INVALID_RESPONSE;
2470 }
2471
2472 // The java code reads -1 size as null byte array
2473 if (response == NULL) {
Wink Saville7f856802009-06-09 10:23:37 -07002474 p.writeInt32(-1);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002475 } else {
2476 p.writeInt32(responselen);
2477 p.write(response, responselen);
2478 }
2479
2480 return 0;
2481}
2482
2483
Wink Savillef4c4d362009-04-02 01:37:03 -07002484static int responseSIM_IO(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002485 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002486 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002487 return RIL_ERRNO_INVALID_RESPONSE;
2488 }
2489
2490 if (responselen != sizeof (RIL_SIM_IO_Response) ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002491 RLOGE("invalid response length was %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002492 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
2493 return RIL_ERRNO_INVALID_RESPONSE;
2494 }
2495
2496 RIL_SIM_IO_Response *p_cur = (RIL_SIM_IO_Response *) response;
2497 p.writeInt32(p_cur->sw1);
2498 p.writeInt32(p_cur->sw2);
2499 writeStringToParcel(p, p_cur->simResponse);
2500
2501 startResponse;
2502 appendPrintBuf("%ssw1=0x%X,sw2=0x%X,%s", printBuf, p_cur->sw1, p_cur->sw2,
2503 (char*)p_cur->simResponse);
2504 closeResponse;
2505
2506
2507 return 0;
2508}
2509
Wink Savillef4c4d362009-04-02 01:37:03 -07002510static int responseCallForwards(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002511 int num;
Wink Saville7f856802009-06-09 10:23:37 -07002512
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002513 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002514 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002515 return RIL_ERRNO_INVALID_RESPONSE;
2516 }
2517
2518 if (responselen % sizeof(RIL_CallForwardInfo *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002519 RLOGE("responseCallForwards: invalid response length %d expected multiple of %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002520 (int)responselen, (int)sizeof(RIL_CallForwardInfo *));
2521 return RIL_ERRNO_INVALID_RESPONSE;
2522 }
2523
2524 /* number of call info's */
2525 num = responselen / sizeof(RIL_CallForwardInfo *);
2526 p.writeInt32(num);
2527
2528 startResponse;
2529 for (int i = 0 ; i < num ; i++) {
2530 RIL_CallForwardInfo *p_cur = ((RIL_CallForwardInfo **) response)[i];
2531
2532 p.writeInt32(p_cur->status);
2533 p.writeInt32(p_cur->reason);
2534 p.writeInt32(p_cur->serviceClass);
2535 p.writeInt32(p_cur->toa);
2536 writeStringToParcel(p, p_cur->number);
2537 p.writeInt32(p_cur->timeSeconds);
2538 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
2539 (p_cur->status==1)?"enable":"disable",
2540 p_cur->reason, p_cur->serviceClass, p_cur->toa,
2541 (char*)p_cur->number,
2542 p_cur->timeSeconds);
2543 }
2544 removeLastChar;
2545 closeResponse;
Wink Saville7f856802009-06-09 10:23:37 -07002546
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002547 return 0;
2548}
2549
Wink Savillef4c4d362009-04-02 01:37:03 -07002550static int responseSsn(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002551 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002552 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002553 return RIL_ERRNO_INVALID_RESPONSE;
2554 }
2555
2556 if (responselen != sizeof(RIL_SuppSvcNotification)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002557 RLOGE("invalid response length was %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002558 (int)responselen, (int)sizeof (RIL_SuppSvcNotification));
2559 return RIL_ERRNO_INVALID_RESPONSE;
2560 }
2561
2562 RIL_SuppSvcNotification *p_cur = (RIL_SuppSvcNotification *) response;
2563 p.writeInt32(p_cur->notificationType);
2564 p.writeInt32(p_cur->code);
2565 p.writeInt32(p_cur->index);
2566 p.writeInt32(p_cur->type);
2567 writeStringToParcel(p, p_cur->number);
2568
2569 startResponse;
2570 appendPrintBuf("%s%s,code=%d,id=%d,type=%d,%s", printBuf,
2571 (p_cur->notificationType==0)?"mo":"mt",
2572 p_cur->code, p_cur->index, p_cur->type,
2573 (char*)p_cur->number);
2574 closeResponse;
2575
2576 return 0;
2577}
2578
Wink Saville3d54e742009-05-18 18:00:44 -07002579static int responseCellList(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002580 int num;
2581
2582 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002583 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002584 return RIL_ERRNO_INVALID_RESPONSE;
2585 }
2586
2587 if (responselen % sizeof (RIL_NeighboringCell *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002588 RLOGE("responseCellList: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002589 (int)responselen, (int)sizeof (RIL_NeighboringCell *));
2590 return RIL_ERRNO_INVALID_RESPONSE;
2591 }
2592
2593 startResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002594 /* number of records */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002595 num = responselen / sizeof(RIL_NeighboringCell *);
2596 p.writeInt32(num);
2597
2598 for (int i = 0 ; i < num ; i++) {
2599 RIL_NeighboringCell *p_cur = ((RIL_NeighboringCell **) response)[i];
2600
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002601 p.writeInt32(p_cur->rssi);
2602 writeStringToParcel (p, p_cur->cid);
2603
2604 appendPrintBuf("%s[cid=%s,rssi=%d],", printBuf,
2605 p_cur->cid, p_cur->rssi);
2606 }
2607 removeLastChar;
2608 closeResponse;
2609
2610 return 0;
2611}
2612
Wink Saville3d54e742009-05-18 18:00:44 -07002613/**
2614 * Marshall the signalInfoRecord into the parcel if it exists.
2615 */
Wink Savillea592eeb2009-05-22 13:26:36 -07002616static void marshallSignalInfoRecord(Parcel &p,
2617 RIL_CDMA_SignalInfoRecord &p_signalInfoRecord) {
Wink Saville3d54e742009-05-18 18:00:44 -07002618 p.writeInt32(p_signalInfoRecord.isPresent);
2619 p.writeInt32(p_signalInfoRecord.signalType);
2620 p.writeInt32(p_signalInfoRecord.alertPitch);
2621 p.writeInt32(p_signalInfoRecord.signal);
2622}
2623
Wink Savillea592eeb2009-05-22 13:26:36 -07002624static int responseCdmaInformationRecords(Parcel &p,
2625 void *response, size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07002626 int num;
Wink Savillea592eeb2009-05-22 13:26:36 -07002627 char* string8 = NULL;
2628 int buffer_lenght;
2629 RIL_CDMA_InformationRecord *infoRec;
Wink Saville3d54e742009-05-18 18:00:44 -07002630
2631 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002632 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002633 return RIL_ERRNO_INVALID_RESPONSE;
2634 }
2635
Wink Savillea592eeb2009-05-22 13:26:36 -07002636 if (responselen != sizeof (RIL_CDMA_InformationRecords)) {
Amit Mahajan52500162014-07-29 17:36:48 -07002637 RLOGE("responseCdmaInformationRecords: invalid response length %d expected multiple of %d\n",
Wink Savillea592eeb2009-05-22 13:26:36 -07002638 (int)responselen, (int)sizeof (RIL_CDMA_InformationRecords *));
Wink Saville3d54e742009-05-18 18:00:44 -07002639 return RIL_ERRNO_INVALID_RESPONSE;
2640 }
2641
Wink Savillea592eeb2009-05-22 13:26:36 -07002642 RIL_CDMA_InformationRecords *p_cur =
2643 (RIL_CDMA_InformationRecords *) response;
2644 num = MIN(p_cur->numberOfInfoRecs, RIL_CDMA_MAX_NUMBER_OF_INFO_RECS);
Wink Saville3d54e742009-05-18 18:00:44 -07002645
2646 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07002647 p.writeInt32(num);
Wink Saville3d54e742009-05-18 18:00:44 -07002648
Wink Savillea592eeb2009-05-22 13:26:36 -07002649 for (int i = 0 ; i < num ; i++) {
2650 infoRec = &p_cur->infoRec[i];
2651 p.writeInt32(infoRec->name);
2652 switch (infoRec->name) {
Wink Savillea592eeb2009-05-22 13:26:36 -07002653 case RIL_CDMA_EXTENDED_DISPLAY_INFO_REC:
2654 if (infoRec->rec.display.alpha_len >
2655 CDMA_ALPHA_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002656 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002657 expected not more than %d\n",
2658 (int)infoRec->rec.display.alpha_len,
2659 CDMA_ALPHA_INFO_BUFFER_LENGTH);
2660 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002661 }
Sukanya Rajkhowa8f42fc72010-06-23 20:14:04 -07002662 // Write as a byteArray
2663 p.writeInt32(infoRec->rec.display.alpha_len);
2664 p.write(infoRec->rec.display.alpha_buf,
2665 infoRec->rec.display.alpha_len);
2666 break;
2667 case RIL_CDMA_DISPLAY_INFO_REC:
2668 if (infoRec->rec.display.alpha_len >
2669 CDMA_ALPHA_INFO_BUFFER_LENGTH) {
2670 RLOGE("invalid display info response length %d \
2671 expected not more than %d\n",
2672 (int)infoRec->rec.display.alpha_len,
2673 CDMA_ALPHA_INFO_BUFFER_LENGTH);
2674 return RIL_ERRNO_INVALID_RESPONSE;
2675 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002676 string8 = (char*) malloc((infoRec->rec.display.alpha_len + 1)
2677 * sizeof(char) );
2678 for (int i = 0 ; i < infoRec->rec.display.alpha_len ; i++) {
2679 string8[i] = infoRec->rec.display.alpha_buf[i];
2680 }
Wink Saville43808972011-01-13 17:39:51 -08002681 string8[(int)infoRec->rec.display.alpha_len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002682 writeStringToParcel(p, (const char*)string8);
2683 free(string8);
2684 string8 = NULL;
Wink Saville3d54e742009-05-18 18:00:44 -07002685 break;
2686 case RIL_CDMA_CALLED_PARTY_NUMBER_INFO_REC:
Wink Saville3d54e742009-05-18 18:00:44 -07002687 case RIL_CDMA_CALLING_PARTY_NUMBER_INFO_REC:
Wink Saville3d54e742009-05-18 18:00:44 -07002688 case RIL_CDMA_CONNECTED_NUMBER_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002689 if (infoRec->rec.number.len > CDMA_NUMBER_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002690 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002691 expected not more than %d\n",
2692 (int)infoRec->rec.number.len,
2693 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2694 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002695 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002696 string8 = (char*) malloc((infoRec->rec.number.len + 1)
2697 * sizeof(char) );
2698 for (int i = 0 ; i < infoRec->rec.number.len; i++) {
2699 string8[i] = infoRec->rec.number.buf[i];
2700 }
Wink Saville43808972011-01-13 17:39:51 -08002701 string8[(int)infoRec->rec.number.len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002702 writeStringToParcel(p, (const char*)string8);
2703 free(string8);
2704 string8 = NULL;
2705 p.writeInt32(infoRec->rec.number.number_type);
2706 p.writeInt32(infoRec->rec.number.number_plan);
2707 p.writeInt32(infoRec->rec.number.pi);
2708 p.writeInt32(infoRec->rec.number.si);
Wink Saville3d54e742009-05-18 18:00:44 -07002709 break;
2710 case RIL_CDMA_SIGNAL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002711 p.writeInt32(infoRec->rec.signal.isPresent);
2712 p.writeInt32(infoRec->rec.signal.signalType);
2713 p.writeInt32(infoRec->rec.signal.alertPitch);
2714 p.writeInt32(infoRec->rec.signal.signal);
2715
2716 appendPrintBuf("%sisPresent=%X, signalType=%X, \
2717 alertPitch=%X, signal=%X, ",
2718 printBuf, (int)infoRec->rec.signal.isPresent,
2719 (int)infoRec->rec.signal.signalType,
2720 (int)infoRec->rec.signal.alertPitch,
2721 (int)infoRec->rec.signal.signal);
2722 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002723 break;
2724 case RIL_CDMA_REDIRECTING_NUMBER_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002725 if (infoRec->rec.redir.redirectingNumber.len >
2726 CDMA_NUMBER_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002727 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002728 expected not more than %d\n",
2729 (int)infoRec->rec.redir.redirectingNumber.len,
2730 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2731 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002732 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002733 string8 = (char*) malloc((infoRec->rec.redir.redirectingNumber
2734 .len + 1) * sizeof(char) );
2735 for (int i = 0;
2736 i < infoRec->rec.redir.redirectingNumber.len;
2737 i++) {
2738 string8[i] = infoRec->rec.redir.redirectingNumber.buf[i];
2739 }
Wink Saville43808972011-01-13 17:39:51 -08002740 string8[(int)infoRec->rec.redir.redirectingNumber.len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002741 writeStringToParcel(p, (const char*)string8);
2742 free(string8);
2743 string8 = NULL;
2744 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_type);
2745 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_plan);
2746 p.writeInt32(infoRec->rec.redir.redirectingNumber.pi);
2747 p.writeInt32(infoRec->rec.redir.redirectingNumber.si);
2748 p.writeInt32(infoRec->rec.redir.redirectingReason);
Wink Saville3d54e742009-05-18 18:00:44 -07002749 break;
2750 case RIL_CDMA_LINE_CONTROL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002751 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPolarityIncluded);
2752 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlToggle);
2753 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlReverse);
2754 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2755
2756 appendPrintBuf("%slineCtrlPolarityIncluded=%d, \
2757 lineCtrlToggle=%d, lineCtrlReverse=%d, \
2758 lineCtrlPowerDenial=%d, ", printBuf,
2759 (int)infoRec->rec.lineCtrl.lineCtrlPolarityIncluded,
2760 (int)infoRec->rec.lineCtrl.lineCtrlToggle,
2761 (int)infoRec->rec.lineCtrl.lineCtrlReverse,
2762 (int)infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2763 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002764 break;
2765 case RIL_CDMA_T53_CLIR_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002766 p.writeInt32((int)(infoRec->rec.clir.cause));
Wink Saville3d54e742009-05-18 18:00:44 -07002767
Wink Savillea592eeb2009-05-22 13:26:36 -07002768 appendPrintBuf("%scause%d", printBuf, infoRec->rec.clir.cause);
2769 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002770 break;
2771 case RIL_CDMA_T53_AUDIO_CONTROL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002772 p.writeInt32(infoRec->rec.audioCtrl.upLink);
2773 p.writeInt32(infoRec->rec.audioCtrl.downLink);
2774
2775 appendPrintBuf("%supLink=%d, downLink=%d, ", printBuf,
2776 infoRec->rec.audioCtrl.upLink,
2777 infoRec->rec.audioCtrl.downLink);
2778 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002779 break;
Wink Savillea592eeb2009-05-22 13:26:36 -07002780 case RIL_CDMA_T53_RELEASE_INFO_REC:
2781 // TODO(Moto): See David Krause, he has the answer:)
Wink Saville8eb2a122012-11-19 16:05:13 -08002782 RLOGE("RIL_CDMA_T53_RELEASE_INFO_REC: return INVALID_RESPONSE");
Wink Savillea592eeb2009-05-22 13:26:36 -07002783 return RIL_ERRNO_INVALID_RESPONSE;
2784 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08002785 RLOGE("Incorrect name value");
Wink Savillea592eeb2009-05-22 13:26:36 -07002786 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002787 }
2788 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002789 closeResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002790
Wink Savillea592eeb2009-05-22 13:26:36 -07002791 return 0;
Wink Saville3d54e742009-05-18 18:00:44 -07002792}
2793
Wink Savillea592eeb2009-05-22 13:26:36 -07002794static int responseRilSignalStrength(Parcel &p,
2795 void *response, size_t responselen) {
2796 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002797 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002798 return RIL_ERRNO_INVALID_RESPONSE;
2799 }
2800
Wink Savillec0114b32011-02-18 10:14:07 -08002801 if (responselen >= sizeof (RIL_SignalStrength_v5)) {
Etan Cohend3652192014-06-20 08:28:44 -07002802 RIL_SignalStrength_v10 *p_cur = ((RIL_SignalStrength_v10 *) response);
Wink Saville3d54e742009-05-18 18:00:44 -07002803
Wink Saville3d54e742009-05-18 18:00:44 -07002804 p.writeInt32(p_cur->GW_SignalStrength.signalStrength);
2805 p.writeInt32(p_cur->GW_SignalStrength.bitErrorRate);
2806 p.writeInt32(p_cur->CDMA_SignalStrength.dbm);
2807 p.writeInt32(p_cur->CDMA_SignalStrength.ecio);
2808 p.writeInt32(p_cur->EVDO_SignalStrength.dbm);
2809 p.writeInt32(p_cur->EVDO_SignalStrength.ecio);
2810 p.writeInt32(p_cur->EVDO_SignalStrength.signalNoiseRatio);
Wink Savillec0114b32011-02-18 10:14:07 -08002811 if (responselen >= sizeof (RIL_SignalStrength_v6)) {
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002812 /*
Wink Saville18e4ab12013-04-07 17:31:04 -07002813 * Fixup LTE for backwards compatibility
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002814 */
Wink Saville18e4ab12013-04-07 17:31:04 -07002815 if (s_callbacks.version <= 6) {
2816 // signalStrength: -1 -> 99
2817 if (p_cur->LTE_SignalStrength.signalStrength == -1) {
2818 p_cur->LTE_SignalStrength.signalStrength = 99;
2819 }
2820 // rsrp: -1 -> INT_MAX all other negative value to positive.
2821 // So remap here
2822 if (p_cur->LTE_SignalStrength.rsrp == -1) {
2823 p_cur->LTE_SignalStrength.rsrp = INT_MAX;
2824 } else if (p_cur->LTE_SignalStrength.rsrp < -1) {
2825 p_cur->LTE_SignalStrength.rsrp = -p_cur->LTE_SignalStrength.rsrp;
2826 }
2827 // rsrq: -1 -> INT_MAX
2828 if (p_cur->LTE_SignalStrength.rsrq == -1) {
2829 p_cur->LTE_SignalStrength.rsrq = INT_MAX;
2830 }
2831 // Not remapping rssnr is already using INT_MAX
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002832
Wink Saville18e4ab12013-04-07 17:31:04 -07002833 // cqi: -1 -> INT_MAX
2834 if (p_cur->LTE_SignalStrength.cqi == -1) {
2835 p_cur->LTE_SignalStrength.cqi = INT_MAX;
2836 }
2837 }
2838 p.writeInt32(p_cur->LTE_SignalStrength.signalStrength);
Wink Savillec0114b32011-02-18 10:14:07 -08002839 p.writeInt32(p_cur->LTE_SignalStrength.rsrp);
2840 p.writeInt32(p_cur->LTE_SignalStrength.rsrq);
2841 p.writeInt32(p_cur->LTE_SignalStrength.rssnr);
2842 p.writeInt32(p_cur->LTE_SignalStrength.cqi);
Etan Cohend3652192014-06-20 08:28:44 -07002843 if (responselen >= sizeof (RIL_SignalStrength_v10)) {
2844 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
2845 } else {
2846 p.writeInt32(INT_MAX);
2847 }
Wink Savillec0114b32011-02-18 10:14:07 -08002848 } else {
Wink Saville18e4ab12013-04-07 17:31:04 -07002849 p.writeInt32(99);
2850 p.writeInt32(INT_MAX);
2851 p.writeInt32(INT_MAX);
2852 p.writeInt32(INT_MAX);
2853 p.writeInt32(INT_MAX);
Etan Cohend3652192014-06-20 08:28:44 -07002854 p.writeInt32(INT_MAX);
Wink Savillec0114b32011-02-18 10:14:07 -08002855 }
johnwangfdf825f2009-05-22 15:50:34 -07002856
2857 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07002858 appendPrintBuf("%s[signalStrength=%d,bitErrorRate=%d,\
Wink Savillec0114b32011-02-18 10:14:07 -08002859 CDMA_SS.dbm=%d,CDMA_SSecio=%d,\
2860 EVDO_SS.dbm=%d,EVDO_SS.ecio=%d,\
2861 EVDO_SS.signalNoiseRatio=%d,\
2862 LTE_SS.signalStrength=%d,LTE_SS.rsrp=%d,LTE_SS.rsrq=%d,\
Etan Cohend3652192014-06-20 08:28:44 -07002863 LTE_SS.rssnr=%d,LTE_SS.cqi=%d,TDSCDMA_SS.rscp=%d]",
Wink Savillea592eeb2009-05-22 13:26:36 -07002864 printBuf,
2865 p_cur->GW_SignalStrength.signalStrength,
2866 p_cur->GW_SignalStrength.bitErrorRate,
2867 p_cur->CDMA_SignalStrength.dbm,
2868 p_cur->CDMA_SignalStrength.ecio,
2869 p_cur->EVDO_SignalStrength.dbm,
2870 p_cur->EVDO_SignalStrength.ecio,
Wink Savillec0114b32011-02-18 10:14:07 -08002871 p_cur->EVDO_SignalStrength.signalNoiseRatio,
2872 p_cur->LTE_SignalStrength.signalStrength,
2873 p_cur->LTE_SignalStrength.rsrp,
2874 p_cur->LTE_SignalStrength.rsrq,
2875 p_cur->LTE_SignalStrength.rssnr,
Etan Cohend3652192014-06-20 08:28:44 -07002876 p_cur->LTE_SignalStrength.cqi,
2877 p_cur->TD_SCDMA_SignalStrength.rscp);
Wink Savillea592eeb2009-05-22 13:26:36 -07002878 closeResponse;
2879
Wink Saville3d54e742009-05-18 18:00:44 -07002880 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08002881 RLOGE("invalid response length");
Wink Saville3d54e742009-05-18 18:00:44 -07002882 return RIL_ERRNO_INVALID_RESPONSE;
2883 }
2884
Wink Saville3d54e742009-05-18 18:00:44 -07002885 return 0;
2886}
2887
2888static int responseCallRing(Parcel &p, void *response, size_t responselen) {
2889 if ((response == NULL) || (responselen == 0)) {
2890 return responseVoid(p, response, responselen);
2891 } else {
2892 return responseCdmaSignalInfoRecord(p, response, responselen);
2893 }
2894}
2895
2896static int responseCdmaSignalInfoRecord(Parcel &p, void *response, size_t responselen) {
2897 if (response == NULL || responselen == 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002898 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002899 return RIL_ERRNO_INVALID_RESPONSE;
2900 }
2901
2902 if (responselen != sizeof (RIL_CDMA_SignalInfoRecord)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002903 RLOGE("invalid response length %d expected sizeof (RIL_CDMA_SignalInfoRecord) of %d\n",
Wink Saville3d54e742009-05-18 18:00:44 -07002904 (int)responselen, (int)sizeof (RIL_CDMA_SignalInfoRecord));
2905 return RIL_ERRNO_INVALID_RESPONSE;
2906 }
2907
2908 startResponse;
2909
2910 RIL_CDMA_SignalInfoRecord *p_cur = ((RIL_CDMA_SignalInfoRecord *) response);
2911 marshallSignalInfoRecord(p, *p_cur);
2912
2913 appendPrintBuf("%s[isPresent=%d,signalType=%d,alertPitch=%d\
2914 signal=%d]",
2915 printBuf,
2916 p_cur->isPresent,
2917 p_cur->signalType,
2918 p_cur->alertPitch,
2919 p_cur->signal);
2920
2921 closeResponse;
2922 return 0;
2923}
2924
Wink Savillea592eeb2009-05-22 13:26:36 -07002925static int responseCdmaCallWaiting(Parcel &p, void *response,
2926 size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07002927 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002928 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002929 return RIL_ERRNO_INVALID_RESPONSE;
2930 }
2931
Wink Savillec0114b32011-02-18 10:14:07 -08002932 if (responselen < sizeof(RIL_CDMA_CallWaiting_v6)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002933 RLOGW("Upgrade to ril version %d\n", RIL_VERSION);
Wink Savillec0114b32011-02-18 10:14:07 -08002934 }
2935
2936 RIL_CDMA_CallWaiting_v6 *p_cur = ((RIL_CDMA_CallWaiting_v6 *) response);
2937
2938 writeStringToParcel(p, p_cur->number);
2939 p.writeInt32(p_cur->numberPresentation);
2940 writeStringToParcel(p, p_cur->name);
2941 marshallSignalInfoRecord(p, p_cur->signalInfoRecord);
2942
2943 if (responselen >= sizeof(RIL_CDMA_CallWaiting_v6)) {
2944 p.writeInt32(p_cur->number_type);
2945 p.writeInt32(p_cur->number_plan);
2946 } else {
2947 p.writeInt32(0);
2948 p.writeInt32(0);
Wink Saville3d54e742009-05-18 18:00:44 -07002949 }
2950
2951 startResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002952 appendPrintBuf("%snumber=%s,numberPresentation=%d, name=%s,\
2953 signalInfoRecord[isPresent=%d,signalType=%d,alertPitch=%d\
Wink Savillec0114b32011-02-18 10:14:07 -08002954 signal=%d,number_type=%d,number_plan=%d]",
Wink Saville3d54e742009-05-18 18:00:44 -07002955 printBuf,
2956 p_cur->number,
2957 p_cur->numberPresentation,
2958 p_cur->name,
2959 p_cur->signalInfoRecord.isPresent,
2960 p_cur->signalInfoRecord.signalType,
2961 p_cur->signalInfoRecord.alertPitch,
Wink Savillec0114b32011-02-18 10:14:07 -08002962 p_cur->signalInfoRecord.signal,
2963 p_cur->number_type,
2964 p_cur->number_plan);
Wink Saville3d54e742009-05-18 18:00:44 -07002965 closeResponse;
2966
2967 return 0;
2968}
2969
Alex Yakavenka45e740e2012-01-31 11:48:27 -08002970static int responseSimRefresh(Parcel &p, void *response, size_t responselen) {
2971 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002972 RLOGE("responseSimRefresh: invalid response: NULL");
Alex Yakavenka45e740e2012-01-31 11:48:27 -08002973 return RIL_ERRNO_INVALID_RESPONSE;
2974 }
2975
2976 startResponse;
Rakesh Pallerla36d27502014-01-10 17:53:15 +05302977 if (s_callbacks.version >= 7) {
Alex Yakavenka45e740e2012-01-31 11:48:27 -08002978 RIL_SimRefreshResponse_v7 *p_cur = ((RIL_SimRefreshResponse_v7 *) response);
2979 p.writeInt32(p_cur->result);
2980 p.writeInt32(p_cur->ef_id);
2981 writeStringToParcel(p, p_cur->aid);
2982
2983 appendPrintBuf("%sresult=%d, ef_id=%d, aid=%s",
2984 printBuf,
2985 p_cur->result,
2986 p_cur->ef_id,
2987 p_cur->aid);
2988 } else {
2989 int *p_cur = ((int *) response);
2990 p.writeInt32(p_cur[0]);
2991 p.writeInt32(p_cur[1]);
2992 writeStringToParcel(p, NULL);
2993
2994 appendPrintBuf("%sresult=%d, ef_id=%d",
2995 printBuf,
2996 p_cur[0],
2997 p_cur[1]);
2998 }
2999 closeResponse;
3000
3001 return 0;
3002}
3003
Wink Saville8a9e0212013-04-09 12:11:38 -07003004static int responseCellInfoList(Parcel &p, void *response, size_t responselen)
3005{
3006 if (response == NULL && responselen != 0) {
3007 RLOGE("invalid response: NULL");
3008 return RIL_ERRNO_INVALID_RESPONSE;
3009 }
3010
3011 if (responselen % sizeof(RIL_CellInfo) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07003012 RLOGE("responseCellInfoList: invalid response length %d expected multiple of %d",
Wink Saville8a9e0212013-04-09 12:11:38 -07003013 (int)responselen, (int)sizeof(RIL_CellInfo));
3014 return RIL_ERRNO_INVALID_RESPONSE;
3015 }
3016
3017 int num = responselen / sizeof(RIL_CellInfo);
3018 p.writeInt32(num);
3019
3020 RIL_CellInfo *p_cur = (RIL_CellInfo *) response;
3021 startResponse;
3022 int i;
3023 for (i = 0; i < num; i++) {
3024 appendPrintBuf("%s[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", printBuf, i,
3025 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
3026 p.writeInt32((int)p_cur->cellInfoType);
3027 p.writeInt32(p_cur->registered);
3028 p.writeInt32(p_cur->timeStampType);
3029 p.writeInt64(p_cur->timeStamp);
3030 switch(p_cur->cellInfoType) {
3031 case RIL_CELL_INFO_TYPE_GSM: {
Wink Savillec57b3eb2013-04-17 12:51:41 -07003032 appendPrintBuf("%s GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,", printBuf,
Wink Saville8a9e0212013-04-09 12:11:38 -07003033 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
3034 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
3035 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
Wink Savillec57b3eb2013-04-17 12:51:41 -07003036 p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3037 appendPrintBuf("%s gsmSS: ss=%d,ber=%d],", printBuf,
Wink Saville8a9e0212013-04-09 12:11:38 -07003038 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
3039 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3040
3041 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
3042 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
3043 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
3044 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
Wink Saville8a9e0212013-04-09 12:11:38 -07003045 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
3046 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3047 break;
3048 }
Wink Savillec57b3eb2013-04-17 12:51:41 -07003049 case RIL_CELL_INFO_TYPE_WCDMA: {
3050 appendPrintBuf("%s WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,", printBuf,
3051 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
3052 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
3053 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
3054 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
3055 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3056 appendPrintBuf("%s wcdmaSS: ss=%d,ber=%d],", printBuf,
3057 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
3058 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3059
3060 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
3061 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
3062 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
3063 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
3064 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3065 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
3066 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3067 break;
3068 }
Wink Saville8a9e0212013-04-09 12:11:38 -07003069 case RIL_CELL_INFO_TYPE_CDMA: {
3070 appendPrintBuf("%s CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d", printBuf,
3071 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
3072 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
3073 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
3074 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
3075 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3076
3077 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
3078 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
3079 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
3080 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
3081 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3082
3083 appendPrintBuf("%s cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d", printBuf,
3084 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
3085 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
3086 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
3087 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
3088 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3089
3090 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
3091 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
3092 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
3093 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
3094 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3095 break;
3096 }
3097 case RIL_CELL_INFO_TYPE_LTE: {
3098 appendPrintBuf("%s LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d", printBuf,
3099 p_cur->CellInfo.lte.cellIdentityLte.mcc,
3100 p_cur->CellInfo.lte.cellIdentityLte.mnc,
3101 p_cur->CellInfo.lte.cellIdentityLte.ci,
3102 p_cur->CellInfo.lte.cellIdentityLte.pci,
3103 p_cur->CellInfo.lte.cellIdentityLte.tac);
3104
3105 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
3106 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
3107 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
3108 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
3109 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
3110
3111 appendPrintBuf("%s lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d", printBuf,
3112 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
3113 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
3114 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
3115 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
3116 p_cur->CellInfo.lte.signalStrengthLte.cqi,
3117 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3118 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
3119 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
3120 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
3121 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
3122 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
3123 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3124 break;
3125 }
Etan Cohend3652192014-06-20 08:28:44 -07003126 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
3127 appendPrintBuf("%s TDSCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,cpid=%d,", printBuf,
3128 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc,
3129 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc,
3130 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac,
3131 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid,
3132 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3133 appendPrintBuf("%s tdscdmaSS: rscp=%d],", printBuf,
3134 p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3135
3136 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
3137 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
3138 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
3139 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
3140 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3141 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3142 break;
3143 }
Wink Saville8a9e0212013-04-09 12:11:38 -07003144 }
3145 p_cur += 1;
3146 }
3147 removeLastChar;
3148 closeResponse;
3149
3150 return 0;
3151}
3152
Etan Cohend3652192014-06-20 08:28:44 -07003153static int responseHardwareConfig(Parcel &p, void *response, size_t responselen)
3154{
3155 if (response == NULL && responselen != 0) {
3156 RLOGE("invalid response: NULL");
3157 return RIL_ERRNO_INVALID_RESPONSE;
3158 }
3159
3160 if (responselen % sizeof(RIL_HardwareConfig) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07003161 RLOGE("responseHardwareConfig: invalid response length %d expected multiple of %d",
Etan Cohend3652192014-06-20 08:28:44 -07003162 (int)responselen, (int)sizeof(RIL_HardwareConfig));
3163 return RIL_ERRNO_INVALID_RESPONSE;
3164 }
3165
3166 int num = responselen / sizeof(RIL_HardwareConfig);
3167 int i;
3168 RIL_HardwareConfig *p_cur = (RIL_HardwareConfig *) response;
3169
3170 p.writeInt32(num);
3171
3172 startResponse;
3173 for (i = 0; i < num; i++) {
3174 switch (p_cur[i].type) {
3175 case RIL_HARDWARE_CONFIG_MODEM: {
3176 writeStringToParcel(p, p_cur[i].uuid);
3177 p.writeInt32((int)p_cur[i].state);
3178 p.writeInt32(p_cur[i].cfg.modem.rat);
3179 p.writeInt32(p_cur[i].cfg.modem.maxVoice);
3180 p.writeInt32(p_cur[i].cfg.modem.maxData);
3181 p.writeInt32(p_cur[i].cfg.modem.maxStandby);
3182
3183 appendPrintBuf("%s modem: uuid=%s,state=%d,rat=%08x,maxV=%d,maxD=%d,maxS=%d", printBuf,
3184 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.modem.rat,
3185 p_cur[i].cfg.modem.maxVoice, p_cur[i].cfg.modem.maxData, p_cur[i].cfg.modem.maxStandby);
3186 break;
3187 }
3188 case RIL_HARDWARE_CONFIG_SIM: {
3189 writeStringToParcel(p, p_cur[i].uuid);
3190 p.writeInt32((int)p_cur[i].state);
3191 writeStringToParcel(p, p_cur[i].cfg.sim.modemUuid);
3192
3193 appendPrintBuf("%s sim: uuid=%s,state=%d,modem-uuid=%s", printBuf,
3194 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.sim.modemUuid);
3195 break;
3196 }
3197 }
3198 }
3199 removeLastChar;
3200 closeResponse;
3201 return 0;
3202}
3203
Naveen Kalla0ec0bc72011-11-15 12:52:06 -08003204static int responseSSData(Parcel &p, void *response, size_t responselen) {
3205 RLOGD("In responseSSData");
3206 int num;
3207
3208 if (response == NULL && responselen != 0) {
3209 RLOGE("invalid response: NULL");
3210 return RIL_ERRNO_INVALID_RESPONSE;
3211 }
3212
3213 if (responselen != sizeof(RIL_StkCcUnsolSsResponse)) {
3214 RLOGE("invalid response length %d, expected %d",
3215 (int)responselen, (int)sizeof(RIL_StkCcUnsolSsResponse));
3216 return RIL_ERRNO_INVALID_RESPONSE;
3217 }
3218
3219 startResponse;
3220 RIL_StkCcUnsolSsResponse *p_cur = (RIL_StkCcUnsolSsResponse *) response;
3221 p.writeInt32(p_cur->serviceType);
3222 p.writeInt32(p_cur->requestType);
3223 p.writeInt32(p_cur->teleserviceType);
3224 p.writeInt32(p_cur->serviceClass);
3225 p.writeInt32(p_cur->result);
3226
3227 if (isServiceTypeCfQuery(p_cur->serviceType, p_cur->requestType)) {
3228 RLOGD("responseSSData CF type, num of Cf elements %d", p_cur->cfData.numValidIndexes);
3229 if (p_cur->cfData.numValidIndexes > NUM_SERVICE_CLASSES) {
3230 RLOGE("numValidIndexes is greater than max value %d, "
3231 "truncating it to max value", NUM_SERVICE_CLASSES);
3232 p_cur->cfData.numValidIndexes = NUM_SERVICE_CLASSES;
3233 }
3234 /* number of call info's */
3235 p.writeInt32(p_cur->cfData.numValidIndexes);
3236
3237 for (int i = 0; i < p_cur->cfData.numValidIndexes; i++) {
3238 RIL_CallForwardInfo cf = p_cur->cfData.cfInfo[i];
3239
3240 p.writeInt32(cf.status);
3241 p.writeInt32(cf.reason);
3242 p.writeInt32(cf.serviceClass);
3243 p.writeInt32(cf.toa);
3244 writeStringToParcel(p, cf.number);
3245 p.writeInt32(cf.timeSeconds);
3246 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
3247 (cf.status==1)?"enable":"disable", cf.reason, cf.serviceClass, cf.toa,
3248 (char*)cf.number, cf.timeSeconds);
3249 RLOGD("Data: %d,reason=%d,cls=%d,toa=%d,num=%s,tout=%d],", cf.status,
3250 cf.reason, cf.serviceClass, cf.toa, (char*)cf.number, cf.timeSeconds);
3251 }
3252 } else {
3253 p.writeInt32 (SS_INFO_MAX);
3254
3255 /* each int*/
3256 for (int i = 0; i < SS_INFO_MAX; i++) {
3257 appendPrintBuf("%s%d,", printBuf, p_cur->ssInfo[i]);
3258 RLOGD("Data: %d",p_cur->ssInfo[i]);
3259 p.writeInt32(p_cur->ssInfo[i]);
3260 }
3261 }
3262 removeLastChar;
3263 closeResponse;
3264
3265 return 0;
3266}
3267
3268static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType) {
3269 if ((reqType == SS_INTERROGATION) &&
3270 (serType == SS_CFU ||
3271 serType == SS_CF_BUSY ||
3272 serType == SS_CF_NO_REPLY ||
3273 serType == SS_CF_NOT_REACHABLE ||
3274 serType == SS_CF_ALL ||
3275 serType == SS_CF_ALL_CONDITIONAL)) {
3276 return true;
3277 }
3278 return false;
3279}
3280
Wink Saville3d54e742009-05-18 18:00:44 -07003281static void triggerEvLoop() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003282 int ret;
3283 if (!pthread_equal(pthread_self(), s_tid_dispatch)) {
3284 /* trigger event loop to wakeup. No reason to do this,
3285 * if we're in the event loop thread */
3286 do {
3287 ret = write (s_fdWakeupWrite, " ", 1);
3288 } while (ret < 0 && errno == EINTR);
3289 }
3290}
3291
Wink Saville3d54e742009-05-18 18:00:44 -07003292static void rilEventAddWakeup(struct ril_event *ev) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003293 ril_event_add(ev);
3294 triggerEvLoop();
3295}
3296
Wink Savillefd729372011-02-22 16:19:39 -08003297static void sendSimStatusAppInfo(Parcel &p, int num_apps, RIL_AppStatus appStatus[]) {
3298 p.writeInt32(num_apps);
3299 startResponse;
3300 for (int i = 0; i < num_apps; i++) {
3301 p.writeInt32(appStatus[i].app_type);
3302 p.writeInt32(appStatus[i].app_state);
3303 p.writeInt32(appStatus[i].perso_substate);
3304 writeStringToParcel(p, (const char*)(appStatus[i].aid_ptr));
3305 writeStringToParcel(p, (const char*)
3306 (appStatus[i].app_label_ptr));
3307 p.writeInt32(appStatus[i].pin1_replaced);
3308 p.writeInt32(appStatus[i].pin1);
3309 p.writeInt32(appStatus[i].pin2);
3310 appendPrintBuf("%s[app_type=%d,app_state=%d,perso_substate=%d,\
3311 aid_ptr=%s,app_label_ptr=%s,pin1_replaced=%d,pin1=%d,pin2=%d],",
3312 printBuf,
3313 appStatus[i].app_type,
3314 appStatus[i].app_state,
3315 appStatus[i].perso_substate,
3316 appStatus[i].aid_ptr,
3317 appStatus[i].app_label_ptr,
3318 appStatus[i].pin1_replaced,
3319 appStatus[i].pin1,
3320 appStatus[i].pin2);
3321 }
3322 closeResponse;
3323}
3324
Wink Savillef4c4d362009-04-02 01:37:03 -07003325static int responseSimStatus(Parcel &p, void *response, size_t responselen) {
3326 int i;
3327
3328 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003329 RLOGE("invalid response: NULL");
Wink Savillef4c4d362009-04-02 01:37:03 -07003330 return RIL_ERRNO_INVALID_RESPONSE;
3331 }
3332
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003333 if (responselen == sizeof (RIL_CardStatus_v6)) {
Wink Savillefd729372011-02-22 16:19:39 -08003334 RIL_CardStatus_v6 *p_cur = ((RIL_CardStatus_v6 *) response);
Wink Savillef4c4d362009-04-02 01:37:03 -07003335
Wink Savillefd729372011-02-22 16:19:39 -08003336 p.writeInt32(p_cur->card_state);
3337 p.writeInt32(p_cur->universal_pin_state);
3338 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3339 p.writeInt32(p_cur->cdma_subscription_app_index);
3340 p.writeInt32(p_cur->ims_subscription_app_index);
3341
3342 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003343 } else if (responselen == sizeof (RIL_CardStatus_v5)) {
Wink Savillefd729372011-02-22 16:19:39 -08003344 RIL_CardStatus_v5 *p_cur = ((RIL_CardStatus_v5 *) response);
3345
3346 p.writeInt32(p_cur->card_state);
3347 p.writeInt32(p_cur->universal_pin_state);
3348 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3349 p.writeInt32(p_cur->cdma_subscription_app_index);
3350 p.writeInt32(-1);
3351
3352 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003353 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003354 RLOGE("responseSimStatus: A RilCardStatus_v6 or _v5 expected\n");
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003355 return RIL_ERRNO_INVALID_RESPONSE;
Wink Savillef4c4d362009-04-02 01:37:03 -07003356 }
Wink Savillef4c4d362009-04-02 01:37:03 -07003357
3358 return 0;
Wink Saville3d54e742009-05-18 18:00:44 -07003359}
Wink Savillef4c4d362009-04-02 01:37:03 -07003360
Wink Savillea592eeb2009-05-22 13:26:36 -07003361static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3362 int num = responselen / sizeof(RIL_GSM_BroadcastSmsConfigInfo *);
Wink Savillef4c4d362009-04-02 01:37:03 -07003363 p.writeInt32(num);
3364
Wink Savillef4c4d362009-04-02 01:37:03 -07003365 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07003366 RIL_GSM_BroadcastSmsConfigInfo **p_cur =
3367 (RIL_GSM_BroadcastSmsConfigInfo **) response;
3368 for (int i = 0; i < num; i++) {
3369 p.writeInt32(p_cur[i]->fromServiceId);
3370 p.writeInt32(p_cur[i]->toServiceId);
3371 p.writeInt32(p_cur[i]->fromCodeScheme);
3372 p.writeInt32(p_cur[i]->toCodeScheme);
3373 p.writeInt32(p_cur[i]->selected);
3374
3375 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId=%d, \
3376 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]",
3377 printBuf, i, p_cur[i]->fromServiceId, p_cur[i]->toServiceId,
3378 p_cur[i]->fromCodeScheme, p_cur[i]->toCodeScheme,
3379 p_cur[i]->selected);
3380 }
Wink Savillef4c4d362009-04-02 01:37:03 -07003381 closeResponse;
3382
3383 return 0;
3384}
3385
Wink Savillea592eeb2009-05-22 13:26:36 -07003386static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3387 RIL_CDMA_BroadcastSmsConfigInfo **p_cur =
3388 (RIL_CDMA_BroadcastSmsConfigInfo **) response;
Wink Savillef4c4d362009-04-02 01:37:03 -07003389
Wink Savillea592eeb2009-05-22 13:26:36 -07003390 int num = responselen / sizeof (RIL_CDMA_BroadcastSmsConfigInfo *);
3391 p.writeInt32(num);
Wink Savillef4c4d362009-04-02 01:37:03 -07003392
3393 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07003394 for (int i = 0 ; i < num ; i++ ) {
3395 p.writeInt32(p_cur[i]->service_category);
3396 p.writeInt32(p_cur[i]->language);
3397 p.writeInt32(p_cur[i]->selected);
Wink Savillef4c4d362009-04-02 01:37:03 -07003398
Wink Savillea592eeb2009-05-22 13:26:36 -07003399 appendPrintBuf("%s [%d: srvice_category=%d, language =%d, \
3400 selected =%d], ",
3401 printBuf, i, p_cur[i]->service_category, p_cur[i]->language,
3402 p_cur[i]->selected);
Wink Savillef5903df2009-04-24 11:54:14 -07003403 }
Wink Savillea592eeb2009-05-22 13:26:36 -07003404 closeResponse;
Wink Savillef5903df2009-04-24 11:54:14 -07003405
Wink Savillef4c4d362009-04-02 01:37:03 -07003406 return 0;
3407}
3408
3409static int responseCdmaSms(Parcel &p, void *response, size_t responselen) {
3410 int num;
3411 int digitCount;
3412 int digitLimit;
3413 uint8_t uct;
3414 void* dest;
3415
Wink Saville8eb2a122012-11-19 16:05:13 -08003416 RLOGD("Inside responseCdmaSms");
Wink Savillef5903df2009-04-24 11:54:14 -07003417
Wink Savillef4c4d362009-04-02 01:37:03 -07003418 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003419 RLOGE("invalid response: NULL");
Wink Savillef4c4d362009-04-02 01:37:03 -07003420 return RIL_ERRNO_INVALID_RESPONSE;
3421 }
3422
Wink Savillef5903df2009-04-24 11:54:14 -07003423 if (responselen != sizeof(RIL_CDMA_SMS_Message)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003424 RLOGE("invalid response length was %d expected %d",
Wink Savillef5903df2009-04-24 11:54:14 -07003425 (int)responselen, (int)sizeof(RIL_CDMA_SMS_Message));
Wink Savillef4c4d362009-04-02 01:37:03 -07003426 return RIL_ERRNO_INVALID_RESPONSE;
3427 }
3428
3429 RIL_CDMA_SMS_Message *p_cur = (RIL_CDMA_SMS_Message *) response;
3430 p.writeInt32(p_cur->uTeleserviceID);
3431 p.write(&(p_cur->bIsServicePresent),sizeof(uct));
3432 p.writeInt32(p_cur->uServicecategory);
3433 p.writeInt32(p_cur->sAddress.digit_mode);
3434 p.writeInt32(p_cur->sAddress.number_mode);
3435 p.writeInt32(p_cur->sAddress.number_type);
3436 p.writeInt32(p_cur->sAddress.number_plan);
3437 p.write(&(p_cur->sAddress.number_of_digits), sizeof(uct));
3438 digitLimit= MIN((p_cur->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
3439 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3440 p.write(&(p_cur->sAddress.digits[digitCount]),sizeof(uct));
3441 }
3442
3443 p.writeInt32(p_cur->sSubAddress.subaddressType);
3444 p.write(&(p_cur->sSubAddress.odd),sizeof(uct));
3445 p.write(&(p_cur->sSubAddress.number_of_digits),sizeof(uct));
3446 digitLimit= MIN((p_cur->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
3447 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3448 p.write(&(p_cur->sSubAddress.digits[digitCount]),sizeof(uct));
3449 }
3450
3451 digitLimit= MIN((p_cur->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
3452 p.writeInt32(p_cur->uBearerDataLen);
3453 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3454 p.write(&(p_cur->aBearerData[digitCount]), sizeof(uct));
3455 }
3456
3457 startResponse;
3458 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
Wink Saville1b5fd232009-04-22 14:50:00 -07003459 sAddress.digit_mode=%d, sAddress.number_mode=%d, sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07003460 printBuf, p_cur->uTeleserviceID,p_cur->bIsServicePresent,p_cur->uServicecategory,
3461 p_cur->sAddress.digit_mode, p_cur->sAddress.number_mode,p_cur->sAddress.number_type);
3462 closeResponse;
3463
3464 return 0;
3465}
3466
Wink Savillec29360a2014-07-13 05:17:28 -07003467static int responseDcRtInfo(Parcel &p, void *response, size_t responselen)
3468{
3469 int num = responselen / sizeof(RIL_DcRtInfo);
3470 if ((responselen % sizeof(RIL_DcRtInfo) != 0) || (num != 1)) {
Amit Mahajan52500162014-07-29 17:36:48 -07003471 RLOGE("responseDcRtInfo: invalid response length %d expected multiple of %d",
Wink Savillec29360a2014-07-13 05:17:28 -07003472 (int)responselen, (int)sizeof(RIL_DcRtInfo));
3473 return RIL_ERRNO_INVALID_RESPONSE;
3474 }
3475
3476 startResponse;
3477 RIL_DcRtInfo *pDcRtInfo = (RIL_DcRtInfo *)response;
3478 p.writeInt64(pDcRtInfo->time);
3479 p.writeInt32(pDcRtInfo->powerState);
3480 appendPrintBuf("%s[time=%d,powerState=%d]", printBuf,
3481 pDcRtInfo->time,
3482 pDcRtInfo->powerState);
3483 closeResponse;
3484
3485 return 0;
3486}
3487
Naveen Kalla41c1c0b2011-11-15 12:48:22 -08003488/* response is the count and the list of RIL_DataCallProfileInfo */
3489static int responseGetDataCallProfile(Parcel &p, void *response, size_t responselen) {
3490 int num = 0;
3491
3492 RLOGD("[OMH>]> %d", responselen);
3493
3494 if (response == NULL && responselen != 0) {
3495 RLOGE("invalid response: NULL");
3496 return RIL_ERRNO_INVALID_RESPONSE;
3497 }
3498
3499 RLOGD("[OMH>]> processing response");
3500
3501 /* number of profile info's */
3502 num = *((int *) response);
3503 if (num > (responselen / sizeof(RIL_DataCallProfileInfo))) {
3504 num = responselen / sizeof(RIL_DataCallProfileInfo);
3505 }
3506 p.writeInt32(num);
3507
3508 RIL_DataCallProfileInfo *p_cur = ((RIL_DataCallProfileInfo *) ((int *)response + 1));
3509
3510 startResponse;
3511 for (int i = 0 ; i < num ; i++) {
3512 p.writeInt32(p_cur->profileId);
3513 p.writeInt32(p_cur->priority);
3514 appendPrintBuf("%s[profileId=%d,priority=%d],", printBuf,
3515 p_cur->profileId, p_cur->priority);
3516 p_cur++;
3517 }
3518 removeLastChar;
3519 closeResponse;
3520
3521 return 0;
3522}
3523
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003524/**
3525 * A write on the wakeup fd is done just to pop us out of select()
3526 * We empty the buffer here and then ril_event will reset the timers on the
3527 * way back down
3528 */
Wink Savillef4c4d362009-04-02 01:37:03 -07003529static void processWakeupCallback(int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003530 char buff[16];
3531 int ret;
3532
Wink Saville8eb2a122012-11-19 16:05:13 -08003533 RLOGV("processWakeupCallback");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003534
3535 /* empty our wakeup socket out */
3536 do {
3537 ret = read(s_fdWakeupRead, &buff, sizeof(buff));
Wink Saville7f856802009-06-09 10:23:37 -07003538 } while (ret > 0 || (ret < 0 && errno == EINTR));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003539}
3540
Etan Cohend3652192014-06-20 08:28:44 -07003541static void onCommandsSocketClosed(RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003542 int ret;
3543 RequestInfo *p_cur;
Etan Cohend3652192014-06-20 08:28:44 -07003544 /* Hook for current context
3545 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
3546 pthread_mutex_t * pendingRequestsMutexHook = &s_pendingRequestsMutex;
3547 /* pendingRequestsHook refer to &s_pendingRequests */
3548 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003549
Etan Cohend3652192014-06-20 08:28:44 -07003550#if (SIM_COUNT >= 2)
3551 if (socket_id == RIL_SOCKET_2) {
3552 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
3553 pendingRequestsHook = &s_pendingRequests_socket2;
3554 }
3555#if (SIM_COUNT >= 3)
3556 else if (socket_id == RIL_SOCKET_3) {
3557 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
3558 pendingRequestsHook = &s_pendingRequests_socket3;
3559 }
3560#endif
3561#if (SIM_COUNT >= 4)
3562 else if (socket_id == RIL_SOCKET_4) {
3563 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
3564 pendingRequestsHook = &s_pendingRequests_socket4;
3565 }
3566#endif
3567#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003568 /* mark pending requests as "cancelled" so we dont report responses */
Etan Cohend3652192014-06-20 08:28:44 -07003569 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003570 assert (ret == 0);
3571
Etan Cohend3652192014-06-20 08:28:44 -07003572 p_cur = *pendingRequestsHook;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003573
Etan Cohend3652192014-06-20 08:28:44 -07003574 for (p_cur = *pendingRequestsHook
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003575 ; p_cur != NULL
3576 ; p_cur = p_cur->p_next
3577 ) {
3578 p_cur->cancelled = 1;
3579 }
3580
Etan Cohend3652192014-06-20 08:28:44 -07003581 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003582 assert (ret == 0);
3583}
3584
Wink Savillef4c4d362009-04-02 01:37:03 -07003585static void processCommandsCallback(int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003586 RecordStream *p_rs;
3587 void *p_record;
3588 size_t recordlen;
3589 int ret;
Etan Cohend3652192014-06-20 08:28:44 -07003590 SocketListenParam *p_info = (SocketListenParam *)param;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003591
Etan Cohend3652192014-06-20 08:28:44 -07003592 assert(fd == p_info->fdCommand);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003593
Etan Cohend3652192014-06-20 08:28:44 -07003594 p_rs = p_info->p_rs;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003595
3596 for (;;) {
3597 /* loop until EAGAIN/EINTR, end of stream, or other error */
3598 ret = record_stream_get_next(p_rs, &p_record, &recordlen);
3599
3600 if (ret == 0 && p_record == NULL) {
3601 /* end-of-stream */
3602 break;
3603 } else if (ret < 0) {
3604 break;
3605 } else if (ret == 0) { /* && p_record != NULL */
Etan Cohend3652192014-06-20 08:28:44 -07003606 processCommandBuffer(p_record, recordlen, p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003607 }
3608 }
3609
3610 if (ret == 0 || !(errno == EAGAIN || errno == EINTR)) {
3611 /* fatal error or end-of-stream */
3612 if (ret != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003613 RLOGE("error on reading command socket errno:%d\n", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003614 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003615 RLOGW("EOS. Closing command socket.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003616 }
Wink Saville7f856802009-06-09 10:23:37 -07003617
Etan Cohend3652192014-06-20 08:28:44 -07003618 close(fd);
3619 p_info->fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003620
Etan Cohend3652192014-06-20 08:28:44 -07003621 ril_event_del(p_info->commands_event);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003622
3623 record_stream_free(p_rs);
3624
3625 /* start listening for new connections again */
3626 rilEventAddWakeup(&s_listen_event);
3627
Etan Cohend3652192014-06-20 08:28:44 -07003628 onCommandsSocketClosed(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003629 }
3630}
3631
3632
Etan Cohend3652192014-06-20 08:28:44 -07003633static void onNewCommandConnect(RIL_SOCKET_ID socket_id) {
Wink Saville5b9df332011-04-06 16:24:21 -07003634 // Inform we are connected and the ril version
Jake Hambya9c18d12011-04-12 23:32:08 -07003635 int rilVer = s_callbacks.version;
Etan Cohend3652192014-06-20 08:28:44 -07003636 RIL_UNSOL_RESPONSE(RIL_UNSOL_RIL_CONNECTED,
3637 &rilVer, sizeof(rilVer), socket_id);
Wink Saville5b9df332011-04-06 16:24:21 -07003638
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003639 // implicit radio state changed
Etan Cohend3652192014-06-20 08:28:44 -07003640 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
3641 NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003642
3643 // Send last NITZ time data, in case it was missed
3644 if (s_lastNITZTimeData != NULL) {
Etan Cohend3652192014-06-20 08:28:44 -07003645 sendResponseRaw(s_lastNITZTimeData, s_lastNITZTimeDataSize, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003646
3647 free(s_lastNITZTimeData);
3648 s_lastNITZTimeData = NULL;
3649 }
3650
3651 // Get version string
3652 if (s_callbacks.getVersion != NULL) {
3653 const char *version;
3654 version = s_callbacks.getVersion();
Wink Saville8eb2a122012-11-19 16:05:13 -08003655 RLOGI("RIL Daemon version: %s\n", version);
Wink Saville7f856802009-06-09 10:23:37 -07003656
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003657 property_set(PROPERTY_RIL_IMPL, version);
3658 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003659 RLOGI("RIL Daemon version: unavailable\n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003660 property_set(PROPERTY_RIL_IMPL, "unavailable");
3661 }
3662
3663}
3664
Wink Savillef4c4d362009-04-02 01:37:03 -07003665static void listenCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003666 int ret;
3667 int err;
3668 int is_phone_socket;
Etan Cohend3652192014-06-20 08:28:44 -07003669 int fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003670 RecordStream *p_rs;
Etan Cohend3652192014-06-20 08:28:44 -07003671 SocketListenParam *p_info = (SocketListenParam *)param;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003672
3673 struct sockaddr_un peeraddr;
3674 socklen_t socklen = sizeof (peeraddr);
3675
3676 struct ucred creds;
3677 socklen_t szCreds = sizeof(creds);
3678
3679 struct passwd *pwd = NULL;
3680
Etan Cohend3652192014-06-20 08:28:44 -07003681 assert (*p_info->fdCommand < 0);
3682 assert (fd == *p_info->fdListen);
Wink Saville7f856802009-06-09 10:23:37 -07003683
Etan Cohend3652192014-06-20 08:28:44 -07003684 fdCommand = accept(fd, (sockaddr *) &peeraddr, &socklen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003685
Etan Cohend3652192014-06-20 08:28:44 -07003686 if (fdCommand < 0 ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003687 RLOGE("Error on accept() errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003688 /* start listening for new connections again */
Etan Cohend3652192014-06-20 08:28:44 -07003689 rilEventAddWakeup(p_info->listen_event);
3690 return;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003691 }
3692
3693 /* check the credential of the other side and only accept socket from
3694 * phone process
Wink Saville7f856802009-06-09 10:23:37 -07003695 */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003696 errno = 0;
3697 is_phone_socket = 0;
Wink Savillef4c4d362009-04-02 01:37:03 -07003698
Etan Cohend3652192014-06-20 08:28:44 -07003699 err = getsockopt(fdCommand, SOL_SOCKET, SO_PEERCRED, &creds, &szCreds);
Wink Savillef4c4d362009-04-02 01:37:03 -07003700
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003701 if (err == 0 && szCreds > 0) {
Wink Savillef4c4d362009-04-02 01:37:03 -07003702 errno = 0;
3703 pwd = getpwuid(creds.uid);
3704 if (pwd != NULL) {
Etan Cohend3652192014-06-20 08:28:44 -07003705 if (strcmp(pwd->pw_name, p_info->processName) == 0) {
Wink Savillef4c4d362009-04-02 01:37:03 -07003706 is_phone_socket = 1;
3707 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003708 RLOGE("RILD can't accept socket from process %s", pwd->pw_name);
Wink Savillef4c4d362009-04-02 01:37:03 -07003709 }
3710 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003711 RLOGE("Error on getpwuid() errno: %d", errno);
Wink Savillef4c4d362009-04-02 01:37:03 -07003712 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003713 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003714 RLOGD("Error on getsockopt() errno: %d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003715 }
3716
Etan Cohend3652192014-06-20 08:28:44 -07003717 if (!is_phone_socket) {
3718 RLOGE("RILD must accept socket from %s", p_info->processName);
Wink Saville7f856802009-06-09 10:23:37 -07003719
Etan Cohend3652192014-06-20 08:28:44 -07003720 close(fdCommand);
3721 fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003722
Etan Cohend3652192014-06-20 08:28:44 -07003723 onCommandsSocketClosed(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003724
3725 /* start listening for new connections again */
Etan Cohend3652192014-06-20 08:28:44 -07003726 rilEventAddWakeup(p_info->listen_event);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003727
3728 return;
3729 }
3730
Etan Cohend3652192014-06-20 08:28:44 -07003731 ret = fcntl(fdCommand, F_SETFL, O_NONBLOCK);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003732
3733 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003734 RLOGE ("Error setting O_NONBLOCK errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003735 }
3736
Etan Cohend3652192014-06-20 08:28:44 -07003737 RLOGI("libril: new connection to %s", rilSocketIdToString(p_info->socket_id));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003738
Etan Cohend3652192014-06-20 08:28:44 -07003739 p_info->fdCommand = fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003740
Etan Cohend3652192014-06-20 08:28:44 -07003741 p_rs = record_stream_new(p_info->fdCommand, MAX_COMMAND_BYTES);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003742
Etan Cohend3652192014-06-20 08:28:44 -07003743 p_info->p_rs = p_rs;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003744
Etan Cohend3652192014-06-20 08:28:44 -07003745 ril_event_set (p_info->commands_event, p_info->fdCommand, 1,
3746 p_info->processCommandsCallback, p_info);
3747
3748 rilEventAddWakeup (p_info->commands_event);
3749
3750 onNewCommandConnect(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003751}
3752
3753static void freeDebugCallbackArgs(int number, char **args) {
3754 for (int i = 0; i < number; i++) {
3755 if (args[i] != NULL) {
3756 free(args[i]);
3757 }
3758 }
3759 free(args);
3760}
3761
Wink Savillef4c4d362009-04-02 01:37:03 -07003762static void debugCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003763 int acceptFD, option;
3764 struct sockaddr_un peeraddr;
3765 socklen_t socklen = sizeof (peeraddr);
3766 int data;
3767 unsigned int qxdm_data[6];
3768 const char *deactData[1] = {"1"};
3769 char *actData[1];
3770 RIL_Dial dialData;
3771 int hangupData[1] = {1};
3772 int number;
3773 char **args;
Etan Cohend3652192014-06-20 08:28:44 -07003774 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
3775 int sim_id = 0;
3776
3777 RLOGI("debugCallback for socket %s", rilSocketIdToString(socket_id));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003778
3779 acceptFD = accept (fd, (sockaddr *) &peeraddr, &socklen);
3780
3781 if (acceptFD < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003782 RLOGE ("error accepting on debug port: %d\n", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003783 return;
3784 }
3785
3786 if (recv(acceptFD, &number, sizeof(int), 0) != sizeof(int)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003787 RLOGE ("error reading on socket: number of Args: \n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003788 return;
3789 }
3790 args = (char **) malloc(sizeof(char*) * number);
3791
3792 for (int i = 0; i < number; i++) {
3793 int len;
3794 if (recv(acceptFD, &len, sizeof(int), 0) != sizeof(int)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003795 RLOGE ("error reading on socket: Len of Args: \n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003796 freeDebugCallbackArgs(i, args);
3797 return;
3798 }
3799 // +1 for null-term
3800 args[i] = (char *) malloc((sizeof(char) * len) + 1);
Wink Saville7f856802009-06-09 10:23:37 -07003801 if (recv(acceptFD, args[i], sizeof(char) * len, 0)
Wink Saville1b5fd232009-04-22 14:50:00 -07003802 != (int)sizeof(char) * len) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003803 RLOGE ("error reading on socket: Args[%d] \n", i);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003804 freeDebugCallbackArgs(i, args);
3805 return;
3806 }
3807 char * buf = args[i];
3808 buf[len] = 0;
Etan Cohend3652192014-06-20 08:28:44 -07003809 if ((i+1) == number) {
3810 /* The last argument should be sim id 0(SIM1)~3(SIM4) */
3811 sim_id = atoi(args[i]);
3812 switch (sim_id) {
3813 case 0:
3814 socket_id = RIL_SOCKET_1;
3815 break;
3816 #if (SIM_COUNT >= 2)
3817 case 1:
3818 socket_id = RIL_SOCKET_2;
3819 break;
3820 #endif
3821 #if (SIM_COUNT >= 3)
3822 case 2:
3823 socket_id = RIL_SOCKET_3;
3824 break;
3825 #endif
3826 #if (SIM_COUNT >= 4)
3827 case 3:
3828 socket_id = RIL_SOCKET_4;
3829 break;
3830 #endif
3831 default:
3832 socket_id = RIL_SOCKET_1;
3833 break;
3834 }
3835 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003836 }
3837
3838 switch (atoi(args[0])) {
3839 case 0:
Wink Saville8eb2a122012-11-19 16:05:13 -08003840 RLOGI ("Connection on debug port: issuing reset.");
Etan Cohend3652192014-06-20 08:28:44 -07003841 issueLocalRequest(RIL_REQUEST_RESET_RADIO, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003842 break;
3843 case 1:
Wink Saville8eb2a122012-11-19 16:05:13 -08003844 RLOGI ("Connection on debug port: issuing radio power off.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003845 data = 0;
Etan Cohend3652192014-06-20 08:28:44 -07003846 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003847 // Close the socket
Etan Cohend3652192014-06-20 08:28:44 -07003848 if (socket_id == RIL_SOCKET_1 && s_ril_param_socket.fdCommand > 0) {
3849 close(s_ril_param_socket.fdCommand);
3850 s_ril_param_socket.fdCommand = -1;
3851 }
3852 #if (SIM_COUNT == 2)
3853 else if (socket_id == RIL_SOCKET_2 && s_ril_param_socket2.fdCommand > 0) {
3854 close(s_ril_param_socket2.fdCommand);
3855 s_ril_param_socket2.fdCommand = -1;
3856 }
3857 #endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003858 break;
3859 case 2:
Wink Saville8eb2a122012-11-19 16:05:13 -08003860 RLOGI ("Debug port: issuing unsolicited voice network change.");
Etan Cohend3652192014-06-20 08:28:44 -07003861 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003862 break;
3863 case 3:
Wink Saville8eb2a122012-11-19 16:05:13 -08003864 RLOGI ("Debug port: QXDM log enable.");
Xia Wangd855ef42010-07-27 17:26:55 -07003865 qxdm_data[0] = 65536; // head.func_tag
3866 qxdm_data[1] = 16; // head.len
3867 qxdm_data[2] = 1; // mode: 1 for 'start logging'
3868 qxdm_data[3] = 32; // log_file_size: 32megabytes
3869 qxdm_data[4] = 0; // log_mask
3870 qxdm_data[5] = 8; // log_max_fileindex
Wink Saville7f856802009-06-09 10:23:37 -07003871 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Etan Cohend3652192014-06-20 08:28:44 -07003872 6 * sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003873 break;
3874 case 4:
Wink Saville8eb2a122012-11-19 16:05:13 -08003875 RLOGI ("Debug port: QXDM log disable.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003876 qxdm_data[0] = 65536;
3877 qxdm_data[1] = 16;
Xia Wangd855ef42010-07-27 17:26:55 -07003878 qxdm_data[2] = 0; // mode: 0 for 'stop logging'
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003879 qxdm_data[3] = 32;
3880 qxdm_data[4] = 0;
Xia Wangd855ef42010-07-27 17:26:55 -07003881 qxdm_data[5] = 8;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003882 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Etan Cohend3652192014-06-20 08:28:44 -07003883 6 * sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003884 break;
3885 case 5:
Wink Saville8eb2a122012-11-19 16:05:13 -08003886 RLOGI("Debug port: Radio On");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003887 data = 1;
Etan Cohend3652192014-06-20 08:28:44 -07003888 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003889 sleep(2);
3890 // Set network selection automatic.
Etan Cohend3652192014-06-20 08:28:44 -07003891 issueLocalRequest(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003892 break;
3893 case 6:
Wink Saville8eb2a122012-11-19 16:05:13 -08003894 RLOGI("Debug port: Setup Data Call, Apn :%s\n", args[1]);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003895 actData[0] = args[1];
Wink Saville7f856802009-06-09 10:23:37 -07003896 issueLocalRequest(RIL_REQUEST_SETUP_DATA_CALL, &actData,
Etan Cohend3652192014-06-20 08:28:44 -07003897 sizeof(actData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003898 break;
3899 case 7:
Wink Saville8eb2a122012-11-19 16:05:13 -08003900 RLOGI("Debug port: Deactivate Data Call");
Wink Saville7f856802009-06-09 10:23:37 -07003901 issueLocalRequest(RIL_REQUEST_DEACTIVATE_DATA_CALL, &deactData,
Etan Cohend3652192014-06-20 08:28:44 -07003902 sizeof(deactData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003903 break;
3904 case 8:
Wink Saville8eb2a122012-11-19 16:05:13 -08003905 RLOGI("Debug port: Dial Call");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003906 dialData.clir = 0;
3907 dialData.address = args[1];
Etan Cohend3652192014-06-20 08:28:44 -07003908 issueLocalRequest(RIL_REQUEST_DIAL, &dialData, sizeof(dialData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003909 break;
3910 case 9:
Wink Saville8eb2a122012-11-19 16:05:13 -08003911 RLOGI("Debug port: Answer Call");
Etan Cohend3652192014-06-20 08:28:44 -07003912 issueLocalRequest(RIL_REQUEST_ANSWER, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003913 break;
3914 case 10:
Wink Saville8eb2a122012-11-19 16:05:13 -08003915 RLOGI("Debug port: End Call");
Wink Saville7f856802009-06-09 10:23:37 -07003916 issueLocalRequest(RIL_REQUEST_HANGUP, &hangupData,
Etan Cohend3652192014-06-20 08:28:44 -07003917 sizeof(hangupData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003918 break;
3919 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08003920 RLOGE ("Invalid request");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003921 break;
3922 }
3923 freeDebugCallbackArgs(number, args);
3924 close(acceptFD);
3925}
3926
3927
Wink Savillef4c4d362009-04-02 01:37:03 -07003928static void userTimerCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003929 UserCallbackInfo *p_info;
3930
3931 p_info = (UserCallbackInfo *)param;
3932
3933 p_info->p_callback(p_info->userParam);
3934
3935
3936 // FIXME generalize this...there should be a cancel mechanism
3937 if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) {
3938 s_last_wake_timeout_info = NULL;
3939 }
3940
3941 free(p_info);
3942}
3943
3944
3945static void *
Wink Savillef4c4d362009-04-02 01:37:03 -07003946eventLoop(void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003947 int ret;
3948 int filedes[2];
3949
3950 ril_event_init();
3951
3952 pthread_mutex_lock(&s_startupMutex);
3953
3954 s_started = 1;
3955 pthread_cond_broadcast(&s_startupCond);
3956
3957 pthread_mutex_unlock(&s_startupMutex);
3958
3959 ret = pipe(filedes);
3960
3961 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003962 RLOGE("Error in pipe() errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003963 return NULL;
3964 }
3965
3966 s_fdWakeupRead = filedes[0];
3967 s_fdWakeupWrite = filedes[1];
3968
3969 fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK);
3970
3971 ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,
3972 processWakeupCallback, NULL);
3973
3974 rilEventAddWakeup (&s_wakeupfd_event);
3975
3976 // Only returns on error
3977 ril_event_loop();
Wink Saville8eb2a122012-11-19 16:05:13 -08003978 RLOGE ("error in event_loop_base errno:%d", errno);
Kazuhiro Ondo5cdc1352011-10-14 17:50:58 -05003979 // kill self to restart on error
3980 kill(0, SIGKILL);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003981
3982 return NULL;
3983}
3984
Wink Saville7f856802009-06-09 10:23:37 -07003985extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07003986RIL_startEventLoop(void) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003987 /* spin up eventLoop thread and wait for it to get started */
3988 s_started = 0;
3989 pthread_mutex_lock(&s_startupMutex);
3990
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08003991 pthread_attr_t attr;
3992 pthread_attr_init(&attr);
Wink Saville7f856802009-06-09 10:23:37 -07003993 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08003994
Elliott Hughesfd81e712014-01-06 12:46:02 -08003995 int result = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
3996 if (result != 0) {
3997 RLOGE("Failed to create dispatch thread: %s", strerror(result));
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08003998 goto done;
3999 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004000
4001 while (s_started == 0) {
4002 pthread_cond_wait(&s_startupCond, &s_startupMutex);
4003 }
4004
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004005done:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004006 pthread_mutex_unlock(&s_startupMutex);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004007}
4008
4009// Used for testing purpose only.
4010extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) {
4011 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4012}
4013
Etan Cohend3652192014-06-20 08:28:44 -07004014static void startListen(RIL_SOCKET_ID socket_id, SocketListenParam* socket_listen_p) {
4015 int fdListen = -1;
4016 int ret;
4017 char socket_name[10];
4018
4019 memset(socket_name, 0, sizeof(char)*10);
4020
4021 switch(socket_id) {
4022 case RIL_SOCKET_1:
4023 strncpy(socket_name, RIL_getRilSocketName(), 9);
4024 break;
4025 #if (SIM_COUNT >= 2)
4026 case RIL_SOCKET_2:
4027 strncpy(socket_name, SOCKET2_NAME_RIL, 9);
4028 break;
4029 #endif
4030 #if (SIM_COUNT >= 3)
4031 case RIL_SOCKET_3:
4032 strncpy(socket_name, SOCKET3_NAME_RIL, 9);
4033 break;
4034 #endif
4035 #if (SIM_COUNT >= 4)
4036 case RIL_SOCKET_4:
4037 strncpy(socket_name, SOCKET4_NAME_RIL, 9);
4038 break;
4039 #endif
4040 default:
4041 RLOGE("Socket id is wrong!!");
4042 return;
4043 }
4044
4045 RLOGI("Start to listen %s", rilSocketIdToString(socket_id));
4046
4047 fdListen = android_get_control_socket(socket_name);
4048 if (fdListen < 0) {
4049 RLOGE("Failed to get socket %s", socket_name);
4050 exit(-1);
4051 }
4052
4053 ret = listen(fdListen, 4);
4054
4055 if (ret < 0) {
4056 RLOGE("Failed to listen on control socket '%d': %s",
4057 fdListen, strerror(errno));
4058 exit(-1);
4059 }
4060 socket_listen_p->fdListen = fdListen;
4061
4062 /* note: non-persistent so we can accept only one connection at a time */
4063 ril_event_set (socket_listen_p->listen_event, fdListen, false,
4064 listenCallback, socket_listen_p);
4065
4066 rilEventAddWakeup (socket_listen_p->listen_event);
4067}
4068
Wink Saville7f856802009-06-09 10:23:37 -07004069extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07004070RIL_register (const RIL_RadioFunctions *callbacks) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004071 int ret;
4072 int flags;
4073
Etan Cohend3652192014-06-20 08:28:44 -07004074 RLOGI("SIM_COUNT: %d", SIM_COUNT);
4075
Wink Saville43808972011-01-13 17:39:51 -08004076 if (callbacks == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004077 RLOGE("RIL_register: RIL_RadioFunctions * null");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004078 return;
4079 }
Wink Saville43808972011-01-13 17:39:51 -08004080 if (callbacks->version < RIL_VERSION_MIN) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004081 RLOGE("RIL_register: version %d is to old, min version is %d",
Wink Saville43808972011-01-13 17:39:51 -08004082 callbacks->version, RIL_VERSION_MIN);
4083 return;
Wink Saville3a4840b2010-04-07 13:29:58 -07004084 }
Wink Saville43808972011-01-13 17:39:51 -08004085 if (callbacks->version > RIL_VERSION) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004086 RLOGE("RIL_register: version %d is too new, max version is %d",
Wink Saville43808972011-01-13 17:39:51 -08004087 callbacks->version, RIL_VERSION);
4088 return;
4089 }
Wink Saville8eb2a122012-11-19 16:05:13 -08004090 RLOGE("RIL_register: RIL version %d", callbacks->version);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004091
4092 if (s_registerCalled > 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004093 RLOGE("RIL_register has been called more than once. "
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004094 "Subsequent call ignored");
4095 return;
4096 }
4097
4098 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4099
Etan Cohend3652192014-06-20 08:28:44 -07004100 /* Initialize socket1 parameters */
4101 s_ril_param_socket = {
4102 RIL_SOCKET_1, /* socket_id */
4103 -1, /* fdListen */
4104 -1, /* fdCommand */
4105 PHONE_PROCESS, /* processName */
4106 &s_commands_event, /* commands_event */
4107 &s_listen_event, /* listen_event */
4108 processCommandsCallback, /* processCommandsCallback */
4109 NULL /* p_rs */
4110 };
4111
4112#if (SIM_COUNT >= 2)
4113 s_ril_param_socket2 = {
4114 RIL_SOCKET_2, /* socket_id */
4115 -1, /* fdListen */
4116 -1, /* fdCommand */
4117 PHONE_PROCESS, /* processName */
4118 &s_commands_event_socket2, /* commands_event */
4119 &s_listen_event_socket2, /* listen_event */
4120 processCommandsCallback, /* processCommandsCallback */
4121 NULL /* p_rs */
4122 };
4123#endif
4124
4125#if (SIM_COUNT >= 3)
4126 s_ril_param_socket3 = {
4127 RIL_SOCKET_3, /* socket_id */
4128 -1, /* fdListen */
4129 -1, /* fdCommand */
4130 PHONE_PROCESS, /* processName */
4131 &s_commands_event_socket3, /* commands_event */
4132 &s_listen_event_socket3, /* listen_event */
4133 processCommandsCallback, /* processCommandsCallback */
4134 NULL /* p_rs */
4135 };
4136#endif
4137
4138#if (SIM_COUNT >= 4)
4139 s_ril_param_socket4 = {
4140 RIL_SOCKET_4, /* socket_id */
4141 -1, /* fdListen */
4142 -1, /* fdCommand */
4143 PHONE_PROCESS, /* processName */
4144 &s_commands_event_socket4, /* commands_event */
4145 &s_listen_event_socket4, /* listen_event */
4146 processCommandsCallback, /* processCommandsCallback */
4147 NULL /* p_rs */
4148 };
4149#endif
4150
4151
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004152 s_registerCalled = 1;
4153
Etan Cohend3652192014-06-20 08:28:44 -07004154 RLOGI("s_registerCalled flag set, %d", s_started);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004155 // Little self-check
4156
Wink Savillef4c4d362009-04-02 01:37:03 -07004157 for (int i = 0; i < (int)NUM_ELEMS(s_commands); i++) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004158 assert(i == s_commands[i].requestNumber);
4159 }
4160
Wink Savillef4c4d362009-04-02 01:37:03 -07004161 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses); i++) {
Wink Saville7f856802009-06-09 10:23:37 -07004162 assert(i + RIL_UNSOL_RESPONSE_BASE
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004163 == s_unsolResponses[i].requestNumber);
4164 }
4165
4166 // New rild impl calls RIL_startEventLoop() first
4167 // old standalone impl wants it here.
4168
4169 if (s_started == 0) {
4170 RIL_startEventLoop();
4171 }
4172
Etan Cohend3652192014-06-20 08:28:44 -07004173 // start listen socket1
4174 startListen(RIL_SOCKET_1, &s_ril_param_socket);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004175
Etan Cohend3652192014-06-20 08:28:44 -07004176#if (SIM_COUNT >= 2)
4177 // start listen socket2
4178 startListen(RIL_SOCKET_2, &s_ril_param_socket2);
4179#endif /* (SIM_COUNT == 2) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004180
Etan Cohend3652192014-06-20 08:28:44 -07004181#if (SIM_COUNT >= 3)
4182 // start listen socket3
4183 startListen(RIL_SOCKET_3, &s_ril_param_socket3);
4184#endif /* (SIM_COUNT == 3) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004185
Etan Cohend3652192014-06-20 08:28:44 -07004186#if (SIM_COUNT >= 4)
4187 // start listen socket4
4188 startListen(RIL_SOCKET_4, &s_ril_param_socket4);
4189#endif /* (SIM_COUNT == 4) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004190
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004191
4192#if 1
4193 // start debug interface socket
4194
Etan Cohend3652192014-06-20 08:28:44 -07004195 char *inst = NULL;
4196 if (strlen(RIL_getRilSocketName()) >= strlen(SOCKET_NAME_RIL)) {
4197 inst = RIL_getRilSocketName() + strlen(SOCKET_NAME_RIL);
4198 }
4199
4200 char rildebug[MAX_DEBUG_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL_DEBUG;
4201 if (inst != NULL) {
4202 strncat(rildebug, inst, MAX_DEBUG_SOCKET_NAME_LENGTH);
4203 }
4204
4205 s_fdDebug = android_get_control_socket(rildebug);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004206 if (s_fdDebug < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07004207 RLOGE("Failed to get socket : %s errno:%d", rildebug, errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004208 exit(-1);
4209 }
4210
4211 ret = listen(s_fdDebug, 4);
4212
4213 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004214 RLOGE("Failed to listen on ril debug socket '%d': %s",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004215 s_fdDebug, strerror(errno));
4216 exit(-1);
4217 }
4218
4219 ril_event_set (&s_debug_event, s_fdDebug, true,
4220 debugCallback, NULL);
4221
4222 rilEventAddWakeup (&s_debug_event);
4223#endif
4224
4225}
4226
4227static int
Wink Savillef4c4d362009-04-02 01:37:03 -07004228checkAndDequeueRequestInfo(struct RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004229 int ret = 0;
Etan Cohend3652192014-06-20 08:28:44 -07004230 /* Hook for current context
4231 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
4232 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
4233 /* pendingRequestsHook refer to &s_pendingRequests */
4234 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
Wink Saville7f856802009-06-09 10:23:37 -07004235
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004236 if (pRI == NULL) {
4237 return 0;
4238 }
4239
Etan Cohend3652192014-06-20 08:28:44 -07004240#if (SIM_COUNT >= 2)
4241 if (pRI->socket_id == RIL_SOCKET_2) {
4242 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
4243 pendingRequestsHook = &s_pendingRequests_socket2;
4244 }
4245#if (SIM_COUNT >= 3)
4246 if (pRI->socket_id == RIL_SOCKET_3) {
4247 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
4248 pendingRequestsHook = &s_pendingRequests_socket3;
4249 }
4250#endif
4251#if (SIM_COUNT >= 4)
4252 if (pRI->socket_id == RIL_SOCKET_4) {
4253 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
4254 pendingRequestsHook = &s_pendingRequests_socket4;
4255 }
4256#endif
4257#endif
4258 pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004259
Etan Cohend3652192014-06-20 08:28:44 -07004260 for(RequestInfo **ppCur = pendingRequestsHook
Wink Saville7f856802009-06-09 10:23:37 -07004261 ; *ppCur != NULL
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004262 ; ppCur = &((*ppCur)->p_next)
4263 ) {
4264 if (pRI == *ppCur) {
4265 ret = 1;
4266
4267 *ppCur = (*ppCur)->p_next;
4268 break;
4269 }
4270 }
4271
Etan Cohend3652192014-06-20 08:28:44 -07004272 pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004273
4274 return ret;
4275}
4276
4277
4278extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07004279RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004280 RequestInfo *pRI;
4281 int ret;
Etan Cohend3652192014-06-20 08:28:44 -07004282 int fd = s_ril_param_socket.fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004283 size_t errorOffset;
Etan Cohend3652192014-06-20 08:28:44 -07004284 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004285
4286 pRI = (RequestInfo *)t;
4287
Jayachandran C6c607592014-08-04 15:48:01 -07004288 if (!checkAndDequeueRequestInfo(pRI)) {
4289 RLOGE ("RIL_onRequestComplete: invalid RIL_Token");
4290 return;
4291 }
4292
Etan Cohend3652192014-06-20 08:28:44 -07004293 socket_id = pRI->socket_id;
4294#if (SIM_COUNT >= 2)
4295 if (socket_id == RIL_SOCKET_2) {
4296 fd = s_ril_param_socket2.fdCommand;
4297 }
4298#if (SIM_COUNT >= 3)
4299 if (socket_id == RIL_SOCKET_3) {
4300 fd = s_ril_param_socket3.fdCommand;
4301 }
4302#endif
4303#if (SIM_COUNT >= 4)
4304 if (socket_id == RIL_SOCKET_4) {
4305 fd = s_ril_param_socket4.fdCommand;
4306 }
4307#endif
4308#endif
4309 RLOGD("RequestComplete, %s", rilSocketIdToString(socket_id));
4310
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004311 if (pRI->local > 0) {
4312 // Locally issued command...void only!
4313 // response does not go back up the command socket
Wink Saville8eb2a122012-11-19 16:05:13 -08004314 RLOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004315
4316 goto done;
4317 }
4318
4319 appendPrintBuf("[%04d]< %s",
4320 pRI->token, requestToString(pRI->pCI->requestNumber));
4321
4322 if (pRI->cancelled == 0) {
4323 Parcel p;
4324
4325 p.writeInt32 (RESPONSE_SOLICITED);
4326 p.writeInt32 (pRI->token);
4327 errorOffset = p.dataPosition();
4328
4329 p.writeInt32 (e);
4330
johnwangb2a61842009-06-02 14:55:45 -07004331 if (response != NULL) {
4332 // there is a response payload, no matter success or not.
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004333 ret = pRI->pCI->responseFunction(p, response, responselen);
4334
4335 /* if an error occurred, rewind and mark it */
4336 if (ret != 0) {
Etan Cohend3652192014-06-20 08:28:44 -07004337 RLOGE ("responseFunction error, ret %d", ret);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004338 p.setDataPosition(errorOffset);
4339 p.writeInt32 (ret);
4340 }
johnwangb2a61842009-06-02 14:55:45 -07004341 }
4342
4343 if (e != RIL_E_SUCCESS) {
4344 appendPrintBuf("%s fails by %s", printBuf, failCauseToString(e));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004345 }
4346
Etan Cohend3652192014-06-20 08:28:44 -07004347 if (fd < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004348 RLOGD ("RIL onRequestComplete: Command channel closed");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004349 }
Etan Cohend3652192014-06-20 08:28:44 -07004350 sendResponse(p, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004351 }
4352
4353done:
4354 free(pRI);
4355}
4356
4357
4358static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004359grabPartialWakeLock() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004360 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
4361}
4362
4363static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004364releaseWakeLock() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004365 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
4366}
4367
4368/**
4369 * Timer callback to put us back to sleep before the default timeout
4370 */
4371static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004372wakeTimeoutCallback (void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004373 // We're using "param != NULL" as a cancellation mechanism
4374 if (param == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004375 //RLOGD("wakeTimeout: releasing wake lock");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004376
4377 releaseWakeLock();
4378 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08004379 //RLOGD("wakeTimeout: releasing wake lock CANCELLED");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004380 }
4381}
4382
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004383static int
4384decodeVoiceRadioTechnology (RIL_RadioState radioState) {
4385 switch (radioState) {
4386 case RADIO_STATE_SIM_NOT_READY:
4387 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4388 case RADIO_STATE_SIM_READY:
4389 return RADIO_TECH_UMTS;
4390
4391 case RADIO_STATE_RUIM_NOT_READY:
4392 case RADIO_STATE_RUIM_READY:
4393 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4394 case RADIO_STATE_NV_NOT_READY:
4395 case RADIO_STATE_NV_READY:
4396 return RADIO_TECH_1xRTT;
4397
4398 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004399 RLOGD("decodeVoiceRadioTechnology: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004400 return -1;
4401 }
4402}
4403
4404static int
4405decodeCdmaSubscriptionSource (RIL_RadioState radioState) {
4406 switch (radioState) {
4407 case RADIO_STATE_SIM_NOT_READY:
4408 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4409 case RADIO_STATE_SIM_READY:
4410 case RADIO_STATE_RUIM_NOT_READY:
4411 case RADIO_STATE_RUIM_READY:
4412 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4413 return CDMA_SUBSCRIPTION_SOURCE_RUIM_SIM;
4414
4415 case RADIO_STATE_NV_NOT_READY:
4416 case RADIO_STATE_NV_READY:
4417 return CDMA_SUBSCRIPTION_SOURCE_NV;
4418
4419 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004420 RLOGD("decodeCdmaSubscriptionSource: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004421 return -1;
4422 }
4423}
4424
4425static int
4426decodeSimStatus (RIL_RadioState radioState) {
4427 switch (radioState) {
4428 case RADIO_STATE_SIM_NOT_READY:
4429 case RADIO_STATE_RUIM_NOT_READY:
4430 case RADIO_STATE_NV_NOT_READY:
4431 case RADIO_STATE_NV_READY:
4432 return -1;
4433 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4434 case RADIO_STATE_SIM_READY:
4435 case RADIO_STATE_RUIM_READY:
4436 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4437 return radioState;
4438 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004439 RLOGD("decodeSimStatus: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004440 return -1;
4441 }
4442}
4443
4444static bool is3gpp2(int radioTech) {
4445 switch (radioTech) {
4446 case RADIO_TECH_IS95A:
4447 case RADIO_TECH_IS95B:
4448 case RADIO_TECH_1xRTT:
4449 case RADIO_TECH_EVDO_0:
4450 case RADIO_TECH_EVDO_A:
4451 case RADIO_TECH_EVDO_B:
4452 case RADIO_TECH_EHRPD:
4453 return true;
4454 default:
4455 return false;
4456 }
4457}
4458
4459/* If RIL sends SIM states or RUIM states, store the voice radio
4460 * technology and subscription source information so that they can be
4461 * returned when telephony framework requests them
4462 */
4463static RIL_RadioState
Etan Cohend3652192014-06-20 08:28:44 -07004464processRadioState(RIL_RadioState newRadioState, RIL_SOCKET_ID socket_id) {
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004465
4466 if((newRadioState > RADIO_STATE_UNAVAILABLE) && (newRadioState < RADIO_STATE_ON)) {
4467 int newVoiceRadioTech;
4468 int newCdmaSubscriptionSource;
4469 int newSimStatus;
4470
4471 /* This is old RIL. Decode Subscription source and Voice Radio Technology
4472 from Radio State and send change notifications if there has been a change */
4473 newVoiceRadioTech = decodeVoiceRadioTechnology(newRadioState);
4474 if(newVoiceRadioTech != voiceRadioTech) {
4475 voiceRadioTech = newVoiceRadioTech;
Etan Cohend3652192014-06-20 08:28:44 -07004476 RIL_UNSOL_RESPONSE(RIL_UNSOL_VOICE_RADIO_TECH_CHANGED,
4477 &voiceRadioTech, sizeof(voiceRadioTech), socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004478 }
4479 if(is3gpp2(newVoiceRadioTech)) {
4480 newCdmaSubscriptionSource = decodeCdmaSubscriptionSource(newRadioState);
4481 if(newCdmaSubscriptionSource != cdmaSubscriptionSource) {
4482 cdmaSubscriptionSource = newCdmaSubscriptionSource;
Etan Cohend3652192014-06-20 08:28:44 -07004483 RIL_UNSOL_RESPONSE(RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED,
4484 &cdmaSubscriptionSource, sizeof(cdmaSubscriptionSource), socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004485 }
4486 }
4487 newSimStatus = decodeSimStatus(newRadioState);
4488 if(newSimStatus != simRuimStatus) {
4489 simRuimStatus = newSimStatus;
Etan Cohend3652192014-06-20 08:28:44 -07004490 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0, socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004491 }
4492
4493 /* Send RADIO_ON to telephony */
4494 newRadioState = RADIO_STATE_ON;
4495 }
4496
4497 return newRadioState;
4498}
4499
Etan Cohend3652192014-06-20 08:28:44 -07004500
4501#if defined(ANDROID_MULTI_SIM)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004502extern "C"
Etan Cohend3652192014-06-20 08:28:44 -07004503void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
4504 size_t datalen, RIL_SOCKET_ID socket_id)
4505#else
4506extern "C"
4507void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004508 size_t datalen)
Etan Cohend3652192014-06-20 08:28:44 -07004509#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004510{
4511 int unsolResponseIndex;
4512 int ret;
4513 int64_t timeReceived = 0;
4514 bool shouldScheduleTimeout = false;
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004515 RIL_RadioState newState;
Etan Cohend3652192014-06-20 08:28:44 -07004516 RIL_SOCKET_ID soc_id = RIL_SOCKET_1;
4517
4518#if defined(ANDROID_MULTI_SIM)
4519 soc_id = socket_id;
4520#endif
4521
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004522
4523 if (s_registerCalled == 0) {
4524 // Ignore RIL_onUnsolicitedResponse before RIL_register
Wink Saville8eb2a122012-11-19 16:05:13 -08004525 RLOGW("RIL_onUnsolicitedResponse called before RIL_register");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004526 return;
4527 }
Wink Saville7f856802009-06-09 10:23:37 -07004528
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004529 unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
4530
4531 if ((unsolResponseIndex < 0)
4532 || (unsolResponseIndex >= (int32_t)NUM_ELEMS(s_unsolResponses))) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004533 RLOGE("unsupported unsolicited response code %d", unsolResponse);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004534 return;
4535 }
4536
4537 // Grab a wake lock if needed for this reponse,
4538 // as we exit we'll either release it immediately
4539 // or set a timer to release it later.
4540 switch (s_unsolResponses[unsolResponseIndex].wakeType) {
4541 case WAKE_PARTIAL:
4542 grabPartialWakeLock();
4543 shouldScheduleTimeout = true;
4544 break;
4545
4546 case DONT_WAKE:
4547 default:
4548 // No wake lock is grabed so don't set timeout
4549 shouldScheduleTimeout = false;
4550 break;
4551 }
4552
4553 // Mark the time this was received, doing this
4554 // after grabing the wakelock incase getting
4555 // the elapsedRealTime might cause us to goto
4556 // sleep.
4557 if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4558 timeReceived = elapsedRealtime();
4559 }
4560
4561 appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
4562
4563 Parcel p;
4564
4565 p.writeInt32 (RESPONSE_UNSOLICITED);
4566 p.writeInt32 (unsolResponse);
4567
4568 ret = s_unsolResponses[unsolResponseIndex]
Bernhard Rosenkränzer6e7c1962013-12-12 10:01:10 +01004569 .responseFunction(p, const_cast<void*>(data), datalen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004570 if (ret != 0) {
4571 // Problem with the response. Don't continue;
4572 goto error_exit;
4573 }
4574
4575 // some things get more payload
4576 switch(unsolResponse) {
4577 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
Etan Cohend3652192014-06-20 08:28:44 -07004578 newState = processRadioState(CALL_ONSTATEREQUEST(soc_id), soc_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004579 p.writeInt32(newState);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004580 appendPrintBuf("%s {%s}", printBuf,
Etan Cohend3652192014-06-20 08:28:44 -07004581 radioStateToString(CALL_ONSTATEREQUEST(soc_id)));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004582 break;
4583
4584
4585 case RIL_UNSOL_NITZ_TIME_RECEIVED:
4586 // Store the time that this was received so the
4587 // handler of this message can account for
4588 // the time it takes to arrive and process. In
4589 // particular the system has been known to sleep
4590 // before this message can be processed.
4591 p.writeInt64(timeReceived);
4592 break;
4593 }
4594
Etan Cohend3652192014-06-20 08:28:44 -07004595 RLOGI("%s UNSOLICITED: %s length:%d", rilSocketIdToString(soc_id), requestToString(unsolResponse), p.dataSize());
4596 ret = sendResponse(p, soc_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004597 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4598
4599 // Unfortunately, NITZ time is not poll/update like everything
4600 // else in the system. So, if the upstream client isn't connected,
4601 // keep a copy of the last NITZ response (with receive time noted
4602 // above) around so we can deliver it when it is connected
4603
4604 if (s_lastNITZTimeData != NULL) {
4605 free (s_lastNITZTimeData);
4606 s_lastNITZTimeData = NULL;
4607 }
4608
4609 s_lastNITZTimeData = malloc(p.dataSize());
4610 s_lastNITZTimeDataSize = p.dataSize();
4611 memcpy(s_lastNITZTimeData, p.data(), p.dataSize());
4612 }
4613
4614 // For now, we automatically go back to sleep after TIMEVAL_WAKE_TIMEOUT
4615 // FIXME The java code should handshake here to release wake lock
4616
4617 if (shouldScheduleTimeout) {
4618 // Cancel the previous request
4619 if (s_last_wake_timeout_info != NULL) {
4620 s_last_wake_timeout_info->userParam = (void *)1;
4621 }
4622
4623 s_last_wake_timeout_info
4624 = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
4625 &TIMEVAL_WAKE_TIMEOUT);
4626 }
4627
4628 // Normal exit
4629 return;
4630
4631error_exit:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004632 if (shouldScheduleTimeout) {
4633 releaseWakeLock();
4634 }
4635}
4636
Wink Saville7f856802009-06-09 10:23:37 -07004637/** FIXME generalize this if you track UserCAllbackInfo, clear it
4638 when the callback occurs
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004639*/
4640static UserCallbackInfo *
Wink Saville7f856802009-06-09 10:23:37 -07004641internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004642 const struct timeval *relativeTime)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004643{
4644 struct timeval myRelativeTime;
4645 UserCallbackInfo *p_info;
4646
4647 p_info = (UserCallbackInfo *) malloc (sizeof(UserCallbackInfo));
4648
Wink Saville7f856802009-06-09 10:23:37 -07004649 p_info->p_callback = callback;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004650 p_info->userParam = param;
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004651
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004652 if (relativeTime == NULL) {
4653 /* treat null parameter as a 0 relative time */
4654 memset (&myRelativeTime, 0, sizeof(myRelativeTime));
4655 } else {
4656 /* FIXME I think event_add's tv param is really const anyway */
4657 memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
4658 }
4659
4660 ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
4661
4662 ril_timer_add(&(p_info->event), &myRelativeTime);
4663
4664 triggerEvLoop();
4665 return p_info;
4666}
4667
Naveen Kalla7edd07c2010-06-21 18:54:47 -07004668
4669extern "C" void
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004670RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
4671 const struct timeval *relativeTime) {
4672 internalRequestTimedCallback (callback, param, relativeTime);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004673}
4674
4675const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004676failCauseToString(RIL_Errno e) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004677 switch(e) {
4678 case RIL_E_SUCCESS: return "E_SUCCESS";
Robert Greenwalt2126ab22013-04-09 12:20:45 -07004679 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RADIO_NOT_AVAILABLE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004680 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
4681 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
4682 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
4683 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
4684 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
4685 case RIL_E_CANCELLED: return "E_CANCELLED";
4686 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
4687 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
4688 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
Wink Savillef4c4d362009-04-02 01:37:03 -07004689 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
John Wang75534472010-04-20 15:11:42 -07004690 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
Wink Saville7f856802009-06-09 10:23:37 -07004691#ifdef FEATURE_MULTIMODE_ANDROID
Wink Savillef4c4d362009-04-02 01:37:03 -07004692 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
4693 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
4694#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004695 default: return "<unknown error>";
4696 }
4697}
4698
4699const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004700radioStateToString(RIL_RadioState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004701 switch(s) {
4702 case RADIO_STATE_OFF: return "RADIO_OFF";
4703 case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
4704 case RADIO_STATE_SIM_NOT_READY: return "RADIO_SIM_NOT_READY";
4705 case RADIO_STATE_SIM_LOCKED_OR_ABSENT: return "RADIO_SIM_LOCKED_OR_ABSENT";
4706 case RADIO_STATE_SIM_READY: return "RADIO_SIM_READY";
Wink Savillef4c4d362009-04-02 01:37:03 -07004707 case RADIO_STATE_RUIM_NOT_READY:return"RADIO_RUIM_NOT_READY";
4708 case RADIO_STATE_RUIM_READY:return"RADIO_RUIM_READY";
4709 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:return"RADIO_RUIM_LOCKED_OR_ABSENT";
4710 case RADIO_STATE_NV_NOT_READY:return"RADIO_NV_NOT_READY";
4711 case RADIO_STATE_NV_READY:return"RADIO_NV_READY";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004712 case RADIO_STATE_ON:return"RADIO_ON";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004713 default: return "<unknown state>";
4714 }
4715}
4716
4717const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004718callStateToString(RIL_CallState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004719 switch(s) {
4720 case RIL_CALL_ACTIVE : return "ACTIVE";
4721 case RIL_CALL_HOLDING: return "HOLDING";
4722 case RIL_CALL_DIALING: return "DIALING";
4723 case RIL_CALL_ALERTING: return "ALERTING";
4724 case RIL_CALL_INCOMING: return "INCOMING";
4725 case RIL_CALL_WAITING: return "WAITING";
4726 default: return "<unknown state>";
4727 }
4728}
4729
4730const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004731requestToString(int request) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004732/*
4733 cat libs/telephony/ril_commands.h \
4734 | egrep "^ *{RIL_" \
4735 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
4736
4737
4738 cat libs/telephony/ril_unsol_commands.h \
4739 | egrep "^ *{RIL_" \
4740 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
4741
4742*/
4743 switch(request) {
4744 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
4745 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
4746 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
4747 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
4748 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
4749 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
4750 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
Rakesh Pallerla215eed72013-10-28 16:42:49 +05304751 case RIL_REQUEST_ENTER_DEPERSONALIZATION_CODE: return "ENTER_DEPERSONALIZATION_CODE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004752 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
4753 case RIL_REQUEST_DIAL: return "DIAL";
4754 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
4755 case RIL_REQUEST_HANGUP: return "HANGUP";
4756 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
4757 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
4758 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
4759 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
4760 case RIL_REQUEST_UDUB: return "UDUB";
4761 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
4762 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
Wink Savillec0114b32011-02-18 10:14:07 -08004763 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
4764 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004765 case RIL_REQUEST_OPERATOR: return "OPERATOR";
4766 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
4767 case RIL_REQUEST_DTMF: return "DTMF";
4768 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
4769 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
Wink Savillef4c4d362009-04-02 01:37:03 -07004770 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004771 case RIL_REQUEST_SIM_IO: return "SIM_IO";
4772 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
4773 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
4774 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
4775 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
4776 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
4777 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
4778 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
4779 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
4780 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
4781 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
4782 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
4783 case RIL_REQUEST_ANSWER: return "ANSWER";
Wink Savillef4c4d362009-04-02 01:37:03 -07004784 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004785 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
4786 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
4787 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
4788 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
4789 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
4790 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
4791 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";
4792 case RIL_REQUEST_DTMF_START: return "DTMF_START";
4793 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
4794 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
4795 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
4796 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
4797 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
4798 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
4799 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
4800 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
4801 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
Wink Savillef4c4d362009-04-02 01:37:03 -07004802 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
4803 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004804 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
4805 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
4806 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
Wink Savillef4c4d362009-04-02 01:37:03 -07004807 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
4808 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004809 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
4810 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
4811 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
4812 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
4813 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
4814 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
4815 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
4816 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
Wink Savillec0114b32011-02-18 10:14:07 -08004817 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE:return"CDMA_SET_SUBSCRIPTION_SOURCE";
Wink Savillef4c4d362009-04-02 01:37:03 -07004818 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"CDMA_SET_ROAMING_PREFERENCE";
4819 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"CDMA_QUERY_ROAMING_PREFERENCE";
4820 case RIL_REQUEST_SET_TTY_MODE:return"SET_TTY_MODE";
4821 case RIL_REQUEST_QUERY_TTY_MODE:return"QUERY_TTY_MODE";
4822 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
4823 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
4824 case RIL_REQUEST_CDMA_FLASH:return"CDMA_FLASH";
4825 case RIL_REQUEST_CDMA_BURST_DTMF:return"CDMA_BURST_DTMF";
4826 case RIL_REQUEST_CDMA_SEND_SMS:return"CDMA_SEND_SMS";
4827 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:return"CDMA_SMS_ACKNOWLEDGE";
Wink Savillea592eeb2009-05-22 13:26:36 -07004828 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG:return"GSM_GET_BROADCAST_SMS_CONFIG";
4829 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG:return"GSM_SET_BROADCAST_SMS_CONFIG";
4830 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG:return "CDMA_GET_BROADCAST_SMS_CONFIG";
4831 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG:return "CDMA_SET_BROADCAST_SMS_CONFIG";
4832 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION:return "CDMA_SMS_BROADCAST_ACTIVATION";
Naveen Kalla03c1edf2009-09-23 11:18:35 -07004833 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return"CDMA_VALIDATE_AND_WRITE_AKEY";
Wink Savillef4c4d362009-04-02 01:37:03 -07004834 case RIL_REQUEST_CDMA_SUBSCRIPTION: return"CDMA_SUBSCRIPTION";
4835 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
4836 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
4837 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
jsh000a9fe2009-05-11 14:52:35 -07004838 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
4839 case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
4840 case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
jsh09a68ba2009-06-10 11:56:38 -07004841 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
jsh563fd722010-06-08 16:52:24 -07004842 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
Wink Savillec0114b32011-02-18 10:14:07 -08004843 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
Jake Hambyfa8d5842011-08-19 16:22:18 -07004844 case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
Jake Hamby300105d2011-09-26 01:01:44 -07004845 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
4846 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004847 case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
Naveen Kallac6e68722011-11-15 11:19:30 -08004848 case RIL_REQUEST_WRITE_SMS_TO_SIM: return "WRITE_SMS_TO_SIM";
Wink Saville8a9e0212013-04-09 12:11:38 -07004849 case RIL_REQUEST_GET_CELL_INFO_LIST: return"GET_CELL_INFO_LIST";
4850 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return"SET_UNSOL_CELL_INFO_LIST_RATE";
Sungmin Choi75697532013-04-26 15:04:45 -07004851 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "RIL_REQUEST_SET_INITIAL_ATTACH_APN";
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07004852 case RIL_REQUEST_IMS_REGISTRATION_STATE: return "IMS_REGISTRATION_STATE";
4853 case RIL_REQUEST_IMS_SEND_SMS: return "IMS_SEND_SMS";
Shishir Agrawal2458d8d2013-11-27 14:53:05 -08004854 case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "SIM_TRANSMIT_APDU_BASIC";
4855 case RIL_REQUEST_SIM_OPEN_CHANNEL: return "SIM_OPEN_CHANNEL";
4856 case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "SIM_CLOSE_CHANNEL";
4857 case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "SIM_TRANSMIT_APDU_CHANNEL";
Preeti Ahuja8c7dd412014-08-21 16:26:24 -07004858 case RIL_REQUEST_SIM_GET_ATR: return "SIM_GET_ATR";
Etan Cohend3652192014-06-20 08:28:44 -07004859 case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "SET_UICC_SUBSCRIPTION";
4860 case RIL_REQUEST_ALLOW_DATA: return "ALLOW_DATA";
Amit Mahajan2b772032014-06-26 14:20:11 -07004861 case RIL_REQUEST_GET_HARDWARE_CONFIG: return "GET_HARDWARE_CONFIG";
4862 case RIL_REQUEST_SIM_AUTHENTICATION: return "SIM_AUTHENTICATION";
Wink Savillec29360a2014-07-13 05:17:28 -07004863 case RIL_REQUEST_GET_DC_RT_INFO: return "GET_DC_RT_INFO";
4864 case RIL_REQUEST_SET_DC_RT_INFO_RATE: return "SET_DC_RT_INFO_RATE";
Amit Mahajanc796e222014-08-13 16:54:01 +00004865 case RIL_REQUEST_SET_DATA_PROFILE: return "SET_DATA_PROFILE";
Naveen Kalla41c1c0b2011-11-15 12:48:22 -08004866 case RIL_REQUEST_GET_DATA_CALL_PROFILE: return "GET_DATA_CALL_PROFILE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004867 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
4868 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08004869 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 -08004870 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
4871 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
4872 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
4873 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
4874 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)";
4875 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
4876 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
Naveen Kallac6e68722011-11-15 11:19:30 -08004877 case RIL_UNSOL_SUPP_SVC_NOTIFICATION: return "UNSOL_SUPP_SVC_NOTIFICATION";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004878 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
4879 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
4880 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
4881 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
4882 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL";
4883 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
Wink Savillef4c4d362009-04-02 01:37:03 -07004884 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004885 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
Wink Savillef4c4d362009-04-02 01:37:03 -07004886 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
4887 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_NEW_CDMA_SMS";
4888 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_NEW_BROADCAST_SMS";
4889 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
Wink Saville3d54e742009-05-18 18:00:44 -07004890 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
4891 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
4892 case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
4893 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
4894 case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
Jaikumar Ganeshaf6ecbf2009-04-29 13:27:51 -07004895 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
John Wang5d621da2009-09-18 17:17:48 -07004896 case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
John Wang5909cf82010-01-29 00:18:54 -08004897 case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
Wink Savilleee274582011-04-16 15:05:49 -07004898 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08004899 case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
4900 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
Wink Saville5b9df332011-04-06 16:24:21 -07004901 case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004902 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
Wink Saville8a9e0212013-04-09 12:11:38 -07004903 case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07004904 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "RESPONSE_IMS_NETWORK_STATE_CHANGED";
Etan Cohend3652192014-06-20 08:28:44 -07004905 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return "UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED";
4906 case RIL_UNSOL_SRVCC_STATE_NOTIFY: return "UNSOL_SRVCC_STATE_NOTIFY";
4907 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return "HARDWARE_CONFIG_CHANGED";
Wink Savillec29360a2014-07-13 05:17:28 -07004908 case RIL_UNSOL_DC_RT_INFO_CHANGED: return "UNSOL_DC_RT_INFO_CHANGED";
Naveen Kallaa65a16a2014-07-31 16:48:31 -07004909 case RIL_REQUEST_SHUTDOWN: return "SHUTDOWN";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004910 default: return "<unknown request>";
4911 }
4912}
4913
Etan Cohend3652192014-06-20 08:28:44 -07004914const char *
4915rilSocketIdToString(RIL_SOCKET_ID socket_id)
4916{
4917 switch(socket_id) {
4918 case RIL_SOCKET_1:
4919 return "RIL_SOCKET_1";
4920#if (SIM_COUNT >= 2)
4921 case RIL_SOCKET_2:
4922 return "RIL_SOCKET_2";
4923#endif
4924#if (SIM_COUNT >= 3)
4925 case RIL_SOCKET_3:
4926 return "RIL_SOCKET_3";
4927#endif
4928#if (SIM_COUNT >= 4)
4929 case RIL_SOCKET_4:
4930 return "RIL_SOCKET_4";
4931#endif
4932 default:
4933 return "not a valid RIL";
4934 }
4935}
4936
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004937} /* namespace android */