blob: 44e6b86846abf98ed443ef7516c2712b5ff838a1 [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 gsmSignalStrength = p_cur->GW_SignalStrength.signalStrength & 0xFF;
Utkarsh Gupta8ede9fa2015-04-23 13:21:49 +05302983
2984#ifdef MODEM_TYPE_XMM6260
2985 if (gsmSignalStrength < 0 ||
2986 (gsmSignalStrength > 31 && p_cur->GW_SignalStrength.signalStrength != 99)) {
2987 gsmSignalStrength = p_cur->CDMA_SignalStrength.dbm;
2988 }
2989#else
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05302990 if (gsmSignalStrength < 0) {
2991 gsmSignalStrength = 99;
2992 } else if (gsmSignalStrength > 31 && gsmSignalStrength != 99) {
2993 gsmSignalStrength = 31;
2994 }
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05302995#endif
2996 p.writeInt32(gsmSignalStrength);
2997
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002998 p.writeInt32(p_cur->GW_SignalStrength.bitErrorRate);
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05302999
3000#if defined(MODEM_TYPE_XMM6262) || defined(MODEM_TYPE_XMM7260)
3001 cdmaDbm = p_cur->CDMA_SignalStrength.dbm & 0xFF;
3002 if (cdmaDbm < 0) {
3003 cdmaDbm = 99;
3004 } else if (cdmaDbm > 31 && cdmaDbm != 99) {
3005 cdmaDbm = 31;
3006 }
3007#else
Caio Schnepperec042542015-04-14 08:03:43 -03003008 cdmaDbm = p_cur->CDMA_SignalStrength.dbm;
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303009#endif
3010 p.writeInt32(cdmaDbm);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003011 p.writeInt32(p_cur->CDMA_SignalStrength.ecio);
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303012
3013#if defined(MODEM_TYPE_XMM6262) || defined(MODEM_TYPE_XMM7260)
3014 evdoDbm = p_cur->EVDO_SignalStrength.dbm & 0xFF;
3015 if (evdoDbm < 0) {
3016 evdoDbm = 99;
3017 } else if (evdoDbm > 31 && evdoDbm != 99) {
3018 evdoDbm = 31;
3019 }
3020#else
3021 evdoDbm = p_cur->EVDO_SignalStrength.dbm;
3022#endif
3023 p.writeInt32(evdoDbm);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003024 p.writeInt32(p_cur->EVDO_SignalStrength.ecio);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003025 p.writeInt32(p_cur->EVDO_SignalStrength.signalNoiseRatio);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003026 if (responselen >= sizeof (RIL_SignalStrength_v6)) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003027 /*
Ethan Chend6e30652013-08-04 22:49:56 -07003028 * Fixup LTE for backwards compatibility
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003029 */
Ethan Chend6e30652013-08-04 22:49:56 -07003030 if (s_callbacks.version <= 6) {
3031 // signalStrength: -1 -> 99
3032 if (p_cur->LTE_SignalStrength.signalStrength == -1) {
3033 p_cur->LTE_SignalStrength.signalStrength = 99;
3034 }
3035 // rsrp: -1 -> INT_MAX all other negative value to positive.
3036 // So remap here
3037 if (p_cur->LTE_SignalStrength.rsrp == -1) {
3038 p_cur->LTE_SignalStrength.rsrp = INT_MAX;
3039 } else if (p_cur->LTE_SignalStrength.rsrp < -1) {
3040 p_cur->LTE_SignalStrength.rsrp = -p_cur->LTE_SignalStrength.rsrp;
3041 }
3042 // rsrq: -1 -> INT_MAX
3043 if (p_cur->LTE_SignalStrength.rsrq == -1) {
3044 p_cur->LTE_SignalStrength.rsrq = INT_MAX;
3045 }
3046 // Not remapping rssnr is already using INT_MAX
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003047
Ethan Chend6e30652013-08-04 22:49:56 -07003048 // cqi: -1 -> INT_MAX
3049 if (p_cur->LTE_SignalStrength.cqi == -1) {
3050 p_cur->LTE_SignalStrength.cqi = INT_MAX;
3051 }
3052 }
3053 p.writeInt32(p_cur->LTE_SignalStrength.signalStrength);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003054 p.writeInt32(p_cur->LTE_SignalStrength.rsrp);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003055 p.writeInt32(p_cur->LTE_SignalStrength.rsrq);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003056 p.writeInt32(p_cur->LTE_SignalStrength.rssnr);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003057 p.writeInt32(p_cur->LTE_SignalStrength.cqi);
Howard Sue32dbfd2015-01-07 15:55:57 +08003058 if (responselen >= sizeof (RIL_SignalStrength_v10)) {
3059 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
3060 } else {
3061 p.writeInt32(INT_MAX);
3062 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003063 } else {
Ethan Chend6e30652013-08-04 22:49:56 -07003064 p.writeInt32(99);
3065 p.writeInt32(INT_MAX);
3066 p.writeInt32(INT_MAX);
3067 p.writeInt32(INT_MAX);
3068 p.writeInt32(INT_MAX);
Howard Sue32dbfd2015-01-07 15:55:57 +08003069 p.writeInt32(INT_MAX);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003070 }
3071
3072 startResponse;
3073 appendPrintBuf("%s[signalStrength=%d,bitErrorRate=%d,\
3074 CDMA_SS.dbm=%d,CDMA_SSecio=%d,\
3075 EVDO_SS.dbm=%d,EVDO_SS.ecio=%d,\
3076 EVDO_SS.signalNoiseRatio=%d,\
3077 LTE_SS.signalStrength=%d,LTE_SS.rsrp=%d,LTE_SS.rsrq=%d,\
Howard Sue32dbfd2015-01-07 15:55:57 +08003078 LTE_SS.rssnr=%d,LTE_SS.cqi=%d,TDSCDMA_SS.rscp=%d]",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003079 printBuf,
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303080 gsmSignalStrength,
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003081 p_cur->GW_SignalStrength.bitErrorRate,
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303082 cdmaDbm,
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003083 p_cur->CDMA_SignalStrength.ecio,
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303084 evdoDbm,
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003085 p_cur->EVDO_SignalStrength.ecio,
3086 p_cur->EVDO_SignalStrength.signalNoiseRatio,
3087 p_cur->LTE_SignalStrength.signalStrength,
3088 p_cur->LTE_SignalStrength.rsrp,
3089 p_cur->LTE_SignalStrength.rsrq,
3090 p_cur->LTE_SignalStrength.rssnr,
Howard Sue32dbfd2015-01-07 15:55:57 +08003091 p_cur->LTE_SignalStrength.cqi,
3092 p_cur->TD_SCDMA_SignalStrength.rscp);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003093 closeResponse;
3094
3095 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003096 RLOGE("invalid response length");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003097 return RIL_ERRNO_INVALID_RESPONSE;
3098 }
3099
3100 return 0;
3101}
3102
3103static int responseCallRing(Parcel &p, void *response, size_t responselen) {
3104 if ((response == NULL) || (responselen == 0)) {
3105 return responseVoid(p, response, responselen);
3106 } else {
3107 return responseCdmaSignalInfoRecord(p, response, responselen);
3108 }
3109}
3110
3111static int responseCdmaSignalInfoRecord(Parcel &p, void *response, size_t responselen) {
3112 if (response == NULL || responselen == 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003113 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003114 return RIL_ERRNO_INVALID_RESPONSE;
3115 }
3116
3117 if (responselen != sizeof (RIL_CDMA_SignalInfoRecord)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003118 RLOGE("invalid response length %d expected sizeof (RIL_CDMA_SignalInfoRecord) of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003119 (int)responselen, (int)sizeof (RIL_CDMA_SignalInfoRecord));
3120 return RIL_ERRNO_INVALID_RESPONSE;
3121 }
3122
3123 startResponse;
3124
3125 RIL_CDMA_SignalInfoRecord *p_cur = ((RIL_CDMA_SignalInfoRecord *) response);
3126 marshallSignalInfoRecord(p, *p_cur);
3127
3128 appendPrintBuf("%s[isPresent=%d,signalType=%d,alertPitch=%d\
3129 signal=%d]",
3130 printBuf,
3131 p_cur->isPresent,
3132 p_cur->signalType,
3133 p_cur->alertPitch,
3134 p_cur->signal);
3135
3136 closeResponse;
3137 return 0;
3138}
3139
3140static int responseCdmaCallWaiting(Parcel &p, void *response,
3141 size_t responselen) {
3142 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003143 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003144 return RIL_ERRNO_INVALID_RESPONSE;
3145 }
3146
3147 if (responselen < sizeof(RIL_CDMA_CallWaiting_v6)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003148 RLOGW("Upgrade to ril version %d\n", RIL_VERSION);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003149 }
3150
3151 RIL_CDMA_CallWaiting_v6 *p_cur = ((RIL_CDMA_CallWaiting_v6 *) response);
3152
3153 writeStringToParcel(p, p_cur->number);
3154 p.writeInt32(p_cur->numberPresentation);
3155 writeStringToParcel(p, p_cur->name);
3156 marshallSignalInfoRecord(p, p_cur->signalInfoRecord);
3157
3158 if (responselen >= sizeof(RIL_CDMA_CallWaiting_v6)) {
3159 p.writeInt32(p_cur->number_type);
3160 p.writeInt32(p_cur->number_plan);
3161 } else {
3162 p.writeInt32(0);
3163 p.writeInt32(0);
3164 }
3165
3166 startResponse;
3167 appendPrintBuf("%snumber=%s,numberPresentation=%d, name=%s,\
3168 signalInfoRecord[isPresent=%d,signalType=%d,alertPitch=%d\
3169 signal=%d,number_type=%d,number_plan=%d]",
3170 printBuf,
3171 p_cur->number,
3172 p_cur->numberPresentation,
3173 p_cur->name,
3174 p_cur->signalInfoRecord.isPresent,
3175 p_cur->signalInfoRecord.signalType,
3176 p_cur->signalInfoRecord.alertPitch,
3177 p_cur->signalInfoRecord.signal,
3178 p_cur->number_type,
3179 p_cur->number_plan);
3180 closeResponse;
3181
3182 return 0;
3183}
3184
3185static int responseSimRefresh(Parcel &p, void *response, size_t responselen) {
3186 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003187 RLOGE("responseSimRefresh: invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003188 return RIL_ERRNO_INVALID_RESPONSE;
3189 }
3190
3191 startResponse;
3192 if (s_callbacks.version == 7) {
3193 RIL_SimRefreshResponse_v7 *p_cur = ((RIL_SimRefreshResponse_v7 *) response);
3194 p.writeInt32(p_cur->result);
3195 p.writeInt32(p_cur->ef_id);
3196 writeStringToParcel(p, p_cur->aid);
3197
3198 appendPrintBuf("%sresult=%d, ef_id=%d, aid=%s",
3199 printBuf,
3200 p_cur->result,
3201 p_cur->ef_id,
3202 p_cur->aid);
3203 } else {
3204 int *p_cur = ((int *) response);
3205 p.writeInt32(p_cur[0]);
3206 p.writeInt32(p_cur[1]);
3207 writeStringToParcel(p, NULL);
3208
3209 appendPrintBuf("%sresult=%d, ef_id=%d",
3210 printBuf,
3211 p_cur[0],
3212 p_cur[1]);
3213 }
3214 closeResponse;
3215
3216 return 0;
3217}
3218
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003219static int responseCellInfoList(Parcel &p, void *response, size_t responselen)
3220{
3221 if (response == NULL && responselen != 0) {
3222 RLOGE("invalid response: NULL");
3223 return RIL_ERRNO_INVALID_RESPONSE;
3224 }
3225
3226 if (responselen % sizeof(RIL_CellInfo) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08003227 RLOGE("responseCellInfoList: invalid response length %d expected multiple of %d",
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003228 (int)responselen, (int)sizeof(RIL_CellInfo));
3229 return RIL_ERRNO_INVALID_RESPONSE;
3230 }
3231
3232 int num = responselen / sizeof(RIL_CellInfo);
3233 p.writeInt32(num);
3234
3235 RIL_CellInfo *p_cur = (RIL_CellInfo *) response;
3236 startResponse;
3237 int i;
3238 for (i = 0; i < num; i++) {
3239 appendPrintBuf("%s[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", printBuf, i,
3240 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
3241 p.writeInt32((int)p_cur->cellInfoType);
3242 p.writeInt32(p_cur->registered);
3243 p.writeInt32(p_cur->timeStampType);
3244 p.writeInt64(p_cur->timeStamp);
3245 switch(p_cur->cellInfoType) {
3246 case RIL_CELL_INFO_TYPE_GSM: {
3247 appendPrintBuf("%s GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,", printBuf,
3248 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
3249 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
3250 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
3251 p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3252 appendPrintBuf("%s gsmSS: ss=%d,ber=%d],", printBuf,
3253 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
3254 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3255
3256 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
3257 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
3258 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
3259 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3260 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
3261 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3262 break;
3263 }
3264 case RIL_CELL_INFO_TYPE_WCDMA: {
3265 appendPrintBuf("%s WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,", printBuf,
3266 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
3267 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
3268 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
3269 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
3270 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3271 appendPrintBuf("%s wcdmaSS: ss=%d,ber=%d],", printBuf,
3272 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
3273 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3274
3275 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
3276 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
3277 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
3278 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
3279 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3280 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
3281 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3282 break;
3283 }
3284 case RIL_CELL_INFO_TYPE_CDMA: {
3285 appendPrintBuf("%s CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d", printBuf,
3286 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
3287 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
3288 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
3289 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
3290 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3291
3292 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
3293 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
3294 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
3295 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
3296 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3297
3298 appendPrintBuf("%s cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d", printBuf,
3299 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
3300 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
3301 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
3302 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
3303 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3304
3305 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
3306 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
3307 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
3308 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
3309 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3310 break;
3311 }
3312 case RIL_CELL_INFO_TYPE_LTE: {
3313 appendPrintBuf("%s LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d", printBuf,
3314 p_cur->CellInfo.lte.cellIdentityLte.mcc,
3315 p_cur->CellInfo.lte.cellIdentityLte.mnc,
3316 p_cur->CellInfo.lte.cellIdentityLte.ci,
3317 p_cur->CellInfo.lte.cellIdentityLte.pci,
3318 p_cur->CellInfo.lte.cellIdentityLte.tac);
3319
3320 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
3321 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
3322 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
3323 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
3324 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
3325
3326 appendPrintBuf("%s lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d", printBuf,
3327 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
3328 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
3329 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
3330 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
3331 p_cur->CellInfo.lte.signalStrengthLte.cqi,
3332 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3333 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
3334 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
3335 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
3336 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
3337 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
3338 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3339 break;
3340 }
Howard Sue32dbfd2015-01-07 15:55:57 +08003341 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
3342 appendPrintBuf("%s TDSCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,cpid=%d,", printBuf,
3343 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc,
3344 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc,
3345 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac,
3346 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid,
3347 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3348 appendPrintBuf("%s tdscdmaSS: rscp=%d],", printBuf,
3349 p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3350
3351 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
3352 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
3353 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
3354 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
3355 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3356 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3357 break;
3358 }
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003359 }
3360 p_cur += 1;
3361 }
3362 removeLastChar;
3363 closeResponse;
3364
3365 return 0;
3366}
3367
Howard Sue32dbfd2015-01-07 15:55:57 +08003368static int responseHardwareConfig(Parcel &p, void *response, size_t responselen)
3369{
3370 if (response == NULL && responselen != 0) {
3371 RLOGE("invalid response: NULL");
3372 return RIL_ERRNO_INVALID_RESPONSE;
3373 }
3374
3375 if (responselen % sizeof(RIL_HardwareConfig) != 0) {
3376 RLOGE("responseHardwareConfig: invalid response length %d expected multiple of %d",
3377 (int)responselen, (int)sizeof(RIL_HardwareConfig));
3378 return RIL_ERRNO_INVALID_RESPONSE;
3379 }
3380
3381 int num = responselen / sizeof(RIL_HardwareConfig);
3382 int i;
3383 RIL_HardwareConfig *p_cur = (RIL_HardwareConfig *) response;
3384
3385 p.writeInt32(num);
3386
3387 startResponse;
3388 for (i = 0; i < num; i++) {
3389 switch (p_cur[i].type) {
3390 case RIL_HARDWARE_CONFIG_MODEM: {
3391 writeStringToParcel(p, p_cur[i].uuid);
3392 p.writeInt32((int)p_cur[i].state);
3393 p.writeInt32(p_cur[i].cfg.modem.rat);
3394 p.writeInt32(p_cur[i].cfg.modem.maxVoice);
3395 p.writeInt32(p_cur[i].cfg.modem.maxData);
3396 p.writeInt32(p_cur[i].cfg.modem.maxStandby);
3397
3398 appendPrintBuf("%s modem: uuid=%s,state=%d,rat=%08x,maxV=%d,maxD=%d,maxS=%d", printBuf,
3399 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.modem.rat,
3400 p_cur[i].cfg.modem.maxVoice, p_cur[i].cfg.modem.maxData, p_cur[i].cfg.modem.maxStandby);
3401 break;
3402 }
3403 case RIL_HARDWARE_CONFIG_SIM: {
3404 writeStringToParcel(p, p_cur[i].uuid);
3405 p.writeInt32((int)p_cur[i].state);
3406 writeStringToParcel(p, p_cur[i].cfg.sim.modemUuid);
3407
3408 appendPrintBuf("%s sim: uuid=%s,state=%d,modem-uuid=%s", printBuf,
3409 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.sim.modemUuid);
3410 break;
3411 }
3412 }
3413 }
3414 removeLastChar;
3415 closeResponse;
3416 return 0;
3417}
3418
Howard Subd82ef12015-04-12 10:25:05 +02003419static int responseRadioCapability(Parcel &p, void *response, size_t responselen) {
3420 if (response == NULL) {
3421 RLOGE("invalid response: NULL");
3422 return RIL_ERRNO_INVALID_RESPONSE;
3423 }
3424
3425 if (responselen != sizeof (RIL_RadioCapability) ) {
3426 RLOGE("invalid response length was %d expected %d",
3427 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3428 return RIL_ERRNO_INVALID_RESPONSE;
3429 }
3430
3431 RIL_RadioCapability *p_cur = (RIL_RadioCapability *) response;
3432 p.writeInt32(p_cur->version);
3433 p.writeInt32(p_cur->session);
3434 p.writeInt32(p_cur->phase);
3435 p.writeInt32(p_cur->rat);
3436 writeStringToParcel(p, p_cur->logicalModemUuid);
3437 p.writeInt32(p_cur->status);
3438
3439 startResponse;
3440 appendPrintBuf("%s[version=%d,session=%d,phase=%d,\
3441 rat=%s,logicalModemUuid=%s,status=%d]",
3442 printBuf,
3443 p_cur->version,
3444 p_cur->session,
3445 p_cur->phase,
3446 p_cur->rat,
3447 p_cur->logicalModemUuid,
3448 p_cur->status);
3449 closeResponse;
3450 return 0;
3451}
3452
3453static int responseSSData(Parcel &p, void *response, size_t responselen) {
3454 RLOGD("In responseSSData");
3455 int num;
3456
3457 if (response == NULL && responselen != 0) {
3458 RLOGE("invalid response length was %d expected %d",
3459 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3460 return RIL_ERRNO_INVALID_RESPONSE;
3461 }
3462
3463 if (responselen != sizeof(RIL_StkCcUnsolSsResponse)) {
3464 RLOGE("invalid response length %d, expected %d",
3465 (int)responselen, (int)sizeof(RIL_StkCcUnsolSsResponse));
3466 return RIL_ERRNO_INVALID_RESPONSE;
3467 }
3468
3469 startResponse;
3470 RIL_StkCcUnsolSsResponse *p_cur = (RIL_StkCcUnsolSsResponse *) response;
3471 p.writeInt32(p_cur->serviceType);
3472 p.writeInt32(p_cur->requestType);
3473 p.writeInt32(p_cur->teleserviceType);
3474 p.writeInt32(p_cur->serviceClass);
3475 p.writeInt32(p_cur->result);
3476
3477 if (isServiceTypeCfQuery(p_cur->serviceType, p_cur->requestType)) {
3478 RLOGD("responseSSData CF type, num of Cf elements %d", p_cur->cfData.numValidIndexes);
3479 if (p_cur->cfData.numValidIndexes > NUM_SERVICE_CLASSES) {
3480 RLOGE("numValidIndexes is greater than max value %d, "
3481 "truncating it to max value", NUM_SERVICE_CLASSES);
3482 p_cur->cfData.numValidIndexes = NUM_SERVICE_CLASSES;
3483 }
3484 /* number of call info's */
3485 p.writeInt32(p_cur->cfData.numValidIndexes);
3486
3487 for (int i = 0; i < p_cur->cfData.numValidIndexes; i++) {
3488 RIL_CallForwardInfo cf = p_cur->cfData.cfInfo[i];
3489
3490 p.writeInt32(cf.status);
3491 p.writeInt32(cf.reason);
3492 p.writeInt32(cf.serviceClass);
3493 p.writeInt32(cf.toa);
3494 writeStringToParcel(p, cf.number);
3495 p.writeInt32(cf.timeSeconds);
3496 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
3497 (cf.status==1)?"enable":"disable", cf.reason, cf.serviceClass, cf.toa,
3498 (char*)cf.number, cf.timeSeconds);
3499 RLOGD("Data: %d,reason=%d,cls=%d,toa=%d,num=%s,tout=%d],", cf.status,
3500 cf.reason, cf.serviceClass, cf.toa, (char*)cf.number, cf.timeSeconds);
3501 }
3502 } else {
3503 p.writeInt32 (SS_INFO_MAX);
3504
3505 /* each int*/
3506 for (int i = 0; i < SS_INFO_MAX; i++) {
3507 appendPrintBuf("%s%d,", printBuf, p_cur->ssInfo[i]);
3508 RLOGD("Data: %d",p_cur->ssInfo[i]);
3509 p.writeInt32(p_cur->ssInfo[i]);
3510 }
3511 }
3512 removeLastChar;
3513 closeResponse;
3514
3515 return 0;
3516}
3517
3518static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType) {
3519 if ((reqType == SS_INTERROGATION) &&
3520 (serType == SS_CFU ||
3521 serType == SS_CF_BUSY ||
3522 serType == SS_CF_NO_REPLY ||
3523 serType == SS_CF_NOT_REACHABLE ||
3524 serType == SS_CF_ALL ||
3525 serType == SS_CF_ALL_CONDITIONAL)) {
3526 return true;
3527 }
3528 return false;
3529}
3530
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003531static void triggerEvLoop() {
3532 int ret;
3533 if (!pthread_equal(pthread_self(), s_tid_dispatch)) {
3534 /* trigger event loop to wakeup. No reason to do this,
3535 * if we're in the event loop thread */
3536 do {
3537 ret = write (s_fdWakeupWrite, " ", 1);
3538 } while (ret < 0 && errno == EINTR);
3539 }
3540}
3541
3542static void rilEventAddWakeup(struct ril_event *ev) {
3543 ril_event_add(ev);
3544 triggerEvLoop();
3545}
3546
3547static void sendSimStatusAppInfo(Parcel &p, int num_apps, RIL_AppStatus appStatus[]) {
3548 p.writeInt32(num_apps);
3549 startResponse;
3550 for (int i = 0; i < num_apps; i++) {
3551 p.writeInt32(appStatus[i].app_type);
3552 p.writeInt32(appStatus[i].app_state);
3553 p.writeInt32(appStatus[i].perso_substate);
3554 writeStringToParcel(p, (const char*)(appStatus[i].aid_ptr));
3555 writeStringToParcel(p, (const char*)
3556 (appStatus[i].app_label_ptr));
3557 p.writeInt32(appStatus[i].pin1_replaced);
3558 p.writeInt32(appStatus[i].pin1);
3559 p.writeInt32(appStatus[i].pin2);
3560 appendPrintBuf("%s[app_type=%d,app_state=%d,perso_substate=%d,\
3561 aid_ptr=%s,app_label_ptr=%s,pin1_replaced=%d,pin1=%d,pin2=%d],",
3562 printBuf,
3563 appStatus[i].app_type,
3564 appStatus[i].app_state,
3565 appStatus[i].perso_substate,
3566 appStatus[i].aid_ptr,
3567 appStatus[i].app_label_ptr,
3568 appStatus[i].pin1_replaced,
3569 appStatus[i].pin1,
3570 appStatus[i].pin2);
3571 }
3572 closeResponse;
3573}
3574
3575static int responseSimStatus(Parcel &p, void *response, size_t responselen) {
Howard Sue32dbfd2015-01-07 15:55:57 +08003576 int i;
3577
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003578 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003579 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003580 return RIL_ERRNO_INVALID_RESPONSE;
3581 }
3582
3583 if (responselen == sizeof (RIL_CardStatus_v6)) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003584 RIL_CardStatus_v6 *p_cur = ((RIL_CardStatus_v6 *) response);
3585
3586 p.writeInt32(p_cur->card_state);
3587 p.writeInt32(p_cur->universal_pin_state);
3588 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3589 p.writeInt32(p_cur->cdma_subscription_app_index);
3590 p.writeInt32(p_cur->ims_subscription_app_index);
3591
3592 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
3593 } else if (responselen == sizeof (RIL_CardStatus_v5)) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003594 RIL_CardStatus_v5 *p_cur = ((RIL_CardStatus_v5 *) response);
3595
3596 p.writeInt32(p_cur->card_state);
3597 p.writeInt32(p_cur->universal_pin_state);
3598 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3599 p.writeInt32(p_cur->cdma_subscription_app_index);
3600 p.writeInt32(-1);
3601
3602 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
3603 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003604 RLOGE("responseSimStatus: A RilCardStatus_v6 or _v5 expected\n");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003605 return RIL_ERRNO_INVALID_RESPONSE;
3606 }
3607
3608 return 0;
3609}
3610
3611static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3612 int num = responselen / sizeof(RIL_GSM_BroadcastSmsConfigInfo *);
3613 p.writeInt32(num);
3614
3615 startResponse;
3616 RIL_GSM_BroadcastSmsConfigInfo **p_cur =
3617 (RIL_GSM_BroadcastSmsConfigInfo **) response;
3618 for (int i = 0; i < num; i++) {
3619 p.writeInt32(p_cur[i]->fromServiceId);
3620 p.writeInt32(p_cur[i]->toServiceId);
3621 p.writeInt32(p_cur[i]->fromCodeScheme);
3622 p.writeInt32(p_cur[i]->toCodeScheme);
3623 p.writeInt32(p_cur[i]->selected);
3624
3625 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId=%d, \
3626 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]",
3627 printBuf, i, p_cur[i]->fromServiceId, p_cur[i]->toServiceId,
3628 p_cur[i]->fromCodeScheme, p_cur[i]->toCodeScheme,
3629 p_cur[i]->selected);
3630 }
3631 closeResponse;
3632
3633 return 0;
3634}
3635
3636static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3637 RIL_CDMA_BroadcastSmsConfigInfo **p_cur =
3638 (RIL_CDMA_BroadcastSmsConfigInfo **) response;
3639
3640 int num = responselen / sizeof (RIL_CDMA_BroadcastSmsConfigInfo *);
3641 p.writeInt32(num);
3642
3643 startResponse;
3644 for (int i = 0 ; i < num ; i++ ) {
3645 p.writeInt32(p_cur[i]->service_category);
3646 p.writeInt32(p_cur[i]->language);
3647 p.writeInt32(p_cur[i]->selected);
3648
3649 appendPrintBuf("%s [%d: srvice_category=%d, language =%d, \
3650 selected =%d], ",
3651 printBuf, i, p_cur[i]->service_category, p_cur[i]->language,
3652 p_cur[i]->selected);
3653 }
3654 closeResponse;
3655
3656 return 0;
3657}
3658
3659static int responseCdmaSms(Parcel &p, void *response, size_t responselen) {
3660 int num;
3661 int digitCount;
3662 int digitLimit;
3663 uint8_t uct;
3664 void* dest;
3665
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003666 RLOGD("Inside responseCdmaSms");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003667
3668 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003669 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003670 return RIL_ERRNO_INVALID_RESPONSE;
3671 }
3672
3673 if (responselen != sizeof(RIL_CDMA_SMS_Message)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003674 RLOGE("invalid response length was %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003675 (int)responselen, (int)sizeof(RIL_CDMA_SMS_Message));
3676 return RIL_ERRNO_INVALID_RESPONSE;
3677 }
3678
3679 RIL_CDMA_SMS_Message *p_cur = (RIL_CDMA_SMS_Message *) response;
3680 p.writeInt32(p_cur->uTeleserviceID);
3681 p.write(&(p_cur->bIsServicePresent),sizeof(uct));
3682 p.writeInt32(p_cur->uServicecategory);
3683 p.writeInt32(p_cur->sAddress.digit_mode);
3684 p.writeInt32(p_cur->sAddress.number_mode);
3685 p.writeInt32(p_cur->sAddress.number_type);
3686 p.writeInt32(p_cur->sAddress.number_plan);
3687 p.write(&(p_cur->sAddress.number_of_digits), sizeof(uct));
3688 digitLimit= MIN((p_cur->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
3689 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3690 p.write(&(p_cur->sAddress.digits[digitCount]),sizeof(uct));
3691 }
3692
3693 p.writeInt32(p_cur->sSubAddress.subaddressType);
3694 p.write(&(p_cur->sSubAddress.odd),sizeof(uct));
3695 p.write(&(p_cur->sSubAddress.number_of_digits),sizeof(uct));
3696 digitLimit= MIN((p_cur->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
3697 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3698 p.write(&(p_cur->sSubAddress.digits[digitCount]),sizeof(uct));
3699 }
3700
3701 digitLimit= MIN((p_cur->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
3702 p.writeInt32(p_cur->uBearerDataLen);
3703 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3704 p.write(&(p_cur->aBearerData[digitCount]), sizeof(uct));
3705 }
3706
3707 startResponse;
3708 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
3709 sAddress.digit_mode=%d, sAddress.number_mode=%d, sAddress.number_type=%d, ",
3710 printBuf, p_cur->uTeleserviceID,p_cur->bIsServicePresent,p_cur->uServicecategory,
3711 p_cur->sAddress.digit_mode, p_cur->sAddress.number_mode,p_cur->sAddress.number_type);
3712 closeResponse;
3713
3714 return 0;
3715}
3716
Howard Sue32dbfd2015-01-07 15:55:57 +08003717static int responseDcRtInfo(Parcel &p, void *response, size_t responselen)
3718{
3719 int num = responselen / sizeof(RIL_DcRtInfo);
3720 if ((responselen % sizeof(RIL_DcRtInfo) != 0) || (num != 1)) {
3721 RLOGE("responseDcRtInfo: invalid response length %d expected multiple of %d",
3722 (int)responselen, (int)sizeof(RIL_DcRtInfo));
3723 return RIL_ERRNO_INVALID_RESPONSE;
3724 }
3725
3726 startResponse;
3727 RIL_DcRtInfo *pDcRtInfo = (RIL_DcRtInfo *)response;
3728 p.writeInt64(pDcRtInfo->time);
3729 p.writeInt32(pDcRtInfo->powerState);
3730 appendPrintBuf("%s[time=%d,powerState=%d]", printBuf,
3731 pDcRtInfo->time,
3732 pDcRtInfo->powerState);
3733 closeResponse;
3734
3735 return 0;
3736}
3737
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003738/**
3739 * A write on the wakeup fd is done just to pop us out of select()
3740 * We empty the buffer here and then ril_event will reset the timers on the
3741 * way back down
3742 */
3743static void processWakeupCallback(int fd, short flags, void *param) {
3744 char buff[16];
3745 int ret;
3746
Ethan Chend6e30652013-08-04 22:49:56 -07003747 RLOGV("processWakeupCallback");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003748
3749 /* empty our wakeup socket out */
3750 do {
3751 ret = read(s_fdWakeupRead, &buff, sizeof(buff));
3752 } while (ret > 0 || (ret < 0 && errno == EINTR));
3753}
3754
Howard Sue32dbfd2015-01-07 15:55:57 +08003755static void onCommandsSocketClosed(RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003756 int ret;
3757 RequestInfo *p_cur;
Howard Sue32dbfd2015-01-07 15:55:57 +08003758 /* Hook for current context
3759 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
3760 pthread_mutex_t * pendingRequestsMutexHook = &s_pendingRequestsMutex;
3761 /* pendingRequestsHook refer to &s_pendingRequests */
3762 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003763
Howard Sue32dbfd2015-01-07 15:55:57 +08003764#if (SIM_COUNT >= 2)
3765 if (socket_id == RIL_SOCKET_2) {
3766 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
3767 pendingRequestsHook = &s_pendingRequests_socket2;
3768 }
3769#if (SIM_COUNT >= 3)
3770 else if (socket_id == RIL_SOCKET_3) {
3771 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
3772 pendingRequestsHook = &s_pendingRequests_socket3;
3773 }
3774#endif
3775#if (SIM_COUNT >= 4)
3776 else if (socket_id == RIL_SOCKET_4) {
3777 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
3778 pendingRequestsHook = &s_pendingRequests_socket4;
3779 }
3780#endif
3781#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003782 /* mark pending requests as "cancelled" so we dont report responses */
Howard Sue32dbfd2015-01-07 15:55:57 +08003783 ret = pthread_mutex_lock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003784 assert (ret == 0);
3785
Howard Sue32dbfd2015-01-07 15:55:57 +08003786 p_cur = *pendingRequestsHook;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003787
Howard Sue32dbfd2015-01-07 15:55:57 +08003788 for (p_cur = *pendingRequestsHook
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003789 ; p_cur != NULL
3790 ; p_cur = p_cur->p_next
3791 ) {
3792 p_cur->cancelled = 1;
3793 }
3794
Howard Sue32dbfd2015-01-07 15:55:57 +08003795 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003796 assert (ret == 0);
3797}
3798
3799static void processCommandsCallback(int fd, short flags, void *param) {
3800 RecordStream *p_rs;
3801 void *p_record;
3802 size_t recordlen;
3803 int ret;
Howard Sue32dbfd2015-01-07 15:55:57 +08003804 SocketListenParam *p_info = (SocketListenParam *)param;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003805
Howard Sue32dbfd2015-01-07 15:55:57 +08003806 assert(fd == p_info->fdCommand);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003807
Howard Sue32dbfd2015-01-07 15:55:57 +08003808 p_rs = p_info->p_rs;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003809
3810 for (;;) {
3811 /* loop until EAGAIN/EINTR, end of stream, or other error */
3812 ret = record_stream_get_next(p_rs, &p_record, &recordlen);
3813
3814 if (ret == 0 && p_record == NULL) {
3815 /* end-of-stream */
3816 break;
3817 } else if (ret < 0) {
3818 break;
3819 } else if (ret == 0) { /* && p_record != NULL */
Howard Sue32dbfd2015-01-07 15:55:57 +08003820 processCommandBuffer(p_record, recordlen, p_info->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003821 }
3822 }
3823
3824 if (ret == 0 || !(errno == EAGAIN || errno == EINTR)) {
3825 /* fatal error or end-of-stream */
3826 if (ret != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003827 RLOGE("error on reading command socket errno:%d\n", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003828 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003829 RLOGW("EOS. Closing command socket.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003830 }
3831
Howard Sue32dbfd2015-01-07 15:55:57 +08003832 close(fd);
3833 p_info->fdCommand = -1;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003834
Howard Sue32dbfd2015-01-07 15:55:57 +08003835 ril_event_del(p_info->commands_event);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003836
3837 record_stream_free(p_rs);
3838
3839 /* start listening for new connections again */
3840 rilEventAddWakeup(&s_listen_event);
3841
Howard Sue32dbfd2015-01-07 15:55:57 +08003842 onCommandsSocketClosed(p_info->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003843 }
3844}
3845
Howard Subd82ef12015-04-12 10:25:05 +02003846
Howard Sue32dbfd2015-01-07 15:55:57 +08003847static void onNewCommandConnect(RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003848 // Inform we are connected and the ril version
3849 int rilVer = s_callbacks.version;
Howard Sue32dbfd2015-01-07 15:55:57 +08003850 RIL_UNSOL_RESPONSE(RIL_UNSOL_RIL_CONNECTED,
3851 &rilVer, sizeof(rilVer), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003852
3853 // implicit radio state changed
Howard Sue32dbfd2015-01-07 15:55:57 +08003854 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
3855 NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003856
3857 // Send last NITZ time data, in case it was missed
3858 if (s_lastNITZTimeData != NULL) {
Howard Sue32dbfd2015-01-07 15:55:57 +08003859 sendResponseRaw(s_lastNITZTimeData, s_lastNITZTimeDataSize, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003860
3861 free(s_lastNITZTimeData);
3862 s_lastNITZTimeData = NULL;
3863 }
3864
3865 // Get version string
3866 if (s_callbacks.getVersion != NULL) {
3867 const char *version;
3868 version = s_callbacks.getVersion();
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003869 RLOGI("RIL Daemon version: %s\n", version);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003870
3871 property_set(PROPERTY_RIL_IMPL, version);
3872 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003873 RLOGI("RIL Daemon version: unavailable\n");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003874 property_set(PROPERTY_RIL_IMPL, "unavailable");
3875 }
3876
3877}
3878
3879static void listenCallback (int fd, short flags, void *param) {
3880 int ret;
3881 int err;
3882 int is_phone_socket;
Howard Sue32dbfd2015-01-07 15:55:57 +08003883 int fdCommand = -1;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003884 RecordStream *p_rs;
Howard Sue32dbfd2015-01-07 15:55:57 +08003885 SocketListenParam *p_info = (SocketListenParam *)param;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003886
3887 struct sockaddr_un peeraddr;
3888 socklen_t socklen = sizeof (peeraddr);
3889
3890 struct ucred creds;
3891 socklen_t szCreds = sizeof(creds);
3892
3893 struct passwd *pwd = NULL;
3894
Howard Sue32dbfd2015-01-07 15:55:57 +08003895 assert (*p_info->fdCommand < 0);
3896 assert (fd == *p_info->fdListen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003897
Howard Sue32dbfd2015-01-07 15:55:57 +08003898 fdCommand = accept(fd, (sockaddr *) &peeraddr, &socklen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003899
Howard Sue32dbfd2015-01-07 15:55:57 +08003900 if (fdCommand < 0 ) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003901 RLOGE("Error on accept() errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003902 /* start listening for new connections again */
Howard Sue32dbfd2015-01-07 15:55:57 +08003903 rilEventAddWakeup(p_info->listen_event);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003904 return;
3905 }
3906
3907 /* check the credential of the other side and only accept socket from
3908 * phone process
3909 */
3910 errno = 0;
3911 is_phone_socket = 0;
3912
Howard Sue32dbfd2015-01-07 15:55:57 +08003913 err = getsockopt(fdCommand, SOL_SOCKET, SO_PEERCRED, &creds, &szCreds);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003914
3915 if (err == 0 && szCreds > 0) {
3916 errno = 0;
3917 pwd = getpwuid(creds.uid);
3918 if (pwd != NULL) {
Howard Sue32dbfd2015-01-07 15:55:57 +08003919 if (strcmp(pwd->pw_name, p_info->processName) == 0) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003920 is_phone_socket = 1;
3921 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003922 RLOGE("RILD can't accept socket from process %s", pwd->pw_name);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003923 }
3924 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003925 RLOGE("Error on getpwuid() errno: %d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003926 }
3927 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003928 RLOGD("Error on getsockopt() errno: %d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003929 }
3930
Howard Subd82ef12015-04-12 10:25:05 +02003931 if (!is_phone_socket) {
Howard Sue32dbfd2015-01-07 15:55:57 +08003932 RLOGE("RILD must accept socket from %s", p_info->processName);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003933
Howard Sue32dbfd2015-01-07 15:55:57 +08003934 close(fdCommand);
3935 fdCommand = -1;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003936
Howard Sue32dbfd2015-01-07 15:55:57 +08003937 onCommandsSocketClosed(p_info->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003938
3939 /* start listening for new connections again */
Howard Sue32dbfd2015-01-07 15:55:57 +08003940 rilEventAddWakeup(p_info->listen_event);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003941
3942 return;
3943 }
3944
Howard Sue32dbfd2015-01-07 15:55:57 +08003945 ret = fcntl(fdCommand, F_SETFL, O_NONBLOCK);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003946
3947 if (ret < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003948 RLOGE ("Error setting O_NONBLOCK errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003949 }
3950
Howard Sue32dbfd2015-01-07 15:55:57 +08003951 RLOGI("libril: new connection to %s", rilSocketIdToString(p_info->socket_id));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003952
Howard Sue32dbfd2015-01-07 15:55:57 +08003953 p_info->fdCommand = fdCommand;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003954
Howard Sue32dbfd2015-01-07 15:55:57 +08003955 p_rs = record_stream_new(p_info->fdCommand, MAX_COMMAND_BYTES);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003956
Howard Sue32dbfd2015-01-07 15:55:57 +08003957 p_info->p_rs = p_rs;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003958
Howard Sue32dbfd2015-01-07 15:55:57 +08003959 ril_event_set (p_info->commands_event, p_info->fdCommand, 1,
3960 p_info->processCommandsCallback, p_info);
3961
3962 rilEventAddWakeup (p_info->commands_event);
3963
3964 onNewCommandConnect(p_info->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003965}
3966
3967static void freeDebugCallbackArgs(int number, char **args) {
3968 for (int i = 0; i < number; i++) {
3969 if (args[i] != NULL) {
3970 free(args[i]);
3971 }
3972 }
3973 free(args);
3974}
3975
3976static void debugCallback (int fd, short flags, void *param) {
3977 int acceptFD, option;
3978 struct sockaddr_un peeraddr;
3979 socklen_t socklen = sizeof (peeraddr);
3980 int data;
3981 unsigned int qxdm_data[6];
3982 const char *deactData[1] = {"1"};
3983 char *actData[1];
3984 RIL_Dial dialData;
3985 int hangupData[1] = {1};
3986 int number;
3987 char **args;
Howard Sue32dbfd2015-01-07 15:55:57 +08003988 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
3989 int sim_id = 0;
3990
3991 RLOGI("debugCallback for socket %s", rilSocketIdToString(socket_id));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003992
3993 acceptFD = accept (fd, (sockaddr *) &peeraddr, &socklen);
3994
3995 if (acceptFD < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003996 RLOGE ("error accepting on debug port: %d\n", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003997 return;
3998 }
3999
4000 if (recv(acceptFD, &number, sizeof(int), 0) != sizeof(int)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004001 RLOGE ("error reading on socket: number of Args: \n");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004002 return;
4003 }
4004 args = (char **) malloc(sizeof(char*) * number);
4005
4006 for (int i = 0; i < number; i++) {
4007 int len;
4008 if (recv(acceptFD, &len, sizeof(int), 0) != sizeof(int)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004009 RLOGE ("error reading on socket: Len of Args: \n");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004010 freeDebugCallbackArgs(i, args);
4011 return;
4012 }
4013 // +1 for null-term
4014 args[i] = (char *) malloc((sizeof(char) * len) + 1);
4015 if (recv(acceptFD, args[i], sizeof(char) * len, 0)
4016 != (int)sizeof(char) * len) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004017 RLOGE ("error reading on socket: Args[%d] \n", i);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004018 freeDebugCallbackArgs(i, args);
4019 return;
4020 }
4021 char * buf = args[i];
4022 buf[len] = 0;
Howard Sue32dbfd2015-01-07 15:55:57 +08004023 if ((i+1) == number) {
4024 /* The last argument should be sim id 0(SIM1)~3(SIM4) */
4025 sim_id = atoi(args[i]);
4026 switch (sim_id) {
4027 case 0:
4028 socket_id = RIL_SOCKET_1;
4029 break;
4030 #if (SIM_COUNT >= 2)
4031 case 1:
4032 socket_id = RIL_SOCKET_2;
4033 break;
4034 #endif
4035 #if (SIM_COUNT >= 3)
4036 case 2:
4037 socket_id = RIL_SOCKET_3;
4038 break;
4039 #endif
4040 #if (SIM_COUNT >= 4)
4041 case 3:
4042 socket_id = RIL_SOCKET_4;
4043 break;
4044 #endif
4045 default:
4046 socket_id = RIL_SOCKET_1;
4047 break;
4048 }
4049 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004050 }
4051
4052 switch (atoi(args[0])) {
4053 case 0:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004054 RLOGI ("Connection on debug port: issuing reset.");
Howard Sue32dbfd2015-01-07 15:55:57 +08004055 issueLocalRequest(RIL_REQUEST_RESET_RADIO, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004056 break;
4057 case 1:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004058 RLOGI ("Connection on debug port: issuing radio power off.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004059 data = 0;
Howard Sue32dbfd2015-01-07 15:55:57 +08004060 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004061 // Close the socket
Howard Subd82ef12015-04-12 10:25:05 +02004062 if (socket_id == RIL_SOCKET_1 && s_ril_param_socket.fdCommand > 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08004063 close(s_ril_param_socket.fdCommand);
4064 s_ril_param_socket.fdCommand = -1;
4065 }
4066 #if (SIM_COUNT == 2)
4067 else if (socket_id == RIL_SOCKET_2 && s_ril_param_socket2.fdCommand > 0) {
4068 close(s_ril_param_socket2.fdCommand);
4069 s_ril_param_socket2.fdCommand = -1;
4070 }
4071 #endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004072 break;
4073 case 2:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004074 RLOGI ("Debug port: issuing unsolicited voice network change.");
Howard Sue32dbfd2015-01-07 15:55:57 +08004075 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004076 break;
4077 case 3:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004078 RLOGI ("Debug port: QXDM log enable.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004079 qxdm_data[0] = 65536; // head.func_tag
4080 qxdm_data[1] = 16; // head.len
4081 qxdm_data[2] = 1; // mode: 1 for 'start logging'
4082 qxdm_data[3] = 32; // log_file_size: 32megabytes
4083 qxdm_data[4] = 0; // log_mask
4084 qxdm_data[5] = 8; // log_max_fileindex
4085 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Howard Sue32dbfd2015-01-07 15:55:57 +08004086 6 * sizeof(int), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004087 break;
4088 case 4:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004089 RLOGI ("Debug port: QXDM log disable.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004090 qxdm_data[0] = 65536;
4091 qxdm_data[1] = 16;
4092 qxdm_data[2] = 0; // mode: 0 for 'stop logging'
4093 qxdm_data[3] = 32;
4094 qxdm_data[4] = 0;
4095 qxdm_data[5] = 8;
4096 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Howard Sue32dbfd2015-01-07 15:55:57 +08004097 6 * sizeof(int), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004098 break;
4099 case 5:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004100 RLOGI("Debug port: Radio On");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004101 data = 1;
Howard Sue32dbfd2015-01-07 15:55:57 +08004102 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004103 sleep(2);
4104 // Set network selection automatic.
Howard Sue32dbfd2015-01-07 15:55:57 +08004105 issueLocalRequest(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004106 break;
4107 case 6:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004108 RLOGI("Debug port: Setup Data Call, Apn :%s\n", args[1]);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004109 actData[0] = args[1];
4110 issueLocalRequest(RIL_REQUEST_SETUP_DATA_CALL, &actData,
Howard Sue32dbfd2015-01-07 15:55:57 +08004111 sizeof(actData), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004112 break;
4113 case 7:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004114 RLOGI("Debug port: Deactivate Data Call");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004115 issueLocalRequest(RIL_REQUEST_DEACTIVATE_DATA_CALL, &deactData,
Howard Sue32dbfd2015-01-07 15:55:57 +08004116 sizeof(deactData), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004117 break;
4118 case 8:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004119 RLOGI("Debug port: Dial Call");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004120 dialData.clir = 0;
4121 dialData.address = args[1];
Howard Sue32dbfd2015-01-07 15:55:57 +08004122 issueLocalRequest(RIL_REQUEST_DIAL, &dialData, sizeof(dialData), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004123 break;
4124 case 9:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004125 RLOGI("Debug port: Answer Call");
Howard Sue32dbfd2015-01-07 15:55:57 +08004126 issueLocalRequest(RIL_REQUEST_ANSWER, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004127 break;
4128 case 10:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004129 RLOGI("Debug port: End Call");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004130 issueLocalRequest(RIL_REQUEST_HANGUP, &hangupData,
Howard Sue32dbfd2015-01-07 15:55:57 +08004131 sizeof(hangupData), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004132 break;
4133 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004134 RLOGE ("Invalid request");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004135 break;
4136 }
4137 freeDebugCallbackArgs(number, args);
4138 close(acceptFD);
4139}
4140
4141
4142static void userTimerCallback (int fd, short flags, void *param) {
4143 UserCallbackInfo *p_info;
4144
4145 p_info = (UserCallbackInfo *)param;
4146
4147 p_info->p_callback(p_info->userParam);
4148
4149
4150 // FIXME generalize this...there should be a cancel mechanism
4151 if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) {
4152 s_last_wake_timeout_info = NULL;
4153 }
4154
4155 free(p_info);
4156}
4157
4158
4159static void *
4160eventLoop(void *param) {
4161 int ret;
4162 int filedes[2];
4163
4164 ril_event_init();
4165
4166 pthread_mutex_lock(&s_startupMutex);
4167
4168 s_started = 1;
4169 pthread_cond_broadcast(&s_startupCond);
4170
4171 pthread_mutex_unlock(&s_startupMutex);
4172
4173 ret = pipe(filedes);
4174
4175 if (ret < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004176 RLOGE("Error in pipe() errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004177 return NULL;
4178 }
4179
4180 s_fdWakeupRead = filedes[0];
4181 s_fdWakeupWrite = filedes[1];
4182
4183 fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK);
4184
4185 ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,
4186 processWakeupCallback, NULL);
4187
4188 rilEventAddWakeup (&s_wakeupfd_event);
4189
4190 // Only returns on error
4191 ril_event_loop();
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004192 RLOGE ("error in event_loop_base errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004193 // kill self to restart on error
4194 kill(0, SIGKILL);
4195
4196 return NULL;
4197}
4198
4199extern "C" void
4200RIL_startEventLoop(void) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004201 /* spin up eventLoop thread and wait for it to get started */
4202 s_started = 0;
4203 pthread_mutex_lock(&s_startupMutex);
4204
Howard Sue32dbfd2015-01-07 15:55:57 +08004205 pthread_attr_t attr;
4206 pthread_attr_init(&attr);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004207 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
Howard Sue32dbfd2015-01-07 15:55:57 +08004208
4209 int result = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
4210 if (result != 0) {
4211 RLOGE("Failed to create dispatch thread: %s", strerror(result));
4212 goto done;
4213 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004214
4215 while (s_started == 0) {
4216 pthread_cond_wait(&s_startupCond, &s_startupMutex);
4217 }
4218
Howard Sue32dbfd2015-01-07 15:55:57 +08004219done:
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004220 pthread_mutex_unlock(&s_startupMutex);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004221}
4222
4223// Used for testing purpose only.
4224extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) {
4225 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4226}
4227
Howard Sue32dbfd2015-01-07 15:55:57 +08004228static void startListen(RIL_SOCKET_ID socket_id, SocketListenParam* socket_listen_p) {
4229 int fdListen = -1;
4230 int ret;
4231 char socket_name[10];
4232
4233 memset(socket_name, 0, sizeof(char)*10);
4234
4235 switch(socket_id) {
4236 case RIL_SOCKET_1:
4237 strncpy(socket_name, RIL_getRilSocketName(), 9);
4238 break;
4239 #if (SIM_COUNT >= 2)
4240 case RIL_SOCKET_2:
4241 strncpy(socket_name, SOCKET2_NAME_RIL, 9);
4242 break;
4243 #endif
4244 #if (SIM_COUNT >= 3)
4245 case RIL_SOCKET_3:
4246 strncpy(socket_name, SOCKET3_NAME_RIL, 9);
4247 break;
4248 #endif
4249 #if (SIM_COUNT >= 4)
4250 case RIL_SOCKET_4:
4251 strncpy(socket_name, SOCKET4_NAME_RIL, 9);
4252 break;
4253 #endif
4254 default:
4255 RLOGE("Socket id is wrong!!");
4256 return;
4257 }
4258
4259 RLOGI("Start to listen %s", rilSocketIdToString(socket_id));
4260
4261 fdListen = android_get_control_socket(socket_name);
4262 if (fdListen < 0) {
4263 RLOGE("Failed to get socket %s", socket_name);
4264 exit(-1);
4265 }
4266
4267 ret = listen(fdListen, 4);
4268
4269 if (ret < 0) {
4270 RLOGE("Failed to listen on control socket '%d': %s",
4271 fdListen, strerror(errno));
4272 exit(-1);
4273 }
4274 socket_listen_p->fdListen = fdListen;
4275
4276 /* note: non-persistent so we can accept only one connection at a time */
4277 ril_event_set (socket_listen_p->listen_event, fdListen, false,
4278 listenCallback, socket_listen_p);
4279
4280 rilEventAddWakeup (socket_listen_p->listen_event);
4281}
4282
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004283extern "C" void
4284RIL_register (const RIL_RadioFunctions *callbacks) {
4285 int ret;
4286 int flags;
4287
Howard Sue32dbfd2015-01-07 15:55:57 +08004288 RLOGI("SIM_COUNT: %d", SIM_COUNT);
4289
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004290 if (callbacks == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004291 RLOGE("RIL_register: RIL_RadioFunctions * null");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004292 return;
4293 }
4294 if (callbacks->version < RIL_VERSION_MIN) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004295 RLOGE("RIL_register: version %d is to old, min version is %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004296 callbacks->version, RIL_VERSION_MIN);
4297 return;
4298 }
4299 if (callbacks->version > RIL_VERSION) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004300 RLOGE("RIL_register: version %d is too new, max version is %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004301 callbacks->version, RIL_VERSION);
4302 return;
4303 }
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004304 RLOGE("RIL_register: RIL version %d", callbacks->version);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004305
4306 if (s_registerCalled > 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004307 RLOGE("RIL_register has been called more than once. "
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004308 "Subsequent call ignored");
4309 return;
4310 }
4311
4312 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4313
Howard Sue32dbfd2015-01-07 15:55:57 +08004314 /* Initialize socket1 parameters */
4315 s_ril_param_socket = {
4316 RIL_SOCKET_1, /* socket_id */
4317 -1, /* fdListen */
4318 -1, /* fdCommand */
4319 PHONE_PROCESS, /* processName */
4320 &s_commands_event, /* commands_event */
4321 &s_listen_event, /* listen_event */
4322 processCommandsCallback, /* processCommandsCallback */
4323 NULL /* p_rs */
4324 };
4325
4326#if (SIM_COUNT >= 2)
4327 s_ril_param_socket2 = {
4328 RIL_SOCKET_2, /* socket_id */
4329 -1, /* fdListen */
4330 -1, /* fdCommand */
4331 PHONE_PROCESS, /* processName */
4332 &s_commands_event_socket2, /* commands_event */
4333 &s_listen_event_socket2, /* listen_event */
4334 processCommandsCallback, /* processCommandsCallback */
4335 NULL /* p_rs */
4336 };
4337#endif
4338
4339#if (SIM_COUNT >= 3)
4340 s_ril_param_socket3 = {
4341 RIL_SOCKET_3, /* socket_id */
4342 -1, /* fdListen */
4343 -1, /* fdCommand */
4344 PHONE_PROCESS, /* processName */
4345 &s_commands_event_socket3, /* commands_event */
4346 &s_listen_event_socket3, /* listen_event */
4347 processCommandsCallback, /* processCommandsCallback */
4348 NULL /* p_rs */
4349 };
4350#endif
4351
4352#if (SIM_COUNT >= 4)
4353 s_ril_param_socket4 = {
4354 RIL_SOCKET_4, /* socket_id */
4355 -1, /* fdListen */
4356 -1, /* fdCommand */
4357 PHONE_PROCESS, /* processName */
4358 &s_commands_event_socket4, /* commands_event */
4359 &s_listen_event_socket4, /* listen_event */
4360 processCommandsCallback, /* processCommandsCallback */
4361 NULL /* p_rs */
4362 };
4363#endif
4364
Howard Subd82ef12015-04-12 10:25:05 +02004365
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004366 s_registerCalled = 1;
4367
Howard Sue32dbfd2015-01-07 15:55:57 +08004368 RLOGI("s_registerCalled flag set, %d", s_started);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004369 // Little self-check
4370
4371 for (int i = 0; i < (int)NUM_ELEMS(s_commands); i++) {
4372 assert(i == s_commands[i].requestNumber);
4373 }
4374
Howard Subd82ef12015-04-12 10:25:05 +02004375 for (int i = 0; i < (int)NUM_ELEMS(s_commands_v); i++) {
4376 assert(i + RIL_VENDOR_COMMANDS_OFFSET == s_commands[i].requestNumber);
4377 }
4378
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004379 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses); i++) {
Howard Sue32dbfd2015-01-07 15:55:57 +08004380 assert(i + RIL_UNSOL_RESPONSE_BASE
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004381 == s_unsolResponses[i].requestNumber);
4382 }
4383
Howard Subd82ef12015-04-12 10:25:05 +02004384 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses_v); i++) {
4385 assert(i + RIL_UNSOL_RESPONSE_BASE + RIL_VENDOR_COMMANDS_OFFSET
4386 == s_unsolResponses[i].requestNumber);
4387 }
4388
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004389 // New rild impl calls RIL_startEventLoop() first
4390 // old standalone impl wants it here.
4391
4392 if (s_started == 0) {
4393 RIL_startEventLoop();
4394 }
4395
Howard Sue32dbfd2015-01-07 15:55:57 +08004396 // start listen socket1
4397 startListen(RIL_SOCKET_1, &s_ril_param_socket);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004398
Howard Sue32dbfd2015-01-07 15:55:57 +08004399#if (SIM_COUNT >= 2)
4400 // start listen socket2
4401 startListen(RIL_SOCKET_2, &s_ril_param_socket2);
4402#endif /* (SIM_COUNT == 2) */
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004403
Howard Sue32dbfd2015-01-07 15:55:57 +08004404#if (SIM_COUNT >= 3)
4405 // start listen socket3
4406 startListen(RIL_SOCKET_3, &s_ril_param_socket3);
4407#endif /* (SIM_COUNT == 3) */
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004408
Howard Sue32dbfd2015-01-07 15:55:57 +08004409#if (SIM_COUNT >= 4)
4410 // start listen socket4
4411 startListen(RIL_SOCKET_4, &s_ril_param_socket4);
4412#endif /* (SIM_COUNT == 4) */
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004413
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004414
4415#if 1
4416 // start debug interface socket
4417
Howard Sue32dbfd2015-01-07 15:55:57 +08004418 char *inst = NULL;
4419 if (strlen(RIL_getRilSocketName()) >= strlen(SOCKET_NAME_RIL)) {
4420 inst = RIL_getRilSocketName() + strlen(SOCKET_NAME_RIL);
4421 }
4422
4423 char rildebug[MAX_DEBUG_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL_DEBUG;
4424 if (inst != NULL) {
Andreas Schneider3063dc12015-04-13 23:04:05 +02004425 snprintf(rildebug, sizeof(rildebug), "%s%s", SOCKET_NAME_RIL_DEBUG, inst);
Howard Sue32dbfd2015-01-07 15:55:57 +08004426 }
4427
4428 s_fdDebug = android_get_control_socket(rildebug);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004429 if (s_fdDebug < 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08004430 RLOGE("Failed to get socket : %s errno:%d", rildebug, errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004431 exit(-1);
4432 }
4433
4434 ret = listen(s_fdDebug, 4);
4435
4436 if (ret < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004437 RLOGE("Failed to listen on ril debug socket '%d': %s",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004438 s_fdDebug, strerror(errno));
4439 exit(-1);
4440 }
4441
4442 ril_event_set (&s_debug_event, s_fdDebug, true,
4443 debugCallback, NULL);
4444
4445 rilEventAddWakeup (&s_debug_event);
4446#endif
4447
4448}
4449
4450static int
4451checkAndDequeueRequestInfo(struct RequestInfo *pRI) {
4452 int ret = 0;
Howard Sue32dbfd2015-01-07 15:55:57 +08004453 /* Hook for current context
4454 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
4455 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
4456 /* pendingRequestsHook refer to &s_pendingRequests */
4457 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004458
4459 if (pRI == NULL) {
4460 return 0;
4461 }
4462
Howard Sue32dbfd2015-01-07 15:55:57 +08004463#if (SIM_COUNT >= 2)
4464 if (pRI->socket_id == RIL_SOCKET_2) {
4465 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
4466 pendingRequestsHook = &s_pendingRequests_socket2;
4467 }
4468#if (SIM_COUNT >= 3)
4469 if (pRI->socket_id == RIL_SOCKET_3) {
4470 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
4471 pendingRequestsHook = &s_pendingRequests_socket3;
4472 }
4473#endif
4474#if (SIM_COUNT >= 4)
4475 if (pRI->socket_id == RIL_SOCKET_4) {
4476 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
4477 pendingRequestsHook = &s_pendingRequests_socket4;
4478 }
4479#endif
4480#endif
4481 pthread_mutex_lock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004482
Howard Sue32dbfd2015-01-07 15:55:57 +08004483 for(RequestInfo **ppCur = pendingRequestsHook
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004484 ; *ppCur != NULL
4485 ; ppCur = &((*ppCur)->p_next)
4486 ) {
4487 if (pRI == *ppCur) {
4488 ret = 1;
4489
4490 *ppCur = (*ppCur)->p_next;
4491 break;
4492 }
4493 }
4494
Howard Sue32dbfd2015-01-07 15:55:57 +08004495 pthread_mutex_unlock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004496
4497 return ret;
4498}
4499
4500
4501extern "C" void
4502RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) {
4503 RequestInfo *pRI;
4504 int ret;
Howard Sue32dbfd2015-01-07 15:55:57 +08004505 int fd = s_ril_param_socket.fdCommand;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004506 size_t errorOffset;
Howard Sue32dbfd2015-01-07 15:55:57 +08004507 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004508
4509 pRI = (RequestInfo *)t;
4510
4511 if (!checkAndDequeueRequestInfo(pRI)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004512 RLOGE ("RIL_onRequestComplete: invalid RIL_Token");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004513 return;
4514 }
4515
Howard Sue32dbfd2015-01-07 15:55:57 +08004516 socket_id = pRI->socket_id;
4517#if (SIM_COUNT >= 2)
4518 if (socket_id == RIL_SOCKET_2) {
4519 fd = s_ril_param_socket2.fdCommand;
4520 }
4521#if (SIM_COUNT >= 3)
4522 if (socket_id == RIL_SOCKET_3) {
4523 fd = s_ril_param_socket3.fdCommand;
4524 }
4525#endif
4526#if (SIM_COUNT >= 4)
4527 if (socket_id == RIL_SOCKET_4) {
4528 fd = s_ril_param_socket4.fdCommand;
4529 }
4530#endif
4531#endif
4532 RLOGD("RequestComplete, %s", rilSocketIdToString(socket_id));
4533
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004534 if (pRI->local > 0) {
4535 // Locally issued command...void only!
4536 // response does not go back up the command socket
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004537 RLOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004538
4539 goto done;
4540 }
4541
4542 appendPrintBuf("[%04d]< %s",
4543 pRI->token, requestToString(pRI->pCI->requestNumber));
4544
4545 if (pRI->cancelled == 0) {
4546 Parcel p;
4547
4548 p.writeInt32 (RESPONSE_SOLICITED);
4549 p.writeInt32 (pRI->token);
4550 errorOffset = p.dataPosition();
4551
4552 p.writeInt32 (e);
4553
4554 if (response != NULL) {
4555 // there is a response payload, no matter success or not.
4556 ret = pRI->pCI->responseFunction(p, response, responselen);
4557
4558 /* if an error occurred, rewind and mark it */
4559 if (ret != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08004560 RLOGE ("responseFunction error, ret %d", ret);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004561 p.setDataPosition(errorOffset);
4562 p.writeInt32 (ret);
4563 }
4564 }
4565
4566 if (e != RIL_E_SUCCESS) {
4567 appendPrintBuf("%s fails by %s", printBuf, failCauseToString(e));
4568 }
4569
Howard Sue32dbfd2015-01-07 15:55:57 +08004570 if (fd < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004571 RLOGD ("RIL onRequestComplete: Command channel closed");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004572 }
Howard Sue32dbfd2015-01-07 15:55:57 +08004573 sendResponse(p, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004574 }
4575
4576done:
4577 free(pRI);
4578}
4579
Howard Subd82ef12015-04-12 10:25:05 +02004580
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004581static void
4582grabPartialWakeLock() {
4583 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
4584}
4585
4586static void
4587releaseWakeLock() {
4588 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
4589}
4590
4591/**
4592 * Timer callback to put us back to sleep before the default timeout
4593 */
4594static void
4595wakeTimeoutCallback (void *param) {
4596 // We're using "param != NULL" as a cancellation mechanism
4597 if (param == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004598 //RLOGD("wakeTimeout: releasing wake lock");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004599
4600 releaseWakeLock();
4601 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004602 //RLOGD("wakeTimeout: releasing wake lock CANCELLED");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004603 }
4604}
4605
4606static int
4607decodeVoiceRadioTechnology (RIL_RadioState radioState) {
4608 switch (radioState) {
4609 case RADIO_STATE_SIM_NOT_READY:
4610 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4611 case RADIO_STATE_SIM_READY:
4612 return RADIO_TECH_UMTS;
4613
4614 case RADIO_STATE_RUIM_NOT_READY:
4615 case RADIO_STATE_RUIM_READY:
4616 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4617 case RADIO_STATE_NV_NOT_READY:
4618 case RADIO_STATE_NV_READY:
4619 return RADIO_TECH_1xRTT;
4620
4621 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004622 RLOGD("decodeVoiceRadioTechnology: Invoked with incorrect RadioState");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004623 return -1;
4624 }
4625}
4626
4627static int
4628decodeCdmaSubscriptionSource (RIL_RadioState radioState) {
4629 switch (radioState) {
4630 case RADIO_STATE_SIM_NOT_READY:
4631 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4632 case RADIO_STATE_SIM_READY:
4633 case RADIO_STATE_RUIM_NOT_READY:
4634 case RADIO_STATE_RUIM_READY:
4635 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4636 return CDMA_SUBSCRIPTION_SOURCE_RUIM_SIM;
4637
4638 case RADIO_STATE_NV_NOT_READY:
4639 case RADIO_STATE_NV_READY:
4640 return CDMA_SUBSCRIPTION_SOURCE_NV;
4641
4642 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004643 RLOGD("decodeCdmaSubscriptionSource: Invoked with incorrect RadioState");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004644 return -1;
4645 }
4646}
4647
4648static int
4649decodeSimStatus (RIL_RadioState radioState) {
4650 switch (radioState) {
4651 case RADIO_STATE_SIM_NOT_READY:
4652 case RADIO_STATE_RUIM_NOT_READY:
4653 case RADIO_STATE_NV_NOT_READY:
4654 case RADIO_STATE_NV_READY:
4655 return -1;
4656 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4657 case RADIO_STATE_SIM_READY:
4658 case RADIO_STATE_RUIM_READY:
4659 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4660 return radioState;
4661 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004662 RLOGD("decodeSimStatus: Invoked with incorrect RadioState");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004663 return -1;
4664 }
4665}
4666
4667static bool is3gpp2(int radioTech) {
4668 switch (radioTech) {
4669 case RADIO_TECH_IS95A:
4670 case RADIO_TECH_IS95B:
4671 case RADIO_TECH_1xRTT:
4672 case RADIO_TECH_EVDO_0:
4673 case RADIO_TECH_EVDO_A:
4674 case RADIO_TECH_EVDO_B:
4675 case RADIO_TECH_EHRPD:
4676 return true;
4677 default:
4678 return false;
4679 }
4680}
4681
4682/* If RIL sends SIM states or RUIM states, store the voice radio
4683 * technology and subscription source information so that they can be
4684 * returned when telephony framework requests them
4685 */
4686static RIL_RadioState
Howard Subd82ef12015-04-12 10:25:05 +02004687processRadioState(RIL_RadioState newRadioState, RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004688
4689 if((newRadioState > RADIO_STATE_UNAVAILABLE) && (newRadioState < RADIO_STATE_ON)) {
4690 int newVoiceRadioTech;
4691 int newCdmaSubscriptionSource;
4692 int newSimStatus;
4693
4694 /* This is old RIL. Decode Subscription source and Voice Radio Technology
4695 from Radio State and send change notifications if there has been a change */
4696 newVoiceRadioTech = decodeVoiceRadioTechnology(newRadioState);
4697 if(newVoiceRadioTech != voiceRadioTech) {
4698 voiceRadioTech = newVoiceRadioTech;
Howard Sue32dbfd2015-01-07 15:55:57 +08004699 RIL_UNSOL_RESPONSE(RIL_UNSOL_VOICE_RADIO_TECH_CHANGED,
4700 &voiceRadioTech, sizeof(voiceRadioTech), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004701 }
4702 if(is3gpp2(newVoiceRadioTech)) {
4703 newCdmaSubscriptionSource = decodeCdmaSubscriptionSource(newRadioState);
4704 if(newCdmaSubscriptionSource != cdmaSubscriptionSource) {
4705 cdmaSubscriptionSource = newCdmaSubscriptionSource;
Howard Sue32dbfd2015-01-07 15:55:57 +08004706 RIL_UNSOL_RESPONSE(RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED,
4707 &cdmaSubscriptionSource, sizeof(cdmaSubscriptionSource), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004708 }
4709 }
4710 newSimStatus = decodeSimStatus(newRadioState);
4711 if(newSimStatus != simRuimStatus) {
4712 simRuimStatus = newSimStatus;
Howard Sue32dbfd2015-01-07 15:55:57 +08004713 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004714 }
4715
4716 /* Send RADIO_ON to telephony */
4717 newRadioState = RADIO_STATE_ON;
4718 }
4719
4720 return newRadioState;
4721}
4722
Howard Subd82ef12015-04-12 10:25:05 +02004723
Howard Sue32dbfd2015-01-07 15:55:57 +08004724#if defined(ANDROID_MULTI_SIM)
4725extern "C"
Andreas Schneider47b2d962015-04-13 22:54:49 +02004726void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Howard Sue32dbfd2015-01-07 15:55:57 +08004727 size_t datalen, RIL_SOCKET_ID socket_id)
4728#else
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004729extern "C"
Andreas Schneider47b2d962015-04-13 22:54:49 +02004730void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004731 size_t datalen)
Howard Sue32dbfd2015-01-07 15:55:57 +08004732#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004733{
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004734 int ret;
4735 int64_t timeReceived = 0;
4736 bool shouldScheduleTimeout = false;
4737 RIL_RadioState newState;
Howard Sue32dbfd2015-01-07 15:55:57 +08004738 RIL_SOCKET_ID soc_id = RIL_SOCKET_1;
Howard Subd82ef12015-04-12 10:25:05 +02004739 UnsolResponseInfo *pRI = NULL;
Howard Sue32dbfd2015-01-07 15:55:57 +08004740
4741#if defined(ANDROID_MULTI_SIM)
4742 soc_id = socket_id;
4743#endif
4744
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004745
4746 if (s_registerCalled == 0) {
4747 // Ignore RIL_onUnsolicitedResponse before RIL_register
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004748 RLOGW("RIL_onUnsolicitedResponse called before RIL_register");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004749 return;
4750 }
Howard Sue32dbfd2015-01-07 15:55:57 +08004751
Howard Subd82ef12015-04-12 10:25:05 +02004752 /* Hack to include Samsung responses */
4753 if (unsolResponse > RIL_VENDOR_COMMANDS_OFFSET + RIL_UNSOL_RESPONSE_BASE) {
4754 int index = unsolResponse - RIL_VENDOR_COMMANDS_OFFSET - RIL_UNSOL_RESPONSE_BASE;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004755
Howard Subd82ef12015-04-12 10:25:05 +02004756 RLOGD("SAMSUNG: unsolResponse=%d, unsolResponseIndex=%d", unsolResponse, index);
4757
4758 if (index < (int32_t)NUM_ELEMS(s_unsolResponses_v))
4759 pRI = &s_unsolResponses_v[index];
4760 } else {
4761 int index = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
4762 if (index < (int32_t)NUM_ELEMS(s_unsolResponses))
4763 pRI = &s_unsolResponses[index];
4764 }
4765
4766 if (pRI == NULL || pRI->responseFunction == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004767 RLOGE("unsupported unsolicited response code %d", unsolResponse);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004768 return;
4769 }
4770
4771 // Grab a wake lock if needed for this reponse,
4772 // as we exit we'll either release it immediately
4773 // or set a timer to release it later.
Howard Subd82ef12015-04-12 10:25:05 +02004774 switch (pRI->wakeType) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004775 case WAKE_PARTIAL:
4776 grabPartialWakeLock();
4777 shouldScheduleTimeout = true;
4778 break;
4779
4780 case DONT_WAKE:
4781 default:
4782 // No wake lock is grabed so don't set timeout
4783 shouldScheduleTimeout = false;
4784 break;
4785 }
4786
4787 // Mark the time this was received, doing this
4788 // after grabing the wakelock incase getting
4789 // the elapsedRealTime might cause us to goto
4790 // sleep.
4791 if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4792 timeReceived = elapsedRealtime();
4793 }
4794
4795 appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
4796
4797 Parcel p;
4798
4799 p.writeInt32 (RESPONSE_UNSOLICITED);
4800 p.writeInt32 (unsolResponse);
4801
Howard Subd82ef12015-04-12 10:25:05 +02004802 ret = pRI->responseFunction(p, const_cast<void*>(data), datalen);
4803
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004804 if (ret != 0) {
4805 // Problem with the response. Don't continue;
4806 goto error_exit;
4807 }
4808
4809 // some things get more payload
4810 switch(unsolResponse) {
4811 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
Howard Sue32dbfd2015-01-07 15:55:57 +08004812 newState = processRadioState(CALL_ONSTATEREQUEST(soc_id), soc_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004813 p.writeInt32(newState);
4814 appendPrintBuf("%s {%s}", printBuf,
Howard Sue32dbfd2015-01-07 15:55:57 +08004815 radioStateToString(CALL_ONSTATEREQUEST(soc_id)));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004816 break;
4817
4818
4819 case RIL_UNSOL_NITZ_TIME_RECEIVED:
4820 // Store the time that this was received so the
4821 // handler of this message can account for
4822 // the time it takes to arrive and process. In
4823 // particular the system has been known to sleep
4824 // before this message can be processed.
4825 p.writeInt64(timeReceived);
4826 break;
4827 }
4828
Howard Sue32dbfd2015-01-07 15:55:57 +08004829 RLOGI("%s UNSOLICITED: %s length:%d", rilSocketIdToString(soc_id), requestToString(unsolResponse), p.dataSize());
4830 ret = sendResponse(p, soc_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004831 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4832
4833 // Unfortunately, NITZ time is not poll/update like everything
4834 // else in the system. So, if the upstream client isn't connected,
4835 // keep a copy of the last NITZ response (with receive time noted
4836 // above) around so we can deliver it when it is connected
4837
4838 if (s_lastNITZTimeData != NULL) {
4839 free (s_lastNITZTimeData);
4840 s_lastNITZTimeData = NULL;
4841 }
4842
4843 s_lastNITZTimeData = malloc(p.dataSize());
4844 s_lastNITZTimeDataSize = p.dataSize();
4845 memcpy(s_lastNITZTimeData, p.data(), p.dataSize());
4846 }
4847
4848 // For now, we automatically go back to sleep after TIMEVAL_WAKE_TIMEOUT
4849 // FIXME The java code should handshake here to release wake lock
4850
4851 if (shouldScheduleTimeout) {
4852 // Cancel the previous request
4853 if (s_last_wake_timeout_info != NULL) {
4854 s_last_wake_timeout_info->userParam = (void *)1;
4855 }
4856
4857 s_last_wake_timeout_info
4858 = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
4859 &TIMEVAL_WAKE_TIMEOUT);
4860 }
4861
4862 // Normal exit
4863 return;
4864
4865error_exit:
4866 if (shouldScheduleTimeout) {
4867 releaseWakeLock();
4868 }
4869}
4870
4871/** FIXME generalize this if you track UserCAllbackInfo, clear it
4872 when the callback occurs
4873*/
4874static UserCallbackInfo *
4875internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
4876 const struct timeval *relativeTime)
4877{
4878 struct timeval myRelativeTime;
4879 UserCallbackInfo *p_info;
4880
4881 p_info = (UserCallbackInfo *) malloc (sizeof(UserCallbackInfo));
4882
4883 p_info->p_callback = callback;
4884 p_info->userParam = param;
4885
4886 if (relativeTime == NULL) {
4887 /* treat null parameter as a 0 relative time */
4888 memset (&myRelativeTime, 0, sizeof(myRelativeTime));
4889 } else {
4890 /* FIXME I think event_add's tv param is really const anyway */
4891 memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
4892 }
4893
4894 ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
4895
4896 ril_timer_add(&(p_info->event), &myRelativeTime);
4897
4898 triggerEvLoop();
4899 return p_info;
4900}
4901
4902
4903extern "C" void
4904RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
4905 const struct timeval *relativeTime) {
4906 internalRequestTimedCallback (callback, param, relativeTime);
4907}
4908
4909const char *
4910failCauseToString(RIL_Errno e) {
4911 switch(e) {
4912 case RIL_E_SUCCESS: return "E_SUCCESS";
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004913 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RADIO_NOT_AVAILABLE";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004914 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
4915 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
4916 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
4917 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
4918 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
4919 case RIL_E_CANCELLED: return "E_CANCELLED";
4920 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
4921 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
4922 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
4923 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
4924 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
4925#ifdef FEATURE_MULTIMODE_ANDROID
4926 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
4927 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
4928#endif
4929 default: return "<unknown error>";
4930 }
4931}
4932
4933const char *
4934radioStateToString(RIL_RadioState s) {
4935 switch(s) {
4936 case RADIO_STATE_OFF: return "RADIO_OFF";
4937 case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
4938 case RADIO_STATE_SIM_NOT_READY: return "RADIO_SIM_NOT_READY";
4939 case RADIO_STATE_SIM_LOCKED_OR_ABSENT: return "RADIO_SIM_LOCKED_OR_ABSENT";
4940 case RADIO_STATE_SIM_READY: return "RADIO_SIM_READY";
4941 case RADIO_STATE_RUIM_NOT_READY:return"RADIO_RUIM_NOT_READY";
4942 case RADIO_STATE_RUIM_READY:return"RADIO_RUIM_READY";
4943 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:return"RADIO_RUIM_LOCKED_OR_ABSENT";
4944 case RADIO_STATE_NV_NOT_READY:return"RADIO_NV_NOT_READY";
4945 case RADIO_STATE_NV_READY:return"RADIO_NV_READY";
4946 case RADIO_STATE_ON:return"RADIO_ON";
4947 default: return "<unknown state>";
4948 }
4949}
4950
4951const char *
4952callStateToString(RIL_CallState s) {
4953 switch(s) {
4954 case RIL_CALL_ACTIVE : return "ACTIVE";
4955 case RIL_CALL_HOLDING: return "HOLDING";
4956 case RIL_CALL_DIALING: return "DIALING";
4957 case RIL_CALL_ALERTING: return "ALERTING";
4958 case RIL_CALL_INCOMING: return "INCOMING";
4959 case RIL_CALL_WAITING: return "WAITING";
4960 default: return "<unknown state>";
4961 }
4962}
4963
4964const char *
4965requestToString(int request) {
4966/*
4967 cat libs/telephony/ril_commands.h \
4968 | egrep "^ *{RIL_" \
4969 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
4970
4971
4972 cat libs/telephony/ril_unsol_commands.h \
4973 | egrep "^ *{RIL_" \
4974 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
4975
4976*/
4977 switch(request) {
4978 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
4979 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
4980 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
4981 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
4982 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
4983 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
4984 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
4985 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
4986 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
4987 case RIL_REQUEST_DIAL: return "DIAL";
4988 case RIL_REQUEST_DIAL_EMERGENCY: return "DIAL";
4989 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
4990 case RIL_REQUEST_HANGUP: return "HANGUP";
4991 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
4992 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
4993 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
4994 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
4995 case RIL_REQUEST_UDUB: return "UDUB";
4996 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
4997 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
4998 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
4999 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
5000 case RIL_REQUEST_OPERATOR: return "OPERATOR";
5001 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
5002 case RIL_REQUEST_DTMF: return "DTMF";
5003 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
5004 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
5005 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
5006 case RIL_REQUEST_SIM_IO: return "SIM_IO";
5007 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
5008 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
5009 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
5010 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
5011 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
5012 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
5013 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
5014 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
5015 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
5016 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
5017 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
5018 case RIL_REQUEST_ANSWER: return "ANSWER";
5019 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
5020 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
5021 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
5022 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
5023 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
5024 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
5025 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
5026 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";
5027 case RIL_REQUEST_DTMF_START: return "DTMF_START";
5028 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
5029 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
5030 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
5031 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
5032 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
5033 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
5034 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
5035 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
5036 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
5037 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
5038 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
5039 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
5040 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
5041 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
5042 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
5043 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
5044 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
5045 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
5046 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
5047 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
5048 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
5049 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
5050 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
5051 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005052 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE:return"CDMA_SET_SUBSCRIPTION_SOURCE";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005053 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"CDMA_SET_ROAMING_PREFERENCE";
5054 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"CDMA_QUERY_ROAMING_PREFERENCE";
5055 case RIL_REQUEST_SET_TTY_MODE:return"SET_TTY_MODE";
5056 case RIL_REQUEST_QUERY_TTY_MODE:return"QUERY_TTY_MODE";
5057 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
5058 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
5059 case RIL_REQUEST_CDMA_FLASH:return"CDMA_FLASH";
5060 case RIL_REQUEST_CDMA_BURST_DTMF:return"CDMA_BURST_DTMF";
5061 case RIL_REQUEST_CDMA_SEND_SMS:return"CDMA_SEND_SMS";
5062 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:return"CDMA_SMS_ACKNOWLEDGE";
5063 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG:return"GSM_GET_BROADCAST_SMS_CONFIG";
5064 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG:return"GSM_SET_BROADCAST_SMS_CONFIG";
5065 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG:return "CDMA_GET_BROADCAST_SMS_CONFIG";
5066 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG:return "CDMA_SET_BROADCAST_SMS_CONFIG";
5067 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION:return "CDMA_SMS_BROADCAST_ACTIVATION";
Ethan Chend6e30652013-08-04 22:49:56 -07005068 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return"CDMA_VALIDATE_AND_WRITE_AKEY";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005069 case RIL_REQUEST_CDMA_SUBSCRIPTION: return"CDMA_SUBSCRIPTION";
5070 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
5071 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
5072 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
5073 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
5074 case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
5075 case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
5076 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
5077 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
5078 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
5079 case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
5080 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
5081 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
5082 case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005083 case RIL_REQUEST_GET_CELL_INFO_LIST: return"GET_CELL_INFO_LIST";
5084 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return"SET_UNSOL_CELL_INFO_LIST_RATE";
Andrew Jiangca4a9a02014-01-18 18:04:08 -05005085 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "RIL_REQUEST_SET_INITIAL_ATTACH_APN";
5086 case RIL_REQUEST_IMS_REGISTRATION_STATE: return "IMS_REGISTRATION_STATE";
5087 case RIL_REQUEST_IMS_SEND_SMS: return "IMS_SEND_SMS";
Howard Sue32dbfd2015-01-07 15:55:57 +08005088 case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "SIM_TRANSMIT_APDU_BASIC";
5089 case RIL_REQUEST_SIM_OPEN_CHANNEL: return "SIM_OPEN_CHANNEL";
5090 case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "SIM_CLOSE_CHANNEL";
5091 case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "SIM_TRANSMIT_APDU_CHANNEL";
Howard Subd82ef12015-04-12 10:25:05 +02005092 case RIL_REQUEST_GET_RADIO_CAPABILITY: return "RIL_REQUEST_GET_RADIO_CAPABILITY";
5093 case RIL_REQUEST_SET_RADIO_CAPABILITY: return "RIL_REQUEST_SET_RADIO_CAPABILITY";
Howard Sue32dbfd2015-01-07 15:55:57 +08005094 case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "SET_UICC_SUBSCRIPTION";
5095 case RIL_REQUEST_ALLOW_DATA: return "ALLOW_DATA";
5096 case RIL_REQUEST_GET_HARDWARE_CONFIG: return "GET_HARDWARE_CONFIG";
5097 case RIL_REQUEST_SIM_AUTHENTICATION: return "SIM_AUTHENTICATION";
5098 case RIL_REQUEST_GET_DC_RT_INFO: return "GET_DC_RT_INFO";
5099 case RIL_REQUEST_SET_DC_RT_INFO_RATE: return "SET_DC_RT_INFO_RATE";
5100 case RIL_REQUEST_SET_DATA_PROFILE: return "SET_DATA_PROFILE";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005101 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
5102 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
5103 case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED";
5104 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
5105 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
5106 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
5107 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
5108 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)";
5109 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
5110 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
Howard Subd82ef12015-04-12 10:25:05 +02005111 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
5112 case RIL_UNSOL_SUPP_SVC_NOTIFICATION: return "UNSOL_SUPP_SVC_NOTIFICATION";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005113 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
5114 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
5115 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
5116 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
5117 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL";
5118 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005119 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
5120 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
5121 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_NEW_CDMA_SMS";
5122 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_NEW_BROADCAST_SMS";
5123 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
5124 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
5125 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
5126 case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
5127 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
5128 case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
5129 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
5130 case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
5131 case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
5132 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
5133 case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
5134 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
5135 case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
5136 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
Ethan Chend6e30652013-08-04 22:49:56 -07005137 case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
Andrew Jiangca4a9a02014-01-18 18:04:08 -05005138 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "RESPONSE_IMS_NETWORK_STATE_CHANGED";
Howard Sue32dbfd2015-01-07 15:55:57 +08005139 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return "UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED";
5140 case RIL_UNSOL_SRVCC_STATE_NOTIFY: return "UNSOL_SRVCC_STATE_NOTIFY";
5141 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return "HARDWARE_CONFIG_CHANGED";
5142 case RIL_UNSOL_DC_RT_INFO_CHANGED: return "UNSOL_DC_RT_INFO_CHANGED";
Howard Subd82ef12015-04-12 10:25:05 +02005143 case RIL_UNSOL_RADIO_CAPABILITY: return "UNSOL_RADIO_CAPABILITY";
5144 case RIL_UNSOL_ON_SS: return "UNSOL_ON_SS";
5145 case RIL_UNSOL_STK_CC_ALPHA_NOTIFY: return "UNSOL_STK_CC_ALPHA_NOTIFY";
Howard Sue32dbfd2015-01-07 15:55:57 +08005146 case RIL_REQUEST_SHUTDOWN: return "SHUTDOWN";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005147 default: return "<unknown request>";
5148 }
5149}
5150
Howard Sue32dbfd2015-01-07 15:55:57 +08005151const char *
5152rilSocketIdToString(RIL_SOCKET_ID socket_id)
5153{
5154 switch(socket_id) {
5155 case RIL_SOCKET_1:
5156 return "RIL_SOCKET_1";
5157#if (SIM_COUNT >= 2)
5158 case RIL_SOCKET_2:
5159 return "RIL_SOCKET_2";
5160#endif
5161#if (SIM_COUNT >= 3)
5162 case RIL_SOCKET_3:
5163 return "RIL_SOCKET_3";
5164#endif
5165#if (SIM_COUNT >= 4)
5166 case RIL_SOCKET_4:
5167 return "RIL_SOCKET_4";
5168#endif
5169 default:
5170 return "not a valid RIL";
5171 }
5172}
5173
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005174} /* namespace android */