blob: f08e3673af169928b5eebe0dca5b40b1cc1c730a [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 Hillenbrand601dc852013-07-07 10:06:59 +0200285static int responseStrings(Parcel &p, void *response, size_t responselen);
286static int responseStringsNetworks(Parcel &p, void *response, size_t responselen);
287static 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 Hillenbrand601dc852013-07-07 10:06:59 +02002227/** response is a char **, pointing to an array of char *'s
2228 The parcel will begin with the version */
2229static int responseStringsWithVersion(int version, Parcel &p, void *response, size_t responselen) {
2230 p.writeInt32(version);
2231 return responseStrings(p, response, responselen);
2232}
2233
2234/** response is a char **, pointing to an array of char *'s */
2235static int responseStrings(Parcel &p, void *response, size_t responselen) {
2236 return responseStrings(p, response, responselen, false);
2237}
2238
2239static int responseStringsNetworks(Parcel &p, void *response, size_t responselen) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002240 return responseStrings(p, response, responselen, true);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002241}
2242
2243/** response is a char **, pointing to an array of char *'s */
2244static int responseStrings(Parcel &p, void *response, size_t responselen, bool network_search) {
2245 int numStrings;
2246
2247 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002248 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002249 return RIL_ERRNO_INVALID_RESPONSE;
2250 }
2251 if (responselen % sizeof(char *) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002252 RLOGE("responseStrings: invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002253 (int)responselen, (int)sizeof(char *));
2254 return RIL_ERRNO_INVALID_RESPONSE;
2255 }
2256
2257 if (response == NULL) {
2258 p.writeInt32 (0);
2259 } else {
2260 char **p_cur = (char **) response;
2261
2262 numStrings = responselen / sizeof(char *);
2263 p.writeInt32 (numStrings);
2264
2265 /* each string*/
2266 startResponse;
2267 for (int i = 0 ; i < numStrings ; i++) {
2268 appendPrintBuf("%s%s,", printBuf, (char*)p_cur[i]);
2269 writeStringToParcel (p, p_cur[i]);
2270 }
2271 removeLastChar;
2272 closeResponse;
2273 }
2274 return 0;
2275}
2276
Howard Subd82ef12015-04-12 10:25:05 +02002277
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002278/**
2279 * NULL strings are accepted
2280 * FIXME currently ignores responselen
2281 */
2282static int responseString(Parcel &p, void *response, size_t responselen) {
2283 /* one string only */
2284 startResponse;
2285 appendPrintBuf("%s%s", printBuf, (char*)response);
2286 closeResponse;
2287
2288 writeStringToParcel(p, (const char *)response);
2289
2290 return 0;
2291}
2292
2293static int responseVoid(Parcel &p, void *response, size_t responselen) {
2294 startResponse;
2295 removeLastChar;
2296 return 0;
2297}
2298
2299static int responseCallList(Parcel &p, void *response, size_t responselen) {
2300 int num;
2301
2302 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002303 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002304 return RIL_ERRNO_INVALID_RESPONSE;
2305 }
2306
2307 if (responselen % sizeof (RIL_Call *) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002308 RLOGE("responseCallList: invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002309 (int)responselen, (int)sizeof (RIL_Call *));
2310 return RIL_ERRNO_INVALID_RESPONSE;
2311 }
2312
2313 startResponse;
2314 /* number of call info's */
2315 num = responselen / sizeof(RIL_Call *);
2316 p.writeInt32(num);
2317
2318 for (int i = 0 ; i < num ; i++) {
2319 RIL_Call *p_cur = ((RIL_Call **) response)[i];
2320 /* each call info */
2321 p.writeInt32(p_cur->state);
2322 p.writeInt32(p_cur->index);
2323 p.writeInt32(p_cur->toa);
2324 p.writeInt32(p_cur->isMpty);
2325 p.writeInt32(p_cur->isMT);
2326 p.writeInt32(p_cur->als);
2327 p.writeInt32(p_cur->isVoice);
Andreas Schneider29472682015-01-01 19:00:04 +01002328
2329#ifdef MODEM_TYPE_XMM7260
2330 p.writeInt32(p_cur->isVideo);
2331
2332 /* Pass CallDetails */
2333 p.writeInt32(0);
2334 p.writeInt32(0);
2335 writeStringToParcel(p, "");
2336#endif
2337
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002338 p.writeInt32(p_cur->isVoicePrivacy);
2339 writeStringToParcel(p, p_cur->number);
2340 p.writeInt32(p_cur->numberPresentation);
2341 writeStringToParcel(p, p_cur->name);
2342 p.writeInt32(p_cur->namePresentation);
2343 // Remove when partners upgrade to version 3
2344 if ((s_callbacks.version < 3) || (p_cur->uusInfo == NULL || p_cur->uusInfo->uusData == NULL)) {
2345 p.writeInt32(0); /* UUS Information is absent */
2346 } else {
2347 RIL_UUS_Info *uusInfo = p_cur->uusInfo;
2348 p.writeInt32(1); /* UUS Information is present */
2349 p.writeInt32(uusInfo->uusType);
2350 p.writeInt32(uusInfo->uusDcs);
2351 p.writeInt32(uusInfo->uusLength);
2352 p.write(uusInfo->uusData, uusInfo->uusLength);
2353 }
2354 appendPrintBuf("%s[id=%d,%s,toa=%d,",
2355 printBuf,
2356 p_cur->index,
2357 callStateToString(p_cur->state),
2358 p_cur->toa);
2359 appendPrintBuf("%s%s,%s,als=%d,%s,%s,",
2360 printBuf,
2361 (p_cur->isMpty)?"conf":"norm",
2362 (p_cur->isMT)?"mt":"mo",
2363 p_cur->als,
2364 (p_cur->isVoice)?"voc":"nonvoc",
2365 (p_cur->isVoicePrivacy)?"evp":"noevp");
Andreas Schneider29472682015-01-01 19:00:04 +01002366#ifdef MODEM_TYPE_XMM7260
2367 appendPrintBuf("%s,%s,",
2368 printBuf,
2369 (p_cur->isVideo) ? "vid" : "novid");
2370#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002371 appendPrintBuf("%s%s,cli=%d,name='%s',%d]",
2372 printBuf,
2373 p_cur->number,
2374 p_cur->numberPresentation,
2375 p_cur->name,
2376 p_cur->namePresentation);
2377 }
2378 removeLastChar;
2379 closeResponse;
2380
2381 return 0;
2382}
2383
2384static int responseSMS(Parcel &p, void *response, size_t responselen) {
2385 if (response == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002386 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002387 return RIL_ERRNO_INVALID_RESPONSE;
2388 }
2389
2390 if (responselen != sizeof (RIL_SMS_Response) ) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002391 RLOGE("invalid response length %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002392 (int)responselen, (int)sizeof (RIL_SMS_Response));
2393 return RIL_ERRNO_INVALID_RESPONSE;
2394 }
2395
2396 RIL_SMS_Response *p_cur = (RIL_SMS_Response *) response;
2397
2398 p.writeInt32(p_cur->messageRef);
2399 writeStringToParcel(p, p_cur->ackPDU);
2400 p.writeInt32(p_cur->errorCode);
2401
2402 startResponse;
2403 appendPrintBuf("%s%d,%s,%d", printBuf, p_cur->messageRef,
2404 (char*)p_cur->ackPDU, p_cur->errorCode);
2405 closeResponse;
2406
2407 return 0;
2408}
2409
2410static int responseDataCallListV4(Parcel &p, void *response, size_t responselen)
2411{
2412 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002413 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002414 return RIL_ERRNO_INVALID_RESPONSE;
2415 }
2416
2417 if (responselen % sizeof(RIL_Data_Call_Response_v4) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002418 RLOGE("responseDataCallListV4: invalid response length %d expected multiple of %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002419 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v4));
2420 return RIL_ERRNO_INVALID_RESPONSE;
2421 }
2422
Howard Sue32dbfd2015-01-07 15:55:57 +08002423 // Write version
2424 p.writeInt32(4);
2425
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002426 int num = responselen / sizeof(RIL_Data_Call_Response_v4);
2427 p.writeInt32(num);
2428
2429 RIL_Data_Call_Response_v4 *p_cur = (RIL_Data_Call_Response_v4 *) response;
2430 startResponse;
2431 int i;
2432 for (i = 0; i < num; i++) {
2433 p.writeInt32(p_cur[i].cid);
2434 p.writeInt32(p_cur[i].active);
2435 writeStringToParcel(p, p_cur[i].type);
2436 // apn is not used, so don't send.
2437 writeStringToParcel(p, p_cur[i].address);
2438 appendPrintBuf("%s[cid=%d,%s,%s,%s],", printBuf,
2439 p_cur[i].cid,
2440 (p_cur[i].active==0)?"down":"up",
2441 (char*)p_cur[i].type,
2442 (char*)p_cur[i].address);
2443 }
2444 removeLastChar;
2445 closeResponse;
2446
2447 return 0;
2448}
2449
Howard Sue32dbfd2015-01-07 15:55:57 +08002450static int responseDataCallListV6(Parcel &p, void *response, size_t responselen)
2451{
2452 if (response == NULL && responselen != 0) {
2453 RLOGE("invalid response: NULL");
2454 return RIL_ERRNO_INVALID_RESPONSE;
2455 }
2456
2457 if (responselen % sizeof(RIL_Data_Call_Response_v6) != 0) {
2458 RLOGE("responseDataCallListV6: invalid response length %d expected multiple of %d",
2459 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v6));
2460 return RIL_ERRNO_INVALID_RESPONSE;
2461 }
2462
2463 // Write version
2464 p.writeInt32(6);
2465
2466 int num = responselen / sizeof(RIL_Data_Call_Response_v6);
2467 p.writeInt32(num);
2468
2469 RIL_Data_Call_Response_v6 *p_cur = (RIL_Data_Call_Response_v6 *) response;
2470 startResponse;
2471 int i;
2472 for (i = 0; i < num; i++) {
2473 p.writeInt32((int)p_cur[i].status);
2474 p.writeInt32(p_cur[i].suggestedRetryTime);
2475 p.writeInt32(p_cur[i].cid);
2476 p.writeInt32(p_cur[i].active);
2477 writeStringToParcel(p, p_cur[i].type);
2478 writeStringToParcel(p, p_cur[i].ifname);
2479 writeStringToParcel(p, p_cur[i].addresses);
2480 writeStringToParcel(p, p_cur[i].dnses);
2481 writeStringToParcel(p, p_cur[i].addresses);
2482 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s],", printBuf,
2483 p_cur[i].status,
2484 p_cur[i].suggestedRetryTime,
2485 p_cur[i].cid,
2486 (p_cur[i].active==0)?"down":"up",
2487 (char*)p_cur[i].type,
2488 (char*)p_cur[i].ifname,
2489 (char*)p_cur[i].addresses,
2490 (char*)p_cur[i].dnses,
2491 (char*)p_cur[i].addresses);
2492 }
2493 removeLastChar;
2494 closeResponse;
2495
2496 return 0;
2497}
2498
Howard Subd82ef12015-04-12 10:25:05 +02002499static int responseDataCallListV9(Parcel &p, void *response, size_t responselen)
2500{
2501 if (response == NULL && responselen != 0) {
2502 RLOGE("invalid response: NULL");
2503 return RIL_ERRNO_INVALID_RESPONSE;
2504 }
2505
2506 if (responselen % sizeof(RIL_Data_Call_Response_v9) != 0) {
2507 RLOGE("responseDataCallListV9: invalid response length %d expected multiple of %d",
2508 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v9));
2509 return RIL_ERRNO_INVALID_RESPONSE;
2510 }
2511
2512 // Write version
2513 p.writeInt32(10);
2514
2515 int num = responselen / sizeof(RIL_Data_Call_Response_v9);
2516 p.writeInt32(num);
2517
2518 RIL_Data_Call_Response_v9 *p_cur = (RIL_Data_Call_Response_v9 *) response;
2519 startResponse;
2520 int i;
2521 for (i = 0; i < num; i++) {
2522 p.writeInt32((int)p_cur[i].status);
2523 p.writeInt32(p_cur[i].suggestedRetryTime);
2524 p.writeInt32(p_cur[i].cid);
2525 p.writeInt32(p_cur[i].active);
2526 writeStringToParcel(p, p_cur[i].type);
2527 writeStringToParcel(p, p_cur[i].ifname);
2528 writeStringToParcel(p, p_cur[i].addresses);
2529 writeStringToParcel(p, p_cur[i].dnses);
2530 writeStringToParcel(p, p_cur[i].gateways);
2531 writeStringToParcel(p, p_cur[i].pcscf);
2532 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s],", printBuf,
2533 p_cur[i].status,
2534 p_cur[i].suggestedRetryTime,
2535 p_cur[i].cid,
2536 (p_cur[i].active==0)?"down":"up",
2537 (char*)p_cur[i].type,
2538 (char*)p_cur[i].ifname,
2539 (char*)p_cur[i].addresses,
2540 (char*)p_cur[i].dnses,
2541 (char*)p_cur[i].gateways,
2542 (char*)p_cur[i].pcscf);
2543 }
2544 removeLastChar;
2545 closeResponse;
2546
2547 return 0;
2548}
2549
2550
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002551static int responseDataCallList(Parcel &p, void *response, size_t responselen)
2552{
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002553 if (s_callbacks.version < 5) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002554 RLOGD("responseDataCallList: v4");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002555 return responseDataCallListV4(p, response, responselen);
Howard Subd82ef12015-04-12 10:25:05 +02002556 } else if (responselen % sizeof(RIL_Data_Call_Response_v6) == 0) {
2557 return responseDataCallListV6(p, response, responselen);
2558 } else if (responselen % sizeof(RIL_Data_Call_Response_v9) == 0) {
2559 return responseDataCallListV9(p, response, responselen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002560 } else {
2561 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002562 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002563 return RIL_ERRNO_INVALID_RESPONSE;
2564 }
2565
Howard Subd82ef12015-04-12 10:25:05 +02002566 if (responselen % sizeof(RIL_Data_Call_Response_v11) != 0) {
2567 RLOGE("invalid response length %d expected multiple of %d",
2568 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v11));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002569 return RIL_ERRNO_INVALID_RESPONSE;
2570 }
2571
Howard Sue32dbfd2015-01-07 15:55:57 +08002572 // Write version
Howard Subd82ef12015-04-12 10:25:05 +02002573 p.writeInt32(11);
Howard Sue32dbfd2015-01-07 15:55:57 +08002574
Howard Subd82ef12015-04-12 10:25:05 +02002575 int num = responselen / sizeof(RIL_Data_Call_Response_v11);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002576 p.writeInt32(num);
2577
Howard Subd82ef12015-04-12 10:25:05 +02002578 RIL_Data_Call_Response_v11 *p_cur = (RIL_Data_Call_Response_v11 *) response;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002579 startResponse;
2580 int i;
2581 for (i = 0; i < num; i++) {
2582 p.writeInt32((int)p_cur[i].status);
2583 p.writeInt32(p_cur[i].suggestedRetryTime);
2584 p.writeInt32(p_cur[i].cid);
2585 p.writeInt32(p_cur[i].active);
2586 writeStringToParcel(p, p_cur[i].type);
2587 writeStringToParcel(p, p_cur[i].ifname);
2588 writeStringToParcel(p, p_cur[i].addresses);
2589 writeStringToParcel(p, p_cur[i].dnses);
Howard Sue32dbfd2015-01-07 15:55:57 +08002590 writeStringToParcel(p, p_cur[i].gateways);
2591 writeStringToParcel(p, p_cur[i].pcscf);
Howard Subd82ef12015-04-12 10:25:05 +02002592 p.writeInt32(p_cur[i].mtu);
2593 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 +02002594 p_cur[i].status,
2595 p_cur[i].suggestedRetryTime,
2596 p_cur[i].cid,
2597 (p_cur[i].active==0)?"down":"up",
2598 (char*)p_cur[i].type,
2599 (char*)p_cur[i].ifname,
2600 (char*)p_cur[i].addresses,
2601 (char*)p_cur[i].dnses,
Howard Sue32dbfd2015-01-07 15:55:57 +08002602 (char*)p_cur[i].gateways,
Howard Subd82ef12015-04-12 10:25:05 +02002603 (char*)p_cur[i].pcscf,
2604 p_cur[i].mtu);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002605 }
2606 removeLastChar;
2607 closeResponse;
2608 }
2609
2610 return 0;
2611}
2612
2613static int responseSetupDataCall(Parcel &p, void *response, size_t responselen)
2614{
2615 if (s_callbacks.version < 5) {
2616 return responseStringsWithVersion(s_callbacks.version, p, response, responselen);
2617 } else {
2618 return responseDataCallList(p, response, responselen);
2619 }
2620}
2621
2622static int responseRaw(Parcel &p, void *response, size_t responselen) {
2623 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002624 RLOGE("invalid response: NULL with responselen != 0");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002625 return RIL_ERRNO_INVALID_RESPONSE;
2626 }
2627
2628 // The java code reads -1 size as null byte array
2629 if (response == NULL) {
2630 p.writeInt32(-1);
2631 } else {
2632 p.writeInt32(responselen);
2633 p.write(response, responselen);
2634 }
2635
2636 return 0;
2637}
2638
2639
2640static int responseSIM_IO(Parcel &p, void *response, size_t responselen) {
2641 if (response == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002642 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002643 return RIL_ERRNO_INVALID_RESPONSE;
2644 }
2645
2646 if (responselen != sizeof (RIL_SIM_IO_Response) ) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002647 RLOGE("invalid response length was %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002648 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
2649 return RIL_ERRNO_INVALID_RESPONSE;
2650 }
2651
2652 RIL_SIM_IO_Response *p_cur = (RIL_SIM_IO_Response *) response;
2653 p.writeInt32(p_cur->sw1);
2654 p.writeInt32(p_cur->sw2);
2655 writeStringToParcel(p, p_cur->simResponse);
2656
2657 startResponse;
2658 appendPrintBuf("%ssw1=0x%X,sw2=0x%X,%s", printBuf, p_cur->sw1, p_cur->sw2,
2659 (char*)p_cur->simResponse);
2660 closeResponse;
2661
2662
2663 return 0;
2664}
2665
2666static int responseCallForwards(Parcel &p, void *response, size_t responselen) {
2667 int num;
2668
2669 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002670 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002671 return RIL_ERRNO_INVALID_RESPONSE;
2672 }
2673
2674 if (responselen % sizeof(RIL_CallForwardInfo *) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002675 RLOGE("responseCallForwards: invalid response length %d expected multiple of %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002676 (int)responselen, (int)sizeof(RIL_CallForwardInfo *));
2677 return RIL_ERRNO_INVALID_RESPONSE;
2678 }
2679
2680 /* number of call info's */
2681 num = responselen / sizeof(RIL_CallForwardInfo *);
2682 p.writeInt32(num);
2683
2684 startResponse;
2685 for (int i = 0 ; i < num ; i++) {
2686 RIL_CallForwardInfo *p_cur = ((RIL_CallForwardInfo **) response)[i];
2687
2688 p.writeInt32(p_cur->status);
2689 p.writeInt32(p_cur->reason);
2690 p.writeInt32(p_cur->serviceClass);
2691 p.writeInt32(p_cur->toa);
2692 writeStringToParcel(p, p_cur->number);
2693 p.writeInt32(p_cur->timeSeconds);
2694 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
2695 (p_cur->status==1)?"enable":"disable",
2696 p_cur->reason, p_cur->serviceClass, p_cur->toa,
2697 (char*)p_cur->number,
2698 p_cur->timeSeconds);
2699 }
2700 removeLastChar;
2701 closeResponse;
2702
2703 return 0;
2704}
2705
2706static int responseSsn(Parcel &p, void *response, size_t responselen) {
2707 if (response == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002708 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002709 return RIL_ERRNO_INVALID_RESPONSE;
2710 }
2711
2712 if (responselen != sizeof(RIL_SuppSvcNotification)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002713 RLOGE("invalid response length was %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002714 (int)responselen, (int)sizeof (RIL_SuppSvcNotification));
2715 return RIL_ERRNO_INVALID_RESPONSE;
2716 }
2717
2718 RIL_SuppSvcNotification *p_cur = (RIL_SuppSvcNotification *) response;
2719 p.writeInt32(p_cur->notificationType);
2720 p.writeInt32(p_cur->code);
2721 p.writeInt32(p_cur->index);
2722 p.writeInt32(p_cur->type);
2723 writeStringToParcel(p, p_cur->number);
2724
2725 startResponse;
2726 appendPrintBuf("%s%s,code=%d,id=%d,type=%d,%s", printBuf,
2727 (p_cur->notificationType==0)?"mo":"mt",
2728 p_cur->code, p_cur->index, p_cur->type,
2729 (char*)p_cur->number);
2730 closeResponse;
2731
2732 return 0;
2733}
2734
2735static int responseCellList(Parcel &p, void *response, size_t responselen) {
2736 int num;
2737
2738 if (response == NULL && responselen != 0) {
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_NeighboringCell *) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002744 RLOGE("responseCellList: invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002745 (int)responselen, (int)sizeof (RIL_NeighboringCell *));
2746 return RIL_ERRNO_INVALID_RESPONSE;
2747 }
2748
2749 startResponse;
2750 /* number of records */
2751 num = responselen / sizeof(RIL_NeighboringCell *);
2752 p.writeInt32(num);
2753
2754 for (int i = 0 ; i < num ; i++) {
2755 RIL_NeighboringCell *p_cur = ((RIL_NeighboringCell **) response)[i];
2756
2757 p.writeInt32(p_cur->rssi);
2758 writeStringToParcel (p, p_cur->cid);
2759
2760 appendPrintBuf("%s[cid=%s,rssi=%d],", printBuf,
2761 p_cur->cid, p_cur->rssi);
2762 }
2763 removeLastChar;
2764 closeResponse;
2765
2766 return 0;
2767}
2768
2769/**
2770 * Marshall the signalInfoRecord into the parcel if it exists.
2771 */
2772static void marshallSignalInfoRecord(Parcel &p,
2773 RIL_CDMA_SignalInfoRecord &p_signalInfoRecord) {
2774 p.writeInt32(p_signalInfoRecord.isPresent);
2775 p.writeInt32(p_signalInfoRecord.signalType);
2776 p.writeInt32(p_signalInfoRecord.alertPitch);
2777 p.writeInt32(p_signalInfoRecord.signal);
2778}
2779
2780static int responseCdmaInformationRecords(Parcel &p,
2781 void *response, size_t responselen) {
2782 int num;
2783 char* string8 = NULL;
2784 int buffer_lenght;
2785 RIL_CDMA_InformationRecord *infoRec;
2786
2787 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002788 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002789 return RIL_ERRNO_INVALID_RESPONSE;
2790 }
2791
2792 if (responselen != sizeof (RIL_CDMA_InformationRecords)) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002793 RLOGE("responseCdmaInformationRecords: invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002794 (int)responselen, (int)sizeof (RIL_CDMA_InformationRecords *));
2795 return RIL_ERRNO_INVALID_RESPONSE;
2796 }
2797
2798 RIL_CDMA_InformationRecords *p_cur =
2799 (RIL_CDMA_InformationRecords *) response;
2800 num = MIN(p_cur->numberOfInfoRecs, RIL_CDMA_MAX_NUMBER_OF_INFO_RECS);
2801
2802 startResponse;
2803 p.writeInt32(num);
2804
2805 for (int i = 0 ; i < num ; i++) {
2806 infoRec = &p_cur->infoRec[i];
2807 p.writeInt32(infoRec->name);
2808 switch (infoRec->name) {
2809 case RIL_CDMA_DISPLAY_INFO_REC:
2810 case RIL_CDMA_EXTENDED_DISPLAY_INFO_REC:
2811 if (infoRec->rec.display.alpha_len >
2812 CDMA_ALPHA_INFO_BUFFER_LENGTH) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002813 RLOGE("invalid display info response length %d \
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002814 expected not more than %d\n",
2815 (int)infoRec->rec.display.alpha_len,
2816 CDMA_ALPHA_INFO_BUFFER_LENGTH);
2817 return RIL_ERRNO_INVALID_RESPONSE;
2818 }
2819 string8 = (char*) malloc((infoRec->rec.display.alpha_len + 1)
2820 * sizeof(char) );
2821 for (int i = 0 ; i < infoRec->rec.display.alpha_len ; i++) {
2822 string8[i] = infoRec->rec.display.alpha_buf[i];
2823 }
2824 string8[(int)infoRec->rec.display.alpha_len] = '\0';
2825 writeStringToParcel(p, (const char*)string8);
2826 free(string8);
2827 string8 = NULL;
2828 break;
2829 case RIL_CDMA_CALLED_PARTY_NUMBER_INFO_REC:
2830 case RIL_CDMA_CALLING_PARTY_NUMBER_INFO_REC:
2831 case RIL_CDMA_CONNECTED_NUMBER_INFO_REC:
2832 if (infoRec->rec.number.len > CDMA_NUMBER_INFO_BUFFER_LENGTH) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002833 RLOGE("invalid display info response length %d \
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002834 expected not more than %d\n",
2835 (int)infoRec->rec.number.len,
2836 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2837 return RIL_ERRNO_INVALID_RESPONSE;
2838 }
2839 string8 = (char*) malloc((infoRec->rec.number.len + 1)
2840 * sizeof(char) );
2841 for (int i = 0 ; i < infoRec->rec.number.len; i++) {
2842 string8[i] = infoRec->rec.number.buf[i];
2843 }
2844 string8[(int)infoRec->rec.number.len] = '\0';
2845 writeStringToParcel(p, (const char*)string8);
2846 free(string8);
2847 string8 = NULL;
2848 p.writeInt32(infoRec->rec.number.number_type);
2849 p.writeInt32(infoRec->rec.number.number_plan);
2850 p.writeInt32(infoRec->rec.number.pi);
2851 p.writeInt32(infoRec->rec.number.si);
2852 break;
2853 case RIL_CDMA_SIGNAL_INFO_REC:
2854 p.writeInt32(infoRec->rec.signal.isPresent);
2855 p.writeInt32(infoRec->rec.signal.signalType);
2856 p.writeInt32(infoRec->rec.signal.alertPitch);
2857 p.writeInt32(infoRec->rec.signal.signal);
2858
2859 appendPrintBuf("%sisPresent=%X, signalType=%X, \
2860 alertPitch=%X, signal=%X, ",
2861 printBuf, (int)infoRec->rec.signal.isPresent,
2862 (int)infoRec->rec.signal.signalType,
2863 (int)infoRec->rec.signal.alertPitch,
2864 (int)infoRec->rec.signal.signal);
2865 removeLastChar;
2866 break;
2867 case RIL_CDMA_REDIRECTING_NUMBER_INFO_REC:
2868 if (infoRec->rec.redir.redirectingNumber.len >
2869 CDMA_NUMBER_INFO_BUFFER_LENGTH) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002870 RLOGE("invalid display info response length %d \
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002871 expected not more than %d\n",
2872 (int)infoRec->rec.redir.redirectingNumber.len,
2873 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2874 return RIL_ERRNO_INVALID_RESPONSE;
2875 }
2876 string8 = (char*) malloc((infoRec->rec.redir.redirectingNumber
2877 .len + 1) * sizeof(char) );
2878 for (int i = 0;
2879 i < infoRec->rec.redir.redirectingNumber.len;
2880 i++) {
2881 string8[i] = infoRec->rec.redir.redirectingNumber.buf[i];
2882 }
2883 string8[(int)infoRec->rec.redir.redirectingNumber.len] = '\0';
2884 writeStringToParcel(p, (const char*)string8);
2885 free(string8);
2886 string8 = NULL;
2887 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_type);
2888 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_plan);
2889 p.writeInt32(infoRec->rec.redir.redirectingNumber.pi);
2890 p.writeInt32(infoRec->rec.redir.redirectingNumber.si);
2891 p.writeInt32(infoRec->rec.redir.redirectingReason);
2892 break;
2893 case RIL_CDMA_LINE_CONTROL_INFO_REC:
2894 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPolarityIncluded);
2895 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlToggle);
2896 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlReverse);
2897 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2898
2899 appendPrintBuf("%slineCtrlPolarityIncluded=%d, \
2900 lineCtrlToggle=%d, lineCtrlReverse=%d, \
2901 lineCtrlPowerDenial=%d, ", printBuf,
2902 (int)infoRec->rec.lineCtrl.lineCtrlPolarityIncluded,
2903 (int)infoRec->rec.lineCtrl.lineCtrlToggle,
2904 (int)infoRec->rec.lineCtrl.lineCtrlReverse,
2905 (int)infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2906 removeLastChar;
2907 break;
2908 case RIL_CDMA_T53_CLIR_INFO_REC:
2909 p.writeInt32((int)(infoRec->rec.clir.cause));
2910
2911 appendPrintBuf("%scause%d", printBuf, infoRec->rec.clir.cause);
2912 removeLastChar;
2913 break;
2914 case RIL_CDMA_T53_AUDIO_CONTROL_INFO_REC:
2915 p.writeInt32(infoRec->rec.audioCtrl.upLink);
2916 p.writeInt32(infoRec->rec.audioCtrl.downLink);
2917
2918 appendPrintBuf("%supLink=%d, downLink=%d, ", printBuf,
2919 infoRec->rec.audioCtrl.upLink,
2920 infoRec->rec.audioCtrl.downLink);
2921 removeLastChar;
2922 break;
2923 case RIL_CDMA_T53_RELEASE_INFO_REC:
2924 // TODO(Moto): See David Krause, he has the answer:)
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002925 RLOGE("RIL_CDMA_T53_RELEASE_INFO_REC: return INVALID_RESPONSE");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002926 return RIL_ERRNO_INVALID_RESPONSE;
2927 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002928 RLOGE("Incorrect name value");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002929 return RIL_ERRNO_INVALID_RESPONSE;
2930 }
2931 }
2932 closeResponse;
2933
2934 return 0;
2935}
2936
2937static int responseRilSignalStrength(Parcel &p,
2938 void *response, size_t responselen) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002939 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002940 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002941 return RIL_ERRNO_INVALID_RESPONSE;
2942 }
2943
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002944 if (responselen >= sizeof (RIL_SignalStrength_v5)) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002945 RIL_SignalStrength_v10 *p_cur = ((RIL_SignalStrength_v10 *) response);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002946
Howard Sue32dbfd2015-01-07 15:55:57 +08002947 p.writeInt32(p_cur->GW_SignalStrength.signalStrength);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002948 p.writeInt32(p_cur->GW_SignalStrength.bitErrorRate);
Howard Sue32dbfd2015-01-07 15:55:57 +08002949 p.writeInt32(p_cur->CDMA_SignalStrength.dbm);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002950 p.writeInt32(p_cur->CDMA_SignalStrength.ecio);
Howard Sue32dbfd2015-01-07 15:55:57 +08002951 p.writeInt32(p_cur->EVDO_SignalStrength.dbm);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002952 p.writeInt32(p_cur->EVDO_SignalStrength.ecio);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002953 p.writeInt32(p_cur->EVDO_SignalStrength.signalNoiseRatio);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002954 if (responselen >= sizeof (RIL_SignalStrength_v6)) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002955 /*
Ethan Chend6e30652013-08-04 22:49:56 -07002956 * Fixup LTE for backwards compatibility
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002957 */
Ethan Chend6e30652013-08-04 22:49:56 -07002958 if (s_callbacks.version <= 6) {
2959 // signalStrength: -1 -> 99
2960 if (p_cur->LTE_SignalStrength.signalStrength == -1) {
2961 p_cur->LTE_SignalStrength.signalStrength = 99;
2962 }
2963 // rsrp: -1 -> INT_MAX all other negative value to positive.
2964 // So remap here
2965 if (p_cur->LTE_SignalStrength.rsrp == -1) {
2966 p_cur->LTE_SignalStrength.rsrp = INT_MAX;
2967 } else if (p_cur->LTE_SignalStrength.rsrp < -1) {
2968 p_cur->LTE_SignalStrength.rsrp = -p_cur->LTE_SignalStrength.rsrp;
2969 }
2970 // rsrq: -1 -> INT_MAX
2971 if (p_cur->LTE_SignalStrength.rsrq == -1) {
2972 p_cur->LTE_SignalStrength.rsrq = INT_MAX;
2973 }
2974 // Not remapping rssnr is already using INT_MAX
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002975
Ethan Chend6e30652013-08-04 22:49:56 -07002976 // cqi: -1 -> INT_MAX
2977 if (p_cur->LTE_SignalStrength.cqi == -1) {
2978 p_cur->LTE_SignalStrength.cqi = INT_MAX;
2979 }
2980 }
2981 p.writeInt32(p_cur->LTE_SignalStrength.signalStrength);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002982 p.writeInt32(p_cur->LTE_SignalStrength.rsrp);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002983 p.writeInt32(p_cur->LTE_SignalStrength.rsrq);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002984 p.writeInt32(p_cur->LTE_SignalStrength.rssnr);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002985 p.writeInt32(p_cur->LTE_SignalStrength.cqi);
Howard Sue32dbfd2015-01-07 15:55:57 +08002986 if (responselen >= sizeof (RIL_SignalStrength_v10)) {
2987 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
2988 } else {
2989 p.writeInt32(INT_MAX);
2990 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002991 } else {
Ethan Chend6e30652013-08-04 22:49:56 -07002992 p.writeInt32(99);
2993 p.writeInt32(INT_MAX);
2994 p.writeInt32(INT_MAX);
2995 p.writeInt32(INT_MAX);
2996 p.writeInt32(INT_MAX);
Howard Sue32dbfd2015-01-07 15:55:57 +08002997 p.writeInt32(INT_MAX);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002998 }
2999
3000 startResponse;
3001 appendPrintBuf("%s[signalStrength=%d,bitErrorRate=%d,\
3002 CDMA_SS.dbm=%d,CDMA_SSecio=%d,\
3003 EVDO_SS.dbm=%d,EVDO_SS.ecio=%d,\
3004 EVDO_SS.signalNoiseRatio=%d,\
3005 LTE_SS.signalStrength=%d,LTE_SS.rsrp=%d,LTE_SS.rsrq=%d,\
Howard Sue32dbfd2015-01-07 15:55:57 +08003006 LTE_SS.rssnr=%d,LTE_SS.cqi=%d,TDSCDMA_SS.rscp=%d]",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003007 printBuf,
Howard Sue32dbfd2015-01-07 15:55:57 +08003008 p_cur->GW_SignalStrength.signalStrength,
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003009 p_cur->GW_SignalStrength.bitErrorRate,
Howard Sue32dbfd2015-01-07 15:55:57 +08003010 p_cur->CDMA_SignalStrength.dbm,
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003011 p_cur->CDMA_SignalStrength.ecio,
Howard Sue32dbfd2015-01-07 15:55:57 +08003012 p_cur->EVDO_SignalStrength.dbm,
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003013 p_cur->EVDO_SignalStrength.ecio,
3014 p_cur->EVDO_SignalStrength.signalNoiseRatio,
3015 p_cur->LTE_SignalStrength.signalStrength,
3016 p_cur->LTE_SignalStrength.rsrp,
3017 p_cur->LTE_SignalStrength.rsrq,
3018 p_cur->LTE_SignalStrength.rssnr,
Howard Sue32dbfd2015-01-07 15:55:57 +08003019 p_cur->LTE_SignalStrength.cqi,
3020 p_cur->TD_SCDMA_SignalStrength.rscp);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003021 closeResponse;
3022
3023 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003024 RLOGE("invalid response length");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003025 return RIL_ERRNO_INVALID_RESPONSE;
3026 }
3027
3028 return 0;
3029}
3030
3031static int responseCallRing(Parcel &p, void *response, size_t responselen) {
3032 if ((response == NULL) || (responselen == 0)) {
3033 return responseVoid(p, response, responselen);
3034 } else {
3035 return responseCdmaSignalInfoRecord(p, response, responselen);
3036 }
3037}
3038
3039static int responseCdmaSignalInfoRecord(Parcel &p, void *response, size_t responselen) {
3040 if (response == NULL || responselen == 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003041 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003042 return RIL_ERRNO_INVALID_RESPONSE;
3043 }
3044
3045 if (responselen != sizeof (RIL_CDMA_SignalInfoRecord)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003046 RLOGE("invalid response length %d expected sizeof (RIL_CDMA_SignalInfoRecord) of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003047 (int)responselen, (int)sizeof (RIL_CDMA_SignalInfoRecord));
3048 return RIL_ERRNO_INVALID_RESPONSE;
3049 }
3050
3051 startResponse;
3052
3053 RIL_CDMA_SignalInfoRecord *p_cur = ((RIL_CDMA_SignalInfoRecord *) response);
3054 marshallSignalInfoRecord(p, *p_cur);
3055
3056 appendPrintBuf("%s[isPresent=%d,signalType=%d,alertPitch=%d\
3057 signal=%d]",
3058 printBuf,
3059 p_cur->isPresent,
3060 p_cur->signalType,
3061 p_cur->alertPitch,
3062 p_cur->signal);
3063
3064 closeResponse;
3065 return 0;
3066}
3067
3068static int responseCdmaCallWaiting(Parcel &p, void *response,
3069 size_t responselen) {
3070 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003071 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003072 return RIL_ERRNO_INVALID_RESPONSE;
3073 }
3074
3075 if (responselen < sizeof(RIL_CDMA_CallWaiting_v6)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003076 RLOGW("Upgrade to ril version %d\n", RIL_VERSION);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003077 }
3078
3079 RIL_CDMA_CallWaiting_v6 *p_cur = ((RIL_CDMA_CallWaiting_v6 *) response);
3080
3081 writeStringToParcel(p, p_cur->number);
3082 p.writeInt32(p_cur->numberPresentation);
3083 writeStringToParcel(p, p_cur->name);
3084 marshallSignalInfoRecord(p, p_cur->signalInfoRecord);
3085
3086 if (responselen >= sizeof(RIL_CDMA_CallWaiting_v6)) {
3087 p.writeInt32(p_cur->number_type);
3088 p.writeInt32(p_cur->number_plan);
3089 } else {
3090 p.writeInt32(0);
3091 p.writeInt32(0);
3092 }
3093
3094 startResponse;
3095 appendPrintBuf("%snumber=%s,numberPresentation=%d, name=%s,\
3096 signalInfoRecord[isPresent=%d,signalType=%d,alertPitch=%d\
3097 signal=%d,number_type=%d,number_plan=%d]",
3098 printBuf,
3099 p_cur->number,
3100 p_cur->numberPresentation,
3101 p_cur->name,
3102 p_cur->signalInfoRecord.isPresent,
3103 p_cur->signalInfoRecord.signalType,
3104 p_cur->signalInfoRecord.alertPitch,
3105 p_cur->signalInfoRecord.signal,
3106 p_cur->number_type,
3107 p_cur->number_plan);
3108 closeResponse;
3109
3110 return 0;
3111}
3112
3113static int responseSimRefresh(Parcel &p, void *response, size_t responselen) {
3114 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003115 RLOGE("responseSimRefresh: invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003116 return RIL_ERRNO_INVALID_RESPONSE;
3117 }
3118
3119 startResponse;
3120 if (s_callbacks.version == 7) {
3121 RIL_SimRefreshResponse_v7 *p_cur = ((RIL_SimRefreshResponse_v7 *) response);
3122 p.writeInt32(p_cur->result);
3123 p.writeInt32(p_cur->ef_id);
3124 writeStringToParcel(p, p_cur->aid);
3125
3126 appendPrintBuf("%sresult=%d, ef_id=%d, aid=%s",
3127 printBuf,
3128 p_cur->result,
3129 p_cur->ef_id,
3130 p_cur->aid);
3131 } else {
3132 int *p_cur = ((int *) response);
3133 p.writeInt32(p_cur[0]);
3134 p.writeInt32(p_cur[1]);
3135 writeStringToParcel(p, NULL);
3136
3137 appendPrintBuf("%sresult=%d, ef_id=%d",
3138 printBuf,
3139 p_cur[0],
3140 p_cur[1]);
3141 }
3142 closeResponse;
3143
3144 return 0;
3145}
3146
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003147static int responseCellInfoList(Parcel &p, void *response, size_t responselen)
3148{
3149 if (response == NULL && responselen != 0) {
3150 RLOGE("invalid response: NULL");
3151 return RIL_ERRNO_INVALID_RESPONSE;
3152 }
3153
3154 if (responselen % sizeof(RIL_CellInfo) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08003155 RLOGE("responseCellInfoList: invalid response length %d expected multiple of %d",
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003156 (int)responselen, (int)sizeof(RIL_CellInfo));
3157 return RIL_ERRNO_INVALID_RESPONSE;
3158 }
3159
3160 int num = responselen / sizeof(RIL_CellInfo);
3161 p.writeInt32(num);
3162
3163 RIL_CellInfo *p_cur = (RIL_CellInfo *) response;
3164 startResponse;
3165 int i;
3166 for (i = 0; i < num; i++) {
3167 appendPrintBuf("%s[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", printBuf, i,
3168 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
3169 p.writeInt32((int)p_cur->cellInfoType);
3170 p.writeInt32(p_cur->registered);
3171 p.writeInt32(p_cur->timeStampType);
3172 p.writeInt64(p_cur->timeStamp);
3173 switch(p_cur->cellInfoType) {
3174 case RIL_CELL_INFO_TYPE_GSM: {
3175 appendPrintBuf("%s GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,", printBuf,
3176 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
3177 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
3178 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
3179 p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3180 appendPrintBuf("%s gsmSS: ss=%d,ber=%d],", printBuf,
3181 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
3182 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3183
3184 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
3185 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
3186 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
3187 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3188 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
3189 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3190 break;
3191 }
3192 case RIL_CELL_INFO_TYPE_WCDMA: {
3193 appendPrintBuf("%s WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,", printBuf,
3194 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
3195 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
3196 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
3197 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
3198 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3199 appendPrintBuf("%s wcdmaSS: ss=%d,ber=%d],", printBuf,
3200 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
3201 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3202
3203 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
3204 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
3205 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
3206 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
3207 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3208 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
3209 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3210 break;
3211 }
3212 case RIL_CELL_INFO_TYPE_CDMA: {
3213 appendPrintBuf("%s CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d", printBuf,
3214 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
3215 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
3216 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
3217 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
3218 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3219
3220 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
3221 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
3222 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
3223 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
3224 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3225
3226 appendPrintBuf("%s cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d", printBuf,
3227 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
3228 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
3229 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
3230 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
3231 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3232
3233 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
3234 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
3235 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
3236 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
3237 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3238 break;
3239 }
3240 case RIL_CELL_INFO_TYPE_LTE: {
3241 appendPrintBuf("%s LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d", printBuf,
3242 p_cur->CellInfo.lte.cellIdentityLte.mcc,
3243 p_cur->CellInfo.lte.cellIdentityLte.mnc,
3244 p_cur->CellInfo.lte.cellIdentityLte.ci,
3245 p_cur->CellInfo.lte.cellIdentityLte.pci,
3246 p_cur->CellInfo.lte.cellIdentityLte.tac);
3247
3248 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
3249 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
3250 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
3251 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
3252 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
3253
3254 appendPrintBuf("%s lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d", printBuf,
3255 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
3256 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
3257 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
3258 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
3259 p_cur->CellInfo.lte.signalStrengthLte.cqi,
3260 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3261 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
3262 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
3263 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
3264 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
3265 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
3266 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3267 break;
3268 }
Howard Sue32dbfd2015-01-07 15:55:57 +08003269 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
3270 appendPrintBuf("%s TDSCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,cpid=%d,", printBuf,
3271 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc,
3272 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc,
3273 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac,
3274 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid,
3275 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3276 appendPrintBuf("%s tdscdmaSS: rscp=%d],", printBuf,
3277 p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3278
3279 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
3280 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
3281 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
3282 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
3283 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3284 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3285 break;
3286 }
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003287 }
3288 p_cur += 1;
3289 }
3290 removeLastChar;
3291 closeResponse;
3292
3293 return 0;
3294}
3295
Howard Sue32dbfd2015-01-07 15:55:57 +08003296static int responseHardwareConfig(Parcel &p, void *response, size_t responselen)
3297{
3298 if (response == NULL && responselen != 0) {
3299 RLOGE("invalid response: NULL");
3300 return RIL_ERRNO_INVALID_RESPONSE;
3301 }
3302
3303 if (responselen % sizeof(RIL_HardwareConfig) != 0) {
3304 RLOGE("responseHardwareConfig: invalid response length %d expected multiple of %d",
3305 (int)responselen, (int)sizeof(RIL_HardwareConfig));
3306 return RIL_ERRNO_INVALID_RESPONSE;
3307 }
3308
3309 int num = responselen / sizeof(RIL_HardwareConfig);
3310 int i;
3311 RIL_HardwareConfig *p_cur = (RIL_HardwareConfig *) response;
3312
3313 p.writeInt32(num);
3314
3315 startResponse;
3316 for (i = 0; i < num; i++) {
3317 switch (p_cur[i].type) {
3318 case RIL_HARDWARE_CONFIG_MODEM: {
3319 writeStringToParcel(p, p_cur[i].uuid);
3320 p.writeInt32((int)p_cur[i].state);
3321 p.writeInt32(p_cur[i].cfg.modem.rat);
3322 p.writeInt32(p_cur[i].cfg.modem.maxVoice);
3323 p.writeInt32(p_cur[i].cfg.modem.maxData);
3324 p.writeInt32(p_cur[i].cfg.modem.maxStandby);
3325
3326 appendPrintBuf("%s modem: uuid=%s,state=%d,rat=%08x,maxV=%d,maxD=%d,maxS=%d", printBuf,
3327 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.modem.rat,
3328 p_cur[i].cfg.modem.maxVoice, p_cur[i].cfg.modem.maxData, p_cur[i].cfg.modem.maxStandby);
3329 break;
3330 }
3331 case RIL_HARDWARE_CONFIG_SIM: {
3332 writeStringToParcel(p, p_cur[i].uuid);
3333 p.writeInt32((int)p_cur[i].state);
3334 writeStringToParcel(p, p_cur[i].cfg.sim.modemUuid);
3335
3336 appendPrintBuf("%s sim: uuid=%s,state=%d,modem-uuid=%s", printBuf,
3337 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.sim.modemUuid);
3338 break;
3339 }
3340 }
3341 }
3342 removeLastChar;
3343 closeResponse;
3344 return 0;
3345}
3346
Howard Subd82ef12015-04-12 10:25:05 +02003347static int responseRadioCapability(Parcel &p, void *response, size_t responselen) {
3348 if (response == NULL) {
3349 RLOGE("invalid response: NULL");
3350 return RIL_ERRNO_INVALID_RESPONSE;
3351 }
3352
3353 if (responselen != sizeof (RIL_RadioCapability) ) {
3354 RLOGE("invalid response length was %d expected %d",
3355 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3356 return RIL_ERRNO_INVALID_RESPONSE;
3357 }
3358
3359 RIL_RadioCapability *p_cur = (RIL_RadioCapability *) response;
3360 p.writeInt32(p_cur->version);
3361 p.writeInt32(p_cur->session);
3362 p.writeInt32(p_cur->phase);
3363 p.writeInt32(p_cur->rat);
3364 writeStringToParcel(p, p_cur->logicalModemUuid);
3365 p.writeInt32(p_cur->status);
3366
3367 startResponse;
3368 appendPrintBuf("%s[version=%d,session=%d,phase=%d,\
3369 rat=%s,logicalModemUuid=%s,status=%d]",
3370 printBuf,
3371 p_cur->version,
3372 p_cur->session,
3373 p_cur->phase,
3374 p_cur->rat,
3375 p_cur->logicalModemUuid,
3376 p_cur->status);
3377 closeResponse;
3378 return 0;
3379}
3380
3381static int responseSSData(Parcel &p, void *response, size_t responselen) {
3382 RLOGD("In responseSSData");
3383 int num;
3384
3385 if (response == NULL && responselen != 0) {
3386 RLOGE("invalid response length was %d expected %d",
3387 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3388 return RIL_ERRNO_INVALID_RESPONSE;
3389 }
3390
3391 if (responselen != sizeof(RIL_StkCcUnsolSsResponse)) {
3392 RLOGE("invalid response length %d, expected %d",
3393 (int)responselen, (int)sizeof(RIL_StkCcUnsolSsResponse));
3394 return RIL_ERRNO_INVALID_RESPONSE;
3395 }
3396
3397 startResponse;
3398 RIL_StkCcUnsolSsResponse *p_cur = (RIL_StkCcUnsolSsResponse *) response;
3399 p.writeInt32(p_cur->serviceType);
3400 p.writeInt32(p_cur->requestType);
3401 p.writeInt32(p_cur->teleserviceType);
3402 p.writeInt32(p_cur->serviceClass);
3403 p.writeInt32(p_cur->result);
3404
3405 if (isServiceTypeCfQuery(p_cur->serviceType, p_cur->requestType)) {
3406 RLOGD("responseSSData CF type, num of Cf elements %d", p_cur->cfData.numValidIndexes);
3407 if (p_cur->cfData.numValidIndexes > NUM_SERVICE_CLASSES) {
3408 RLOGE("numValidIndexes is greater than max value %d, "
3409 "truncating it to max value", NUM_SERVICE_CLASSES);
3410 p_cur->cfData.numValidIndexes = NUM_SERVICE_CLASSES;
3411 }
3412 /* number of call info's */
3413 p.writeInt32(p_cur->cfData.numValidIndexes);
3414
3415 for (int i = 0; i < p_cur->cfData.numValidIndexes; i++) {
3416 RIL_CallForwardInfo cf = p_cur->cfData.cfInfo[i];
3417
3418 p.writeInt32(cf.status);
3419 p.writeInt32(cf.reason);
3420 p.writeInt32(cf.serviceClass);
3421 p.writeInt32(cf.toa);
3422 writeStringToParcel(p, cf.number);
3423 p.writeInt32(cf.timeSeconds);
3424 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
3425 (cf.status==1)?"enable":"disable", cf.reason, cf.serviceClass, cf.toa,
3426 (char*)cf.number, cf.timeSeconds);
3427 RLOGD("Data: %d,reason=%d,cls=%d,toa=%d,num=%s,tout=%d],", cf.status,
3428 cf.reason, cf.serviceClass, cf.toa, (char*)cf.number, cf.timeSeconds);
3429 }
3430 } else {
3431 p.writeInt32 (SS_INFO_MAX);
3432
3433 /* each int*/
3434 for (int i = 0; i < SS_INFO_MAX; i++) {
3435 appendPrintBuf("%s%d,", printBuf, p_cur->ssInfo[i]);
3436 RLOGD("Data: %d",p_cur->ssInfo[i]);
3437 p.writeInt32(p_cur->ssInfo[i]);
3438 }
3439 }
3440 removeLastChar;
3441 closeResponse;
3442
3443 return 0;
3444}
3445
3446static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType) {
3447 if ((reqType == SS_INTERROGATION) &&
3448 (serType == SS_CFU ||
3449 serType == SS_CF_BUSY ||
3450 serType == SS_CF_NO_REPLY ||
3451 serType == SS_CF_NOT_REACHABLE ||
3452 serType == SS_CF_ALL ||
3453 serType == SS_CF_ALL_CONDITIONAL)) {
3454 return true;
3455 }
3456 return false;
3457}
3458
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003459static void triggerEvLoop() {
3460 int ret;
3461 if (!pthread_equal(pthread_self(), s_tid_dispatch)) {
3462 /* trigger event loop to wakeup. No reason to do this,
3463 * if we're in the event loop thread */
3464 do {
3465 ret = write (s_fdWakeupWrite, " ", 1);
3466 } while (ret < 0 && errno == EINTR);
3467 }
3468}
3469
3470static void rilEventAddWakeup(struct ril_event *ev) {
3471 ril_event_add(ev);
3472 triggerEvLoop();
3473}
3474
3475static void sendSimStatusAppInfo(Parcel &p, int num_apps, RIL_AppStatus appStatus[]) {
3476 p.writeInt32(num_apps);
3477 startResponse;
3478 for (int i = 0; i < num_apps; i++) {
3479 p.writeInt32(appStatus[i].app_type);
3480 p.writeInt32(appStatus[i].app_state);
3481 p.writeInt32(appStatus[i].perso_substate);
3482 writeStringToParcel(p, (const char*)(appStatus[i].aid_ptr));
3483 writeStringToParcel(p, (const char*)
3484 (appStatus[i].app_label_ptr));
3485 p.writeInt32(appStatus[i].pin1_replaced);
3486 p.writeInt32(appStatus[i].pin1);
3487 p.writeInt32(appStatus[i].pin2);
3488 appendPrintBuf("%s[app_type=%d,app_state=%d,perso_substate=%d,\
3489 aid_ptr=%s,app_label_ptr=%s,pin1_replaced=%d,pin1=%d,pin2=%d],",
3490 printBuf,
3491 appStatus[i].app_type,
3492 appStatus[i].app_state,
3493 appStatus[i].perso_substate,
3494 appStatus[i].aid_ptr,
3495 appStatus[i].app_label_ptr,
3496 appStatus[i].pin1_replaced,
3497 appStatus[i].pin1,
3498 appStatus[i].pin2);
3499 }
3500 closeResponse;
3501}
3502
3503static int responseSimStatus(Parcel &p, void *response, size_t responselen) {
Howard Sue32dbfd2015-01-07 15:55:57 +08003504 int i;
3505
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003506 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003507 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003508 return RIL_ERRNO_INVALID_RESPONSE;
3509 }
3510
3511 if (responselen == sizeof (RIL_CardStatus_v6)) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003512 RIL_CardStatus_v6 *p_cur = ((RIL_CardStatus_v6 *) response);
3513
3514 p.writeInt32(p_cur->card_state);
3515 p.writeInt32(p_cur->universal_pin_state);
3516 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3517 p.writeInt32(p_cur->cdma_subscription_app_index);
3518 p.writeInt32(p_cur->ims_subscription_app_index);
3519
3520 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
3521 } else if (responselen == sizeof (RIL_CardStatus_v5)) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003522 RIL_CardStatus_v5 *p_cur = ((RIL_CardStatus_v5 *) response);
3523
3524 p.writeInt32(p_cur->card_state);
3525 p.writeInt32(p_cur->universal_pin_state);
3526 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3527 p.writeInt32(p_cur->cdma_subscription_app_index);
3528 p.writeInt32(-1);
3529
3530 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
3531 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003532 RLOGE("responseSimStatus: A RilCardStatus_v6 or _v5 expected\n");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003533 return RIL_ERRNO_INVALID_RESPONSE;
3534 }
3535
3536 return 0;
3537}
3538
3539static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3540 int num = responselen / sizeof(RIL_GSM_BroadcastSmsConfigInfo *);
3541 p.writeInt32(num);
3542
3543 startResponse;
3544 RIL_GSM_BroadcastSmsConfigInfo **p_cur =
3545 (RIL_GSM_BroadcastSmsConfigInfo **) response;
3546 for (int i = 0; i < num; i++) {
3547 p.writeInt32(p_cur[i]->fromServiceId);
3548 p.writeInt32(p_cur[i]->toServiceId);
3549 p.writeInt32(p_cur[i]->fromCodeScheme);
3550 p.writeInt32(p_cur[i]->toCodeScheme);
3551 p.writeInt32(p_cur[i]->selected);
3552
3553 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId=%d, \
3554 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]",
3555 printBuf, i, p_cur[i]->fromServiceId, p_cur[i]->toServiceId,
3556 p_cur[i]->fromCodeScheme, p_cur[i]->toCodeScheme,
3557 p_cur[i]->selected);
3558 }
3559 closeResponse;
3560
3561 return 0;
3562}
3563
3564static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3565 RIL_CDMA_BroadcastSmsConfigInfo **p_cur =
3566 (RIL_CDMA_BroadcastSmsConfigInfo **) response;
3567
3568 int num = responselen / sizeof (RIL_CDMA_BroadcastSmsConfigInfo *);
3569 p.writeInt32(num);
3570
3571 startResponse;
3572 for (int i = 0 ; i < num ; i++ ) {
3573 p.writeInt32(p_cur[i]->service_category);
3574 p.writeInt32(p_cur[i]->language);
3575 p.writeInt32(p_cur[i]->selected);
3576
3577 appendPrintBuf("%s [%d: srvice_category=%d, language =%d, \
3578 selected =%d], ",
3579 printBuf, i, p_cur[i]->service_category, p_cur[i]->language,
3580 p_cur[i]->selected);
3581 }
3582 closeResponse;
3583
3584 return 0;
3585}
3586
3587static int responseCdmaSms(Parcel &p, void *response, size_t responselen) {
3588 int num;
3589 int digitCount;
3590 int digitLimit;
3591 uint8_t uct;
3592 void* dest;
3593
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003594 RLOGD("Inside responseCdmaSms");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003595
3596 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003597 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003598 return RIL_ERRNO_INVALID_RESPONSE;
3599 }
3600
3601 if (responselen != sizeof(RIL_CDMA_SMS_Message)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003602 RLOGE("invalid response length was %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003603 (int)responselen, (int)sizeof(RIL_CDMA_SMS_Message));
3604 return RIL_ERRNO_INVALID_RESPONSE;
3605 }
3606
3607 RIL_CDMA_SMS_Message *p_cur = (RIL_CDMA_SMS_Message *) response;
3608 p.writeInt32(p_cur->uTeleserviceID);
3609 p.write(&(p_cur->bIsServicePresent),sizeof(uct));
3610 p.writeInt32(p_cur->uServicecategory);
3611 p.writeInt32(p_cur->sAddress.digit_mode);
3612 p.writeInt32(p_cur->sAddress.number_mode);
3613 p.writeInt32(p_cur->sAddress.number_type);
3614 p.writeInt32(p_cur->sAddress.number_plan);
3615 p.write(&(p_cur->sAddress.number_of_digits), sizeof(uct));
3616 digitLimit= MIN((p_cur->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
3617 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3618 p.write(&(p_cur->sAddress.digits[digitCount]),sizeof(uct));
3619 }
3620
3621 p.writeInt32(p_cur->sSubAddress.subaddressType);
3622 p.write(&(p_cur->sSubAddress.odd),sizeof(uct));
3623 p.write(&(p_cur->sSubAddress.number_of_digits),sizeof(uct));
3624 digitLimit= MIN((p_cur->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
3625 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3626 p.write(&(p_cur->sSubAddress.digits[digitCount]),sizeof(uct));
3627 }
3628
3629 digitLimit= MIN((p_cur->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
3630 p.writeInt32(p_cur->uBearerDataLen);
3631 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3632 p.write(&(p_cur->aBearerData[digitCount]), sizeof(uct));
3633 }
3634
3635 startResponse;
3636 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
3637 sAddress.digit_mode=%d, sAddress.number_mode=%d, sAddress.number_type=%d, ",
3638 printBuf, p_cur->uTeleserviceID,p_cur->bIsServicePresent,p_cur->uServicecategory,
3639 p_cur->sAddress.digit_mode, p_cur->sAddress.number_mode,p_cur->sAddress.number_type);
3640 closeResponse;
3641
3642 return 0;
3643}
3644
Howard Sue32dbfd2015-01-07 15:55:57 +08003645static int responseDcRtInfo(Parcel &p, void *response, size_t responselen)
3646{
3647 int num = responselen / sizeof(RIL_DcRtInfo);
3648 if ((responselen % sizeof(RIL_DcRtInfo) != 0) || (num != 1)) {
3649 RLOGE("responseDcRtInfo: invalid response length %d expected multiple of %d",
3650 (int)responselen, (int)sizeof(RIL_DcRtInfo));
3651 return RIL_ERRNO_INVALID_RESPONSE;
3652 }
3653
3654 startResponse;
3655 RIL_DcRtInfo *pDcRtInfo = (RIL_DcRtInfo *)response;
3656 p.writeInt64(pDcRtInfo->time);
3657 p.writeInt32(pDcRtInfo->powerState);
3658 appendPrintBuf("%s[time=%d,powerState=%d]", printBuf,
3659 pDcRtInfo->time,
3660 pDcRtInfo->powerState);
3661 closeResponse;
3662
3663 return 0;
3664}
3665
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003666/**
3667 * A write on the wakeup fd is done just to pop us out of select()
3668 * We empty the buffer here and then ril_event will reset the timers on the
3669 * way back down
3670 */
3671static void processWakeupCallback(int fd, short flags, void *param) {
3672 char buff[16];
3673 int ret;
3674
Ethan Chend6e30652013-08-04 22:49:56 -07003675 RLOGV("processWakeupCallback");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003676
3677 /* empty our wakeup socket out */
3678 do {
3679 ret = read(s_fdWakeupRead, &buff, sizeof(buff));
3680 } while (ret > 0 || (ret < 0 && errno == EINTR));
3681}
3682
Howard Sue32dbfd2015-01-07 15:55:57 +08003683static void onCommandsSocketClosed(RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003684 int ret;
3685 RequestInfo *p_cur;
Howard Sue32dbfd2015-01-07 15:55:57 +08003686 /* Hook for current context
3687 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
3688 pthread_mutex_t * pendingRequestsMutexHook = &s_pendingRequestsMutex;
3689 /* pendingRequestsHook refer to &s_pendingRequests */
3690 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003691
Howard Sue32dbfd2015-01-07 15:55:57 +08003692#if (SIM_COUNT >= 2)
3693 if (socket_id == RIL_SOCKET_2) {
3694 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
3695 pendingRequestsHook = &s_pendingRequests_socket2;
3696 }
3697#if (SIM_COUNT >= 3)
3698 else if (socket_id == RIL_SOCKET_3) {
3699 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
3700 pendingRequestsHook = &s_pendingRequests_socket3;
3701 }
3702#endif
3703#if (SIM_COUNT >= 4)
3704 else if (socket_id == RIL_SOCKET_4) {
3705 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
3706 pendingRequestsHook = &s_pendingRequests_socket4;
3707 }
3708#endif
3709#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003710 /* mark pending requests as "cancelled" so we dont report responses */
Howard Sue32dbfd2015-01-07 15:55:57 +08003711 ret = pthread_mutex_lock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003712 assert (ret == 0);
3713
Howard Sue32dbfd2015-01-07 15:55:57 +08003714 p_cur = *pendingRequestsHook;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003715
Howard Sue32dbfd2015-01-07 15:55:57 +08003716 for (p_cur = *pendingRequestsHook
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003717 ; p_cur != NULL
3718 ; p_cur = p_cur->p_next
3719 ) {
3720 p_cur->cancelled = 1;
3721 }
3722
Howard Sue32dbfd2015-01-07 15:55:57 +08003723 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003724 assert (ret == 0);
3725}
3726
3727static void processCommandsCallback(int fd, short flags, void *param) {
3728 RecordStream *p_rs;
3729 void *p_record;
3730 size_t recordlen;
3731 int ret;
Howard Sue32dbfd2015-01-07 15:55:57 +08003732 SocketListenParam *p_info = (SocketListenParam *)param;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003733
Howard Sue32dbfd2015-01-07 15:55:57 +08003734 assert(fd == p_info->fdCommand);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003735
Howard Sue32dbfd2015-01-07 15:55:57 +08003736 p_rs = p_info->p_rs;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003737
3738 for (;;) {
3739 /* loop until EAGAIN/EINTR, end of stream, or other error */
3740 ret = record_stream_get_next(p_rs, &p_record, &recordlen);
3741
3742 if (ret == 0 && p_record == NULL) {
3743 /* end-of-stream */
3744 break;
3745 } else if (ret < 0) {
3746 break;
3747 } else if (ret == 0) { /* && p_record != NULL */
Howard Sue32dbfd2015-01-07 15:55:57 +08003748 processCommandBuffer(p_record, recordlen, p_info->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003749 }
3750 }
3751
3752 if (ret == 0 || !(errno == EAGAIN || errno == EINTR)) {
3753 /* fatal error or end-of-stream */
3754 if (ret != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003755 RLOGE("error on reading command socket errno:%d\n", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003756 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003757 RLOGW("EOS. Closing command socket.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003758 }
3759
Howard Sue32dbfd2015-01-07 15:55:57 +08003760 close(fd);
3761 p_info->fdCommand = -1;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003762
Howard Sue32dbfd2015-01-07 15:55:57 +08003763 ril_event_del(p_info->commands_event);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003764
3765 record_stream_free(p_rs);
3766
3767 /* start listening for new connections again */
3768 rilEventAddWakeup(&s_listen_event);
3769
Howard Sue32dbfd2015-01-07 15:55:57 +08003770 onCommandsSocketClosed(p_info->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003771 }
3772}
3773
Howard Subd82ef12015-04-12 10:25:05 +02003774
Howard Sue32dbfd2015-01-07 15:55:57 +08003775static void onNewCommandConnect(RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003776 // Inform we are connected and the ril version
3777 int rilVer = s_callbacks.version;
Howard Sue32dbfd2015-01-07 15:55:57 +08003778 RIL_UNSOL_RESPONSE(RIL_UNSOL_RIL_CONNECTED,
3779 &rilVer, sizeof(rilVer), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003780
3781 // implicit radio state changed
Howard Sue32dbfd2015-01-07 15:55:57 +08003782 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
3783 NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003784
3785 // Send last NITZ time data, in case it was missed
3786 if (s_lastNITZTimeData != NULL) {
Howard Sue32dbfd2015-01-07 15:55:57 +08003787 sendResponseRaw(s_lastNITZTimeData, s_lastNITZTimeDataSize, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003788
3789 free(s_lastNITZTimeData);
3790 s_lastNITZTimeData = NULL;
3791 }
3792
3793 // Get version string
3794 if (s_callbacks.getVersion != NULL) {
3795 const char *version;
3796 version = s_callbacks.getVersion();
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003797 RLOGI("RIL Daemon version: %s\n", version);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003798
3799 property_set(PROPERTY_RIL_IMPL, version);
3800 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003801 RLOGI("RIL Daemon version: unavailable\n");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003802 property_set(PROPERTY_RIL_IMPL, "unavailable");
3803 }
3804
3805}
3806
3807static void listenCallback (int fd, short flags, void *param) {
3808 int ret;
3809 int err;
3810 int is_phone_socket;
Howard Sue32dbfd2015-01-07 15:55:57 +08003811 int fdCommand = -1;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003812 RecordStream *p_rs;
Howard Sue32dbfd2015-01-07 15:55:57 +08003813 SocketListenParam *p_info = (SocketListenParam *)param;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003814
3815 struct sockaddr_un peeraddr;
3816 socklen_t socklen = sizeof (peeraddr);
3817
3818 struct ucred creds;
3819 socklen_t szCreds = sizeof(creds);
3820
3821 struct passwd *pwd = NULL;
3822
Howard Sue32dbfd2015-01-07 15:55:57 +08003823 assert (*p_info->fdCommand < 0);
3824 assert (fd == *p_info->fdListen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003825
Howard Sue32dbfd2015-01-07 15:55:57 +08003826 fdCommand = accept(fd, (sockaddr *) &peeraddr, &socklen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003827
Howard Sue32dbfd2015-01-07 15:55:57 +08003828 if (fdCommand < 0 ) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003829 RLOGE("Error on accept() errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003830 /* start listening for new connections again */
Howard Sue32dbfd2015-01-07 15:55:57 +08003831 rilEventAddWakeup(p_info->listen_event);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003832 return;
3833 }
3834
3835 /* check the credential of the other side and only accept socket from
3836 * phone process
3837 */
3838 errno = 0;
3839 is_phone_socket = 0;
3840
Howard Sue32dbfd2015-01-07 15:55:57 +08003841 err = getsockopt(fdCommand, SOL_SOCKET, SO_PEERCRED, &creds, &szCreds);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003842
3843 if (err == 0 && szCreds > 0) {
3844 errno = 0;
3845 pwd = getpwuid(creds.uid);
3846 if (pwd != NULL) {
Howard Sue32dbfd2015-01-07 15:55:57 +08003847 if (strcmp(pwd->pw_name, p_info->processName) == 0) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003848 is_phone_socket = 1;
3849 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003850 RLOGE("RILD can't accept socket from process %s", pwd->pw_name);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003851 }
3852 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003853 RLOGE("Error on getpwuid() errno: %d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003854 }
3855 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003856 RLOGD("Error on getsockopt() errno: %d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003857 }
3858
Howard Subd82ef12015-04-12 10:25:05 +02003859 if (!is_phone_socket) {
Howard Sue32dbfd2015-01-07 15:55:57 +08003860 RLOGE("RILD must accept socket from %s", p_info->processName);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003861
Howard Sue32dbfd2015-01-07 15:55:57 +08003862 close(fdCommand);
3863 fdCommand = -1;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003864
Howard Sue32dbfd2015-01-07 15:55:57 +08003865 onCommandsSocketClosed(p_info->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003866
3867 /* start listening for new connections again */
Howard Sue32dbfd2015-01-07 15:55:57 +08003868 rilEventAddWakeup(p_info->listen_event);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003869
3870 return;
3871 }
3872
Howard Sue32dbfd2015-01-07 15:55:57 +08003873 ret = fcntl(fdCommand, F_SETFL, O_NONBLOCK);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003874
3875 if (ret < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003876 RLOGE ("Error setting O_NONBLOCK errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003877 }
3878
Howard Sue32dbfd2015-01-07 15:55:57 +08003879 RLOGI("libril: new connection to %s", rilSocketIdToString(p_info->socket_id));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003880
Howard Sue32dbfd2015-01-07 15:55:57 +08003881 p_info->fdCommand = fdCommand;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003882
Howard Sue32dbfd2015-01-07 15:55:57 +08003883 p_rs = record_stream_new(p_info->fdCommand, MAX_COMMAND_BYTES);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003884
Howard Sue32dbfd2015-01-07 15:55:57 +08003885 p_info->p_rs = p_rs;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003886
Howard Sue32dbfd2015-01-07 15:55:57 +08003887 ril_event_set (p_info->commands_event, p_info->fdCommand, 1,
3888 p_info->processCommandsCallback, p_info);
3889
3890 rilEventAddWakeup (p_info->commands_event);
3891
3892 onNewCommandConnect(p_info->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003893}
3894
3895static void freeDebugCallbackArgs(int number, char **args) {
3896 for (int i = 0; i < number; i++) {
3897 if (args[i] != NULL) {
3898 free(args[i]);
3899 }
3900 }
3901 free(args);
3902}
3903
3904static void debugCallback (int fd, short flags, void *param) {
3905 int acceptFD, option;
3906 struct sockaddr_un peeraddr;
3907 socklen_t socklen = sizeof (peeraddr);
3908 int data;
3909 unsigned int qxdm_data[6];
3910 const char *deactData[1] = {"1"};
3911 char *actData[1];
3912 RIL_Dial dialData;
3913 int hangupData[1] = {1};
3914 int number;
3915 char **args;
Howard Sue32dbfd2015-01-07 15:55:57 +08003916 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
3917 int sim_id = 0;
3918
3919 RLOGI("debugCallback for socket %s", rilSocketIdToString(socket_id));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003920
3921 acceptFD = accept (fd, (sockaddr *) &peeraddr, &socklen);
3922
3923 if (acceptFD < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003924 RLOGE ("error accepting on debug port: %d\n", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003925 return;
3926 }
3927
3928 if (recv(acceptFD, &number, sizeof(int), 0) != sizeof(int)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003929 RLOGE ("error reading on socket: number of Args: \n");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003930 return;
3931 }
3932 args = (char **) malloc(sizeof(char*) * number);
3933
3934 for (int i = 0; i < number; i++) {
3935 int len;
3936 if (recv(acceptFD, &len, sizeof(int), 0) != sizeof(int)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003937 RLOGE ("error reading on socket: Len of Args: \n");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003938 freeDebugCallbackArgs(i, args);
3939 return;
3940 }
3941 // +1 for null-term
3942 args[i] = (char *) malloc((sizeof(char) * len) + 1);
3943 if (recv(acceptFD, args[i], sizeof(char) * len, 0)
3944 != (int)sizeof(char) * len) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003945 RLOGE ("error reading on socket: Args[%d] \n", i);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003946 freeDebugCallbackArgs(i, args);
3947 return;
3948 }
3949 char * buf = args[i];
3950 buf[len] = 0;
Howard Sue32dbfd2015-01-07 15:55:57 +08003951 if ((i+1) == number) {
3952 /* The last argument should be sim id 0(SIM1)~3(SIM4) */
3953 sim_id = atoi(args[i]);
3954 switch (sim_id) {
3955 case 0:
3956 socket_id = RIL_SOCKET_1;
3957 break;
3958 #if (SIM_COUNT >= 2)
3959 case 1:
3960 socket_id = RIL_SOCKET_2;
3961 break;
3962 #endif
3963 #if (SIM_COUNT >= 3)
3964 case 2:
3965 socket_id = RIL_SOCKET_3;
3966 break;
3967 #endif
3968 #if (SIM_COUNT >= 4)
3969 case 3:
3970 socket_id = RIL_SOCKET_4;
3971 break;
3972 #endif
3973 default:
3974 socket_id = RIL_SOCKET_1;
3975 break;
3976 }
3977 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003978 }
3979
3980 switch (atoi(args[0])) {
3981 case 0:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003982 RLOGI ("Connection on debug port: issuing reset.");
Howard Sue32dbfd2015-01-07 15:55:57 +08003983 issueLocalRequest(RIL_REQUEST_RESET_RADIO, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003984 break;
3985 case 1:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003986 RLOGI ("Connection on debug port: issuing radio power off.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003987 data = 0;
Howard Sue32dbfd2015-01-07 15:55:57 +08003988 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003989 // Close the socket
Howard Subd82ef12015-04-12 10:25:05 +02003990 if (socket_id == RIL_SOCKET_1 && s_ril_param_socket.fdCommand > 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08003991 close(s_ril_param_socket.fdCommand);
3992 s_ril_param_socket.fdCommand = -1;
3993 }
3994 #if (SIM_COUNT == 2)
3995 else if (socket_id == RIL_SOCKET_2 && s_ril_param_socket2.fdCommand > 0) {
3996 close(s_ril_param_socket2.fdCommand);
3997 s_ril_param_socket2.fdCommand = -1;
3998 }
3999 #endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004000 break;
4001 case 2:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004002 RLOGI ("Debug port: issuing unsolicited voice network change.");
Howard Sue32dbfd2015-01-07 15:55:57 +08004003 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004004 break;
4005 case 3:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004006 RLOGI ("Debug port: QXDM log enable.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004007 qxdm_data[0] = 65536; // head.func_tag
4008 qxdm_data[1] = 16; // head.len
4009 qxdm_data[2] = 1; // mode: 1 for 'start logging'
4010 qxdm_data[3] = 32; // log_file_size: 32megabytes
4011 qxdm_data[4] = 0; // log_mask
4012 qxdm_data[5] = 8; // log_max_fileindex
4013 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Howard Sue32dbfd2015-01-07 15:55:57 +08004014 6 * sizeof(int), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004015 break;
4016 case 4:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004017 RLOGI ("Debug port: QXDM log disable.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004018 qxdm_data[0] = 65536;
4019 qxdm_data[1] = 16;
4020 qxdm_data[2] = 0; // mode: 0 for 'stop logging'
4021 qxdm_data[3] = 32;
4022 qxdm_data[4] = 0;
4023 qxdm_data[5] = 8;
4024 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Howard Sue32dbfd2015-01-07 15:55:57 +08004025 6 * sizeof(int), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004026 break;
4027 case 5:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004028 RLOGI("Debug port: Radio On");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004029 data = 1;
Howard Sue32dbfd2015-01-07 15:55:57 +08004030 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004031 sleep(2);
4032 // Set network selection automatic.
Howard Sue32dbfd2015-01-07 15:55:57 +08004033 issueLocalRequest(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004034 break;
4035 case 6:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004036 RLOGI("Debug port: Setup Data Call, Apn :%s\n", args[1]);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004037 actData[0] = args[1];
4038 issueLocalRequest(RIL_REQUEST_SETUP_DATA_CALL, &actData,
Howard Sue32dbfd2015-01-07 15:55:57 +08004039 sizeof(actData), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004040 break;
4041 case 7:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004042 RLOGI("Debug port: Deactivate Data Call");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004043 issueLocalRequest(RIL_REQUEST_DEACTIVATE_DATA_CALL, &deactData,
Howard Sue32dbfd2015-01-07 15:55:57 +08004044 sizeof(deactData), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004045 break;
4046 case 8:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004047 RLOGI("Debug port: Dial Call");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004048 dialData.clir = 0;
4049 dialData.address = args[1];
Howard Sue32dbfd2015-01-07 15:55:57 +08004050 issueLocalRequest(RIL_REQUEST_DIAL, &dialData, sizeof(dialData), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004051 break;
4052 case 9:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004053 RLOGI("Debug port: Answer Call");
Howard Sue32dbfd2015-01-07 15:55:57 +08004054 issueLocalRequest(RIL_REQUEST_ANSWER, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004055 break;
4056 case 10:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004057 RLOGI("Debug port: End Call");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004058 issueLocalRequest(RIL_REQUEST_HANGUP, &hangupData,
Howard Sue32dbfd2015-01-07 15:55:57 +08004059 sizeof(hangupData), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004060 break;
4061 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004062 RLOGE ("Invalid request");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004063 break;
4064 }
4065 freeDebugCallbackArgs(number, args);
4066 close(acceptFD);
4067}
4068
4069
4070static void userTimerCallback (int fd, short flags, void *param) {
4071 UserCallbackInfo *p_info;
4072
4073 p_info = (UserCallbackInfo *)param;
4074
4075 p_info->p_callback(p_info->userParam);
4076
4077
4078 // FIXME generalize this...there should be a cancel mechanism
4079 if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) {
4080 s_last_wake_timeout_info = NULL;
4081 }
4082
4083 free(p_info);
4084}
4085
4086
4087static void *
4088eventLoop(void *param) {
4089 int ret;
4090 int filedes[2];
4091
4092 ril_event_init();
4093
4094 pthread_mutex_lock(&s_startupMutex);
4095
4096 s_started = 1;
4097 pthread_cond_broadcast(&s_startupCond);
4098
4099 pthread_mutex_unlock(&s_startupMutex);
4100
4101 ret = pipe(filedes);
4102
4103 if (ret < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004104 RLOGE("Error in pipe() errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004105 return NULL;
4106 }
4107
4108 s_fdWakeupRead = filedes[0];
4109 s_fdWakeupWrite = filedes[1];
4110
4111 fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK);
4112
4113 ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,
4114 processWakeupCallback, NULL);
4115
4116 rilEventAddWakeup (&s_wakeupfd_event);
4117
4118 // Only returns on error
4119 ril_event_loop();
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004120 RLOGE ("error in event_loop_base errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004121 // kill self to restart on error
4122 kill(0, SIGKILL);
4123
4124 return NULL;
4125}
4126
4127extern "C" void
4128RIL_startEventLoop(void) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004129 /* spin up eventLoop thread and wait for it to get started */
4130 s_started = 0;
4131 pthread_mutex_lock(&s_startupMutex);
4132
Howard Sue32dbfd2015-01-07 15:55:57 +08004133 pthread_attr_t attr;
4134 pthread_attr_init(&attr);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004135 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
Howard Sue32dbfd2015-01-07 15:55:57 +08004136
4137 int result = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
4138 if (result != 0) {
4139 RLOGE("Failed to create dispatch thread: %s", strerror(result));
4140 goto done;
4141 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004142
4143 while (s_started == 0) {
4144 pthread_cond_wait(&s_startupCond, &s_startupMutex);
4145 }
4146
Howard Sue32dbfd2015-01-07 15:55:57 +08004147done:
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004148 pthread_mutex_unlock(&s_startupMutex);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004149}
4150
4151// Used for testing purpose only.
4152extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) {
4153 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4154}
4155
Howard Sue32dbfd2015-01-07 15:55:57 +08004156static void startListen(RIL_SOCKET_ID socket_id, SocketListenParam* socket_listen_p) {
4157 int fdListen = -1;
4158 int ret;
4159 char socket_name[10];
4160
4161 memset(socket_name, 0, sizeof(char)*10);
4162
4163 switch(socket_id) {
4164 case RIL_SOCKET_1:
4165 strncpy(socket_name, RIL_getRilSocketName(), 9);
4166 break;
4167 #if (SIM_COUNT >= 2)
4168 case RIL_SOCKET_2:
4169 strncpy(socket_name, SOCKET2_NAME_RIL, 9);
4170 break;
4171 #endif
4172 #if (SIM_COUNT >= 3)
4173 case RIL_SOCKET_3:
4174 strncpy(socket_name, SOCKET3_NAME_RIL, 9);
4175 break;
4176 #endif
4177 #if (SIM_COUNT >= 4)
4178 case RIL_SOCKET_4:
4179 strncpy(socket_name, SOCKET4_NAME_RIL, 9);
4180 break;
4181 #endif
4182 default:
4183 RLOGE("Socket id is wrong!!");
4184 return;
4185 }
4186
4187 RLOGI("Start to listen %s", rilSocketIdToString(socket_id));
4188
4189 fdListen = android_get_control_socket(socket_name);
4190 if (fdListen < 0) {
4191 RLOGE("Failed to get socket %s", socket_name);
4192 exit(-1);
4193 }
4194
4195 ret = listen(fdListen, 4);
4196
4197 if (ret < 0) {
4198 RLOGE("Failed to listen on control socket '%d': %s",
4199 fdListen, strerror(errno));
4200 exit(-1);
4201 }
4202 socket_listen_p->fdListen = fdListen;
4203
4204 /* note: non-persistent so we can accept only one connection at a time */
4205 ril_event_set (socket_listen_p->listen_event, fdListen, false,
4206 listenCallback, socket_listen_p);
4207
4208 rilEventAddWakeup (socket_listen_p->listen_event);
4209}
4210
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004211extern "C" void
4212RIL_register (const RIL_RadioFunctions *callbacks) {
4213 int ret;
4214 int flags;
4215
Howard Sue32dbfd2015-01-07 15:55:57 +08004216 RLOGI("SIM_COUNT: %d", SIM_COUNT);
4217
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004218 if (callbacks == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004219 RLOGE("RIL_register: RIL_RadioFunctions * null");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004220 return;
4221 }
4222 if (callbacks->version < RIL_VERSION_MIN) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004223 RLOGE("RIL_register: version %d is to old, min version is %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004224 callbacks->version, RIL_VERSION_MIN);
4225 return;
4226 }
4227 if (callbacks->version > RIL_VERSION) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004228 RLOGE("RIL_register: version %d is too new, max version is %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004229 callbacks->version, RIL_VERSION);
4230 return;
4231 }
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004232 RLOGE("RIL_register: RIL version %d", callbacks->version);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004233
4234 if (s_registerCalled > 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004235 RLOGE("RIL_register has been called more than once. "
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004236 "Subsequent call ignored");
4237 return;
4238 }
4239
4240 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4241
Howard Sue32dbfd2015-01-07 15:55:57 +08004242 /* Initialize socket1 parameters */
4243 s_ril_param_socket = {
4244 RIL_SOCKET_1, /* socket_id */
4245 -1, /* fdListen */
4246 -1, /* fdCommand */
4247 PHONE_PROCESS, /* processName */
4248 &s_commands_event, /* commands_event */
4249 &s_listen_event, /* listen_event */
4250 processCommandsCallback, /* processCommandsCallback */
4251 NULL /* p_rs */
4252 };
4253
4254#if (SIM_COUNT >= 2)
4255 s_ril_param_socket2 = {
4256 RIL_SOCKET_2, /* socket_id */
4257 -1, /* fdListen */
4258 -1, /* fdCommand */
4259 PHONE_PROCESS, /* processName */
4260 &s_commands_event_socket2, /* commands_event */
4261 &s_listen_event_socket2, /* listen_event */
4262 processCommandsCallback, /* processCommandsCallback */
4263 NULL /* p_rs */
4264 };
4265#endif
4266
4267#if (SIM_COUNT >= 3)
4268 s_ril_param_socket3 = {
4269 RIL_SOCKET_3, /* socket_id */
4270 -1, /* fdListen */
4271 -1, /* fdCommand */
4272 PHONE_PROCESS, /* processName */
4273 &s_commands_event_socket3, /* commands_event */
4274 &s_listen_event_socket3, /* listen_event */
4275 processCommandsCallback, /* processCommandsCallback */
4276 NULL /* p_rs */
4277 };
4278#endif
4279
4280#if (SIM_COUNT >= 4)
4281 s_ril_param_socket4 = {
4282 RIL_SOCKET_4, /* socket_id */
4283 -1, /* fdListen */
4284 -1, /* fdCommand */
4285 PHONE_PROCESS, /* processName */
4286 &s_commands_event_socket4, /* commands_event */
4287 &s_listen_event_socket4, /* listen_event */
4288 processCommandsCallback, /* processCommandsCallback */
4289 NULL /* p_rs */
4290 };
4291#endif
4292
Howard Subd82ef12015-04-12 10:25:05 +02004293
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004294 s_registerCalled = 1;
4295
Howard Sue32dbfd2015-01-07 15:55:57 +08004296 RLOGI("s_registerCalled flag set, %d", s_started);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004297 // Little self-check
4298
4299 for (int i = 0; i < (int)NUM_ELEMS(s_commands); i++) {
4300 assert(i == s_commands[i].requestNumber);
4301 }
4302
Howard Subd82ef12015-04-12 10:25:05 +02004303 for (int i = 0; i < (int)NUM_ELEMS(s_commands_v); i++) {
4304 assert(i + RIL_VENDOR_COMMANDS_OFFSET == s_commands[i].requestNumber);
4305 }
4306
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004307 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses); i++) {
Howard Sue32dbfd2015-01-07 15:55:57 +08004308 assert(i + RIL_UNSOL_RESPONSE_BASE
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004309 == s_unsolResponses[i].requestNumber);
4310 }
4311
Howard Subd82ef12015-04-12 10:25:05 +02004312 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses_v); i++) {
4313 assert(i + RIL_UNSOL_RESPONSE_BASE + RIL_VENDOR_COMMANDS_OFFSET
4314 == s_unsolResponses[i].requestNumber);
4315 }
4316
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004317 // New rild impl calls RIL_startEventLoop() first
4318 // old standalone impl wants it here.
4319
4320 if (s_started == 0) {
4321 RIL_startEventLoop();
4322 }
4323
Howard Sue32dbfd2015-01-07 15:55:57 +08004324 // start listen socket1
4325 startListen(RIL_SOCKET_1, &s_ril_param_socket);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004326
Howard Sue32dbfd2015-01-07 15:55:57 +08004327#if (SIM_COUNT >= 2)
4328 // start listen socket2
4329 startListen(RIL_SOCKET_2, &s_ril_param_socket2);
4330#endif /* (SIM_COUNT == 2) */
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004331
Howard Sue32dbfd2015-01-07 15:55:57 +08004332#if (SIM_COUNT >= 3)
4333 // start listen socket3
4334 startListen(RIL_SOCKET_3, &s_ril_param_socket3);
4335#endif /* (SIM_COUNT == 3) */
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004336
Howard Sue32dbfd2015-01-07 15:55:57 +08004337#if (SIM_COUNT >= 4)
4338 // start listen socket4
4339 startListen(RIL_SOCKET_4, &s_ril_param_socket4);
4340#endif /* (SIM_COUNT == 4) */
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004341
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004342
4343#if 1
4344 // start debug interface socket
4345
Howard Sue32dbfd2015-01-07 15:55:57 +08004346 char *inst = NULL;
4347 if (strlen(RIL_getRilSocketName()) >= strlen(SOCKET_NAME_RIL)) {
4348 inst = RIL_getRilSocketName() + strlen(SOCKET_NAME_RIL);
4349 }
4350
4351 char rildebug[MAX_DEBUG_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL_DEBUG;
4352 if (inst != NULL) {
4353 strncat(rildebug, inst, MAX_DEBUG_SOCKET_NAME_LENGTH);
4354 }
4355
4356 s_fdDebug = android_get_control_socket(rildebug);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004357 if (s_fdDebug < 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08004358 RLOGE("Failed to get socket : %s errno:%d", rildebug, errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004359 exit(-1);
4360 }
4361
4362 ret = listen(s_fdDebug, 4);
4363
4364 if (ret < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004365 RLOGE("Failed to listen on ril debug socket '%d': %s",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004366 s_fdDebug, strerror(errno));
4367 exit(-1);
4368 }
4369
4370 ril_event_set (&s_debug_event, s_fdDebug, true,
4371 debugCallback, NULL);
4372
4373 rilEventAddWakeup (&s_debug_event);
4374#endif
4375
4376}
4377
4378static int
4379checkAndDequeueRequestInfo(struct RequestInfo *pRI) {
4380 int ret = 0;
Howard Sue32dbfd2015-01-07 15:55:57 +08004381 /* Hook for current context
4382 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
4383 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
4384 /* pendingRequestsHook refer to &s_pendingRequests */
4385 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004386
4387 if (pRI == NULL) {
4388 return 0;
4389 }
4390
Howard Sue32dbfd2015-01-07 15:55:57 +08004391#if (SIM_COUNT >= 2)
4392 if (pRI->socket_id == RIL_SOCKET_2) {
4393 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
4394 pendingRequestsHook = &s_pendingRequests_socket2;
4395 }
4396#if (SIM_COUNT >= 3)
4397 if (pRI->socket_id == RIL_SOCKET_3) {
4398 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
4399 pendingRequestsHook = &s_pendingRequests_socket3;
4400 }
4401#endif
4402#if (SIM_COUNT >= 4)
4403 if (pRI->socket_id == RIL_SOCKET_4) {
4404 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
4405 pendingRequestsHook = &s_pendingRequests_socket4;
4406 }
4407#endif
4408#endif
4409 pthread_mutex_lock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004410
Howard Sue32dbfd2015-01-07 15:55:57 +08004411 for(RequestInfo **ppCur = pendingRequestsHook
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004412 ; *ppCur != NULL
4413 ; ppCur = &((*ppCur)->p_next)
4414 ) {
4415 if (pRI == *ppCur) {
4416 ret = 1;
4417
4418 *ppCur = (*ppCur)->p_next;
4419 break;
4420 }
4421 }
4422
Howard Sue32dbfd2015-01-07 15:55:57 +08004423 pthread_mutex_unlock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004424
4425 return ret;
4426}
4427
4428
4429extern "C" void
4430RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) {
4431 RequestInfo *pRI;
4432 int ret;
Howard Sue32dbfd2015-01-07 15:55:57 +08004433 int fd = s_ril_param_socket.fdCommand;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004434 size_t errorOffset;
Howard Sue32dbfd2015-01-07 15:55:57 +08004435 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004436
4437 pRI = (RequestInfo *)t;
4438
4439 if (!checkAndDequeueRequestInfo(pRI)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004440 RLOGE ("RIL_onRequestComplete: invalid RIL_Token");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004441 return;
4442 }
4443
Howard Sue32dbfd2015-01-07 15:55:57 +08004444 socket_id = pRI->socket_id;
4445#if (SIM_COUNT >= 2)
4446 if (socket_id == RIL_SOCKET_2) {
4447 fd = s_ril_param_socket2.fdCommand;
4448 }
4449#if (SIM_COUNT >= 3)
4450 if (socket_id == RIL_SOCKET_3) {
4451 fd = s_ril_param_socket3.fdCommand;
4452 }
4453#endif
4454#if (SIM_COUNT >= 4)
4455 if (socket_id == RIL_SOCKET_4) {
4456 fd = s_ril_param_socket4.fdCommand;
4457 }
4458#endif
4459#endif
4460 RLOGD("RequestComplete, %s", rilSocketIdToString(socket_id));
4461
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004462 if (pRI->local > 0) {
4463 // Locally issued command...void only!
4464 // response does not go back up the command socket
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004465 RLOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004466
4467 goto done;
4468 }
4469
4470 appendPrintBuf("[%04d]< %s",
4471 pRI->token, requestToString(pRI->pCI->requestNumber));
4472
4473 if (pRI->cancelled == 0) {
4474 Parcel p;
4475
4476 p.writeInt32 (RESPONSE_SOLICITED);
4477 p.writeInt32 (pRI->token);
4478 errorOffset = p.dataPosition();
4479
4480 p.writeInt32 (e);
4481
4482 if (response != NULL) {
4483 // there is a response payload, no matter success or not.
4484 ret = pRI->pCI->responseFunction(p, response, responselen);
4485
4486 /* if an error occurred, rewind and mark it */
4487 if (ret != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08004488 RLOGE ("responseFunction error, ret %d", ret);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004489 p.setDataPosition(errorOffset);
4490 p.writeInt32 (ret);
4491 }
4492 }
4493
4494 if (e != RIL_E_SUCCESS) {
4495 appendPrintBuf("%s fails by %s", printBuf, failCauseToString(e));
4496 }
4497
Howard Sue32dbfd2015-01-07 15:55:57 +08004498 if (fd < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004499 RLOGD ("RIL onRequestComplete: Command channel closed");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004500 }
Howard Sue32dbfd2015-01-07 15:55:57 +08004501 sendResponse(p, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004502 }
4503
4504done:
4505 free(pRI);
4506}
4507
Howard Subd82ef12015-04-12 10:25:05 +02004508
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004509static void
4510grabPartialWakeLock() {
4511 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
4512}
4513
4514static void
4515releaseWakeLock() {
4516 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
4517}
4518
4519/**
4520 * Timer callback to put us back to sleep before the default timeout
4521 */
4522static void
4523wakeTimeoutCallback (void *param) {
4524 // We're using "param != NULL" as a cancellation mechanism
4525 if (param == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004526 //RLOGD("wakeTimeout: releasing wake lock");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004527
4528 releaseWakeLock();
4529 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004530 //RLOGD("wakeTimeout: releasing wake lock CANCELLED");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004531 }
4532}
4533
4534static int
4535decodeVoiceRadioTechnology (RIL_RadioState radioState) {
4536 switch (radioState) {
4537 case RADIO_STATE_SIM_NOT_READY:
4538 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4539 case RADIO_STATE_SIM_READY:
4540 return RADIO_TECH_UMTS;
4541
4542 case RADIO_STATE_RUIM_NOT_READY:
4543 case RADIO_STATE_RUIM_READY:
4544 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4545 case RADIO_STATE_NV_NOT_READY:
4546 case RADIO_STATE_NV_READY:
4547 return RADIO_TECH_1xRTT;
4548
4549 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004550 RLOGD("decodeVoiceRadioTechnology: Invoked with incorrect RadioState");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004551 return -1;
4552 }
4553}
4554
4555static int
4556decodeCdmaSubscriptionSource (RIL_RadioState radioState) {
4557 switch (radioState) {
4558 case RADIO_STATE_SIM_NOT_READY:
4559 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4560 case RADIO_STATE_SIM_READY:
4561 case RADIO_STATE_RUIM_NOT_READY:
4562 case RADIO_STATE_RUIM_READY:
4563 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4564 return CDMA_SUBSCRIPTION_SOURCE_RUIM_SIM;
4565
4566 case RADIO_STATE_NV_NOT_READY:
4567 case RADIO_STATE_NV_READY:
4568 return CDMA_SUBSCRIPTION_SOURCE_NV;
4569
4570 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004571 RLOGD("decodeCdmaSubscriptionSource: Invoked with incorrect RadioState");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004572 return -1;
4573 }
4574}
4575
4576static int
4577decodeSimStatus (RIL_RadioState radioState) {
4578 switch (radioState) {
4579 case RADIO_STATE_SIM_NOT_READY:
4580 case RADIO_STATE_RUIM_NOT_READY:
4581 case RADIO_STATE_NV_NOT_READY:
4582 case RADIO_STATE_NV_READY:
4583 return -1;
4584 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4585 case RADIO_STATE_SIM_READY:
4586 case RADIO_STATE_RUIM_READY:
4587 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4588 return radioState;
4589 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004590 RLOGD("decodeSimStatus: Invoked with incorrect RadioState");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004591 return -1;
4592 }
4593}
4594
4595static bool is3gpp2(int radioTech) {
4596 switch (radioTech) {
4597 case RADIO_TECH_IS95A:
4598 case RADIO_TECH_IS95B:
4599 case RADIO_TECH_1xRTT:
4600 case RADIO_TECH_EVDO_0:
4601 case RADIO_TECH_EVDO_A:
4602 case RADIO_TECH_EVDO_B:
4603 case RADIO_TECH_EHRPD:
4604 return true;
4605 default:
4606 return false;
4607 }
4608}
4609
4610/* If RIL sends SIM states or RUIM states, store the voice radio
4611 * technology and subscription source information so that they can be
4612 * returned when telephony framework requests them
4613 */
4614static RIL_RadioState
Howard Subd82ef12015-04-12 10:25:05 +02004615processRadioState(RIL_RadioState newRadioState, RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004616
4617 if((newRadioState > RADIO_STATE_UNAVAILABLE) && (newRadioState < RADIO_STATE_ON)) {
4618 int newVoiceRadioTech;
4619 int newCdmaSubscriptionSource;
4620 int newSimStatus;
4621
4622 /* This is old RIL. Decode Subscription source and Voice Radio Technology
4623 from Radio State and send change notifications if there has been a change */
4624 newVoiceRadioTech = decodeVoiceRadioTechnology(newRadioState);
4625 if(newVoiceRadioTech != voiceRadioTech) {
4626 voiceRadioTech = newVoiceRadioTech;
Howard Sue32dbfd2015-01-07 15:55:57 +08004627 RIL_UNSOL_RESPONSE(RIL_UNSOL_VOICE_RADIO_TECH_CHANGED,
4628 &voiceRadioTech, sizeof(voiceRadioTech), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004629 }
4630 if(is3gpp2(newVoiceRadioTech)) {
4631 newCdmaSubscriptionSource = decodeCdmaSubscriptionSource(newRadioState);
4632 if(newCdmaSubscriptionSource != cdmaSubscriptionSource) {
4633 cdmaSubscriptionSource = newCdmaSubscriptionSource;
Howard Sue32dbfd2015-01-07 15:55:57 +08004634 RIL_UNSOL_RESPONSE(RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED,
4635 &cdmaSubscriptionSource, sizeof(cdmaSubscriptionSource), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004636 }
4637 }
4638 newSimStatus = decodeSimStatus(newRadioState);
4639 if(newSimStatus != simRuimStatus) {
4640 simRuimStatus = newSimStatus;
Howard Sue32dbfd2015-01-07 15:55:57 +08004641 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004642 }
4643
4644 /* Send RADIO_ON to telephony */
4645 newRadioState = RADIO_STATE_ON;
4646 }
4647
4648 return newRadioState;
4649}
4650
Howard Subd82ef12015-04-12 10:25:05 +02004651
Howard Sue32dbfd2015-01-07 15:55:57 +08004652#if defined(ANDROID_MULTI_SIM)
4653extern "C"
Howard Subd82ef12015-04-12 10:25:05 +02004654void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
Howard Sue32dbfd2015-01-07 15:55:57 +08004655 size_t datalen, RIL_SOCKET_ID socket_id)
4656#else
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004657extern "C"
Howard Subd82ef12015-04-12 10:25:05 +02004658void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004659 size_t datalen)
Howard Sue32dbfd2015-01-07 15:55:57 +08004660#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004661{
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004662 int ret;
4663 int64_t timeReceived = 0;
4664 bool shouldScheduleTimeout = false;
4665 RIL_RadioState newState;
Howard Sue32dbfd2015-01-07 15:55:57 +08004666 RIL_SOCKET_ID soc_id = RIL_SOCKET_1;
Howard Subd82ef12015-04-12 10:25:05 +02004667 UnsolResponseInfo *pRI = NULL;
Howard Sue32dbfd2015-01-07 15:55:57 +08004668
4669#if defined(ANDROID_MULTI_SIM)
4670 soc_id = socket_id;
4671#endif
4672
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004673
4674 if (s_registerCalled == 0) {
4675 // Ignore RIL_onUnsolicitedResponse before RIL_register
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004676 RLOGW("RIL_onUnsolicitedResponse called before RIL_register");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004677 return;
4678 }
Howard Sue32dbfd2015-01-07 15:55:57 +08004679
Howard Subd82ef12015-04-12 10:25:05 +02004680 /* Hack to include Samsung responses */
4681 if (unsolResponse > RIL_VENDOR_COMMANDS_OFFSET + RIL_UNSOL_RESPONSE_BASE) {
4682 int index = unsolResponse - RIL_VENDOR_COMMANDS_OFFSET - RIL_UNSOL_RESPONSE_BASE;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004683
Howard Subd82ef12015-04-12 10:25:05 +02004684 RLOGD("SAMSUNG: unsolResponse=%d, unsolResponseIndex=%d", unsolResponse, index);
4685
4686 if (index < (int32_t)NUM_ELEMS(s_unsolResponses_v))
4687 pRI = &s_unsolResponses_v[index];
4688 } else {
4689 int index = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
4690 if (index < (int32_t)NUM_ELEMS(s_unsolResponses))
4691 pRI = &s_unsolResponses[index];
4692 }
4693
4694 if (pRI == NULL || pRI->responseFunction == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004695 RLOGE("unsupported unsolicited response code %d", unsolResponse);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004696 return;
4697 }
4698
4699 // Grab a wake lock if needed for this reponse,
4700 // as we exit we'll either release it immediately
4701 // or set a timer to release it later.
Howard Subd82ef12015-04-12 10:25:05 +02004702 switch (pRI->wakeType) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004703 case WAKE_PARTIAL:
4704 grabPartialWakeLock();
4705 shouldScheduleTimeout = true;
4706 break;
4707
4708 case DONT_WAKE:
4709 default:
4710 // No wake lock is grabed so don't set timeout
4711 shouldScheduleTimeout = false;
4712 break;
4713 }
4714
4715 // Mark the time this was received, doing this
4716 // after grabing the wakelock incase getting
4717 // the elapsedRealTime might cause us to goto
4718 // sleep.
4719 if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4720 timeReceived = elapsedRealtime();
4721 }
4722
4723 appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
4724
4725 Parcel p;
4726
4727 p.writeInt32 (RESPONSE_UNSOLICITED);
4728 p.writeInt32 (unsolResponse);
4729
Howard Subd82ef12015-04-12 10:25:05 +02004730 ret = pRI->responseFunction(p, const_cast<void*>(data), datalen);
4731
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004732 if (ret != 0) {
4733 // Problem with the response. Don't continue;
4734 goto error_exit;
4735 }
4736
4737 // some things get more payload
4738 switch(unsolResponse) {
4739 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
Howard Sue32dbfd2015-01-07 15:55:57 +08004740 newState = processRadioState(CALL_ONSTATEREQUEST(soc_id), soc_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004741 p.writeInt32(newState);
4742 appendPrintBuf("%s {%s}", printBuf,
Howard Sue32dbfd2015-01-07 15:55:57 +08004743 radioStateToString(CALL_ONSTATEREQUEST(soc_id)));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004744 break;
4745
4746
4747 case RIL_UNSOL_NITZ_TIME_RECEIVED:
4748 // Store the time that this was received so the
4749 // handler of this message can account for
4750 // the time it takes to arrive and process. In
4751 // particular the system has been known to sleep
4752 // before this message can be processed.
4753 p.writeInt64(timeReceived);
4754 break;
4755 }
4756
Howard Sue32dbfd2015-01-07 15:55:57 +08004757 RLOGI("%s UNSOLICITED: %s length:%d", rilSocketIdToString(soc_id), requestToString(unsolResponse), p.dataSize());
4758 ret = sendResponse(p, soc_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004759 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4760
4761 // Unfortunately, NITZ time is not poll/update like everything
4762 // else in the system. So, if the upstream client isn't connected,
4763 // keep a copy of the last NITZ response (with receive time noted
4764 // above) around so we can deliver it when it is connected
4765
4766 if (s_lastNITZTimeData != NULL) {
4767 free (s_lastNITZTimeData);
4768 s_lastNITZTimeData = NULL;
4769 }
4770
4771 s_lastNITZTimeData = malloc(p.dataSize());
4772 s_lastNITZTimeDataSize = p.dataSize();
4773 memcpy(s_lastNITZTimeData, p.data(), p.dataSize());
4774 }
4775
4776 // For now, we automatically go back to sleep after TIMEVAL_WAKE_TIMEOUT
4777 // FIXME The java code should handshake here to release wake lock
4778
4779 if (shouldScheduleTimeout) {
4780 // Cancel the previous request
4781 if (s_last_wake_timeout_info != NULL) {
4782 s_last_wake_timeout_info->userParam = (void *)1;
4783 }
4784
4785 s_last_wake_timeout_info
4786 = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
4787 &TIMEVAL_WAKE_TIMEOUT);
4788 }
4789
4790 // Normal exit
4791 return;
4792
4793error_exit:
4794 if (shouldScheduleTimeout) {
4795 releaseWakeLock();
4796 }
4797}
4798
4799/** FIXME generalize this if you track UserCAllbackInfo, clear it
4800 when the callback occurs
4801*/
4802static UserCallbackInfo *
4803internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
4804 const struct timeval *relativeTime)
4805{
4806 struct timeval myRelativeTime;
4807 UserCallbackInfo *p_info;
4808
4809 p_info = (UserCallbackInfo *) malloc (sizeof(UserCallbackInfo));
4810
4811 p_info->p_callback = callback;
4812 p_info->userParam = param;
4813
4814 if (relativeTime == NULL) {
4815 /* treat null parameter as a 0 relative time */
4816 memset (&myRelativeTime, 0, sizeof(myRelativeTime));
4817 } else {
4818 /* FIXME I think event_add's tv param is really const anyway */
4819 memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
4820 }
4821
4822 ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
4823
4824 ril_timer_add(&(p_info->event), &myRelativeTime);
4825
4826 triggerEvLoop();
4827 return p_info;
4828}
4829
4830
4831extern "C" void
4832RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
4833 const struct timeval *relativeTime) {
4834 internalRequestTimedCallback (callback, param, relativeTime);
4835}
4836
4837const char *
4838failCauseToString(RIL_Errno e) {
4839 switch(e) {
4840 case RIL_E_SUCCESS: return "E_SUCCESS";
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004841 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RADIO_NOT_AVAILABLE";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004842 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
4843 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
4844 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
4845 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
4846 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
4847 case RIL_E_CANCELLED: return "E_CANCELLED";
4848 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
4849 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
4850 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
4851 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
4852 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
4853#ifdef FEATURE_MULTIMODE_ANDROID
4854 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
4855 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
4856#endif
4857 default: return "<unknown error>";
4858 }
4859}
4860
4861const char *
4862radioStateToString(RIL_RadioState s) {
4863 switch(s) {
4864 case RADIO_STATE_OFF: return "RADIO_OFF";
4865 case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
4866 case RADIO_STATE_SIM_NOT_READY: return "RADIO_SIM_NOT_READY";
4867 case RADIO_STATE_SIM_LOCKED_OR_ABSENT: return "RADIO_SIM_LOCKED_OR_ABSENT";
4868 case RADIO_STATE_SIM_READY: return "RADIO_SIM_READY";
4869 case RADIO_STATE_RUIM_NOT_READY:return"RADIO_RUIM_NOT_READY";
4870 case RADIO_STATE_RUIM_READY:return"RADIO_RUIM_READY";
4871 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:return"RADIO_RUIM_LOCKED_OR_ABSENT";
4872 case RADIO_STATE_NV_NOT_READY:return"RADIO_NV_NOT_READY";
4873 case RADIO_STATE_NV_READY:return"RADIO_NV_READY";
4874 case RADIO_STATE_ON:return"RADIO_ON";
4875 default: return "<unknown state>";
4876 }
4877}
4878
4879const char *
4880callStateToString(RIL_CallState s) {
4881 switch(s) {
4882 case RIL_CALL_ACTIVE : return "ACTIVE";
4883 case RIL_CALL_HOLDING: return "HOLDING";
4884 case RIL_CALL_DIALING: return "DIALING";
4885 case RIL_CALL_ALERTING: return "ALERTING";
4886 case RIL_CALL_INCOMING: return "INCOMING";
4887 case RIL_CALL_WAITING: return "WAITING";
4888 default: return "<unknown state>";
4889 }
4890}
4891
4892const char *
4893requestToString(int request) {
4894/*
4895 cat libs/telephony/ril_commands.h \
4896 | egrep "^ *{RIL_" \
4897 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
4898
4899
4900 cat libs/telephony/ril_unsol_commands.h \
4901 | egrep "^ *{RIL_" \
4902 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
4903
4904*/
4905 switch(request) {
4906 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
4907 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
4908 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
4909 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
4910 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
4911 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
4912 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
4913 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
4914 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
4915 case RIL_REQUEST_DIAL: return "DIAL";
4916 case RIL_REQUEST_DIAL_EMERGENCY: return "DIAL";
4917 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
4918 case RIL_REQUEST_HANGUP: return "HANGUP";
4919 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
4920 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
4921 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
4922 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
4923 case RIL_REQUEST_UDUB: return "UDUB";
4924 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
4925 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
4926 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
4927 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
4928 case RIL_REQUEST_OPERATOR: return "OPERATOR";
4929 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
4930 case RIL_REQUEST_DTMF: return "DTMF";
4931 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
4932 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
4933 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
4934 case RIL_REQUEST_SIM_IO: return "SIM_IO";
4935 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
4936 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
4937 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
4938 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
4939 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
4940 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
4941 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
4942 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
4943 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
4944 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
4945 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
4946 case RIL_REQUEST_ANSWER: return "ANSWER";
4947 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
4948 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
4949 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
4950 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
4951 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
4952 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
4953 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
4954 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";
4955 case RIL_REQUEST_DTMF_START: return "DTMF_START";
4956 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
4957 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
4958 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
4959 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
4960 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
4961 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
4962 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
4963 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
4964 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
4965 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
4966 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
4967 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
4968 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
4969 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
4970 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
4971 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
4972 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
4973 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
4974 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
4975 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
4976 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
4977 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
4978 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
4979 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004980 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE:return"CDMA_SET_SUBSCRIPTION_SOURCE";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004981 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"CDMA_SET_ROAMING_PREFERENCE";
4982 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"CDMA_QUERY_ROAMING_PREFERENCE";
4983 case RIL_REQUEST_SET_TTY_MODE:return"SET_TTY_MODE";
4984 case RIL_REQUEST_QUERY_TTY_MODE:return"QUERY_TTY_MODE";
4985 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
4986 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
4987 case RIL_REQUEST_CDMA_FLASH:return"CDMA_FLASH";
4988 case RIL_REQUEST_CDMA_BURST_DTMF:return"CDMA_BURST_DTMF";
4989 case RIL_REQUEST_CDMA_SEND_SMS:return"CDMA_SEND_SMS";
4990 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:return"CDMA_SMS_ACKNOWLEDGE";
4991 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG:return"GSM_GET_BROADCAST_SMS_CONFIG";
4992 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG:return"GSM_SET_BROADCAST_SMS_CONFIG";
4993 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG:return "CDMA_GET_BROADCAST_SMS_CONFIG";
4994 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG:return "CDMA_SET_BROADCAST_SMS_CONFIG";
4995 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION:return "CDMA_SMS_BROADCAST_ACTIVATION";
Ethan Chend6e30652013-08-04 22:49:56 -07004996 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return"CDMA_VALIDATE_AND_WRITE_AKEY";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004997 case RIL_REQUEST_CDMA_SUBSCRIPTION: return"CDMA_SUBSCRIPTION";
4998 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
4999 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
5000 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
5001 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
5002 case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
5003 case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
5004 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
5005 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
5006 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
5007 case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
5008 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
5009 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
5010 case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005011 case RIL_REQUEST_GET_CELL_INFO_LIST: return"GET_CELL_INFO_LIST";
5012 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return"SET_UNSOL_CELL_INFO_LIST_RATE";
Andrew Jiangca4a9a02014-01-18 18:04:08 -05005013 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "RIL_REQUEST_SET_INITIAL_ATTACH_APN";
5014 case RIL_REQUEST_IMS_REGISTRATION_STATE: return "IMS_REGISTRATION_STATE";
5015 case RIL_REQUEST_IMS_SEND_SMS: return "IMS_SEND_SMS";
Howard Sue32dbfd2015-01-07 15:55:57 +08005016 case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "SIM_TRANSMIT_APDU_BASIC";
5017 case RIL_REQUEST_SIM_OPEN_CHANNEL: return "SIM_OPEN_CHANNEL";
5018 case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "SIM_CLOSE_CHANNEL";
5019 case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "SIM_TRANSMIT_APDU_CHANNEL";
Howard Subd82ef12015-04-12 10:25:05 +02005020 case RIL_REQUEST_GET_RADIO_CAPABILITY: return "RIL_REQUEST_GET_RADIO_CAPABILITY";
5021 case RIL_REQUEST_SET_RADIO_CAPABILITY: return "RIL_REQUEST_SET_RADIO_CAPABILITY";
Howard Sue32dbfd2015-01-07 15:55:57 +08005022 case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "SET_UICC_SUBSCRIPTION";
5023 case RIL_REQUEST_ALLOW_DATA: return "ALLOW_DATA";
5024 case RIL_REQUEST_GET_HARDWARE_CONFIG: return "GET_HARDWARE_CONFIG";
5025 case RIL_REQUEST_SIM_AUTHENTICATION: return "SIM_AUTHENTICATION";
5026 case RIL_REQUEST_GET_DC_RT_INFO: return "GET_DC_RT_INFO";
5027 case RIL_REQUEST_SET_DC_RT_INFO_RATE: return "SET_DC_RT_INFO_RATE";
5028 case RIL_REQUEST_SET_DATA_PROFILE: return "SET_DATA_PROFILE";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005029 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
5030 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
5031 case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED";
5032 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
5033 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
5034 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
5035 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
5036 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)";
5037 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
5038 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
Howard Subd82ef12015-04-12 10:25:05 +02005039 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
5040 case RIL_UNSOL_SUPP_SVC_NOTIFICATION: return "UNSOL_SUPP_SVC_NOTIFICATION";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005041 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
5042 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
5043 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
5044 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
5045 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL";
5046 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005047 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
5048 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
5049 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_NEW_CDMA_SMS";
5050 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_NEW_BROADCAST_SMS";
5051 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
5052 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
5053 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
5054 case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
5055 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
5056 case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
5057 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
5058 case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
5059 case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
5060 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
5061 case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
5062 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
5063 case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
5064 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
Ethan Chend6e30652013-08-04 22:49:56 -07005065 case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
Andrew Jiangca4a9a02014-01-18 18:04:08 -05005066 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "RESPONSE_IMS_NETWORK_STATE_CHANGED";
Howard Sue32dbfd2015-01-07 15:55:57 +08005067 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return "UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED";
5068 case RIL_UNSOL_SRVCC_STATE_NOTIFY: return "UNSOL_SRVCC_STATE_NOTIFY";
5069 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return "HARDWARE_CONFIG_CHANGED";
5070 case RIL_UNSOL_DC_RT_INFO_CHANGED: return "UNSOL_DC_RT_INFO_CHANGED";
Howard Subd82ef12015-04-12 10:25:05 +02005071 case RIL_UNSOL_RADIO_CAPABILITY: return "UNSOL_RADIO_CAPABILITY";
5072 case RIL_UNSOL_ON_SS: return "UNSOL_ON_SS";
5073 case RIL_UNSOL_STK_CC_ALPHA_NOTIFY: return "UNSOL_STK_CC_ALPHA_NOTIFY";
Howard Sue32dbfd2015-01-07 15:55:57 +08005074 case RIL_REQUEST_SHUTDOWN: return "SHUTDOWN";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005075 default: return "<unknown request>";
5076 }
5077}
5078
Howard Sue32dbfd2015-01-07 15:55:57 +08005079const char *
5080rilSocketIdToString(RIL_SOCKET_ID socket_id)
5081{
5082 switch(socket_id) {
5083 case RIL_SOCKET_1:
5084 return "RIL_SOCKET_1";
5085#if (SIM_COUNT >= 2)
5086 case RIL_SOCKET_2:
5087 return "RIL_SOCKET_2";
5088#endif
5089#if (SIM_COUNT >= 3)
5090 case RIL_SOCKET_3:
5091 return "RIL_SOCKET_3";
5092#endif
5093#if (SIM_COUNT >= 4)
5094 case RIL_SOCKET_4:
5095 return "RIL_SOCKET_4";
5096#endif
5097 default:
5098 return "not a valid RIL";
5099 }
5100}
5101
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005102} /* namespace android */