blob: 97e40b12d4c510e1f742d6f0a483f176143f9360 [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)
Howard Subd82ef12015-04-12 10:25:05 +0200323extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
Howard Sue32dbfd2015-01-07 15:55:57 +0800324 size_t datalen, RIL_SOCKET_ID socket_id);
325#else
Howard Subd82ef12015-04-12 10:25:05 +0200326extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, 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) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002970 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002971 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002972 return RIL_ERRNO_INVALID_RESPONSE;
2973 }
2974
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002975 if (responselen >= sizeof (RIL_SignalStrength_v5)) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002976 RIL_SignalStrength_v10 *p_cur = ((RIL_SignalStrength_v10 *) response);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002977
Howard Sue32dbfd2015-01-07 15:55:57 +08002978 p.writeInt32(p_cur->GW_SignalStrength.signalStrength);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002979 p.writeInt32(p_cur->GW_SignalStrength.bitErrorRate);
Howard Sue32dbfd2015-01-07 15:55:57 +08002980 p.writeInt32(p_cur->CDMA_SignalStrength.dbm);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002981 p.writeInt32(p_cur->CDMA_SignalStrength.ecio);
Howard Sue32dbfd2015-01-07 15:55:57 +08002982 p.writeInt32(p_cur->EVDO_SignalStrength.dbm);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002983 p.writeInt32(p_cur->EVDO_SignalStrength.ecio);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002984 p.writeInt32(p_cur->EVDO_SignalStrength.signalNoiseRatio);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002985 if (responselen >= sizeof (RIL_SignalStrength_v6)) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002986 /*
Ethan Chend6e30652013-08-04 22:49:56 -07002987 * Fixup LTE for backwards compatibility
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002988 */
Ethan Chend6e30652013-08-04 22:49:56 -07002989 if (s_callbacks.version <= 6) {
2990 // signalStrength: -1 -> 99
2991 if (p_cur->LTE_SignalStrength.signalStrength == -1) {
2992 p_cur->LTE_SignalStrength.signalStrength = 99;
2993 }
2994 // rsrp: -1 -> INT_MAX all other negative value to positive.
2995 // So remap here
2996 if (p_cur->LTE_SignalStrength.rsrp == -1) {
2997 p_cur->LTE_SignalStrength.rsrp = INT_MAX;
2998 } else if (p_cur->LTE_SignalStrength.rsrp < -1) {
2999 p_cur->LTE_SignalStrength.rsrp = -p_cur->LTE_SignalStrength.rsrp;
3000 }
3001 // rsrq: -1 -> INT_MAX
3002 if (p_cur->LTE_SignalStrength.rsrq == -1) {
3003 p_cur->LTE_SignalStrength.rsrq = INT_MAX;
3004 }
3005 // Not remapping rssnr is already using INT_MAX
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003006
Ethan Chend6e30652013-08-04 22:49:56 -07003007 // cqi: -1 -> INT_MAX
3008 if (p_cur->LTE_SignalStrength.cqi == -1) {
3009 p_cur->LTE_SignalStrength.cqi = INT_MAX;
3010 }
3011 }
3012 p.writeInt32(p_cur->LTE_SignalStrength.signalStrength);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003013 p.writeInt32(p_cur->LTE_SignalStrength.rsrp);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003014 p.writeInt32(p_cur->LTE_SignalStrength.rsrq);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003015 p.writeInt32(p_cur->LTE_SignalStrength.rssnr);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003016 p.writeInt32(p_cur->LTE_SignalStrength.cqi);
Howard Sue32dbfd2015-01-07 15:55:57 +08003017 if (responselen >= sizeof (RIL_SignalStrength_v10)) {
3018 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
3019 } else {
3020 p.writeInt32(INT_MAX);
3021 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003022 } else {
Ethan Chend6e30652013-08-04 22:49:56 -07003023 p.writeInt32(99);
3024 p.writeInt32(INT_MAX);
3025 p.writeInt32(INT_MAX);
3026 p.writeInt32(INT_MAX);
3027 p.writeInt32(INT_MAX);
Howard Sue32dbfd2015-01-07 15:55:57 +08003028 p.writeInt32(INT_MAX);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003029 }
3030
3031 startResponse;
3032 appendPrintBuf("%s[signalStrength=%d,bitErrorRate=%d,\
3033 CDMA_SS.dbm=%d,CDMA_SSecio=%d,\
3034 EVDO_SS.dbm=%d,EVDO_SS.ecio=%d,\
3035 EVDO_SS.signalNoiseRatio=%d,\
3036 LTE_SS.signalStrength=%d,LTE_SS.rsrp=%d,LTE_SS.rsrq=%d,\
Howard Sue32dbfd2015-01-07 15:55:57 +08003037 LTE_SS.rssnr=%d,LTE_SS.cqi=%d,TDSCDMA_SS.rscp=%d]",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003038 printBuf,
Howard Sue32dbfd2015-01-07 15:55:57 +08003039 p_cur->GW_SignalStrength.signalStrength,
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003040 p_cur->GW_SignalStrength.bitErrorRate,
Howard Sue32dbfd2015-01-07 15:55:57 +08003041 p_cur->CDMA_SignalStrength.dbm,
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003042 p_cur->CDMA_SignalStrength.ecio,
Howard Sue32dbfd2015-01-07 15:55:57 +08003043 p_cur->EVDO_SignalStrength.dbm,
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003044 p_cur->EVDO_SignalStrength.ecio,
3045 p_cur->EVDO_SignalStrength.signalNoiseRatio,
3046 p_cur->LTE_SignalStrength.signalStrength,
3047 p_cur->LTE_SignalStrength.rsrp,
3048 p_cur->LTE_SignalStrength.rsrq,
3049 p_cur->LTE_SignalStrength.rssnr,
Howard Sue32dbfd2015-01-07 15:55:57 +08003050 p_cur->LTE_SignalStrength.cqi,
3051 p_cur->TD_SCDMA_SignalStrength.rscp);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003052 closeResponse;
3053
3054 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003055 RLOGE("invalid response length");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003056 return RIL_ERRNO_INVALID_RESPONSE;
3057 }
3058
3059 return 0;
3060}
3061
3062static int responseCallRing(Parcel &p, void *response, size_t responselen) {
3063 if ((response == NULL) || (responselen == 0)) {
3064 return responseVoid(p, response, responselen);
3065 } else {
3066 return responseCdmaSignalInfoRecord(p, response, responselen);
3067 }
3068}
3069
3070static int responseCdmaSignalInfoRecord(Parcel &p, void *response, size_t responselen) {
3071 if (response == NULL || responselen == 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003072 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003073 return RIL_ERRNO_INVALID_RESPONSE;
3074 }
3075
3076 if (responselen != sizeof (RIL_CDMA_SignalInfoRecord)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003077 RLOGE("invalid response length %d expected sizeof (RIL_CDMA_SignalInfoRecord) of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003078 (int)responselen, (int)sizeof (RIL_CDMA_SignalInfoRecord));
3079 return RIL_ERRNO_INVALID_RESPONSE;
3080 }
3081
3082 startResponse;
3083
3084 RIL_CDMA_SignalInfoRecord *p_cur = ((RIL_CDMA_SignalInfoRecord *) response);
3085 marshallSignalInfoRecord(p, *p_cur);
3086
3087 appendPrintBuf("%s[isPresent=%d,signalType=%d,alertPitch=%d\
3088 signal=%d]",
3089 printBuf,
3090 p_cur->isPresent,
3091 p_cur->signalType,
3092 p_cur->alertPitch,
3093 p_cur->signal);
3094
3095 closeResponse;
3096 return 0;
3097}
3098
3099static int responseCdmaCallWaiting(Parcel &p, void *response,
3100 size_t responselen) {
3101 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003102 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003103 return RIL_ERRNO_INVALID_RESPONSE;
3104 }
3105
3106 if (responselen < sizeof(RIL_CDMA_CallWaiting_v6)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003107 RLOGW("Upgrade to ril version %d\n", RIL_VERSION);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003108 }
3109
3110 RIL_CDMA_CallWaiting_v6 *p_cur = ((RIL_CDMA_CallWaiting_v6 *) response);
3111
3112 writeStringToParcel(p, p_cur->number);
3113 p.writeInt32(p_cur->numberPresentation);
3114 writeStringToParcel(p, p_cur->name);
3115 marshallSignalInfoRecord(p, p_cur->signalInfoRecord);
3116
3117 if (responselen >= sizeof(RIL_CDMA_CallWaiting_v6)) {
3118 p.writeInt32(p_cur->number_type);
3119 p.writeInt32(p_cur->number_plan);
3120 } else {
3121 p.writeInt32(0);
3122 p.writeInt32(0);
3123 }
3124
3125 startResponse;
3126 appendPrintBuf("%snumber=%s,numberPresentation=%d, name=%s,\
3127 signalInfoRecord[isPresent=%d,signalType=%d,alertPitch=%d\
3128 signal=%d,number_type=%d,number_plan=%d]",
3129 printBuf,
3130 p_cur->number,
3131 p_cur->numberPresentation,
3132 p_cur->name,
3133 p_cur->signalInfoRecord.isPresent,
3134 p_cur->signalInfoRecord.signalType,
3135 p_cur->signalInfoRecord.alertPitch,
3136 p_cur->signalInfoRecord.signal,
3137 p_cur->number_type,
3138 p_cur->number_plan);
3139 closeResponse;
3140
3141 return 0;
3142}
3143
3144static int responseSimRefresh(Parcel &p, void *response, size_t responselen) {
3145 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003146 RLOGE("responseSimRefresh: invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003147 return RIL_ERRNO_INVALID_RESPONSE;
3148 }
3149
3150 startResponse;
3151 if (s_callbacks.version == 7) {
3152 RIL_SimRefreshResponse_v7 *p_cur = ((RIL_SimRefreshResponse_v7 *) response);
3153 p.writeInt32(p_cur->result);
3154 p.writeInt32(p_cur->ef_id);
3155 writeStringToParcel(p, p_cur->aid);
3156
3157 appendPrintBuf("%sresult=%d, ef_id=%d, aid=%s",
3158 printBuf,
3159 p_cur->result,
3160 p_cur->ef_id,
3161 p_cur->aid);
3162 } else {
3163 int *p_cur = ((int *) response);
3164 p.writeInt32(p_cur[0]);
3165 p.writeInt32(p_cur[1]);
3166 writeStringToParcel(p, NULL);
3167
3168 appendPrintBuf("%sresult=%d, ef_id=%d",
3169 printBuf,
3170 p_cur[0],
3171 p_cur[1]);
3172 }
3173 closeResponse;
3174
3175 return 0;
3176}
3177
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003178static int responseCellInfoList(Parcel &p, void *response, size_t responselen)
3179{
3180 if (response == NULL && responselen != 0) {
3181 RLOGE("invalid response: NULL");
3182 return RIL_ERRNO_INVALID_RESPONSE;
3183 }
3184
3185 if (responselen % sizeof(RIL_CellInfo) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08003186 RLOGE("responseCellInfoList: invalid response length %d expected multiple of %d",
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003187 (int)responselen, (int)sizeof(RIL_CellInfo));
3188 return RIL_ERRNO_INVALID_RESPONSE;
3189 }
3190
3191 int num = responselen / sizeof(RIL_CellInfo);
3192 p.writeInt32(num);
3193
3194 RIL_CellInfo *p_cur = (RIL_CellInfo *) response;
3195 startResponse;
3196 int i;
3197 for (i = 0; i < num; i++) {
3198 appendPrintBuf("%s[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", printBuf, i,
3199 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
3200 p.writeInt32((int)p_cur->cellInfoType);
3201 p.writeInt32(p_cur->registered);
3202 p.writeInt32(p_cur->timeStampType);
3203 p.writeInt64(p_cur->timeStamp);
3204 switch(p_cur->cellInfoType) {
3205 case RIL_CELL_INFO_TYPE_GSM: {
3206 appendPrintBuf("%s GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,", printBuf,
3207 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
3208 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
3209 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
3210 p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3211 appendPrintBuf("%s gsmSS: ss=%d,ber=%d],", printBuf,
3212 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
3213 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3214
3215 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
3216 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
3217 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
3218 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3219 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
3220 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3221 break;
3222 }
3223 case RIL_CELL_INFO_TYPE_WCDMA: {
3224 appendPrintBuf("%s WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,", printBuf,
3225 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
3226 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
3227 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
3228 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
3229 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3230 appendPrintBuf("%s wcdmaSS: ss=%d,ber=%d],", printBuf,
3231 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
3232 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3233
3234 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
3235 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
3236 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
3237 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
3238 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3239 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
3240 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3241 break;
3242 }
3243 case RIL_CELL_INFO_TYPE_CDMA: {
3244 appendPrintBuf("%s CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d", printBuf,
3245 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
3246 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
3247 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
3248 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
3249 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3250
3251 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
3252 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
3253 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
3254 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
3255 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3256
3257 appendPrintBuf("%s cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d", printBuf,
3258 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
3259 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
3260 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
3261 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
3262 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3263
3264 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
3265 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
3266 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
3267 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
3268 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3269 break;
3270 }
3271 case RIL_CELL_INFO_TYPE_LTE: {
3272 appendPrintBuf("%s LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d", printBuf,
3273 p_cur->CellInfo.lte.cellIdentityLte.mcc,
3274 p_cur->CellInfo.lte.cellIdentityLte.mnc,
3275 p_cur->CellInfo.lte.cellIdentityLte.ci,
3276 p_cur->CellInfo.lte.cellIdentityLte.pci,
3277 p_cur->CellInfo.lte.cellIdentityLte.tac);
3278
3279 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
3280 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
3281 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
3282 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
3283 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
3284
3285 appendPrintBuf("%s lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d", printBuf,
3286 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
3287 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
3288 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
3289 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
3290 p_cur->CellInfo.lte.signalStrengthLte.cqi,
3291 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3292 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
3293 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
3294 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
3295 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
3296 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
3297 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3298 break;
3299 }
Howard Sue32dbfd2015-01-07 15:55:57 +08003300 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
3301 appendPrintBuf("%s TDSCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,cpid=%d,", printBuf,
3302 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc,
3303 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc,
3304 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac,
3305 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid,
3306 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3307 appendPrintBuf("%s tdscdmaSS: rscp=%d],", printBuf,
3308 p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3309
3310 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
3311 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
3312 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
3313 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
3314 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3315 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3316 break;
3317 }
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003318 }
3319 p_cur += 1;
3320 }
3321 removeLastChar;
3322 closeResponse;
3323
3324 return 0;
3325}
3326
Howard Sue32dbfd2015-01-07 15:55:57 +08003327static int responseHardwareConfig(Parcel &p, void *response, size_t responselen)
3328{
3329 if (response == NULL && responselen != 0) {
3330 RLOGE("invalid response: NULL");
3331 return RIL_ERRNO_INVALID_RESPONSE;
3332 }
3333
3334 if (responselen % sizeof(RIL_HardwareConfig) != 0) {
3335 RLOGE("responseHardwareConfig: invalid response length %d expected multiple of %d",
3336 (int)responselen, (int)sizeof(RIL_HardwareConfig));
3337 return RIL_ERRNO_INVALID_RESPONSE;
3338 }
3339
3340 int num = responselen / sizeof(RIL_HardwareConfig);
3341 int i;
3342 RIL_HardwareConfig *p_cur = (RIL_HardwareConfig *) response;
3343
3344 p.writeInt32(num);
3345
3346 startResponse;
3347 for (i = 0; i < num; i++) {
3348 switch (p_cur[i].type) {
3349 case RIL_HARDWARE_CONFIG_MODEM: {
3350 writeStringToParcel(p, p_cur[i].uuid);
3351 p.writeInt32((int)p_cur[i].state);
3352 p.writeInt32(p_cur[i].cfg.modem.rat);
3353 p.writeInt32(p_cur[i].cfg.modem.maxVoice);
3354 p.writeInt32(p_cur[i].cfg.modem.maxData);
3355 p.writeInt32(p_cur[i].cfg.modem.maxStandby);
3356
3357 appendPrintBuf("%s modem: uuid=%s,state=%d,rat=%08x,maxV=%d,maxD=%d,maxS=%d", printBuf,
3358 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.modem.rat,
3359 p_cur[i].cfg.modem.maxVoice, p_cur[i].cfg.modem.maxData, p_cur[i].cfg.modem.maxStandby);
3360 break;
3361 }
3362 case RIL_HARDWARE_CONFIG_SIM: {
3363 writeStringToParcel(p, p_cur[i].uuid);
3364 p.writeInt32((int)p_cur[i].state);
3365 writeStringToParcel(p, p_cur[i].cfg.sim.modemUuid);
3366
3367 appendPrintBuf("%s sim: uuid=%s,state=%d,modem-uuid=%s", printBuf,
3368 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.sim.modemUuid);
3369 break;
3370 }
3371 }
3372 }
3373 removeLastChar;
3374 closeResponse;
3375 return 0;
3376}
3377
Howard Subd82ef12015-04-12 10:25:05 +02003378static int responseRadioCapability(Parcel &p, void *response, size_t responselen) {
3379 if (response == NULL) {
3380 RLOGE("invalid response: NULL");
3381 return RIL_ERRNO_INVALID_RESPONSE;
3382 }
3383
3384 if (responselen != sizeof (RIL_RadioCapability) ) {
3385 RLOGE("invalid response length was %d expected %d",
3386 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3387 return RIL_ERRNO_INVALID_RESPONSE;
3388 }
3389
3390 RIL_RadioCapability *p_cur = (RIL_RadioCapability *) response;
3391 p.writeInt32(p_cur->version);
3392 p.writeInt32(p_cur->session);
3393 p.writeInt32(p_cur->phase);
3394 p.writeInt32(p_cur->rat);
3395 writeStringToParcel(p, p_cur->logicalModemUuid);
3396 p.writeInt32(p_cur->status);
3397
3398 startResponse;
3399 appendPrintBuf("%s[version=%d,session=%d,phase=%d,\
3400 rat=%s,logicalModemUuid=%s,status=%d]",
3401 printBuf,
3402 p_cur->version,
3403 p_cur->session,
3404 p_cur->phase,
3405 p_cur->rat,
3406 p_cur->logicalModemUuid,
3407 p_cur->status);
3408 closeResponse;
3409 return 0;
3410}
3411
3412static int responseSSData(Parcel &p, void *response, size_t responselen) {
3413 RLOGD("In responseSSData");
3414 int num;
3415
3416 if (response == NULL && responselen != 0) {
3417 RLOGE("invalid response length was %d expected %d",
3418 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3419 return RIL_ERRNO_INVALID_RESPONSE;
3420 }
3421
3422 if (responselen != sizeof(RIL_StkCcUnsolSsResponse)) {
3423 RLOGE("invalid response length %d, expected %d",
3424 (int)responselen, (int)sizeof(RIL_StkCcUnsolSsResponse));
3425 return RIL_ERRNO_INVALID_RESPONSE;
3426 }
3427
3428 startResponse;
3429 RIL_StkCcUnsolSsResponse *p_cur = (RIL_StkCcUnsolSsResponse *) response;
3430 p.writeInt32(p_cur->serviceType);
3431 p.writeInt32(p_cur->requestType);
3432 p.writeInt32(p_cur->teleserviceType);
3433 p.writeInt32(p_cur->serviceClass);
3434 p.writeInt32(p_cur->result);
3435
3436 if (isServiceTypeCfQuery(p_cur->serviceType, p_cur->requestType)) {
3437 RLOGD("responseSSData CF type, num of Cf elements %d", p_cur->cfData.numValidIndexes);
3438 if (p_cur->cfData.numValidIndexes > NUM_SERVICE_CLASSES) {
3439 RLOGE("numValidIndexes is greater than max value %d, "
3440 "truncating it to max value", NUM_SERVICE_CLASSES);
3441 p_cur->cfData.numValidIndexes = NUM_SERVICE_CLASSES;
3442 }
3443 /* number of call info's */
3444 p.writeInt32(p_cur->cfData.numValidIndexes);
3445
3446 for (int i = 0; i < p_cur->cfData.numValidIndexes; i++) {
3447 RIL_CallForwardInfo cf = p_cur->cfData.cfInfo[i];
3448
3449 p.writeInt32(cf.status);
3450 p.writeInt32(cf.reason);
3451 p.writeInt32(cf.serviceClass);
3452 p.writeInt32(cf.toa);
3453 writeStringToParcel(p, cf.number);
3454 p.writeInt32(cf.timeSeconds);
3455 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
3456 (cf.status==1)?"enable":"disable", cf.reason, cf.serviceClass, cf.toa,
3457 (char*)cf.number, cf.timeSeconds);
3458 RLOGD("Data: %d,reason=%d,cls=%d,toa=%d,num=%s,tout=%d],", cf.status,
3459 cf.reason, cf.serviceClass, cf.toa, (char*)cf.number, cf.timeSeconds);
3460 }
3461 } else {
3462 p.writeInt32 (SS_INFO_MAX);
3463
3464 /* each int*/
3465 for (int i = 0; i < SS_INFO_MAX; i++) {
3466 appendPrintBuf("%s%d,", printBuf, p_cur->ssInfo[i]);
3467 RLOGD("Data: %d",p_cur->ssInfo[i]);
3468 p.writeInt32(p_cur->ssInfo[i]);
3469 }
3470 }
3471 removeLastChar;
3472 closeResponse;
3473
3474 return 0;
3475}
3476
3477static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType) {
3478 if ((reqType == SS_INTERROGATION) &&
3479 (serType == SS_CFU ||
3480 serType == SS_CF_BUSY ||
3481 serType == SS_CF_NO_REPLY ||
3482 serType == SS_CF_NOT_REACHABLE ||
3483 serType == SS_CF_ALL ||
3484 serType == SS_CF_ALL_CONDITIONAL)) {
3485 return true;
3486 }
3487 return false;
3488}
3489
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003490static void triggerEvLoop() {
3491 int ret;
3492 if (!pthread_equal(pthread_self(), s_tid_dispatch)) {
3493 /* trigger event loop to wakeup. No reason to do this,
3494 * if we're in the event loop thread */
3495 do {
3496 ret = write (s_fdWakeupWrite, " ", 1);
3497 } while (ret < 0 && errno == EINTR);
3498 }
3499}
3500
3501static void rilEventAddWakeup(struct ril_event *ev) {
3502 ril_event_add(ev);
3503 triggerEvLoop();
3504}
3505
3506static void sendSimStatusAppInfo(Parcel &p, int num_apps, RIL_AppStatus appStatus[]) {
3507 p.writeInt32(num_apps);
3508 startResponse;
3509 for (int i = 0; i < num_apps; i++) {
3510 p.writeInt32(appStatus[i].app_type);
3511 p.writeInt32(appStatus[i].app_state);
3512 p.writeInt32(appStatus[i].perso_substate);
3513 writeStringToParcel(p, (const char*)(appStatus[i].aid_ptr));
3514 writeStringToParcel(p, (const char*)
3515 (appStatus[i].app_label_ptr));
3516 p.writeInt32(appStatus[i].pin1_replaced);
3517 p.writeInt32(appStatus[i].pin1);
3518 p.writeInt32(appStatus[i].pin2);
3519 appendPrintBuf("%s[app_type=%d,app_state=%d,perso_substate=%d,\
3520 aid_ptr=%s,app_label_ptr=%s,pin1_replaced=%d,pin1=%d,pin2=%d],",
3521 printBuf,
3522 appStatus[i].app_type,
3523 appStatus[i].app_state,
3524 appStatus[i].perso_substate,
3525 appStatus[i].aid_ptr,
3526 appStatus[i].app_label_ptr,
3527 appStatus[i].pin1_replaced,
3528 appStatus[i].pin1,
3529 appStatus[i].pin2);
3530 }
3531 closeResponse;
3532}
3533
3534static int responseSimStatus(Parcel &p, void *response, size_t responselen) {
Howard Sue32dbfd2015-01-07 15:55:57 +08003535 int i;
3536
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003537 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003538 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003539 return RIL_ERRNO_INVALID_RESPONSE;
3540 }
3541
3542 if (responselen == sizeof (RIL_CardStatus_v6)) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003543 RIL_CardStatus_v6 *p_cur = ((RIL_CardStatus_v6 *) response);
3544
3545 p.writeInt32(p_cur->card_state);
3546 p.writeInt32(p_cur->universal_pin_state);
3547 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3548 p.writeInt32(p_cur->cdma_subscription_app_index);
3549 p.writeInt32(p_cur->ims_subscription_app_index);
3550
3551 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
3552 } else if (responselen == sizeof (RIL_CardStatus_v5)) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003553 RIL_CardStatus_v5 *p_cur = ((RIL_CardStatus_v5 *) response);
3554
3555 p.writeInt32(p_cur->card_state);
3556 p.writeInt32(p_cur->universal_pin_state);
3557 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3558 p.writeInt32(p_cur->cdma_subscription_app_index);
3559 p.writeInt32(-1);
3560
3561 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
3562 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003563 RLOGE("responseSimStatus: A RilCardStatus_v6 or _v5 expected\n");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003564 return RIL_ERRNO_INVALID_RESPONSE;
3565 }
3566
3567 return 0;
3568}
3569
3570static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3571 int num = responselen / sizeof(RIL_GSM_BroadcastSmsConfigInfo *);
3572 p.writeInt32(num);
3573
3574 startResponse;
3575 RIL_GSM_BroadcastSmsConfigInfo **p_cur =
3576 (RIL_GSM_BroadcastSmsConfigInfo **) response;
3577 for (int i = 0; i < num; i++) {
3578 p.writeInt32(p_cur[i]->fromServiceId);
3579 p.writeInt32(p_cur[i]->toServiceId);
3580 p.writeInt32(p_cur[i]->fromCodeScheme);
3581 p.writeInt32(p_cur[i]->toCodeScheme);
3582 p.writeInt32(p_cur[i]->selected);
3583
3584 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId=%d, \
3585 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]",
3586 printBuf, i, p_cur[i]->fromServiceId, p_cur[i]->toServiceId,
3587 p_cur[i]->fromCodeScheme, p_cur[i]->toCodeScheme,
3588 p_cur[i]->selected);
3589 }
3590 closeResponse;
3591
3592 return 0;
3593}
3594
3595static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3596 RIL_CDMA_BroadcastSmsConfigInfo **p_cur =
3597 (RIL_CDMA_BroadcastSmsConfigInfo **) response;
3598
3599 int num = responselen / sizeof (RIL_CDMA_BroadcastSmsConfigInfo *);
3600 p.writeInt32(num);
3601
3602 startResponse;
3603 for (int i = 0 ; i < num ; i++ ) {
3604 p.writeInt32(p_cur[i]->service_category);
3605 p.writeInt32(p_cur[i]->language);
3606 p.writeInt32(p_cur[i]->selected);
3607
3608 appendPrintBuf("%s [%d: srvice_category=%d, language =%d, \
3609 selected =%d], ",
3610 printBuf, i, p_cur[i]->service_category, p_cur[i]->language,
3611 p_cur[i]->selected);
3612 }
3613 closeResponse;
3614
3615 return 0;
3616}
3617
3618static int responseCdmaSms(Parcel &p, void *response, size_t responselen) {
3619 int num;
3620 int digitCount;
3621 int digitLimit;
3622 uint8_t uct;
3623 void* dest;
3624
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003625 RLOGD("Inside responseCdmaSms");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003626
3627 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003628 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003629 return RIL_ERRNO_INVALID_RESPONSE;
3630 }
3631
3632 if (responselen != sizeof(RIL_CDMA_SMS_Message)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003633 RLOGE("invalid response length was %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003634 (int)responselen, (int)sizeof(RIL_CDMA_SMS_Message));
3635 return RIL_ERRNO_INVALID_RESPONSE;
3636 }
3637
3638 RIL_CDMA_SMS_Message *p_cur = (RIL_CDMA_SMS_Message *) response;
3639 p.writeInt32(p_cur->uTeleserviceID);
3640 p.write(&(p_cur->bIsServicePresent),sizeof(uct));
3641 p.writeInt32(p_cur->uServicecategory);
3642 p.writeInt32(p_cur->sAddress.digit_mode);
3643 p.writeInt32(p_cur->sAddress.number_mode);
3644 p.writeInt32(p_cur->sAddress.number_type);
3645 p.writeInt32(p_cur->sAddress.number_plan);
3646 p.write(&(p_cur->sAddress.number_of_digits), sizeof(uct));
3647 digitLimit= MIN((p_cur->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
3648 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3649 p.write(&(p_cur->sAddress.digits[digitCount]),sizeof(uct));
3650 }
3651
3652 p.writeInt32(p_cur->sSubAddress.subaddressType);
3653 p.write(&(p_cur->sSubAddress.odd),sizeof(uct));
3654 p.write(&(p_cur->sSubAddress.number_of_digits),sizeof(uct));
3655 digitLimit= MIN((p_cur->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
3656 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3657 p.write(&(p_cur->sSubAddress.digits[digitCount]),sizeof(uct));
3658 }
3659
3660 digitLimit= MIN((p_cur->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
3661 p.writeInt32(p_cur->uBearerDataLen);
3662 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3663 p.write(&(p_cur->aBearerData[digitCount]), sizeof(uct));
3664 }
3665
3666 startResponse;
3667 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
3668 sAddress.digit_mode=%d, sAddress.number_mode=%d, sAddress.number_type=%d, ",
3669 printBuf, p_cur->uTeleserviceID,p_cur->bIsServicePresent,p_cur->uServicecategory,
3670 p_cur->sAddress.digit_mode, p_cur->sAddress.number_mode,p_cur->sAddress.number_type);
3671 closeResponse;
3672
3673 return 0;
3674}
3675
Howard Sue32dbfd2015-01-07 15:55:57 +08003676static int responseDcRtInfo(Parcel &p, void *response, size_t responselen)
3677{
3678 int num = responselen / sizeof(RIL_DcRtInfo);
3679 if ((responselen % sizeof(RIL_DcRtInfo) != 0) || (num != 1)) {
3680 RLOGE("responseDcRtInfo: invalid response length %d expected multiple of %d",
3681 (int)responselen, (int)sizeof(RIL_DcRtInfo));
3682 return RIL_ERRNO_INVALID_RESPONSE;
3683 }
3684
3685 startResponse;
3686 RIL_DcRtInfo *pDcRtInfo = (RIL_DcRtInfo *)response;
3687 p.writeInt64(pDcRtInfo->time);
3688 p.writeInt32(pDcRtInfo->powerState);
3689 appendPrintBuf("%s[time=%d,powerState=%d]", printBuf,
3690 pDcRtInfo->time,
3691 pDcRtInfo->powerState);
3692 closeResponse;
3693
3694 return 0;
3695}
3696
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003697/**
3698 * A write on the wakeup fd is done just to pop us out of select()
3699 * We empty the buffer here and then ril_event will reset the timers on the
3700 * way back down
3701 */
3702static void processWakeupCallback(int fd, short flags, void *param) {
3703 char buff[16];
3704 int ret;
3705
Ethan Chend6e30652013-08-04 22:49:56 -07003706 RLOGV("processWakeupCallback");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003707
3708 /* empty our wakeup socket out */
3709 do {
3710 ret = read(s_fdWakeupRead, &buff, sizeof(buff));
3711 } while (ret > 0 || (ret < 0 && errno == EINTR));
3712}
3713
Howard Sue32dbfd2015-01-07 15:55:57 +08003714static void onCommandsSocketClosed(RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003715 int ret;
3716 RequestInfo *p_cur;
Howard Sue32dbfd2015-01-07 15:55:57 +08003717 /* Hook for current context
3718 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
3719 pthread_mutex_t * pendingRequestsMutexHook = &s_pendingRequestsMutex;
3720 /* pendingRequestsHook refer to &s_pendingRequests */
3721 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003722
Howard Sue32dbfd2015-01-07 15:55:57 +08003723#if (SIM_COUNT >= 2)
3724 if (socket_id == RIL_SOCKET_2) {
3725 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
3726 pendingRequestsHook = &s_pendingRequests_socket2;
3727 }
3728#if (SIM_COUNT >= 3)
3729 else if (socket_id == RIL_SOCKET_3) {
3730 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
3731 pendingRequestsHook = &s_pendingRequests_socket3;
3732 }
3733#endif
3734#if (SIM_COUNT >= 4)
3735 else if (socket_id == RIL_SOCKET_4) {
3736 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
3737 pendingRequestsHook = &s_pendingRequests_socket4;
3738 }
3739#endif
3740#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003741 /* mark pending requests as "cancelled" so we dont report responses */
Howard Sue32dbfd2015-01-07 15:55:57 +08003742 ret = pthread_mutex_lock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003743 assert (ret == 0);
3744
Howard Sue32dbfd2015-01-07 15:55:57 +08003745 p_cur = *pendingRequestsHook;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003746
Howard Sue32dbfd2015-01-07 15:55:57 +08003747 for (p_cur = *pendingRequestsHook
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003748 ; p_cur != NULL
3749 ; p_cur = p_cur->p_next
3750 ) {
3751 p_cur->cancelled = 1;
3752 }
3753
Howard Sue32dbfd2015-01-07 15:55:57 +08003754 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003755 assert (ret == 0);
3756}
3757
3758static void processCommandsCallback(int fd, short flags, void *param) {
3759 RecordStream *p_rs;
3760 void *p_record;
3761 size_t recordlen;
3762 int ret;
Howard Sue32dbfd2015-01-07 15:55:57 +08003763 SocketListenParam *p_info = (SocketListenParam *)param;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003764
Howard Sue32dbfd2015-01-07 15:55:57 +08003765 assert(fd == p_info->fdCommand);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003766
Howard Sue32dbfd2015-01-07 15:55:57 +08003767 p_rs = p_info->p_rs;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003768
3769 for (;;) {
3770 /* loop until EAGAIN/EINTR, end of stream, or other error */
3771 ret = record_stream_get_next(p_rs, &p_record, &recordlen);
3772
3773 if (ret == 0 && p_record == NULL) {
3774 /* end-of-stream */
3775 break;
3776 } else if (ret < 0) {
3777 break;
3778 } else if (ret == 0) { /* && p_record != NULL */
Howard Sue32dbfd2015-01-07 15:55:57 +08003779 processCommandBuffer(p_record, recordlen, p_info->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003780 }
3781 }
3782
3783 if (ret == 0 || !(errno == EAGAIN || errno == EINTR)) {
3784 /* fatal error or end-of-stream */
3785 if (ret != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003786 RLOGE("error on reading command socket errno:%d\n", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003787 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003788 RLOGW("EOS. Closing command socket.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003789 }
3790
Howard Sue32dbfd2015-01-07 15:55:57 +08003791 close(fd);
3792 p_info->fdCommand = -1;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003793
Howard Sue32dbfd2015-01-07 15:55:57 +08003794 ril_event_del(p_info->commands_event);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003795
3796 record_stream_free(p_rs);
3797
3798 /* start listening for new connections again */
3799 rilEventAddWakeup(&s_listen_event);
3800
Howard Sue32dbfd2015-01-07 15:55:57 +08003801 onCommandsSocketClosed(p_info->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003802 }
3803}
3804
Howard Subd82ef12015-04-12 10:25:05 +02003805
Howard Sue32dbfd2015-01-07 15:55:57 +08003806static void onNewCommandConnect(RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003807 // Inform we are connected and the ril version
3808 int rilVer = s_callbacks.version;
Howard Sue32dbfd2015-01-07 15:55:57 +08003809 RIL_UNSOL_RESPONSE(RIL_UNSOL_RIL_CONNECTED,
3810 &rilVer, sizeof(rilVer), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003811
3812 // implicit radio state changed
Howard Sue32dbfd2015-01-07 15:55:57 +08003813 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
3814 NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003815
3816 // Send last NITZ time data, in case it was missed
3817 if (s_lastNITZTimeData != NULL) {
Howard Sue32dbfd2015-01-07 15:55:57 +08003818 sendResponseRaw(s_lastNITZTimeData, s_lastNITZTimeDataSize, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003819
3820 free(s_lastNITZTimeData);
3821 s_lastNITZTimeData = NULL;
3822 }
3823
3824 // Get version string
3825 if (s_callbacks.getVersion != NULL) {
3826 const char *version;
3827 version = s_callbacks.getVersion();
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003828 RLOGI("RIL Daemon version: %s\n", version);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003829
3830 property_set(PROPERTY_RIL_IMPL, version);
3831 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003832 RLOGI("RIL Daemon version: unavailable\n");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003833 property_set(PROPERTY_RIL_IMPL, "unavailable");
3834 }
3835
3836}
3837
3838static void listenCallback (int fd, short flags, void *param) {
3839 int ret;
3840 int err;
3841 int is_phone_socket;
Howard Sue32dbfd2015-01-07 15:55:57 +08003842 int fdCommand = -1;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003843 RecordStream *p_rs;
Howard Sue32dbfd2015-01-07 15:55:57 +08003844 SocketListenParam *p_info = (SocketListenParam *)param;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003845
3846 struct sockaddr_un peeraddr;
3847 socklen_t socklen = sizeof (peeraddr);
3848
3849 struct ucred creds;
3850 socklen_t szCreds = sizeof(creds);
3851
3852 struct passwd *pwd = NULL;
3853
Howard Sue32dbfd2015-01-07 15:55:57 +08003854 assert (*p_info->fdCommand < 0);
3855 assert (fd == *p_info->fdListen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003856
Howard Sue32dbfd2015-01-07 15:55:57 +08003857 fdCommand = accept(fd, (sockaddr *) &peeraddr, &socklen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003858
Howard Sue32dbfd2015-01-07 15:55:57 +08003859 if (fdCommand < 0 ) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003860 RLOGE("Error on accept() errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003861 /* start listening for new connections again */
Howard Sue32dbfd2015-01-07 15:55:57 +08003862 rilEventAddWakeup(p_info->listen_event);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003863 return;
3864 }
3865
3866 /* check the credential of the other side and only accept socket from
3867 * phone process
3868 */
3869 errno = 0;
3870 is_phone_socket = 0;
3871
Howard Sue32dbfd2015-01-07 15:55:57 +08003872 err = getsockopt(fdCommand, SOL_SOCKET, SO_PEERCRED, &creds, &szCreds);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003873
3874 if (err == 0 && szCreds > 0) {
3875 errno = 0;
3876 pwd = getpwuid(creds.uid);
3877 if (pwd != NULL) {
Howard Sue32dbfd2015-01-07 15:55:57 +08003878 if (strcmp(pwd->pw_name, p_info->processName) == 0) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003879 is_phone_socket = 1;
3880 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003881 RLOGE("RILD can't accept socket from process %s", pwd->pw_name);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003882 }
3883 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003884 RLOGE("Error on getpwuid() errno: %d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003885 }
3886 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003887 RLOGD("Error on getsockopt() errno: %d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003888 }
3889
Howard Subd82ef12015-04-12 10:25:05 +02003890 if (!is_phone_socket) {
Howard Sue32dbfd2015-01-07 15:55:57 +08003891 RLOGE("RILD must accept socket from %s", p_info->processName);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003892
Howard Sue32dbfd2015-01-07 15:55:57 +08003893 close(fdCommand);
3894 fdCommand = -1;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003895
Howard Sue32dbfd2015-01-07 15:55:57 +08003896 onCommandsSocketClosed(p_info->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003897
3898 /* start listening for new connections again */
Howard Sue32dbfd2015-01-07 15:55:57 +08003899 rilEventAddWakeup(p_info->listen_event);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003900
3901 return;
3902 }
3903
Howard Sue32dbfd2015-01-07 15:55:57 +08003904 ret = fcntl(fdCommand, F_SETFL, O_NONBLOCK);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003905
3906 if (ret < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003907 RLOGE ("Error setting O_NONBLOCK errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003908 }
3909
Howard Sue32dbfd2015-01-07 15:55:57 +08003910 RLOGI("libril: new connection to %s", rilSocketIdToString(p_info->socket_id));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003911
Howard Sue32dbfd2015-01-07 15:55:57 +08003912 p_info->fdCommand = fdCommand;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003913
Howard Sue32dbfd2015-01-07 15:55:57 +08003914 p_rs = record_stream_new(p_info->fdCommand, MAX_COMMAND_BYTES);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003915
Howard Sue32dbfd2015-01-07 15:55:57 +08003916 p_info->p_rs = p_rs;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003917
Howard Sue32dbfd2015-01-07 15:55:57 +08003918 ril_event_set (p_info->commands_event, p_info->fdCommand, 1,
3919 p_info->processCommandsCallback, p_info);
3920
3921 rilEventAddWakeup (p_info->commands_event);
3922
3923 onNewCommandConnect(p_info->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003924}
3925
3926static void freeDebugCallbackArgs(int number, char **args) {
3927 for (int i = 0; i < number; i++) {
3928 if (args[i] != NULL) {
3929 free(args[i]);
3930 }
3931 }
3932 free(args);
3933}
3934
3935static void debugCallback (int fd, short flags, void *param) {
3936 int acceptFD, option;
3937 struct sockaddr_un peeraddr;
3938 socklen_t socklen = sizeof (peeraddr);
3939 int data;
3940 unsigned int qxdm_data[6];
3941 const char *deactData[1] = {"1"};
3942 char *actData[1];
3943 RIL_Dial dialData;
3944 int hangupData[1] = {1};
3945 int number;
3946 char **args;
Howard Sue32dbfd2015-01-07 15:55:57 +08003947 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
3948 int sim_id = 0;
3949
3950 RLOGI("debugCallback for socket %s", rilSocketIdToString(socket_id));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003951
3952 acceptFD = accept (fd, (sockaddr *) &peeraddr, &socklen);
3953
3954 if (acceptFD < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003955 RLOGE ("error accepting on debug port: %d\n", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003956 return;
3957 }
3958
3959 if (recv(acceptFD, &number, sizeof(int), 0) != sizeof(int)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003960 RLOGE ("error reading on socket: number of Args: \n");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003961 return;
3962 }
3963 args = (char **) malloc(sizeof(char*) * number);
3964
3965 for (int i = 0; i < number; i++) {
3966 int len;
3967 if (recv(acceptFD, &len, sizeof(int), 0) != sizeof(int)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003968 RLOGE ("error reading on socket: Len of Args: \n");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003969 freeDebugCallbackArgs(i, args);
3970 return;
3971 }
3972 // +1 for null-term
3973 args[i] = (char *) malloc((sizeof(char) * len) + 1);
3974 if (recv(acceptFD, args[i], sizeof(char) * len, 0)
3975 != (int)sizeof(char) * len) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003976 RLOGE ("error reading on socket: Args[%d] \n", i);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003977 freeDebugCallbackArgs(i, args);
3978 return;
3979 }
3980 char * buf = args[i];
3981 buf[len] = 0;
Howard Sue32dbfd2015-01-07 15:55:57 +08003982 if ((i+1) == number) {
3983 /* The last argument should be sim id 0(SIM1)~3(SIM4) */
3984 sim_id = atoi(args[i]);
3985 switch (sim_id) {
3986 case 0:
3987 socket_id = RIL_SOCKET_1;
3988 break;
3989 #if (SIM_COUNT >= 2)
3990 case 1:
3991 socket_id = RIL_SOCKET_2;
3992 break;
3993 #endif
3994 #if (SIM_COUNT >= 3)
3995 case 2:
3996 socket_id = RIL_SOCKET_3;
3997 break;
3998 #endif
3999 #if (SIM_COUNT >= 4)
4000 case 3:
4001 socket_id = RIL_SOCKET_4;
4002 break;
4003 #endif
4004 default:
4005 socket_id = RIL_SOCKET_1;
4006 break;
4007 }
4008 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004009 }
4010
4011 switch (atoi(args[0])) {
4012 case 0:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004013 RLOGI ("Connection on debug port: issuing reset.");
Howard Sue32dbfd2015-01-07 15:55:57 +08004014 issueLocalRequest(RIL_REQUEST_RESET_RADIO, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004015 break;
4016 case 1:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004017 RLOGI ("Connection on debug port: issuing radio power off.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004018 data = 0;
Howard Sue32dbfd2015-01-07 15:55:57 +08004019 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004020 // Close the socket
Howard Subd82ef12015-04-12 10:25:05 +02004021 if (socket_id == RIL_SOCKET_1 && s_ril_param_socket.fdCommand > 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08004022 close(s_ril_param_socket.fdCommand);
4023 s_ril_param_socket.fdCommand = -1;
4024 }
4025 #if (SIM_COUNT == 2)
4026 else if (socket_id == RIL_SOCKET_2 && s_ril_param_socket2.fdCommand > 0) {
4027 close(s_ril_param_socket2.fdCommand);
4028 s_ril_param_socket2.fdCommand = -1;
4029 }
4030 #endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004031 break;
4032 case 2:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004033 RLOGI ("Debug port: issuing unsolicited voice network change.");
Howard Sue32dbfd2015-01-07 15:55:57 +08004034 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004035 break;
4036 case 3:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004037 RLOGI ("Debug port: QXDM log enable.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004038 qxdm_data[0] = 65536; // head.func_tag
4039 qxdm_data[1] = 16; // head.len
4040 qxdm_data[2] = 1; // mode: 1 for 'start logging'
4041 qxdm_data[3] = 32; // log_file_size: 32megabytes
4042 qxdm_data[4] = 0; // log_mask
4043 qxdm_data[5] = 8; // log_max_fileindex
4044 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Howard Sue32dbfd2015-01-07 15:55:57 +08004045 6 * sizeof(int), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004046 break;
4047 case 4:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004048 RLOGI ("Debug port: QXDM log disable.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004049 qxdm_data[0] = 65536;
4050 qxdm_data[1] = 16;
4051 qxdm_data[2] = 0; // mode: 0 for 'stop logging'
4052 qxdm_data[3] = 32;
4053 qxdm_data[4] = 0;
4054 qxdm_data[5] = 8;
4055 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Howard Sue32dbfd2015-01-07 15:55:57 +08004056 6 * sizeof(int), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004057 break;
4058 case 5:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004059 RLOGI("Debug port: Radio On");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004060 data = 1;
Howard Sue32dbfd2015-01-07 15:55:57 +08004061 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004062 sleep(2);
4063 // Set network selection automatic.
Howard Sue32dbfd2015-01-07 15:55:57 +08004064 issueLocalRequest(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004065 break;
4066 case 6:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004067 RLOGI("Debug port: Setup Data Call, Apn :%s\n", args[1]);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004068 actData[0] = args[1];
4069 issueLocalRequest(RIL_REQUEST_SETUP_DATA_CALL, &actData,
Howard Sue32dbfd2015-01-07 15:55:57 +08004070 sizeof(actData), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004071 break;
4072 case 7:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004073 RLOGI("Debug port: Deactivate Data Call");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004074 issueLocalRequest(RIL_REQUEST_DEACTIVATE_DATA_CALL, &deactData,
Howard Sue32dbfd2015-01-07 15:55:57 +08004075 sizeof(deactData), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004076 break;
4077 case 8:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004078 RLOGI("Debug port: Dial Call");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004079 dialData.clir = 0;
4080 dialData.address = args[1];
Howard Sue32dbfd2015-01-07 15:55:57 +08004081 issueLocalRequest(RIL_REQUEST_DIAL, &dialData, sizeof(dialData), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004082 break;
4083 case 9:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004084 RLOGI("Debug port: Answer Call");
Howard Sue32dbfd2015-01-07 15:55:57 +08004085 issueLocalRequest(RIL_REQUEST_ANSWER, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004086 break;
4087 case 10:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004088 RLOGI("Debug port: End Call");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004089 issueLocalRequest(RIL_REQUEST_HANGUP, &hangupData,
Howard Sue32dbfd2015-01-07 15:55:57 +08004090 sizeof(hangupData), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004091 break;
4092 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004093 RLOGE ("Invalid request");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004094 break;
4095 }
4096 freeDebugCallbackArgs(number, args);
4097 close(acceptFD);
4098}
4099
4100
4101static void userTimerCallback (int fd, short flags, void *param) {
4102 UserCallbackInfo *p_info;
4103
4104 p_info = (UserCallbackInfo *)param;
4105
4106 p_info->p_callback(p_info->userParam);
4107
4108
4109 // FIXME generalize this...there should be a cancel mechanism
4110 if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) {
4111 s_last_wake_timeout_info = NULL;
4112 }
4113
4114 free(p_info);
4115}
4116
4117
4118static void *
4119eventLoop(void *param) {
4120 int ret;
4121 int filedes[2];
4122
4123 ril_event_init();
4124
4125 pthread_mutex_lock(&s_startupMutex);
4126
4127 s_started = 1;
4128 pthread_cond_broadcast(&s_startupCond);
4129
4130 pthread_mutex_unlock(&s_startupMutex);
4131
4132 ret = pipe(filedes);
4133
4134 if (ret < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004135 RLOGE("Error in pipe() errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004136 return NULL;
4137 }
4138
4139 s_fdWakeupRead = filedes[0];
4140 s_fdWakeupWrite = filedes[1];
4141
4142 fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK);
4143
4144 ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,
4145 processWakeupCallback, NULL);
4146
4147 rilEventAddWakeup (&s_wakeupfd_event);
4148
4149 // Only returns on error
4150 ril_event_loop();
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004151 RLOGE ("error in event_loop_base errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004152 // kill self to restart on error
4153 kill(0, SIGKILL);
4154
4155 return NULL;
4156}
4157
4158extern "C" void
4159RIL_startEventLoop(void) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004160 /* spin up eventLoop thread and wait for it to get started */
4161 s_started = 0;
4162 pthread_mutex_lock(&s_startupMutex);
4163
Howard Sue32dbfd2015-01-07 15:55:57 +08004164 pthread_attr_t attr;
4165 pthread_attr_init(&attr);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004166 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
Howard Sue32dbfd2015-01-07 15:55:57 +08004167
4168 int result = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
4169 if (result != 0) {
4170 RLOGE("Failed to create dispatch thread: %s", strerror(result));
4171 goto done;
4172 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004173
4174 while (s_started == 0) {
4175 pthread_cond_wait(&s_startupCond, &s_startupMutex);
4176 }
4177
Howard Sue32dbfd2015-01-07 15:55:57 +08004178done:
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004179 pthread_mutex_unlock(&s_startupMutex);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004180}
4181
4182// Used for testing purpose only.
4183extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) {
4184 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4185}
4186
Howard Sue32dbfd2015-01-07 15:55:57 +08004187static void startListen(RIL_SOCKET_ID socket_id, SocketListenParam* socket_listen_p) {
4188 int fdListen = -1;
4189 int ret;
4190 char socket_name[10];
4191
4192 memset(socket_name, 0, sizeof(char)*10);
4193
4194 switch(socket_id) {
4195 case RIL_SOCKET_1:
4196 strncpy(socket_name, RIL_getRilSocketName(), 9);
4197 break;
4198 #if (SIM_COUNT >= 2)
4199 case RIL_SOCKET_2:
4200 strncpy(socket_name, SOCKET2_NAME_RIL, 9);
4201 break;
4202 #endif
4203 #if (SIM_COUNT >= 3)
4204 case RIL_SOCKET_3:
4205 strncpy(socket_name, SOCKET3_NAME_RIL, 9);
4206 break;
4207 #endif
4208 #if (SIM_COUNT >= 4)
4209 case RIL_SOCKET_4:
4210 strncpy(socket_name, SOCKET4_NAME_RIL, 9);
4211 break;
4212 #endif
4213 default:
4214 RLOGE("Socket id is wrong!!");
4215 return;
4216 }
4217
4218 RLOGI("Start to listen %s", rilSocketIdToString(socket_id));
4219
4220 fdListen = android_get_control_socket(socket_name);
4221 if (fdListen < 0) {
4222 RLOGE("Failed to get socket %s", socket_name);
4223 exit(-1);
4224 }
4225
4226 ret = listen(fdListen, 4);
4227
4228 if (ret < 0) {
4229 RLOGE("Failed to listen on control socket '%d': %s",
4230 fdListen, strerror(errno));
4231 exit(-1);
4232 }
4233 socket_listen_p->fdListen = fdListen;
4234
4235 /* note: non-persistent so we can accept only one connection at a time */
4236 ril_event_set (socket_listen_p->listen_event, fdListen, false,
4237 listenCallback, socket_listen_p);
4238
4239 rilEventAddWakeup (socket_listen_p->listen_event);
4240}
4241
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004242extern "C" void
4243RIL_register (const RIL_RadioFunctions *callbacks) {
4244 int ret;
4245 int flags;
4246
Howard Sue32dbfd2015-01-07 15:55:57 +08004247 RLOGI("SIM_COUNT: %d", SIM_COUNT);
4248
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004249 if (callbacks == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004250 RLOGE("RIL_register: RIL_RadioFunctions * null");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004251 return;
4252 }
4253 if (callbacks->version < RIL_VERSION_MIN) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004254 RLOGE("RIL_register: version %d is to old, min version is %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004255 callbacks->version, RIL_VERSION_MIN);
4256 return;
4257 }
4258 if (callbacks->version > RIL_VERSION) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004259 RLOGE("RIL_register: version %d is too new, max version is %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004260 callbacks->version, RIL_VERSION);
4261 return;
4262 }
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004263 RLOGE("RIL_register: RIL version %d", callbacks->version);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004264
4265 if (s_registerCalled > 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004266 RLOGE("RIL_register has been called more than once. "
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004267 "Subsequent call ignored");
4268 return;
4269 }
4270
4271 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4272
Howard Sue32dbfd2015-01-07 15:55:57 +08004273 /* Initialize socket1 parameters */
4274 s_ril_param_socket = {
4275 RIL_SOCKET_1, /* socket_id */
4276 -1, /* fdListen */
4277 -1, /* fdCommand */
4278 PHONE_PROCESS, /* processName */
4279 &s_commands_event, /* commands_event */
4280 &s_listen_event, /* listen_event */
4281 processCommandsCallback, /* processCommandsCallback */
4282 NULL /* p_rs */
4283 };
4284
4285#if (SIM_COUNT >= 2)
4286 s_ril_param_socket2 = {
4287 RIL_SOCKET_2, /* socket_id */
4288 -1, /* fdListen */
4289 -1, /* fdCommand */
4290 PHONE_PROCESS, /* processName */
4291 &s_commands_event_socket2, /* commands_event */
4292 &s_listen_event_socket2, /* listen_event */
4293 processCommandsCallback, /* processCommandsCallback */
4294 NULL /* p_rs */
4295 };
4296#endif
4297
4298#if (SIM_COUNT >= 3)
4299 s_ril_param_socket3 = {
4300 RIL_SOCKET_3, /* socket_id */
4301 -1, /* fdListen */
4302 -1, /* fdCommand */
4303 PHONE_PROCESS, /* processName */
4304 &s_commands_event_socket3, /* commands_event */
4305 &s_listen_event_socket3, /* listen_event */
4306 processCommandsCallback, /* processCommandsCallback */
4307 NULL /* p_rs */
4308 };
4309#endif
4310
4311#if (SIM_COUNT >= 4)
4312 s_ril_param_socket4 = {
4313 RIL_SOCKET_4, /* socket_id */
4314 -1, /* fdListen */
4315 -1, /* fdCommand */
4316 PHONE_PROCESS, /* processName */
4317 &s_commands_event_socket4, /* commands_event */
4318 &s_listen_event_socket4, /* listen_event */
4319 processCommandsCallback, /* processCommandsCallback */
4320 NULL /* p_rs */
4321 };
4322#endif
4323
Howard Subd82ef12015-04-12 10:25:05 +02004324
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004325 s_registerCalled = 1;
4326
Howard Sue32dbfd2015-01-07 15:55:57 +08004327 RLOGI("s_registerCalled flag set, %d", s_started);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004328 // Little self-check
4329
4330 for (int i = 0; i < (int)NUM_ELEMS(s_commands); i++) {
4331 assert(i == s_commands[i].requestNumber);
4332 }
4333
Howard Subd82ef12015-04-12 10:25:05 +02004334 for (int i = 0; i < (int)NUM_ELEMS(s_commands_v); i++) {
4335 assert(i + RIL_VENDOR_COMMANDS_OFFSET == s_commands[i].requestNumber);
4336 }
4337
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004338 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses); i++) {
Howard Sue32dbfd2015-01-07 15:55:57 +08004339 assert(i + RIL_UNSOL_RESPONSE_BASE
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004340 == s_unsolResponses[i].requestNumber);
4341 }
4342
Howard Subd82ef12015-04-12 10:25:05 +02004343 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses_v); i++) {
4344 assert(i + RIL_UNSOL_RESPONSE_BASE + RIL_VENDOR_COMMANDS_OFFSET
4345 == s_unsolResponses[i].requestNumber);
4346 }
4347
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004348 // New rild impl calls RIL_startEventLoop() first
4349 // old standalone impl wants it here.
4350
4351 if (s_started == 0) {
4352 RIL_startEventLoop();
4353 }
4354
Howard Sue32dbfd2015-01-07 15:55:57 +08004355 // start listen socket1
4356 startListen(RIL_SOCKET_1, &s_ril_param_socket);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004357
Howard Sue32dbfd2015-01-07 15:55:57 +08004358#if (SIM_COUNT >= 2)
4359 // start listen socket2
4360 startListen(RIL_SOCKET_2, &s_ril_param_socket2);
4361#endif /* (SIM_COUNT == 2) */
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004362
Howard Sue32dbfd2015-01-07 15:55:57 +08004363#if (SIM_COUNT >= 3)
4364 // start listen socket3
4365 startListen(RIL_SOCKET_3, &s_ril_param_socket3);
4366#endif /* (SIM_COUNT == 3) */
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004367
Howard Sue32dbfd2015-01-07 15:55:57 +08004368#if (SIM_COUNT >= 4)
4369 // start listen socket4
4370 startListen(RIL_SOCKET_4, &s_ril_param_socket4);
4371#endif /* (SIM_COUNT == 4) */
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004372
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004373
4374#if 1
4375 // start debug interface socket
4376
Howard Sue32dbfd2015-01-07 15:55:57 +08004377 char *inst = NULL;
4378 if (strlen(RIL_getRilSocketName()) >= strlen(SOCKET_NAME_RIL)) {
4379 inst = RIL_getRilSocketName() + strlen(SOCKET_NAME_RIL);
4380 }
4381
4382 char rildebug[MAX_DEBUG_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL_DEBUG;
4383 if (inst != NULL) {
4384 strncat(rildebug, inst, MAX_DEBUG_SOCKET_NAME_LENGTH);
4385 }
4386
4387 s_fdDebug = android_get_control_socket(rildebug);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004388 if (s_fdDebug < 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08004389 RLOGE("Failed to get socket : %s errno:%d", rildebug, errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004390 exit(-1);
4391 }
4392
4393 ret = listen(s_fdDebug, 4);
4394
4395 if (ret < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004396 RLOGE("Failed to listen on ril debug socket '%d': %s",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004397 s_fdDebug, strerror(errno));
4398 exit(-1);
4399 }
4400
4401 ril_event_set (&s_debug_event, s_fdDebug, true,
4402 debugCallback, NULL);
4403
4404 rilEventAddWakeup (&s_debug_event);
4405#endif
4406
4407}
4408
4409static int
4410checkAndDequeueRequestInfo(struct RequestInfo *pRI) {
4411 int ret = 0;
Howard Sue32dbfd2015-01-07 15:55:57 +08004412 /* Hook for current context
4413 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
4414 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
4415 /* pendingRequestsHook refer to &s_pendingRequests */
4416 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004417
4418 if (pRI == NULL) {
4419 return 0;
4420 }
4421
Howard Sue32dbfd2015-01-07 15:55:57 +08004422#if (SIM_COUNT >= 2)
4423 if (pRI->socket_id == RIL_SOCKET_2) {
4424 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
4425 pendingRequestsHook = &s_pendingRequests_socket2;
4426 }
4427#if (SIM_COUNT >= 3)
4428 if (pRI->socket_id == RIL_SOCKET_3) {
4429 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
4430 pendingRequestsHook = &s_pendingRequests_socket3;
4431 }
4432#endif
4433#if (SIM_COUNT >= 4)
4434 if (pRI->socket_id == RIL_SOCKET_4) {
4435 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
4436 pendingRequestsHook = &s_pendingRequests_socket4;
4437 }
4438#endif
4439#endif
4440 pthread_mutex_lock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004441
Howard Sue32dbfd2015-01-07 15:55:57 +08004442 for(RequestInfo **ppCur = pendingRequestsHook
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004443 ; *ppCur != NULL
4444 ; ppCur = &((*ppCur)->p_next)
4445 ) {
4446 if (pRI == *ppCur) {
4447 ret = 1;
4448
4449 *ppCur = (*ppCur)->p_next;
4450 break;
4451 }
4452 }
4453
Howard Sue32dbfd2015-01-07 15:55:57 +08004454 pthread_mutex_unlock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004455
4456 return ret;
4457}
4458
4459
4460extern "C" void
4461RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) {
4462 RequestInfo *pRI;
4463 int ret;
Howard Sue32dbfd2015-01-07 15:55:57 +08004464 int fd = s_ril_param_socket.fdCommand;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004465 size_t errorOffset;
Howard Sue32dbfd2015-01-07 15:55:57 +08004466 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004467
4468 pRI = (RequestInfo *)t;
4469
4470 if (!checkAndDequeueRequestInfo(pRI)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004471 RLOGE ("RIL_onRequestComplete: invalid RIL_Token");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004472 return;
4473 }
4474
Howard Sue32dbfd2015-01-07 15:55:57 +08004475 socket_id = pRI->socket_id;
4476#if (SIM_COUNT >= 2)
4477 if (socket_id == RIL_SOCKET_2) {
4478 fd = s_ril_param_socket2.fdCommand;
4479 }
4480#if (SIM_COUNT >= 3)
4481 if (socket_id == RIL_SOCKET_3) {
4482 fd = s_ril_param_socket3.fdCommand;
4483 }
4484#endif
4485#if (SIM_COUNT >= 4)
4486 if (socket_id == RIL_SOCKET_4) {
4487 fd = s_ril_param_socket4.fdCommand;
4488 }
4489#endif
4490#endif
4491 RLOGD("RequestComplete, %s", rilSocketIdToString(socket_id));
4492
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004493 if (pRI->local > 0) {
4494 // Locally issued command...void only!
4495 // response does not go back up the command socket
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004496 RLOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004497
4498 goto done;
4499 }
4500
4501 appendPrintBuf("[%04d]< %s",
4502 pRI->token, requestToString(pRI->pCI->requestNumber));
4503
4504 if (pRI->cancelled == 0) {
4505 Parcel p;
4506
4507 p.writeInt32 (RESPONSE_SOLICITED);
4508 p.writeInt32 (pRI->token);
4509 errorOffset = p.dataPosition();
4510
4511 p.writeInt32 (e);
4512
4513 if (response != NULL) {
4514 // there is a response payload, no matter success or not.
4515 ret = pRI->pCI->responseFunction(p, response, responselen);
4516
4517 /* if an error occurred, rewind and mark it */
4518 if (ret != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08004519 RLOGE ("responseFunction error, ret %d", ret);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004520 p.setDataPosition(errorOffset);
4521 p.writeInt32 (ret);
4522 }
4523 }
4524
4525 if (e != RIL_E_SUCCESS) {
4526 appendPrintBuf("%s fails by %s", printBuf, failCauseToString(e));
4527 }
4528
Howard Sue32dbfd2015-01-07 15:55:57 +08004529 if (fd < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004530 RLOGD ("RIL onRequestComplete: Command channel closed");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004531 }
Howard Sue32dbfd2015-01-07 15:55:57 +08004532 sendResponse(p, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004533 }
4534
4535done:
4536 free(pRI);
4537}
4538
Howard Subd82ef12015-04-12 10:25:05 +02004539
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004540static void
4541grabPartialWakeLock() {
4542 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
4543}
4544
4545static void
4546releaseWakeLock() {
4547 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
4548}
4549
4550/**
4551 * Timer callback to put us back to sleep before the default timeout
4552 */
4553static void
4554wakeTimeoutCallback (void *param) {
4555 // We're using "param != NULL" as a cancellation mechanism
4556 if (param == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004557 //RLOGD("wakeTimeout: releasing wake lock");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004558
4559 releaseWakeLock();
4560 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004561 //RLOGD("wakeTimeout: releasing wake lock CANCELLED");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004562 }
4563}
4564
4565static int
4566decodeVoiceRadioTechnology (RIL_RadioState radioState) {
4567 switch (radioState) {
4568 case RADIO_STATE_SIM_NOT_READY:
4569 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4570 case RADIO_STATE_SIM_READY:
4571 return RADIO_TECH_UMTS;
4572
4573 case RADIO_STATE_RUIM_NOT_READY:
4574 case RADIO_STATE_RUIM_READY:
4575 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4576 case RADIO_STATE_NV_NOT_READY:
4577 case RADIO_STATE_NV_READY:
4578 return RADIO_TECH_1xRTT;
4579
4580 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004581 RLOGD("decodeVoiceRadioTechnology: Invoked with incorrect RadioState");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004582 return -1;
4583 }
4584}
4585
4586static int
4587decodeCdmaSubscriptionSource (RIL_RadioState radioState) {
4588 switch (radioState) {
4589 case RADIO_STATE_SIM_NOT_READY:
4590 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4591 case RADIO_STATE_SIM_READY:
4592 case RADIO_STATE_RUIM_NOT_READY:
4593 case RADIO_STATE_RUIM_READY:
4594 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4595 return CDMA_SUBSCRIPTION_SOURCE_RUIM_SIM;
4596
4597 case RADIO_STATE_NV_NOT_READY:
4598 case RADIO_STATE_NV_READY:
4599 return CDMA_SUBSCRIPTION_SOURCE_NV;
4600
4601 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004602 RLOGD("decodeCdmaSubscriptionSource: Invoked with incorrect RadioState");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004603 return -1;
4604 }
4605}
4606
4607static int
4608decodeSimStatus (RIL_RadioState radioState) {
4609 switch (radioState) {
4610 case RADIO_STATE_SIM_NOT_READY:
4611 case RADIO_STATE_RUIM_NOT_READY:
4612 case RADIO_STATE_NV_NOT_READY:
4613 case RADIO_STATE_NV_READY:
4614 return -1;
4615 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4616 case RADIO_STATE_SIM_READY:
4617 case RADIO_STATE_RUIM_READY:
4618 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4619 return radioState;
4620 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004621 RLOGD("decodeSimStatus: Invoked with incorrect RadioState");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004622 return -1;
4623 }
4624}
4625
4626static bool is3gpp2(int radioTech) {
4627 switch (radioTech) {
4628 case RADIO_TECH_IS95A:
4629 case RADIO_TECH_IS95B:
4630 case RADIO_TECH_1xRTT:
4631 case RADIO_TECH_EVDO_0:
4632 case RADIO_TECH_EVDO_A:
4633 case RADIO_TECH_EVDO_B:
4634 case RADIO_TECH_EHRPD:
4635 return true;
4636 default:
4637 return false;
4638 }
4639}
4640
4641/* If RIL sends SIM states or RUIM states, store the voice radio
4642 * technology and subscription source information so that they can be
4643 * returned when telephony framework requests them
4644 */
4645static RIL_RadioState
Howard Subd82ef12015-04-12 10:25:05 +02004646processRadioState(RIL_RadioState newRadioState, RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004647
4648 if((newRadioState > RADIO_STATE_UNAVAILABLE) && (newRadioState < RADIO_STATE_ON)) {
4649 int newVoiceRadioTech;
4650 int newCdmaSubscriptionSource;
4651 int newSimStatus;
4652
4653 /* This is old RIL. Decode Subscription source and Voice Radio Technology
4654 from Radio State and send change notifications if there has been a change */
4655 newVoiceRadioTech = decodeVoiceRadioTechnology(newRadioState);
4656 if(newVoiceRadioTech != voiceRadioTech) {
4657 voiceRadioTech = newVoiceRadioTech;
Howard Sue32dbfd2015-01-07 15:55:57 +08004658 RIL_UNSOL_RESPONSE(RIL_UNSOL_VOICE_RADIO_TECH_CHANGED,
4659 &voiceRadioTech, sizeof(voiceRadioTech), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004660 }
4661 if(is3gpp2(newVoiceRadioTech)) {
4662 newCdmaSubscriptionSource = decodeCdmaSubscriptionSource(newRadioState);
4663 if(newCdmaSubscriptionSource != cdmaSubscriptionSource) {
4664 cdmaSubscriptionSource = newCdmaSubscriptionSource;
Howard Sue32dbfd2015-01-07 15:55:57 +08004665 RIL_UNSOL_RESPONSE(RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED,
4666 &cdmaSubscriptionSource, sizeof(cdmaSubscriptionSource), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004667 }
4668 }
4669 newSimStatus = decodeSimStatus(newRadioState);
4670 if(newSimStatus != simRuimStatus) {
4671 simRuimStatus = newSimStatus;
Howard Sue32dbfd2015-01-07 15:55:57 +08004672 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004673 }
4674
4675 /* Send RADIO_ON to telephony */
4676 newRadioState = RADIO_STATE_ON;
4677 }
4678
4679 return newRadioState;
4680}
4681
Howard Subd82ef12015-04-12 10:25:05 +02004682
Howard Sue32dbfd2015-01-07 15:55:57 +08004683#if defined(ANDROID_MULTI_SIM)
4684extern "C"
Howard Subd82ef12015-04-12 10:25:05 +02004685void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
Howard Sue32dbfd2015-01-07 15:55:57 +08004686 size_t datalen, RIL_SOCKET_ID socket_id)
4687#else
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004688extern "C"
Howard Subd82ef12015-04-12 10:25:05 +02004689void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004690 size_t datalen)
Howard Sue32dbfd2015-01-07 15:55:57 +08004691#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004692{
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004693 int ret;
4694 int64_t timeReceived = 0;
4695 bool shouldScheduleTimeout = false;
4696 RIL_RadioState newState;
Howard Sue32dbfd2015-01-07 15:55:57 +08004697 RIL_SOCKET_ID soc_id = RIL_SOCKET_1;
Howard Subd82ef12015-04-12 10:25:05 +02004698 UnsolResponseInfo *pRI = NULL;
Howard Sue32dbfd2015-01-07 15:55:57 +08004699
4700#if defined(ANDROID_MULTI_SIM)
4701 soc_id = socket_id;
4702#endif
4703
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004704
4705 if (s_registerCalled == 0) {
4706 // Ignore RIL_onUnsolicitedResponse before RIL_register
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004707 RLOGW("RIL_onUnsolicitedResponse called before RIL_register");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004708 return;
4709 }
Howard Sue32dbfd2015-01-07 15:55:57 +08004710
Howard Subd82ef12015-04-12 10:25:05 +02004711 /* Hack to include Samsung responses */
4712 if (unsolResponse > RIL_VENDOR_COMMANDS_OFFSET + RIL_UNSOL_RESPONSE_BASE) {
4713 int index = unsolResponse - RIL_VENDOR_COMMANDS_OFFSET - RIL_UNSOL_RESPONSE_BASE;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004714
Howard Subd82ef12015-04-12 10:25:05 +02004715 RLOGD("SAMSUNG: unsolResponse=%d, unsolResponseIndex=%d", unsolResponse, index);
4716
4717 if (index < (int32_t)NUM_ELEMS(s_unsolResponses_v))
4718 pRI = &s_unsolResponses_v[index];
4719 } else {
4720 int index = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
4721 if (index < (int32_t)NUM_ELEMS(s_unsolResponses))
4722 pRI = &s_unsolResponses[index];
4723 }
4724
4725 if (pRI == NULL || pRI->responseFunction == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004726 RLOGE("unsupported unsolicited response code %d", unsolResponse);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004727 return;
4728 }
4729
4730 // Grab a wake lock if needed for this reponse,
4731 // as we exit we'll either release it immediately
4732 // or set a timer to release it later.
Howard Subd82ef12015-04-12 10:25:05 +02004733 switch (pRI->wakeType) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004734 case WAKE_PARTIAL:
4735 grabPartialWakeLock();
4736 shouldScheduleTimeout = true;
4737 break;
4738
4739 case DONT_WAKE:
4740 default:
4741 // No wake lock is grabed so don't set timeout
4742 shouldScheduleTimeout = false;
4743 break;
4744 }
4745
4746 // Mark the time this was received, doing this
4747 // after grabing the wakelock incase getting
4748 // the elapsedRealTime might cause us to goto
4749 // sleep.
4750 if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4751 timeReceived = elapsedRealtime();
4752 }
4753
4754 appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
4755
4756 Parcel p;
4757
4758 p.writeInt32 (RESPONSE_UNSOLICITED);
4759 p.writeInt32 (unsolResponse);
4760
Howard Subd82ef12015-04-12 10:25:05 +02004761 ret = pRI->responseFunction(p, const_cast<void*>(data), datalen);
4762
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004763 if (ret != 0) {
4764 // Problem with the response. Don't continue;
4765 goto error_exit;
4766 }
4767
4768 // some things get more payload
4769 switch(unsolResponse) {
4770 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
Howard Sue32dbfd2015-01-07 15:55:57 +08004771 newState = processRadioState(CALL_ONSTATEREQUEST(soc_id), soc_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004772 p.writeInt32(newState);
4773 appendPrintBuf("%s {%s}", printBuf,
Howard Sue32dbfd2015-01-07 15:55:57 +08004774 radioStateToString(CALL_ONSTATEREQUEST(soc_id)));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004775 break;
4776
4777
4778 case RIL_UNSOL_NITZ_TIME_RECEIVED:
4779 // Store the time that this was received so the
4780 // handler of this message can account for
4781 // the time it takes to arrive and process. In
4782 // particular the system has been known to sleep
4783 // before this message can be processed.
4784 p.writeInt64(timeReceived);
4785 break;
4786 }
4787
Howard Sue32dbfd2015-01-07 15:55:57 +08004788 RLOGI("%s UNSOLICITED: %s length:%d", rilSocketIdToString(soc_id), requestToString(unsolResponse), p.dataSize());
4789 ret = sendResponse(p, soc_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004790 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4791
4792 // Unfortunately, NITZ time is not poll/update like everything
4793 // else in the system. So, if the upstream client isn't connected,
4794 // keep a copy of the last NITZ response (with receive time noted
4795 // above) around so we can deliver it when it is connected
4796
4797 if (s_lastNITZTimeData != NULL) {
4798 free (s_lastNITZTimeData);
4799 s_lastNITZTimeData = NULL;
4800 }
4801
4802 s_lastNITZTimeData = malloc(p.dataSize());
4803 s_lastNITZTimeDataSize = p.dataSize();
4804 memcpy(s_lastNITZTimeData, p.data(), p.dataSize());
4805 }
4806
4807 // For now, we automatically go back to sleep after TIMEVAL_WAKE_TIMEOUT
4808 // FIXME The java code should handshake here to release wake lock
4809
4810 if (shouldScheduleTimeout) {
4811 // Cancel the previous request
4812 if (s_last_wake_timeout_info != NULL) {
4813 s_last_wake_timeout_info->userParam = (void *)1;
4814 }
4815
4816 s_last_wake_timeout_info
4817 = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
4818 &TIMEVAL_WAKE_TIMEOUT);
4819 }
4820
4821 // Normal exit
4822 return;
4823
4824error_exit:
4825 if (shouldScheduleTimeout) {
4826 releaseWakeLock();
4827 }
4828}
4829
4830/** FIXME generalize this if you track UserCAllbackInfo, clear it
4831 when the callback occurs
4832*/
4833static UserCallbackInfo *
4834internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
4835 const struct timeval *relativeTime)
4836{
4837 struct timeval myRelativeTime;
4838 UserCallbackInfo *p_info;
4839
4840 p_info = (UserCallbackInfo *) malloc (sizeof(UserCallbackInfo));
4841
4842 p_info->p_callback = callback;
4843 p_info->userParam = param;
4844
4845 if (relativeTime == NULL) {
4846 /* treat null parameter as a 0 relative time */
4847 memset (&myRelativeTime, 0, sizeof(myRelativeTime));
4848 } else {
4849 /* FIXME I think event_add's tv param is really const anyway */
4850 memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
4851 }
4852
4853 ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
4854
4855 ril_timer_add(&(p_info->event), &myRelativeTime);
4856
4857 triggerEvLoop();
4858 return p_info;
4859}
4860
4861
4862extern "C" void
4863RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
4864 const struct timeval *relativeTime) {
4865 internalRequestTimedCallback (callback, param, relativeTime);
4866}
4867
4868const char *
4869failCauseToString(RIL_Errno e) {
4870 switch(e) {
4871 case RIL_E_SUCCESS: return "E_SUCCESS";
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004872 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RADIO_NOT_AVAILABLE";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004873 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
4874 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
4875 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
4876 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
4877 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
4878 case RIL_E_CANCELLED: return "E_CANCELLED";
4879 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
4880 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
4881 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
4882 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
4883 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
4884#ifdef FEATURE_MULTIMODE_ANDROID
4885 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
4886 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
4887#endif
4888 default: return "<unknown error>";
4889 }
4890}
4891
4892const char *
4893radioStateToString(RIL_RadioState s) {
4894 switch(s) {
4895 case RADIO_STATE_OFF: return "RADIO_OFF";
4896 case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
4897 case RADIO_STATE_SIM_NOT_READY: return "RADIO_SIM_NOT_READY";
4898 case RADIO_STATE_SIM_LOCKED_OR_ABSENT: return "RADIO_SIM_LOCKED_OR_ABSENT";
4899 case RADIO_STATE_SIM_READY: return "RADIO_SIM_READY";
4900 case RADIO_STATE_RUIM_NOT_READY:return"RADIO_RUIM_NOT_READY";
4901 case RADIO_STATE_RUIM_READY:return"RADIO_RUIM_READY";
4902 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:return"RADIO_RUIM_LOCKED_OR_ABSENT";
4903 case RADIO_STATE_NV_NOT_READY:return"RADIO_NV_NOT_READY";
4904 case RADIO_STATE_NV_READY:return"RADIO_NV_READY";
4905 case RADIO_STATE_ON:return"RADIO_ON";
4906 default: return "<unknown state>";
4907 }
4908}
4909
4910const char *
4911callStateToString(RIL_CallState s) {
4912 switch(s) {
4913 case RIL_CALL_ACTIVE : return "ACTIVE";
4914 case RIL_CALL_HOLDING: return "HOLDING";
4915 case RIL_CALL_DIALING: return "DIALING";
4916 case RIL_CALL_ALERTING: return "ALERTING";
4917 case RIL_CALL_INCOMING: return "INCOMING";
4918 case RIL_CALL_WAITING: return "WAITING";
4919 default: return "<unknown state>";
4920 }
4921}
4922
4923const char *
4924requestToString(int request) {
4925/*
4926 cat libs/telephony/ril_commands.h \
4927 | egrep "^ *{RIL_" \
4928 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
4929
4930
4931 cat libs/telephony/ril_unsol_commands.h \
4932 | egrep "^ *{RIL_" \
4933 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
4934
4935*/
4936 switch(request) {
4937 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
4938 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
4939 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
4940 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
4941 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
4942 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
4943 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
4944 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
4945 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
4946 case RIL_REQUEST_DIAL: return "DIAL";
4947 case RIL_REQUEST_DIAL_EMERGENCY: return "DIAL";
4948 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
4949 case RIL_REQUEST_HANGUP: return "HANGUP";
4950 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
4951 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
4952 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
4953 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
4954 case RIL_REQUEST_UDUB: return "UDUB";
4955 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
4956 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
4957 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
4958 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
4959 case RIL_REQUEST_OPERATOR: return "OPERATOR";
4960 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
4961 case RIL_REQUEST_DTMF: return "DTMF";
4962 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
4963 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
4964 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
4965 case RIL_REQUEST_SIM_IO: return "SIM_IO";
4966 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
4967 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
4968 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
4969 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
4970 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
4971 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
4972 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
4973 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
4974 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
4975 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
4976 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
4977 case RIL_REQUEST_ANSWER: return "ANSWER";
4978 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
4979 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
4980 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
4981 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
4982 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
4983 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
4984 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
4985 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";
4986 case RIL_REQUEST_DTMF_START: return "DTMF_START";
4987 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
4988 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
4989 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
4990 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
4991 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
4992 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
4993 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
4994 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
4995 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
4996 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
4997 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
4998 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
4999 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
5000 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
5001 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
5002 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
5003 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
5004 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
5005 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
5006 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
5007 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
5008 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
5009 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
5010 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005011 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE:return"CDMA_SET_SUBSCRIPTION_SOURCE";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005012 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"CDMA_SET_ROAMING_PREFERENCE";
5013 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"CDMA_QUERY_ROAMING_PREFERENCE";
5014 case RIL_REQUEST_SET_TTY_MODE:return"SET_TTY_MODE";
5015 case RIL_REQUEST_QUERY_TTY_MODE:return"QUERY_TTY_MODE";
5016 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
5017 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
5018 case RIL_REQUEST_CDMA_FLASH:return"CDMA_FLASH";
5019 case RIL_REQUEST_CDMA_BURST_DTMF:return"CDMA_BURST_DTMF";
5020 case RIL_REQUEST_CDMA_SEND_SMS:return"CDMA_SEND_SMS";
5021 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:return"CDMA_SMS_ACKNOWLEDGE";
5022 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG:return"GSM_GET_BROADCAST_SMS_CONFIG";
5023 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG:return"GSM_SET_BROADCAST_SMS_CONFIG";
5024 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG:return "CDMA_GET_BROADCAST_SMS_CONFIG";
5025 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG:return "CDMA_SET_BROADCAST_SMS_CONFIG";
5026 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION:return "CDMA_SMS_BROADCAST_ACTIVATION";
Ethan Chend6e30652013-08-04 22:49:56 -07005027 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return"CDMA_VALIDATE_AND_WRITE_AKEY";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005028 case RIL_REQUEST_CDMA_SUBSCRIPTION: return"CDMA_SUBSCRIPTION";
5029 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
5030 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
5031 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
5032 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
5033 case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
5034 case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
5035 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
5036 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
5037 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
5038 case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
5039 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
5040 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
5041 case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005042 case RIL_REQUEST_GET_CELL_INFO_LIST: return"GET_CELL_INFO_LIST";
5043 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return"SET_UNSOL_CELL_INFO_LIST_RATE";
Andrew Jiangca4a9a02014-01-18 18:04:08 -05005044 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "RIL_REQUEST_SET_INITIAL_ATTACH_APN";
5045 case RIL_REQUEST_IMS_REGISTRATION_STATE: return "IMS_REGISTRATION_STATE";
5046 case RIL_REQUEST_IMS_SEND_SMS: return "IMS_SEND_SMS";
Howard Sue32dbfd2015-01-07 15:55:57 +08005047 case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "SIM_TRANSMIT_APDU_BASIC";
5048 case RIL_REQUEST_SIM_OPEN_CHANNEL: return "SIM_OPEN_CHANNEL";
5049 case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "SIM_CLOSE_CHANNEL";
5050 case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "SIM_TRANSMIT_APDU_CHANNEL";
Howard Subd82ef12015-04-12 10:25:05 +02005051 case RIL_REQUEST_GET_RADIO_CAPABILITY: return "RIL_REQUEST_GET_RADIO_CAPABILITY";
5052 case RIL_REQUEST_SET_RADIO_CAPABILITY: return "RIL_REQUEST_SET_RADIO_CAPABILITY";
Howard Sue32dbfd2015-01-07 15:55:57 +08005053 case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "SET_UICC_SUBSCRIPTION";
5054 case RIL_REQUEST_ALLOW_DATA: return "ALLOW_DATA";
5055 case RIL_REQUEST_GET_HARDWARE_CONFIG: return "GET_HARDWARE_CONFIG";
5056 case RIL_REQUEST_SIM_AUTHENTICATION: return "SIM_AUTHENTICATION";
5057 case RIL_REQUEST_GET_DC_RT_INFO: return "GET_DC_RT_INFO";
5058 case RIL_REQUEST_SET_DC_RT_INFO_RATE: return "SET_DC_RT_INFO_RATE";
5059 case RIL_REQUEST_SET_DATA_PROFILE: return "SET_DATA_PROFILE";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005060 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
5061 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
5062 case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED";
5063 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
5064 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
5065 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
5066 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
5067 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)";
5068 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
5069 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
Howard Subd82ef12015-04-12 10:25:05 +02005070 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
5071 case RIL_UNSOL_SUPP_SVC_NOTIFICATION: return "UNSOL_SUPP_SVC_NOTIFICATION";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005072 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
5073 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
5074 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
5075 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
5076 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL";
5077 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005078 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
5079 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
5080 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_NEW_CDMA_SMS";
5081 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_NEW_BROADCAST_SMS";
5082 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
5083 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
5084 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
5085 case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
5086 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
5087 case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
5088 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
5089 case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
5090 case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
5091 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
5092 case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
5093 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
5094 case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
5095 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
Ethan Chend6e30652013-08-04 22:49:56 -07005096 case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
Andrew Jiangca4a9a02014-01-18 18:04:08 -05005097 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "RESPONSE_IMS_NETWORK_STATE_CHANGED";
Howard Sue32dbfd2015-01-07 15:55:57 +08005098 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return "UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED";
5099 case RIL_UNSOL_SRVCC_STATE_NOTIFY: return "UNSOL_SRVCC_STATE_NOTIFY";
5100 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return "HARDWARE_CONFIG_CHANGED";
5101 case RIL_UNSOL_DC_RT_INFO_CHANGED: return "UNSOL_DC_RT_INFO_CHANGED";
Howard Subd82ef12015-04-12 10:25:05 +02005102 case RIL_UNSOL_RADIO_CAPABILITY: return "UNSOL_RADIO_CAPABILITY";
5103 case RIL_UNSOL_ON_SS: return "UNSOL_ON_SS";
5104 case RIL_UNSOL_STK_CC_ALPHA_NOTIFY: return "UNSOL_STK_CC_ALPHA_NOTIFY";
Howard Sue32dbfd2015-01-07 15:55:57 +08005105 case RIL_REQUEST_SHUTDOWN: return "SHUTDOWN";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005106 default: return "<unknown request>";
5107 }
5108}
5109
Howard Sue32dbfd2015-01-07 15:55:57 +08005110const char *
5111rilSocketIdToString(RIL_SOCKET_ID socket_id)
5112{
5113 switch(socket_id) {
5114 case RIL_SOCKET_1:
5115 return "RIL_SOCKET_1";
5116#if (SIM_COUNT >= 2)
5117 case RIL_SOCKET_2:
5118 return "RIL_SOCKET_2";
5119#endif
5120#if (SIM_COUNT >= 3)
5121 case RIL_SOCKET_3:
5122 return "RIL_SOCKET_3";
5123#endif
5124#if (SIM_COUNT >= 4)
5125 case RIL_SOCKET_4:
5126 return "RIL_SOCKET_4";
5127#endif
5128 default:
5129 return "not a valid RIL";
5130 }
5131}
5132
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005133} /* namespace android */