blob: 66dd958863aecdc42f334a141674c3d2316f3c32 [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
121enum WakeType {DONT_WAKE, WAKE_PARTIAL};
122
123typedef struct {
124 int requestNumber;
125 void (*dispatchFunction) (Parcel &p, struct RequestInfo *pRI);
126 int(*responseFunction) (Parcel &p, void *response, size_t responselen);
127} CommandInfo;
128
129typedef struct {
130 int requestNumber;
131 int (*responseFunction) (Parcel &p, void *response, size_t responselen);
132 WakeType wakeType;
133} UnsolResponseInfo;
134
135typedef struct RequestInfo {
136 int32_t token; //this is not RIL_Token
137 CommandInfo *pCI;
138 struct RequestInfo *p_next;
139 char cancelled;
140 char local; // responses to local commands do not go back to command process
Howard Sue32dbfd2015-01-07 15:55:57 +0800141 RIL_SOCKET_ID socket_id;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200142} RequestInfo;
143
144typedef struct UserCallbackInfo {
145 RIL_TimedCallback p_callback;
146 void *userParam;
147 struct ril_event event;
148 struct UserCallbackInfo *p_next;
149} UserCallbackInfo;
150
Howard Sue32dbfd2015-01-07 15:55:57 +0800151typedef struct SocketListenParam {
152 RIL_SOCKET_ID socket_id;
153 int fdListen;
154 int fdCommand;
155 char* processName;
156 struct ril_event* commands_event;
157 struct ril_event* listen_event;
158 void (*processCommandsCallback)(int fd, short flags, void *param);
159 RecordStream *p_rs;
160} SocketListenParam;
161
162extern "C" const char * requestToString(int request);
163extern "C" const char * failCauseToString(RIL_Errno);
164extern "C" const char * callStateToString(RIL_CallState);
165extern "C" const char * radioStateToString(RIL_RadioState);
166extern "C" const char * rilSocketIdToString(RIL_SOCKET_ID socket_id);
167
168extern "C"
169char rild[MAX_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200170
Howard Subd82ef12015-04-12 10:25:05 +0200171#define RIL_VENDOR_COMMANDS_OFFSET 10000
172
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200173/*******************************************************************/
174
175RIL_RadioFunctions s_callbacks = {0, NULL, NULL, NULL, NULL, NULL};
176static int s_registerCalled = 0;
177
178static pthread_t s_tid_dispatch;
179static pthread_t s_tid_reader;
180static int s_started = 0;
181
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200182static int s_fdDebug = -1;
Howard Sue32dbfd2015-01-07 15:55:57 +0800183static int s_fdDebug_socket2 = -1;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200184
185static int s_fdWakeupRead;
186static int s_fdWakeupWrite;
187
188static struct ril_event s_commands_event;
189static struct ril_event s_wakeupfd_event;
190static struct ril_event s_listen_event;
Howard Sue32dbfd2015-01-07 15:55:57 +0800191static SocketListenParam s_ril_param_socket;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200192
193static pthread_mutex_t s_pendingRequestsMutex = PTHREAD_MUTEX_INITIALIZER;
194static pthread_mutex_t s_writeMutex = PTHREAD_MUTEX_INITIALIZER;
Howard Sue32dbfd2015-01-07 15:55:57 +0800195static RequestInfo *s_pendingRequests = NULL;
196
197#if (SIM_COUNT >= 2)
198static struct ril_event s_commands_event_socket2;
199static struct ril_event s_listen_event_socket2;
200static SocketListenParam s_ril_param_socket2;
201
202static pthread_mutex_t s_pendingRequestsMutex_socket2 = PTHREAD_MUTEX_INITIALIZER;
203static pthread_mutex_t s_writeMutex_socket2 = PTHREAD_MUTEX_INITIALIZER;
204static RequestInfo *s_pendingRequests_socket2 = NULL;
205#endif
206
207#if (SIM_COUNT >= 3)
208static struct ril_event s_commands_event_socket3;
209static struct ril_event s_listen_event_socket3;
210static SocketListenParam s_ril_param_socket3;
211
212static pthread_mutex_t s_pendingRequestsMutex_socket3 = PTHREAD_MUTEX_INITIALIZER;
213static pthread_mutex_t s_writeMutex_socket3 = PTHREAD_MUTEX_INITIALIZER;
214static RequestInfo *s_pendingRequests_socket3 = NULL;
215#endif
216
217#if (SIM_COUNT >= 4)
218static struct ril_event s_commands_event_socket4;
219static struct ril_event s_listen_event_socket4;
220static SocketListenParam s_ril_param_socket4;
221
222static pthread_mutex_t s_pendingRequestsMutex_socket4 = PTHREAD_MUTEX_INITIALIZER;
223static pthread_mutex_t s_writeMutex_socket4 = PTHREAD_MUTEX_INITIALIZER;
224static RequestInfo *s_pendingRequests_socket4 = NULL;
225#endif
226
227static struct ril_event s_wake_timeout_event;
228static struct ril_event s_debug_event;
229
Howard Subd82ef12015-04-12 10:25:05 +0200230
Howard Sue32dbfd2015-01-07 15:55:57 +0800231static const struct timeval TIMEVAL_WAKE_TIMEOUT = {1,0};
232
Howard Subd82ef12015-04-12 10:25:05 +0200233
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200234static pthread_mutex_t s_startupMutex = PTHREAD_MUTEX_INITIALIZER;
235static pthread_cond_t s_startupCond = PTHREAD_COND_INITIALIZER;
236
237static pthread_mutex_t s_dispatchMutex = PTHREAD_MUTEX_INITIALIZER;
238static pthread_cond_t s_dispatchCond = PTHREAD_COND_INITIALIZER;
239
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200240static RequestInfo *s_toDispatchHead = NULL;
241static RequestInfo *s_toDispatchTail = NULL;
242
243static UserCallbackInfo *s_last_wake_timeout_info = NULL;
244
245static void *s_lastNITZTimeData = NULL;
246static size_t s_lastNITZTimeDataSize;
247
248#if RILC_LOG
249 static char printBuf[PRINTBUF_SIZE];
250#endif
251
252/*******************************************************************/
Howard Sue32dbfd2015-01-07 15:55:57 +0800253static int sendResponse (Parcel &p, RIL_SOCKET_ID socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200254
255static void dispatchVoid (Parcel& p, RequestInfo *pRI);
256static void dispatchString (Parcel& p, RequestInfo *pRI);
257static void dispatchStrings (Parcel& p, RequestInfo *pRI);
258static void dispatchInts (Parcel& p, RequestInfo *pRI);
259static void dispatchDial (Parcel& p, RequestInfo *pRI);
260static void dispatchSIM_IO (Parcel& p, RequestInfo *pRI);
Howard Sue32dbfd2015-01-07 15:55:57 +0800261static void dispatchSIM_APDU (Parcel& p, RequestInfo *pRI);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200262static void dispatchCallForward(Parcel& p, RequestInfo *pRI);
263static void dispatchRaw(Parcel& p, RequestInfo *pRI);
264static void dispatchSmsWrite (Parcel &p, RequestInfo *pRI);
265static void dispatchDataCall (Parcel& p, RequestInfo *pRI);
266static void dispatchVoiceRadioTech (Parcel& p, RequestInfo *pRI);
Andrew Jiangca4a9a02014-01-18 18:04:08 -0500267static void dispatchSetInitialAttachApn (Parcel& p, RequestInfo *pRI);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200268static void dispatchCdmaSubscriptionSource (Parcel& p, RequestInfo *pRI);
269
270static void dispatchCdmaSms(Parcel &p, RequestInfo *pRI);
Andrew Jiangca4a9a02014-01-18 18:04:08 -0500271static void dispatchImsSms(Parcel &p, RequestInfo *pRI);
272static void dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
273static void dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200274static void dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI);
275static void dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI);
276static void dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI);
277static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI);
Howard Sue32dbfd2015-01-07 15:55:57 +0800278static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI);
279static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI);
280static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI);
281static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI);
282static void dispatchDataProfile(Parcel &p, RequestInfo *pRI);
Howard Subd82ef12015-04-12 10:25:05 +0200283static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200284static int responseInts(Parcel &p, void *response, size_t responselen);
Daniel Hillenbrandd0b84162015-04-12 11:53:23 +0200285static int responseIntsGetPreferredNetworkType(Parcel &p, void *response, size_t responselen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200286static int responseStrings(Parcel &p, void *response, size_t responselen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200287static int responseStrings(Parcel &p, void *response, size_t responselen, bool network_search);
288static int responseString(Parcel &p, void *response, size_t responselen);
289static int responseVoid(Parcel &p, void *response, size_t responselen);
290static int responseCallList(Parcel &p, void *response, size_t responselen);
291static int responseSMS(Parcel &p, void *response, size_t responselen);
292static int responseSIM_IO(Parcel &p, void *response, size_t responselen);
293static int responseCallForwards(Parcel &p, void *response, size_t responselen);
294static int responseDataCallList(Parcel &p, void *response, size_t responselen);
295static int responseSetupDataCall(Parcel &p, void *response, size_t responselen);
296static int responseRaw(Parcel &p, void *response, size_t responselen);
297static int responseSsn(Parcel &p, void *response, size_t responselen);
298static int responseSimStatus(Parcel &p, void *response, size_t responselen);
299static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen);
300static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen);
301static int responseCdmaSms(Parcel &p, void *response, size_t responselen);
302static int responseCellList(Parcel &p, void *response, size_t responselen);
303static int responseCdmaInformationRecords(Parcel &p,void *response, size_t responselen);
304static int responseRilSignalStrength(Parcel &p,void *response, size_t responselen);
305static int responseCallRing(Parcel &p, void *response, size_t responselen);
306static int responseCdmaSignalInfoRecord(Parcel &p,void *response, size_t responselen);
307static int responseCdmaCallWaiting(Parcel &p,void *response, size_t responselen);
308static int responseSimRefresh(Parcel &p, void *response, size_t responselen);
XpLoDWilDba5c6a32013-07-27 21:12:19 +0200309static int responseCellInfoList(Parcel &p, void *response, size_t responselen);
Howard Sue32dbfd2015-01-07 15:55:57 +0800310static int responseHardwareConfig(Parcel &p, void *response, size_t responselen);
311static int responseDcRtInfo(Parcel &p, void *response, size_t responselen);
Howard Subd82ef12015-04-12 10:25:05 +0200312static int responseRadioCapability(Parcel &p, void *response, size_t responselen);
313static int responseSSData(Parcel &p, void *response, size_t responselen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200314
315static int decodeVoiceRadioTechnology (RIL_RadioState radioState);
316static int decodeCdmaSubscriptionSource (RIL_RadioState radioState);
Howard Subd82ef12015-04-12 10:25:05 +0200317static RIL_RadioState processRadioState(RIL_RadioState newRadioState);
318
319static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200320
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200321#ifdef RIL_SHLIB
Howard Sue32dbfd2015-01-07 15:55:57 +0800322#if defined(ANDROID_MULTI_SIM)
Andreas Schneider47b2d962015-04-13 22:54:49 +0200323extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Howard Sue32dbfd2015-01-07 15:55:57 +0800324 size_t datalen, RIL_SOCKET_ID socket_id);
325#else
Andreas Schneider47b2d962015-04-13 22:54:49 +0200326extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200327 size_t datalen);
328#endif
Howard Sue32dbfd2015-01-07 15:55:57 +0800329#endif
330
331#if defined(ANDROID_MULTI_SIM)
332#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c), (d))
333#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d), (e))
334#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest(a)
335#else
336#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c))
337#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d))
338#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest()
339#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200340
341static UserCallbackInfo * internalRequestTimedCallback
342 (RIL_TimedCallback callback, void *param,
343 const struct timeval *relativeTime);
344
345/** Index == requestNumber */
346static CommandInfo s_commands[] = {
347#include "ril_commands.h"
348};
349
Howard Subd82ef12015-04-12 10:25:05 +0200350static CommandInfo s_commands_v[] = {
351#include "ril_commands_vendor.h"
352};
353
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200354static UnsolResponseInfo s_unsolResponses[] = {
355#include "ril_unsol_commands.h"
356};
357
Howard Subd82ef12015-04-12 10:25:05 +0200358static UnsolResponseInfo s_unsolResponses_v[] = {
359#include "ril_unsol_commands_vendor.h"
360};
361
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200362/* For older RILs that do not support new commands RIL_REQUEST_VOICE_RADIO_TECH and
363 RIL_UNSOL_VOICE_RADIO_TECH_CHANGED messages, decode the voice radio tech from
364 radio state message and store it. Every time there is a change in Radio State
365 check to see if voice radio tech changes and notify telephony
366 */
367int voiceRadioTech = -1;
368
369/* For older RILs that do not support new commands RIL_REQUEST_GET_CDMA_SUBSCRIPTION_SOURCE
370 and RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED messages, decode the subscription
371 source from radio state and store it. Every time there is a change in Radio State
372 check to see if subscription source changed and notify telephony
373 */
374int cdmaSubscriptionSource = -1;
375
376/* For older RILs that do not send RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, decode the
377 SIM/RUIM state from radio state and store it. Every time there is a change in Radio State,
378 check to see if SIM/RUIM status changed and notify telephony
379 */
380int simRuimStatus = -1;
381
Howard Sue32dbfd2015-01-07 15:55:57 +0800382static char * RIL_getRilSocketName() {
383 return rild;
384}
385
386extern "C"
387void RIL_setRilSocketName(char * s) {
388 strncpy(rild, s, MAX_SOCKET_NAME_LENGTH);
389}
390
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200391static char *
392strdupReadString(Parcel &p) {
393 size_t stringlen;
394 const char16_t *s16;
395
396 s16 = p.readString16Inplace(&stringlen);
397
398 return strndup16to8(s16, stringlen);
399}
400
Howard Subd82ef12015-04-12 10:25:05 +0200401static status_t
402readStringFromParcelInplace(Parcel &p, char *str, size_t maxLen) {
403 size_t s16Len;
404 const char16_t *s16;
405
406 s16 = p.readString16Inplace(&s16Len);
407 if (s16 == NULL) {
408 return NO_MEMORY;
409 }
410 size_t strLen = strnlen16to8(s16, s16Len);
411 if ((strLen + 1) > maxLen) {
412 return NO_MEMORY;
413 }
414 if (strncpy16to8(str, s16, strLen) == NULL) {
415 return NO_MEMORY;
416 } else {
417 return NO_ERROR;
418 }
419}
420
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200421static void writeStringToParcel(Parcel &p, const char *s) {
422 char16_t *s16;
423 size_t s16_len;
424 s16 = strdup8to16(s, &s16_len);
425 p.writeString16(s16, s16_len);
426 free(s16);
427}
428
429
430static void
431memsetString (char *s) {
432 if (s != NULL) {
433 memset (s, 0, strlen(s));
434 }
435}
436
437void nullParcelReleaseFunction (const uint8_t* data, size_t dataSize,
438 const size_t* objects, size_t objectsSize,
439 void* cookie) {
440 // do nothing -- the data reference lives longer than the Parcel object
441}
442
443/**
444 * To be called from dispatch thread
445 * Issue a single local request, ensuring that the response
446 * is not sent back up to the command process
447 */
448static void
Howard Sue32dbfd2015-01-07 15:55:57 +0800449issueLocalRequest(int request, void *data, int len, RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200450 RequestInfo *pRI;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200451 int ret;
Howard Sue32dbfd2015-01-07 15:55:57 +0800452 /* Hook for current context */
453 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
454 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
455 /* pendingRequestsHook refer to &s_pendingRequests */
456 RequestInfo** pendingRequestsHook = &s_pendingRequests;
457
458#if (SIM_COUNT == 2)
459 if (socket_id == RIL_SOCKET_2) {
460 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
461 pendingRequestsHook = &s_pendingRequests_socket2;
462 }
463#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200464
465 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
466
467 pRI->local = 1;
468 pRI->token = 0xffffffff; // token is not used in this context
469
Howard Subd82ef12015-04-12 10:25:05 +0200470 /* Check vendor commands */
471 if (request > RIL_VENDOR_COMMANDS_OFFSET) {
472 pRI->pCI = &(s_commands_v[request - RIL_VENDOR_COMMANDS_OFFSET]);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200473 } else {
474 pRI->pCI = &(s_commands[request]);
475 }
Howard Sue32dbfd2015-01-07 15:55:57 +0800476 pRI->socket_id = socket_id;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200477
Howard Sue32dbfd2015-01-07 15:55:57 +0800478 ret = pthread_mutex_lock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200479 assert (ret == 0);
480
Howard Sue32dbfd2015-01-07 15:55:57 +0800481 pRI->p_next = *pendingRequestsHook;
482 *pendingRequestsHook = pRI;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200483
Howard Sue32dbfd2015-01-07 15:55:57 +0800484 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200485 assert (ret == 0);
486
XpLoDWilDba5c6a32013-07-27 21:12:19 +0200487 RLOGD("C[locl]> %s", requestToString(request));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200488
Howard Sue32dbfd2015-01-07 15:55:57 +0800489 CALL_ONREQUEST(request, data, len, pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200490}
491
Howard Subd82ef12015-04-12 10:25:05 +0200492
493
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200494static int
Howard Sue32dbfd2015-01-07 15:55:57 +0800495processCommandBuffer(void *buffer, size_t buflen, RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200496 Parcel p;
497 status_t status;
498 int32_t request;
499 int32_t token;
500 RequestInfo *pRI;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200501 int ret;
Howard Sue32dbfd2015-01-07 15:55:57 +0800502 /* Hook for current context */
503 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
504 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
505 /* pendingRequestsHook refer to &s_pendingRequests */
506 RequestInfo** pendingRequestsHook = &s_pendingRequests;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200507
508 p.setData((uint8_t *) buffer, buflen);
509
510 // status checked at end
511 status = p.readInt32(&request);
512 status = p.readInt32 (&token);
513
Howard Sue32dbfd2015-01-07 15:55:57 +0800514#if (SIM_COUNT >= 2)
515 if (socket_id == RIL_SOCKET_2) {
516 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
517 pendingRequestsHook = &s_pendingRequests_socket2;
518 }
519#if (SIM_COUNT >= 3)
520 else if (socket_id == RIL_SOCKET_3) {
521 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
522 pendingRequestsHook = &s_pendingRequests_socket3;
523 }
524#endif
525#if (SIM_COUNT >= 4)
526 else if (socket_id == RIL_SOCKET_4) {
527 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
528 pendingRequestsHook = &s_pendingRequests_socket4;
529 }
530#endif
531#endif
532
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200533 if (status != NO_ERROR) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +0200534 RLOGE("invalid request block");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200535 return 0;
536 }
537
Howard Subd82ef12015-04-12 10:25:05 +0200538 CommandInfo *pCI = NULL;
539 if (request > RIL_VENDOR_COMMANDS_OFFSET) {
540 int index = request - RIL_VENDOR_COMMANDS_OFFSET;
541 RLOGD("processCommandBuffer: samsung request=%d, index=%d",
542 request, index);
543 if (index < (int32_t)NUM_ELEMS(s_commands_v))
544 pCI = &(s_commands_v[index]);
545 } else {
546 if (request < (int32_t)NUM_ELEMS(s_commands))
547 pCI = &(s_commands[request]);
548 }
Howard Sue32dbfd2015-01-07 15:55:57 +0800549
Howard Subd82ef12015-04-12 10:25:05 +0200550 if (pCI == NULL) {
551 Parcel pErr;
XpLoDWilDba5c6a32013-07-27 21:12:19 +0200552 RLOGE("unsupported request code %d token %d", request, token);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200553 // FIXME this should perhaps return a response
Howard Sue32dbfd2015-01-07 15:55:57 +0800554 pErr.writeInt32 (RESPONSE_SOLICITED);
555 pErr.writeInt32 (token);
556 pErr.writeInt32 (RIL_E_GENERIC_FAILURE);
557
558 sendResponse(pErr, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200559 return 0;
560 }
561
562 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
563
564 pRI->token = token;
Howard Subd82ef12015-04-12 10:25:05 +0200565 pRI->pCI = pCI;
Howard Sue32dbfd2015-01-07 15:55:57 +0800566 pRI->socket_id = socket_id;
567
568 ret = pthread_mutex_lock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200569 assert (ret == 0);
570
Howard Sue32dbfd2015-01-07 15:55:57 +0800571 pRI->p_next = *pendingRequestsHook;
572 *pendingRequestsHook = pRI;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200573
Howard Sue32dbfd2015-01-07 15:55:57 +0800574 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200575 assert (ret == 0);
576
577/* sLastDispatchedToken = token; */
578
579 pRI->pCI->dispatchFunction(p, pRI);
580
581 return 0;
582}
583
584static void
585invalidCommandBlock (RequestInfo *pRI) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +0200586 RLOGE("invalid command block for token %d request %s",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200587 pRI->token, requestToString(pRI->pCI->requestNumber));
588}
589
590/** Callee expects NULL */
591static void
592dispatchVoid (Parcel& p, RequestInfo *pRI) {
593 clearPrintBuf;
594 printRequest(pRI->token, pRI->pCI->requestNumber);
Howard Sue32dbfd2015-01-07 15:55:57 +0800595 CALL_ONREQUEST(pRI->pCI->requestNumber, NULL, 0, pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200596}
597
598/** Callee expects const char * */
599static void
600dispatchString (Parcel& p, RequestInfo *pRI) {
601 status_t status;
602 size_t datalen;
603 size_t stringlen;
604 char *string8 = NULL;
605
606 string8 = strdupReadString(p);
607
608 startRequest;
609 appendPrintBuf("%s%s", printBuf, string8);
610 closeRequest;
611 printRequest(pRI->token, pRI->pCI->requestNumber);
612
Howard Sue32dbfd2015-01-07 15:55:57 +0800613 CALL_ONREQUEST(pRI->pCI->requestNumber, string8,
614 sizeof(char *), pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200615
616#ifdef MEMSET_FREED
617 memsetString(string8);
618#endif
619
620 free(string8);
621 return;
622invalid:
623 invalidCommandBlock(pRI);
624 return;
625}
626
627/** Callee expects const char ** */
628static void
629dispatchStrings (Parcel &p, RequestInfo *pRI) {
630 int32_t countStrings;
631 status_t status;
632 size_t datalen;
633 char **pStrings;
634
635 status = p.readInt32 (&countStrings);
636
637 if (status != NO_ERROR) {
638 goto invalid;
639 }
640
641 startRequest;
642 if (countStrings == 0) {
643 // just some non-null pointer
644 pStrings = (char **)alloca(sizeof(char *));
645 datalen = 0;
646 } else if (((int)countStrings) == -1) {
647 pStrings = NULL;
648 datalen = 0;
649 } else {
650 datalen = sizeof(char *) * countStrings;
651
652 pStrings = (char **)alloca(datalen);
653
654 for (int i = 0 ; i < countStrings ; i++) {
655 pStrings[i] = strdupReadString(p);
656 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
657 }
658 }
659 removeLastChar;
660 closeRequest;
661 printRequest(pRI->token, pRI->pCI->requestNumber);
662
Howard Sue32dbfd2015-01-07 15:55:57 +0800663 CALL_ONREQUEST(pRI->pCI->requestNumber, pStrings, datalen, pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200664
665 if (pStrings != NULL) {
666 for (int i = 0 ; i < countStrings ; i++) {
667#ifdef MEMSET_FREED
668 memsetString (pStrings[i]);
669#endif
670 free(pStrings[i]);
671 }
672
673#ifdef MEMSET_FREED
674 memset(pStrings, 0, datalen);
675#endif
676 }
677
678 return;
679invalid:
680 invalidCommandBlock(pRI);
681 return;
682}
683
684/** Callee expects const int * */
685static void
686dispatchInts (Parcel &p, RequestInfo *pRI) {
687 int32_t count;
688 status_t status;
689 size_t datalen;
690 int *pInts;
691
692 status = p.readInt32 (&count);
693
694 if (status != NO_ERROR || count == 0) {
695 goto invalid;
696 }
697
698 datalen = sizeof(int) * count;
699 pInts = (int *)alloca(datalen);
700
701 startRequest;
702 for (int i = 0 ; i < count ; i++) {
703 int32_t t;
704
705 status = p.readInt32(&t);
706 pInts[i] = (int)t;
707 appendPrintBuf("%s%d,", printBuf, t);
708
709 if (status != NO_ERROR) {
710 goto invalid;
711 }
712 }
713 removeLastChar;
714 closeRequest;
715 printRequest(pRI->token, pRI->pCI->requestNumber);
716
Howard Sue32dbfd2015-01-07 15:55:57 +0800717 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<int *>(pInts),
718 datalen, pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200719
720#ifdef MEMSET_FREED
721 memset(pInts, 0, datalen);
722#endif
723
724 return;
725invalid:
726 invalidCommandBlock(pRI);
727 return;
728}
729
730
731/**
732 * Callee expects const RIL_SMS_WriteArgs *
733 * Payload is:
734 * int32_t status
735 * String pdu
736 */
737static void
738dispatchSmsWrite (Parcel &p, RequestInfo *pRI) {
739 RIL_SMS_WriteArgs args;
740 int32_t t;
741 status_t status;
742
743 memset (&args, 0, sizeof(args));
744
745 status = p.readInt32(&t);
746 args.status = (int)t;
747
748 args.pdu = strdupReadString(p);
749
750 if (status != NO_ERROR || args.pdu == NULL) {
751 goto invalid;
752 }
753
754 args.smsc = strdupReadString(p);
755
756 startRequest;
757 appendPrintBuf("%s%d,%s,smsc=%s", printBuf, args.status,
758 (char*)args.pdu, (char*)args.smsc);
759 closeRequest;
760 printRequest(pRI->token, pRI->pCI->requestNumber);
761
Howard Sue32dbfd2015-01-07 15:55:57 +0800762 CALL_ONREQUEST(pRI->pCI->requestNumber, &args, sizeof(args), pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200763
764#ifdef MEMSET_FREED
765 memsetString (args.pdu);
766#endif
767
768 free (args.pdu);
769
770#ifdef MEMSET_FREED
771 memset(&args, 0, sizeof(args));
772#endif
773
774 return;
775invalid:
776 invalidCommandBlock(pRI);
777 return;
778}
779
780/**
781 * Callee expects const RIL_Dial *
782 * Payload is:
783 * String address
784 * int32_t clir
785 */
786static void
787dispatchDial (Parcel &p, RequestInfo *pRI) {
788 RIL_Dial dial;
789 RIL_UUS_Info uusInfo;
790 int32_t sizeOfDial;
791 int32_t t;
792 int32_t uusPresent;
Andreas Schneider29472682015-01-01 19:00:04 +0100793#ifdef MODEM_TYPE_XMM7260
794 char *csv;
795#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200796 status_t status;
797
798 memset (&dial, 0, sizeof(dial));
799
800 dial.address = strdupReadString(p);
801
802 status = p.readInt32(&t);
803 dial.clir = (int)t;
804
805 if (status != NO_ERROR || dial.address == NULL) {
806 goto invalid;
807 }
808
Andreas Schneider29472682015-01-01 19:00:04 +0100809#ifdef MODEM_TYPE_XMM7260
810 /* CallDetails.call_type */
811 status = p.readInt32(&t);
812 if (status != NO_ERROR) {
813 goto invalid;
814 }
815 /* CallDetails.call_domain */
816 p.readInt32(&t);
817 if (status != NO_ERROR) {
818 goto invalid;
819 }
820 /* CallDetails.getCsvFromExtra */
821 csv = strdupReadString(p);
822 if (csv == NULL) {
823 goto invalid;
824 }
825 free(csv);
826#endif
827
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200828 if (s_callbacks.version < 3) { // Remove when partners upgrade to version 3
829 uusPresent = 0;
830 sizeOfDial = sizeof(dial) - sizeof(RIL_UUS_Info *);
831 } else {
832 status = p.readInt32(&uusPresent);
833
834 if (status != NO_ERROR) {
835 goto invalid;
836 }
837
838 if (uusPresent == 0) {
Andreas Schneidereef440e2015-04-07 19:01:54 +0200839#if defined(MODEM_TYPE_XMM6262) || defined(MODEM_TYPE_XMM7260)
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200840 dial.uusInfo = NULL;
Andreas Schneiderf68609b2015-04-07 19:01:34 +0200841#elif defined(MODEM_TYPE_XMM6260)
Howard Sue32dbfd2015-01-07 15:55:57 +0800842 /* Samsung hack */
843 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
844 uusInfo.uusType = (RIL_UUS_Type) 0;
845 uusInfo.uusDcs = (RIL_UUS_DCS) 0;
846 uusInfo.uusData = NULL;
847 uusInfo.uusLength = 0;
848 dial.uusInfo = &uusInfo;
849#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200850 } else {
851 int32_t len;
852
853 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
854
855 status = p.readInt32(&t);
856 uusInfo.uusType = (RIL_UUS_Type) t;
857
858 status = p.readInt32(&t);
859 uusInfo.uusDcs = (RIL_UUS_DCS) t;
860
861 status = p.readInt32(&len);
862 if (status != NO_ERROR) {
863 goto invalid;
864 }
865
866 // The java code writes -1 for null arrays
867 if (((int) len) == -1) {
868 uusInfo.uusData = NULL;
869 len = 0;
870 } else {
871 uusInfo.uusData = (char*) p.readInplace(len);
872 }
873
874 uusInfo.uusLength = len;
875 dial.uusInfo = &uusInfo;
876 }
877 sizeOfDial = sizeof(dial);
878 }
879
880 startRequest;
881 appendPrintBuf("%snum=%s,clir=%d", printBuf, dial.address, dial.clir);
882 if (uusPresent) {
883 appendPrintBuf("%s,uusType=%d,uusDcs=%d,uusLen=%d", printBuf,
884 dial.uusInfo->uusType, dial.uusInfo->uusDcs,
885 dial.uusInfo->uusLength);
886 }
887 closeRequest;
888 printRequest(pRI->token, pRI->pCI->requestNumber);
889
Howard Sue32dbfd2015-01-07 15:55:57 +0800890 CALL_ONREQUEST(pRI->pCI->requestNumber, &dial, sizeOfDial, pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200891
892#ifdef MEMSET_FREED
893 memsetString (dial.address);
894#endif
895
896 free (dial.address);
897
898#ifdef MEMSET_FREED
899 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
900 memset(&dial, 0, sizeof(dial));
901#endif
902
903 return;
904invalid:
905 invalidCommandBlock(pRI);
906 return;
907}
908
909/**
910 * Callee expects const RIL_SIM_IO *
911 * Payload is:
912 * int32_t command
913 * int32_t fileid
914 * String path
915 * int32_t p1, p2, p3
916 * String data
917 * String pin2
918 * String aidPtr
919 */
920static void
921dispatchSIM_IO (Parcel &p, RequestInfo *pRI) {
922 union RIL_SIM_IO {
923 RIL_SIM_IO_v6 v6;
924 RIL_SIM_IO_v5 v5;
925 } simIO;
926
927 int32_t t;
928 int size;
929 status_t status;
930
931 memset (&simIO, 0, sizeof(simIO));
932
933 // note we only check status at the end
934
935 status = p.readInt32(&t);
936 simIO.v6.command = (int)t;
937
938 status = p.readInt32(&t);
939 simIO.v6.fileid = (int)t;
940
941 simIO.v6.path = strdupReadString(p);
942
943 status = p.readInt32(&t);
944 simIO.v6.p1 = (int)t;
945
946 status = p.readInt32(&t);
947 simIO.v6.p2 = (int)t;
948
949 status = p.readInt32(&t);
950 simIO.v6.p3 = (int)t;
951
952 simIO.v6.data = strdupReadString(p);
953 simIO.v6.pin2 = strdupReadString(p);
954 simIO.v6.aidPtr = strdupReadString(p);
955
956 startRequest;
957 appendPrintBuf("%scmd=0x%X,efid=0x%X,path=%s,%d,%d,%d,%s,pin2=%s,aid=%s", printBuf,
958 simIO.v6.command, simIO.v6.fileid, (char*)simIO.v6.path,
959 simIO.v6.p1, simIO.v6.p2, simIO.v6.p3,
960 (char*)simIO.v6.data, (char*)simIO.v6.pin2, simIO.v6.aidPtr);
961 closeRequest;
962 printRequest(pRI->token, pRI->pCI->requestNumber);
963
964 if (status != NO_ERROR) {
965 goto invalid;
966 }
967
968 size = (s_callbacks.version < 6) ? sizeof(simIO.v5) : sizeof(simIO.v6);
Howard Sue32dbfd2015-01-07 15:55:57 +0800969 CALL_ONREQUEST(pRI->pCI->requestNumber, &simIO, size, pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200970
971#ifdef MEMSET_FREED
972 memsetString (simIO.v6.path);
973 memsetString (simIO.v6.data);
974 memsetString (simIO.v6.pin2);
975 memsetString (simIO.v6.aidPtr);
976#endif
977
978 free (simIO.v6.path);
979 free (simIO.v6.data);
980 free (simIO.v6.pin2);
981 free (simIO.v6.aidPtr);
982
983#ifdef MEMSET_FREED
984 memset(&simIO, 0, sizeof(simIO));
985#endif
986
987 return;
988invalid:
989 invalidCommandBlock(pRI);
990 return;
991}
992
993/**
Howard Sue32dbfd2015-01-07 15:55:57 +0800994 * Callee expects const RIL_SIM_APDU *
995 * Payload is:
996 * int32_t sessionid
997 * int32_t cla
998 * int32_t instruction
999 * int32_t p1, p2, p3
1000 * String data
1001 */
1002static void
1003dispatchSIM_APDU (Parcel &p, RequestInfo *pRI) {
1004 int32_t t;
1005 status_t status;
1006 RIL_SIM_APDU apdu;
1007
1008 memset (&apdu, 0, sizeof(RIL_SIM_APDU));
1009
1010 // Note we only check status at the end. Any single failure leads to
1011 // subsequent reads filing.
1012 status = p.readInt32(&t);
1013 apdu.sessionid = (int)t;
1014
1015 status = p.readInt32(&t);
1016 apdu.cla = (int)t;
1017
1018 status = p.readInt32(&t);
1019 apdu.instruction = (int)t;
1020
1021 status = p.readInt32(&t);
1022 apdu.p1 = (int)t;
1023
1024 status = p.readInt32(&t);
1025 apdu.p2 = (int)t;
1026
1027 status = p.readInt32(&t);
1028 apdu.p3 = (int)t;
1029
1030 apdu.data = strdupReadString(p);
1031
1032 startRequest;
1033 appendPrintBuf("%ssessionid=%d,cla=%d,ins=%d,p1=%d,p2=%d,p3=%d,data=%s",
1034 printBuf, apdu.sessionid, apdu.cla, apdu.instruction, apdu.p1, apdu.p2,
1035 apdu.p3, (char*)apdu.data);
1036 closeRequest;
1037 printRequest(pRI->token, pRI->pCI->requestNumber);
1038
1039 if (status != NO_ERROR) {
1040 goto invalid;
1041 }
1042
1043 CALL_ONREQUEST(pRI->pCI->requestNumber, &apdu, sizeof(RIL_SIM_APDU), pRI, pRI->socket_id);
1044
1045#ifdef MEMSET_FREED
1046 memsetString(apdu.data);
1047#endif
1048 free(apdu.data);
1049
1050#ifdef MEMSET_FREED
1051 memset(&apdu, 0, sizeof(RIL_SIM_APDU));
1052#endif
1053
1054 return;
1055invalid:
1056 invalidCommandBlock(pRI);
1057 return;
1058}
1059
Howard Subd82ef12015-04-12 10:25:05 +02001060
Howard Sue32dbfd2015-01-07 15:55:57 +08001061/**
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001062 * Callee expects const RIL_CallForwardInfo *
1063 * Payload is:
1064 * int32_t status/action
1065 * int32_t reason
1066 * int32_t serviceCode
1067 * int32_t toa
1068 * String number (0 length -> null)
1069 * int32_t timeSeconds
1070 */
1071static void
1072dispatchCallForward(Parcel &p, RequestInfo *pRI) {
1073 RIL_CallForwardInfo cff;
1074 int32_t t;
1075 status_t status;
1076
1077 memset (&cff, 0, sizeof(cff));
1078
1079 // note we only check status at the end
1080
1081 status = p.readInt32(&t);
1082 cff.status = (int)t;
1083
1084 status = p.readInt32(&t);
1085 cff.reason = (int)t;
1086
1087 status = p.readInt32(&t);
1088 cff.serviceClass = (int)t;
1089
1090 status = p.readInt32(&t);
1091 cff.toa = (int)t;
1092
1093 cff.number = strdupReadString(p);
1094
1095 status = p.readInt32(&t);
1096 cff.timeSeconds = (int)t;
1097
1098 if (status != NO_ERROR) {
1099 goto invalid;
1100 }
1101
1102 // special case: number 0-length fields is null
1103
1104 if (cff.number != NULL && strlen (cff.number) == 0) {
1105 cff.number = NULL;
1106 }
1107
1108 startRequest;
1109 appendPrintBuf("%sstat=%d,reason=%d,serv=%d,toa=%d,%s,tout=%d", printBuf,
1110 cff.status, cff.reason, cff.serviceClass, cff.toa,
1111 (char*)cff.number, cff.timeSeconds);
1112 closeRequest;
1113 printRequest(pRI->token, pRI->pCI->requestNumber);
1114
Howard Sue32dbfd2015-01-07 15:55:57 +08001115 CALL_ONREQUEST(pRI->pCI->requestNumber, &cff, sizeof(cff), pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001116
1117#ifdef MEMSET_FREED
1118 memsetString(cff.number);
1119#endif
1120
1121 free (cff.number);
1122
1123#ifdef MEMSET_FREED
1124 memset(&cff, 0, sizeof(cff));
1125#endif
1126
1127 return;
1128invalid:
1129 invalidCommandBlock(pRI);
1130 return;
1131}
1132
1133
1134static void
1135dispatchRaw(Parcel &p, RequestInfo *pRI) {
1136 int32_t len;
1137 status_t status;
1138 const void *data;
1139
1140 status = p.readInt32(&len);
1141
1142 if (status != NO_ERROR) {
1143 goto invalid;
1144 }
1145
1146 // The java code writes -1 for null arrays
1147 if (((int)len) == -1) {
1148 data = NULL;
1149 len = 0;
1150 }
1151
1152 data = p.readInplace(len);
1153
1154 startRequest;
1155 appendPrintBuf("%sraw_size=%d", printBuf, len);
1156 closeRequest;
1157 printRequest(pRI->token, pRI->pCI->requestNumber);
1158
Howard Sue32dbfd2015-01-07 15:55:57 +08001159 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<void *>(data), len, pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001160
1161 return;
1162invalid:
1163 invalidCommandBlock(pRI);
1164 return;
1165}
1166
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001167static status_t
1168constructCdmaSms(Parcel &p, RequestInfo *pRI, RIL_CDMA_SMS_Message& rcsm) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001169 int32_t t;
1170 uint8_t ut;
1171 status_t status;
1172 int32_t digitCount;
1173 int digitLimit;
1174
1175 memset(&rcsm, 0, sizeof(rcsm));
1176
1177 status = p.readInt32(&t);
1178 rcsm.uTeleserviceID = (int) t;
1179
1180 status = p.read(&ut,sizeof(ut));
1181 rcsm.bIsServicePresent = (uint8_t) ut;
1182
1183 status = p.readInt32(&t);
1184 rcsm.uServicecategory = (int) t;
1185
1186 status = p.readInt32(&t);
1187 rcsm.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1188
1189 status = p.readInt32(&t);
1190 rcsm.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1191
1192 status = p.readInt32(&t);
1193 rcsm.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1194
1195 status = p.readInt32(&t);
1196 rcsm.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1197
1198 status = p.read(&ut,sizeof(ut));
1199 rcsm.sAddress.number_of_digits= (uint8_t) ut;
1200
1201 digitLimit= MIN((rcsm.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
1202 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1203 status = p.read(&ut,sizeof(ut));
1204 rcsm.sAddress.digits[digitCount] = (uint8_t) ut;
1205 }
1206
1207 status = p.readInt32(&t);
1208 rcsm.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1209
1210 status = p.read(&ut,sizeof(ut));
1211 rcsm.sSubAddress.odd = (uint8_t) ut;
1212
1213 status = p.read(&ut,sizeof(ut));
1214 rcsm.sSubAddress.number_of_digits = (uint8_t) ut;
1215
1216 digitLimit= MIN((rcsm.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
1217 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1218 status = p.read(&ut,sizeof(ut));
1219 rcsm.sSubAddress.digits[digitCount] = (uint8_t) ut;
1220 }
1221
1222 status = p.readInt32(&t);
1223 rcsm.uBearerDataLen = (int) t;
1224
1225 digitLimit= MIN((rcsm.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
1226 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1227 status = p.read(&ut, sizeof(ut));
1228 rcsm.aBearerData[digitCount] = (uint8_t) ut;
1229 }
1230
1231 if (status != NO_ERROR) {
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001232 return status;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001233 }
1234
1235 startRequest;
1236 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
1237 sAddress.digit_mode=%d, sAddress.Number_mode=%d, sAddress.number_type=%d, ",
1238 printBuf, rcsm.uTeleserviceID,rcsm.bIsServicePresent,rcsm.uServicecategory,
1239 rcsm.sAddress.digit_mode, rcsm.sAddress.number_mode,rcsm.sAddress.number_type);
1240 closeRequest;
1241
1242 printRequest(pRI->token, pRI->pCI->requestNumber);
1243
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001244 return status;
1245}
1246
1247static void
1248dispatchCdmaSms(Parcel &p, RequestInfo *pRI) {
1249 RIL_CDMA_SMS_Message rcsm;
1250
1251 ALOGD("dispatchCdmaSms");
1252 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1253 goto invalid;
1254 }
1255
Howard Sue32dbfd2015-01-07 15:55:57 +08001256 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm),pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001257
1258#ifdef MEMSET_FREED
1259 memset(&rcsm, 0, sizeof(rcsm));
1260#endif
1261
1262 return;
1263
1264invalid:
1265 invalidCommandBlock(pRI);
1266 return;
1267}
1268
1269static void
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001270dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1271 RIL_IMS_SMS_Message rism;
1272 RIL_CDMA_SMS_Message rcsm;
1273
1274 ALOGD("dispatchImsCdmaSms: retry=%d, messageRef=%d", retry, messageRef);
1275
1276 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1277 goto invalid;
1278 }
1279 memset(&rism, 0, sizeof(rism));
1280 rism.tech = RADIO_TECH_3GPP2;
1281 rism.retry = retry;
1282 rism.messageRef = messageRef;
1283 rism.message.cdmaMessage = &rcsm;
1284
Howard Sue32dbfd2015-01-07 15:55:57 +08001285 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001286 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Howard Sue32dbfd2015-01-07 15:55:57 +08001287 +sizeof(rcsm),pRI, pRI->socket_id);
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001288
1289#ifdef MEMSET_FREED
1290 memset(&rcsm, 0, sizeof(rcsm));
1291 memset(&rism, 0, sizeof(rism));
1292#endif
1293
1294 return;
1295
1296invalid:
1297 invalidCommandBlock(pRI);
1298 return;
1299}
1300
1301static void
1302dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1303 RIL_IMS_SMS_Message rism;
1304 int32_t countStrings;
1305 status_t status;
1306 size_t datalen;
1307 char **pStrings;
1308 ALOGD("dispatchImsGsmSms: retry=%d, messageRef=%d", retry, messageRef);
1309
1310 status = p.readInt32 (&countStrings);
1311
1312 if (status != NO_ERROR) {
1313 goto invalid;
1314 }
1315
1316 memset(&rism, 0, sizeof(rism));
1317 rism.tech = RADIO_TECH_3GPP;
1318 rism.retry = retry;
1319 rism.messageRef = messageRef;
1320
1321 startRequest;
Howard Sue32dbfd2015-01-07 15:55:57 +08001322 appendPrintBuf("%stech=%d, retry=%d, messageRef=%d, ", printBuf,
1323 (int)rism.tech, (int)rism.retry, rism.messageRef);
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001324 if (countStrings == 0) {
1325 // just some non-null pointer
1326 pStrings = (char **)alloca(sizeof(char *));
1327 datalen = 0;
1328 } else if (((int)countStrings) == -1) {
1329 pStrings = NULL;
1330 datalen = 0;
1331 } else {
1332 datalen = sizeof(char *) * countStrings;
1333
1334 pStrings = (char **)alloca(datalen);
1335
1336 for (int i = 0 ; i < countStrings ; i++) {
1337 pStrings[i] = strdupReadString(p);
1338 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
1339 }
1340 }
1341 removeLastChar;
1342 closeRequest;
1343 printRequest(pRI->token, pRI->pCI->requestNumber);
1344
1345 rism.message.gsmMessage = pStrings;
Howard Sue32dbfd2015-01-07 15:55:57 +08001346 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001347 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Howard Sue32dbfd2015-01-07 15:55:57 +08001348 +datalen, pRI, pRI->socket_id);
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001349
1350 if (pStrings != NULL) {
1351 for (int i = 0 ; i < countStrings ; i++) {
1352#ifdef MEMSET_FREED
1353 memsetString (pStrings[i]);
1354#endif
1355 free(pStrings[i]);
1356 }
1357
1358#ifdef MEMSET_FREED
1359 memset(pStrings, 0, datalen);
1360#endif
1361 }
1362
1363#ifdef MEMSET_FREED
1364 memset(&rism, 0, sizeof(rism));
1365#endif
1366 return;
1367invalid:
1368 ALOGE("dispatchImsGsmSms invalid block");
1369 invalidCommandBlock(pRI);
1370 return;
1371}
1372
1373static void
1374dispatchImsSms(Parcel &p, RequestInfo *pRI) {
1375 int32_t t;
1376 status_t status = p.readInt32(&t);
1377 RIL_RadioTechnologyFamily format;
1378 uint8_t retry;
1379 int32_t messageRef;
1380
1381 ALOGD("dispatchImsSms");
1382 if (status != NO_ERROR) {
1383 goto invalid;
1384 }
1385 format = (RIL_RadioTechnologyFamily) t;
1386
1387 // read retry field
1388 status = p.read(&retry,sizeof(retry));
1389 if (status != NO_ERROR) {
1390 goto invalid;
1391 }
1392 // read messageRef field
1393 status = p.read(&messageRef,sizeof(messageRef));
1394 if (status != NO_ERROR) {
1395 goto invalid;
1396 }
1397
1398 if (RADIO_TECH_3GPP == format) {
1399 dispatchImsGsmSms(p, pRI, retry, messageRef);
1400 } else if (RADIO_TECH_3GPP2 == format) {
1401 dispatchImsCdmaSms(p, pRI, retry, messageRef);
1402 } else {
1403 ALOGE("requestImsSendSMS invalid format value =%d", format);
1404 }
1405
1406 return;
1407
1408invalid:
1409 invalidCommandBlock(pRI);
1410 return;
1411}
1412
1413static void
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001414dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI) {
1415 RIL_CDMA_SMS_Ack rcsa;
1416 int32_t t;
1417 status_t status;
1418 int32_t digitCount;
1419
1420 memset(&rcsa, 0, sizeof(rcsa));
1421
1422 status = p.readInt32(&t);
1423 rcsa.uErrorClass = (RIL_CDMA_SMS_ErrorClass) t;
1424
1425 status = p.readInt32(&t);
1426 rcsa.uSMSCauseCode = (int) t;
1427
1428 if (status != NO_ERROR) {
1429 goto invalid;
1430 }
1431
1432 startRequest;
1433 appendPrintBuf("%suErrorClass=%d, uTLStatus=%d, ",
1434 printBuf, rcsa.uErrorClass, rcsa.uSMSCauseCode);
1435 closeRequest;
1436
1437 printRequest(pRI->token, pRI->pCI->requestNumber);
1438
Howard Sue32dbfd2015-01-07 15:55:57 +08001439 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsa, sizeof(rcsa),pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001440
1441#ifdef MEMSET_FREED
1442 memset(&rcsa, 0, sizeof(rcsa));
1443#endif
1444
1445 return;
1446
1447invalid:
1448 invalidCommandBlock(pRI);
1449 return;
1450}
1451
1452static void
1453dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1454 int32_t t;
1455 status_t status;
1456 int32_t num;
1457
1458 status = p.readInt32(&num);
1459 if (status != NO_ERROR) {
1460 goto invalid;
1461 }
1462
Ethan Chend6e30652013-08-04 22:49:56 -07001463 {
1464 RIL_GSM_BroadcastSmsConfigInfo gsmBci[num];
1465 RIL_GSM_BroadcastSmsConfigInfo *gsmBciPtrs[num];
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001466
Ethan Chend6e30652013-08-04 22:49:56 -07001467 startRequest;
1468 for (int i = 0 ; i < num ; i++ ) {
1469 gsmBciPtrs[i] = &gsmBci[i];
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001470
Ethan Chend6e30652013-08-04 22:49:56 -07001471 status = p.readInt32(&t);
1472 gsmBci[i].fromServiceId = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001473
Ethan Chend6e30652013-08-04 22:49:56 -07001474 status = p.readInt32(&t);
1475 gsmBci[i].toServiceId = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001476
Ethan Chend6e30652013-08-04 22:49:56 -07001477 status = p.readInt32(&t);
1478 gsmBci[i].fromCodeScheme = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001479
Ethan Chend6e30652013-08-04 22:49:56 -07001480 status = p.readInt32(&t);
1481 gsmBci[i].toCodeScheme = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001482
Ethan Chend6e30652013-08-04 22:49:56 -07001483 status = p.readInt32(&t);
1484 gsmBci[i].selected = (uint8_t) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001485
Ethan Chend6e30652013-08-04 22:49:56 -07001486 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId =%d, \
1487 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]", printBuf, i,
1488 gsmBci[i].fromServiceId, gsmBci[i].toServiceId,
1489 gsmBci[i].fromCodeScheme, gsmBci[i].toCodeScheme,
1490 gsmBci[i].selected);
1491 }
1492 closeRequest;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001493
Ethan Chend6e30652013-08-04 22:49:56 -07001494 if (status != NO_ERROR) {
1495 goto invalid;
1496 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001497
Howard Sue32dbfd2015-01-07 15:55:57 +08001498 CALL_ONREQUEST(pRI->pCI->requestNumber,
Ethan Chend6e30652013-08-04 22:49:56 -07001499 gsmBciPtrs,
1500 num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *),
Howard Sue32dbfd2015-01-07 15:55:57 +08001501 pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001502
1503#ifdef MEMSET_FREED
Ethan Chend6e30652013-08-04 22:49:56 -07001504 memset(gsmBci, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo));
1505 memset(gsmBciPtrs, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001506#endif
Ethan Chend6e30652013-08-04 22:49:56 -07001507 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001508
1509 return;
1510
1511invalid:
1512 invalidCommandBlock(pRI);
1513 return;
1514}
1515
1516static void
1517dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1518 int32_t t;
1519 status_t status;
1520 int32_t num;
1521
1522 status = p.readInt32(&num);
1523 if (status != NO_ERROR) {
1524 goto invalid;
1525 }
1526
Ethan Chend6e30652013-08-04 22:49:56 -07001527 {
1528 RIL_CDMA_BroadcastSmsConfigInfo cdmaBci[num];
1529 RIL_CDMA_BroadcastSmsConfigInfo *cdmaBciPtrs[num];
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001530
Ethan Chend6e30652013-08-04 22:49:56 -07001531 startRequest;
1532 for (int i = 0 ; i < num ; i++ ) {
1533 cdmaBciPtrs[i] = &cdmaBci[i];
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001534
Ethan Chend6e30652013-08-04 22:49:56 -07001535 status = p.readInt32(&t);
1536 cdmaBci[i].service_category = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001537
Ethan Chend6e30652013-08-04 22:49:56 -07001538 status = p.readInt32(&t);
1539 cdmaBci[i].language = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001540
Ethan Chend6e30652013-08-04 22:49:56 -07001541 status = p.readInt32(&t);
1542 cdmaBci[i].selected = (uint8_t) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001543
Ethan Chend6e30652013-08-04 22:49:56 -07001544 appendPrintBuf("%s [%d: service_category=%d, language =%d, \
1545 entries.bSelected =%d]", printBuf, i, cdmaBci[i].service_category,
1546 cdmaBci[i].language, cdmaBci[i].selected);
1547 }
1548 closeRequest;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001549
Ethan Chend6e30652013-08-04 22:49:56 -07001550 if (status != NO_ERROR) {
1551 goto invalid;
1552 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001553
Howard Sue32dbfd2015-01-07 15:55:57 +08001554 CALL_ONREQUEST(pRI->pCI->requestNumber,
Ethan Chend6e30652013-08-04 22:49:56 -07001555 cdmaBciPtrs,
1556 num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *),
Howard Sue32dbfd2015-01-07 15:55:57 +08001557 pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001558
1559#ifdef MEMSET_FREED
Ethan Chend6e30652013-08-04 22:49:56 -07001560 memset(cdmaBci, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo));
1561 memset(cdmaBciPtrs, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001562#endif
Ethan Chend6e30652013-08-04 22:49:56 -07001563 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001564
1565 return;
1566
1567invalid:
1568 invalidCommandBlock(pRI);
1569 return;
1570}
1571
1572static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI) {
1573 RIL_CDMA_SMS_WriteArgs rcsw;
1574 int32_t t;
1575 uint32_t ut;
1576 uint8_t uct;
1577 status_t status;
1578 int32_t digitCount;
1579
1580 memset(&rcsw, 0, sizeof(rcsw));
1581
1582 status = p.readInt32(&t);
1583 rcsw.status = t;
1584
1585 status = p.readInt32(&t);
1586 rcsw.message.uTeleserviceID = (int) t;
1587
1588 status = p.read(&uct,sizeof(uct));
1589 rcsw.message.bIsServicePresent = (uint8_t) uct;
1590
1591 status = p.readInt32(&t);
1592 rcsw.message.uServicecategory = (int) t;
1593
1594 status = p.readInt32(&t);
1595 rcsw.message.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1596
1597 status = p.readInt32(&t);
1598 rcsw.message.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1599
1600 status = p.readInt32(&t);
1601 rcsw.message.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1602
1603 status = p.readInt32(&t);
1604 rcsw.message.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1605
1606 status = p.read(&uct,sizeof(uct));
1607 rcsw.message.sAddress.number_of_digits = (uint8_t) uct;
1608
1609 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_ADDRESS_MAX; digitCount ++) {
1610 status = p.read(&uct,sizeof(uct));
1611 rcsw.message.sAddress.digits[digitCount] = (uint8_t) uct;
1612 }
1613
1614 status = p.readInt32(&t);
1615 rcsw.message.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1616
1617 status = p.read(&uct,sizeof(uct));
1618 rcsw.message.sSubAddress.odd = (uint8_t) uct;
1619
1620 status = p.read(&uct,sizeof(uct));
1621 rcsw.message.sSubAddress.number_of_digits = (uint8_t) uct;
1622
1623 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_SUBADDRESS_MAX; digitCount ++) {
1624 status = p.read(&uct,sizeof(uct));
1625 rcsw.message.sSubAddress.digits[digitCount] = (uint8_t) uct;
1626 }
1627
1628 status = p.readInt32(&t);
1629 rcsw.message.uBearerDataLen = (int) t;
1630
1631 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_BEARER_DATA_MAX; digitCount ++) {
1632 status = p.read(&uct, sizeof(uct));
1633 rcsw.message.aBearerData[digitCount] = (uint8_t) uct;
1634 }
1635
1636 if (status != NO_ERROR) {
1637 goto invalid;
1638 }
1639
1640 startRequest;
1641 appendPrintBuf("%sstatus=%d, message.uTeleserviceID=%d, message.bIsServicePresent=%d, \
1642 message.uServicecategory=%d, message.sAddress.digit_mode=%d, \
1643 message.sAddress.number_mode=%d, \
1644 message.sAddress.number_type=%d, ",
1645 printBuf, rcsw.status, rcsw.message.uTeleserviceID, rcsw.message.bIsServicePresent,
1646 rcsw.message.uServicecategory, rcsw.message.sAddress.digit_mode,
1647 rcsw.message.sAddress.number_mode,
1648 rcsw.message.sAddress.number_type);
1649 closeRequest;
1650
1651 printRequest(pRI->token, pRI->pCI->requestNumber);
1652
Howard Sue32dbfd2015-01-07 15:55:57 +08001653 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsw, sizeof(rcsw),pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001654
1655#ifdef MEMSET_FREED
1656 memset(&rcsw, 0, sizeof(rcsw));
1657#endif
1658
1659 return;
1660
1661invalid:
1662 invalidCommandBlock(pRI);
1663 return;
1664
1665}
1666
Ethan Chend6e30652013-08-04 22:49:56 -07001667// For backwards compatibility in RIL_REQUEST_SETUP_DATA_CALL.
1668// Version 4 of the RIL interface adds a new PDP type parameter to support
1669// IPv6 and dual-stack PDP contexts. When dealing with a previous version of
1670// RIL, remove the parameter from the request.
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001671static void dispatchDataCall(Parcel& p, RequestInfo *pRI) {
Ethan Chend6e30652013-08-04 22:49:56 -07001672 // In RIL v3, REQUEST_SETUP_DATA_CALL takes 6 parameters.
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001673 const int numParamsRilV3 = 6;
1674
Ethan Chend6e30652013-08-04 22:49:56 -07001675 // The first bytes of the RIL parcel contain the request number and the
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001676 // serial number - see processCommandBuffer(). Copy them over too.
1677 int pos = p.dataPosition();
1678
1679 int numParams = p.readInt32();
1680 if (s_callbacks.version < 4 && numParams > numParamsRilV3) {
1681 Parcel p2;
1682 p2.appendFrom(&p, 0, pos);
1683 p2.writeInt32(numParamsRilV3);
1684 for(int i = 0; i < numParamsRilV3; i++) {
1685 p2.writeString16(p.readString16());
1686 }
1687 p2.setDataPosition(pos);
1688 dispatchStrings(p2, pRI);
1689 } else {
1690 p.setDataPosition(pos);
1691 dispatchStrings(p, pRI);
1692 }
1693}
1694
1695// For backwards compatibility with RILs that dont support RIL_REQUEST_VOICE_RADIO_TECH.
Ethan Chend6e30652013-08-04 22:49:56 -07001696// When all RILs handle this request, this function can be removed and
1697// the request can be sent directly to the RIL using dispatchVoid.
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001698static void dispatchVoiceRadioTech(Parcel& p, RequestInfo *pRI) {
Howard Sue32dbfd2015-01-07 15:55:57 +08001699 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001700
1701 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1702 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1703 }
1704
Ethan Chend6e30652013-08-04 22:49:56 -07001705 // RILs that support RADIO_STATE_ON should support this request.
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001706 if (RADIO_STATE_ON == state) {
1707 dispatchVoid(p, pRI);
1708 return;
1709 }
1710
Ethan Chend6e30652013-08-04 22:49:56 -07001711 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1712 // will not support this new request either and decode Voice Radio Technology
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001713 // from Radio State
1714 voiceRadioTech = decodeVoiceRadioTechnology(state);
1715
1716 if (voiceRadioTech < 0)
1717 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1718 else
1719 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &voiceRadioTech, sizeof(int));
1720}
1721
Ethan Chend6e30652013-08-04 22:49:56 -07001722// For backwards compatibility in RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE:.
1723// When all RILs handle this request, this function can be removed and
1724// the request can be sent directly to the RIL using dispatchVoid.
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001725static void dispatchCdmaSubscriptionSource(Parcel& p, RequestInfo *pRI) {
Howard Sue32dbfd2015-01-07 15:55:57 +08001726 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001727
1728 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1729 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1730 }
1731
1732 // RILs that support RADIO_STATE_ON should support this request.
1733 if (RADIO_STATE_ON == state) {
1734 dispatchVoid(p, pRI);
1735 return;
1736 }
1737
Ethan Chend6e30652013-08-04 22:49:56 -07001738 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001739 // will not support this new request either and decode CDMA Subscription Source
Ethan Chend6e30652013-08-04 22:49:56 -07001740 // from Radio State
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001741 cdmaSubscriptionSource = decodeCdmaSubscriptionSource(state);
1742
1743 if (cdmaSubscriptionSource < 0)
1744 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1745 else
1746 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &cdmaSubscriptionSource, sizeof(int));
1747}
1748
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001749static void dispatchSetInitialAttachApn(Parcel &p, RequestInfo *pRI)
1750{
1751 RIL_InitialAttachApn pf;
1752 int32_t t;
1753 status_t status;
1754
1755 memset(&pf, 0, sizeof(pf));
1756
1757 pf.apn = strdupReadString(p);
1758 pf.protocol = strdupReadString(p);
1759
1760 status = p.readInt32(&t);
1761 pf.authtype = (int) t;
1762
1763 pf.username = strdupReadString(p);
1764 pf.password = strdupReadString(p);
1765
1766 startRequest;
1767 appendPrintBuf("%sapn=%s, protocol=%s, auth_type=%d, username=%s, password=%s",
1768 printBuf, pf.apn, pf.protocol, pf.auth_type, pf.username, pf.password);
1769 closeRequest;
1770 printRequest(pRI->token, pRI->pCI->requestNumber);
1771
1772 if (status != NO_ERROR) {
1773 goto invalid;
1774 }
Howard Sue32dbfd2015-01-07 15:55:57 +08001775 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001776
1777#ifdef MEMSET_FREED
1778 memsetString(pf.apn);
1779 memsetString(pf.protocol);
1780 memsetString(pf.username);
1781 memsetString(pf.password);
1782#endif
1783
1784 free(pf.apn);
1785 free(pf.protocol);
1786 free(pf.username);
1787 free(pf.password);
1788
1789#ifdef MEMSET_FREED
1790 memset(&pf, 0, sizeof(pf));
1791#endif
1792
1793 return;
1794invalid:
1795 invalidCommandBlock(pRI);
1796 return;
1797}
1798
Howard Sue32dbfd2015-01-07 15:55:57 +08001799static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI) {
1800 RIL_NV_ReadItem nvri;
1801 int32_t t;
1802 status_t status;
1803
1804 memset(&nvri, 0, sizeof(nvri));
1805
1806 status = p.readInt32(&t);
1807 nvri.itemID = (RIL_NV_Item) t;
1808
1809 if (status != NO_ERROR) {
1810 goto invalid;
1811 }
1812
1813 startRequest;
1814 appendPrintBuf("%snvri.itemID=%d, ", printBuf, nvri.itemID);
1815 closeRequest;
1816
1817 printRequest(pRI->token, pRI->pCI->requestNumber);
1818
1819 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvri, sizeof(nvri), pRI, pRI->socket_id);
1820
1821#ifdef MEMSET_FREED
1822 memset(&nvri, 0, sizeof(nvri));
1823#endif
1824
1825 return;
1826
1827invalid:
1828 invalidCommandBlock(pRI);
1829 return;
1830}
1831
1832static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI) {
1833 RIL_NV_WriteItem nvwi;
1834 int32_t t;
1835 status_t status;
1836
1837 memset(&nvwi, 0, sizeof(nvwi));
1838
1839 status = p.readInt32(&t);
1840 nvwi.itemID = (RIL_NV_Item) t;
1841
1842 nvwi.value = strdupReadString(p);
1843
1844 if (status != NO_ERROR || nvwi.value == NULL) {
1845 goto invalid;
1846 }
1847
1848 startRequest;
1849 appendPrintBuf("%snvwi.itemID=%d, value=%s, ", printBuf, nvwi.itemID,
1850 nvwi.value);
1851 closeRequest;
1852
1853 printRequest(pRI->token, pRI->pCI->requestNumber);
1854
1855 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvwi, sizeof(nvwi), pRI, pRI->socket_id);
1856
1857#ifdef MEMSET_FREED
1858 memsetString(nvwi.value);
1859#endif
1860
1861 free(nvwi.value);
1862
1863#ifdef MEMSET_FREED
1864 memset(&nvwi, 0, sizeof(nvwi));
1865#endif
1866
1867 return;
1868
1869invalid:
1870 invalidCommandBlock(pRI);
1871 return;
1872}
1873
1874
1875static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI) {
1876 RIL_SelectUiccSub uicc_sub;
1877 status_t status;
1878 int32_t t;
1879 memset(&uicc_sub, 0, sizeof(uicc_sub));
1880
1881 status = p.readInt32(&t);
1882 if (status != NO_ERROR) {
1883 goto invalid;
1884 }
1885 uicc_sub.slot = (int) t;
1886
1887 status = p.readInt32(&t);
1888 if (status != NO_ERROR) {
1889 goto invalid;
1890 }
1891 uicc_sub.app_index = (int) t;
1892
1893 status = p.readInt32(&t);
1894 if (status != NO_ERROR) {
1895 goto invalid;
1896 }
1897 uicc_sub.sub_type = (RIL_SubscriptionType) t;
1898
1899 status = p.readInt32(&t);
1900 if (status != NO_ERROR) {
1901 goto invalid;
1902 }
1903 uicc_sub.act_status = (RIL_UiccSubActStatus) t;
1904
1905 startRequest;
1906 appendPrintBuf("slot=%d, app_index=%d, act_status = %d", uicc_sub.slot, uicc_sub.app_index,
1907 uicc_sub.act_status);
1908 RLOGD("dispatchUiccSubscription, slot=%d, app_index=%d, act_status = %d", uicc_sub.slot,
1909 uicc_sub.app_index, uicc_sub.act_status);
1910 closeRequest;
1911 printRequest(pRI->token, pRI->pCI->requestNumber);
1912
1913 CALL_ONREQUEST(pRI->pCI->requestNumber, &uicc_sub, sizeof(uicc_sub), pRI, pRI->socket_id);
1914
1915#ifdef MEMSET_FREED
1916 memset(&uicc_sub, 0, sizeof(uicc_sub));
1917#endif
1918 return;
1919
1920invalid:
1921 invalidCommandBlock(pRI);
1922 return;
1923}
1924
1925static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI)
1926{
1927 RIL_SimAuthentication pf;
1928 int32_t t;
1929 status_t status;
1930
1931 memset(&pf, 0, sizeof(pf));
1932
1933 status = p.readInt32(&t);
1934 pf.authContext = (int) t;
1935 pf.authData = strdupReadString(p);
1936 pf.aid = strdupReadString(p);
1937
1938 startRequest;
1939 appendPrintBuf("authContext=%s, authData=%s, aid=%s", pf.authContext, pf.authData, pf.aid);
1940 closeRequest;
1941 printRequest(pRI->token, pRI->pCI->requestNumber);
1942
1943 if (status != NO_ERROR) {
1944 goto invalid;
1945 }
1946 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
1947
1948#ifdef MEMSET_FREED
1949 memsetString(pf.authData);
1950 memsetString(pf.aid);
1951#endif
1952
1953 free(pf.authData);
1954 free(pf.aid);
1955
1956#ifdef MEMSET_FREED
1957 memset(&pf, 0, sizeof(pf));
1958#endif
1959
1960 return;
1961invalid:
1962 invalidCommandBlock(pRI);
1963 return;
1964}
1965
1966static void dispatchDataProfile(Parcel &p, RequestInfo *pRI) {
1967 int32_t t;
1968 status_t status;
1969 int32_t num;
1970
1971 status = p.readInt32(&num);
1972 if (status != NO_ERROR) {
1973 goto invalid;
1974 }
1975
1976 {
1977 RIL_DataProfileInfo dataProfiles[num];
1978 RIL_DataProfileInfo *dataProfilePtrs[num];
1979
1980 startRequest;
1981 for (int i = 0 ; i < num ; i++ ) {
1982 dataProfilePtrs[i] = &dataProfiles[i];
1983
1984 status = p.readInt32(&t);
1985 dataProfiles[i].profileId = (int) t;
1986
1987 dataProfiles[i].apn = strdupReadString(p);
1988 dataProfiles[i].protocol = strdupReadString(p);
1989 status = p.readInt32(&t);
1990 dataProfiles[i].authType = (int) t;
1991
1992 dataProfiles[i].user = strdupReadString(p);
1993 dataProfiles[i].password = strdupReadString(p);
1994
1995 status = p.readInt32(&t);
1996 dataProfiles[i].type = (int) t;
1997
1998 status = p.readInt32(&t);
1999 dataProfiles[i].maxConnsTime = (int) t;
2000 status = p.readInt32(&t);
2001 dataProfiles[i].maxConns = (int) t;
2002 status = p.readInt32(&t);
2003 dataProfiles[i].waitTime = (int) t;
2004
2005 status = p.readInt32(&t);
2006 dataProfiles[i].enabled = (int) t;
2007
2008 appendPrintBuf("%s [%d: profileId=%d, apn =%s, protocol =%s, authType =%d, \
2009 user =%s, password =%s, type =%d, maxConnsTime =%d, maxConns =%d, \
2010 waitTime =%d, enabled =%d]", printBuf, i, dataProfiles[i].profileId,
2011 dataProfiles[i].apn, dataProfiles[i].protocol, dataProfiles[i].authType,
2012 dataProfiles[i].user, dataProfiles[i].password, dataProfiles[i].type,
2013 dataProfiles[i].maxConnsTime, dataProfiles[i].maxConns,
2014 dataProfiles[i].waitTime, dataProfiles[i].enabled);
2015 }
2016 closeRequest;
2017 printRequest(pRI->token, pRI->pCI->requestNumber);
2018
2019 if (status != NO_ERROR) {
2020 goto invalid;
2021 }
2022 CALL_ONREQUEST(pRI->pCI->requestNumber,
2023 dataProfilePtrs,
2024 num * sizeof(RIL_DataProfileInfo *),
2025 pRI, pRI->socket_id);
2026
2027#ifdef MEMSET_FREED
2028 memset(dataProfiles, 0, num * sizeof(RIL_DataProfileInfo));
2029 memset(dataProfilePtrs, 0, num * sizeof(RIL_DataProfileInfo *));
2030#endif
2031 }
2032
2033 return;
2034
2035invalid:
2036 invalidCommandBlock(pRI);
2037 return;
2038}
2039
Howard Subd82ef12015-04-12 10:25:05 +02002040static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI){
2041 RIL_RadioCapability rc;
2042 int32_t t;
2043 status_t status;
2044
2045 memset (&rc, 0, sizeof(RIL_RadioCapability));
2046
2047 status = p.readInt32(&t);
2048 rc.version = (int)t;
2049 if (status != NO_ERROR) {
2050 goto invalid;
2051 }
2052
2053 status = p.readInt32(&t);
2054 rc.session= (int)t;
2055 if (status != NO_ERROR) {
2056 goto invalid;
2057 }
2058
2059 status = p.readInt32(&t);
2060 rc.phase= (int)t;
2061 if (status != NO_ERROR) {
2062 goto invalid;
2063 }
2064
2065 status = p.readInt32(&t);
2066 rc.rat = (int)t;
2067 if (status != NO_ERROR) {
2068 goto invalid;
2069 }
2070
2071 status = readStringFromParcelInplace(p, rc.logicalModemUuid, sizeof(rc.logicalModemUuid));
2072 if (status != NO_ERROR) {
2073 goto invalid;
2074 }
2075
2076 status = p.readInt32(&t);
2077 rc.status = (int)t;
2078
2079 if (status != NO_ERROR) {
2080 goto invalid;
2081 }
2082
2083 startRequest;
2084 appendPrintBuf("%s [version:%d, session:%d, phase:%d, rat:%d, \
2085 logicalModemUuid:%s, status:%d", printBuf, rc.version, rc.session
2086 rc.phase, rc.rat, rc.logicalModemUuid, rc.session);
2087
2088 closeRequest;
2089 printRequest(pRI->token, pRI->pCI->requestNumber);
2090
2091 CALL_ONREQUEST(pRI->pCI->requestNumber,
2092 &rc,
2093 sizeof(RIL_RadioCapability),
2094 pRI, pRI->socket_id);
2095 return;
2096invalid:
2097 invalidCommandBlock(pRI);
2098 return;
2099}
2100
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002101static int
2102blockingWrite(int fd, const void *buffer, size_t len) {
2103 size_t writeOffset = 0;
2104 const uint8_t *toWrite;
2105
2106 toWrite = (const uint8_t *)buffer;
2107
2108 while (writeOffset < len) {
2109 ssize_t written;
2110 do {
2111 written = write (fd, toWrite + writeOffset,
2112 len - writeOffset);
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002113 } while (written < 0 && ((errno == EINTR) || (errno == EAGAIN)));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002114
2115 if (written >= 0) {
2116 writeOffset += written;
2117 } else { // written < 0
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002118 RLOGE ("RIL Response: unexpected error on write errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002119 close(fd);
2120 return -1;
2121 }
2122 }
2123
2124 return 0;
2125}
2126
2127static int
Howard Sue32dbfd2015-01-07 15:55:57 +08002128sendResponseRaw (const void *data, size_t dataSize, RIL_SOCKET_ID socket_id) {
2129 int fd = s_ril_param_socket.fdCommand;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002130 int ret;
2131 uint32_t header;
Howard Sue32dbfd2015-01-07 15:55:57 +08002132 pthread_mutex_t * writeMutexHook = &s_writeMutex;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002133
Howard Sue32dbfd2015-01-07 15:55:57 +08002134 RLOGE("Send Response to %s", rilSocketIdToString(socket_id));
2135
2136#if (SIM_COUNT >= 2)
2137 if (socket_id == RIL_SOCKET_2) {
2138 fd = s_ril_param_socket2.fdCommand;
2139 writeMutexHook = &s_writeMutex_socket2;
2140 }
2141#if (SIM_COUNT >= 3)
2142 else if (socket_id == RIL_SOCKET_3) {
2143 fd = s_ril_param_socket3.fdCommand;
2144 writeMutexHook = &s_writeMutex_socket3;
2145 }
2146#endif
2147#if (SIM_COUNT >= 4)
2148 else if (socket_id == RIL_SOCKET_4) {
2149 fd = s_ril_param_socket4.fdCommand;
2150 writeMutexHook = &s_writeMutex_socket4;
2151 }
2152#endif
2153#endif
2154 if (fd < 0) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002155 return -1;
2156 }
2157
Howard Subd82ef12015-04-12 10:25:05 +02002158 if (dataSize > MAX_COMMAND_BYTES) {
2159 RLOGE("RIL: packet larger than %u (%u)",
2160 MAX_COMMAND_BYTES, (unsigned int )dataSize);
2161
2162 return -1;
2163 }
2164
Howard Sue32dbfd2015-01-07 15:55:57 +08002165 pthread_mutex_lock(writeMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002166
2167 header = htonl(dataSize);
2168
2169 ret = blockingWrite(fd, (void *)&header, sizeof(header));
2170
2171 if (ret < 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002172 pthread_mutex_unlock(writeMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002173 return ret;
2174 }
2175
2176 ret = blockingWrite(fd, data, dataSize);
2177
2178 if (ret < 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002179 pthread_mutex_unlock(writeMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002180 return ret;
2181 }
2182
Howard Sue32dbfd2015-01-07 15:55:57 +08002183 pthread_mutex_unlock(writeMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002184
2185 return 0;
2186}
2187
2188static int
Howard Sue32dbfd2015-01-07 15:55:57 +08002189sendResponse (Parcel &p, RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002190 printResponse;
Howard Sue32dbfd2015-01-07 15:55:57 +08002191 return sendResponseRaw(p.data(), p.dataSize(), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002192}
2193
Howard Sue32dbfd2015-01-07 15:55:57 +08002194/** response is an int* pointing to an array of ints */
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002195
2196static int
2197responseInts(Parcel &p, void *response, size_t responselen) {
2198 int numInts;
2199
2200 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002201 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002202 return RIL_ERRNO_INVALID_RESPONSE;
2203 }
2204 if (responselen % sizeof(int) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002205 RLOGE("responseInts: invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002206 (int)responselen, (int)sizeof(int));
2207 return RIL_ERRNO_INVALID_RESPONSE;
2208 }
2209
2210 int *p_int = (int *) response;
2211
Howard Sue32dbfd2015-01-07 15:55:57 +08002212 numInts = responselen / sizeof(int);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002213 p.writeInt32 (numInts);
2214
2215 /* each int*/
2216 startResponse;
2217 for (int i = 0 ; i < numInts ; i++) {
2218 appendPrintBuf("%s%d,", printBuf, p_int[i]);
2219 p.writeInt32(p_int[i]);
2220 }
2221 removeLastChar;
2222 closeResponse;
2223
2224 return 0;
2225}
2226
Daniel Hillenbrandd0b84162015-04-12 11:53:23 +02002227static int
2228responseIntsGetPreferredNetworkType(Parcel &p, void *response, size_t responselen) {
2229 int numInts;
2230
2231 if (response == NULL && responselen != 0) {
2232 RLOGE("invalid response: NULL");
2233 return RIL_ERRNO_INVALID_RESPONSE;
2234 }
2235 if (responselen % sizeof(int) != 0) {
2236 RLOGE("responseInts: invalid response length %d expected multiple of %d\n",
2237 (int)responselen, (int)sizeof(int));
2238 return RIL_ERRNO_INVALID_RESPONSE;
2239 }
2240
2241 int *p_int = (int *) response;
2242
2243 numInts = responselen / sizeof(int);
2244 p.writeInt32 (numInts);
2245
2246 /* each int*/
2247 startResponse;
2248 for (int i = 0 ; i < numInts ; i++) {
2249 if (i == 0 && p_int[0] == 7) {
2250 RLOGD("REQUEST_GET_PREFERRED_NETWORK_TYPE: NETWORK_MODE_GLOBAL => NETWORK_MODE_WCDMA_PREF");
2251 p_int[0] = 0;
2252 }
2253 appendPrintBuf("%s%d,", printBuf, p_int[i]);
2254 p.writeInt32(p_int[i]);
2255 }
2256 removeLastChar;
2257 closeResponse;
2258
2259 return 0;
2260}
2261
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002262/** response is a char **, pointing to an array of char *'s
2263 The parcel will begin with the version */
2264static int responseStringsWithVersion(int version, Parcel &p, void *response, size_t responselen) {
2265 p.writeInt32(version);
2266 return responseStrings(p, response, responselen);
2267}
2268
2269/** response is a char **, pointing to an array of char *'s */
2270static int responseStrings(Parcel &p, void *response, size_t responselen) {
2271 return responseStrings(p, response, responselen, false);
2272}
2273
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002274/** response is a char **, pointing to an array of char *'s */
2275static int responseStrings(Parcel &p, void *response, size_t responselen, bool network_search) {
2276 int numStrings;
2277
2278 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002279 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002280 return RIL_ERRNO_INVALID_RESPONSE;
2281 }
2282 if (responselen % sizeof(char *) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002283 RLOGE("responseStrings: invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002284 (int)responselen, (int)sizeof(char *));
2285 return RIL_ERRNO_INVALID_RESPONSE;
2286 }
2287
2288 if (response == NULL) {
2289 p.writeInt32 (0);
2290 } else {
2291 char **p_cur = (char **) response;
2292
2293 numStrings = responselen / sizeof(char *);
2294 p.writeInt32 (numStrings);
2295
2296 /* each string*/
2297 startResponse;
2298 for (int i = 0 ; i < numStrings ; i++) {
2299 appendPrintBuf("%s%s,", printBuf, (char*)p_cur[i]);
2300 writeStringToParcel (p, p_cur[i]);
2301 }
2302 removeLastChar;
2303 closeResponse;
2304 }
2305 return 0;
2306}
2307
Howard Subd82ef12015-04-12 10:25:05 +02002308
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002309/**
2310 * NULL strings are accepted
2311 * FIXME currently ignores responselen
2312 */
2313static int responseString(Parcel &p, void *response, size_t responselen) {
2314 /* one string only */
2315 startResponse;
2316 appendPrintBuf("%s%s", printBuf, (char*)response);
2317 closeResponse;
2318
2319 writeStringToParcel(p, (const char *)response);
2320
2321 return 0;
2322}
2323
2324static int responseVoid(Parcel &p, void *response, size_t responselen) {
2325 startResponse;
2326 removeLastChar;
2327 return 0;
2328}
2329
2330static int responseCallList(Parcel &p, void *response, size_t responselen) {
2331 int num;
2332
2333 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002334 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002335 return RIL_ERRNO_INVALID_RESPONSE;
2336 }
2337
2338 if (responselen % sizeof (RIL_Call *) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002339 RLOGE("responseCallList: invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002340 (int)responselen, (int)sizeof (RIL_Call *));
2341 return RIL_ERRNO_INVALID_RESPONSE;
2342 }
2343
2344 startResponse;
2345 /* number of call info's */
2346 num = responselen / sizeof(RIL_Call *);
2347 p.writeInt32(num);
2348
2349 for (int i = 0 ; i < num ; i++) {
2350 RIL_Call *p_cur = ((RIL_Call **) response)[i];
2351 /* each call info */
2352 p.writeInt32(p_cur->state);
2353 p.writeInt32(p_cur->index);
2354 p.writeInt32(p_cur->toa);
2355 p.writeInt32(p_cur->isMpty);
2356 p.writeInt32(p_cur->isMT);
2357 p.writeInt32(p_cur->als);
2358 p.writeInt32(p_cur->isVoice);
Andreas Schneider29472682015-01-01 19:00:04 +01002359
2360#ifdef MODEM_TYPE_XMM7260
2361 p.writeInt32(p_cur->isVideo);
2362
2363 /* Pass CallDetails */
2364 p.writeInt32(0);
2365 p.writeInt32(0);
2366 writeStringToParcel(p, "");
2367#endif
2368
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002369 p.writeInt32(p_cur->isVoicePrivacy);
2370 writeStringToParcel(p, p_cur->number);
2371 p.writeInt32(p_cur->numberPresentation);
2372 writeStringToParcel(p, p_cur->name);
2373 p.writeInt32(p_cur->namePresentation);
2374 // Remove when partners upgrade to version 3
2375 if ((s_callbacks.version < 3) || (p_cur->uusInfo == NULL || p_cur->uusInfo->uusData == NULL)) {
2376 p.writeInt32(0); /* UUS Information is absent */
2377 } else {
2378 RIL_UUS_Info *uusInfo = p_cur->uusInfo;
2379 p.writeInt32(1); /* UUS Information is present */
2380 p.writeInt32(uusInfo->uusType);
2381 p.writeInt32(uusInfo->uusDcs);
2382 p.writeInt32(uusInfo->uusLength);
2383 p.write(uusInfo->uusData, uusInfo->uusLength);
2384 }
2385 appendPrintBuf("%s[id=%d,%s,toa=%d,",
2386 printBuf,
2387 p_cur->index,
2388 callStateToString(p_cur->state),
2389 p_cur->toa);
2390 appendPrintBuf("%s%s,%s,als=%d,%s,%s,",
2391 printBuf,
2392 (p_cur->isMpty)?"conf":"norm",
2393 (p_cur->isMT)?"mt":"mo",
2394 p_cur->als,
2395 (p_cur->isVoice)?"voc":"nonvoc",
2396 (p_cur->isVoicePrivacy)?"evp":"noevp");
Andreas Schneider29472682015-01-01 19:00:04 +01002397#ifdef MODEM_TYPE_XMM7260
2398 appendPrintBuf("%s,%s,",
2399 printBuf,
2400 (p_cur->isVideo) ? "vid" : "novid");
2401#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002402 appendPrintBuf("%s%s,cli=%d,name='%s',%d]",
2403 printBuf,
2404 p_cur->number,
2405 p_cur->numberPresentation,
2406 p_cur->name,
2407 p_cur->namePresentation);
2408 }
2409 removeLastChar;
2410 closeResponse;
2411
2412 return 0;
2413}
2414
2415static int responseSMS(Parcel &p, void *response, size_t responselen) {
2416 if (response == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002417 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002418 return RIL_ERRNO_INVALID_RESPONSE;
2419 }
2420
2421 if (responselen != sizeof (RIL_SMS_Response) ) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002422 RLOGE("invalid response length %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002423 (int)responselen, (int)sizeof (RIL_SMS_Response));
2424 return RIL_ERRNO_INVALID_RESPONSE;
2425 }
2426
2427 RIL_SMS_Response *p_cur = (RIL_SMS_Response *) response;
2428
2429 p.writeInt32(p_cur->messageRef);
2430 writeStringToParcel(p, p_cur->ackPDU);
2431 p.writeInt32(p_cur->errorCode);
2432
2433 startResponse;
2434 appendPrintBuf("%s%d,%s,%d", printBuf, p_cur->messageRef,
2435 (char*)p_cur->ackPDU, p_cur->errorCode);
2436 closeResponse;
2437
2438 return 0;
2439}
2440
2441static int responseDataCallListV4(Parcel &p, void *response, size_t responselen)
2442{
2443 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002444 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002445 return RIL_ERRNO_INVALID_RESPONSE;
2446 }
2447
2448 if (responselen % sizeof(RIL_Data_Call_Response_v4) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002449 RLOGE("responseDataCallListV4: invalid response length %d expected multiple of %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002450 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v4));
2451 return RIL_ERRNO_INVALID_RESPONSE;
2452 }
2453
Howard Sue32dbfd2015-01-07 15:55:57 +08002454 // Write version
2455 p.writeInt32(4);
2456
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002457 int num = responselen / sizeof(RIL_Data_Call_Response_v4);
2458 p.writeInt32(num);
2459
2460 RIL_Data_Call_Response_v4 *p_cur = (RIL_Data_Call_Response_v4 *) response;
2461 startResponse;
2462 int i;
2463 for (i = 0; i < num; i++) {
2464 p.writeInt32(p_cur[i].cid);
2465 p.writeInt32(p_cur[i].active);
2466 writeStringToParcel(p, p_cur[i].type);
2467 // apn is not used, so don't send.
2468 writeStringToParcel(p, p_cur[i].address);
2469 appendPrintBuf("%s[cid=%d,%s,%s,%s],", printBuf,
2470 p_cur[i].cid,
2471 (p_cur[i].active==0)?"down":"up",
2472 (char*)p_cur[i].type,
2473 (char*)p_cur[i].address);
2474 }
2475 removeLastChar;
2476 closeResponse;
2477
2478 return 0;
2479}
2480
Howard Sue32dbfd2015-01-07 15:55:57 +08002481static int responseDataCallListV6(Parcel &p, void *response, size_t responselen)
2482{
2483 if (response == NULL && responselen != 0) {
2484 RLOGE("invalid response: NULL");
2485 return RIL_ERRNO_INVALID_RESPONSE;
2486 }
2487
2488 if (responselen % sizeof(RIL_Data_Call_Response_v6) != 0) {
2489 RLOGE("responseDataCallListV6: invalid response length %d expected multiple of %d",
2490 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v6));
2491 return RIL_ERRNO_INVALID_RESPONSE;
2492 }
2493
2494 // Write version
2495 p.writeInt32(6);
2496
2497 int num = responselen / sizeof(RIL_Data_Call_Response_v6);
2498 p.writeInt32(num);
2499
2500 RIL_Data_Call_Response_v6 *p_cur = (RIL_Data_Call_Response_v6 *) response;
2501 startResponse;
2502 int i;
2503 for (i = 0; i < num; i++) {
2504 p.writeInt32((int)p_cur[i].status);
2505 p.writeInt32(p_cur[i].suggestedRetryTime);
2506 p.writeInt32(p_cur[i].cid);
2507 p.writeInt32(p_cur[i].active);
2508 writeStringToParcel(p, p_cur[i].type);
2509 writeStringToParcel(p, p_cur[i].ifname);
2510 writeStringToParcel(p, p_cur[i].addresses);
2511 writeStringToParcel(p, p_cur[i].dnses);
2512 writeStringToParcel(p, p_cur[i].addresses);
2513 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s],", printBuf,
2514 p_cur[i].status,
2515 p_cur[i].suggestedRetryTime,
2516 p_cur[i].cid,
2517 (p_cur[i].active==0)?"down":"up",
2518 (char*)p_cur[i].type,
2519 (char*)p_cur[i].ifname,
2520 (char*)p_cur[i].addresses,
2521 (char*)p_cur[i].dnses,
2522 (char*)p_cur[i].addresses);
2523 }
2524 removeLastChar;
2525 closeResponse;
2526
2527 return 0;
2528}
2529
Howard Subd82ef12015-04-12 10:25:05 +02002530static int responseDataCallListV9(Parcel &p, void *response, size_t responselen)
2531{
2532 if (response == NULL && responselen != 0) {
2533 RLOGE("invalid response: NULL");
2534 return RIL_ERRNO_INVALID_RESPONSE;
2535 }
2536
2537 if (responselen % sizeof(RIL_Data_Call_Response_v9) != 0) {
2538 RLOGE("responseDataCallListV9: invalid response length %d expected multiple of %d",
2539 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v9));
2540 return RIL_ERRNO_INVALID_RESPONSE;
2541 }
2542
2543 // Write version
2544 p.writeInt32(10);
2545
2546 int num = responselen / sizeof(RIL_Data_Call_Response_v9);
2547 p.writeInt32(num);
2548
2549 RIL_Data_Call_Response_v9 *p_cur = (RIL_Data_Call_Response_v9 *) response;
2550 startResponse;
2551 int i;
2552 for (i = 0; i < num; i++) {
2553 p.writeInt32((int)p_cur[i].status);
2554 p.writeInt32(p_cur[i].suggestedRetryTime);
2555 p.writeInt32(p_cur[i].cid);
2556 p.writeInt32(p_cur[i].active);
2557 writeStringToParcel(p, p_cur[i].type);
2558 writeStringToParcel(p, p_cur[i].ifname);
2559 writeStringToParcel(p, p_cur[i].addresses);
2560 writeStringToParcel(p, p_cur[i].dnses);
2561 writeStringToParcel(p, p_cur[i].gateways);
2562 writeStringToParcel(p, p_cur[i].pcscf);
2563 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s],", printBuf,
2564 p_cur[i].status,
2565 p_cur[i].suggestedRetryTime,
2566 p_cur[i].cid,
2567 (p_cur[i].active==0)?"down":"up",
2568 (char*)p_cur[i].type,
2569 (char*)p_cur[i].ifname,
2570 (char*)p_cur[i].addresses,
2571 (char*)p_cur[i].dnses,
2572 (char*)p_cur[i].gateways,
2573 (char*)p_cur[i].pcscf);
2574 }
2575 removeLastChar;
2576 closeResponse;
2577
2578 return 0;
2579}
2580
2581
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002582static int responseDataCallList(Parcel &p, void *response, size_t responselen)
2583{
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002584 if (s_callbacks.version < 5) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002585 RLOGD("responseDataCallList: v4");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002586 return responseDataCallListV4(p, response, responselen);
Howard Subd82ef12015-04-12 10:25:05 +02002587 } else if (responselen % sizeof(RIL_Data_Call_Response_v6) == 0) {
2588 return responseDataCallListV6(p, response, responselen);
2589 } else if (responselen % sizeof(RIL_Data_Call_Response_v9) == 0) {
2590 return responseDataCallListV9(p, response, responselen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002591 } else {
2592 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002593 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002594 return RIL_ERRNO_INVALID_RESPONSE;
2595 }
2596
Howard Subd82ef12015-04-12 10:25:05 +02002597 if (responselen % sizeof(RIL_Data_Call_Response_v11) != 0) {
2598 RLOGE("invalid response length %d expected multiple of %d",
2599 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v11));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002600 return RIL_ERRNO_INVALID_RESPONSE;
2601 }
2602
Howard Sue32dbfd2015-01-07 15:55:57 +08002603 // Write version
Howard Subd82ef12015-04-12 10:25:05 +02002604 p.writeInt32(11);
Howard Sue32dbfd2015-01-07 15:55:57 +08002605
Howard Subd82ef12015-04-12 10:25:05 +02002606 int num = responselen / sizeof(RIL_Data_Call_Response_v11);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002607 p.writeInt32(num);
2608
Howard Subd82ef12015-04-12 10:25:05 +02002609 RIL_Data_Call_Response_v11 *p_cur = (RIL_Data_Call_Response_v11 *) response;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002610 startResponse;
2611 int i;
2612 for (i = 0; i < num; i++) {
2613 p.writeInt32((int)p_cur[i].status);
2614 p.writeInt32(p_cur[i].suggestedRetryTime);
2615 p.writeInt32(p_cur[i].cid);
2616 p.writeInt32(p_cur[i].active);
2617 writeStringToParcel(p, p_cur[i].type);
2618 writeStringToParcel(p, p_cur[i].ifname);
2619 writeStringToParcel(p, p_cur[i].addresses);
2620 writeStringToParcel(p, p_cur[i].dnses);
Howard Sue32dbfd2015-01-07 15:55:57 +08002621 writeStringToParcel(p, p_cur[i].gateways);
2622 writeStringToParcel(p, p_cur[i].pcscf);
Howard Subd82ef12015-04-12 10:25:05 +02002623 p.writeInt32(p_cur[i].mtu);
2624 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s,mtu=%d],", printBuf,
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002625 p_cur[i].status,
2626 p_cur[i].suggestedRetryTime,
2627 p_cur[i].cid,
2628 (p_cur[i].active==0)?"down":"up",
2629 (char*)p_cur[i].type,
2630 (char*)p_cur[i].ifname,
2631 (char*)p_cur[i].addresses,
2632 (char*)p_cur[i].dnses,
Howard Sue32dbfd2015-01-07 15:55:57 +08002633 (char*)p_cur[i].gateways,
Howard Subd82ef12015-04-12 10:25:05 +02002634 (char*)p_cur[i].pcscf,
2635 p_cur[i].mtu);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002636 }
2637 removeLastChar;
2638 closeResponse;
2639 }
2640
2641 return 0;
2642}
2643
2644static int responseSetupDataCall(Parcel &p, void *response, size_t responselen)
2645{
2646 if (s_callbacks.version < 5) {
2647 return responseStringsWithVersion(s_callbacks.version, p, response, responselen);
2648 } else {
2649 return responseDataCallList(p, response, responselen);
2650 }
2651}
2652
2653static int responseRaw(Parcel &p, void *response, size_t responselen) {
2654 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002655 RLOGE("invalid response: NULL with responselen != 0");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002656 return RIL_ERRNO_INVALID_RESPONSE;
2657 }
2658
2659 // The java code reads -1 size as null byte array
2660 if (response == NULL) {
2661 p.writeInt32(-1);
2662 } else {
2663 p.writeInt32(responselen);
2664 p.write(response, responselen);
2665 }
2666
2667 return 0;
2668}
2669
2670
2671static int responseSIM_IO(Parcel &p, void *response, size_t responselen) {
2672 if (response == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002673 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002674 return RIL_ERRNO_INVALID_RESPONSE;
2675 }
2676
2677 if (responselen != sizeof (RIL_SIM_IO_Response) ) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002678 RLOGE("invalid response length was %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002679 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
2680 return RIL_ERRNO_INVALID_RESPONSE;
2681 }
2682
2683 RIL_SIM_IO_Response *p_cur = (RIL_SIM_IO_Response *) response;
2684 p.writeInt32(p_cur->sw1);
2685 p.writeInt32(p_cur->sw2);
2686 writeStringToParcel(p, p_cur->simResponse);
2687
2688 startResponse;
2689 appendPrintBuf("%ssw1=0x%X,sw2=0x%X,%s", printBuf, p_cur->sw1, p_cur->sw2,
2690 (char*)p_cur->simResponse);
2691 closeResponse;
2692
2693
2694 return 0;
2695}
2696
2697static int responseCallForwards(Parcel &p, void *response, size_t responselen) {
2698 int num;
2699
2700 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002701 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002702 return RIL_ERRNO_INVALID_RESPONSE;
2703 }
2704
2705 if (responselen % sizeof(RIL_CallForwardInfo *) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002706 RLOGE("responseCallForwards: invalid response length %d expected multiple of %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002707 (int)responselen, (int)sizeof(RIL_CallForwardInfo *));
2708 return RIL_ERRNO_INVALID_RESPONSE;
2709 }
2710
2711 /* number of call info's */
2712 num = responselen / sizeof(RIL_CallForwardInfo *);
2713 p.writeInt32(num);
2714
2715 startResponse;
2716 for (int i = 0 ; i < num ; i++) {
2717 RIL_CallForwardInfo *p_cur = ((RIL_CallForwardInfo **) response)[i];
2718
2719 p.writeInt32(p_cur->status);
2720 p.writeInt32(p_cur->reason);
2721 p.writeInt32(p_cur->serviceClass);
2722 p.writeInt32(p_cur->toa);
2723 writeStringToParcel(p, p_cur->number);
2724 p.writeInt32(p_cur->timeSeconds);
2725 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
2726 (p_cur->status==1)?"enable":"disable",
2727 p_cur->reason, p_cur->serviceClass, p_cur->toa,
2728 (char*)p_cur->number,
2729 p_cur->timeSeconds);
2730 }
2731 removeLastChar;
2732 closeResponse;
2733
2734 return 0;
2735}
2736
2737static int responseSsn(Parcel &p, void *response, size_t responselen) {
2738 if (response == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002739 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002740 return RIL_ERRNO_INVALID_RESPONSE;
2741 }
2742
2743 if (responselen != sizeof(RIL_SuppSvcNotification)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002744 RLOGE("invalid response length was %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002745 (int)responselen, (int)sizeof (RIL_SuppSvcNotification));
2746 return RIL_ERRNO_INVALID_RESPONSE;
2747 }
2748
2749 RIL_SuppSvcNotification *p_cur = (RIL_SuppSvcNotification *) response;
2750 p.writeInt32(p_cur->notificationType);
2751 p.writeInt32(p_cur->code);
2752 p.writeInt32(p_cur->index);
2753 p.writeInt32(p_cur->type);
2754 writeStringToParcel(p, p_cur->number);
2755
2756 startResponse;
2757 appendPrintBuf("%s%s,code=%d,id=%d,type=%d,%s", printBuf,
2758 (p_cur->notificationType==0)?"mo":"mt",
2759 p_cur->code, p_cur->index, p_cur->type,
2760 (char*)p_cur->number);
2761 closeResponse;
2762
2763 return 0;
2764}
2765
2766static int responseCellList(Parcel &p, void *response, size_t responselen) {
2767 int num;
2768
2769 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002770 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002771 return RIL_ERRNO_INVALID_RESPONSE;
2772 }
2773
2774 if (responselen % sizeof (RIL_NeighboringCell *) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002775 RLOGE("responseCellList: invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002776 (int)responselen, (int)sizeof (RIL_NeighboringCell *));
2777 return RIL_ERRNO_INVALID_RESPONSE;
2778 }
2779
2780 startResponse;
2781 /* number of records */
2782 num = responselen / sizeof(RIL_NeighboringCell *);
2783 p.writeInt32(num);
2784
2785 for (int i = 0 ; i < num ; i++) {
2786 RIL_NeighboringCell *p_cur = ((RIL_NeighboringCell **) response)[i];
2787
2788 p.writeInt32(p_cur->rssi);
2789 writeStringToParcel (p, p_cur->cid);
2790
2791 appendPrintBuf("%s[cid=%s,rssi=%d],", printBuf,
2792 p_cur->cid, p_cur->rssi);
2793 }
2794 removeLastChar;
2795 closeResponse;
2796
2797 return 0;
2798}
2799
2800/**
2801 * Marshall the signalInfoRecord into the parcel if it exists.
2802 */
2803static void marshallSignalInfoRecord(Parcel &p,
2804 RIL_CDMA_SignalInfoRecord &p_signalInfoRecord) {
2805 p.writeInt32(p_signalInfoRecord.isPresent);
2806 p.writeInt32(p_signalInfoRecord.signalType);
2807 p.writeInt32(p_signalInfoRecord.alertPitch);
2808 p.writeInt32(p_signalInfoRecord.signal);
2809}
2810
2811static int responseCdmaInformationRecords(Parcel &p,
2812 void *response, size_t responselen) {
2813 int num;
2814 char* string8 = NULL;
2815 int buffer_lenght;
2816 RIL_CDMA_InformationRecord *infoRec;
2817
2818 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002819 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002820 return RIL_ERRNO_INVALID_RESPONSE;
2821 }
2822
2823 if (responselen != sizeof (RIL_CDMA_InformationRecords)) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002824 RLOGE("responseCdmaInformationRecords: invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002825 (int)responselen, (int)sizeof (RIL_CDMA_InformationRecords *));
2826 return RIL_ERRNO_INVALID_RESPONSE;
2827 }
2828
2829 RIL_CDMA_InformationRecords *p_cur =
2830 (RIL_CDMA_InformationRecords *) response;
2831 num = MIN(p_cur->numberOfInfoRecs, RIL_CDMA_MAX_NUMBER_OF_INFO_RECS);
2832
2833 startResponse;
2834 p.writeInt32(num);
2835
2836 for (int i = 0 ; i < num ; i++) {
2837 infoRec = &p_cur->infoRec[i];
2838 p.writeInt32(infoRec->name);
2839 switch (infoRec->name) {
2840 case RIL_CDMA_DISPLAY_INFO_REC:
2841 case RIL_CDMA_EXTENDED_DISPLAY_INFO_REC:
2842 if (infoRec->rec.display.alpha_len >
2843 CDMA_ALPHA_INFO_BUFFER_LENGTH) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002844 RLOGE("invalid display info response length %d \
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002845 expected not more than %d\n",
2846 (int)infoRec->rec.display.alpha_len,
2847 CDMA_ALPHA_INFO_BUFFER_LENGTH);
2848 return RIL_ERRNO_INVALID_RESPONSE;
2849 }
2850 string8 = (char*) malloc((infoRec->rec.display.alpha_len + 1)
2851 * sizeof(char) );
2852 for (int i = 0 ; i < infoRec->rec.display.alpha_len ; i++) {
2853 string8[i] = infoRec->rec.display.alpha_buf[i];
2854 }
2855 string8[(int)infoRec->rec.display.alpha_len] = '\0';
2856 writeStringToParcel(p, (const char*)string8);
2857 free(string8);
2858 string8 = NULL;
2859 break;
2860 case RIL_CDMA_CALLED_PARTY_NUMBER_INFO_REC:
2861 case RIL_CDMA_CALLING_PARTY_NUMBER_INFO_REC:
2862 case RIL_CDMA_CONNECTED_NUMBER_INFO_REC:
2863 if (infoRec->rec.number.len > CDMA_NUMBER_INFO_BUFFER_LENGTH) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002864 RLOGE("invalid display info response length %d \
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002865 expected not more than %d\n",
2866 (int)infoRec->rec.number.len,
2867 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2868 return RIL_ERRNO_INVALID_RESPONSE;
2869 }
2870 string8 = (char*) malloc((infoRec->rec.number.len + 1)
2871 * sizeof(char) );
2872 for (int i = 0 ; i < infoRec->rec.number.len; i++) {
2873 string8[i] = infoRec->rec.number.buf[i];
2874 }
2875 string8[(int)infoRec->rec.number.len] = '\0';
2876 writeStringToParcel(p, (const char*)string8);
2877 free(string8);
2878 string8 = NULL;
2879 p.writeInt32(infoRec->rec.number.number_type);
2880 p.writeInt32(infoRec->rec.number.number_plan);
2881 p.writeInt32(infoRec->rec.number.pi);
2882 p.writeInt32(infoRec->rec.number.si);
2883 break;
2884 case RIL_CDMA_SIGNAL_INFO_REC:
2885 p.writeInt32(infoRec->rec.signal.isPresent);
2886 p.writeInt32(infoRec->rec.signal.signalType);
2887 p.writeInt32(infoRec->rec.signal.alertPitch);
2888 p.writeInt32(infoRec->rec.signal.signal);
2889
2890 appendPrintBuf("%sisPresent=%X, signalType=%X, \
2891 alertPitch=%X, signal=%X, ",
2892 printBuf, (int)infoRec->rec.signal.isPresent,
2893 (int)infoRec->rec.signal.signalType,
2894 (int)infoRec->rec.signal.alertPitch,
2895 (int)infoRec->rec.signal.signal);
2896 removeLastChar;
2897 break;
2898 case RIL_CDMA_REDIRECTING_NUMBER_INFO_REC:
2899 if (infoRec->rec.redir.redirectingNumber.len >
2900 CDMA_NUMBER_INFO_BUFFER_LENGTH) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002901 RLOGE("invalid display info response length %d \
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002902 expected not more than %d\n",
2903 (int)infoRec->rec.redir.redirectingNumber.len,
2904 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2905 return RIL_ERRNO_INVALID_RESPONSE;
2906 }
2907 string8 = (char*) malloc((infoRec->rec.redir.redirectingNumber
2908 .len + 1) * sizeof(char) );
2909 for (int i = 0;
2910 i < infoRec->rec.redir.redirectingNumber.len;
2911 i++) {
2912 string8[i] = infoRec->rec.redir.redirectingNumber.buf[i];
2913 }
2914 string8[(int)infoRec->rec.redir.redirectingNumber.len] = '\0';
2915 writeStringToParcel(p, (const char*)string8);
2916 free(string8);
2917 string8 = NULL;
2918 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_type);
2919 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_plan);
2920 p.writeInt32(infoRec->rec.redir.redirectingNumber.pi);
2921 p.writeInt32(infoRec->rec.redir.redirectingNumber.si);
2922 p.writeInt32(infoRec->rec.redir.redirectingReason);
2923 break;
2924 case RIL_CDMA_LINE_CONTROL_INFO_REC:
2925 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPolarityIncluded);
2926 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlToggle);
2927 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlReverse);
2928 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2929
2930 appendPrintBuf("%slineCtrlPolarityIncluded=%d, \
2931 lineCtrlToggle=%d, lineCtrlReverse=%d, \
2932 lineCtrlPowerDenial=%d, ", printBuf,
2933 (int)infoRec->rec.lineCtrl.lineCtrlPolarityIncluded,
2934 (int)infoRec->rec.lineCtrl.lineCtrlToggle,
2935 (int)infoRec->rec.lineCtrl.lineCtrlReverse,
2936 (int)infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2937 removeLastChar;
2938 break;
2939 case RIL_CDMA_T53_CLIR_INFO_REC:
2940 p.writeInt32((int)(infoRec->rec.clir.cause));
2941
2942 appendPrintBuf("%scause%d", printBuf, infoRec->rec.clir.cause);
2943 removeLastChar;
2944 break;
2945 case RIL_CDMA_T53_AUDIO_CONTROL_INFO_REC:
2946 p.writeInt32(infoRec->rec.audioCtrl.upLink);
2947 p.writeInt32(infoRec->rec.audioCtrl.downLink);
2948
2949 appendPrintBuf("%supLink=%d, downLink=%d, ", printBuf,
2950 infoRec->rec.audioCtrl.upLink,
2951 infoRec->rec.audioCtrl.downLink);
2952 removeLastChar;
2953 break;
2954 case RIL_CDMA_T53_RELEASE_INFO_REC:
2955 // TODO(Moto): See David Krause, he has the answer:)
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002956 RLOGE("RIL_CDMA_T53_RELEASE_INFO_REC: return INVALID_RESPONSE");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002957 return RIL_ERRNO_INVALID_RESPONSE;
2958 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002959 RLOGE("Incorrect name value");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002960 return RIL_ERRNO_INVALID_RESPONSE;
2961 }
2962 }
2963 closeResponse;
2964
2965 return 0;
2966}
2967
2968static int responseRilSignalStrength(Parcel &p,
2969 void *response, size_t responselen) {
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05302970 int gsmSignalStrength;
2971 int cdmaDbm;
2972 int evdoDbm;
2973
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002974 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002975 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002976 return RIL_ERRNO_INVALID_RESPONSE;
2977 }
2978
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002979 if (responselen >= sizeof (RIL_SignalStrength_v5)) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002980 RIL_SignalStrength_v10 *p_cur = ((RIL_SignalStrength_v10 *) response);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002981
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05302982#if defined(MODEM_TYPE_XMM6262) || defined(MODEM_TYPE_XMM7260)
2983 gsmSignalStrength = p_cur->GW_SignalStrength.signalStrength & 0xFF;
2984 if (gsmSignalStrength < 0) {
2985 gsmSignalStrength = 99;
2986 } else if (gsmSignalStrength > 31 && gsmSignalStrength != 99) {
2987 gsmSignalStrength = 31;
2988 }
2989#else
2990 gsmSignalStrength = p_cur->GW_SignalStrength.signalStrength;
2991#endif
2992 p.writeInt32(gsmSignalStrength);
2993
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002994 p.writeInt32(p_cur->GW_SignalStrength.bitErrorRate);
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05302995
2996#if defined(MODEM_TYPE_XMM6262) || defined(MODEM_TYPE_XMM7260)
2997 cdmaDbm = p_cur->CDMA_SignalStrength.dbm & 0xFF;
2998 if (cdmaDbm < 0) {
2999 cdmaDbm = 99;
3000 } else if (cdmaDbm > 31 && cdmaDbm != 99) {
3001 cdmaDbm = 31;
3002 }
3003#else
3004 cdmaDbm = p_cur->CDMA_SignalStrength.dbm
3005#endif
3006 p.writeInt32(cdmaDbm);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003007 p.writeInt32(p_cur->CDMA_SignalStrength.ecio);
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303008
3009#if defined(MODEM_TYPE_XMM6262) || defined(MODEM_TYPE_XMM7260)
3010 evdoDbm = p_cur->EVDO_SignalStrength.dbm & 0xFF;
3011 if (evdoDbm < 0) {
3012 evdoDbm = 99;
3013 } else if (evdoDbm > 31 && evdoDbm != 99) {
3014 evdoDbm = 31;
3015 }
3016#else
3017 evdoDbm = p_cur->EVDO_SignalStrength.dbm;
3018#endif
3019 p.writeInt32(evdoDbm);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003020 p.writeInt32(p_cur->EVDO_SignalStrength.ecio);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003021 p.writeInt32(p_cur->EVDO_SignalStrength.signalNoiseRatio);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003022 if (responselen >= sizeof (RIL_SignalStrength_v6)) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003023 /*
Ethan Chend6e30652013-08-04 22:49:56 -07003024 * Fixup LTE for backwards compatibility
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003025 */
Ethan Chend6e30652013-08-04 22:49:56 -07003026 if (s_callbacks.version <= 6) {
3027 // signalStrength: -1 -> 99
3028 if (p_cur->LTE_SignalStrength.signalStrength == -1) {
3029 p_cur->LTE_SignalStrength.signalStrength = 99;
3030 }
3031 // rsrp: -1 -> INT_MAX all other negative value to positive.
3032 // So remap here
3033 if (p_cur->LTE_SignalStrength.rsrp == -1) {
3034 p_cur->LTE_SignalStrength.rsrp = INT_MAX;
3035 } else if (p_cur->LTE_SignalStrength.rsrp < -1) {
3036 p_cur->LTE_SignalStrength.rsrp = -p_cur->LTE_SignalStrength.rsrp;
3037 }
3038 // rsrq: -1 -> INT_MAX
3039 if (p_cur->LTE_SignalStrength.rsrq == -1) {
3040 p_cur->LTE_SignalStrength.rsrq = INT_MAX;
3041 }
3042 // Not remapping rssnr is already using INT_MAX
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003043
Ethan Chend6e30652013-08-04 22:49:56 -07003044 // cqi: -1 -> INT_MAX
3045 if (p_cur->LTE_SignalStrength.cqi == -1) {
3046 p_cur->LTE_SignalStrength.cqi = INT_MAX;
3047 }
3048 }
3049 p.writeInt32(p_cur->LTE_SignalStrength.signalStrength);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003050 p.writeInt32(p_cur->LTE_SignalStrength.rsrp);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003051 p.writeInt32(p_cur->LTE_SignalStrength.rsrq);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003052 p.writeInt32(p_cur->LTE_SignalStrength.rssnr);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003053 p.writeInt32(p_cur->LTE_SignalStrength.cqi);
Howard Sue32dbfd2015-01-07 15:55:57 +08003054 if (responselen >= sizeof (RIL_SignalStrength_v10)) {
3055 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
3056 } else {
3057 p.writeInt32(INT_MAX);
3058 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003059 } else {
Ethan Chend6e30652013-08-04 22:49:56 -07003060 p.writeInt32(99);
3061 p.writeInt32(INT_MAX);
3062 p.writeInt32(INT_MAX);
3063 p.writeInt32(INT_MAX);
3064 p.writeInt32(INT_MAX);
Howard Sue32dbfd2015-01-07 15:55:57 +08003065 p.writeInt32(INT_MAX);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003066 }
3067
3068 startResponse;
3069 appendPrintBuf("%s[signalStrength=%d,bitErrorRate=%d,\
3070 CDMA_SS.dbm=%d,CDMA_SSecio=%d,\
3071 EVDO_SS.dbm=%d,EVDO_SS.ecio=%d,\
3072 EVDO_SS.signalNoiseRatio=%d,\
3073 LTE_SS.signalStrength=%d,LTE_SS.rsrp=%d,LTE_SS.rsrq=%d,\
Howard Sue32dbfd2015-01-07 15:55:57 +08003074 LTE_SS.rssnr=%d,LTE_SS.cqi=%d,TDSCDMA_SS.rscp=%d]",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003075 printBuf,
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303076 gsmSignalStrength,
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003077 p_cur->GW_SignalStrength.bitErrorRate,
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303078 cdmaDbm,
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003079 p_cur->CDMA_SignalStrength.ecio,
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303080 evdoDbm,
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003081 p_cur->EVDO_SignalStrength.ecio,
3082 p_cur->EVDO_SignalStrength.signalNoiseRatio,
3083 p_cur->LTE_SignalStrength.signalStrength,
3084 p_cur->LTE_SignalStrength.rsrp,
3085 p_cur->LTE_SignalStrength.rsrq,
3086 p_cur->LTE_SignalStrength.rssnr,
Howard Sue32dbfd2015-01-07 15:55:57 +08003087 p_cur->LTE_SignalStrength.cqi,
3088 p_cur->TD_SCDMA_SignalStrength.rscp);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003089 closeResponse;
3090
3091 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003092 RLOGE("invalid response length");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003093 return RIL_ERRNO_INVALID_RESPONSE;
3094 }
3095
3096 return 0;
3097}
3098
3099static int responseCallRing(Parcel &p, void *response, size_t responselen) {
3100 if ((response == NULL) || (responselen == 0)) {
3101 return responseVoid(p, response, responselen);
3102 } else {
3103 return responseCdmaSignalInfoRecord(p, response, responselen);
3104 }
3105}
3106
3107static int responseCdmaSignalInfoRecord(Parcel &p, void *response, size_t responselen) {
3108 if (response == NULL || responselen == 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003109 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003110 return RIL_ERRNO_INVALID_RESPONSE;
3111 }
3112
3113 if (responselen != sizeof (RIL_CDMA_SignalInfoRecord)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003114 RLOGE("invalid response length %d expected sizeof (RIL_CDMA_SignalInfoRecord) of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003115 (int)responselen, (int)sizeof (RIL_CDMA_SignalInfoRecord));
3116 return RIL_ERRNO_INVALID_RESPONSE;
3117 }
3118
3119 startResponse;
3120
3121 RIL_CDMA_SignalInfoRecord *p_cur = ((RIL_CDMA_SignalInfoRecord *) response);
3122 marshallSignalInfoRecord(p, *p_cur);
3123
3124 appendPrintBuf("%s[isPresent=%d,signalType=%d,alertPitch=%d\
3125 signal=%d]",
3126 printBuf,
3127 p_cur->isPresent,
3128 p_cur->signalType,
3129 p_cur->alertPitch,
3130 p_cur->signal);
3131
3132 closeResponse;
3133 return 0;
3134}
3135
3136static int responseCdmaCallWaiting(Parcel &p, void *response,
3137 size_t responselen) {
3138 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003139 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003140 return RIL_ERRNO_INVALID_RESPONSE;
3141 }
3142
3143 if (responselen < sizeof(RIL_CDMA_CallWaiting_v6)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003144 RLOGW("Upgrade to ril version %d\n", RIL_VERSION);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003145 }
3146
3147 RIL_CDMA_CallWaiting_v6 *p_cur = ((RIL_CDMA_CallWaiting_v6 *) response);
3148
3149 writeStringToParcel(p, p_cur->number);
3150 p.writeInt32(p_cur->numberPresentation);
3151 writeStringToParcel(p, p_cur->name);
3152 marshallSignalInfoRecord(p, p_cur->signalInfoRecord);
3153
3154 if (responselen >= sizeof(RIL_CDMA_CallWaiting_v6)) {
3155 p.writeInt32(p_cur->number_type);
3156 p.writeInt32(p_cur->number_plan);
3157 } else {
3158 p.writeInt32(0);
3159 p.writeInt32(0);
3160 }
3161
3162 startResponse;
3163 appendPrintBuf("%snumber=%s,numberPresentation=%d, name=%s,\
3164 signalInfoRecord[isPresent=%d,signalType=%d,alertPitch=%d\
3165 signal=%d,number_type=%d,number_plan=%d]",
3166 printBuf,
3167 p_cur->number,
3168 p_cur->numberPresentation,
3169 p_cur->name,
3170 p_cur->signalInfoRecord.isPresent,
3171 p_cur->signalInfoRecord.signalType,
3172 p_cur->signalInfoRecord.alertPitch,
3173 p_cur->signalInfoRecord.signal,
3174 p_cur->number_type,
3175 p_cur->number_plan);
3176 closeResponse;
3177
3178 return 0;
3179}
3180
3181static int responseSimRefresh(Parcel &p, void *response, size_t responselen) {
3182 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003183 RLOGE("responseSimRefresh: invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003184 return RIL_ERRNO_INVALID_RESPONSE;
3185 }
3186
3187 startResponse;
3188 if (s_callbacks.version == 7) {
3189 RIL_SimRefreshResponse_v7 *p_cur = ((RIL_SimRefreshResponse_v7 *) response);
3190 p.writeInt32(p_cur->result);
3191 p.writeInt32(p_cur->ef_id);
3192 writeStringToParcel(p, p_cur->aid);
3193
3194 appendPrintBuf("%sresult=%d, ef_id=%d, aid=%s",
3195 printBuf,
3196 p_cur->result,
3197 p_cur->ef_id,
3198 p_cur->aid);
3199 } else {
3200 int *p_cur = ((int *) response);
3201 p.writeInt32(p_cur[0]);
3202 p.writeInt32(p_cur[1]);
3203 writeStringToParcel(p, NULL);
3204
3205 appendPrintBuf("%sresult=%d, ef_id=%d",
3206 printBuf,
3207 p_cur[0],
3208 p_cur[1]);
3209 }
3210 closeResponse;
3211
3212 return 0;
3213}
3214
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003215static int responseCellInfoList(Parcel &p, void *response, size_t responselen)
3216{
3217 if (response == NULL && responselen != 0) {
3218 RLOGE("invalid response: NULL");
3219 return RIL_ERRNO_INVALID_RESPONSE;
3220 }
3221
3222 if (responselen % sizeof(RIL_CellInfo) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08003223 RLOGE("responseCellInfoList: invalid response length %d expected multiple of %d",
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003224 (int)responselen, (int)sizeof(RIL_CellInfo));
3225 return RIL_ERRNO_INVALID_RESPONSE;
3226 }
3227
3228 int num = responselen / sizeof(RIL_CellInfo);
3229 p.writeInt32(num);
3230
3231 RIL_CellInfo *p_cur = (RIL_CellInfo *) response;
3232 startResponse;
3233 int i;
3234 for (i = 0; i < num; i++) {
3235 appendPrintBuf("%s[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", printBuf, i,
3236 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
3237 p.writeInt32((int)p_cur->cellInfoType);
3238 p.writeInt32(p_cur->registered);
3239 p.writeInt32(p_cur->timeStampType);
3240 p.writeInt64(p_cur->timeStamp);
3241 switch(p_cur->cellInfoType) {
3242 case RIL_CELL_INFO_TYPE_GSM: {
3243 appendPrintBuf("%s GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,", printBuf,
3244 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
3245 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
3246 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
3247 p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3248 appendPrintBuf("%s gsmSS: ss=%d,ber=%d],", printBuf,
3249 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
3250 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3251
3252 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
3253 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
3254 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
3255 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3256 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
3257 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3258 break;
3259 }
3260 case RIL_CELL_INFO_TYPE_WCDMA: {
3261 appendPrintBuf("%s WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,", printBuf,
3262 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
3263 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
3264 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
3265 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
3266 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3267 appendPrintBuf("%s wcdmaSS: ss=%d,ber=%d],", printBuf,
3268 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
3269 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3270
3271 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
3272 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
3273 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
3274 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
3275 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3276 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
3277 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3278 break;
3279 }
3280 case RIL_CELL_INFO_TYPE_CDMA: {
3281 appendPrintBuf("%s CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d", printBuf,
3282 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
3283 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
3284 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
3285 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
3286 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3287
3288 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
3289 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
3290 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
3291 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
3292 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3293
3294 appendPrintBuf("%s cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d", printBuf,
3295 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
3296 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
3297 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
3298 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
3299 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3300
3301 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
3302 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
3303 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
3304 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
3305 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3306 break;
3307 }
3308 case RIL_CELL_INFO_TYPE_LTE: {
3309 appendPrintBuf("%s LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d", printBuf,
3310 p_cur->CellInfo.lte.cellIdentityLte.mcc,
3311 p_cur->CellInfo.lte.cellIdentityLte.mnc,
3312 p_cur->CellInfo.lte.cellIdentityLte.ci,
3313 p_cur->CellInfo.lte.cellIdentityLte.pci,
3314 p_cur->CellInfo.lte.cellIdentityLte.tac);
3315
3316 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
3317 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
3318 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
3319 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
3320 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
3321
3322 appendPrintBuf("%s lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d", printBuf,
3323 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
3324 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
3325 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
3326 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
3327 p_cur->CellInfo.lte.signalStrengthLte.cqi,
3328 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3329 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
3330 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
3331 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
3332 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
3333 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
3334 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3335 break;
3336 }
Howard Sue32dbfd2015-01-07 15:55:57 +08003337 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
3338 appendPrintBuf("%s TDSCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,cpid=%d,", printBuf,
3339 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc,
3340 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc,
3341 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac,
3342 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid,
3343 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3344 appendPrintBuf("%s tdscdmaSS: rscp=%d],", printBuf,
3345 p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3346
3347 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
3348 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
3349 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
3350 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
3351 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3352 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3353 break;
3354 }
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003355 }
3356 p_cur += 1;
3357 }
3358 removeLastChar;
3359 closeResponse;
3360
3361 return 0;
3362}
3363
Howard Sue32dbfd2015-01-07 15:55:57 +08003364static int responseHardwareConfig(Parcel &p, void *response, size_t responselen)
3365{
3366 if (response == NULL && responselen != 0) {
3367 RLOGE("invalid response: NULL");
3368 return RIL_ERRNO_INVALID_RESPONSE;
3369 }
3370
3371 if (responselen % sizeof(RIL_HardwareConfig) != 0) {
3372 RLOGE("responseHardwareConfig: invalid response length %d expected multiple of %d",
3373 (int)responselen, (int)sizeof(RIL_HardwareConfig));
3374 return RIL_ERRNO_INVALID_RESPONSE;
3375 }
3376
3377 int num = responselen / sizeof(RIL_HardwareConfig);
3378 int i;
3379 RIL_HardwareConfig *p_cur = (RIL_HardwareConfig *) response;
3380
3381 p.writeInt32(num);
3382
3383 startResponse;
3384 for (i = 0; i < num; i++) {
3385 switch (p_cur[i].type) {
3386 case RIL_HARDWARE_CONFIG_MODEM: {
3387 writeStringToParcel(p, p_cur[i].uuid);
3388 p.writeInt32((int)p_cur[i].state);
3389 p.writeInt32(p_cur[i].cfg.modem.rat);
3390 p.writeInt32(p_cur[i].cfg.modem.maxVoice);
3391 p.writeInt32(p_cur[i].cfg.modem.maxData);
3392 p.writeInt32(p_cur[i].cfg.modem.maxStandby);
3393
3394 appendPrintBuf("%s modem: uuid=%s,state=%d,rat=%08x,maxV=%d,maxD=%d,maxS=%d", printBuf,
3395 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.modem.rat,
3396 p_cur[i].cfg.modem.maxVoice, p_cur[i].cfg.modem.maxData, p_cur[i].cfg.modem.maxStandby);
3397 break;
3398 }
3399 case RIL_HARDWARE_CONFIG_SIM: {
3400 writeStringToParcel(p, p_cur[i].uuid);
3401 p.writeInt32((int)p_cur[i].state);
3402 writeStringToParcel(p, p_cur[i].cfg.sim.modemUuid);
3403
3404 appendPrintBuf("%s sim: uuid=%s,state=%d,modem-uuid=%s", printBuf,
3405 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.sim.modemUuid);
3406 break;
3407 }
3408 }
3409 }
3410 removeLastChar;
3411 closeResponse;
3412 return 0;
3413}
3414
Howard Subd82ef12015-04-12 10:25:05 +02003415static int responseRadioCapability(Parcel &p, void *response, size_t responselen) {
3416 if (response == NULL) {
3417 RLOGE("invalid response: NULL");
3418 return RIL_ERRNO_INVALID_RESPONSE;
3419 }
3420
3421 if (responselen != sizeof (RIL_RadioCapability) ) {
3422 RLOGE("invalid response length was %d expected %d",
3423 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3424 return RIL_ERRNO_INVALID_RESPONSE;
3425 }
3426
3427 RIL_RadioCapability *p_cur = (RIL_RadioCapability *) response;
3428 p.writeInt32(p_cur->version);
3429 p.writeInt32(p_cur->session);
3430 p.writeInt32(p_cur->phase);
3431 p.writeInt32(p_cur->rat);
3432 writeStringToParcel(p, p_cur->logicalModemUuid);
3433 p.writeInt32(p_cur->status);
3434
3435 startResponse;
3436 appendPrintBuf("%s[version=%d,session=%d,phase=%d,\
3437 rat=%s,logicalModemUuid=%s,status=%d]",
3438 printBuf,
3439 p_cur->version,
3440 p_cur->session,
3441 p_cur->phase,
3442 p_cur->rat,
3443 p_cur->logicalModemUuid,
3444 p_cur->status);
3445 closeResponse;
3446 return 0;
3447}
3448
3449static int responseSSData(Parcel &p, void *response, size_t responselen) {
3450 RLOGD("In responseSSData");
3451 int num;
3452
3453 if (response == NULL && responselen != 0) {
3454 RLOGE("invalid response length was %d expected %d",
3455 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3456 return RIL_ERRNO_INVALID_RESPONSE;
3457 }
3458
3459 if (responselen != sizeof(RIL_StkCcUnsolSsResponse)) {
3460 RLOGE("invalid response length %d, expected %d",
3461 (int)responselen, (int)sizeof(RIL_StkCcUnsolSsResponse));
3462 return RIL_ERRNO_INVALID_RESPONSE;
3463 }
3464
3465 startResponse;
3466 RIL_StkCcUnsolSsResponse *p_cur = (RIL_StkCcUnsolSsResponse *) response;
3467 p.writeInt32(p_cur->serviceType);
3468 p.writeInt32(p_cur->requestType);
3469 p.writeInt32(p_cur->teleserviceType);
3470 p.writeInt32(p_cur->serviceClass);
3471 p.writeInt32(p_cur->result);
3472
3473 if (isServiceTypeCfQuery(p_cur->serviceType, p_cur->requestType)) {
3474 RLOGD("responseSSData CF type, num of Cf elements %d", p_cur->cfData.numValidIndexes);
3475 if (p_cur->cfData.numValidIndexes > NUM_SERVICE_CLASSES) {
3476 RLOGE("numValidIndexes is greater than max value %d, "
3477 "truncating it to max value", NUM_SERVICE_CLASSES);
3478 p_cur->cfData.numValidIndexes = NUM_SERVICE_CLASSES;
3479 }
3480 /* number of call info's */
3481 p.writeInt32(p_cur->cfData.numValidIndexes);
3482
3483 for (int i = 0; i < p_cur->cfData.numValidIndexes; i++) {
3484 RIL_CallForwardInfo cf = p_cur->cfData.cfInfo[i];
3485
3486 p.writeInt32(cf.status);
3487 p.writeInt32(cf.reason);
3488 p.writeInt32(cf.serviceClass);
3489 p.writeInt32(cf.toa);
3490 writeStringToParcel(p, cf.number);
3491 p.writeInt32(cf.timeSeconds);
3492 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
3493 (cf.status==1)?"enable":"disable", cf.reason, cf.serviceClass, cf.toa,
3494 (char*)cf.number, cf.timeSeconds);
3495 RLOGD("Data: %d,reason=%d,cls=%d,toa=%d,num=%s,tout=%d],", cf.status,
3496 cf.reason, cf.serviceClass, cf.toa, (char*)cf.number, cf.timeSeconds);
3497 }
3498 } else {
3499 p.writeInt32 (SS_INFO_MAX);
3500
3501 /* each int*/
3502 for (int i = 0; i < SS_INFO_MAX; i++) {
3503 appendPrintBuf("%s%d,", printBuf, p_cur->ssInfo[i]);
3504 RLOGD("Data: %d",p_cur->ssInfo[i]);
3505 p.writeInt32(p_cur->ssInfo[i]);
3506 }
3507 }
3508 removeLastChar;
3509 closeResponse;
3510
3511 return 0;
3512}
3513
3514static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType) {
3515 if ((reqType == SS_INTERROGATION) &&
3516 (serType == SS_CFU ||
3517 serType == SS_CF_BUSY ||
3518 serType == SS_CF_NO_REPLY ||
3519 serType == SS_CF_NOT_REACHABLE ||
3520 serType == SS_CF_ALL ||
3521 serType == SS_CF_ALL_CONDITIONAL)) {
3522 return true;
3523 }
3524 return false;
3525}
3526
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003527static void triggerEvLoop() {
3528 int ret;
3529 if (!pthread_equal(pthread_self(), s_tid_dispatch)) {
3530 /* trigger event loop to wakeup. No reason to do this,
3531 * if we're in the event loop thread */
3532 do {
3533 ret = write (s_fdWakeupWrite, " ", 1);
3534 } while (ret < 0 && errno == EINTR);
3535 }
3536}
3537
3538static void rilEventAddWakeup(struct ril_event *ev) {
3539 ril_event_add(ev);
3540 triggerEvLoop();
3541}
3542
3543static void sendSimStatusAppInfo(Parcel &p, int num_apps, RIL_AppStatus appStatus[]) {
3544 p.writeInt32(num_apps);
3545 startResponse;
3546 for (int i = 0; i < num_apps; i++) {
3547 p.writeInt32(appStatus[i].app_type);
3548 p.writeInt32(appStatus[i].app_state);
3549 p.writeInt32(appStatus[i].perso_substate);
3550 writeStringToParcel(p, (const char*)(appStatus[i].aid_ptr));
3551 writeStringToParcel(p, (const char*)
3552 (appStatus[i].app_label_ptr));
3553 p.writeInt32(appStatus[i].pin1_replaced);
3554 p.writeInt32(appStatus[i].pin1);
3555 p.writeInt32(appStatus[i].pin2);
3556 appendPrintBuf("%s[app_type=%d,app_state=%d,perso_substate=%d,\
3557 aid_ptr=%s,app_label_ptr=%s,pin1_replaced=%d,pin1=%d,pin2=%d],",
3558 printBuf,
3559 appStatus[i].app_type,
3560 appStatus[i].app_state,
3561 appStatus[i].perso_substate,
3562 appStatus[i].aid_ptr,
3563 appStatus[i].app_label_ptr,
3564 appStatus[i].pin1_replaced,
3565 appStatus[i].pin1,
3566 appStatus[i].pin2);
3567 }
3568 closeResponse;
3569}
3570
3571static int responseSimStatus(Parcel &p, void *response, size_t responselen) {
Howard Sue32dbfd2015-01-07 15:55:57 +08003572 int i;
3573
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003574 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003575 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003576 return RIL_ERRNO_INVALID_RESPONSE;
3577 }
3578
3579 if (responselen == sizeof (RIL_CardStatus_v6)) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003580 RIL_CardStatus_v6 *p_cur = ((RIL_CardStatus_v6 *) response);
3581
3582 p.writeInt32(p_cur->card_state);
3583 p.writeInt32(p_cur->universal_pin_state);
3584 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3585 p.writeInt32(p_cur->cdma_subscription_app_index);
3586 p.writeInt32(p_cur->ims_subscription_app_index);
3587
3588 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
3589 } else if (responselen == sizeof (RIL_CardStatus_v5)) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003590 RIL_CardStatus_v5 *p_cur = ((RIL_CardStatus_v5 *) response);
3591
3592 p.writeInt32(p_cur->card_state);
3593 p.writeInt32(p_cur->universal_pin_state);
3594 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3595 p.writeInt32(p_cur->cdma_subscription_app_index);
3596 p.writeInt32(-1);
3597
3598 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
3599 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003600 RLOGE("responseSimStatus: A RilCardStatus_v6 or _v5 expected\n");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003601 return RIL_ERRNO_INVALID_RESPONSE;
3602 }
3603
3604 return 0;
3605}
3606
3607static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3608 int num = responselen / sizeof(RIL_GSM_BroadcastSmsConfigInfo *);
3609 p.writeInt32(num);
3610
3611 startResponse;
3612 RIL_GSM_BroadcastSmsConfigInfo **p_cur =
3613 (RIL_GSM_BroadcastSmsConfigInfo **) response;
3614 for (int i = 0; i < num; i++) {
3615 p.writeInt32(p_cur[i]->fromServiceId);
3616 p.writeInt32(p_cur[i]->toServiceId);
3617 p.writeInt32(p_cur[i]->fromCodeScheme);
3618 p.writeInt32(p_cur[i]->toCodeScheme);
3619 p.writeInt32(p_cur[i]->selected);
3620
3621 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId=%d, \
3622 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]",
3623 printBuf, i, p_cur[i]->fromServiceId, p_cur[i]->toServiceId,
3624 p_cur[i]->fromCodeScheme, p_cur[i]->toCodeScheme,
3625 p_cur[i]->selected);
3626 }
3627 closeResponse;
3628
3629 return 0;
3630}
3631
3632static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3633 RIL_CDMA_BroadcastSmsConfigInfo **p_cur =
3634 (RIL_CDMA_BroadcastSmsConfigInfo **) response;
3635
3636 int num = responselen / sizeof (RIL_CDMA_BroadcastSmsConfigInfo *);
3637 p.writeInt32(num);
3638
3639 startResponse;
3640 for (int i = 0 ; i < num ; i++ ) {
3641 p.writeInt32(p_cur[i]->service_category);
3642 p.writeInt32(p_cur[i]->language);
3643 p.writeInt32(p_cur[i]->selected);
3644
3645 appendPrintBuf("%s [%d: srvice_category=%d, language =%d, \
3646 selected =%d], ",
3647 printBuf, i, p_cur[i]->service_category, p_cur[i]->language,
3648 p_cur[i]->selected);
3649 }
3650 closeResponse;
3651
3652 return 0;
3653}
3654
3655static int responseCdmaSms(Parcel &p, void *response, size_t responselen) {
3656 int num;
3657 int digitCount;
3658 int digitLimit;
3659 uint8_t uct;
3660 void* dest;
3661
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003662 RLOGD("Inside responseCdmaSms");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003663
3664 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003665 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003666 return RIL_ERRNO_INVALID_RESPONSE;
3667 }
3668
3669 if (responselen != sizeof(RIL_CDMA_SMS_Message)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003670 RLOGE("invalid response length was %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003671 (int)responselen, (int)sizeof(RIL_CDMA_SMS_Message));
3672 return RIL_ERRNO_INVALID_RESPONSE;
3673 }
3674
3675 RIL_CDMA_SMS_Message *p_cur = (RIL_CDMA_SMS_Message *) response;
3676 p.writeInt32(p_cur->uTeleserviceID);
3677 p.write(&(p_cur->bIsServicePresent),sizeof(uct));
3678 p.writeInt32(p_cur->uServicecategory);
3679 p.writeInt32(p_cur->sAddress.digit_mode);
3680 p.writeInt32(p_cur->sAddress.number_mode);
3681 p.writeInt32(p_cur->sAddress.number_type);
3682 p.writeInt32(p_cur->sAddress.number_plan);
3683 p.write(&(p_cur->sAddress.number_of_digits), sizeof(uct));
3684 digitLimit= MIN((p_cur->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
3685 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3686 p.write(&(p_cur->sAddress.digits[digitCount]),sizeof(uct));
3687 }
3688
3689 p.writeInt32(p_cur->sSubAddress.subaddressType);
3690 p.write(&(p_cur->sSubAddress.odd),sizeof(uct));
3691 p.write(&(p_cur->sSubAddress.number_of_digits),sizeof(uct));
3692 digitLimit= MIN((p_cur->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
3693 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3694 p.write(&(p_cur->sSubAddress.digits[digitCount]),sizeof(uct));
3695 }
3696
3697 digitLimit= MIN((p_cur->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
3698 p.writeInt32(p_cur->uBearerDataLen);
3699 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3700 p.write(&(p_cur->aBearerData[digitCount]), sizeof(uct));
3701 }
3702
3703 startResponse;
3704 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
3705 sAddress.digit_mode=%d, sAddress.number_mode=%d, sAddress.number_type=%d, ",
3706 printBuf, p_cur->uTeleserviceID,p_cur->bIsServicePresent,p_cur->uServicecategory,
3707 p_cur->sAddress.digit_mode, p_cur->sAddress.number_mode,p_cur->sAddress.number_type);
3708 closeResponse;
3709
3710 return 0;
3711}
3712
Howard Sue32dbfd2015-01-07 15:55:57 +08003713static int responseDcRtInfo(Parcel &p, void *response, size_t responselen)
3714{
3715 int num = responselen / sizeof(RIL_DcRtInfo);
3716 if ((responselen % sizeof(RIL_DcRtInfo) != 0) || (num != 1)) {
3717 RLOGE("responseDcRtInfo: invalid response length %d expected multiple of %d",
3718 (int)responselen, (int)sizeof(RIL_DcRtInfo));
3719 return RIL_ERRNO_INVALID_RESPONSE;
3720 }
3721
3722 startResponse;
3723 RIL_DcRtInfo *pDcRtInfo = (RIL_DcRtInfo *)response;
3724 p.writeInt64(pDcRtInfo->time);
3725 p.writeInt32(pDcRtInfo->powerState);
3726 appendPrintBuf("%s[time=%d,powerState=%d]", printBuf,
3727 pDcRtInfo->time,
3728 pDcRtInfo->powerState);
3729 closeResponse;
3730
3731 return 0;
3732}
3733
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003734/**
3735 * A write on the wakeup fd is done just to pop us out of select()
3736 * We empty the buffer here and then ril_event will reset the timers on the
3737 * way back down
3738 */
3739static void processWakeupCallback(int fd, short flags, void *param) {
3740 char buff[16];
3741 int ret;
3742
Ethan Chend6e30652013-08-04 22:49:56 -07003743 RLOGV("processWakeupCallback");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003744
3745 /* empty our wakeup socket out */
3746 do {
3747 ret = read(s_fdWakeupRead, &buff, sizeof(buff));
3748 } while (ret > 0 || (ret < 0 && errno == EINTR));
3749}
3750
Howard Sue32dbfd2015-01-07 15:55:57 +08003751static void onCommandsSocketClosed(RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003752 int ret;
3753 RequestInfo *p_cur;
Howard Sue32dbfd2015-01-07 15:55:57 +08003754 /* Hook for current context
3755 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
3756 pthread_mutex_t * pendingRequestsMutexHook = &s_pendingRequestsMutex;
3757 /* pendingRequestsHook refer to &s_pendingRequests */
3758 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003759
Howard Sue32dbfd2015-01-07 15:55:57 +08003760#if (SIM_COUNT >= 2)
3761 if (socket_id == RIL_SOCKET_2) {
3762 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
3763 pendingRequestsHook = &s_pendingRequests_socket2;
3764 }
3765#if (SIM_COUNT >= 3)
3766 else if (socket_id == RIL_SOCKET_3) {
3767 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
3768 pendingRequestsHook = &s_pendingRequests_socket3;
3769 }
3770#endif
3771#if (SIM_COUNT >= 4)
3772 else if (socket_id == RIL_SOCKET_4) {
3773 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
3774 pendingRequestsHook = &s_pendingRequests_socket4;
3775 }
3776#endif
3777#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003778 /* mark pending requests as "cancelled" so we dont report responses */
Howard Sue32dbfd2015-01-07 15:55:57 +08003779 ret = pthread_mutex_lock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003780 assert (ret == 0);
3781
Howard Sue32dbfd2015-01-07 15:55:57 +08003782 p_cur = *pendingRequestsHook;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003783
Howard Sue32dbfd2015-01-07 15:55:57 +08003784 for (p_cur = *pendingRequestsHook
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003785 ; p_cur != NULL
3786 ; p_cur = p_cur->p_next
3787 ) {
3788 p_cur->cancelled = 1;
3789 }
3790
Howard Sue32dbfd2015-01-07 15:55:57 +08003791 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003792 assert (ret == 0);
3793}
3794
3795static void processCommandsCallback(int fd, short flags, void *param) {
3796 RecordStream *p_rs;
3797 void *p_record;
3798 size_t recordlen;
3799 int ret;
Howard Sue32dbfd2015-01-07 15:55:57 +08003800 SocketListenParam *p_info = (SocketListenParam *)param;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003801
Howard Sue32dbfd2015-01-07 15:55:57 +08003802 assert(fd == p_info->fdCommand);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003803
Howard Sue32dbfd2015-01-07 15:55:57 +08003804 p_rs = p_info->p_rs;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003805
3806 for (;;) {
3807 /* loop until EAGAIN/EINTR, end of stream, or other error */
3808 ret = record_stream_get_next(p_rs, &p_record, &recordlen);
3809
3810 if (ret == 0 && p_record == NULL) {
3811 /* end-of-stream */
3812 break;
3813 } else if (ret < 0) {
3814 break;
3815 } else if (ret == 0) { /* && p_record != NULL */
Howard Sue32dbfd2015-01-07 15:55:57 +08003816 processCommandBuffer(p_record, recordlen, p_info->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003817 }
3818 }
3819
3820 if (ret == 0 || !(errno == EAGAIN || errno == EINTR)) {
3821 /* fatal error or end-of-stream */
3822 if (ret != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003823 RLOGE("error on reading command socket errno:%d\n", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003824 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003825 RLOGW("EOS. Closing command socket.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003826 }
3827
Howard Sue32dbfd2015-01-07 15:55:57 +08003828 close(fd);
3829 p_info->fdCommand = -1;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003830
Howard Sue32dbfd2015-01-07 15:55:57 +08003831 ril_event_del(p_info->commands_event);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003832
3833 record_stream_free(p_rs);
3834
3835 /* start listening for new connections again */
3836 rilEventAddWakeup(&s_listen_event);
3837
Howard Sue32dbfd2015-01-07 15:55:57 +08003838 onCommandsSocketClosed(p_info->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003839 }
3840}
3841
Howard Subd82ef12015-04-12 10:25:05 +02003842
Howard Sue32dbfd2015-01-07 15:55:57 +08003843static void onNewCommandConnect(RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003844 // Inform we are connected and the ril version
3845 int rilVer = s_callbacks.version;
Howard Sue32dbfd2015-01-07 15:55:57 +08003846 RIL_UNSOL_RESPONSE(RIL_UNSOL_RIL_CONNECTED,
3847 &rilVer, sizeof(rilVer), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003848
3849 // implicit radio state changed
Howard Sue32dbfd2015-01-07 15:55:57 +08003850 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
3851 NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003852
3853 // Send last NITZ time data, in case it was missed
3854 if (s_lastNITZTimeData != NULL) {
Howard Sue32dbfd2015-01-07 15:55:57 +08003855 sendResponseRaw(s_lastNITZTimeData, s_lastNITZTimeDataSize, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003856
3857 free(s_lastNITZTimeData);
3858 s_lastNITZTimeData = NULL;
3859 }
3860
3861 // Get version string
3862 if (s_callbacks.getVersion != NULL) {
3863 const char *version;
3864 version = s_callbacks.getVersion();
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003865 RLOGI("RIL Daemon version: %s\n", version);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003866
3867 property_set(PROPERTY_RIL_IMPL, version);
3868 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003869 RLOGI("RIL Daemon version: unavailable\n");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003870 property_set(PROPERTY_RIL_IMPL, "unavailable");
3871 }
3872
3873}
3874
3875static void listenCallback (int fd, short flags, void *param) {
3876 int ret;
3877 int err;
3878 int is_phone_socket;
Howard Sue32dbfd2015-01-07 15:55:57 +08003879 int fdCommand = -1;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003880 RecordStream *p_rs;
Howard Sue32dbfd2015-01-07 15:55:57 +08003881 SocketListenParam *p_info = (SocketListenParam *)param;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003882
3883 struct sockaddr_un peeraddr;
3884 socklen_t socklen = sizeof (peeraddr);
3885
3886 struct ucred creds;
3887 socklen_t szCreds = sizeof(creds);
3888
3889 struct passwd *pwd = NULL;
3890
Howard Sue32dbfd2015-01-07 15:55:57 +08003891 assert (*p_info->fdCommand < 0);
3892 assert (fd == *p_info->fdListen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003893
Howard Sue32dbfd2015-01-07 15:55:57 +08003894 fdCommand = accept(fd, (sockaddr *) &peeraddr, &socklen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003895
Howard Sue32dbfd2015-01-07 15:55:57 +08003896 if (fdCommand < 0 ) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003897 RLOGE("Error on accept() errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003898 /* start listening for new connections again */
Howard Sue32dbfd2015-01-07 15:55:57 +08003899 rilEventAddWakeup(p_info->listen_event);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003900 return;
3901 }
3902
3903 /* check the credential of the other side and only accept socket from
3904 * phone process
3905 */
3906 errno = 0;
3907 is_phone_socket = 0;
3908
Howard Sue32dbfd2015-01-07 15:55:57 +08003909 err = getsockopt(fdCommand, SOL_SOCKET, SO_PEERCRED, &creds, &szCreds);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003910
3911 if (err == 0 && szCreds > 0) {
3912 errno = 0;
3913 pwd = getpwuid(creds.uid);
3914 if (pwd != NULL) {
Howard Sue32dbfd2015-01-07 15:55:57 +08003915 if (strcmp(pwd->pw_name, p_info->processName) == 0) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003916 is_phone_socket = 1;
3917 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003918 RLOGE("RILD can't accept socket from process %s", pwd->pw_name);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003919 }
3920 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003921 RLOGE("Error on getpwuid() errno: %d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003922 }
3923 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003924 RLOGD("Error on getsockopt() errno: %d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003925 }
3926
Howard Subd82ef12015-04-12 10:25:05 +02003927 if (!is_phone_socket) {
Howard Sue32dbfd2015-01-07 15:55:57 +08003928 RLOGE("RILD must accept socket from %s", p_info->processName);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003929
Howard Sue32dbfd2015-01-07 15:55:57 +08003930 close(fdCommand);
3931 fdCommand = -1;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003932
Howard Sue32dbfd2015-01-07 15:55:57 +08003933 onCommandsSocketClosed(p_info->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003934
3935 /* start listening for new connections again */
Howard Sue32dbfd2015-01-07 15:55:57 +08003936 rilEventAddWakeup(p_info->listen_event);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003937
3938 return;
3939 }
3940
Howard Sue32dbfd2015-01-07 15:55:57 +08003941 ret = fcntl(fdCommand, F_SETFL, O_NONBLOCK);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003942
3943 if (ret < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003944 RLOGE ("Error setting O_NONBLOCK errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003945 }
3946
Howard Sue32dbfd2015-01-07 15:55:57 +08003947 RLOGI("libril: new connection to %s", rilSocketIdToString(p_info->socket_id));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003948
Howard Sue32dbfd2015-01-07 15:55:57 +08003949 p_info->fdCommand = fdCommand;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003950
Howard Sue32dbfd2015-01-07 15:55:57 +08003951 p_rs = record_stream_new(p_info->fdCommand, MAX_COMMAND_BYTES);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003952
Howard Sue32dbfd2015-01-07 15:55:57 +08003953 p_info->p_rs = p_rs;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003954
Howard Sue32dbfd2015-01-07 15:55:57 +08003955 ril_event_set (p_info->commands_event, p_info->fdCommand, 1,
3956 p_info->processCommandsCallback, p_info);
3957
3958 rilEventAddWakeup (p_info->commands_event);
3959
3960 onNewCommandConnect(p_info->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003961}
3962
3963static void freeDebugCallbackArgs(int number, char **args) {
3964 for (int i = 0; i < number; i++) {
3965 if (args[i] != NULL) {
3966 free(args[i]);
3967 }
3968 }
3969 free(args);
3970}
3971
3972static void debugCallback (int fd, short flags, void *param) {
3973 int acceptFD, option;
3974 struct sockaddr_un peeraddr;
3975 socklen_t socklen = sizeof (peeraddr);
3976 int data;
3977 unsigned int qxdm_data[6];
3978 const char *deactData[1] = {"1"};
3979 char *actData[1];
3980 RIL_Dial dialData;
3981 int hangupData[1] = {1};
3982 int number;
3983 char **args;
Howard Sue32dbfd2015-01-07 15:55:57 +08003984 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
3985 int sim_id = 0;
3986
3987 RLOGI("debugCallback for socket %s", rilSocketIdToString(socket_id));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003988
3989 acceptFD = accept (fd, (sockaddr *) &peeraddr, &socklen);
3990
3991 if (acceptFD < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003992 RLOGE ("error accepting on debug port: %d\n", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003993 return;
3994 }
3995
3996 if (recv(acceptFD, &number, sizeof(int), 0) != sizeof(int)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003997 RLOGE ("error reading on socket: number of Args: \n");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003998 return;
3999 }
4000 args = (char **) malloc(sizeof(char*) * number);
4001
4002 for (int i = 0; i < number; i++) {
4003 int len;
4004 if (recv(acceptFD, &len, sizeof(int), 0) != sizeof(int)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004005 RLOGE ("error reading on socket: Len of Args: \n");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004006 freeDebugCallbackArgs(i, args);
4007 return;
4008 }
4009 // +1 for null-term
4010 args[i] = (char *) malloc((sizeof(char) * len) + 1);
4011 if (recv(acceptFD, args[i], sizeof(char) * len, 0)
4012 != (int)sizeof(char) * len) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004013 RLOGE ("error reading on socket: Args[%d] \n", i);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004014 freeDebugCallbackArgs(i, args);
4015 return;
4016 }
4017 char * buf = args[i];
4018 buf[len] = 0;
Howard Sue32dbfd2015-01-07 15:55:57 +08004019 if ((i+1) == number) {
4020 /* The last argument should be sim id 0(SIM1)~3(SIM4) */
4021 sim_id = atoi(args[i]);
4022 switch (sim_id) {
4023 case 0:
4024 socket_id = RIL_SOCKET_1;
4025 break;
4026 #if (SIM_COUNT >= 2)
4027 case 1:
4028 socket_id = RIL_SOCKET_2;
4029 break;
4030 #endif
4031 #if (SIM_COUNT >= 3)
4032 case 2:
4033 socket_id = RIL_SOCKET_3;
4034 break;
4035 #endif
4036 #if (SIM_COUNT >= 4)
4037 case 3:
4038 socket_id = RIL_SOCKET_4;
4039 break;
4040 #endif
4041 default:
4042 socket_id = RIL_SOCKET_1;
4043 break;
4044 }
4045 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004046 }
4047
4048 switch (atoi(args[0])) {
4049 case 0:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004050 RLOGI ("Connection on debug port: issuing reset.");
Howard Sue32dbfd2015-01-07 15:55:57 +08004051 issueLocalRequest(RIL_REQUEST_RESET_RADIO, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004052 break;
4053 case 1:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004054 RLOGI ("Connection on debug port: issuing radio power off.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004055 data = 0;
Howard Sue32dbfd2015-01-07 15:55:57 +08004056 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004057 // Close the socket
Howard Subd82ef12015-04-12 10:25:05 +02004058 if (socket_id == RIL_SOCKET_1 && s_ril_param_socket.fdCommand > 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08004059 close(s_ril_param_socket.fdCommand);
4060 s_ril_param_socket.fdCommand = -1;
4061 }
4062 #if (SIM_COUNT == 2)
4063 else if (socket_id == RIL_SOCKET_2 && s_ril_param_socket2.fdCommand > 0) {
4064 close(s_ril_param_socket2.fdCommand);
4065 s_ril_param_socket2.fdCommand = -1;
4066 }
4067 #endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004068 break;
4069 case 2:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004070 RLOGI ("Debug port: issuing unsolicited voice network change.");
Howard Sue32dbfd2015-01-07 15:55:57 +08004071 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004072 break;
4073 case 3:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004074 RLOGI ("Debug port: QXDM log enable.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004075 qxdm_data[0] = 65536; // head.func_tag
4076 qxdm_data[1] = 16; // head.len
4077 qxdm_data[2] = 1; // mode: 1 for 'start logging'
4078 qxdm_data[3] = 32; // log_file_size: 32megabytes
4079 qxdm_data[4] = 0; // log_mask
4080 qxdm_data[5] = 8; // log_max_fileindex
4081 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Howard Sue32dbfd2015-01-07 15:55:57 +08004082 6 * sizeof(int), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004083 break;
4084 case 4:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004085 RLOGI ("Debug port: QXDM log disable.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004086 qxdm_data[0] = 65536;
4087 qxdm_data[1] = 16;
4088 qxdm_data[2] = 0; // mode: 0 for 'stop logging'
4089 qxdm_data[3] = 32;
4090 qxdm_data[4] = 0;
4091 qxdm_data[5] = 8;
4092 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Howard Sue32dbfd2015-01-07 15:55:57 +08004093 6 * sizeof(int), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004094 break;
4095 case 5:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004096 RLOGI("Debug port: Radio On");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004097 data = 1;
Howard Sue32dbfd2015-01-07 15:55:57 +08004098 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004099 sleep(2);
4100 // Set network selection automatic.
Howard Sue32dbfd2015-01-07 15:55:57 +08004101 issueLocalRequest(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004102 break;
4103 case 6:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004104 RLOGI("Debug port: Setup Data Call, Apn :%s\n", args[1]);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004105 actData[0] = args[1];
4106 issueLocalRequest(RIL_REQUEST_SETUP_DATA_CALL, &actData,
Howard Sue32dbfd2015-01-07 15:55:57 +08004107 sizeof(actData), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004108 break;
4109 case 7:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004110 RLOGI("Debug port: Deactivate Data Call");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004111 issueLocalRequest(RIL_REQUEST_DEACTIVATE_DATA_CALL, &deactData,
Howard Sue32dbfd2015-01-07 15:55:57 +08004112 sizeof(deactData), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004113 break;
4114 case 8:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004115 RLOGI("Debug port: Dial Call");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004116 dialData.clir = 0;
4117 dialData.address = args[1];
Howard Sue32dbfd2015-01-07 15:55:57 +08004118 issueLocalRequest(RIL_REQUEST_DIAL, &dialData, sizeof(dialData), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004119 break;
4120 case 9:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004121 RLOGI("Debug port: Answer Call");
Howard Sue32dbfd2015-01-07 15:55:57 +08004122 issueLocalRequest(RIL_REQUEST_ANSWER, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004123 break;
4124 case 10:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004125 RLOGI("Debug port: End Call");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004126 issueLocalRequest(RIL_REQUEST_HANGUP, &hangupData,
Howard Sue32dbfd2015-01-07 15:55:57 +08004127 sizeof(hangupData), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004128 break;
4129 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004130 RLOGE ("Invalid request");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004131 break;
4132 }
4133 freeDebugCallbackArgs(number, args);
4134 close(acceptFD);
4135}
4136
4137
4138static void userTimerCallback (int fd, short flags, void *param) {
4139 UserCallbackInfo *p_info;
4140
4141 p_info = (UserCallbackInfo *)param;
4142
4143 p_info->p_callback(p_info->userParam);
4144
4145
4146 // FIXME generalize this...there should be a cancel mechanism
4147 if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) {
4148 s_last_wake_timeout_info = NULL;
4149 }
4150
4151 free(p_info);
4152}
4153
4154
4155static void *
4156eventLoop(void *param) {
4157 int ret;
4158 int filedes[2];
4159
4160 ril_event_init();
4161
4162 pthread_mutex_lock(&s_startupMutex);
4163
4164 s_started = 1;
4165 pthread_cond_broadcast(&s_startupCond);
4166
4167 pthread_mutex_unlock(&s_startupMutex);
4168
4169 ret = pipe(filedes);
4170
4171 if (ret < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004172 RLOGE("Error in pipe() errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004173 return NULL;
4174 }
4175
4176 s_fdWakeupRead = filedes[0];
4177 s_fdWakeupWrite = filedes[1];
4178
4179 fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK);
4180
4181 ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,
4182 processWakeupCallback, NULL);
4183
4184 rilEventAddWakeup (&s_wakeupfd_event);
4185
4186 // Only returns on error
4187 ril_event_loop();
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004188 RLOGE ("error in event_loop_base errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004189 // kill self to restart on error
4190 kill(0, SIGKILL);
4191
4192 return NULL;
4193}
4194
4195extern "C" void
4196RIL_startEventLoop(void) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004197 /* spin up eventLoop thread and wait for it to get started */
4198 s_started = 0;
4199 pthread_mutex_lock(&s_startupMutex);
4200
Howard Sue32dbfd2015-01-07 15:55:57 +08004201 pthread_attr_t attr;
4202 pthread_attr_init(&attr);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004203 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
Howard Sue32dbfd2015-01-07 15:55:57 +08004204
4205 int result = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
4206 if (result != 0) {
4207 RLOGE("Failed to create dispatch thread: %s", strerror(result));
4208 goto done;
4209 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004210
4211 while (s_started == 0) {
4212 pthread_cond_wait(&s_startupCond, &s_startupMutex);
4213 }
4214
Howard Sue32dbfd2015-01-07 15:55:57 +08004215done:
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004216 pthread_mutex_unlock(&s_startupMutex);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004217}
4218
4219// Used for testing purpose only.
4220extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) {
4221 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4222}
4223
Howard Sue32dbfd2015-01-07 15:55:57 +08004224static void startListen(RIL_SOCKET_ID socket_id, SocketListenParam* socket_listen_p) {
4225 int fdListen = -1;
4226 int ret;
4227 char socket_name[10];
4228
4229 memset(socket_name, 0, sizeof(char)*10);
4230
4231 switch(socket_id) {
4232 case RIL_SOCKET_1:
4233 strncpy(socket_name, RIL_getRilSocketName(), 9);
4234 break;
4235 #if (SIM_COUNT >= 2)
4236 case RIL_SOCKET_2:
4237 strncpy(socket_name, SOCKET2_NAME_RIL, 9);
4238 break;
4239 #endif
4240 #if (SIM_COUNT >= 3)
4241 case RIL_SOCKET_3:
4242 strncpy(socket_name, SOCKET3_NAME_RIL, 9);
4243 break;
4244 #endif
4245 #if (SIM_COUNT >= 4)
4246 case RIL_SOCKET_4:
4247 strncpy(socket_name, SOCKET4_NAME_RIL, 9);
4248 break;
4249 #endif
4250 default:
4251 RLOGE("Socket id is wrong!!");
4252 return;
4253 }
4254
4255 RLOGI("Start to listen %s", rilSocketIdToString(socket_id));
4256
4257 fdListen = android_get_control_socket(socket_name);
4258 if (fdListen < 0) {
4259 RLOGE("Failed to get socket %s", socket_name);
4260 exit(-1);
4261 }
4262
4263 ret = listen(fdListen, 4);
4264
4265 if (ret < 0) {
4266 RLOGE("Failed to listen on control socket '%d': %s",
4267 fdListen, strerror(errno));
4268 exit(-1);
4269 }
4270 socket_listen_p->fdListen = fdListen;
4271
4272 /* note: non-persistent so we can accept only one connection at a time */
4273 ril_event_set (socket_listen_p->listen_event, fdListen, false,
4274 listenCallback, socket_listen_p);
4275
4276 rilEventAddWakeup (socket_listen_p->listen_event);
4277}
4278
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004279extern "C" void
4280RIL_register (const RIL_RadioFunctions *callbacks) {
4281 int ret;
4282 int flags;
4283
Howard Sue32dbfd2015-01-07 15:55:57 +08004284 RLOGI("SIM_COUNT: %d", SIM_COUNT);
4285
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004286 if (callbacks == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004287 RLOGE("RIL_register: RIL_RadioFunctions * null");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004288 return;
4289 }
4290 if (callbacks->version < RIL_VERSION_MIN) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004291 RLOGE("RIL_register: version %d is to old, min version is %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004292 callbacks->version, RIL_VERSION_MIN);
4293 return;
4294 }
4295 if (callbacks->version > RIL_VERSION) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004296 RLOGE("RIL_register: version %d is too new, max version is %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004297 callbacks->version, RIL_VERSION);
4298 return;
4299 }
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004300 RLOGE("RIL_register: RIL version %d", callbacks->version);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004301
4302 if (s_registerCalled > 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004303 RLOGE("RIL_register has been called more than once. "
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004304 "Subsequent call ignored");
4305 return;
4306 }
4307
4308 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4309
Howard Sue32dbfd2015-01-07 15:55:57 +08004310 /* Initialize socket1 parameters */
4311 s_ril_param_socket = {
4312 RIL_SOCKET_1, /* socket_id */
4313 -1, /* fdListen */
4314 -1, /* fdCommand */
4315 PHONE_PROCESS, /* processName */
4316 &s_commands_event, /* commands_event */
4317 &s_listen_event, /* listen_event */
4318 processCommandsCallback, /* processCommandsCallback */
4319 NULL /* p_rs */
4320 };
4321
4322#if (SIM_COUNT >= 2)
4323 s_ril_param_socket2 = {
4324 RIL_SOCKET_2, /* socket_id */
4325 -1, /* fdListen */
4326 -1, /* fdCommand */
4327 PHONE_PROCESS, /* processName */
4328 &s_commands_event_socket2, /* commands_event */
4329 &s_listen_event_socket2, /* listen_event */
4330 processCommandsCallback, /* processCommandsCallback */
4331 NULL /* p_rs */
4332 };
4333#endif
4334
4335#if (SIM_COUNT >= 3)
4336 s_ril_param_socket3 = {
4337 RIL_SOCKET_3, /* socket_id */
4338 -1, /* fdListen */
4339 -1, /* fdCommand */
4340 PHONE_PROCESS, /* processName */
4341 &s_commands_event_socket3, /* commands_event */
4342 &s_listen_event_socket3, /* listen_event */
4343 processCommandsCallback, /* processCommandsCallback */
4344 NULL /* p_rs */
4345 };
4346#endif
4347
4348#if (SIM_COUNT >= 4)
4349 s_ril_param_socket4 = {
4350 RIL_SOCKET_4, /* socket_id */
4351 -1, /* fdListen */
4352 -1, /* fdCommand */
4353 PHONE_PROCESS, /* processName */
4354 &s_commands_event_socket4, /* commands_event */
4355 &s_listen_event_socket4, /* listen_event */
4356 processCommandsCallback, /* processCommandsCallback */
4357 NULL /* p_rs */
4358 };
4359#endif
4360
Howard Subd82ef12015-04-12 10:25:05 +02004361
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004362 s_registerCalled = 1;
4363
Howard Sue32dbfd2015-01-07 15:55:57 +08004364 RLOGI("s_registerCalled flag set, %d", s_started);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004365 // Little self-check
4366
4367 for (int i = 0; i < (int)NUM_ELEMS(s_commands); i++) {
4368 assert(i == s_commands[i].requestNumber);
4369 }
4370
Howard Subd82ef12015-04-12 10:25:05 +02004371 for (int i = 0; i < (int)NUM_ELEMS(s_commands_v); i++) {
4372 assert(i + RIL_VENDOR_COMMANDS_OFFSET == s_commands[i].requestNumber);
4373 }
4374
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004375 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses); i++) {
Howard Sue32dbfd2015-01-07 15:55:57 +08004376 assert(i + RIL_UNSOL_RESPONSE_BASE
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004377 == s_unsolResponses[i].requestNumber);
4378 }
4379
Howard Subd82ef12015-04-12 10:25:05 +02004380 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses_v); i++) {
4381 assert(i + RIL_UNSOL_RESPONSE_BASE + RIL_VENDOR_COMMANDS_OFFSET
4382 == s_unsolResponses[i].requestNumber);
4383 }
4384
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004385 // New rild impl calls RIL_startEventLoop() first
4386 // old standalone impl wants it here.
4387
4388 if (s_started == 0) {
4389 RIL_startEventLoop();
4390 }
4391
Howard Sue32dbfd2015-01-07 15:55:57 +08004392 // start listen socket1
4393 startListen(RIL_SOCKET_1, &s_ril_param_socket);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004394
Howard Sue32dbfd2015-01-07 15:55:57 +08004395#if (SIM_COUNT >= 2)
4396 // start listen socket2
4397 startListen(RIL_SOCKET_2, &s_ril_param_socket2);
4398#endif /* (SIM_COUNT == 2) */
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004399
Howard Sue32dbfd2015-01-07 15:55:57 +08004400#if (SIM_COUNT >= 3)
4401 // start listen socket3
4402 startListen(RIL_SOCKET_3, &s_ril_param_socket3);
4403#endif /* (SIM_COUNT == 3) */
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004404
Howard Sue32dbfd2015-01-07 15:55:57 +08004405#if (SIM_COUNT >= 4)
4406 // start listen socket4
4407 startListen(RIL_SOCKET_4, &s_ril_param_socket4);
4408#endif /* (SIM_COUNT == 4) */
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004409
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004410
4411#if 1
4412 // start debug interface socket
4413
Howard Sue32dbfd2015-01-07 15:55:57 +08004414 char *inst = NULL;
4415 if (strlen(RIL_getRilSocketName()) >= strlen(SOCKET_NAME_RIL)) {
4416 inst = RIL_getRilSocketName() + strlen(SOCKET_NAME_RIL);
4417 }
4418
4419 char rildebug[MAX_DEBUG_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL_DEBUG;
4420 if (inst != NULL) {
4421 strncat(rildebug, inst, MAX_DEBUG_SOCKET_NAME_LENGTH);
4422 }
4423
4424 s_fdDebug = android_get_control_socket(rildebug);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004425 if (s_fdDebug < 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08004426 RLOGE("Failed to get socket : %s errno:%d", rildebug, errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004427 exit(-1);
4428 }
4429
4430 ret = listen(s_fdDebug, 4);
4431
4432 if (ret < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004433 RLOGE("Failed to listen on ril debug socket '%d': %s",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004434 s_fdDebug, strerror(errno));
4435 exit(-1);
4436 }
4437
4438 ril_event_set (&s_debug_event, s_fdDebug, true,
4439 debugCallback, NULL);
4440
4441 rilEventAddWakeup (&s_debug_event);
4442#endif
4443
4444}
4445
4446static int
4447checkAndDequeueRequestInfo(struct RequestInfo *pRI) {
4448 int ret = 0;
Howard Sue32dbfd2015-01-07 15:55:57 +08004449 /* Hook for current context
4450 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
4451 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
4452 /* pendingRequestsHook refer to &s_pendingRequests */
4453 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004454
4455 if (pRI == NULL) {
4456 return 0;
4457 }
4458
Howard Sue32dbfd2015-01-07 15:55:57 +08004459#if (SIM_COUNT >= 2)
4460 if (pRI->socket_id == RIL_SOCKET_2) {
4461 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
4462 pendingRequestsHook = &s_pendingRequests_socket2;
4463 }
4464#if (SIM_COUNT >= 3)
4465 if (pRI->socket_id == RIL_SOCKET_3) {
4466 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
4467 pendingRequestsHook = &s_pendingRequests_socket3;
4468 }
4469#endif
4470#if (SIM_COUNT >= 4)
4471 if (pRI->socket_id == RIL_SOCKET_4) {
4472 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
4473 pendingRequestsHook = &s_pendingRequests_socket4;
4474 }
4475#endif
4476#endif
4477 pthread_mutex_lock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004478
Howard Sue32dbfd2015-01-07 15:55:57 +08004479 for(RequestInfo **ppCur = pendingRequestsHook
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004480 ; *ppCur != NULL
4481 ; ppCur = &((*ppCur)->p_next)
4482 ) {
4483 if (pRI == *ppCur) {
4484 ret = 1;
4485
4486 *ppCur = (*ppCur)->p_next;
4487 break;
4488 }
4489 }
4490
Howard Sue32dbfd2015-01-07 15:55:57 +08004491 pthread_mutex_unlock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004492
4493 return ret;
4494}
4495
4496
4497extern "C" void
4498RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) {
4499 RequestInfo *pRI;
4500 int ret;
Howard Sue32dbfd2015-01-07 15:55:57 +08004501 int fd = s_ril_param_socket.fdCommand;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004502 size_t errorOffset;
Howard Sue32dbfd2015-01-07 15:55:57 +08004503 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004504
4505 pRI = (RequestInfo *)t;
4506
4507 if (!checkAndDequeueRequestInfo(pRI)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004508 RLOGE ("RIL_onRequestComplete: invalid RIL_Token");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004509 return;
4510 }
4511
Howard Sue32dbfd2015-01-07 15:55:57 +08004512 socket_id = pRI->socket_id;
4513#if (SIM_COUNT >= 2)
4514 if (socket_id == RIL_SOCKET_2) {
4515 fd = s_ril_param_socket2.fdCommand;
4516 }
4517#if (SIM_COUNT >= 3)
4518 if (socket_id == RIL_SOCKET_3) {
4519 fd = s_ril_param_socket3.fdCommand;
4520 }
4521#endif
4522#if (SIM_COUNT >= 4)
4523 if (socket_id == RIL_SOCKET_4) {
4524 fd = s_ril_param_socket4.fdCommand;
4525 }
4526#endif
4527#endif
4528 RLOGD("RequestComplete, %s", rilSocketIdToString(socket_id));
4529
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004530 if (pRI->local > 0) {
4531 // Locally issued command...void only!
4532 // response does not go back up the command socket
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004533 RLOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004534
4535 goto done;
4536 }
4537
4538 appendPrintBuf("[%04d]< %s",
4539 pRI->token, requestToString(pRI->pCI->requestNumber));
4540
4541 if (pRI->cancelled == 0) {
4542 Parcel p;
4543
4544 p.writeInt32 (RESPONSE_SOLICITED);
4545 p.writeInt32 (pRI->token);
4546 errorOffset = p.dataPosition();
4547
4548 p.writeInt32 (e);
4549
4550 if (response != NULL) {
4551 // there is a response payload, no matter success or not.
4552 ret = pRI->pCI->responseFunction(p, response, responselen);
4553
4554 /* if an error occurred, rewind and mark it */
4555 if (ret != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08004556 RLOGE ("responseFunction error, ret %d", ret);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004557 p.setDataPosition(errorOffset);
4558 p.writeInt32 (ret);
4559 }
4560 }
4561
4562 if (e != RIL_E_SUCCESS) {
4563 appendPrintBuf("%s fails by %s", printBuf, failCauseToString(e));
4564 }
4565
Howard Sue32dbfd2015-01-07 15:55:57 +08004566 if (fd < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004567 RLOGD ("RIL onRequestComplete: Command channel closed");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004568 }
Howard Sue32dbfd2015-01-07 15:55:57 +08004569 sendResponse(p, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004570 }
4571
4572done:
4573 free(pRI);
4574}
4575
Howard Subd82ef12015-04-12 10:25:05 +02004576
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004577static void
4578grabPartialWakeLock() {
4579 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
4580}
4581
4582static void
4583releaseWakeLock() {
4584 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
4585}
4586
4587/**
4588 * Timer callback to put us back to sleep before the default timeout
4589 */
4590static void
4591wakeTimeoutCallback (void *param) {
4592 // We're using "param != NULL" as a cancellation mechanism
4593 if (param == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004594 //RLOGD("wakeTimeout: releasing wake lock");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004595
4596 releaseWakeLock();
4597 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004598 //RLOGD("wakeTimeout: releasing wake lock CANCELLED");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004599 }
4600}
4601
4602static int
4603decodeVoiceRadioTechnology (RIL_RadioState radioState) {
4604 switch (radioState) {
4605 case RADIO_STATE_SIM_NOT_READY:
4606 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4607 case RADIO_STATE_SIM_READY:
4608 return RADIO_TECH_UMTS;
4609
4610 case RADIO_STATE_RUIM_NOT_READY:
4611 case RADIO_STATE_RUIM_READY:
4612 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4613 case RADIO_STATE_NV_NOT_READY:
4614 case RADIO_STATE_NV_READY:
4615 return RADIO_TECH_1xRTT;
4616
4617 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004618 RLOGD("decodeVoiceRadioTechnology: Invoked with incorrect RadioState");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004619 return -1;
4620 }
4621}
4622
4623static int
4624decodeCdmaSubscriptionSource (RIL_RadioState radioState) {
4625 switch (radioState) {
4626 case RADIO_STATE_SIM_NOT_READY:
4627 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4628 case RADIO_STATE_SIM_READY:
4629 case RADIO_STATE_RUIM_NOT_READY:
4630 case RADIO_STATE_RUIM_READY:
4631 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4632 return CDMA_SUBSCRIPTION_SOURCE_RUIM_SIM;
4633
4634 case RADIO_STATE_NV_NOT_READY:
4635 case RADIO_STATE_NV_READY:
4636 return CDMA_SUBSCRIPTION_SOURCE_NV;
4637
4638 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004639 RLOGD("decodeCdmaSubscriptionSource: Invoked with incorrect RadioState");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004640 return -1;
4641 }
4642}
4643
4644static int
4645decodeSimStatus (RIL_RadioState radioState) {
4646 switch (radioState) {
4647 case RADIO_STATE_SIM_NOT_READY:
4648 case RADIO_STATE_RUIM_NOT_READY:
4649 case RADIO_STATE_NV_NOT_READY:
4650 case RADIO_STATE_NV_READY:
4651 return -1;
4652 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4653 case RADIO_STATE_SIM_READY:
4654 case RADIO_STATE_RUIM_READY:
4655 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4656 return radioState;
4657 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004658 RLOGD("decodeSimStatus: Invoked with incorrect RadioState");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004659 return -1;
4660 }
4661}
4662
4663static bool is3gpp2(int radioTech) {
4664 switch (radioTech) {
4665 case RADIO_TECH_IS95A:
4666 case RADIO_TECH_IS95B:
4667 case RADIO_TECH_1xRTT:
4668 case RADIO_TECH_EVDO_0:
4669 case RADIO_TECH_EVDO_A:
4670 case RADIO_TECH_EVDO_B:
4671 case RADIO_TECH_EHRPD:
4672 return true;
4673 default:
4674 return false;
4675 }
4676}
4677
4678/* If RIL sends SIM states or RUIM states, store the voice radio
4679 * technology and subscription source information so that they can be
4680 * returned when telephony framework requests them
4681 */
4682static RIL_RadioState
Howard Subd82ef12015-04-12 10:25:05 +02004683processRadioState(RIL_RadioState newRadioState, RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004684
4685 if((newRadioState > RADIO_STATE_UNAVAILABLE) && (newRadioState < RADIO_STATE_ON)) {
4686 int newVoiceRadioTech;
4687 int newCdmaSubscriptionSource;
4688 int newSimStatus;
4689
4690 /* This is old RIL. Decode Subscription source and Voice Radio Technology
4691 from Radio State and send change notifications if there has been a change */
4692 newVoiceRadioTech = decodeVoiceRadioTechnology(newRadioState);
4693 if(newVoiceRadioTech != voiceRadioTech) {
4694 voiceRadioTech = newVoiceRadioTech;
Howard Sue32dbfd2015-01-07 15:55:57 +08004695 RIL_UNSOL_RESPONSE(RIL_UNSOL_VOICE_RADIO_TECH_CHANGED,
4696 &voiceRadioTech, sizeof(voiceRadioTech), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004697 }
4698 if(is3gpp2(newVoiceRadioTech)) {
4699 newCdmaSubscriptionSource = decodeCdmaSubscriptionSource(newRadioState);
4700 if(newCdmaSubscriptionSource != cdmaSubscriptionSource) {
4701 cdmaSubscriptionSource = newCdmaSubscriptionSource;
Howard Sue32dbfd2015-01-07 15:55:57 +08004702 RIL_UNSOL_RESPONSE(RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED,
4703 &cdmaSubscriptionSource, sizeof(cdmaSubscriptionSource), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004704 }
4705 }
4706 newSimStatus = decodeSimStatus(newRadioState);
4707 if(newSimStatus != simRuimStatus) {
4708 simRuimStatus = newSimStatus;
Howard Sue32dbfd2015-01-07 15:55:57 +08004709 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004710 }
4711
4712 /* Send RADIO_ON to telephony */
4713 newRadioState = RADIO_STATE_ON;
4714 }
4715
4716 return newRadioState;
4717}
4718
Howard Subd82ef12015-04-12 10:25:05 +02004719
Howard Sue32dbfd2015-01-07 15:55:57 +08004720#if defined(ANDROID_MULTI_SIM)
4721extern "C"
Andreas Schneider47b2d962015-04-13 22:54:49 +02004722void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Howard Sue32dbfd2015-01-07 15:55:57 +08004723 size_t datalen, RIL_SOCKET_ID socket_id)
4724#else
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004725extern "C"
Andreas Schneider47b2d962015-04-13 22:54:49 +02004726void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004727 size_t datalen)
Howard Sue32dbfd2015-01-07 15:55:57 +08004728#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004729{
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004730 int ret;
4731 int64_t timeReceived = 0;
4732 bool shouldScheduleTimeout = false;
4733 RIL_RadioState newState;
Howard Sue32dbfd2015-01-07 15:55:57 +08004734 RIL_SOCKET_ID soc_id = RIL_SOCKET_1;
Howard Subd82ef12015-04-12 10:25:05 +02004735 UnsolResponseInfo *pRI = NULL;
Howard Sue32dbfd2015-01-07 15:55:57 +08004736
4737#if defined(ANDROID_MULTI_SIM)
4738 soc_id = socket_id;
4739#endif
4740
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004741
4742 if (s_registerCalled == 0) {
4743 // Ignore RIL_onUnsolicitedResponse before RIL_register
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004744 RLOGW("RIL_onUnsolicitedResponse called before RIL_register");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004745 return;
4746 }
Howard Sue32dbfd2015-01-07 15:55:57 +08004747
Howard Subd82ef12015-04-12 10:25:05 +02004748 /* Hack to include Samsung responses */
4749 if (unsolResponse > RIL_VENDOR_COMMANDS_OFFSET + RIL_UNSOL_RESPONSE_BASE) {
4750 int index = unsolResponse - RIL_VENDOR_COMMANDS_OFFSET - RIL_UNSOL_RESPONSE_BASE;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004751
Howard Subd82ef12015-04-12 10:25:05 +02004752 RLOGD("SAMSUNG: unsolResponse=%d, unsolResponseIndex=%d", unsolResponse, index);
4753
4754 if (index < (int32_t)NUM_ELEMS(s_unsolResponses_v))
4755 pRI = &s_unsolResponses_v[index];
4756 } else {
4757 int index = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
4758 if (index < (int32_t)NUM_ELEMS(s_unsolResponses))
4759 pRI = &s_unsolResponses[index];
4760 }
4761
4762 if (pRI == NULL || pRI->responseFunction == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004763 RLOGE("unsupported unsolicited response code %d", unsolResponse);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004764 return;
4765 }
4766
4767 // Grab a wake lock if needed for this reponse,
4768 // as we exit we'll either release it immediately
4769 // or set a timer to release it later.
Howard Subd82ef12015-04-12 10:25:05 +02004770 switch (pRI->wakeType) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004771 case WAKE_PARTIAL:
4772 grabPartialWakeLock();
4773 shouldScheduleTimeout = true;
4774 break;
4775
4776 case DONT_WAKE:
4777 default:
4778 // No wake lock is grabed so don't set timeout
4779 shouldScheduleTimeout = false;
4780 break;
4781 }
4782
4783 // Mark the time this was received, doing this
4784 // after grabing the wakelock incase getting
4785 // the elapsedRealTime might cause us to goto
4786 // sleep.
4787 if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4788 timeReceived = elapsedRealtime();
4789 }
4790
4791 appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
4792
4793 Parcel p;
4794
4795 p.writeInt32 (RESPONSE_UNSOLICITED);
4796 p.writeInt32 (unsolResponse);
4797
Howard Subd82ef12015-04-12 10:25:05 +02004798 ret = pRI->responseFunction(p, const_cast<void*>(data), datalen);
4799
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004800 if (ret != 0) {
4801 // Problem with the response. Don't continue;
4802 goto error_exit;
4803 }
4804
4805 // some things get more payload
4806 switch(unsolResponse) {
4807 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
Howard Sue32dbfd2015-01-07 15:55:57 +08004808 newState = processRadioState(CALL_ONSTATEREQUEST(soc_id), soc_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004809 p.writeInt32(newState);
4810 appendPrintBuf("%s {%s}", printBuf,
Howard Sue32dbfd2015-01-07 15:55:57 +08004811 radioStateToString(CALL_ONSTATEREQUEST(soc_id)));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004812 break;
4813
4814
4815 case RIL_UNSOL_NITZ_TIME_RECEIVED:
4816 // Store the time that this was received so the
4817 // handler of this message can account for
4818 // the time it takes to arrive and process. In
4819 // particular the system has been known to sleep
4820 // before this message can be processed.
4821 p.writeInt64(timeReceived);
4822 break;
4823 }
4824
Howard Sue32dbfd2015-01-07 15:55:57 +08004825 RLOGI("%s UNSOLICITED: %s length:%d", rilSocketIdToString(soc_id), requestToString(unsolResponse), p.dataSize());
4826 ret = sendResponse(p, soc_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004827 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4828
4829 // Unfortunately, NITZ time is not poll/update like everything
4830 // else in the system. So, if the upstream client isn't connected,
4831 // keep a copy of the last NITZ response (with receive time noted
4832 // above) around so we can deliver it when it is connected
4833
4834 if (s_lastNITZTimeData != NULL) {
4835 free (s_lastNITZTimeData);
4836 s_lastNITZTimeData = NULL;
4837 }
4838
4839 s_lastNITZTimeData = malloc(p.dataSize());
4840 s_lastNITZTimeDataSize = p.dataSize();
4841 memcpy(s_lastNITZTimeData, p.data(), p.dataSize());
4842 }
4843
4844 // For now, we automatically go back to sleep after TIMEVAL_WAKE_TIMEOUT
4845 // FIXME The java code should handshake here to release wake lock
4846
4847 if (shouldScheduleTimeout) {
4848 // Cancel the previous request
4849 if (s_last_wake_timeout_info != NULL) {
4850 s_last_wake_timeout_info->userParam = (void *)1;
4851 }
4852
4853 s_last_wake_timeout_info
4854 = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
4855 &TIMEVAL_WAKE_TIMEOUT);
4856 }
4857
4858 // Normal exit
4859 return;
4860
4861error_exit:
4862 if (shouldScheduleTimeout) {
4863 releaseWakeLock();
4864 }
4865}
4866
4867/** FIXME generalize this if you track UserCAllbackInfo, clear it
4868 when the callback occurs
4869*/
4870static UserCallbackInfo *
4871internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
4872 const struct timeval *relativeTime)
4873{
4874 struct timeval myRelativeTime;
4875 UserCallbackInfo *p_info;
4876
4877 p_info = (UserCallbackInfo *) malloc (sizeof(UserCallbackInfo));
4878
4879 p_info->p_callback = callback;
4880 p_info->userParam = param;
4881
4882 if (relativeTime == NULL) {
4883 /* treat null parameter as a 0 relative time */
4884 memset (&myRelativeTime, 0, sizeof(myRelativeTime));
4885 } else {
4886 /* FIXME I think event_add's tv param is really const anyway */
4887 memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
4888 }
4889
4890 ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
4891
4892 ril_timer_add(&(p_info->event), &myRelativeTime);
4893
4894 triggerEvLoop();
4895 return p_info;
4896}
4897
4898
4899extern "C" void
4900RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
4901 const struct timeval *relativeTime) {
4902 internalRequestTimedCallback (callback, param, relativeTime);
4903}
4904
4905const char *
4906failCauseToString(RIL_Errno e) {
4907 switch(e) {
4908 case RIL_E_SUCCESS: return "E_SUCCESS";
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004909 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RADIO_NOT_AVAILABLE";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004910 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
4911 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
4912 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
4913 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
4914 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
4915 case RIL_E_CANCELLED: return "E_CANCELLED";
4916 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
4917 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
4918 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
4919 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
4920 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
4921#ifdef FEATURE_MULTIMODE_ANDROID
4922 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
4923 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
4924#endif
4925 default: return "<unknown error>";
4926 }
4927}
4928
4929const char *
4930radioStateToString(RIL_RadioState s) {
4931 switch(s) {
4932 case RADIO_STATE_OFF: return "RADIO_OFF";
4933 case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
4934 case RADIO_STATE_SIM_NOT_READY: return "RADIO_SIM_NOT_READY";
4935 case RADIO_STATE_SIM_LOCKED_OR_ABSENT: return "RADIO_SIM_LOCKED_OR_ABSENT";
4936 case RADIO_STATE_SIM_READY: return "RADIO_SIM_READY";
4937 case RADIO_STATE_RUIM_NOT_READY:return"RADIO_RUIM_NOT_READY";
4938 case RADIO_STATE_RUIM_READY:return"RADIO_RUIM_READY";
4939 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:return"RADIO_RUIM_LOCKED_OR_ABSENT";
4940 case RADIO_STATE_NV_NOT_READY:return"RADIO_NV_NOT_READY";
4941 case RADIO_STATE_NV_READY:return"RADIO_NV_READY";
4942 case RADIO_STATE_ON:return"RADIO_ON";
4943 default: return "<unknown state>";
4944 }
4945}
4946
4947const char *
4948callStateToString(RIL_CallState s) {
4949 switch(s) {
4950 case RIL_CALL_ACTIVE : return "ACTIVE";
4951 case RIL_CALL_HOLDING: return "HOLDING";
4952 case RIL_CALL_DIALING: return "DIALING";
4953 case RIL_CALL_ALERTING: return "ALERTING";
4954 case RIL_CALL_INCOMING: return "INCOMING";
4955 case RIL_CALL_WAITING: return "WAITING";
4956 default: return "<unknown state>";
4957 }
4958}
4959
4960const char *
4961requestToString(int request) {
4962/*
4963 cat libs/telephony/ril_commands.h \
4964 | egrep "^ *{RIL_" \
4965 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
4966
4967
4968 cat libs/telephony/ril_unsol_commands.h \
4969 | egrep "^ *{RIL_" \
4970 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
4971
4972*/
4973 switch(request) {
4974 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
4975 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
4976 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
4977 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
4978 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
4979 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
4980 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
4981 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
4982 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
4983 case RIL_REQUEST_DIAL: return "DIAL";
4984 case RIL_REQUEST_DIAL_EMERGENCY: return "DIAL";
4985 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
4986 case RIL_REQUEST_HANGUP: return "HANGUP";
4987 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
4988 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
4989 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
4990 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
4991 case RIL_REQUEST_UDUB: return "UDUB";
4992 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
4993 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
4994 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
4995 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
4996 case RIL_REQUEST_OPERATOR: return "OPERATOR";
4997 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
4998 case RIL_REQUEST_DTMF: return "DTMF";
4999 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
5000 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
5001 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
5002 case RIL_REQUEST_SIM_IO: return "SIM_IO";
5003 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
5004 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
5005 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
5006 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
5007 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
5008 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
5009 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
5010 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
5011 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
5012 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
5013 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
5014 case RIL_REQUEST_ANSWER: return "ANSWER";
5015 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
5016 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
5017 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
5018 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
5019 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
5020 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
5021 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
5022 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";
5023 case RIL_REQUEST_DTMF_START: return "DTMF_START";
5024 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
5025 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
5026 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
5027 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
5028 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
5029 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
5030 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
5031 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
5032 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
5033 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
5034 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
5035 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
5036 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
5037 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
5038 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
5039 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
5040 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
5041 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
5042 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
5043 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
5044 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
5045 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
5046 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
5047 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005048 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE:return"CDMA_SET_SUBSCRIPTION_SOURCE";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005049 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"CDMA_SET_ROAMING_PREFERENCE";
5050 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"CDMA_QUERY_ROAMING_PREFERENCE";
5051 case RIL_REQUEST_SET_TTY_MODE:return"SET_TTY_MODE";
5052 case RIL_REQUEST_QUERY_TTY_MODE:return"QUERY_TTY_MODE";
5053 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
5054 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
5055 case RIL_REQUEST_CDMA_FLASH:return"CDMA_FLASH";
5056 case RIL_REQUEST_CDMA_BURST_DTMF:return"CDMA_BURST_DTMF";
5057 case RIL_REQUEST_CDMA_SEND_SMS:return"CDMA_SEND_SMS";
5058 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:return"CDMA_SMS_ACKNOWLEDGE";
5059 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG:return"GSM_GET_BROADCAST_SMS_CONFIG";
5060 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG:return"GSM_SET_BROADCAST_SMS_CONFIG";
5061 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG:return "CDMA_GET_BROADCAST_SMS_CONFIG";
5062 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG:return "CDMA_SET_BROADCAST_SMS_CONFIG";
5063 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION:return "CDMA_SMS_BROADCAST_ACTIVATION";
Ethan Chend6e30652013-08-04 22:49:56 -07005064 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return"CDMA_VALIDATE_AND_WRITE_AKEY";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005065 case RIL_REQUEST_CDMA_SUBSCRIPTION: return"CDMA_SUBSCRIPTION";
5066 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
5067 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
5068 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
5069 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
5070 case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
5071 case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
5072 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
5073 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
5074 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
5075 case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
5076 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
5077 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
5078 case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005079 case RIL_REQUEST_GET_CELL_INFO_LIST: return"GET_CELL_INFO_LIST";
5080 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return"SET_UNSOL_CELL_INFO_LIST_RATE";
Andrew Jiangca4a9a02014-01-18 18:04:08 -05005081 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "RIL_REQUEST_SET_INITIAL_ATTACH_APN";
5082 case RIL_REQUEST_IMS_REGISTRATION_STATE: return "IMS_REGISTRATION_STATE";
5083 case RIL_REQUEST_IMS_SEND_SMS: return "IMS_SEND_SMS";
Howard Sue32dbfd2015-01-07 15:55:57 +08005084 case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "SIM_TRANSMIT_APDU_BASIC";
5085 case RIL_REQUEST_SIM_OPEN_CHANNEL: return "SIM_OPEN_CHANNEL";
5086 case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "SIM_CLOSE_CHANNEL";
5087 case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "SIM_TRANSMIT_APDU_CHANNEL";
Howard Subd82ef12015-04-12 10:25:05 +02005088 case RIL_REQUEST_GET_RADIO_CAPABILITY: return "RIL_REQUEST_GET_RADIO_CAPABILITY";
5089 case RIL_REQUEST_SET_RADIO_CAPABILITY: return "RIL_REQUEST_SET_RADIO_CAPABILITY";
Howard Sue32dbfd2015-01-07 15:55:57 +08005090 case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "SET_UICC_SUBSCRIPTION";
5091 case RIL_REQUEST_ALLOW_DATA: return "ALLOW_DATA";
5092 case RIL_REQUEST_GET_HARDWARE_CONFIG: return "GET_HARDWARE_CONFIG";
5093 case RIL_REQUEST_SIM_AUTHENTICATION: return "SIM_AUTHENTICATION";
5094 case RIL_REQUEST_GET_DC_RT_INFO: return "GET_DC_RT_INFO";
5095 case RIL_REQUEST_SET_DC_RT_INFO_RATE: return "SET_DC_RT_INFO_RATE";
5096 case RIL_REQUEST_SET_DATA_PROFILE: return "SET_DATA_PROFILE";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005097 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
5098 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
5099 case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED";
5100 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
5101 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
5102 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
5103 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
5104 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)";
5105 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
5106 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
Howard Subd82ef12015-04-12 10:25:05 +02005107 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
5108 case RIL_UNSOL_SUPP_SVC_NOTIFICATION: return "UNSOL_SUPP_SVC_NOTIFICATION";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005109 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
5110 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
5111 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
5112 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
5113 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL";
5114 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005115 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
5116 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
5117 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_NEW_CDMA_SMS";
5118 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_NEW_BROADCAST_SMS";
5119 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
5120 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
5121 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
5122 case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
5123 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
5124 case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
5125 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
5126 case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
5127 case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
5128 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
5129 case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
5130 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
5131 case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
5132 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
Ethan Chend6e30652013-08-04 22:49:56 -07005133 case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
Andrew Jiangca4a9a02014-01-18 18:04:08 -05005134 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "RESPONSE_IMS_NETWORK_STATE_CHANGED";
Howard Sue32dbfd2015-01-07 15:55:57 +08005135 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return "UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED";
5136 case RIL_UNSOL_SRVCC_STATE_NOTIFY: return "UNSOL_SRVCC_STATE_NOTIFY";
5137 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return "HARDWARE_CONFIG_CHANGED";
5138 case RIL_UNSOL_DC_RT_INFO_CHANGED: return "UNSOL_DC_RT_INFO_CHANGED";
Howard Subd82ef12015-04-12 10:25:05 +02005139 case RIL_UNSOL_RADIO_CAPABILITY: return "UNSOL_RADIO_CAPABILITY";
5140 case RIL_UNSOL_ON_SS: return "UNSOL_ON_SS";
5141 case RIL_UNSOL_STK_CC_ALPHA_NOTIFY: return "UNSOL_STK_CC_ALPHA_NOTIFY";
Howard Sue32dbfd2015-01-07 15:55:57 +08005142 case RIL_REQUEST_SHUTDOWN: return "SHUTDOWN";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005143 default: return "<unknown request>";
5144 }
5145}
5146
Howard Sue32dbfd2015-01-07 15:55:57 +08005147const char *
5148rilSocketIdToString(RIL_SOCKET_ID socket_id)
5149{
5150 switch(socket_id) {
5151 case RIL_SOCKET_1:
5152 return "RIL_SOCKET_1";
5153#if (SIM_COUNT >= 2)
5154 case RIL_SOCKET_2:
5155 return "RIL_SOCKET_2";
5156#endif
5157#if (SIM_COUNT >= 3)
5158 case RIL_SOCKET_3:
5159 return "RIL_SOCKET_3";
5160#endif
5161#if (SIM_COUNT >= 4)
5162 case RIL_SOCKET_4:
5163 return "RIL_SOCKET_4";
5164#endif
5165 default:
5166 return "not a valid RIL";
5167 }
5168}
5169
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005170} /* namespace android */