blob: 43fed590147e746048bb8e6c6ffc35bd37ebbbf0 [file] [log] [blame]
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001/* //device/libs/telephony/ril.cpp
2**
3** Copyright 2006, The Android Open Source Project
4**
5** 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
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** 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
15** limitations under the License.
16*/
17
18#define LOG_TAG "RILC"
19
20#include <hardware_legacy/power.h>
21
22#include <telephony/ril.h>
23#include <telephony/ril_cdma_sms.h>
24#include <cutils/sockets.h>
25#include <cutils/jstring.h>
Andrew Jiangca4a9a02014-01-18 18:04:08 -050026#include <telephony/record_stream.h>
Daniel Hillenbrand601dc852013-07-07 10:06:59 +020027#include <utils/Log.h>
28#include <utils/SystemClock.h>
29#include <pthread.h>
30#include <binder/Parcel.h>
31#include <cutils/jstring.h>
32
33#include <sys/types.h>
XpLoDWilDba5c6a32013-07-27 21:12:19 +020034#include <sys/limits.h>
Daniel Hillenbrand601dc852013-07-07 10:06:59 +020035#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"
Howard Sue32dbfd2015-01-07 15:55:57 +080060#define SOCKET2_NAME_RIL "rild2"
61#define SOCKET3_NAME_RIL "rild3"
62#define SOCKET4_NAME_RIL "rild4"
63
Daniel Hillenbrand601dc852013-07-07 10:06:59 +020064#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
81#define MIN(a,b) ((a)<(b) ? (a) : (b))
82
83/* 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) \
XpLoDWilDba5c6a32013-07-27 21:12:19 +0200100 RLOGD("[%04d]> %s %s", token, requestToString(req), printBuf)
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200101
102 #define startResponse sprintf(printBuf, "%s {", printBuf)
103 #define closeResponse sprintf(printBuf, "%s}", printBuf)
XpLoDWilDba5c6a32013-07-27 21:12:19 +0200104 #define printResponse RLOGD("%s", printBuf)
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200105
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
Howard Sue32dbfd2015-01-07 15:55:57 +0800121#define MAX_RIL_SOL RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE
122#define MAX_RIL_UNSOL RIL_UNSOL_CELL_INFO_LIST
Daniel Hillenbranda22f51c2013-09-04 23:46:58 +0200123
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200124enum WakeType {DONT_WAKE, WAKE_PARTIAL};
125
126typedef struct {
127 int requestNumber;
128 void (*dispatchFunction) (Parcel &p, struct RequestInfo *pRI);
129 int(*responseFunction) (Parcel &p, void *response, size_t responselen);
130} CommandInfo;
131
132typedef struct {
133 int requestNumber;
134 int (*responseFunction) (Parcel &p, void *response, size_t responselen);
135 WakeType wakeType;
136} UnsolResponseInfo;
137
138typedef struct RequestInfo {
139 int32_t token; //this is not RIL_Token
140 CommandInfo *pCI;
141 struct RequestInfo *p_next;
142 char cancelled;
143 char local; // responses to local commands do not go back to command process
Howard Sue32dbfd2015-01-07 15:55:57 +0800144 RIL_SOCKET_ID socket_id;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200145} RequestInfo;
146
147typedef struct UserCallbackInfo {
148 RIL_TimedCallback p_callback;
149 void *userParam;
150 struct ril_event event;
151 struct UserCallbackInfo *p_next;
152} UserCallbackInfo;
153
Howard Sue32dbfd2015-01-07 15:55:57 +0800154typedef struct SocketListenParam {
155 RIL_SOCKET_ID socket_id;
156 int fdListen;
157 int fdCommand;
158 char* processName;
159 struct ril_event* commands_event;
160 struct ril_event* listen_event;
161 void (*processCommandsCallback)(int fd, short flags, void *param);
162 RecordStream *p_rs;
163} SocketListenParam;
164
165extern "C" const char * requestToString(int request);
166extern "C" const char * failCauseToString(RIL_Errno);
167extern "C" const char * callStateToString(RIL_CallState);
168extern "C" const char * radioStateToString(RIL_RadioState);
169extern "C" const char * rilSocketIdToString(RIL_SOCKET_ID socket_id);
170
171extern "C"
172char rild[MAX_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200173
174/*******************************************************************/
175
176RIL_RadioFunctions s_callbacks = {0, NULL, NULL, NULL, NULL, NULL};
177static int s_registerCalled = 0;
178
179static pthread_t s_tid_dispatch;
180static pthread_t s_tid_reader;
181static int s_started = 0;
182
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200183static int s_fdDebug = -1;
Howard Sue32dbfd2015-01-07 15:55:57 +0800184static int s_fdDebug_socket2 = -1;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200185
186static int s_fdWakeupRead;
187static int s_fdWakeupWrite;
188
189static struct ril_event s_commands_event;
190static struct ril_event s_wakeupfd_event;
191static struct ril_event s_listen_event;
Howard Sue32dbfd2015-01-07 15:55:57 +0800192static SocketListenParam s_ril_param_socket;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200193
194static pthread_mutex_t s_pendingRequestsMutex = PTHREAD_MUTEX_INITIALIZER;
195static pthread_mutex_t s_writeMutex = PTHREAD_MUTEX_INITIALIZER;
Howard Sue32dbfd2015-01-07 15:55:57 +0800196static RequestInfo *s_pendingRequests = NULL;
197
198#if (SIM_COUNT >= 2)
199static struct ril_event s_commands_event_socket2;
200static struct ril_event s_listen_event_socket2;
201static SocketListenParam s_ril_param_socket2;
202
203static pthread_mutex_t s_pendingRequestsMutex_socket2 = PTHREAD_MUTEX_INITIALIZER;
204static pthread_mutex_t s_writeMutex_socket2 = PTHREAD_MUTEX_INITIALIZER;
205static RequestInfo *s_pendingRequests_socket2 = NULL;
206#endif
207
208#if (SIM_COUNT >= 3)
209static struct ril_event s_commands_event_socket3;
210static struct ril_event s_listen_event_socket3;
211static SocketListenParam s_ril_param_socket3;
212
213static pthread_mutex_t s_pendingRequestsMutex_socket3 = PTHREAD_MUTEX_INITIALIZER;
214static pthread_mutex_t s_writeMutex_socket3 = PTHREAD_MUTEX_INITIALIZER;
215static RequestInfo *s_pendingRequests_socket3 = NULL;
216#endif
217
218#if (SIM_COUNT >= 4)
219static struct ril_event s_commands_event_socket4;
220static struct ril_event s_listen_event_socket4;
221static SocketListenParam s_ril_param_socket4;
222
223static pthread_mutex_t s_pendingRequestsMutex_socket4 = PTHREAD_MUTEX_INITIALIZER;
224static pthread_mutex_t s_writeMutex_socket4 = PTHREAD_MUTEX_INITIALIZER;
225static RequestInfo *s_pendingRequests_socket4 = NULL;
226#endif
227
228static struct ril_event s_wake_timeout_event;
229static struct ril_event s_debug_event;
230
231static const struct timeval TIMEVAL_WAKE_TIMEOUT = {1,0};
232
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200233static pthread_mutex_t s_startupMutex = PTHREAD_MUTEX_INITIALIZER;
234static pthread_cond_t s_startupCond = PTHREAD_COND_INITIALIZER;
235
236static pthread_mutex_t s_dispatchMutex = PTHREAD_MUTEX_INITIALIZER;
237static pthread_cond_t s_dispatchCond = PTHREAD_COND_INITIALIZER;
238
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200239static RequestInfo *s_toDispatchHead = NULL;
240static RequestInfo *s_toDispatchTail = NULL;
241
242static UserCallbackInfo *s_last_wake_timeout_info = NULL;
243
244static void *s_lastNITZTimeData = NULL;
245static size_t s_lastNITZTimeDataSize;
246
247#if RILC_LOG
248 static char printBuf[PRINTBUF_SIZE];
249#endif
250
251/*******************************************************************/
Howard Sue32dbfd2015-01-07 15:55:57 +0800252static int sendResponse (Parcel &p, RIL_SOCKET_ID socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200253
254static void dispatchVoid (Parcel& p, RequestInfo *pRI);
255static void dispatchString (Parcel& p, RequestInfo *pRI);
256static void dispatchStrings (Parcel& p, RequestInfo *pRI);
257static void dispatchInts (Parcel& p, RequestInfo *pRI);
258static void dispatchDial (Parcel& p, RequestInfo *pRI);
259static void dispatchSIM_IO (Parcel& p, RequestInfo *pRI);
Howard Sue32dbfd2015-01-07 15:55:57 +0800260static void dispatchSIM_APDU (Parcel& p, RequestInfo *pRI);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200261static void dispatchCallForward(Parcel& p, RequestInfo *pRI);
262static void dispatchRaw(Parcel& p, RequestInfo *pRI);
263static void dispatchSmsWrite (Parcel &p, RequestInfo *pRI);
264static void dispatchDataCall (Parcel& p, RequestInfo *pRI);
265static void dispatchVoiceRadioTech (Parcel& p, RequestInfo *pRI);
Andrew Jiangca4a9a02014-01-18 18:04:08 -0500266static void dispatchSetInitialAttachApn (Parcel& p, RequestInfo *pRI);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200267static void dispatchCdmaSubscriptionSource (Parcel& p, RequestInfo *pRI);
268
269static void dispatchCdmaSms(Parcel &p, RequestInfo *pRI);
Andrew Jiangca4a9a02014-01-18 18:04:08 -0500270static void dispatchImsSms(Parcel &p, RequestInfo *pRI);
271static void dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
272static void dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200273static void dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI);
274static void dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI);
275static void dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI);
276static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI);
Howard Sue32dbfd2015-01-07 15:55:57 +0800277static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI);
278static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI);
279static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI);
280static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI);
281static void dispatchDataProfile(Parcel &p, RequestInfo *pRI);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200282static int responseInts(Parcel &p, void *response, size_t responselen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200283static int responseStrings(Parcel &p, void *response, size_t responselen);
284static int responseStringsNetworks(Parcel &p, void *response, size_t responselen);
285static int responseStrings(Parcel &p, void *response, size_t responselen, bool network_search);
286static int responseString(Parcel &p, void *response, size_t responselen);
287static int responseVoid(Parcel &p, void *response, size_t responselen);
288static int responseCallList(Parcel &p, void *response, size_t responselen);
289static int responseSMS(Parcel &p, void *response, size_t responselen);
290static int responseSIM_IO(Parcel &p, void *response, size_t responselen);
291static int responseCallForwards(Parcel &p, void *response, size_t responselen);
292static int responseDataCallList(Parcel &p, void *response, size_t responselen);
293static int responseSetupDataCall(Parcel &p, void *response, size_t responselen);
294static int responseRaw(Parcel &p, void *response, size_t responselen);
295static int responseSsn(Parcel &p, void *response, size_t responselen);
296static int responseSimStatus(Parcel &p, void *response, size_t responselen);
297static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen);
298static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen);
299static int responseCdmaSms(Parcel &p, void *response, size_t responselen);
300static int responseCellList(Parcel &p, void *response, size_t responselen);
301static int responseCdmaInformationRecords(Parcel &p,void *response, size_t responselen);
302static int responseRilSignalStrength(Parcel &p,void *response, size_t responselen);
303static int responseCallRing(Parcel &p, void *response, size_t responselen);
304static int responseCdmaSignalInfoRecord(Parcel &p,void *response, size_t responselen);
305static int responseCdmaCallWaiting(Parcel &p,void *response, size_t responselen);
306static int responseSimRefresh(Parcel &p, void *response, size_t responselen);
XpLoDWilDba5c6a32013-07-27 21:12:19 +0200307static int responseCellInfoList(Parcel &p, void *response, size_t responselen);
Howard Sue32dbfd2015-01-07 15:55:57 +0800308static int responseHardwareConfig(Parcel &p, void *response, size_t responselen);
309static int responseDcRtInfo(Parcel &p, void *response, size_t responselen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200310
311static int decodeVoiceRadioTechnology (RIL_RadioState radioState);
312static int decodeCdmaSubscriptionSource (RIL_RadioState radioState);
Andreas Schneider68f80d82015-04-07 19:13:42 +0200313static RIL_RadioState processRadioState(RIL_RadioState newRadioState, RIL_SOCKET_ID socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200314
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200315#ifdef RIL_SHLIB
Howard Sue32dbfd2015-01-07 15:55:57 +0800316#if defined(ANDROID_MULTI_SIM)
Andreas Schneider8e5fa432015-04-07 19:14:05 +0200317extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Howard Sue32dbfd2015-01-07 15:55:57 +0800318 size_t datalen, RIL_SOCKET_ID socket_id);
319#else
Andreas Schneider8e5fa432015-04-07 19:14:05 +0200320extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200321 size_t datalen);
322#endif
Howard Sue32dbfd2015-01-07 15:55:57 +0800323#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
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200334
335static UserCallbackInfo * internalRequestTimedCallback
336 (RIL_TimedCallback callback, void *param,
337 const struct timeval *relativeTime);
338
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
348/* 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;
367
Howard Sue32dbfd2015-01-07 15:55:57 +0800368static 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
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200377static char *
378strdupReadString(Parcel &p) {
379 size_t stringlen;
380 const char16_t *s16;
381
382 s16 = p.readString16Inplace(&stringlen);
383
384 return strndup16to8(s16, stringlen);
385}
386
387static void writeStringToParcel(Parcel &p, const char *s) {
388 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
397memsetString (char *s) {
398 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,
405 void* cookie) {
406 // do nothing -- the data reference lives longer than the Parcel object
407}
408
409/**
410 * To be called from dispatch thread
411 * Issue a single local request, ensuring that the response
412 * is not sent back up to the command process
413 */
414static void
Howard Sue32dbfd2015-01-07 15:55:57 +0800415issueLocalRequest(int request, void *data, int len, RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200416 RequestInfo *pRI;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200417 int ret;
Howard Sue32dbfd2015-01-07 15:55:57 +0800418 /* 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
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200430
431 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
432
433 pRI->local = 1;
434 pRI->token = 0xffffffff; // token is not used in this context
435
436 /* Hack to include Samsung requests */
437 if (request > 10000) {
Howard Sue32dbfd2015-01-07 15:55:57 +0800438 int index = request - 10000 + MAX_RIL_SOL;
Ethan Chend6e30652013-08-04 22:49:56 -0700439 RLOGD("SAMSUNG: request=%d, index=%d", request, index);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200440 pRI->pCI = &(s_commands[index]);
441 } else {
442 pRI->pCI = &(s_commands[request]);
443 }
Howard Sue32dbfd2015-01-07 15:55:57 +0800444 pRI->socket_id = socket_id;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200445
Howard Sue32dbfd2015-01-07 15:55:57 +0800446 ret = pthread_mutex_lock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200447 assert (ret == 0);
448
Howard Sue32dbfd2015-01-07 15:55:57 +0800449 pRI->p_next = *pendingRequestsHook;
450 *pendingRequestsHook = pRI;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200451
Howard Sue32dbfd2015-01-07 15:55:57 +0800452 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200453 assert (ret == 0);
454
XpLoDWilDba5c6a32013-07-27 21:12:19 +0200455 RLOGD("C[locl]> %s", requestToString(request));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200456
Howard Sue32dbfd2015-01-07 15:55:57 +0800457 CALL_ONREQUEST(request, data, len, pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200458}
459
460static int
Howard Sue32dbfd2015-01-07 15:55:57 +0800461processCommandBuffer(void *buffer, size_t buflen, RIL_SOCKET_ID socket_id) {
462
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200463 Parcel p;
464 status_t status;
465 int32_t request;
466 int32_t token;
467 RequestInfo *pRI;
Howard Sue32dbfd2015-01-07 15:55:57 +0800468
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200469 int ret;
Howard Sue32dbfd2015-01-07 15:55:57 +0800470 /* Hook for current context */
471 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
472 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
473 /* pendingRequestsHook refer to &s_pendingRequests */
474 RequestInfo** pendingRequestsHook = &s_pendingRequests;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200475
476 p.setData((uint8_t *) buffer, buflen);
477
478 // status checked at end
479 status = p.readInt32(&request);
480 status = p.readInt32 (&token);
481
Howard Sue32dbfd2015-01-07 15:55:57 +0800482 RLOGD("SOCKET %s REQUEST: %s length:%d", rilSocketIdToString(socket_id), requestToString(request), buflen);
483
484#if (SIM_COUNT >= 2)
485 if (socket_id == RIL_SOCKET_2) {
486 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
487 pendingRequestsHook = &s_pendingRequests_socket2;
488 }
489#if (SIM_COUNT >= 3)
490 else if (socket_id == RIL_SOCKET_3) {
491 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
492 pendingRequestsHook = &s_pendingRequests_socket3;
493 }
494#endif
495#if (SIM_COUNT >= 4)
496 else if (socket_id == RIL_SOCKET_4) {
497 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
498 pendingRequestsHook = &s_pendingRequests_socket4;
499 }
500#endif
501#endif
502
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200503 if (status != NO_ERROR) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +0200504 RLOGE("invalid request block");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200505 return 0;
506 }
507
Howard Sue32dbfd2015-01-07 15:55:57 +0800508 if (request < 1 || request >= (int32_t)NUM_ELEMS(s_commands)) {
509 Parcel pErr;
510
XpLoDWilDba5c6a32013-07-27 21:12:19 +0200511 RLOGE("unsupported request code %d token %d", request, token);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200512 // FIXME this should perhaps return a response
Howard Sue32dbfd2015-01-07 15:55:57 +0800513 pErr.writeInt32 (RESPONSE_SOLICITED);
514 pErr.writeInt32 (token);
515 pErr.writeInt32 (RIL_E_GENERIC_FAILURE);
516
517 sendResponse(pErr, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200518 return 0;
519 }
520
521 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
522
523 pRI->token = token;
524
525 /* Hack to include Samsung requests */
526 if (request > 10000) {
Howard Sue32dbfd2015-01-07 15:55:57 +0800527 int index = request - 10000 + MAX_RIL_SOL;
Ethan Chend6e30652013-08-04 22:49:56 -0700528 RLOGD("processCommandBuffer: samsung request=%d, index=%d",
529 request, index);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200530 pRI->pCI = &(s_commands[index]);
531 } else {
532 pRI->pCI = &(s_commands[request]);
533 }
534
Howard Sue32dbfd2015-01-07 15:55:57 +0800535 pRI->socket_id = socket_id;
536
537 ret = pthread_mutex_lock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200538 assert (ret == 0);
539
Howard Sue32dbfd2015-01-07 15:55:57 +0800540 pRI->p_next = *pendingRequestsHook;
541 *pendingRequestsHook = pRI;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200542
Howard Sue32dbfd2015-01-07 15:55:57 +0800543 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200544 assert (ret == 0);
545
546/* sLastDispatchedToken = token; */
547
548 pRI->pCI->dispatchFunction(p, pRI);
549
550 return 0;
551}
552
553static void
554invalidCommandBlock (RequestInfo *pRI) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +0200555 RLOGE("invalid command block for token %d request %s",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200556 pRI->token, requestToString(pRI->pCI->requestNumber));
557}
558
559/** Callee expects NULL */
560static void
561dispatchVoid (Parcel& p, RequestInfo *pRI) {
562 clearPrintBuf;
563 printRequest(pRI->token, pRI->pCI->requestNumber);
Howard Sue32dbfd2015-01-07 15:55:57 +0800564 CALL_ONREQUEST(pRI->pCI->requestNumber, NULL, 0, pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200565}
566
567/** Callee expects const char * */
568static void
569dispatchString (Parcel& p, RequestInfo *pRI) {
570 status_t status;
571 size_t datalen;
572 size_t stringlen;
573 char *string8 = NULL;
574
575 string8 = strdupReadString(p);
576
577 startRequest;
578 appendPrintBuf("%s%s", printBuf, string8);
579 closeRequest;
580 printRequest(pRI->token, pRI->pCI->requestNumber);
581
Howard Sue32dbfd2015-01-07 15:55:57 +0800582 CALL_ONREQUEST(pRI->pCI->requestNumber, string8,
583 sizeof(char *), pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200584
585#ifdef MEMSET_FREED
586 memsetString(string8);
587#endif
588
589 free(string8);
590 return;
591invalid:
592 invalidCommandBlock(pRI);
593 return;
594}
595
596/** Callee expects const char ** */
597static void
598dispatchStrings (Parcel &p, RequestInfo *pRI) {
599 int32_t countStrings;
600 status_t status;
601 size_t datalen;
602 char **pStrings;
603
604 status = p.readInt32 (&countStrings);
605
606 if (status != NO_ERROR) {
607 goto invalid;
608 }
609
610 startRequest;
611 if (countStrings == 0) {
612 // just some non-null pointer
613 pStrings = (char **)alloca(sizeof(char *));
614 datalen = 0;
615 } else if (((int)countStrings) == -1) {
616 pStrings = NULL;
617 datalen = 0;
618 } else {
619 datalen = sizeof(char *) * countStrings;
620
621 pStrings = (char **)alloca(datalen);
622
623 for (int i = 0 ; i < countStrings ; i++) {
624 pStrings[i] = strdupReadString(p);
625 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
626 }
627 }
628 removeLastChar;
629 closeRequest;
630 printRequest(pRI->token, pRI->pCI->requestNumber);
631
Howard Sue32dbfd2015-01-07 15:55:57 +0800632 CALL_ONREQUEST(pRI->pCI->requestNumber, pStrings, datalen, pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200633
634 if (pStrings != NULL) {
635 for (int i = 0 ; i < countStrings ; i++) {
636#ifdef MEMSET_FREED
637 memsetString (pStrings[i]);
638#endif
639 free(pStrings[i]);
640 }
641
642#ifdef MEMSET_FREED
643 memset(pStrings, 0, datalen);
644#endif
645 }
646
647 return;
648invalid:
649 invalidCommandBlock(pRI);
650 return;
651}
652
653/** Callee expects const int * */
654static void
655dispatchInts (Parcel &p, RequestInfo *pRI) {
656 int32_t count;
657 status_t status;
658 size_t datalen;
659 int *pInts;
660
661 status = p.readInt32 (&count);
662
663 if (status != NO_ERROR || count == 0) {
664 goto invalid;
665 }
666
667 datalen = sizeof(int) * count;
668 pInts = (int *)alloca(datalen);
669
670 startRequest;
671 for (int i = 0 ; i < count ; i++) {
672 int32_t t;
673
674 status = p.readInt32(&t);
675 pInts[i] = (int)t;
676 appendPrintBuf("%s%d,", printBuf, t);
677
678 if (status != NO_ERROR) {
679 goto invalid;
680 }
681 }
682 removeLastChar;
683 closeRequest;
684 printRequest(pRI->token, pRI->pCI->requestNumber);
685
Howard Sue32dbfd2015-01-07 15:55:57 +0800686 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<int *>(pInts),
687 datalen, pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200688
689#ifdef MEMSET_FREED
690 memset(pInts, 0, datalen);
691#endif
692
693 return;
694invalid:
695 invalidCommandBlock(pRI);
696 return;
697}
698
699
700/**
701 * Callee expects const RIL_SMS_WriteArgs *
702 * Payload is:
703 * int32_t status
704 * String pdu
705 */
706static void
707dispatchSmsWrite (Parcel &p, RequestInfo *pRI) {
708 RIL_SMS_WriteArgs args;
709 int32_t t;
710 status_t status;
711
712 memset (&args, 0, sizeof(args));
713
714 status = p.readInt32(&t);
715 args.status = (int)t;
716
717 args.pdu = strdupReadString(p);
718
719 if (status != NO_ERROR || args.pdu == NULL) {
720 goto invalid;
721 }
722
723 args.smsc = strdupReadString(p);
724
725 startRequest;
726 appendPrintBuf("%s%d,%s,smsc=%s", printBuf, args.status,
727 (char*)args.pdu, (char*)args.smsc);
728 closeRequest;
729 printRequest(pRI->token, pRI->pCI->requestNumber);
730
Howard Sue32dbfd2015-01-07 15:55:57 +0800731 CALL_ONREQUEST(pRI->pCI->requestNumber, &args, sizeof(args), pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200732
733#ifdef MEMSET_FREED
734 memsetString (args.pdu);
735#endif
736
737 free (args.pdu);
738
739#ifdef MEMSET_FREED
740 memset(&args, 0, sizeof(args));
741#endif
742
743 return;
744invalid:
745 invalidCommandBlock(pRI);
746 return;
747}
748
749/**
750 * Callee expects const RIL_Dial *
751 * Payload is:
752 * String address
753 * int32_t clir
754 */
755static void
756dispatchDial (Parcel &p, RequestInfo *pRI) {
757 RIL_Dial dial;
758 RIL_UUS_Info uusInfo;
759 int32_t sizeOfDial;
760 int32_t t;
761 int32_t uusPresent;
Andreas Schneider29472682015-01-01 19:00:04 +0100762#ifdef MODEM_TYPE_XMM7260
763 char *csv;
764#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200765 status_t status;
766
767 memset (&dial, 0, sizeof(dial));
768
769 dial.address = strdupReadString(p);
770
771 status = p.readInt32(&t);
772 dial.clir = (int)t;
773
774 if (status != NO_ERROR || dial.address == NULL) {
775 goto invalid;
776 }
777
Andreas Schneider29472682015-01-01 19:00:04 +0100778#ifdef MODEM_TYPE_XMM7260
779 /* CallDetails.call_type */
780 status = p.readInt32(&t);
781 if (status != NO_ERROR) {
782 goto invalid;
783 }
784 /* CallDetails.call_domain */
785 p.readInt32(&t);
786 if (status != NO_ERROR) {
787 goto invalid;
788 }
789 /* CallDetails.getCsvFromExtra */
790 csv = strdupReadString(p);
791 if (csv == NULL) {
792 goto invalid;
793 }
794 free(csv);
795#endif
796
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200797 if (s_callbacks.version < 3) { // Remove when partners upgrade to version 3
798 uusPresent = 0;
799 sizeOfDial = sizeof(dial) - sizeof(RIL_UUS_Info *);
800 } else {
801 status = p.readInt32(&uusPresent);
802
803 if (status != NO_ERROR) {
804 goto invalid;
805 }
806
807 if (uusPresent == 0) {
Andreas Schneidereef440e2015-04-07 19:01:54 +0200808#if defined(MODEM_TYPE_XMM6262) || defined(MODEM_TYPE_XMM7260)
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200809 dial.uusInfo = NULL;
Andreas Schneiderf68609b2015-04-07 19:01:34 +0200810#elif defined(MODEM_TYPE_XMM6260)
Howard Sue32dbfd2015-01-07 15:55:57 +0800811 /* Samsung hack */
812 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
813 uusInfo.uusType = (RIL_UUS_Type) 0;
814 uusInfo.uusDcs = (RIL_UUS_DCS) 0;
815 uusInfo.uusData = NULL;
816 uusInfo.uusLength = 0;
817 dial.uusInfo = &uusInfo;
818#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200819 } else {
820 int32_t len;
821
822 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
823
824 status = p.readInt32(&t);
825 uusInfo.uusType = (RIL_UUS_Type) t;
826
827 status = p.readInt32(&t);
828 uusInfo.uusDcs = (RIL_UUS_DCS) t;
829
830 status = p.readInt32(&len);
831 if (status != NO_ERROR) {
832 goto invalid;
833 }
834
835 // The java code writes -1 for null arrays
836 if (((int) len) == -1) {
837 uusInfo.uusData = NULL;
838 len = 0;
839 } else {
840 uusInfo.uusData = (char*) p.readInplace(len);
841 }
842
843 uusInfo.uusLength = len;
844 dial.uusInfo = &uusInfo;
845 }
846 sizeOfDial = sizeof(dial);
847 }
848
849 startRequest;
850 appendPrintBuf("%snum=%s,clir=%d", printBuf, dial.address, dial.clir);
851 if (uusPresent) {
852 appendPrintBuf("%s,uusType=%d,uusDcs=%d,uusLen=%d", printBuf,
853 dial.uusInfo->uusType, dial.uusInfo->uusDcs,
854 dial.uusInfo->uusLength);
855 }
856 closeRequest;
857 printRequest(pRI->token, pRI->pCI->requestNumber);
858
Howard Sue32dbfd2015-01-07 15:55:57 +0800859 CALL_ONREQUEST(pRI->pCI->requestNumber, &dial, sizeOfDial, pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200860
861#ifdef MEMSET_FREED
862 memsetString (dial.address);
863#endif
864
865 free (dial.address);
866
867#ifdef MEMSET_FREED
868 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
869 memset(&dial, 0, sizeof(dial));
870#endif
871
872 return;
873invalid:
874 invalidCommandBlock(pRI);
875 return;
876}
877
878/**
879 * Callee expects const RIL_SIM_IO *
880 * Payload is:
881 * int32_t command
882 * int32_t fileid
883 * String path
884 * int32_t p1, p2, p3
885 * String data
886 * String pin2
887 * String aidPtr
888 */
889static void
890dispatchSIM_IO (Parcel &p, RequestInfo *pRI) {
891 union RIL_SIM_IO {
892 RIL_SIM_IO_v6 v6;
893 RIL_SIM_IO_v5 v5;
894 } simIO;
895
896 int32_t t;
897 int size;
898 status_t status;
899
900 memset (&simIO, 0, sizeof(simIO));
901
902 // note we only check status at the end
903
904 status = p.readInt32(&t);
905 simIO.v6.command = (int)t;
906
907 status = p.readInt32(&t);
908 simIO.v6.fileid = (int)t;
909
910 simIO.v6.path = strdupReadString(p);
911
912 status = p.readInt32(&t);
913 simIO.v6.p1 = (int)t;
914
915 status = p.readInt32(&t);
916 simIO.v6.p2 = (int)t;
917
918 status = p.readInt32(&t);
919 simIO.v6.p3 = (int)t;
920
921 simIO.v6.data = strdupReadString(p);
922 simIO.v6.pin2 = strdupReadString(p);
923 simIO.v6.aidPtr = strdupReadString(p);
924
925 startRequest;
926 appendPrintBuf("%scmd=0x%X,efid=0x%X,path=%s,%d,%d,%d,%s,pin2=%s,aid=%s", printBuf,
927 simIO.v6.command, simIO.v6.fileid, (char*)simIO.v6.path,
928 simIO.v6.p1, simIO.v6.p2, simIO.v6.p3,
929 (char*)simIO.v6.data, (char*)simIO.v6.pin2, simIO.v6.aidPtr);
930 closeRequest;
931 printRequest(pRI->token, pRI->pCI->requestNumber);
932
933 if (status != NO_ERROR) {
934 goto invalid;
935 }
936
937 size = (s_callbacks.version < 6) ? sizeof(simIO.v5) : sizeof(simIO.v6);
Howard Sue32dbfd2015-01-07 15:55:57 +0800938 CALL_ONREQUEST(pRI->pCI->requestNumber, &simIO, size, pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200939
940#ifdef MEMSET_FREED
941 memsetString (simIO.v6.path);
942 memsetString (simIO.v6.data);
943 memsetString (simIO.v6.pin2);
944 memsetString (simIO.v6.aidPtr);
945#endif
946
947 free (simIO.v6.path);
948 free (simIO.v6.data);
949 free (simIO.v6.pin2);
950 free (simIO.v6.aidPtr);
951
952#ifdef MEMSET_FREED
953 memset(&simIO, 0, sizeof(simIO));
954#endif
955
956 return;
957invalid:
958 invalidCommandBlock(pRI);
959 return;
960}
961
962/**
Howard Sue32dbfd2015-01-07 15:55:57 +0800963 * Callee expects const RIL_SIM_APDU *
964 * Payload is:
965 * int32_t sessionid
966 * int32_t cla
967 * int32_t instruction
968 * int32_t p1, p2, p3
969 * String data
970 */
971static void
972dispatchSIM_APDU (Parcel &p, RequestInfo *pRI) {
973 int32_t t;
974 status_t status;
975 RIL_SIM_APDU apdu;
976
977 memset (&apdu, 0, sizeof(RIL_SIM_APDU));
978
979 // Note we only check status at the end. Any single failure leads to
980 // subsequent reads filing.
981 status = p.readInt32(&t);
982 apdu.sessionid = (int)t;
983
984 status = p.readInt32(&t);
985 apdu.cla = (int)t;
986
987 status = p.readInt32(&t);
988 apdu.instruction = (int)t;
989
990 status = p.readInt32(&t);
991 apdu.p1 = (int)t;
992
993 status = p.readInt32(&t);
994 apdu.p2 = (int)t;
995
996 status = p.readInt32(&t);
997 apdu.p3 = (int)t;
998
999 apdu.data = strdupReadString(p);
1000
1001 startRequest;
1002 appendPrintBuf("%ssessionid=%d,cla=%d,ins=%d,p1=%d,p2=%d,p3=%d,data=%s",
1003 printBuf, apdu.sessionid, apdu.cla, apdu.instruction, apdu.p1, apdu.p2,
1004 apdu.p3, (char*)apdu.data);
1005 closeRequest;
1006 printRequest(pRI->token, pRI->pCI->requestNumber);
1007
1008 if (status != NO_ERROR) {
1009 goto invalid;
1010 }
1011
1012 CALL_ONREQUEST(pRI->pCI->requestNumber, &apdu, sizeof(RIL_SIM_APDU), pRI, pRI->socket_id);
1013
1014#ifdef MEMSET_FREED
1015 memsetString(apdu.data);
1016#endif
1017 free(apdu.data);
1018
1019#ifdef MEMSET_FREED
1020 memset(&apdu, 0, sizeof(RIL_SIM_APDU));
1021#endif
1022
1023 return;
1024invalid:
1025 invalidCommandBlock(pRI);
1026 return;
1027}
1028
1029/**
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001030 * Callee expects const RIL_CallForwardInfo *
1031 * Payload is:
1032 * int32_t status/action
1033 * int32_t reason
1034 * int32_t serviceCode
1035 * int32_t toa
1036 * String number (0 length -> null)
1037 * int32_t timeSeconds
1038 */
1039static void
1040dispatchCallForward(Parcel &p, RequestInfo *pRI) {
1041 RIL_CallForwardInfo cff;
1042 int32_t t;
1043 status_t status;
1044
1045 memset (&cff, 0, sizeof(cff));
1046
1047 // note we only check status at the end
1048
1049 status = p.readInt32(&t);
1050 cff.status = (int)t;
1051
1052 status = p.readInt32(&t);
1053 cff.reason = (int)t;
1054
1055 status = p.readInt32(&t);
1056 cff.serviceClass = (int)t;
1057
1058 status = p.readInt32(&t);
1059 cff.toa = (int)t;
1060
1061 cff.number = strdupReadString(p);
1062
1063 status = p.readInt32(&t);
1064 cff.timeSeconds = (int)t;
1065
1066 if (status != NO_ERROR) {
1067 goto invalid;
1068 }
1069
1070 // special case: number 0-length fields is null
1071
1072 if (cff.number != NULL && strlen (cff.number) == 0) {
1073 cff.number = NULL;
1074 }
1075
1076 startRequest;
1077 appendPrintBuf("%sstat=%d,reason=%d,serv=%d,toa=%d,%s,tout=%d", printBuf,
1078 cff.status, cff.reason, cff.serviceClass, cff.toa,
1079 (char*)cff.number, cff.timeSeconds);
1080 closeRequest;
1081 printRequest(pRI->token, pRI->pCI->requestNumber);
1082
Howard Sue32dbfd2015-01-07 15:55:57 +08001083 CALL_ONREQUEST(pRI->pCI->requestNumber, &cff, sizeof(cff), pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001084
1085#ifdef MEMSET_FREED
1086 memsetString(cff.number);
1087#endif
1088
1089 free (cff.number);
1090
1091#ifdef MEMSET_FREED
1092 memset(&cff, 0, sizeof(cff));
1093#endif
1094
1095 return;
1096invalid:
1097 invalidCommandBlock(pRI);
1098 return;
1099}
1100
1101
1102static void
1103dispatchRaw(Parcel &p, RequestInfo *pRI) {
1104 int32_t len;
1105 status_t status;
1106 const void *data;
1107
1108 status = p.readInt32(&len);
1109
1110 if (status != NO_ERROR) {
1111 goto invalid;
1112 }
1113
1114 // The java code writes -1 for null arrays
1115 if (((int)len) == -1) {
1116 data = NULL;
1117 len = 0;
1118 }
1119
1120 data = p.readInplace(len);
1121
1122 startRequest;
1123 appendPrintBuf("%sraw_size=%d", printBuf, len);
1124 closeRequest;
1125 printRequest(pRI->token, pRI->pCI->requestNumber);
1126
Howard Sue32dbfd2015-01-07 15:55:57 +08001127 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<void *>(data), len, pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001128
1129 return;
1130invalid:
1131 invalidCommandBlock(pRI);
1132 return;
1133}
1134
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001135static status_t
1136constructCdmaSms(Parcel &p, RequestInfo *pRI, RIL_CDMA_SMS_Message& rcsm) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001137 int32_t t;
1138 uint8_t ut;
1139 status_t status;
1140 int32_t digitCount;
1141 int digitLimit;
1142
1143 memset(&rcsm, 0, sizeof(rcsm));
1144
1145 status = p.readInt32(&t);
1146 rcsm.uTeleserviceID = (int) t;
1147
1148 status = p.read(&ut,sizeof(ut));
1149 rcsm.bIsServicePresent = (uint8_t) ut;
1150
1151 status = p.readInt32(&t);
1152 rcsm.uServicecategory = (int) t;
1153
1154 status = p.readInt32(&t);
1155 rcsm.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1156
1157 status = p.readInt32(&t);
1158 rcsm.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1159
1160 status = p.readInt32(&t);
1161 rcsm.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1162
1163 status = p.readInt32(&t);
1164 rcsm.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1165
1166 status = p.read(&ut,sizeof(ut));
1167 rcsm.sAddress.number_of_digits= (uint8_t) ut;
1168
1169 digitLimit= MIN((rcsm.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
1170 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1171 status = p.read(&ut,sizeof(ut));
1172 rcsm.sAddress.digits[digitCount] = (uint8_t) ut;
1173 }
1174
1175 status = p.readInt32(&t);
1176 rcsm.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1177
1178 status = p.read(&ut,sizeof(ut));
1179 rcsm.sSubAddress.odd = (uint8_t) ut;
1180
1181 status = p.read(&ut,sizeof(ut));
1182 rcsm.sSubAddress.number_of_digits = (uint8_t) ut;
1183
1184 digitLimit= MIN((rcsm.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
1185 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1186 status = p.read(&ut,sizeof(ut));
1187 rcsm.sSubAddress.digits[digitCount] = (uint8_t) ut;
1188 }
1189
1190 status = p.readInt32(&t);
1191 rcsm.uBearerDataLen = (int) t;
1192
1193 digitLimit= MIN((rcsm.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
1194 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1195 status = p.read(&ut, sizeof(ut));
1196 rcsm.aBearerData[digitCount] = (uint8_t) ut;
1197 }
1198
1199 if (status != NO_ERROR) {
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001200 return status;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001201 }
1202
1203 startRequest;
1204 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
1205 sAddress.digit_mode=%d, sAddress.Number_mode=%d, sAddress.number_type=%d, ",
1206 printBuf, rcsm.uTeleserviceID,rcsm.bIsServicePresent,rcsm.uServicecategory,
1207 rcsm.sAddress.digit_mode, rcsm.sAddress.number_mode,rcsm.sAddress.number_type);
1208 closeRequest;
1209
1210 printRequest(pRI->token, pRI->pCI->requestNumber);
1211
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001212 return status;
1213}
1214
1215static void
1216dispatchCdmaSms(Parcel &p, RequestInfo *pRI) {
1217 RIL_CDMA_SMS_Message rcsm;
1218
1219 ALOGD("dispatchCdmaSms");
1220 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1221 goto invalid;
1222 }
1223
Howard Sue32dbfd2015-01-07 15:55:57 +08001224 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm),pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001225
1226#ifdef MEMSET_FREED
1227 memset(&rcsm, 0, sizeof(rcsm));
1228#endif
1229
1230 return;
1231
1232invalid:
1233 invalidCommandBlock(pRI);
1234 return;
1235}
1236
1237static void
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001238dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1239 RIL_IMS_SMS_Message rism;
1240 RIL_CDMA_SMS_Message rcsm;
1241
1242 ALOGD("dispatchImsCdmaSms: retry=%d, messageRef=%d", retry, messageRef);
1243
1244 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1245 goto invalid;
1246 }
1247 memset(&rism, 0, sizeof(rism));
1248 rism.tech = RADIO_TECH_3GPP2;
1249 rism.retry = retry;
1250 rism.messageRef = messageRef;
1251 rism.message.cdmaMessage = &rcsm;
1252
Howard Sue32dbfd2015-01-07 15:55:57 +08001253 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001254 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Howard Sue32dbfd2015-01-07 15:55:57 +08001255 +sizeof(rcsm),pRI, pRI->socket_id);
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001256
1257#ifdef MEMSET_FREED
1258 memset(&rcsm, 0, sizeof(rcsm));
1259 memset(&rism, 0, sizeof(rism));
1260#endif
1261
1262 return;
1263
1264invalid:
1265 invalidCommandBlock(pRI);
1266 return;
1267}
1268
1269static void
1270dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1271 RIL_IMS_SMS_Message rism;
1272 int32_t countStrings;
1273 status_t status;
1274 size_t datalen;
1275 char **pStrings;
1276 ALOGD("dispatchImsGsmSms: retry=%d, messageRef=%d", retry, messageRef);
1277
1278 status = p.readInt32 (&countStrings);
1279
1280 if (status != NO_ERROR) {
1281 goto invalid;
1282 }
1283
1284 memset(&rism, 0, sizeof(rism));
1285 rism.tech = RADIO_TECH_3GPP;
1286 rism.retry = retry;
1287 rism.messageRef = messageRef;
1288
1289 startRequest;
Howard Sue32dbfd2015-01-07 15:55:57 +08001290 appendPrintBuf("%stech=%d, retry=%d, messageRef=%d, ", printBuf,
1291 (int)rism.tech, (int)rism.retry, rism.messageRef);
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001292 if (countStrings == 0) {
1293 // just some non-null pointer
1294 pStrings = (char **)alloca(sizeof(char *));
1295 datalen = 0;
1296 } else if (((int)countStrings) == -1) {
1297 pStrings = NULL;
1298 datalen = 0;
1299 } else {
1300 datalen = sizeof(char *) * countStrings;
1301
1302 pStrings = (char **)alloca(datalen);
1303
1304 for (int i = 0 ; i < countStrings ; i++) {
1305 pStrings[i] = strdupReadString(p);
1306 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
1307 }
1308 }
1309 removeLastChar;
1310 closeRequest;
1311 printRequest(pRI->token, pRI->pCI->requestNumber);
1312
1313 rism.message.gsmMessage = pStrings;
Howard Sue32dbfd2015-01-07 15:55:57 +08001314 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001315 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Howard Sue32dbfd2015-01-07 15:55:57 +08001316 +datalen, pRI, pRI->socket_id);
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001317
1318 if (pStrings != NULL) {
1319 for (int i = 0 ; i < countStrings ; i++) {
1320#ifdef MEMSET_FREED
1321 memsetString (pStrings[i]);
1322#endif
1323 free(pStrings[i]);
1324 }
1325
1326#ifdef MEMSET_FREED
1327 memset(pStrings, 0, datalen);
1328#endif
1329 }
1330
1331#ifdef MEMSET_FREED
1332 memset(&rism, 0, sizeof(rism));
1333#endif
1334 return;
1335invalid:
1336 ALOGE("dispatchImsGsmSms invalid block");
1337 invalidCommandBlock(pRI);
1338 return;
1339}
1340
1341static void
1342dispatchImsSms(Parcel &p, RequestInfo *pRI) {
1343 int32_t t;
1344 status_t status = p.readInt32(&t);
1345 RIL_RadioTechnologyFamily format;
1346 uint8_t retry;
1347 int32_t messageRef;
1348
1349 ALOGD("dispatchImsSms");
1350 if (status != NO_ERROR) {
1351 goto invalid;
1352 }
1353 format = (RIL_RadioTechnologyFamily) t;
1354
1355 // read retry field
1356 status = p.read(&retry,sizeof(retry));
1357 if (status != NO_ERROR) {
1358 goto invalid;
1359 }
1360 // read messageRef field
1361 status = p.read(&messageRef,sizeof(messageRef));
1362 if (status != NO_ERROR) {
1363 goto invalid;
1364 }
1365
1366 if (RADIO_TECH_3GPP == format) {
1367 dispatchImsGsmSms(p, pRI, retry, messageRef);
1368 } else if (RADIO_TECH_3GPP2 == format) {
1369 dispatchImsCdmaSms(p, pRI, retry, messageRef);
1370 } else {
1371 ALOGE("requestImsSendSMS invalid format value =%d", format);
1372 }
1373
1374 return;
1375
1376invalid:
1377 invalidCommandBlock(pRI);
1378 return;
1379}
1380
1381static void
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001382dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI) {
1383 RIL_CDMA_SMS_Ack rcsa;
1384 int32_t t;
1385 status_t status;
1386 int32_t digitCount;
1387
1388 memset(&rcsa, 0, sizeof(rcsa));
1389
1390 status = p.readInt32(&t);
1391 rcsa.uErrorClass = (RIL_CDMA_SMS_ErrorClass) t;
1392
1393 status = p.readInt32(&t);
1394 rcsa.uSMSCauseCode = (int) t;
1395
1396 if (status != NO_ERROR) {
1397 goto invalid;
1398 }
1399
1400 startRequest;
1401 appendPrintBuf("%suErrorClass=%d, uTLStatus=%d, ",
1402 printBuf, rcsa.uErrorClass, rcsa.uSMSCauseCode);
1403 closeRequest;
1404
1405 printRequest(pRI->token, pRI->pCI->requestNumber);
1406
Howard Sue32dbfd2015-01-07 15:55:57 +08001407 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsa, sizeof(rcsa),pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001408
1409#ifdef MEMSET_FREED
1410 memset(&rcsa, 0, sizeof(rcsa));
1411#endif
1412
1413 return;
1414
1415invalid:
1416 invalidCommandBlock(pRI);
1417 return;
1418}
1419
1420static void
1421dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1422 int32_t t;
1423 status_t status;
1424 int32_t num;
1425
1426 status = p.readInt32(&num);
1427 if (status != NO_ERROR) {
1428 goto invalid;
1429 }
1430
Ethan Chend6e30652013-08-04 22:49:56 -07001431 {
1432 RIL_GSM_BroadcastSmsConfigInfo gsmBci[num];
1433 RIL_GSM_BroadcastSmsConfigInfo *gsmBciPtrs[num];
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001434
Ethan Chend6e30652013-08-04 22:49:56 -07001435 startRequest;
1436 for (int i = 0 ; i < num ; i++ ) {
1437 gsmBciPtrs[i] = &gsmBci[i];
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001438
Ethan Chend6e30652013-08-04 22:49:56 -07001439 status = p.readInt32(&t);
1440 gsmBci[i].fromServiceId = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001441
Ethan Chend6e30652013-08-04 22:49:56 -07001442 status = p.readInt32(&t);
1443 gsmBci[i].toServiceId = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001444
Ethan Chend6e30652013-08-04 22:49:56 -07001445 status = p.readInt32(&t);
1446 gsmBci[i].fromCodeScheme = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001447
Ethan Chend6e30652013-08-04 22:49:56 -07001448 status = p.readInt32(&t);
1449 gsmBci[i].toCodeScheme = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001450
Ethan Chend6e30652013-08-04 22:49:56 -07001451 status = p.readInt32(&t);
1452 gsmBci[i].selected = (uint8_t) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001453
Ethan Chend6e30652013-08-04 22:49:56 -07001454 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId =%d, \
1455 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]", printBuf, i,
1456 gsmBci[i].fromServiceId, gsmBci[i].toServiceId,
1457 gsmBci[i].fromCodeScheme, gsmBci[i].toCodeScheme,
1458 gsmBci[i].selected);
1459 }
1460 closeRequest;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001461
Ethan Chend6e30652013-08-04 22:49:56 -07001462 if (status != NO_ERROR) {
1463 goto invalid;
1464 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001465
Howard Sue32dbfd2015-01-07 15:55:57 +08001466 CALL_ONREQUEST(pRI->pCI->requestNumber,
Ethan Chend6e30652013-08-04 22:49:56 -07001467 gsmBciPtrs,
1468 num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *),
Howard Sue32dbfd2015-01-07 15:55:57 +08001469 pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001470
1471#ifdef MEMSET_FREED
Ethan Chend6e30652013-08-04 22:49:56 -07001472 memset(gsmBci, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo));
1473 memset(gsmBciPtrs, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001474#endif
Ethan Chend6e30652013-08-04 22:49:56 -07001475 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001476
1477 return;
1478
1479invalid:
1480 invalidCommandBlock(pRI);
1481 return;
1482}
1483
1484static void
1485dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1486 int32_t t;
1487 status_t status;
1488 int32_t num;
1489
1490 status = p.readInt32(&num);
1491 if (status != NO_ERROR) {
1492 goto invalid;
1493 }
1494
Ethan Chend6e30652013-08-04 22:49:56 -07001495 {
1496 RIL_CDMA_BroadcastSmsConfigInfo cdmaBci[num];
1497 RIL_CDMA_BroadcastSmsConfigInfo *cdmaBciPtrs[num];
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001498
Ethan Chend6e30652013-08-04 22:49:56 -07001499 startRequest;
1500 for (int i = 0 ; i < num ; i++ ) {
1501 cdmaBciPtrs[i] = &cdmaBci[i];
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001502
Ethan Chend6e30652013-08-04 22:49:56 -07001503 status = p.readInt32(&t);
1504 cdmaBci[i].service_category = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001505
Ethan Chend6e30652013-08-04 22:49:56 -07001506 status = p.readInt32(&t);
1507 cdmaBci[i].language = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001508
Ethan Chend6e30652013-08-04 22:49:56 -07001509 status = p.readInt32(&t);
1510 cdmaBci[i].selected = (uint8_t) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001511
Ethan Chend6e30652013-08-04 22:49:56 -07001512 appendPrintBuf("%s [%d: service_category=%d, language =%d, \
1513 entries.bSelected =%d]", printBuf, i, cdmaBci[i].service_category,
1514 cdmaBci[i].language, cdmaBci[i].selected);
1515 }
1516 closeRequest;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001517
Ethan Chend6e30652013-08-04 22:49:56 -07001518 if (status != NO_ERROR) {
1519 goto invalid;
1520 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001521
Howard Sue32dbfd2015-01-07 15:55:57 +08001522 CALL_ONREQUEST(pRI->pCI->requestNumber,
Ethan Chend6e30652013-08-04 22:49:56 -07001523 cdmaBciPtrs,
1524 num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *),
Howard Sue32dbfd2015-01-07 15:55:57 +08001525 pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001526
1527#ifdef MEMSET_FREED
Ethan Chend6e30652013-08-04 22:49:56 -07001528 memset(cdmaBci, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo));
1529 memset(cdmaBciPtrs, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001530#endif
Ethan Chend6e30652013-08-04 22:49:56 -07001531 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001532
1533 return;
1534
1535invalid:
1536 invalidCommandBlock(pRI);
1537 return;
1538}
1539
1540static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI) {
1541 RIL_CDMA_SMS_WriteArgs rcsw;
1542 int32_t t;
1543 uint32_t ut;
1544 uint8_t uct;
1545 status_t status;
1546 int32_t digitCount;
1547
1548 memset(&rcsw, 0, sizeof(rcsw));
1549
1550 status = p.readInt32(&t);
1551 rcsw.status = t;
1552
1553 status = p.readInt32(&t);
1554 rcsw.message.uTeleserviceID = (int) t;
1555
1556 status = p.read(&uct,sizeof(uct));
1557 rcsw.message.bIsServicePresent = (uint8_t) uct;
1558
1559 status = p.readInt32(&t);
1560 rcsw.message.uServicecategory = (int) t;
1561
1562 status = p.readInt32(&t);
1563 rcsw.message.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1564
1565 status = p.readInt32(&t);
1566 rcsw.message.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1567
1568 status = p.readInt32(&t);
1569 rcsw.message.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1570
1571 status = p.readInt32(&t);
1572 rcsw.message.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1573
1574 status = p.read(&uct,sizeof(uct));
1575 rcsw.message.sAddress.number_of_digits = (uint8_t) uct;
1576
1577 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_ADDRESS_MAX; digitCount ++) {
1578 status = p.read(&uct,sizeof(uct));
1579 rcsw.message.sAddress.digits[digitCount] = (uint8_t) uct;
1580 }
1581
1582 status = p.readInt32(&t);
1583 rcsw.message.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1584
1585 status = p.read(&uct,sizeof(uct));
1586 rcsw.message.sSubAddress.odd = (uint8_t) uct;
1587
1588 status = p.read(&uct,sizeof(uct));
1589 rcsw.message.sSubAddress.number_of_digits = (uint8_t) uct;
1590
1591 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_SUBADDRESS_MAX; digitCount ++) {
1592 status = p.read(&uct,sizeof(uct));
1593 rcsw.message.sSubAddress.digits[digitCount] = (uint8_t) uct;
1594 }
1595
1596 status = p.readInt32(&t);
1597 rcsw.message.uBearerDataLen = (int) t;
1598
1599 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_BEARER_DATA_MAX; digitCount ++) {
1600 status = p.read(&uct, sizeof(uct));
1601 rcsw.message.aBearerData[digitCount] = (uint8_t) uct;
1602 }
1603
1604 if (status != NO_ERROR) {
1605 goto invalid;
1606 }
1607
1608 startRequest;
1609 appendPrintBuf("%sstatus=%d, message.uTeleserviceID=%d, message.bIsServicePresent=%d, \
1610 message.uServicecategory=%d, message.sAddress.digit_mode=%d, \
1611 message.sAddress.number_mode=%d, \
1612 message.sAddress.number_type=%d, ",
1613 printBuf, rcsw.status, rcsw.message.uTeleserviceID, rcsw.message.bIsServicePresent,
1614 rcsw.message.uServicecategory, rcsw.message.sAddress.digit_mode,
1615 rcsw.message.sAddress.number_mode,
1616 rcsw.message.sAddress.number_type);
1617 closeRequest;
1618
1619 printRequest(pRI->token, pRI->pCI->requestNumber);
1620
Howard Sue32dbfd2015-01-07 15:55:57 +08001621 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsw, sizeof(rcsw),pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001622
1623#ifdef MEMSET_FREED
1624 memset(&rcsw, 0, sizeof(rcsw));
1625#endif
1626
1627 return;
1628
1629invalid:
1630 invalidCommandBlock(pRI);
1631 return;
1632
1633}
1634
Ethan Chend6e30652013-08-04 22:49:56 -07001635// For backwards compatibility in RIL_REQUEST_SETUP_DATA_CALL.
1636// Version 4 of the RIL interface adds a new PDP type parameter to support
1637// IPv6 and dual-stack PDP contexts. When dealing with a previous version of
1638// RIL, remove the parameter from the request.
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001639static void dispatchDataCall(Parcel& p, RequestInfo *pRI) {
Ethan Chend6e30652013-08-04 22:49:56 -07001640 // In RIL v3, REQUEST_SETUP_DATA_CALL takes 6 parameters.
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001641 const int numParamsRilV3 = 6;
1642
Ethan Chend6e30652013-08-04 22:49:56 -07001643 // The first bytes of the RIL parcel contain the request number and the
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001644 // serial number - see processCommandBuffer(). Copy them over too.
1645 int pos = p.dataPosition();
1646
1647 int numParams = p.readInt32();
1648 if (s_callbacks.version < 4 && numParams > numParamsRilV3) {
1649 Parcel p2;
1650 p2.appendFrom(&p, 0, pos);
1651 p2.writeInt32(numParamsRilV3);
1652 for(int i = 0; i < numParamsRilV3; i++) {
1653 p2.writeString16(p.readString16());
1654 }
1655 p2.setDataPosition(pos);
1656 dispatchStrings(p2, pRI);
1657 } else {
1658 p.setDataPosition(pos);
1659 dispatchStrings(p, pRI);
1660 }
1661}
1662
1663// For backwards compatibility with RILs that dont support RIL_REQUEST_VOICE_RADIO_TECH.
Ethan Chend6e30652013-08-04 22:49:56 -07001664// When all RILs handle this request, this function can be removed and
1665// the request can be sent directly to the RIL using dispatchVoid.
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001666static void dispatchVoiceRadioTech(Parcel& p, RequestInfo *pRI) {
Howard Sue32dbfd2015-01-07 15:55:57 +08001667 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001668
1669 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1670 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1671 }
1672
Ethan Chend6e30652013-08-04 22:49:56 -07001673 // RILs that support RADIO_STATE_ON should support this request.
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001674 if (RADIO_STATE_ON == state) {
1675 dispatchVoid(p, pRI);
1676 return;
1677 }
1678
Ethan Chend6e30652013-08-04 22:49:56 -07001679 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1680 // will not support this new request either and decode Voice Radio Technology
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001681 // from Radio State
1682 voiceRadioTech = decodeVoiceRadioTechnology(state);
1683
1684 if (voiceRadioTech < 0)
1685 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1686 else
1687 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &voiceRadioTech, sizeof(int));
1688}
1689
Ethan Chend6e30652013-08-04 22:49:56 -07001690// For backwards compatibility in RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE:.
1691// When all RILs handle this request, this function can be removed and
1692// the request can be sent directly to the RIL using dispatchVoid.
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001693static void dispatchCdmaSubscriptionSource(Parcel& p, RequestInfo *pRI) {
Howard Sue32dbfd2015-01-07 15:55:57 +08001694 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001695
1696 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1697 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1698 }
1699
1700 // RILs that support RADIO_STATE_ON should support this request.
1701 if (RADIO_STATE_ON == state) {
1702 dispatchVoid(p, pRI);
1703 return;
1704 }
1705
Ethan Chend6e30652013-08-04 22:49:56 -07001706 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001707 // will not support this new request either and decode CDMA Subscription Source
Ethan Chend6e30652013-08-04 22:49:56 -07001708 // from Radio State
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001709 cdmaSubscriptionSource = decodeCdmaSubscriptionSource(state);
1710
1711 if (cdmaSubscriptionSource < 0)
1712 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1713 else
1714 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &cdmaSubscriptionSource, sizeof(int));
1715}
1716
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001717static void dispatchSetInitialAttachApn(Parcel &p, RequestInfo *pRI)
1718{
1719 RIL_InitialAttachApn pf;
1720 int32_t t;
1721 status_t status;
1722
1723 memset(&pf, 0, sizeof(pf));
1724
1725 pf.apn = strdupReadString(p);
1726 pf.protocol = strdupReadString(p);
1727
1728 status = p.readInt32(&t);
1729 pf.authtype = (int) t;
1730
1731 pf.username = strdupReadString(p);
1732 pf.password = strdupReadString(p);
1733
1734 startRequest;
1735 appendPrintBuf("%sapn=%s, protocol=%s, auth_type=%d, username=%s, password=%s",
1736 printBuf, pf.apn, pf.protocol, pf.auth_type, pf.username, pf.password);
1737 closeRequest;
1738 printRequest(pRI->token, pRI->pCI->requestNumber);
1739
1740 if (status != NO_ERROR) {
1741 goto invalid;
1742 }
Howard Sue32dbfd2015-01-07 15:55:57 +08001743 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001744
1745#ifdef MEMSET_FREED
1746 memsetString(pf.apn);
1747 memsetString(pf.protocol);
1748 memsetString(pf.username);
1749 memsetString(pf.password);
1750#endif
1751
1752 free(pf.apn);
1753 free(pf.protocol);
1754 free(pf.username);
1755 free(pf.password);
1756
1757#ifdef MEMSET_FREED
1758 memset(&pf, 0, sizeof(pf));
1759#endif
1760
1761 return;
1762invalid:
1763 invalidCommandBlock(pRI);
1764 return;
1765}
1766
Howard Sue32dbfd2015-01-07 15:55:57 +08001767static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI) {
1768 RIL_NV_ReadItem nvri;
1769 int32_t t;
1770 status_t status;
1771
1772 memset(&nvri, 0, sizeof(nvri));
1773
1774 status = p.readInt32(&t);
1775 nvri.itemID = (RIL_NV_Item) t;
1776
1777 if (status != NO_ERROR) {
1778 goto invalid;
1779 }
1780
1781 startRequest;
1782 appendPrintBuf("%snvri.itemID=%d, ", printBuf, nvri.itemID);
1783 closeRequest;
1784
1785 printRequest(pRI->token, pRI->pCI->requestNumber);
1786
1787 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvri, sizeof(nvri), pRI, pRI->socket_id);
1788
1789#ifdef MEMSET_FREED
1790 memset(&nvri, 0, sizeof(nvri));
1791#endif
1792
1793 return;
1794
1795invalid:
1796 invalidCommandBlock(pRI);
1797 return;
1798}
1799
1800static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI) {
1801 RIL_NV_WriteItem nvwi;
1802 int32_t t;
1803 status_t status;
1804
1805 memset(&nvwi, 0, sizeof(nvwi));
1806
1807 status = p.readInt32(&t);
1808 nvwi.itemID = (RIL_NV_Item) t;
1809
1810 nvwi.value = strdupReadString(p);
1811
1812 if (status != NO_ERROR || nvwi.value == NULL) {
1813 goto invalid;
1814 }
1815
1816 startRequest;
1817 appendPrintBuf("%snvwi.itemID=%d, value=%s, ", printBuf, nvwi.itemID,
1818 nvwi.value);
1819 closeRequest;
1820
1821 printRequest(pRI->token, pRI->pCI->requestNumber);
1822
1823 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvwi, sizeof(nvwi), pRI, pRI->socket_id);
1824
1825#ifdef MEMSET_FREED
1826 memsetString(nvwi.value);
1827#endif
1828
1829 free(nvwi.value);
1830
1831#ifdef MEMSET_FREED
1832 memset(&nvwi, 0, sizeof(nvwi));
1833#endif
1834
1835 return;
1836
1837invalid:
1838 invalidCommandBlock(pRI);
1839 return;
1840}
1841
1842
1843static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI) {
1844 RIL_SelectUiccSub uicc_sub;
1845 status_t status;
1846 int32_t t;
1847 memset(&uicc_sub, 0, sizeof(uicc_sub));
1848
1849 status = p.readInt32(&t);
1850 if (status != NO_ERROR) {
1851 goto invalid;
1852 }
1853 uicc_sub.slot = (int) t;
1854
1855 status = p.readInt32(&t);
1856 if (status != NO_ERROR) {
1857 goto invalid;
1858 }
1859 uicc_sub.app_index = (int) t;
1860
1861 status = p.readInt32(&t);
1862 if (status != NO_ERROR) {
1863 goto invalid;
1864 }
1865 uicc_sub.sub_type = (RIL_SubscriptionType) t;
1866
1867 status = p.readInt32(&t);
1868 if (status != NO_ERROR) {
1869 goto invalid;
1870 }
1871 uicc_sub.act_status = (RIL_UiccSubActStatus) t;
1872
1873 startRequest;
1874 appendPrintBuf("slot=%d, app_index=%d, act_status = %d", uicc_sub.slot, uicc_sub.app_index,
1875 uicc_sub.act_status);
1876 RLOGD("dispatchUiccSubscription, slot=%d, app_index=%d, act_status = %d", uicc_sub.slot,
1877 uicc_sub.app_index, uicc_sub.act_status);
1878 closeRequest;
1879 printRequest(pRI->token, pRI->pCI->requestNumber);
1880
1881 CALL_ONREQUEST(pRI->pCI->requestNumber, &uicc_sub, sizeof(uicc_sub), pRI, pRI->socket_id);
1882
1883#ifdef MEMSET_FREED
1884 memset(&uicc_sub, 0, sizeof(uicc_sub));
1885#endif
1886 return;
1887
1888invalid:
1889 invalidCommandBlock(pRI);
1890 return;
1891}
1892
1893static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI)
1894{
1895 RIL_SimAuthentication pf;
1896 int32_t t;
1897 status_t status;
1898
1899 memset(&pf, 0, sizeof(pf));
1900
1901 status = p.readInt32(&t);
1902 pf.authContext = (int) t;
1903 pf.authData = strdupReadString(p);
1904 pf.aid = strdupReadString(p);
1905
1906 startRequest;
1907 appendPrintBuf("authContext=%s, authData=%s, aid=%s", pf.authContext, pf.authData, pf.aid);
1908 closeRequest;
1909 printRequest(pRI->token, pRI->pCI->requestNumber);
1910
1911 if (status != NO_ERROR) {
1912 goto invalid;
1913 }
1914 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
1915
1916#ifdef MEMSET_FREED
1917 memsetString(pf.authData);
1918 memsetString(pf.aid);
1919#endif
1920
1921 free(pf.authData);
1922 free(pf.aid);
1923
1924#ifdef MEMSET_FREED
1925 memset(&pf, 0, sizeof(pf));
1926#endif
1927
1928 return;
1929invalid:
1930 invalidCommandBlock(pRI);
1931 return;
1932}
1933
1934static void dispatchDataProfile(Parcel &p, RequestInfo *pRI) {
1935 int32_t t;
1936 status_t status;
1937 int32_t num;
1938
1939 status = p.readInt32(&num);
1940 if (status != NO_ERROR) {
1941 goto invalid;
1942 }
1943
1944 {
1945 RIL_DataProfileInfo dataProfiles[num];
1946 RIL_DataProfileInfo *dataProfilePtrs[num];
1947
1948 startRequest;
1949 for (int i = 0 ; i < num ; i++ ) {
1950 dataProfilePtrs[i] = &dataProfiles[i];
1951
1952 status = p.readInt32(&t);
1953 dataProfiles[i].profileId = (int) t;
1954
1955 dataProfiles[i].apn = strdupReadString(p);
1956 dataProfiles[i].protocol = strdupReadString(p);
1957 status = p.readInt32(&t);
1958 dataProfiles[i].authType = (int) t;
1959
1960 dataProfiles[i].user = strdupReadString(p);
1961 dataProfiles[i].password = strdupReadString(p);
1962
1963 status = p.readInt32(&t);
1964 dataProfiles[i].type = (int) t;
1965
1966 status = p.readInt32(&t);
1967 dataProfiles[i].maxConnsTime = (int) t;
1968 status = p.readInt32(&t);
1969 dataProfiles[i].maxConns = (int) t;
1970 status = p.readInt32(&t);
1971 dataProfiles[i].waitTime = (int) t;
1972
1973 status = p.readInt32(&t);
1974 dataProfiles[i].enabled = (int) t;
1975
1976 appendPrintBuf("%s [%d: profileId=%d, apn =%s, protocol =%s, authType =%d, \
1977 user =%s, password =%s, type =%d, maxConnsTime =%d, maxConns =%d, \
1978 waitTime =%d, enabled =%d]", printBuf, i, dataProfiles[i].profileId,
1979 dataProfiles[i].apn, dataProfiles[i].protocol, dataProfiles[i].authType,
1980 dataProfiles[i].user, dataProfiles[i].password, dataProfiles[i].type,
1981 dataProfiles[i].maxConnsTime, dataProfiles[i].maxConns,
1982 dataProfiles[i].waitTime, dataProfiles[i].enabled);
1983 }
1984 closeRequest;
1985 printRequest(pRI->token, pRI->pCI->requestNumber);
1986
1987 if (status != NO_ERROR) {
1988 goto invalid;
1989 }
1990 CALL_ONREQUEST(pRI->pCI->requestNumber,
1991 dataProfilePtrs,
1992 num * sizeof(RIL_DataProfileInfo *),
1993 pRI, pRI->socket_id);
1994
1995#ifdef MEMSET_FREED
1996 memset(dataProfiles, 0, num * sizeof(RIL_DataProfileInfo));
1997 memset(dataProfilePtrs, 0, num * sizeof(RIL_DataProfileInfo *));
1998#endif
1999 }
2000
2001 return;
2002
2003invalid:
2004 invalidCommandBlock(pRI);
2005 return;
2006}
2007
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002008static int
2009blockingWrite(int fd, const void *buffer, size_t len) {
2010 size_t writeOffset = 0;
2011 const uint8_t *toWrite;
2012
2013 toWrite = (const uint8_t *)buffer;
2014
2015 while (writeOffset < len) {
2016 ssize_t written;
2017 do {
2018 written = write (fd, toWrite + writeOffset,
2019 len - writeOffset);
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002020 } while (written < 0 && ((errno == EINTR) || (errno == EAGAIN)));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002021
2022 if (written >= 0) {
2023 writeOffset += written;
2024 } else { // written < 0
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002025 RLOGE ("RIL Response: unexpected error on write errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002026 close(fd);
2027 return -1;
2028 }
2029 }
2030
2031 return 0;
2032}
2033
2034static int
Howard Sue32dbfd2015-01-07 15:55:57 +08002035sendResponseRaw (const void *data, size_t dataSize, RIL_SOCKET_ID socket_id) {
2036 int fd = s_ril_param_socket.fdCommand;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002037 int ret;
2038 uint32_t header;
Howard Sue32dbfd2015-01-07 15:55:57 +08002039 pthread_mutex_t * writeMutexHook = &s_writeMutex;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002040
Howard Sue32dbfd2015-01-07 15:55:57 +08002041 RLOGE("Send Response to %s", rilSocketIdToString(socket_id));
2042
2043#if (SIM_COUNT >= 2)
2044 if (socket_id == RIL_SOCKET_2) {
2045 fd = s_ril_param_socket2.fdCommand;
2046 writeMutexHook = &s_writeMutex_socket2;
2047 }
2048#if (SIM_COUNT >= 3)
2049 else if (socket_id == RIL_SOCKET_3) {
2050 fd = s_ril_param_socket3.fdCommand;
2051 writeMutexHook = &s_writeMutex_socket3;
2052 }
2053#endif
2054#if (SIM_COUNT >= 4)
2055 else if (socket_id == RIL_SOCKET_4) {
2056 fd = s_ril_param_socket4.fdCommand;
2057 writeMutexHook = &s_writeMutex_socket4;
2058 }
2059#endif
2060#endif
2061 if (fd < 0) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002062 return -1;
2063 }
2064
Howard Sue32dbfd2015-01-07 15:55:57 +08002065 pthread_mutex_lock(writeMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002066
2067 header = htonl(dataSize);
2068
2069 ret = blockingWrite(fd, (void *)&header, sizeof(header));
2070
2071 if (ret < 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002072 pthread_mutex_unlock(writeMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002073 return ret;
2074 }
2075
2076 ret = blockingWrite(fd, data, dataSize);
2077
2078 if (ret < 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002079 pthread_mutex_unlock(writeMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002080 return ret;
2081 }
2082
Howard Sue32dbfd2015-01-07 15:55:57 +08002083 pthread_mutex_unlock(writeMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002084
2085 return 0;
2086}
2087
2088static int
Howard Sue32dbfd2015-01-07 15:55:57 +08002089sendResponse (Parcel &p, RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002090 printResponse;
Howard Sue32dbfd2015-01-07 15:55:57 +08002091 return sendResponseRaw(p.data(), p.dataSize(), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002092}
2093
Howard Sue32dbfd2015-01-07 15:55:57 +08002094/** response is an int* pointing to an array of ints */
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002095
2096static int
2097responseInts(Parcel &p, void *response, size_t responselen) {
2098 int numInts;
2099
2100 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002101 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002102 return RIL_ERRNO_INVALID_RESPONSE;
2103 }
2104 if (responselen % sizeof(int) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002105 RLOGE("responseInts: invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002106 (int)responselen, (int)sizeof(int));
2107 return RIL_ERRNO_INVALID_RESPONSE;
2108 }
2109
2110 int *p_int = (int *) response;
2111
Howard Sue32dbfd2015-01-07 15:55:57 +08002112 numInts = responselen / sizeof(int);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002113 p.writeInt32 (numInts);
2114
2115 /* each int*/
2116 startResponse;
2117 for (int i = 0 ; i < numInts ; i++) {
2118 appendPrintBuf("%s%d,", printBuf, p_int[i]);
2119 p.writeInt32(p_int[i]);
2120 }
2121 removeLastChar;
2122 closeResponse;
2123
2124 return 0;
2125}
2126
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002127/** response is a char **, pointing to an array of char *'s
2128 The parcel will begin with the version */
2129static int responseStringsWithVersion(int version, Parcel &p, void *response, size_t responselen) {
2130 p.writeInt32(version);
2131 return responseStrings(p, response, responselen);
2132}
2133
2134/** response is a char **, pointing to an array of char *'s */
2135static int responseStrings(Parcel &p, void *response, size_t responselen) {
2136 return responseStrings(p, response, responselen, false);
2137}
2138
2139static int responseStringsNetworks(Parcel &p, void *response, size_t responselen) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002140 return responseStrings(p, response, responselen, true);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002141}
2142
2143/** response is a char **, pointing to an array of char *'s */
2144static int responseStrings(Parcel &p, void *response, size_t responselen, bool network_search) {
2145 int numStrings;
2146
2147 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002148 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002149 return RIL_ERRNO_INVALID_RESPONSE;
2150 }
2151 if (responselen % sizeof(char *) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002152 RLOGE("responseStrings: invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002153 (int)responselen, (int)sizeof(char *));
2154 return RIL_ERRNO_INVALID_RESPONSE;
2155 }
2156
2157 if (response == NULL) {
2158 p.writeInt32 (0);
2159 } else {
2160 char **p_cur = (char **) response;
2161
2162 numStrings = responselen / sizeof(char *);
2163 p.writeInt32 (numStrings);
2164
2165 /* each string*/
2166 startResponse;
2167 for (int i = 0 ; i < numStrings ; i++) {
2168 appendPrintBuf("%s%s,", printBuf, (char*)p_cur[i]);
2169 writeStringToParcel (p, p_cur[i]);
2170 }
2171 removeLastChar;
2172 closeResponse;
2173 }
2174 return 0;
2175}
2176
2177/**
2178 * NULL strings are accepted
2179 * FIXME currently ignores responselen
2180 */
2181static int responseString(Parcel &p, void *response, size_t responselen) {
2182 /* one string only */
2183 startResponse;
2184 appendPrintBuf("%s%s", printBuf, (char*)response);
2185 closeResponse;
2186
2187 writeStringToParcel(p, (const char *)response);
2188
2189 return 0;
2190}
2191
2192static int responseVoid(Parcel &p, void *response, size_t responselen) {
2193 startResponse;
2194 removeLastChar;
2195 return 0;
2196}
2197
2198static int responseCallList(Parcel &p, void *response, size_t responselen) {
2199 int num;
2200
2201 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002202 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002203 return RIL_ERRNO_INVALID_RESPONSE;
2204 }
2205
2206 if (responselen % sizeof (RIL_Call *) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002207 RLOGE("responseCallList: invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002208 (int)responselen, (int)sizeof (RIL_Call *));
2209 return RIL_ERRNO_INVALID_RESPONSE;
2210 }
2211
2212 startResponse;
2213 /* number of call info's */
2214 num = responselen / sizeof(RIL_Call *);
2215 p.writeInt32(num);
2216
2217 for (int i = 0 ; i < num ; i++) {
2218 RIL_Call *p_cur = ((RIL_Call **) response)[i];
2219 /* each call info */
2220 p.writeInt32(p_cur->state);
2221 p.writeInt32(p_cur->index);
2222 p.writeInt32(p_cur->toa);
2223 p.writeInt32(p_cur->isMpty);
2224 p.writeInt32(p_cur->isMT);
2225 p.writeInt32(p_cur->als);
2226 p.writeInt32(p_cur->isVoice);
Andreas Schneider29472682015-01-01 19:00:04 +01002227
2228#ifdef MODEM_TYPE_XMM7260
2229 p.writeInt32(p_cur->isVideo);
2230
2231 /* Pass CallDetails */
2232 p.writeInt32(0);
2233 p.writeInt32(0);
2234 writeStringToParcel(p, "");
2235#endif
2236
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002237 p.writeInt32(p_cur->isVoicePrivacy);
2238 writeStringToParcel(p, p_cur->number);
2239 p.writeInt32(p_cur->numberPresentation);
2240 writeStringToParcel(p, p_cur->name);
2241 p.writeInt32(p_cur->namePresentation);
2242 // Remove when partners upgrade to version 3
2243 if ((s_callbacks.version < 3) || (p_cur->uusInfo == NULL || p_cur->uusInfo->uusData == NULL)) {
2244 p.writeInt32(0); /* UUS Information is absent */
2245 } else {
2246 RIL_UUS_Info *uusInfo = p_cur->uusInfo;
2247 p.writeInt32(1); /* UUS Information is present */
2248 p.writeInt32(uusInfo->uusType);
2249 p.writeInt32(uusInfo->uusDcs);
2250 p.writeInt32(uusInfo->uusLength);
2251 p.write(uusInfo->uusData, uusInfo->uusLength);
2252 }
2253 appendPrintBuf("%s[id=%d,%s,toa=%d,",
2254 printBuf,
2255 p_cur->index,
2256 callStateToString(p_cur->state),
2257 p_cur->toa);
2258 appendPrintBuf("%s%s,%s,als=%d,%s,%s,",
2259 printBuf,
2260 (p_cur->isMpty)?"conf":"norm",
2261 (p_cur->isMT)?"mt":"mo",
2262 p_cur->als,
2263 (p_cur->isVoice)?"voc":"nonvoc",
2264 (p_cur->isVoicePrivacy)?"evp":"noevp");
Andreas Schneider29472682015-01-01 19:00:04 +01002265#ifdef MODEM_TYPE_XMM7260
2266 appendPrintBuf("%s,%s,",
2267 printBuf,
2268 (p_cur->isVideo) ? "vid" : "novid");
2269#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002270 appendPrintBuf("%s%s,cli=%d,name='%s',%d]",
2271 printBuf,
2272 p_cur->number,
2273 p_cur->numberPresentation,
2274 p_cur->name,
2275 p_cur->namePresentation);
2276 }
2277 removeLastChar;
2278 closeResponse;
2279
2280 return 0;
2281}
2282
2283static int responseSMS(Parcel &p, void *response, size_t responselen) {
2284 if (response == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002285 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002286 return RIL_ERRNO_INVALID_RESPONSE;
2287 }
2288
2289 if (responselen != sizeof (RIL_SMS_Response) ) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002290 RLOGE("invalid response length %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002291 (int)responselen, (int)sizeof (RIL_SMS_Response));
2292 return RIL_ERRNO_INVALID_RESPONSE;
2293 }
2294
2295 RIL_SMS_Response *p_cur = (RIL_SMS_Response *) response;
2296
2297 p.writeInt32(p_cur->messageRef);
2298 writeStringToParcel(p, p_cur->ackPDU);
2299 p.writeInt32(p_cur->errorCode);
2300
2301 startResponse;
2302 appendPrintBuf("%s%d,%s,%d", printBuf, p_cur->messageRef,
2303 (char*)p_cur->ackPDU, p_cur->errorCode);
2304 closeResponse;
2305
2306 return 0;
2307}
2308
2309static int responseDataCallListV4(Parcel &p, void *response, size_t responselen)
2310{
2311 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002312 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002313 return RIL_ERRNO_INVALID_RESPONSE;
2314 }
2315
2316 if (responselen % sizeof(RIL_Data_Call_Response_v4) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002317 RLOGE("responseDataCallListV4: invalid response length %d expected multiple of %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002318 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v4));
2319 return RIL_ERRNO_INVALID_RESPONSE;
2320 }
2321
Howard Sue32dbfd2015-01-07 15:55:57 +08002322 // Write version
2323 p.writeInt32(4);
2324
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002325 int num = responselen / sizeof(RIL_Data_Call_Response_v4);
2326 p.writeInt32(num);
2327
2328 RIL_Data_Call_Response_v4 *p_cur = (RIL_Data_Call_Response_v4 *) response;
2329 startResponse;
2330 int i;
2331 for (i = 0; i < num; i++) {
2332 p.writeInt32(p_cur[i].cid);
2333 p.writeInt32(p_cur[i].active);
2334 writeStringToParcel(p, p_cur[i].type);
2335 // apn is not used, so don't send.
2336 writeStringToParcel(p, p_cur[i].address);
2337 appendPrintBuf("%s[cid=%d,%s,%s,%s],", printBuf,
2338 p_cur[i].cid,
2339 (p_cur[i].active==0)?"down":"up",
2340 (char*)p_cur[i].type,
2341 (char*)p_cur[i].address);
2342 }
2343 removeLastChar;
2344 closeResponse;
2345
2346 return 0;
2347}
2348
Howard Sue32dbfd2015-01-07 15:55:57 +08002349static int responseDataCallListV6(Parcel &p, void *response, size_t responselen)
2350{
2351 if (response == NULL && responselen != 0) {
2352 RLOGE("invalid response: NULL");
2353 return RIL_ERRNO_INVALID_RESPONSE;
2354 }
2355
2356 if (responselen % sizeof(RIL_Data_Call_Response_v6) != 0) {
2357 RLOGE("responseDataCallListV6: invalid response length %d expected multiple of %d",
2358 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v6));
2359 return RIL_ERRNO_INVALID_RESPONSE;
2360 }
2361
2362 // Write version
2363 p.writeInt32(6);
2364
2365 int num = responselen / sizeof(RIL_Data_Call_Response_v6);
2366 p.writeInt32(num);
2367
2368 RIL_Data_Call_Response_v6 *p_cur = (RIL_Data_Call_Response_v6 *) response;
2369 startResponse;
2370 int i;
2371 for (i = 0; i < num; i++) {
2372 p.writeInt32((int)p_cur[i].status);
2373 p.writeInt32(p_cur[i].suggestedRetryTime);
2374 p.writeInt32(p_cur[i].cid);
2375 p.writeInt32(p_cur[i].active);
2376 writeStringToParcel(p, p_cur[i].type);
2377 writeStringToParcel(p, p_cur[i].ifname);
2378 writeStringToParcel(p, p_cur[i].addresses);
2379 writeStringToParcel(p, p_cur[i].dnses);
2380 writeStringToParcel(p, p_cur[i].addresses);
2381 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s],", printBuf,
2382 p_cur[i].status,
2383 p_cur[i].suggestedRetryTime,
2384 p_cur[i].cid,
2385 (p_cur[i].active==0)?"down":"up",
2386 (char*)p_cur[i].type,
2387 (char*)p_cur[i].ifname,
2388 (char*)p_cur[i].addresses,
2389 (char*)p_cur[i].dnses,
2390 (char*)p_cur[i].addresses);
2391 }
2392 removeLastChar;
2393 closeResponse;
2394
2395 return 0;
2396}
2397
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002398static int responseDataCallList(Parcel &p, void *response, size_t responselen)
2399{
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002400 if (s_callbacks.version < 5) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002401 RLOGD("responseDataCallList: v4");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002402 return responseDataCallListV4(p, response, responselen);
2403 } else {
2404 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002405 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002406 return RIL_ERRNO_INVALID_RESPONSE;
2407 }
2408
Howard Sue32dbfd2015-01-07 15:55:57 +08002409 // Support v6 or v9 with new rils
2410 if (responselen % sizeof(RIL_Data_Call_Response_v6) == 0) {
2411 RLOGD("responseDataCallList: v6");
2412 return responseDataCallListV6(p, response, responselen);
2413 }
2414
2415 if (responselen % sizeof(RIL_Data_Call_Response_v9) != 0) {
2416 RLOGE("responseDataCallList: invalid response length %d expected multiple of %d",
2417 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v9));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002418 return RIL_ERRNO_INVALID_RESPONSE;
2419 }
2420
Howard Sue32dbfd2015-01-07 15:55:57 +08002421 // Write version
2422 p.writeInt32(10);
2423
2424 int num = responselen / sizeof(RIL_Data_Call_Response_v9);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002425 p.writeInt32(num);
2426
Howard Sue32dbfd2015-01-07 15:55:57 +08002427 RIL_Data_Call_Response_v9 *p_cur = (RIL_Data_Call_Response_v9 *) response;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002428 startResponse;
2429 int i;
2430 for (i = 0; i < num; i++) {
2431 p.writeInt32((int)p_cur[i].status);
2432 p.writeInt32(p_cur[i].suggestedRetryTime);
2433 p.writeInt32(p_cur[i].cid);
2434 p.writeInt32(p_cur[i].active);
2435 writeStringToParcel(p, p_cur[i].type);
2436 writeStringToParcel(p, p_cur[i].ifname);
2437 writeStringToParcel(p, p_cur[i].addresses);
2438 writeStringToParcel(p, p_cur[i].dnses);
Howard Sue32dbfd2015-01-07 15:55:57 +08002439 writeStringToParcel(p, p_cur[i].gateways);
2440 writeStringToParcel(p, p_cur[i].pcscf);
2441 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s],", printBuf,
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002442 p_cur[i].status,
2443 p_cur[i].suggestedRetryTime,
2444 p_cur[i].cid,
2445 (p_cur[i].active==0)?"down":"up",
2446 (char*)p_cur[i].type,
2447 (char*)p_cur[i].ifname,
2448 (char*)p_cur[i].addresses,
2449 (char*)p_cur[i].dnses,
Howard Sue32dbfd2015-01-07 15:55:57 +08002450 (char*)p_cur[i].gateways,
2451 (char*)p_cur[i].pcscf);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002452 }
2453 removeLastChar;
2454 closeResponse;
2455 }
2456
2457 return 0;
2458}
2459
2460static int responseSetupDataCall(Parcel &p, void *response, size_t responselen)
2461{
2462 if (s_callbacks.version < 5) {
2463 return responseStringsWithVersion(s_callbacks.version, p, response, responselen);
2464 } else {
2465 return responseDataCallList(p, response, responselen);
2466 }
2467}
2468
2469static int responseRaw(Parcel &p, void *response, size_t responselen) {
2470 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002471 RLOGE("invalid response: NULL with responselen != 0");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002472 return RIL_ERRNO_INVALID_RESPONSE;
2473 }
2474
2475 // The java code reads -1 size as null byte array
2476 if (response == NULL) {
2477 p.writeInt32(-1);
2478 } else {
2479 p.writeInt32(responselen);
2480 p.write(response, responselen);
2481 }
2482
2483 return 0;
2484}
2485
2486
2487static int responseSIM_IO(Parcel &p, void *response, size_t responselen) {
2488 if (response == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002489 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002490 return RIL_ERRNO_INVALID_RESPONSE;
2491 }
2492
2493 if (responselen != sizeof (RIL_SIM_IO_Response) ) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002494 RLOGE("invalid response length was %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002495 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
2496 return RIL_ERRNO_INVALID_RESPONSE;
2497 }
2498
2499 RIL_SIM_IO_Response *p_cur = (RIL_SIM_IO_Response *) response;
2500 p.writeInt32(p_cur->sw1);
2501 p.writeInt32(p_cur->sw2);
2502 writeStringToParcel(p, p_cur->simResponse);
2503
2504 startResponse;
2505 appendPrintBuf("%ssw1=0x%X,sw2=0x%X,%s", printBuf, p_cur->sw1, p_cur->sw2,
2506 (char*)p_cur->simResponse);
2507 closeResponse;
2508
2509
2510 return 0;
2511}
2512
2513static int responseCallForwards(Parcel &p, void *response, size_t responselen) {
2514 int num;
2515
2516 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002517 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002518 return RIL_ERRNO_INVALID_RESPONSE;
2519 }
2520
2521 if (responselen % sizeof(RIL_CallForwardInfo *) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002522 RLOGE("responseCallForwards: invalid response length %d expected multiple of %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002523 (int)responselen, (int)sizeof(RIL_CallForwardInfo *));
2524 return RIL_ERRNO_INVALID_RESPONSE;
2525 }
2526
2527 /* number of call info's */
2528 num = responselen / sizeof(RIL_CallForwardInfo *);
2529 p.writeInt32(num);
2530
2531 startResponse;
2532 for (int i = 0 ; i < num ; i++) {
2533 RIL_CallForwardInfo *p_cur = ((RIL_CallForwardInfo **) response)[i];
2534
2535 p.writeInt32(p_cur->status);
2536 p.writeInt32(p_cur->reason);
2537 p.writeInt32(p_cur->serviceClass);
2538 p.writeInt32(p_cur->toa);
2539 writeStringToParcel(p, p_cur->number);
2540 p.writeInt32(p_cur->timeSeconds);
2541 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
2542 (p_cur->status==1)?"enable":"disable",
2543 p_cur->reason, p_cur->serviceClass, p_cur->toa,
2544 (char*)p_cur->number,
2545 p_cur->timeSeconds);
2546 }
2547 removeLastChar;
2548 closeResponse;
2549
2550 return 0;
2551}
2552
2553static int responseSsn(Parcel &p, void *response, size_t responselen) {
2554 if (response == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002555 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002556 return RIL_ERRNO_INVALID_RESPONSE;
2557 }
2558
2559 if (responselen != sizeof(RIL_SuppSvcNotification)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002560 RLOGE("invalid response length was %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002561 (int)responselen, (int)sizeof (RIL_SuppSvcNotification));
2562 return RIL_ERRNO_INVALID_RESPONSE;
2563 }
2564
2565 RIL_SuppSvcNotification *p_cur = (RIL_SuppSvcNotification *) response;
2566 p.writeInt32(p_cur->notificationType);
2567 p.writeInt32(p_cur->code);
2568 p.writeInt32(p_cur->index);
2569 p.writeInt32(p_cur->type);
2570 writeStringToParcel(p, p_cur->number);
2571
2572 startResponse;
2573 appendPrintBuf("%s%s,code=%d,id=%d,type=%d,%s", printBuf,
2574 (p_cur->notificationType==0)?"mo":"mt",
2575 p_cur->code, p_cur->index, p_cur->type,
2576 (char*)p_cur->number);
2577 closeResponse;
2578
2579 return 0;
2580}
2581
2582static int responseCellList(Parcel &p, void *response, size_t responselen) {
2583 int num;
2584
2585 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002586 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002587 return RIL_ERRNO_INVALID_RESPONSE;
2588 }
2589
2590 if (responselen % sizeof (RIL_NeighboringCell *) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002591 RLOGE("responseCellList: invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002592 (int)responselen, (int)sizeof (RIL_NeighboringCell *));
2593 return RIL_ERRNO_INVALID_RESPONSE;
2594 }
2595
2596 startResponse;
2597 /* number of records */
2598 num = responselen / sizeof(RIL_NeighboringCell *);
2599 p.writeInt32(num);
2600
2601 for (int i = 0 ; i < num ; i++) {
2602 RIL_NeighboringCell *p_cur = ((RIL_NeighboringCell **) response)[i];
2603
2604 p.writeInt32(p_cur->rssi);
2605 writeStringToParcel (p, p_cur->cid);
2606
2607 appendPrintBuf("%s[cid=%s,rssi=%d],", printBuf,
2608 p_cur->cid, p_cur->rssi);
2609 }
2610 removeLastChar;
2611 closeResponse;
2612
2613 return 0;
2614}
2615
2616/**
2617 * Marshall the signalInfoRecord into the parcel if it exists.
2618 */
2619static void marshallSignalInfoRecord(Parcel &p,
2620 RIL_CDMA_SignalInfoRecord &p_signalInfoRecord) {
2621 p.writeInt32(p_signalInfoRecord.isPresent);
2622 p.writeInt32(p_signalInfoRecord.signalType);
2623 p.writeInt32(p_signalInfoRecord.alertPitch);
2624 p.writeInt32(p_signalInfoRecord.signal);
2625}
2626
2627static int responseCdmaInformationRecords(Parcel &p,
2628 void *response, size_t responselen) {
2629 int num;
2630 char* string8 = NULL;
2631 int buffer_lenght;
2632 RIL_CDMA_InformationRecord *infoRec;
2633
2634 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002635 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002636 return RIL_ERRNO_INVALID_RESPONSE;
2637 }
2638
2639 if (responselen != sizeof (RIL_CDMA_InformationRecords)) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002640 RLOGE("responseCdmaInformationRecords: invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002641 (int)responselen, (int)sizeof (RIL_CDMA_InformationRecords *));
2642 return RIL_ERRNO_INVALID_RESPONSE;
2643 }
2644
2645 RIL_CDMA_InformationRecords *p_cur =
2646 (RIL_CDMA_InformationRecords *) response;
2647 num = MIN(p_cur->numberOfInfoRecs, RIL_CDMA_MAX_NUMBER_OF_INFO_RECS);
2648
2649 startResponse;
2650 p.writeInt32(num);
2651
2652 for (int i = 0 ; i < num ; i++) {
2653 infoRec = &p_cur->infoRec[i];
2654 p.writeInt32(infoRec->name);
2655 switch (infoRec->name) {
2656 case RIL_CDMA_DISPLAY_INFO_REC:
2657 case RIL_CDMA_EXTENDED_DISPLAY_INFO_REC:
2658 if (infoRec->rec.display.alpha_len >
2659 CDMA_ALPHA_INFO_BUFFER_LENGTH) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002660 RLOGE("invalid display info response length %d \
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002661 expected not more than %d\n",
2662 (int)infoRec->rec.display.alpha_len,
2663 CDMA_ALPHA_INFO_BUFFER_LENGTH);
2664 return RIL_ERRNO_INVALID_RESPONSE;
2665 }
2666 string8 = (char*) malloc((infoRec->rec.display.alpha_len + 1)
2667 * sizeof(char) );
2668 for (int i = 0 ; i < infoRec->rec.display.alpha_len ; i++) {
2669 string8[i] = infoRec->rec.display.alpha_buf[i];
2670 }
2671 string8[(int)infoRec->rec.display.alpha_len] = '\0';
2672 writeStringToParcel(p, (const char*)string8);
2673 free(string8);
2674 string8 = NULL;
2675 break;
2676 case RIL_CDMA_CALLED_PARTY_NUMBER_INFO_REC:
2677 case RIL_CDMA_CALLING_PARTY_NUMBER_INFO_REC:
2678 case RIL_CDMA_CONNECTED_NUMBER_INFO_REC:
2679 if (infoRec->rec.number.len > CDMA_NUMBER_INFO_BUFFER_LENGTH) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002680 RLOGE("invalid display info response length %d \
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002681 expected not more than %d\n",
2682 (int)infoRec->rec.number.len,
2683 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2684 return RIL_ERRNO_INVALID_RESPONSE;
2685 }
2686 string8 = (char*) malloc((infoRec->rec.number.len + 1)
2687 * sizeof(char) );
2688 for (int i = 0 ; i < infoRec->rec.number.len; i++) {
2689 string8[i] = infoRec->rec.number.buf[i];
2690 }
2691 string8[(int)infoRec->rec.number.len] = '\0';
2692 writeStringToParcel(p, (const char*)string8);
2693 free(string8);
2694 string8 = NULL;
2695 p.writeInt32(infoRec->rec.number.number_type);
2696 p.writeInt32(infoRec->rec.number.number_plan);
2697 p.writeInt32(infoRec->rec.number.pi);
2698 p.writeInt32(infoRec->rec.number.si);
2699 break;
2700 case RIL_CDMA_SIGNAL_INFO_REC:
2701 p.writeInt32(infoRec->rec.signal.isPresent);
2702 p.writeInt32(infoRec->rec.signal.signalType);
2703 p.writeInt32(infoRec->rec.signal.alertPitch);
2704 p.writeInt32(infoRec->rec.signal.signal);
2705
2706 appendPrintBuf("%sisPresent=%X, signalType=%X, \
2707 alertPitch=%X, signal=%X, ",
2708 printBuf, (int)infoRec->rec.signal.isPresent,
2709 (int)infoRec->rec.signal.signalType,
2710 (int)infoRec->rec.signal.alertPitch,
2711 (int)infoRec->rec.signal.signal);
2712 removeLastChar;
2713 break;
2714 case RIL_CDMA_REDIRECTING_NUMBER_INFO_REC:
2715 if (infoRec->rec.redir.redirectingNumber.len >
2716 CDMA_NUMBER_INFO_BUFFER_LENGTH) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002717 RLOGE("invalid display info response length %d \
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002718 expected not more than %d\n",
2719 (int)infoRec->rec.redir.redirectingNumber.len,
2720 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2721 return RIL_ERRNO_INVALID_RESPONSE;
2722 }
2723 string8 = (char*) malloc((infoRec->rec.redir.redirectingNumber
2724 .len + 1) * sizeof(char) );
2725 for (int i = 0;
2726 i < infoRec->rec.redir.redirectingNumber.len;
2727 i++) {
2728 string8[i] = infoRec->rec.redir.redirectingNumber.buf[i];
2729 }
2730 string8[(int)infoRec->rec.redir.redirectingNumber.len] = '\0';
2731 writeStringToParcel(p, (const char*)string8);
2732 free(string8);
2733 string8 = NULL;
2734 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_type);
2735 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_plan);
2736 p.writeInt32(infoRec->rec.redir.redirectingNumber.pi);
2737 p.writeInt32(infoRec->rec.redir.redirectingNumber.si);
2738 p.writeInt32(infoRec->rec.redir.redirectingReason);
2739 break;
2740 case RIL_CDMA_LINE_CONTROL_INFO_REC:
2741 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPolarityIncluded);
2742 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlToggle);
2743 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlReverse);
2744 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2745
2746 appendPrintBuf("%slineCtrlPolarityIncluded=%d, \
2747 lineCtrlToggle=%d, lineCtrlReverse=%d, \
2748 lineCtrlPowerDenial=%d, ", printBuf,
2749 (int)infoRec->rec.lineCtrl.lineCtrlPolarityIncluded,
2750 (int)infoRec->rec.lineCtrl.lineCtrlToggle,
2751 (int)infoRec->rec.lineCtrl.lineCtrlReverse,
2752 (int)infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2753 removeLastChar;
2754 break;
2755 case RIL_CDMA_T53_CLIR_INFO_REC:
2756 p.writeInt32((int)(infoRec->rec.clir.cause));
2757
2758 appendPrintBuf("%scause%d", printBuf, infoRec->rec.clir.cause);
2759 removeLastChar;
2760 break;
2761 case RIL_CDMA_T53_AUDIO_CONTROL_INFO_REC:
2762 p.writeInt32(infoRec->rec.audioCtrl.upLink);
2763 p.writeInt32(infoRec->rec.audioCtrl.downLink);
2764
2765 appendPrintBuf("%supLink=%d, downLink=%d, ", printBuf,
2766 infoRec->rec.audioCtrl.upLink,
2767 infoRec->rec.audioCtrl.downLink);
2768 removeLastChar;
2769 break;
2770 case RIL_CDMA_T53_RELEASE_INFO_REC:
2771 // TODO(Moto): See David Krause, he has the answer:)
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002772 RLOGE("RIL_CDMA_T53_RELEASE_INFO_REC: return INVALID_RESPONSE");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002773 return RIL_ERRNO_INVALID_RESPONSE;
2774 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002775 RLOGE("Incorrect name value");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002776 return RIL_ERRNO_INVALID_RESPONSE;
2777 }
2778 }
2779 closeResponse;
2780
2781 return 0;
2782}
2783
2784static int responseRilSignalStrength(Parcel &p,
2785 void *response, size_t responselen) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002786 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002787 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002788 return RIL_ERRNO_INVALID_RESPONSE;
2789 }
2790
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002791 if (responselen >= sizeof (RIL_SignalStrength_v5)) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002792 RIL_SignalStrength_v10 *p_cur = ((RIL_SignalStrength_v10 *) response);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002793
Howard Sue32dbfd2015-01-07 15:55:57 +08002794 p.writeInt32(p_cur->GW_SignalStrength.signalStrength);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002795 p.writeInt32(p_cur->GW_SignalStrength.bitErrorRate);
Howard Sue32dbfd2015-01-07 15:55:57 +08002796 p.writeInt32(p_cur->CDMA_SignalStrength.dbm);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002797 p.writeInt32(p_cur->CDMA_SignalStrength.ecio);
Howard Sue32dbfd2015-01-07 15:55:57 +08002798 p.writeInt32(p_cur->EVDO_SignalStrength.dbm);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002799 p.writeInt32(p_cur->EVDO_SignalStrength.ecio);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002800 p.writeInt32(p_cur->EVDO_SignalStrength.signalNoiseRatio);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002801 if (responselen >= sizeof (RIL_SignalStrength_v6)) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002802 /*
Ethan Chend6e30652013-08-04 22:49:56 -07002803 * Fixup LTE for backwards compatibility
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002804 */
Ethan Chend6e30652013-08-04 22:49:56 -07002805 if (s_callbacks.version <= 6) {
2806 // signalStrength: -1 -> 99
2807 if (p_cur->LTE_SignalStrength.signalStrength == -1) {
2808 p_cur->LTE_SignalStrength.signalStrength = 99;
2809 }
2810 // rsrp: -1 -> INT_MAX all other negative value to positive.
2811 // So remap here
2812 if (p_cur->LTE_SignalStrength.rsrp == -1) {
2813 p_cur->LTE_SignalStrength.rsrp = INT_MAX;
2814 } else if (p_cur->LTE_SignalStrength.rsrp < -1) {
2815 p_cur->LTE_SignalStrength.rsrp = -p_cur->LTE_SignalStrength.rsrp;
2816 }
2817 // rsrq: -1 -> INT_MAX
2818 if (p_cur->LTE_SignalStrength.rsrq == -1) {
2819 p_cur->LTE_SignalStrength.rsrq = INT_MAX;
2820 }
2821 // Not remapping rssnr is already using INT_MAX
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002822
Ethan Chend6e30652013-08-04 22:49:56 -07002823 // cqi: -1 -> INT_MAX
2824 if (p_cur->LTE_SignalStrength.cqi == -1) {
2825 p_cur->LTE_SignalStrength.cqi = INT_MAX;
2826 }
2827 }
2828 p.writeInt32(p_cur->LTE_SignalStrength.signalStrength);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002829 p.writeInt32(p_cur->LTE_SignalStrength.rsrp);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002830 p.writeInt32(p_cur->LTE_SignalStrength.rsrq);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002831 p.writeInt32(p_cur->LTE_SignalStrength.rssnr);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002832 p.writeInt32(p_cur->LTE_SignalStrength.cqi);
Howard Sue32dbfd2015-01-07 15:55:57 +08002833 if (responselen >= sizeof (RIL_SignalStrength_v10)) {
2834 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
2835 } else {
2836 p.writeInt32(INT_MAX);
2837 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002838 } else {
Ethan Chend6e30652013-08-04 22:49:56 -07002839 p.writeInt32(99);
2840 p.writeInt32(INT_MAX);
2841 p.writeInt32(INT_MAX);
2842 p.writeInt32(INT_MAX);
2843 p.writeInt32(INT_MAX);
Howard Sue32dbfd2015-01-07 15:55:57 +08002844 p.writeInt32(INT_MAX);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002845 }
2846
2847 startResponse;
2848 appendPrintBuf("%s[signalStrength=%d,bitErrorRate=%d,\
2849 CDMA_SS.dbm=%d,CDMA_SSecio=%d,\
2850 EVDO_SS.dbm=%d,EVDO_SS.ecio=%d,\
2851 EVDO_SS.signalNoiseRatio=%d,\
2852 LTE_SS.signalStrength=%d,LTE_SS.rsrp=%d,LTE_SS.rsrq=%d,\
Howard Sue32dbfd2015-01-07 15:55:57 +08002853 LTE_SS.rssnr=%d,LTE_SS.cqi=%d,TDSCDMA_SS.rscp=%d]",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002854 printBuf,
Howard Sue32dbfd2015-01-07 15:55:57 +08002855 p_cur->GW_SignalStrength.signalStrength,
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002856 p_cur->GW_SignalStrength.bitErrorRate,
Howard Sue32dbfd2015-01-07 15:55:57 +08002857 p_cur->CDMA_SignalStrength.dbm,
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002858 p_cur->CDMA_SignalStrength.ecio,
Howard Sue32dbfd2015-01-07 15:55:57 +08002859 p_cur->EVDO_SignalStrength.dbm,
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002860 p_cur->EVDO_SignalStrength.ecio,
2861 p_cur->EVDO_SignalStrength.signalNoiseRatio,
2862 p_cur->LTE_SignalStrength.signalStrength,
2863 p_cur->LTE_SignalStrength.rsrp,
2864 p_cur->LTE_SignalStrength.rsrq,
2865 p_cur->LTE_SignalStrength.rssnr,
Howard Sue32dbfd2015-01-07 15:55:57 +08002866 p_cur->LTE_SignalStrength.cqi,
2867 p_cur->TD_SCDMA_SignalStrength.rscp);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002868 closeResponse;
2869
2870 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002871 RLOGE("invalid response length");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002872 return RIL_ERRNO_INVALID_RESPONSE;
2873 }
2874
2875 return 0;
2876}
2877
2878static int responseCallRing(Parcel &p, void *response, size_t responselen) {
2879 if ((response == NULL) || (responselen == 0)) {
2880 return responseVoid(p, response, responselen);
2881 } else {
2882 return responseCdmaSignalInfoRecord(p, response, responselen);
2883 }
2884}
2885
2886static int responseCdmaSignalInfoRecord(Parcel &p, void *response, size_t responselen) {
2887 if (response == NULL || responselen == 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002888 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002889 return RIL_ERRNO_INVALID_RESPONSE;
2890 }
2891
2892 if (responselen != sizeof (RIL_CDMA_SignalInfoRecord)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002893 RLOGE("invalid response length %d expected sizeof (RIL_CDMA_SignalInfoRecord) of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002894 (int)responselen, (int)sizeof (RIL_CDMA_SignalInfoRecord));
2895 return RIL_ERRNO_INVALID_RESPONSE;
2896 }
2897
2898 startResponse;
2899
2900 RIL_CDMA_SignalInfoRecord *p_cur = ((RIL_CDMA_SignalInfoRecord *) response);
2901 marshallSignalInfoRecord(p, *p_cur);
2902
2903 appendPrintBuf("%s[isPresent=%d,signalType=%d,alertPitch=%d\
2904 signal=%d]",
2905 printBuf,
2906 p_cur->isPresent,
2907 p_cur->signalType,
2908 p_cur->alertPitch,
2909 p_cur->signal);
2910
2911 closeResponse;
2912 return 0;
2913}
2914
2915static int responseCdmaCallWaiting(Parcel &p, void *response,
2916 size_t responselen) {
2917 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002918 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002919 return RIL_ERRNO_INVALID_RESPONSE;
2920 }
2921
2922 if (responselen < sizeof(RIL_CDMA_CallWaiting_v6)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002923 RLOGW("Upgrade to ril version %d\n", RIL_VERSION);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002924 }
2925
2926 RIL_CDMA_CallWaiting_v6 *p_cur = ((RIL_CDMA_CallWaiting_v6 *) response);
2927
2928 writeStringToParcel(p, p_cur->number);
2929 p.writeInt32(p_cur->numberPresentation);
2930 writeStringToParcel(p, p_cur->name);
2931 marshallSignalInfoRecord(p, p_cur->signalInfoRecord);
2932
2933 if (responselen >= sizeof(RIL_CDMA_CallWaiting_v6)) {
2934 p.writeInt32(p_cur->number_type);
2935 p.writeInt32(p_cur->number_plan);
2936 } else {
2937 p.writeInt32(0);
2938 p.writeInt32(0);
2939 }
2940
2941 startResponse;
2942 appendPrintBuf("%snumber=%s,numberPresentation=%d, name=%s,\
2943 signalInfoRecord[isPresent=%d,signalType=%d,alertPitch=%d\
2944 signal=%d,number_type=%d,number_plan=%d]",
2945 printBuf,
2946 p_cur->number,
2947 p_cur->numberPresentation,
2948 p_cur->name,
2949 p_cur->signalInfoRecord.isPresent,
2950 p_cur->signalInfoRecord.signalType,
2951 p_cur->signalInfoRecord.alertPitch,
2952 p_cur->signalInfoRecord.signal,
2953 p_cur->number_type,
2954 p_cur->number_plan);
2955 closeResponse;
2956
2957 return 0;
2958}
2959
2960static int responseSimRefresh(Parcel &p, void *response, size_t responselen) {
2961 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002962 RLOGE("responseSimRefresh: invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002963 return RIL_ERRNO_INVALID_RESPONSE;
2964 }
2965
2966 startResponse;
2967 if (s_callbacks.version == 7) {
2968 RIL_SimRefreshResponse_v7 *p_cur = ((RIL_SimRefreshResponse_v7 *) response);
2969 p.writeInt32(p_cur->result);
2970 p.writeInt32(p_cur->ef_id);
2971 writeStringToParcel(p, p_cur->aid);
2972
2973 appendPrintBuf("%sresult=%d, ef_id=%d, aid=%s",
2974 printBuf,
2975 p_cur->result,
2976 p_cur->ef_id,
2977 p_cur->aid);
2978 } else {
2979 int *p_cur = ((int *) response);
2980 p.writeInt32(p_cur[0]);
2981 p.writeInt32(p_cur[1]);
2982 writeStringToParcel(p, NULL);
2983
2984 appendPrintBuf("%sresult=%d, ef_id=%d",
2985 printBuf,
2986 p_cur[0],
2987 p_cur[1]);
2988 }
2989 closeResponse;
2990
2991 return 0;
2992}
2993
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002994static int responseCellInfoList(Parcel &p, void *response, size_t responselen)
2995{
2996 if (response == NULL && responselen != 0) {
2997 RLOGE("invalid response: NULL");
2998 return RIL_ERRNO_INVALID_RESPONSE;
2999 }
3000
3001 if (responselen % sizeof(RIL_CellInfo) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08003002 RLOGE("responseCellInfoList: invalid response length %d expected multiple of %d",
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003003 (int)responselen, (int)sizeof(RIL_CellInfo));
3004 return RIL_ERRNO_INVALID_RESPONSE;
3005 }
3006
3007 int num = responselen / sizeof(RIL_CellInfo);
3008 p.writeInt32(num);
3009
3010 RIL_CellInfo *p_cur = (RIL_CellInfo *) response;
3011 startResponse;
3012 int i;
3013 for (i = 0; i < num; i++) {
3014 appendPrintBuf("%s[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", printBuf, i,
3015 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
3016 p.writeInt32((int)p_cur->cellInfoType);
3017 p.writeInt32(p_cur->registered);
3018 p.writeInt32(p_cur->timeStampType);
3019 p.writeInt64(p_cur->timeStamp);
3020 switch(p_cur->cellInfoType) {
3021 case RIL_CELL_INFO_TYPE_GSM: {
3022 appendPrintBuf("%s GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,", printBuf,
3023 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
3024 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
3025 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
3026 p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3027 appendPrintBuf("%s gsmSS: ss=%d,ber=%d],", printBuf,
3028 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
3029 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3030
3031 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
3032 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
3033 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
3034 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3035 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
3036 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3037 break;
3038 }
3039 case RIL_CELL_INFO_TYPE_WCDMA: {
3040 appendPrintBuf("%s WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,", printBuf,
3041 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
3042 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
3043 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
3044 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
3045 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3046 appendPrintBuf("%s wcdmaSS: ss=%d,ber=%d],", printBuf,
3047 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
3048 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3049
3050 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
3051 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
3052 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
3053 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
3054 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3055 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
3056 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3057 break;
3058 }
3059 case RIL_CELL_INFO_TYPE_CDMA: {
3060 appendPrintBuf("%s CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d", printBuf,
3061 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
3062 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
3063 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
3064 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
3065 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3066
3067 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
3068 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
3069 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
3070 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
3071 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3072
3073 appendPrintBuf("%s cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d", printBuf,
3074 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
3075 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
3076 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
3077 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
3078 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3079
3080 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
3081 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
3082 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
3083 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
3084 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3085 break;
3086 }
3087 case RIL_CELL_INFO_TYPE_LTE: {
3088 appendPrintBuf("%s LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d", printBuf,
3089 p_cur->CellInfo.lte.cellIdentityLte.mcc,
3090 p_cur->CellInfo.lte.cellIdentityLte.mnc,
3091 p_cur->CellInfo.lte.cellIdentityLte.ci,
3092 p_cur->CellInfo.lte.cellIdentityLte.pci,
3093 p_cur->CellInfo.lte.cellIdentityLte.tac);
3094
3095 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
3096 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
3097 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
3098 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
3099 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
3100
3101 appendPrintBuf("%s lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d", printBuf,
3102 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
3103 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
3104 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
3105 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
3106 p_cur->CellInfo.lte.signalStrengthLte.cqi,
3107 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3108 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
3109 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
3110 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
3111 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
3112 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
3113 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3114 break;
3115 }
Howard Sue32dbfd2015-01-07 15:55:57 +08003116 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
3117 appendPrintBuf("%s TDSCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,cpid=%d,", printBuf,
3118 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc,
3119 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc,
3120 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac,
3121 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid,
3122 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3123 appendPrintBuf("%s tdscdmaSS: rscp=%d],", printBuf,
3124 p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3125
3126 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
3127 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
3128 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
3129 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
3130 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3131 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3132 break;
3133 }
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003134 }
3135 p_cur += 1;
3136 }
3137 removeLastChar;
3138 closeResponse;
3139
3140 return 0;
3141}
3142
Howard Sue32dbfd2015-01-07 15:55:57 +08003143static int responseHardwareConfig(Parcel &p, void *response, size_t responselen)
3144{
3145 if (response == NULL && responselen != 0) {
3146 RLOGE("invalid response: NULL");
3147 return RIL_ERRNO_INVALID_RESPONSE;
3148 }
3149
3150 if (responselen % sizeof(RIL_HardwareConfig) != 0) {
3151 RLOGE("responseHardwareConfig: invalid response length %d expected multiple of %d",
3152 (int)responselen, (int)sizeof(RIL_HardwareConfig));
3153 return RIL_ERRNO_INVALID_RESPONSE;
3154 }
3155
3156 int num = responselen / sizeof(RIL_HardwareConfig);
3157 int i;
3158 RIL_HardwareConfig *p_cur = (RIL_HardwareConfig *) response;
3159
3160 p.writeInt32(num);
3161
3162 startResponse;
3163 for (i = 0; i < num; i++) {
3164 switch (p_cur[i].type) {
3165 case RIL_HARDWARE_CONFIG_MODEM: {
3166 writeStringToParcel(p, p_cur[i].uuid);
3167 p.writeInt32((int)p_cur[i].state);
3168 p.writeInt32(p_cur[i].cfg.modem.rat);
3169 p.writeInt32(p_cur[i].cfg.modem.maxVoice);
3170 p.writeInt32(p_cur[i].cfg.modem.maxData);
3171 p.writeInt32(p_cur[i].cfg.modem.maxStandby);
3172
3173 appendPrintBuf("%s modem: uuid=%s,state=%d,rat=%08x,maxV=%d,maxD=%d,maxS=%d", printBuf,
3174 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.modem.rat,
3175 p_cur[i].cfg.modem.maxVoice, p_cur[i].cfg.modem.maxData, p_cur[i].cfg.modem.maxStandby);
3176 break;
3177 }
3178 case RIL_HARDWARE_CONFIG_SIM: {
3179 writeStringToParcel(p, p_cur[i].uuid);
3180 p.writeInt32((int)p_cur[i].state);
3181 writeStringToParcel(p, p_cur[i].cfg.sim.modemUuid);
3182
3183 appendPrintBuf("%s sim: uuid=%s,state=%d,modem-uuid=%s", printBuf,
3184 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.sim.modemUuid);
3185 break;
3186 }
3187 }
3188 }
3189 removeLastChar;
3190 closeResponse;
3191 return 0;
3192}
3193
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003194static void triggerEvLoop() {
3195 int ret;
3196 if (!pthread_equal(pthread_self(), s_tid_dispatch)) {
3197 /* trigger event loop to wakeup. No reason to do this,
3198 * if we're in the event loop thread */
3199 do {
3200 ret = write (s_fdWakeupWrite, " ", 1);
3201 } while (ret < 0 && errno == EINTR);
3202 }
3203}
3204
3205static void rilEventAddWakeup(struct ril_event *ev) {
3206 ril_event_add(ev);
3207 triggerEvLoop();
3208}
3209
3210static void sendSimStatusAppInfo(Parcel &p, int num_apps, RIL_AppStatus appStatus[]) {
3211 p.writeInt32(num_apps);
3212 startResponse;
3213 for (int i = 0; i < num_apps; i++) {
3214 p.writeInt32(appStatus[i].app_type);
3215 p.writeInt32(appStatus[i].app_state);
3216 p.writeInt32(appStatus[i].perso_substate);
3217 writeStringToParcel(p, (const char*)(appStatus[i].aid_ptr));
3218 writeStringToParcel(p, (const char*)
3219 (appStatus[i].app_label_ptr));
3220 p.writeInt32(appStatus[i].pin1_replaced);
3221 p.writeInt32(appStatus[i].pin1);
3222 p.writeInt32(appStatus[i].pin2);
3223 appendPrintBuf("%s[app_type=%d,app_state=%d,perso_substate=%d,\
3224 aid_ptr=%s,app_label_ptr=%s,pin1_replaced=%d,pin1=%d,pin2=%d],",
3225 printBuf,
3226 appStatus[i].app_type,
3227 appStatus[i].app_state,
3228 appStatus[i].perso_substate,
3229 appStatus[i].aid_ptr,
3230 appStatus[i].app_label_ptr,
3231 appStatus[i].pin1_replaced,
3232 appStatus[i].pin1,
3233 appStatus[i].pin2);
3234 }
3235 closeResponse;
3236}
3237
3238static int responseSimStatus(Parcel &p, void *response, size_t responselen) {
Howard Sue32dbfd2015-01-07 15:55:57 +08003239 int i;
3240
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003241 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003242 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003243 return RIL_ERRNO_INVALID_RESPONSE;
3244 }
3245
3246 if (responselen == sizeof (RIL_CardStatus_v6)) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003247 RIL_CardStatus_v6 *p_cur = ((RIL_CardStatus_v6 *) response);
3248
3249 p.writeInt32(p_cur->card_state);
3250 p.writeInt32(p_cur->universal_pin_state);
3251 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3252 p.writeInt32(p_cur->cdma_subscription_app_index);
3253 p.writeInt32(p_cur->ims_subscription_app_index);
3254
3255 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
3256 } else if (responselen == sizeof (RIL_CardStatus_v5)) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003257 RIL_CardStatus_v5 *p_cur = ((RIL_CardStatus_v5 *) response);
3258
3259 p.writeInt32(p_cur->card_state);
3260 p.writeInt32(p_cur->universal_pin_state);
3261 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3262 p.writeInt32(p_cur->cdma_subscription_app_index);
3263 p.writeInt32(-1);
3264
3265 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
3266 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003267 RLOGE("responseSimStatus: A RilCardStatus_v6 or _v5 expected\n");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003268 return RIL_ERRNO_INVALID_RESPONSE;
3269 }
3270
3271 return 0;
3272}
3273
3274static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3275 int num = responselen / sizeof(RIL_GSM_BroadcastSmsConfigInfo *);
3276 p.writeInt32(num);
3277
3278 startResponse;
3279 RIL_GSM_BroadcastSmsConfigInfo **p_cur =
3280 (RIL_GSM_BroadcastSmsConfigInfo **) response;
3281 for (int i = 0; i < num; i++) {
3282 p.writeInt32(p_cur[i]->fromServiceId);
3283 p.writeInt32(p_cur[i]->toServiceId);
3284 p.writeInt32(p_cur[i]->fromCodeScheme);
3285 p.writeInt32(p_cur[i]->toCodeScheme);
3286 p.writeInt32(p_cur[i]->selected);
3287
3288 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId=%d, \
3289 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]",
3290 printBuf, i, p_cur[i]->fromServiceId, p_cur[i]->toServiceId,
3291 p_cur[i]->fromCodeScheme, p_cur[i]->toCodeScheme,
3292 p_cur[i]->selected);
3293 }
3294 closeResponse;
3295
3296 return 0;
3297}
3298
3299static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3300 RIL_CDMA_BroadcastSmsConfigInfo **p_cur =
3301 (RIL_CDMA_BroadcastSmsConfigInfo **) response;
3302
3303 int num = responselen / sizeof (RIL_CDMA_BroadcastSmsConfigInfo *);
3304 p.writeInt32(num);
3305
3306 startResponse;
3307 for (int i = 0 ; i < num ; i++ ) {
3308 p.writeInt32(p_cur[i]->service_category);
3309 p.writeInt32(p_cur[i]->language);
3310 p.writeInt32(p_cur[i]->selected);
3311
3312 appendPrintBuf("%s [%d: srvice_category=%d, language =%d, \
3313 selected =%d], ",
3314 printBuf, i, p_cur[i]->service_category, p_cur[i]->language,
3315 p_cur[i]->selected);
3316 }
3317 closeResponse;
3318
3319 return 0;
3320}
3321
3322static int responseCdmaSms(Parcel &p, void *response, size_t responselen) {
3323 int num;
3324 int digitCount;
3325 int digitLimit;
3326 uint8_t uct;
3327 void* dest;
3328
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003329 RLOGD("Inside responseCdmaSms");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003330
3331 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003332 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003333 return RIL_ERRNO_INVALID_RESPONSE;
3334 }
3335
3336 if (responselen != sizeof(RIL_CDMA_SMS_Message)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003337 RLOGE("invalid response length was %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003338 (int)responselen, (int)sizeof(RIL_CDMA_SMS_Message));
3339 return RIL_ERRNO_INVALID_RESPONSE;
3340 }
3341
3342 RIL_CDMA_SMS_Message *p_cur = (RIL_CDMA_SMS_Message *) response;
3343 p.writeInt32(p_cur->uTeleserviceID);
3344 p.write(&(p_cur->bIsServicePresent),sizeof(uct));
3345 p.writeInt32(p_cur->uServicecategory);
3346 p.writeInt32(p_cur->sAddress.digit_mode);
3347 p.writeInt32(p_cur->sAddress.number_mode);
3348 p.writeInt32(p_cur->sAddress.number_type);
3349 p.writeInt32(p_cur->sAddress.number_plan);
3350 p.write(&(p_cur->sAddress.number_of_digits), sizeof(uct));
3351 digitLimit= MIN((p_cur->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
3352 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3353 p.write(&(p_cur->sAddress.digits[digitCount]),sizeof(uct));
3354 }
3355
3356 p.writeInt32(p_cur->sSubAddress.subaddressType);
3357 p.write(&(p_cur->sSubAddress.odd),sizeof(uct));
3358 p.write(&(p_cur->sSubAddress.number_of_digits),sizeof(uct));
3359 digitLimit= MIN((p_cur->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
3360 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3361 p.write(&(p_cur->sSubAddress.digits[digitCount]),sizeof(uct));
3362 }
3363
3364 digitLimit= MIN((p_cur->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
3365 p.writeInt32(p_cur->uBearerDataLen);
3366 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3367 p.write(&(p_cur->aBearerData[digitCount]), sizeof(uct));
3368 }
3369
3370 startResponse;
3371 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
3372 sAddress.digit_mode=%d, sAddress.number_mode=%d, sAddress.number_type=%d, ",
3373 printBuf, p_cur->uTeleserviceID,p_cur->bIsServicePresent,p_cur->uServicecategory,
3374 p_cur->sAddress.digit_mode, p_cur->sAddress.number_mode,p_cur->sAddress.number_type);
3375 closeResponse;
3376
3377 return 0;
3378}
3379
Howard Sue32dbfd2015-01-07 15:55:57 +08003380static int responseDcRtInfo(Parcel &p, void *response, size_t responselen)
3381{
3382 int num = responselen / sizeof(RIL_DcRtInfo);
3383 if ((responselen % sizeof(RIL_DcRtInfo) != 0) || (num != 1)) {
3384 RLOGE("responseDcRtInfo: invalid response length %d expected multiple of %d",
3385 (int)responselen, (int)sizeof(RIL_DcRtInfo));
3386 return RIL_ERRNO_INVALID_RESPONSE;
3387 }
3388
3389 startResponse;
3390 RIL_DcRtInfo *pDcRtInfo = (RIL_DcRtInfo *)response;
3391 p.writeInt64(pDcRtInfo->time);
3392 p.writeInt32(pDcRtInfo->powerState);
3393 appendPrintBuf("%s[time=%d,powerState=%d]", printBuf,
3394 pDcRtInfo->time,
3395 pDcRtInfo->powerState);
3396 closeResponse;
3397
3398 return 0;
3399}
3400
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003401/**
3402 * A write on the wakeup fd is done just to pop us out of select()
3403 * We empty the buffer here and then ril_event will reset the timers on the
3404 * way back down
3405 */
3406static void processWakeupCallback(int fd, short flags, void *param) {
3407 char buff[16];
3408 int ret;
3409
Ethan Chend6e30652013-08-04 22:49:56 -07003410 RLOGV("processWakeupCallback");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003411
3412 /* empty our wakeup socket out */
3413 do {
3414 ret = read(s_fdWakeupRead, &buff, sizeof(buff));
3415 } while (ret > 0 || (ret < 0 && errno == EINTR));
3416}
3417
Howard Sue32dbfd2015-01-07 15:55:57 +08003418static void onCommandsSocketClosed(RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003419 int ret;
3420 RequestInfo *p_cur;
Howard Sue32dbfd2015-01-07 15:55:57 +08003421 /* Hook for current context
3422 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
3423 pthread_mutex_t * pendingRequestsMutexHook = &s_pendingRequestsMutex;
3424 /* pendingRequestsHook refer to &s_pendingRequests */
3425 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003426
Howard Sue32dbfd2015-01-07 15:55:57 +08003427#if (SIM_COUNT >= 2)
3428 if (socket_id == RIL_SOCKET_2) {
3429 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
3430 pendingRequestsHook = &s_pendingRequests_socket2;
3431 }
3432#if (SIM_COUNT >= 3)
3433 else if (socket_id == RIL_SOCKET_3) {
3434 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
3435 pendingRequestsHook = &s_pendingRequests_socket3;
3436 }
3437#endif
3438#if (SIM_COUNT >= 4)
3439 else if (socket_id == RIL_SOCKET_4) {
3440 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
3441 pendingRequestsHook = &s_pendingRequests_socket4;
3442 }
3443#endif
3444#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003445 /* mark pending requests as "cancelled" so we dont report responses */
Howard Sue32dbfd2015-01-07 15:55:57 +08003446 ret = pthread_mutex_lock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003447 assert (ret == 0);
3448
Howard Sue32dbfd2015-01-07 15:55:57 +08003449 p_cur = *pendingRequestsHook;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003450
Howard Sue32dbfd2015-01-07 15:55:57 +08003451 for (p_cur = *pendingRequestsHook
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003452 ; p_cur != NULL
3453 ; p_cur = p_cur->p_next
3454 ) {
3455 p_cur->cancelled = 1;
3456 }
3457
Howard Sue32dbfd2015-01-07 15:55:57 +08003458 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003459 assert (ret == 0);
3460}
3461
3462static void processCommandsCallback(int fd, short flags, void *param) {
3463 RecordStream *p_rs;
3464 void *p_record;
3465 size_t recordlen;
3466 int ret;
Howard Sue32dbfd2015-01-07 15:55:57 +08003467 SocketListenParam *p_info = (SocketListenParam *)param;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003468
Howard Sue32dbfd2015-01-07 15:55:57 +08003469 assert(fd == p_info->fdCommand);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003470
Howard Sue32dbfd2015-01-07 15:55:57 +08003471 p_rs = p_info->p_rs;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003472
3473 for (;;) {
3474 /* loop until EAGAIN/EINTR, end of stream, or other error */
3475 ret = record_stream_get_next(p_rs, &p_record, &recordlen);
3476
3477 if (ret == 0 && p_record == NULL) {
3478 /* end-of-stream */
3479 break;
3480 } else if (ret < 0) {
3481 break;
3482 } else if (ret == 0) { /* && p_record != NULL */
Howard Sue32dbfd2015-01-07 15:55:57 +08003483 processCommandBuffer(p_record, recordlen, p_info->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003484 }
3485 }
3486
3487 if (ret == 0 || !(errno == EAGAIN || errno == EINTR)) {
3488 /* fatal error or end-of-stream */
3489 if (ret != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003490 RLOGE("error on reading command socket errno:%d\n", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003491 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003492 RLOGW("EOS. Closing command socket.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003493 }
3494
Howard Sue32dbfd2015-01-07 15:55:57 +08003495 close(fd);
3496 p_info->fdCommand = -1;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003497
Howard Sue32dbfd2015-01-07 15:55:57 +08003498 ril_event_del(p_info->commands_event);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003499
3500 record_stream_free(p_rs);
3501
3502 /* start listening for new connections again */
3503 rilEventAddWakeup(&s_listen_event);
3504
Howard Sue32dbfd2015-01-07 15:55:57 +08003505 onCommandsSocketClosed(p_info->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003506 }
3507}
3508
Howard Sue32dbfd2015-01-07 15:55:57 +08003509static void onNewCommandConnect(RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003510 // Inform we are connected and the ril version
3511 int rilVer = s_callbacks.version;
Howard Sue32dbfd2015-01-07 15:55:57 +08003512 RIL_UNSOL_RESPONSE(RIL_UNSOL_RIL_CONNECTED,
3513 &rilVer, sizeof(rilVer), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003514
3515 // implicit radio state changed
Howard Sue32dbfd2015-01-07 15:55:57 +08003516 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
3517 NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003518
3519 // Send last NITZ time data, in case it was missed
3520 if (s_lastNITZTimeData != NULL) {
Howard Sue32dbfd2015-01-07 15:55:57 +08003521 sendResponseRaw(s_lastNITZTimeData, s_lastNITZTimeDataSize, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003522
3523 free(s_lastNITZTimeData);
3524 s_lastNITZTimeData = NULL;
3525 }
3526
3527 // Get version string
3528 if (s_callbacks.getVersion != NULL) {
3529 const char *version;
3530 version = s_callbacks.getVersion();
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003531 RLOGI("RIL Daemon version: %s\n", version);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003532
3533 property_set(PROPERTY_RIL_IMPL, version);
3534 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003535 RLOGI("RIL Daemon version: unavailable\n");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003536 property_set(PROPERTY_RIL_IMPL, "unavailable");
3537 }
3538
3539}
3540
3541static void listenCallback (int fd, short flags, void *param) {
3542 int ret;
3543 int err;
3544 int is_phone_socket;
Howard Sue32dbfd2015-01-07 15:55:57 +08003545 int fdCommand = -1;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003546 RecordStream *p_rs;
Howard Sue32dbfd2015-01-07 15:55:57 +08003547 SocketListenParam *p_info = (SocketListenParam *)param;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003548
3549 struct sockaddr_un peeraddr;
3550 socklen_t socklen = sizeof (peeraddr);
3551
3552 struct ucred creds;
3553 socklen_t szCreds = sizeof(creds);
3554
3555 struct passwd *pwd = NULL;
3556
Howard Sue32dbfd2015-01-07 15:55:57 +08003557 assert (*p_info->fdCommand < 0);
3558 assert (fd == *p_info->fdListen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003559
Howard Sue32dbfd2015-01-07 15:55:57 +08003560 fdCommand = accept(fd, (sockaddr *) &peeraddr, &socklen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003561
Howard Sue32dbfd2015-01-07 15:55:57 +08003562 if (fdCommand < 0 ) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003563 RLOGE("Error on accept() errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003564 /* start listening for new connections again */
Howard Sue32dbfd2015-01-07 15:55:57 +08003565 rilEventAddWakeup(p_info->listen_event);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003566 return;
3567 }
3568
3569 /* check the credential of the other side and only accept socket from
3570 * phone process
3571 */
3572 errno = 0;
3573 is_phone_socket = 0;
3574
Howard Sue32dbfd2015-01-07 15:55:57 +08003575 err = getsockopt(fdCommand, SOL_SOCKET, SO_PEERCRED, &creds, &szCreds);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003576
3577 if (err == 0 && szCreds > 0) {
3578 errno = 0;
3579 pwd = getpwuid(creds.uid);
3580 if (pwd != NULL) {
Howard Sue32dbfd2015-01-07 15:55:57 +08003581 if (strcmp(pwd->pw_name, p_info->processName) == 0) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003582 is_phone_socket = 1;
3583 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003584 RLOGE("RILD can't accept socket from process %s", pwd->pw_name);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003585 }
3586 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003587 RLOGE("Error on getpwuid() errno: %d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003588 }
3589 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003590 RLOGD("Error on getsockopt() errno: %d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003591 }
3592
3593 if ( !is_phone_socket ) {
Howard Sue32dbfd2015-01-07 15:55:57 +08003594 RLOGE("RILD must accept socket from %s", p_info->processName);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003595
Howard Sue32dbfd2015-01-07 15:55:57 +08003596 close(fdCommand);
3597 fdCommand = -1;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003598
Howard Sue32dbfd2015-01-07 15:55:57 +08003599 onCommandsSocketClosed(p_info->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003600
3601 /* start listening for new connections again */
Howard Sue32dbfd2015-01-07 15:55:57 +08003602 rilEventAddWakeup(p_info->listen_event);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003603
3604 return;
3605 }
3606
Howard Sue32dbfd2015-01-07 15:55:57 +08003607 ret = fcntl(fdCommand, F_SETFL, O_NONBLOCK);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003608
3609 if (ret < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003610 RLOGE ("Error setting O_NONBLOCK errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003611 }
3612
Howard Sue32dbfd2015-01-07 15:55:57 +08003613 RLOGI("libril: new connection to %s", rilSocketIdToString(p_info->socket_id));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003614
Howard Sue32dbfd2015-01-07 15:55:57 +08003615 p_info->fdCommand = fdCommand;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003616
Howard Sue32dbfd2015-01-07 15:55:57 +08003617 p_rs = record_stream_new(p_info->fdCommand, MAX_COMMAND_BYTES);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003618
Howard Sue32dbfd2015-01-07 15:55:57 +08003619 p_info->p_rs = p_rs;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003620
Howard Sue32dbfd2015-01-07 15:55:57 +08003621 ril_event_set (p_info->commands_event, p_info->fdCommand, 1,
3622 p_info->processCommandsCallback, p_info);
3623
3624 rilEventAddWakeup (p_info->commands_event);
3625
3626 onNewCommandConnect(p_info->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003627}
3628
3629static void freeDebugCallbackArgs(int number, char **args) {
3630 for (int i = 0; i < number; i++) {
3631 if (args[i] != NULL) {
3632 free(args[i]);
3633 }
3634 }
3635 free(args);
3636}
3637
3638static void debugCallback (int fd, short flags, void *param) {
3639 int acceptFD, option;
3640 struct sockaddr_un peeraddr;
3641 socklen_t socklen = sizeof (peeraddr);
3642 int data;
3643 unsigned int qxdm_data[6];
3644 const char *deactData[1] = {"1"};
3645 char *actData[1];
3646 RIL_Dial dialData;
3647 int hangupData[1] = {1};
3648 int number;
3649 char **args;
Howard Sue32dbfd2015-01-07 15:55:57 +08003650 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
3651 int sim_id = 0;
3652
3653 RLOGI("debugCallback for socket %s", rilSocketIdToString(socket_id));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003654
3655 acceptFD = accept (fd, (sockaddr *) &peeraddr, &socklen);
3656
3657 if (acceptFD < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003658 RLOGE ("error accepting on debug port: %d\n", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003659 return;
3660 }
3661
3662 if (recv(acceptFD, &number, sizeof(int), 0) != sizeof(int)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003663 RLOGE ("error reading on socket: number of Args: \n");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003664 return;
3665 }
3666 args = (char **) malloc(sizeof(char*) * number);
3667
3668 for (int i = 0; i < number; i++) {
3669 int len;
3670 if (recv(acceptFD, &len, sizeof(int), 0) != sizeof(int)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003671 RLOGE ("error reading on socket: Len of Args: \n");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003672 freeDebugCallbackArgs(i, args);
3673 return;
3674 }
3675 // +1 for null-term
3676 args[i] = (char *) malloc((sizeof(char) * len) + 1);
3677 if (recv(acceptFD, args[i], sizeof(char) * len, 0)
3678 != (int)sizeof(char) * len) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003679 RLOGE ("error reading on socket: Args[%d] \n", i);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003680 freeDebugCallbackArgs(i, args);
3681 return;
3682 }
3683 char * buf = args[i];
3684 buf[len] = 0;
Howard Sue32dbfd2015-01-07 15:55:57 +08003685 if ((i+1) == number) {
3686 /* The last argument should be sim id 0(SIM1)~3(SIM4) */
3687 sim_id = atoi(args[i]);
3688 switch (sim_id) {
3689 case 0:
3690 socket_id = RIL_SOCKET_1;
3691 break;
3692 #if (SIM_COUNT >= 2)
3693 case 1:
3694 socket_id = RIL_SOCKET_2;
3695 break;
3696 #endif
3697 #if (SIM_COUNT >= 3)
3698 case 2:
3699 socket_id = RIL_SOCKET_3;
3700 break;
3701 #endif
3702 #if (SIM_COUNT >= 4)
3703 case 3:
3704 socket_id = RIL_SOCKET_4;
3705 break;
3706 #endif
3707 default:
3708 socket_id = RIL_SOCKET_1;
3709 break;
3710 }
3711 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003712 }
3713
3714 switch (atoi(args[0])) {
3715 case 0:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003716 RLOGI ("Connection on debug port: issuing reset.");
Howard Sue32dbfd2015-01-07 15:55:57 +08003717 issueLocalRequest(RIL_REQUEST_RESET_RADIO, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003718 break;
3719 case 1:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003720 RLOGI ("Connection on debug port: issuing radio power off.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003721 data = 0;
Howard Sue32dbfd2015-01-07 15:55:57 +08003722 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003723 // Close the socket
Howard Sue32dbfd2015-01-07 15:55:57 +08003724 if (socket_id == RIL_SOCKET_1 && s_ril_param_socket.fdCommand > 0) {
3725 close(s_ril_param_socket.fdCommand);
3726 s_ril_param_socket.fdCommand = -1;
3727 }
3728 #if (SIM_COUNT == 2)
3729 else if (socket_id == RIL_SOCKET_2 && s_ril_param_socket2.fdCommand > 0) {
3730 close(s_ril_param_socket2.fdCommand);
3731 s_ril_param_socket2.fdCommand = -1;
3732 }
3733 #endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003734 break;
3735 case 2:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003736 RLOGI ("Debug port: issuing unsolicited voice network change.");
Howard Sue32dbfd2015-01-07 15:55:57 +08003737 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003738 break;
3739 case 3:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003740 RLOGI ("Debug port: QXDM log enable.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003741 qxdm_data[0] = 65536; // head.func_tag
3742 qxdm_data[1] = 16; // head.len
3743 qxdm_data[2] = 1; // mode: 1 for 'start logging'
3744 qxdm_data[3] = 32; // log_file_size: 32megabytes
3745 qxdm_data[4] = 0; // log_mask
3746 qxdm_data[5] = 8; // log_max_fileindex
3747 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Howard Sue32dbfd2015-01-07 15:55:57 +08003748 6 * sizeof(int), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003749 break;
3750 case 4:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003751 RLOGI ("Debug port: QXDM log disable.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003752 qxdm_data[0] = 65536;
3753 qxdm_data[1] = 16;
3754 qxdm_data[2] = 0; // mode: 0 for 'stop logging'
3755 qxdm_data[3] = 32;
3756 qxdm_data[4] = 0;
3757 qxdm_data[5] = 8;
3758 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Howard Sue32dbfd2015-01-07 15:55:57 +08003759 6 * sizeof(int), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003760 break;
3761 case 5:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003762 RLOGI("Debug port: Radio On");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003763 data = 1;
Howard Sue32dbfd2015-01-07 15:55:57 +08003764 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003765 sleep(2);
3766 // Set network selection automatic.
Howard Sue32dbfd2015-01-07 15:55:57 +08003767 issueLocalRequest(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003768 break;
3769 case 6:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003770 RLOGI("Debug port: Setup Data Call, Apn :%s\n", args[1]);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003771 actData[0] = args[1];
3772 issueLocalRequest(RIL_REQUEST_SETUP_DATA_CALL, &actData,
Howard Sue32dbfd2015-01-07 15:55:57 +08003773 sizeof(actData), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003774 break;
3775 case 7:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003776 RLOGI("Debug port: Deactivate Data Call");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003777 issueLocalRequest(RIL_REQUEST_DEACTIVATE_DATA_CALL, &deactData,
Howard Sue32dbfd2015-01-07 15:55:57 +08003778 sizeof(deactData), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003779 break;
3780 case 8:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003781 RLOGI("Debug port: Dial Call");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003782 dialData.clir = 0;
3783 dialData.address = args[1];
Howard Sue32dbfd2015-01-07 15:55:57 +08003784 issueLocalRequest(RIL_REQUEST_DIAL, &dialData, sizeof(dialData), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003785 break;
3786 case 9:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003787 RLOGI("Debug port: Answer Call");
Howard Sue32dbfd2015-01-07 15:55:57 +08003788 issueLocalRequest(RIL_REQUEST_ANSWER, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003789 break;
3790 case 10:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003791 RLOGI("Debug port: End Call");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003792 issueLocalRequest(RIL_REQUEST_HANGUP, &hangupData,
Howard Sue32dbfd2015-01-07 15:55:57 +08003793 sizeof(hangupData), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003794 break;
3795 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003796 RLOGE ("Invalid request");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003797 break;
3798 }
3799 freeDebugCallbackArgs(number, args);
3800 close(acceptFD);
3801}
3802
3803
3804static void userTimerCallback (int fd, short flags, void *param) {
3805 UserCallbackInfo *p_info;
3806
3807 p_info = (UserCallbackInfo *)param;
3808
3809 p_info->p_callback(p_info->userParam);
3810
3811
3812 // FIXME generalize this...there should be a cancel mechanism
3813 if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) {
3814 s_last_wake_timeout_info = NULL;
3815 }
3816
3817 free(p_info);
3818}
3819
3820
3821static void *
3822eventLoop(void *param) {
3823 int ret;
3824 int filedes[2];
3825
3826 ril_event_init();
3827
3828 pthread_mutex_lock(&s_startupMutex);
3829
3830 s_started = 1;
3831 pthread_cond_broadcast(&s_startupCond);
3832
3833 pthread_mutex_unlock(&s_startupMutex);
3834
3835 ret = pipe(filedes);
3836
3837 if (ret < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003838 RLOGE("Error in pipe() errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003839 return NULL;
3840 }
3841
3842 s_fdWakeupRead = filedes[0];
3843 s_fdWakeupWrite = filedes[1];
3844
3845 fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK);
3846
3847 ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,
3848 processWakeupCallback, NULL);
3849
3850 rilEventAddWakeup (&s_wakeupfd_event);
3851
3852 // Only returns on error
3853 ril_event_loop();
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003854 RLOGE ("error in event_loop_base errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003855 // kill self to restart on error
3856 kill(0, SIGKILL);
3857
3858 return NULL;
3859}
3860
3861extern "C" void
3862RIL_startEventLoop(void) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003863 /* spin up eventLoop thread and wait for it to get started */
3864 s_started = 0;
3865 pthread_mutex_lock(&s_startupMutex);
3866
Howard Sue32dbfd2015-01-07 15:55:57 +08003867 pthread_attr_t attr;
3868 pthread_attr_init(&attr);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003869 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
Howard Sue32dbfd2015-01-07 15:55:57 +08003870
3871 int result = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
3872 if (result != 0) {
3873 RLOGE("Failed to create dispatch thread: %s", strerror(result));
3874 goto done;
3875 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003876
3877 while (s_started == 0) {
3878 pthread_cond_wait(&s_startupCond, &s_startupMutex);
3879 }
3880
Howard Sue32dbfd2015-01-07 15:55:57 +08003881done:
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003882 pthread_mutex_unlock(&s_startupMutex);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003883}
3884
3885// Used for testing purpose only.
3886extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) {
3887 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
3888}
3889
Howard Sue32dbfd2015-01-07 15:55:57 +08003890static void startListen(RIL_SOCKET_ID socket_id, SocketListenParam* socket_listen_p) {
3891 int fdListen = -1;
3892 int ret;
3893 char socket_name[10];
3894
3895 memset(socket_name, 0, sizeof(char)*10);
3896
3897 switch(socket_id) {
3898 case RIL_SOCKET_1:
3899 strncpy(socket_name, RIL_getRilSocketName(), 9);
3900 break;
3901 #if (SIM_COUNT >= 2)
3902 case RIL_SOCKET_2:
3903 strncpy(socket_name, SOCKET2_NAME_RIL, 9);
3904 break;
3905 #endif
3906 #if (SIM_COUNT >= 3)
3907 case RIL_SOCKET_3:
3908 strncpy(socket_name, SOCKET3_NAME_RIL, 9);
3909 break;
3910 #endif
3911 #if (SIM_COUNT >= 4)
3912 case RIL_SOCKET_4:
3913 strncpy(socket_name, SOCKET4_NAME_RIL, 9);
3914 break;
3915 #endif
3916 default:
3917 RLOGE("Socket id is wrong!!");
3918 return;
3919 }
3920
3921 RLOGI("Start to listen %s", rilSocketIdToString(socket_id));
3922
3923 fdListen = android_get_control_socket(socket_name);
3924 if (fdListen < 0) {
3925 RLOGE("Failed to get socket %s", socket_name);
3926 exit(-1);
3927 }
3928
3929 ret = listen(fdListen, 4);
3930
3931 if (ret < 0) {
3932 RLOGE("Failed to listen on control socket '%d': %s",
3933 fdListen, strerror(errno));
3934 exit(-1);
3935 }
3936 socket_listen_p->fdListen = fdListen;
3937
3938 /* note: non-persistent so we can accept only one connection at a time */
3939 ril_event_set (socket_listen_p->listen_event, fdListen, false,
3940 listenCallback, socket_listen_p);
3941
3942 rilEventAddWakeup (socket_listen_p->listen_event);
3943}
3944
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003945extern "C" void
3946RIL_register (const RIL_RadioFunctions *callbacks) {
3947 int ret;
3948 int flags;
3949
Howard Sue32dbfd2015-01-07 15:55:57 +08003950 RLOGI("SIM_COUNT: %d", SIM_COUNT);
3951
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003952 if (callbacks == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003953 RLOGE("RIL_register: RIL_RadioFunctions * null");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003954 return;
3955 }
3956 if (callbacks->version < RIL_VERSION_MIN) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003957 RLOGE("RIL_register: version %d is to old, min version is %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003958 callbacks->version, RIL_VERSION_MIN);
3959 return;
3960 }
3961 if (callbacks->version > RIL_VERSION) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003962 RLOGE("RIL_register: version %d is too new, max version is %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003963 callbacks->version, RIL_VERSION);
3964 return;
3965 }
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003966 RLOGE("RIL_register: RIL version %d", callbacks->version);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003967
3968 if (s_registerCalled > 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003969 RLOGE("RIL_register has been called more than once. "
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003970 "Subsequent call ignored");
3971 return;
3972 }
3973
3974 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
3975
Howard Sue32dbfd2015-01-07 15:55:57 +08003976 /* Initialize socket1 parameters */
3977 s_ril_param_socket = {
3978 RIL_SOCKET_1, /* socket_id */
3979 -1, /* fdListen */
3980 -1, /* fdCommand */
3981 PHONE_PROCESS, /* processName */
3982 &s_commands_event, /* commands_event */
3983 &s_listen_event, /* listen_event */
3984 processCommandsCallback, /* processCommandsCallback */
3985 NULL /* p_rs */
3986 };
3987
3988#if (SIM_COUNT >= 2)
3989 s_ril_param_socket2 = {
3990 RIL_SOCKET_2, /* socket_id */
3991 -1, /* fdListen */
3992 -1, /* fdCommand */
3993 PHONE_PROCESS, /* processName */
3994 &s_commands_event_socket2, /* commands_event */
3995 &s_listen_event_socket2, /* listen_event */
3996 processCommandsCallback, /* processCommandsCallback */
3997 NULL /* p_rs */
3998 };
3999#endif
4000
4001#if (SIM_COUNT >= 3)
4002 s_ril_param_socket3 = {
4003 RIL_SOCKET_3, /* socket_id */
4004 -1, /* fdListen */
4005 -1, /* fdCommand */
4006 PHONE_PROCESS, /* processName */
4007 &s_commands_event_socket3, /* commands_event */
4008 &s_listen_event_socket3, /* listen_event */
4009 processCommandsCallback, /* processCommandsCallback */
4010 NULL /* p_rs */
4011 };
4012#endif
4013
4014#if (SIM_COUNT >= 4)
4015 s_ril_param_socket4 = {
4016 RIL_SOCKET_4, /* socket_id */
4017 -1, /* fdListen */
4018 -1, /* fdCommand */
4019 PHONE_PROCESS, /* processName */
4020 &s_commands_event_socket4, /* commands_event */
4021 &s_listen_event_socket4, /* listen_event */
4022 processCommandsCallback, /* processCommandsCallback */
4023 NULL /* p_rs */
4024 };
4025#endif
4026
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004027 s_registerCalled = 1;
4028
Howard Sue32dbfd2015-01-07 15:55:57 +08004029 RLOGI("s_registerCalled flag set, %d", s_started);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004030 // Little self-check
4031
4032 for (int i = 0; i < (int)NUM_ELEMS(s_commands); i++) {
4033 assert(i == s_commands[i].requestNumber);
4034 }
4035
4036 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses); i++) {
Howard Sue32dbfd2015-01-07 15:55:57 +08004037 assert(i + RIL_UNSOL_RESPONSE_BASE
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004038 == s_unsolResponses[i].requestNumber);
4039 }
4040
4041 // New rild impl calls RIL_startEventLoop() first
4042 // old standalone impl wants it here.
4043
4044 if (s_started == 0) {
4045 RIL_startEventLoop();
4046 }
4047
Howard Sue32dbfd2015-01-07 15:55:57 +08004048 // start listen socket1
4049 startListen(RIL_SOCKET_1, &s_ril_param_socket);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004050
Howard Sue32dbfd2015-01-07 15:55:57 +08004051#if (SIM_COUNT >= 2)
4052 // start listen socket2
4053 startListen(RIL_SOCKET_2, &s_ril_param_socket2);
4054#endif /* (SIM_COUNT == 2) */
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004055
Howard Sue32dbfd2015-01-07 15:55:57 +08004056#if (SIM_COUNT >= 3)
4057 // start listen socket3
4058 startListen(RIL_SOCKET_3, &s_ril_param_socket3);
4059#endif /* (SIM_COUNT == 3) */
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004060
Howard Sue32dbfd2015-01-07 15:55:57 +08004061#if (SIM_COUNT >= 4)
4062 // start listen socket4
4063 startListen(RIL_SOCKET_4, &s_ril_param_socket4);
4064#endif /* (SIM_COUNT == 4) */
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004065
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004066
4067#if 1
4068 // start debug interface socket
4069
Howard Sue32dbfd2015-01-07 15:55:57 +08004070 char *inst = NULL;
4071 if (strlen(RIL_getRilSocketName()) >= strlen(SOCKET_NAME_RIL)) {
4072 inst = RIL_getRilSocketName() + strlen(SOCKET_NAME_RIL);
4073 }
4074
4075 char rildebug[MAX_DEBUG_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL_DEBUG;
4076 if (inst != NULL) {
4077 strncat(rildebug, inst, MAX_DEBUG_SOCKET_NAME_LENGTH);
4078 }
4079
4080 s_fdDebug = android_get_control_socket(rildebug);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004081 if (s_fdDebug < 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08004082 RLOGE("Failed to get socket : %s errno:%d", rildebug, errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004083 exit(-1);
4084 }
4085
4086 ret = listen(s_fdDebug, 4);
4087
4088 if (ret < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004089 RLOGE("Failed to listen on ril debug socket '%d': %s",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004090 s_fdDebug, strerror(errno));
4091 exit(-1);
4092 }
4093
4094 ril_event_set (&s_debug_event, s_fdDebug, true,
4095 debugCallback, NULL);
4096
4097 rilEventAddWakeup (&s_debug_event);
4098#endif
4099
4100}
4101
4102static int
4103checkAndDequeueRequestInfo(struct RequestInfo *pRI) {
4104 int ret = 0;
Howard Sue32dbfd2015-01-07 15:55:57 +08004105 /* Hook for current context
4106 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
4107 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
4108 /* pendingRequestsHook refer to &s_pendingRequests */
4109 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004110
4111 if (pRI == NULL) {
4112 return 0;
4113 }
4114
Howard Sue32dbfd2015-01-07 15:55:57 +08004115#if (SIM_COUNT >= 2)
4116 if (pRI->socket_id == RIL_SOCKET_2) {
4117 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
4118 pendingRequestsHook = &s_pendingRequests_socket2;
4119 }
4120#if (SIM_COUNT >= 3)
4121 if (pRI->socket_id == RIL_SOCKET_3) {
4122 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
4123 pendingRequestsHook = &s_pendingRequests_socket3;
4124 }
4125#endif
4126#if (SIM_COUNT >= 4)
4127 if (pRI->socket_id == RIL_SOCKET_4) {
4128 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
4129 pendingRequestsHook = &s_pendingRequests_socket4;
4130 }
4131#endif
4132#endif
4133 pthread_mutex_lock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004134
Howard Sue32dbfd2015-01-07 15:55:57 +08004135 for(RequestInfo **ppCur = pendingRequestsHook
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004136 ; *ppCur != NULL
4137 ; ppCur = &((*ppCur)->p_next)
4138 ) {
4139 if (pRI == *ppCur) {
4140 ret = 1;
4141
4142 *ppCur = (*ppCur)->p_next;
4143 break;
4144 }
4145 }
4146
Howard Sue32dbfd2015-01-07 15:55:57 +08004147 pthread_mutex_unlock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004148
4149 return ret;
4150}
4151
4152
Howard Sue32dbfd2015-01-07 15:55:57 +08004153
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004154extern "C" void
4155RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) {
4156 RequestInfo *pRI;
4157 int ret;
Howard Sue32dbfd2015-01-07 15:55:57 +08004158 int fd = s_ril_param_socket.fdCommand;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004159 size_t errorOffset;
Howard Sue32dbfd2015-01-07 15:55:57 +08004160 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004161
4162 pRI = (RequestInfo *)t;
4163
4164 if (!checkAndDequeueRequestInfo(pRI)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004165 RLOGE ("RIL_onRequestComplete: invalid RIL_Token");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004166 return;
4167 }
4168
Howard Sue32dbfd2015-01-07 15:55:57 +08004169 socket_id = pRI->socket_id;
4170#if (SIM_COUNT >= 2)
4171 if (socket_id == RIL_SOCKET_2) {
4172 fd = s_ril_param_socket2.fdCommand;
4173 }
4174#if (SIM_COUNT >= 3)
4175 if (socket_id == RIL_SOCKET_3) {
4176 fd = s_ril_param_socket3.fdCommand;
4177 }
4178#endif
4179#if (SIM_COUNT >= 4)
4180 if (socket_id == RIL_SOCKET_4) {
4181 fd = s_ril_param_socket4.fdCommand;
4182 }
4183#endif
4184#endif
4185 RLOGD("RequestComplete, %s", rilSocketIdToString(socket_id));
4186
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004187 if (pRI->local > 0) {
4188 // Locally issued command...void only!
4189 // response does not go back up the command socket
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004190 RLOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004191
4192 goto done;
4193 }
4194
4195 appendPrintBuf("[%04d]< %s",
4196 pRI->token, requestToString(pRI->pCI->requestNumber));
4197
4198 if (pRI->cancelled == 0) {
4199 Parcel p;
4200
4201 p.writeInt32 (RESPONSE_SOLICITED);
4202 p.writeInt32 (pRI->token);
4203 errorOffset = p.dataPosition();
4204
4205 p.writeInt32 (e);
4206
4207 if (response != NULL) {
4208 // there is a response payload, no matter success or not.
4209 ret = pRI->pCI->responseFunction(p, response, responselen);
4210
4211 /* if an error occurred, rewind and mark it */
4212 if (ret != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08004213 RLOGE ("responseFunction error, ret %d", ret);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004214 p.setDataPosition(errorOffset);
4215 p.writeInt32 (ret);
4216 }
4217 }
4218
4219 if (e != RIL_E_SUCCESS) {
4220 appendPrintBuf("%s fails by %s", printBuf, failCauseToString(e));
4221 }
4222
Howard Sue32dbfd2015-01-07 15:55:57 +08004223 if (fd < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004224 RLOGD ("RIL onRequestComplete: Command channel closed");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004225 }
Howard Sue32dbfd2015-01-07 15:55:57 +08004226 sendResponse(p, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004227 }
4228
4229done:
4230 free(pRI);
4231}
4232
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004233static void
4234grabPartialWakeLock() {
4235 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
4236}
4237
4238static void
4239releaseWakeLock() {
4240 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
4241}
4242
4243/**
4244 * Timer callback to put us back to sleep before the default timeout
4245 */
4246static void
4247wakeTimeoutCallback (void *param) {
4248 // We're using "param != NULL" as a cancellation mechanism
4249 if (param == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004250 //RLOGD("wakeTimeout: releasing wake lock");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004251
4252 releaseWakeLock();
4253 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004254 //RLOGD("wakeTimeout: releasing wake lock CANCELLED");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004255 }
4256}
4257
4258static int
4259decodeVoiceRadioTechnology (RIL_RadioState radioState) {
4260 switch (radioState) {
4261 case RADIO_STATE_SIM_NOT_READY:
4262 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4263 case RADIO_STATE_SIM_READY:
4264 return RADIO_TECH_UMTS;
4265
4266 case RADIO_STATE_RUIM_NOT_READY:
4267 case RADIO_STATE_RUIM_READY:
4268 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4269 case RADIO_STATE_NV_NOT_READY:
4270 case RADIO_STATE_NV_READY:
4271 return RADIO_TECH_1xRTT;
4272
4273 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004274 RLOGD("decodeVoiceRadioTechnology: Invoked with incorrect RadioState");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004275 return -1;
4276 }
4277}
4278
4279static int
4280decodeCdmaSubscriptionSource (RIL_RadioState radioState) {
4281 switch (radioState) {
4282 case RADIO_STATE_SIM_NOT_READY:
4283 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4284 case RADIO_STATE_SIM_READY:
4285 case RADIO_STATE_RUIM_NOT_READY:
4286 case RADIO_STATE_RUIM_READY:
4287 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4288 return CDMA_SUBSCRIPTION_SOURCE_RUIM_SIM;
4289
4290 case RADIO_STATE_NV_NOT_READY:
4291 case RADIO_STATE_NV_READY:
4292 return CDMA_SUBSCRIPTION_SOURCE_NV;
4293
4294 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004295 RLOGD("decodeCdmaSubscriptionSource: Invoked with incorrect RadioState");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004296 return -1;
4297 }
4298}
4299
4300static int
4301decodeSimStatus (RIL_RadioState radioState) {
4302 switch (radioState) {
4303 case RADIO_STATE_SIM_NOT_READY:
4304 case RADIO_STATE_RUIM_NOT_READY:
4305 case RADIO_STATE_NV_NOT_READY:
4306 case RADIO_STATE_NV_READY:
4307 return -1;
4308 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4309 case RADIO_STATE_SIM_READY:
4310 case RADIO_STATE_RUIM_READY:
4311 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4312 return radioState;
4313 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004314 RLOGD("decodeSimStatus: Invoked with incorrect RadioState");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004315 return -1;
4316 }
4317}
4318
4319static bool is3gpp2(int radioTech) {
4320 switch (radioTech) {
4321 case RADIO_TECH_IS95A:
4322 case RADIO_TECH_IS95B:
4323 case RADIO_TECH_1xRTT:
4324 case RADIO_TECH_EVDO_0:
4325 case RADIO_TECH_EVDO_A:
4326 case RADIO_TECH_EVDO_B:
4327 case RADIO_TECH_EHRPD:
4328 return true;
4329 default:
4330 return false;
4331 }
4332}
4333
4334/* If RIL sends SIM states or RUIM states, store the voice radio
4335 * technology and subscription source information so that they can be
4336 * returned when telephony framework requests them
4337 */
4338static RIL_RadioState
Andreas Schneider68f80d82015-04-07 19:13:42 +02004339processRadioState(RIL_RadioState newRadioState, RIL_SOCKET_ID socket_id __unused) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004340
4341 if((newRadioState > RADIO_STATE_UNAVAILABLE) && (newRadioState < RADIO_STATE_ON)) {
4342 int newVoiceRadioTech;
4343 int newCdmaSubscriptionSource;
4344 int newSimStatus;
4345
4346 /* This is old RIL. Decode Subscription source and Voice Radio Technology
4347 from Radio State and send change notifications if there has been a change */
4348 newVoiceRadioTech = decodeVoiceRadioTechnology(newRadioState);
4349 if(newVoiceRadioTech != voiceRadioTech) {
4350 voiceRadioTech = newVoiceRadioTech;
Howard Sue32dbfd2015-01-07 15:55:57 +08004351 RIL_UNSOL_RESPONSE(RIL_UNSOL_VOICE_RADIO_TECH_CHANGED,
4352 &voiceRadioTech, sizeof(voiceRadioTech), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004353 }
4354 if(is3gpp2(newVoiceRadioTech)) {
4355 newCdmaSubscriptionSource = decodeCdmaSubscriptionSource(newRadioState);
4356 if(newCdmaSubscriptionSource != cdmaSubscriptionSource) {
4357 cdmaSubscriptionSource = newCdmaSubscriptionSource;
Howard Sue32dbfd2015-01-07 15:55:57 +08004358 RIL_UNSOL_RESPONSE(RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED,
4359 &cdmaSubscriptionSource, sizeof(cdmaSubscriptionSource), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004360 }
4361 }
4362 newSimStatus = decodeSimStatus(newRadioState);
4363 if(newSimStatus != simRuimStatus) {
4364 simRuimStatus = newSimStatus;
Howard Sue32dbfd2015-01-07 15:55:57 +08004365 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004366 }
4367
4368 /* Send RADIO_ON to telephony */
4369 newRadioState = RADIO_STATE_ON;
4370 }
4371
4372 return newRadioState;
4373}
4374
Howard Sue32dbfd2015-01-07 15:55:57 +08004375#if defined(ANDROID_MULTI_SIM)
4376extern "C"
Andreas Schneider8e5fa432015-04-07 19:14:05 +02004377void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Howard Sue32dbfd2015-01-07 15:55:57 +08004378 size_t datalen, RIL_SOCKET_ID socket_id)
4379#else
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004380extern "C"
Andreas Schneider8e5fa432015-04-07 19:14:05 +02004381void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004382 size_t datalen)
Howard Sue32dbfd2015-01-07 15:55:57 +08004383#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004384{
4385 int unsolResponseIndex;
4386 int ret;
4387 int64_t timeReceived = 0;
4388 bool shouldScheduleTimeout = false;
4389 RIL_RadioState newState;
Howard Sue32dbfd2015-01-07 15:55:57 +08004390 RIL_SOCKET_ID soc_id = RIL_SOCKET_1;
4391
4392#if defined(ANDROID_MULTI_SIM)
4393 soc_id = socket_id;
4394#endif
4395
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004396
4397 if (s_registerCalled == 0) {
4398 // Ignore RIL_onUnsolicitedResponse before RIL_register
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004399 RLOGW("RIL_onUnsolicitedResponse called before RIL_register");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004400 return;
4401 }
Howard Sue32dbfd2015-01-07 15:55:57 +08004402
4403 unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004404
4405 if ((unsolResponseIndex < 0)
4406 || (unsolResponseIndex >= (int32_t)NUM_ELEMS(s_unsolResponses))) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004407 RLOGE("unsupported unsolicited response code %d", unsolResponse);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004408 return;
4409 }
4410
4411 // Grab a wake lock if needed for this reponse,
4412 // as we exit we'll either release it immediately
4413 // or set a timer to release it later.
4414 switch (s_unsolResponses[unsolResponseIndex].wakeType) {
4415 case WAKE_PARTIAL:
4416 grabPartialWakeLock();
4417 shouldScheduleTimeout = true;
4418 break;
4419
4420 case DONT_WAKE:
4421 default:
4422 // No wake lock is grabed so don't set timeout
4423 shouldScheduleTimeout = false;
4424 break;
4425 }
4426
4427 // Mark the time this was received, doing this
4428 // after grabing the wakelock incase getting
4429 // the elapsedRealTime might cause us to goto
4430 // sleep.
4431 if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4432 timeReceived = elapsedRealtime();
4433 }
4434
4435 appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
4436
4437 Parcel p;
4438
4439 p.writeInt32 (RESPONSE_UNSOLICITED);
4440 p.writeInt32 (unsolResponse);
4441
4442 ret = s_unsolResponses[unsolResponseIndex]
Howard Sue32dbfd2015-01-07 15:55:57 +08004443 .responseFunction(p, const_cast<void*>(data), datalen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004444 if (ret != 0) {
4445 // Problem with the response. Don't continue;
4446 goto error_exit;
4447 }
4448
4449 // some things get more payload
4450 switch(unsolResponse) {
4451 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
Howard Sue32dbfd2015-01-07 15:55:57 +08004452 newState = processRadioState(CALL_ONSTATEREQUEST(soc_id), soc_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004453 p.writeInt32(newState);
4454 appendPrintBuf("%s {%s}", printBuf,
Howard Sue32dbfd2015-01-07 15:55:57 +08004455 radioStateToString(CALL_ONSTATEREQUEST(soc_id)));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004456 break;
4457
4458
4459 case RIL_UNSOL_NITZ_TIME_RECEIVED:
4460 // Store the time that this was received so the
4461 // handler of this message can account for
4462 // the time it takes to arrive and process. In
4463 // particular the system has been known to sleep
4464 // before this message can be processed.
4465 p.writeInt64(timeReceived);
4466 break;
4467 }
4468
Howard Sue32dbfd2015-01-07 15:55:57 +08004469 RLOGI("%s UNSOLICITED: %s length:%d", rilSocketIdToString(soc_id), requestToString(unsolResponse), p.dataSize());
4470 ret = sendResponse(p, soc_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004471 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4472
4473 // Unfortunately, NITZ time is not poll/update like everything
4474 // else in the system. So, if the upstream client isn't connected,
4475 // keep a copy of the last NITZ response (with receive time noted
4476 // above) around so we can deliver it when it is connected
4477
4478 if (s_lastNITZTimeData != NULL) {
4479 free (s_lastNITZTimeData);
4480 s_lastNITZTimeData = NULL;
4481 }
4482
4483 s_lastNITZTimeData = malloc(p.dataSize());
4484 s_lastNITZTimeDataSize = p.dataSize();
4485 memcpy(s_lastNITZTimeData, p.data(), p.dataSize());
4486 }
4487
4488 // For now, we automatically go back to sleep after TIMEVAL_WAKE_TIMEOUT
4489 // FIXME The java code should handshake here to release wake lock
4490
4491 if (shouldScheduleTimeout) {
4492 // Cancel the previous request
4493 if (s_last_wake_timeout_info != NULL) {
4494 s_last_wake_timeout_info->userParam = (void *)1;
4495 }
4496
4497 s_last_wake_timeout_info
4498 = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
4499 &TIMEVAL_WAKE_TIMEOUT);
4500 }
4501
4502 // Normal exit
4503 return;
4504
4505error_exit:
4506 if (shouldScheduleTimeout) {
4507 releaseWakeLock();
4508 }
4509}
4510
4511/** FIXME generalize this if you track UserCAllbackInfo, clear it
4512 when the callback occurs
4513*/
4514static UserCallbackInfo *
4515internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
4516 const struct timeval *relativeTime)
4517{
4518 struct timeval myRelativeTime;
4519 UserCallbackInfo *p_info;
4520
4521 p_info = (UserCallbackInfo *) malloc (sizeof(UserCallbackInfo));
4522
4523 p_info->p_callback = callback;
4524 p_info->userParam = param;
4525
4526 if (relativeTime == NULL) {
4527 /* treat null parameter as a 0 relative time */
4528 memset (&myRelativeTime, 0, sizeof(myRelativeTime));
4529 } else {
4530 /* FIXME I think event_add's tv param is really const anyway */
4531 memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
4532 }
4533
4534 ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
4535
4536 ril_timer_add(&(p_info->event), &myRelativeTime);
4537
4538 triggerEvLoop();
4539 return p_info;
4540}
4541
4542
4543extern "C" void
4544RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
4545 const struct timeval *relativeTime) {
4546 internalRequestTimedCallback (callback, param, relativeTime);
4547}
4548
4549const char *
4550failCauseToString(RIL_Errno e) {
4551 switch(e) {
4552 case RIL_E_SUCCESS: return "E_SUCCESS";
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004553 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RADIO_NOT_AVAILABLE";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004554 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
4555 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
4556 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
4557 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
4558 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
4559 case RIL_E_CANCELLED: return "E_CANCELLED";
4560 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
4561 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
4562 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
4563 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
4564 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
4565#ifdef FEATURE_MULTIMODE_ANDROID
4566 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
4567 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
4568#endif
4569 default: return "<unknown error>";
4570 }
4571}
4572
4573const char *
4574radioStateToString(RIL_RadioState s) {
4575 switch(s) {
4576 case RADIO_STATE_OFF: return "RADIO_OFF";
4577 case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
4578 case RADIO_STATE_SIM_NOT_READY: return "RADIO_SIM_NOT_READY";
4579 case RADIO_STATE_SIM_LOCKED_OR_ABSENT: return "RADIO_SIM_LOCKED_OR_ABSENT";
4580 case RADIO_STATE_SIM_READY: return "RADIO_SIM_READY";
4581 case RADIO_STATE_RUIM_NOT_READY:return"RADIO_RUIM_NOT_READY";
4582 case RADIO_STATE_RUIM_READY:return"RADIO_RUIM_READY";
4583 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:return"RADIO_RUIM_LOCKED_OR_ABSENT";
4584 case RADIO_STATE_NV_NOT_READY:return"RADIO_NV_NOT_READY";
4585 case RADIO_STATE_NV_READY:return"RADIO_NV_READY";
4586 case RADIO_STATE_ON:return"RADIO_ON";
4587 default: return "<unknown state>";
4588 }
4589}
4590
4591const char *
4592callStateToString(RIL_CallState s) {
4593 switch(s) {
4594 case RIL_CALL_ACTIVE : return "ACTIVE";
4595 case RIL_CALL_HOLDING: return "HOLDING";
4596 case RIL_CALL_DIALING: return "DIALING";
4597 case RIL_CALL_ALERTING: return "ALERTING";
4598 case RIL_CALL_INCOMING: return "INCOMING";
4599 case RIL_CALL_WAITING: return "WAITING";
4600 default: return "<unknown state>";
4601 }
4602}
4603
4604const char *
4605requestToString(int request) {
4606/*
4607 cat libs/telephony/ril_commands.h \
4608 | egrep "^ *{RIL_" \
4609 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
4610
4611
4612 cat libs/telephony/ril_unsol_commands.h \
4613 | egrep "^ *{RIL_" \
4614 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
4615
4616*/
4617 switch(request) {
4618 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
4619 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
4620 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
4621 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
4622 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
4623 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
4624 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
4625 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
4626 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
4627 case RIL_REQUEST_DIAL: return "DIAL";
4628 case RIL_REQUEST_DIAL_EMERGENCY: return "DIAL";
4629 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
4630 case RIL_REQUEST_HANGUP: return "HANGUP";
4631 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
4632 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
4633 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
4634 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
4635 case RIL_REQUEST_UDUB: return "UDUB";
4636 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
4637 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
4638 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
4639 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
4640 case RIL_REQUEST_OPERATOR: return "OPERATOR";
4641 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
4642 case RIL_REQUEST_DTMF: return "DTMF";
4643 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
4644 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
4645 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
4646 case RIL_REQUEST_SIM_IO: return "SIM_IO";
4647 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
4648 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
4649 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
4650 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
4651 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
4652 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
4653 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
4654 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
4655 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
4656 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
4657 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
4658 case RIL_REQUEST_ANSWER: return "ANSWER";
4659 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
4660 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
4661 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
4662 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
4663 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
4664 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
4665 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
4666 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";
4667 case RIL_REQUEST_DTMF_START: return "DTMF_START";
4668 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
4669 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
4670 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
4671 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
4672 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
4673 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
4674 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
4675 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
4676 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
4677 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
4678 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
4679 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
4680 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
4681 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
4682 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
4683 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
4684 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
4685 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
4686 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
4687 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
4688 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
4689 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
4690 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
4691 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004692 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE:return"CDMA_SET_SUBSCRIPTION_SOURCE";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004693 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"CDMA_SET_ROAMING_PREFERENCE";
4694 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"CDMA_QUERY_ROAMING_PREFERENCE";
4695 case RIL_REQUEST_SET_TTY_MODE:return"SET_TTY_MODE";
4696 case RIL_REQUEST_QUERY_TTY_MODE:return"QUERY_TTY_MODE";
4697 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
4698 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
4699 case RIL_REQUEST_CDMA_FLASH:return"CDMA_FLASH";
4700 case RIL_REQUEST_CDMA_BURST_DTMF:return"CDMA_BURST_DTMF";
4701 case RIL_REQUEST_CDMA_SEND_SMS:return"CDMA_SEND_SMS";
4702 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:return"CDMA_SMS_ACKNOWLEDGE";
4703 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG:return"GSM_GET_BROADCAST_SMS_CONFIG";
4704 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG:return"GSM_SET_BROADCAST_SMS_CONFIG";
4705 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG:return "CDMA_GET_BROADCAST_SMS_CONFIG";
4706 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG:return "CDMA_SET_BROADCAST_SMS_CONFIG";
4707 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION:return "CDMA_SMS_BROADCAST_ACTIVATION";
Ethan Chend6e30652013-08-04 22:49:56 -07004708 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return"CDMA_VALIDATE_AND_WRITE_AKEY";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004709 case RIL_REQUEST_CDMA_SUBSCRIPTION: return"CDMA_SUBSCRIPTION";
4710 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
4711 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
4712 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
4713 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
4714 case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
4715 case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
4716 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
4717 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
4718 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
4719 case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
4720 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
4721 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
4722 case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004723 case RIL_REQUEST_GET_CELL_INFO_LIST: return"GET_CELL_INFO_LIST";
4724 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return"SET_UNSOL_CELL_INFO_LIST_RATE";
Andrew Jiangca4a9a02014-01-18 18:04:08 -05004725 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "RIL_REQUEST_SET_INITIAL_ATTACH_APN";
4726 case RIL_REQUEST_IMS_REGISTRATION_STATE: return "IMS_REGISTRATION_STATE";
4727 case RIL_REQUEST_IMS_SEND_SMS: return "IMS_SEND_SMS";
Howard Sue32dbfd2015-01-07 15:55:57 +08004728 case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "SIM_TRANSMIT_APDU_BASIC";
4729 case RIL_REQUEST_SIM_OPEN_CHANNEL: return "SIM_OPEN_CHANNEL";
4730 case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "SIM_CLOSE_CHANNEL";
4731 case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "SIM_TRANSMIT_APDU_CHANNEL";
4732 case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "SET_UICC_SUBSCRIPTION";
4733 case RIL_REQUEST_ALLOW_DATA: return "ALLOW_DATA";
4734 case RIL_REQUEST_GET_HARDWARE_CONFIG: return "GET_HARDWARE_CONFIG";
4735 case RIL_REQUEST_SIM_AUTHENTICATION: return "SIM_AUTHENTICATION";
4736 case RIL_REQUEST_GET_DC_RT_INFO: return "GET_DC_RT_INFO";
4737 case RIL_REQUEST_SET_DC_RT_INFO_RATE: return "SET_DC_RT_INFO_RATE";
4738 case RIL_REQUEST_SET_DATA_PROFILE: return "SET_DATA_PROFILE";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004739 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
4740 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
4741 case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED";
4742 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
4743 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
4744 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
4745 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
4746 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)";
4747 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
4748 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
4749 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
4750 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
4751 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
4752 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
4753 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL";
4754 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
4755 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
4756 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
4757 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
4758 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_NEW_CDMA_SMS";
4759 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_NEW_BROADCAST_SMS";
4760 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
4761 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
4762 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
4763 case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
4764 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
4765 case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
4766 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
4767 case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
4768 case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
4769 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
4770 case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
4771 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
4772 case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
4773 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
Ethan Chend6e30652013-08-04 22:49:56 -07004774 case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
Andrew Jiangca4a9a02014-01-18 18:04:08 -05004775 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "RESPONSE_IMS_NETWORK_STATE_CHANGED";
Howard Sue32dbfd2015-01-07 15:55:57 +08004776 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return "UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED";
4777 case RIL_UNSOL_SRVCC_STATE_NOTIFY: return "UNSOL_SRVCC_STATE_NOTIFY";
4778 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return "HARDWARE_CONFIG_CHANGED";
4779 case RIL_UNSOL_DC_RT_INFO_CHANGED: return "UNSOL_DC_RT_INFO_CHANGED";
4780 case RIL_REQUEST_SHUTDOWN: return "SHUTDOWN";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004781 default: return "<unknown request>";
4782 }
4783}
4784
Howard Sue32dbfd2015-01-07 15:55:57 +08004785const char *
4786rilSocketIdToString(RIL_SOCKET_ID socket_id)
4787{
4788 switch(socket_id) {
4789 case RIL_SOCKET_1:
4790 return "RIL_SOCKET_1";
4791#if (SIM_COUNT >= 2)
4792 case RIL_SOCKET_2:
4793 return "RIL_SOCKET_2";
4794#endif
4795#if (SIM_COUNT >= 3)
4796 case RIL_SOCKET_3:
4797 return "RIL_SOCKET_3";
4798#endif
4799#if (SIM_COUNT >= 4)
4800 case RIL_SOCKET_4:
4801 return "RIL_SOCKET_4";
4802#endif
4803 default:
4804 return "not a valid RIL";
4805 }
4806}
4807
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004808} /* namespace android */