blob: 41c3833fff63557c465ae8970efa98edb0d16863 [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>
Daniel Hillenbrand601dc852013-07-07 10:06:59 +020021#include <telephony/ril.h>
22#include <telephony/ril_cdma_sms.h>
23#include <cutils/sockets.h>
24#include <cutils/jstring.h>
Andrew Jiangca4a9a02014-01-18 18:04:08 -050025#include <telephony/record_stream.h>
Daniel Hillenbrand601dc852013-07-07 10:06:59 +020026#include <utils/Log.h>
27#include <utils/SystemClock.h>
28#include <pthread.h>
29#include <binder/Parcel.h>
30#include <cutils/jstring.h>
Daniel Hillenbrand601dc852013-07-07 10:06:59 +020031#include <sys/types.h>
XpLoDWilDba5c6a32013-07-27 21:12:19 +020032#include <sys/limits.h>
Daniel Hillenbrand601dc852013-07-07 10:06:59 +020033#include <pwd.h>
Daniel Hillenbrand601dc852013-07-07 10:06:59 +020034#include <stdio.h>
35#include <stdlib.h>
36#include <stdarg.h>
37#include <string.h>
38#include <unistd.h>
39#include <fcntl.h>
40#include <time.h>
41#include <errno.h>
42#include <assert.h>
43#include <ctype.h>
44#include <alloca.h>
45#include <sys/un.h>
46#include <assert.h>
47#include <netinet/in.h>
48#include <cutils/properties.h>
Dheeraj Shettycc231012014-07-02 21:27:57 +020049#include <RilSapSocket.h>
Daniel Hillenbrand601dc852013-07-07 10:06:59 +020050
Dheeraj Shettycc231012014-07-02 21:27:57 +020051extern "C" void
52RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +020053namespace android {
54
55#define PHONE_PROCESS "radio"
Dheeraj Shettycc231012014-07-02 21:27:57 +020056#define BLUETOOTH_PROCESS "bluetooth"
Daniel Hillenbrand601dc852013-07-07 10:06:59 +020057
58#define SOCKET_NAME_RIL "rild"
Howard Sue32dbfd2015-01-07 15:55:57 +080059#define SOCKET2_NAME_RIL "rild2"
60#define SOCKET3_NAME_RIL "rild3"
61#define SOCKET4_NAME_RIL "rild4"
62
Daniel Hillenbrand601dc852013-07-07 10:06:59 +020063#define SOCKET_NAME_RIL_DEBUG "rild-debug"
64
65#define ANDROID_WAKE_LOCK_NAME "radio-interface"
66
Nathan Haroldd6306fa2015-07-28 14:54:58 -070067#define ANDROID_WAKE_LOCK_SECS 0
68#define ANDROID_WAKE_LOCK_USECS 200000
Daniel Hillenbrand601dc852013-07-07 10:06:59 +020069
70#define PROPERTY_RIL_IMPL "gsm.version.ril-impl"
71
72// match with constant in RIL.java
73#define MAX_COMMAND_BYTES (8 * 1024)
74
75// Basically: memset buffers that the client library
76// shouldn't be using anymore in an attempt to find
77// memory usage issues sooner.
78#define MEMSET_FREED 1
79
80#define NUM_ELEMS(a) (sizeof (a) / sizeof (a)[0])
81
82#define MIN(a,b) ((a)<(b) ? (a) : (b))
83
84/* Constants for response types */
85#define RESPONSE_SOLICITED 0
86#define RESPONSE_UNSOLICITED 1
87
88/* Negative values for private RIL errno's */
89#define RIL_ERRNO_INVALID_RESPONSE -1
90
91// request, response, and unsolicited msg print macro
92#define PRINTBUF_SIZE 8096
93
Robert Greenwaltbc29c432015-04-29 16:57:39 -070094// Enable verbose logging
95#define VDBG 0
96
Daniel Hillenbrand601dc852013-07-07 10:06:59 +020097// Enable RILC log
98#define RILC_LOG 0
99
100#if RILC_LOG
101 #define startRequest sprintf(printBuf, "(")
102 #define closeRequest sprintf(printBuf, "%s)", printBuf)
forkbombe0568e12015-11-23 18:37:37 +1100103 #define printRequest(token, req) \
104 RLOGD("[%04d]> %s %s", token, requestToString(req), printBuf)
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200105
106 #define startResponse sprintf(printBuf, "%s {", printBuf)
107 #define closeResponse sprintf(printBuf, "%s}", printBuf)
XpLoDWilDba5c6a32013-07-27 21:12:19 +0200108 #define printResponse RLOGD("%s", printBuf)
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200109
110 #define clearPrintBuf printBuf[0] = 0
111 #define removeLastChar printBuf[strlen(printBuf)-1] = 0
Ajay Nambi323c8822015-08-05 14:53:50 +0530112 #define appendPrintBuf(x...) snprintf(printBuf, PRINTBUF_SIZE, x)
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200113#else
114 #define startRequest
115 #define closeRequest
116 #define printRequest(token, req)
117 #define startResponse
118 #define closeResponse
119 #define printResponse
120 #define clearPrintBuf
121 #define removeLastChar
122 #define appendPrintBuf(x...)
123#endif
124
125enum WakeType {DONT_WAKE, WAKE_PARTIAL};
126
127typedef struct {
128 int requestNumber;
129 void (*dispatchFunction) (Parcel &p, struct RequestInfo *pRI);
130 int(*responseFunction) (Parcel &p, void *response, size_t responselen);
131} CommandInfo;
132
133typedef struct {
134 int requestNumber;
135 int (*responseFunction) (Parcel &p, void *response, size_t responselen);
136 WakeType wakeType;
137} UnsolResponseInfo;
138
139typedef struct RequestInfo {
140 int32_t token; //this is not RIL_Token
141 CommandInfo *pCI;
142 struct RequestInfo *p_next;
143 char cancelled;
144 char local; // responses to local commands do not go back to command process
Howard Sue32dbfd2015-01-07 15:55:57 +0800145 RIL_SOCKET_ID socket_id;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200146} RequestInfo;
147
148typedef struct UserCallbackInfo {
149 RIL_TimedCallback p_callback;
150 void *userParam;
151 struct ril_event event;
152 struct UserCallbackInfo *p_next;
153} UserCallbackInfo;
154
Howard Sue32dbfd2015-01-07 15:55:57 +0800155extern "C" const char * requestToString(int request);
156extern "C" const char * failCauseToString(RIL_Errno);
157extern "C" const char * callStateToString(RIL_CallState);
158extern "C" const char * radioStateToString(RIL_RadioState);
159extern "C" const char * rilSocketIdToString(RIL_SOCKET_ID socket_id);
160
161extern "C"
162char rild[MAX_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200163
Howard Subd82ef12015-04-12 10:25:05 +0200164#define RIL_VENDOR_COMMANDS_OFFSET 10000
165
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200166/*******************************************************************/
167
168RIL_RadioFunctions s_callbacks = {0, NULL, NULL, NULL, NULL, NULL};
169static int s_registerCalled = 0;
170
171static pthread_t s_tid_dispatch;
172static pthread_t s_tid_reader;
173static int s_started = 0;
174
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200175static int s_fdDebug = -1;
Howard Sue32dbfd2015-01-07 15:55:57 +0800176static int s_fdDebug_socket2 = -1;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200177
178static int s_fdWakeupRead;
179static int s_fdWakeupWrite;
180
181static struct ril_event s_commands_event;
182static struct ril_event s_wakeupfd_event;
183static struct ril_event s_listen_event;
Howard Sue32dbfd2015-01-07 15:55:57 +0800184static SocketListenParam s_ril_param_socket;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200185
186static pthread_mutex_t s_pendingRequestsMutex = PTHREAD_MUTEX_INITIALIZER;
187static pthread_mutex_t s_writeMutex = PTHREAD_MUTEX_INITIALIZER;
Howard Sue32dbfd2015-01-07 15:55:57 +0800188static RequestInfo *s_pendingRequests = NULL;
189
190#if (SIM_COUNT >= 2)
191static struct ril_event s_commands_event_socket2;
192static struct ril_event s_listen_event_socket2;
193static SocketListenParam s_ril_param_socket2;
194
195static pthread_mutex_t s_pendingRequestsMutex_socket2 = PTHREAD_MUTEX_INITIALIZER;
196static pthread_mutex_t s_writeMutex_socket2 = PTHREAD_MUTEX_INITIALIZER;
197static RequestInfo *s_pendingRequests_socket2 = NULL;
198#endif
199
200#if (SIM_COUNT >= 3)
201static struct ril_event s_commands_event_socket3;
202static struct ril_event s_listen_event_socket3;
203static SocketListenParam s_ril_param_socket3;
204
205static pthread_mutex_t s_pendingRequestsMutex_socket3 = PTHREAD_MUTEX_INITIALIZER;
206static pthread_mutex_t s_writeMutex_socket3 = PTHREAD_MUTEX_INITIALIZER;
207static RequestInfo *s_pendingRequests_socket3 = NULL;
208#endif
209
210#if (SIM_COUNT >= 4)
211static struct ril_event s_commands_event_socket4;
212static struct ril_event s_listen_event_socket4;
213static SocketListenParam s_ril_param_socket4;
214
215static pthread_mutex_t s_pendingRequestsMutex_socket4 = PTHREAD_MUTEX_INITIALIZER;
216static pthread_mutex_t s_writeMutex_socket4 = PTHREAD_MUTEX_INITIALIZER;
217static RequestInfo *s_pendingRequests_socket4 = NULL;
218#endif
219
220static struct ril_event s_wake_timeout_event;
221static struct ril_event s_debug_event;
222
Howard Subd82ef12015-04-12 10:25:05 +0200223
Nathan Haroldd6306fa2015-07-28 14:54:58 -0700224static const struct timeval TIMEVAL_WAKE_TIMEOUT = {ANDROID_WAKE_LOCK_SECS,ANDROID_WAKE_LOCK_USECS};
Howard Sue32dbfd2015-01-07 15:55:57 +0800225
Howard Subd82ef12015-04-12 10:25:05 +0200226
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200227static pthread_mutex_t s_startupMutex = PTHREAD_MUTEX_INITIALIZER;
228static pthread_cond_t s_startupCond = PTHREAD_COND_INITIALIZER;
229
230static pthread_mutex_t s_dispatchMutex = PTHREAD_MUTEX_INITIALIZER;
231static pthread_cond_t s_dispatchCond = PTHREAD_COND_INITIALIZER;
232
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200233static RequestInfo *s_toDispatchHead = NULL;
234static RequestInfo *s_toDispatchTail = NULL;
235
236static UserCallbackInfo *s_last_wake_timeout_info = NULL;
237
238static void *s_lastNITZTimeData = NULL;
239static size_t s_lastNITZTimeDataSize;
240
241#if RILC_LOG
242 static char printBuf[PRINTBUF_SIZE];
243#endif
244
245/*******************************************************************/
Howard Sue32dbfd2015-01-07 15:55:57 +0800246static int sendResponse (Parcel &p, RIL_SOCKET_ID socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200247
248static void dispatchVoid (Parcel& p, RequestInfo *pRI);
249static void dispatchString (Parcel& p, RequestInfo *pRI);
250static void dispatchStrings (Parcel& p, RequestInfo *pRI);
251static void dispatchInts (Parcel& p, RequestInfo *pRI);
252static void dispatchDial (Parcel& p, RequestInfo *pRI);
253static void dispatchSIM_IO (Parcel& p, RequestInfo *pRI);
Howard Sue32dbfd2015-01-07 15:55:57 +0800254static void dispatchSIM_APDU (Parcel& p, RequestInfo *pRI);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200255static void dispatchCallForward(Parcel& p, RequestInfo *pRI);
256static void dispatchRaw(Parcel& p, RequestInfo *pRI);
257static void dispatchSmsWrite (Parcel &p, RequestInfo *pRI);
258static void dispatchDataCall (Parcel& p, RequestInfo *pRI);
259static void dispatchVoiceRadioTech (Parcel& p, RequestInfo *pRI);
Andrew Jiangca4a9a02014-01-18 18:04:08 -0500260static void dispatchSetInitialAttachApn (Parcel& p, RequestInfo *pRI);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200261static void dispatchCdmaSubscriptionSource (Parcel& p, RequestInfo *pRI);
262
263static void dispatchCdmaSms(Parcel &p, RequestInfo *pRI);
Andrew Jiangca4a9a02014-01-18 18:04:08 -0500264static void dispatchImsSms(Parcel &p, RequestInfo *pRI);
265static void dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
266static void dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200267static void dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI);
268static void dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI);
269static void dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI);
270static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI);
Howard Sue32dbfd2015-01-07 15:55:57 +0800271static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI);
272static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI);
273static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI);
274static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI);
275static void dispatchDataProfile(Parcel &p, RequestInfo *pRI);
Howard Subd82ef12015-04-12 10:25:05 +0200276static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200277static int responseInts(Parcel &p, void *response, size_t responselen);
Daniel Hillenbrandd0b84162015-04-12 11:53:23 +0200278static int responseIntsGetPreferredNetworkType(Parcel &p, void *response, size_t responselen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200279static int responseStrings(Parcel &p, void *response, size_t responselen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200280static int responseString(Parcel &p, void *response, size_t responselen);
281static int responseVoid(Parcel &p, void *response, size_t responselen);
282static int responseCallList(Parcel &p, void *response, size_t responselen);
283static int responseSMS(Parcel &p, void *response, size_t responselen);
284static int responseSIM_IO(Parcel &p, void *response, size_t responselen);
285static int responseCallForwards(Parcel &p, void *response, size_t responselen);
286static int responseDataCallList(Parcel &p, void *response, size_t responselen);
287static int responseSetupDataCall(Parcel &p, void *response, size_t responselen);
288static int responseRaw(Parcel &p, void *response, size_t responselen);
289static int responseSsn(Parcel &p, void *response, size_t responselen);
290static int responseSimStatus(Parcel &p, void *response, size_t responselen);
291static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen);
292static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen);
293static int responseCdmaSms(Parcel &p, void *response, size_t responselen);
294static int responseCellList(Parcel &p, void *response, size_t responselen);
295static int responseCdmaInformationRecords(Parcel &p,void *response, size_t responselen);
296static int responseRilSignalStrength(Parcel &p,void *response, size_t responselen);
297static int responseCallRing(Parcel &p, void *response, size_t responselen);
298static int responseCdmaSignalInfoRecord(Parcel &p,void *response, size_t responselen);
299static int responseCdmaCallWaiting(Parcel &p,void *response, size_t responselen);
300static int responseSimRefresh(Parcel &p, void *response, size_t responselen);
XpLoDWilDba5c6a32013-07-27 21:12:19 +0200301static int responseCellInfoList(Parcel &p, void *response, size_t responselen);
Howard Sue32dbfd2015-01-07 15:55:57 +0800302static int responseHardwareConfig(Parcel &p, void *response, size_t responselen);
303static int responseDcRtInfo(Parcel &p, void *response, size_t responselen);
Howard Subd82ef12015-04-12 10:25:05 +0200304static int responseRadioCapability(Parcel &p, void *response, size_t responselen);
305static int responseSSData(Parcel &p, void *response, size_t responselen);
fenglu9bdede02015-04-14 14:53:55 -0700306static int responseLceStatus(Parcel &p, void *response, size_t responselen);
307static int responseLceData(Parcel &p, void *response, size_t responselen);
Prerepa Viswanadham8e755592015-05-28 00:37:32 -0700308static int responseActivityData(Parcel &p, void *response, size_t responselen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200309
310static int decodeVoiceRadioTechnology (RIL_RadioState radioState);
311static int decodeCdmaSubscriptionSource (RIL_RadioState radioState);
Howard Subd82ef12015-04-12 10:25:05 +0200312static RIL_RadioState processRadioState(RIL_RadioState newRadioState);
313
314static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200315
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200316#ifdef RIL_SHLIB
Howard Sue32dbfd2015-01-07 15:55:57 +0800317#if defined(ANDROID_MULTI_SIM)
Andreas Schneider47b2d962015-04-13 22:54:49 +0200318extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Howard Sue32dbfd2015-01-07 15:55:57 +0800319 size_t datalen, RIL_SOCKET_ID socket_id);
320#else
Andreas Schneider47b2d962015-04-13 22:54:49 +0200321extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200322 size_t datalen);
323#endif
Howard Sue32dbfd2015-01-07 15:55:57 +0800324#endif
325
326#if defined(ANDROID_MULTI_SIM)
327#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c), (d))
328#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d), (e))
329#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest(a)
330#else
331#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c))
332#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d))
333#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest()
334#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200335
336static UserCallbackInfo * internalRequestTimedCallback
337 (RIL_TimedCallback callback, void *param,
338 const struct timeval *relativeTime);
339
340/** Index == requestNumber */
341static CommandInfo s_commands[] = {
342#include "ril_commands.h"
343};
344
345static UnsolResponseInfo s_unsolResponses[] = {
346#include "ril_unsol_commands.h"
347};
348
Christopher N. Hessec694ff02016-03-27 21:04:38 +0200349static CommandInfo s_commands_v[] = {
350#include <telephony/ril_commands_vendor.h>
351};
352
Howard Subd82ef12015-04-12 10:25:05 +0200353static UnsolResponseInfo s_unsolResponses_v[] = {
Christopher N. Hessec694ff02016-03-27 21:04:38 +0200354#include <telephony/ril_unsol_commands_vendor.h>
Howard Subd82ef12015-04-12 10:25:05 +0200355};
356
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200357/* For older RILs that do not support new commands RIL_REQUEST_VOICE_RADIO_TECH and
358 RIL_UNSOL_VOICE_RADIO_TECH_CHANGED messages, decode the voice radio tech from
359 radio state message and store it. Every time there is a change in Radio State
360 check to see if voice radio tech changes and notify telephony
361 */
362int voiceRadioTech = -1;
363
364/* For older RILs that do not support new commands RIL_REQUEST_GET_CDMA_SUBSCRIPTION_SOURCE
365 and RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED messages, decode the subscription
366 source from radio state and store it. Every time there is a change in Radio State
367 check to see if subscription source changed and notify telephony
368 */
369int cdmaSubscriptionSource = -1;
370
371/* For older RILs that do not send RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, decode the
372 SIM/RUIM state from radio state and store it. Every time there is a change in Radio State,
373 check to see if SIM/RUIM status changed and notify telephony
374 */
375int simRuimStatus = -1;
376
Howard Sue32dbfd2015-01-07 15:55:57 +0800377static char * RIL_getRilSocketName() {
378 return rild;
379}
380
381extern "C"
Dheeraj Shettycc231012014-07-02 21:27:57 +0200382void RIL_setRilSocketName(const char * s) {
Howard Sue32dbfd2015-01-07 15:55:57 +0800383 strncpy(rild, s, MAX_SOCKET_NAME_LENGTH);
384}
385
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200386static char *
387strdupReadString(Parcel &p) {
388 size_t stringlen;
389 const char16_t *s16;
390
391 s16 = p.readString16Inplace(&stringlen);
392
393 return strndup16to8(s16, stringlen);
394}
395
Howard Subd82ef12015-04-12 10:25:05 +0200396static status_t
397readStringFromParcelInplace(Parcel &p, char *str, size_t maxLen) {
398 size_t s16Len;
399 const char16_t *s16;
400
401 s16 = p.readString16Inplace(&s16Len);
402 if (s16 == NULL) {
403 return NO_MEMORY;
404 }
405 size_t strLen = strnlen16to8(s16, s16Len);
406 if ((strLen + 1) > maxLen) {
407 return NO_MEMORY;
408 }
409 if (strncpy16to8(str, s16, strLen) == NULL) {
410 return NO_MEMORY;
411 } else {
412 return NO_ERROR;
413 }
414}
415
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200416static void writeStringToParcel(Parcel &p, const char *s) {
417 char16_t *s16;
418 size_t s16_len;
419 s16 = strdup8to16(s, &s16_len);
420 p.writeString16(s16, s16_len);
421 free(s16);
422}
423
424
425static void
426memsetString (char *s) {
427 if (s != NULL) {
428 memset (s, 0, strlen(s));
429 }
430}
431
432void nullParcelReleaseFunction (const uint8_t* data, size_t dataSize,
433 const size_t* objects, size_t objectsSize,
434 void* cookie) {
435 // do nothing -- the data reference lives longer than the Parcel object
436}
437
438/**
439 * To be called from dispatch thread
440 * Issue a single local request, ensuring that the response
441 * is not sent back up to the command process
442 */
443static void
Howard Sue32dbfd2015-01-07 15:55:57 +0800444issueLocalRequest(int request, void *data, int len, RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200445 RequestInfo *pRI;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200446 int ret;
Howard Sue32dbfd2015-01-07 15:55:57 +0800447 /* Hook for current context */
448 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
449 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
450 /* pendingRequestsHook refer to &s_pendingRequests */
451 RequestInfo** pendingRequestsHook = &s_pendingRequests;
452
453#if (SIM_COUNT == 2)
454 if (socket_id == RIL_SOCKET_2) {
455 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
456 pendingRequestsHook = &s_pendingRequests_socket2;
457 }
458#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200459
460 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
461
462 pRI->local = 1;
463 pRI->token = 0xffffffff; // token is not used in this context
464
Howard Subd82ef12015-04-12 10:25:05 +0200465 /* Check vendor commands */
466 if (request > RIL_VENDOR_COMMANDS_OFFSET) {
467 pRI->pCI = &(s_commands_v[request - RIL_VENDOR_COMMANDS_OFFSET]);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200468 } else {
469 pRI->pCI = &(s_commands[request]);
470 }
Howard Sue32dbfd2015-01-07 15:55:57 +0800471 pRI->socket_id = socket_id;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200472
Howard Sue32dbfd2015-01-07 15:55:57 +0800473 ret = pthread_mutex_lock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200474 assert (ret == 0);
475
Howard Sue32dbfd2015-01-07 15:55:57 +0800476 pRI->p_next = *pendingRequestsHook;
477 *pendingRequestsHook = pRI;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200478
Howard Sue32dbfd2015-01-07 15:55:57 +0800479 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200480 assert (ret == 0);
481
XpLoDWilDba5c6a32013-07-27 21:12:19 +0200482 RLOGD("C[locl]> %s", requestToString(request));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200483
Howard Sue32dbfd2015-01-07 15:55:57 +0800484 CALL_ONREQUEST(request, data, len, pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200485}
486
Howard Subd82ef12015-04-12 10:25:05 +0200487
488
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200489static int
Howard Sue32dbfd2015-01-07 15:55:57 +0800490processCommandBuffer(void *buffer, size_t buflen, RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200491 Parcel p;
492 status_t status;
493 int32_t request;
494 int32_t token;
495 RequestInfo *pRI;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200496 int ret;
Howard Sue32dbfd2015-01-07 15:55:57 +0800497 /* Hook for current context */
498 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
499 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
500 /* pendingRequestsHook refer to &s_pendingRequests */
501 RequestInfo** pendingRequestsHook = &s_pendingRequests;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200502
503 p.setData((uint8_t *) buffer, buflen);
504
505 // status checked at end
506 status = p.readInt32(&request);
507 status = p.readInt32 (&token);
508
Howard Sue32dbfd2015-01-07 15:55:57 +0800509#if (SIM_COUNT >= 2)
510 if (socket_id == RIL_SOCKET_2) {
511 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
512 pendingRequestsHook = &s_pendingRequests_socket2;
513 }
514#if (SIM_COUNT >= 3)
515 else if (socket_id == RIL_SOCKET_3) {
516 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
517 pendingRequestsHook = &s_pendingRequests_socket3;
518 }
519#endif
520#if (SIM_COUNT >= 4)
521 else if (socket_id == RIL_SOCKET_4) {
522 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
523 pendingRequestsHook = &s_pendingRequests_socket4;
524 }
525#endif
526#endif
527
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200528 if (status != NO_ERROR) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +0200529 RLOGE("invalid request block");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200530 return 0;
531 }
532
Howard Subd82ef12015-04-12 10:25:05 +0200533 CommandInfo *pCI = NULL;
534 if (request > RIL_VENDOR_COMMANDS_OFFSET) {
535 int index = request - RIL_VENDOR_COMMANDS_OFFSET;
536 RLOGD("processCommandBuffer: samsung request=%d, index=%d",
537 request, index);
538 if (index < (int32_t)NUM_ELEMS(s_commands_v))
539 pCI = &(s_commands_v[index]);
540 } else {
541 if (request < (int32_t)NUM_ELEMS(s_commands))
542 pCI = &(s_commands[request]);
543 }
Howard Sue32dbfd2015-01-07 15:55:57 +0800544
Howard Subd82ef12015-04-12 10:25:05 +0200545 if (pCI == NULL) {
546 Parcel pErr;
XpLoDWilDba5c6a32013-07-27 21:12:19 +0200547 RLOGE("unsupported request code %d token %d", request, token);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200548 // FIXME this should perhaps return a response
Howard Sue32dbfd2015-01-07 15:55:57 +0800549 pErr.writeInt32 (RESPONSE_SOLICITED);
550 pErr.writeInt32 (token);
551 pErr.writeInt32 (RIL_E_GENERIC_FAILURE);
552
553 sendResponse(pErr, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200554 return 0;
555 }
556
557 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
558
559 pRI->token = token;
Howard Subd82ef12015-04-12 10:25:05 +0200560 pRI->pCI = pCI;
Howard Sue32dbfd2015-01-07 15:55:57 +0800561 pRI->socket_id = socket_id;
562
563 ret = pthread_mutex_lock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200564 assert (ret == 0);
565
Howard Sue32dbfd2015-01-07 15:55:57 +0800566 pRI->p_next = *pendingRequestsHook;
567 *pendingRequestsHook = pRI;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200568
Howard Sue32dbfd2015-01-07 15:55:57 +0800569 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200570 assert (ret == 0);
571
572/* sLastDispatchedToken = token; */
573
574 pRI->pCI->dispatchFunction(p, pRI);
575
576 return 0;
577}
578
579static void
580invalidCommandBlock (RequestInfo *pRI) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +0200581 RLOGE("invalid command block for token %d request %s",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200582 pRI->token, requestToString(pRI->pCI->requestNumber));
583}
584
585/** Callee expects NULL */
586static void
587dispatchVoid (Parcel& p, RequestInfo *pRI) {
588 clearPrintBuf;
589 printRequest(pRI->token, pRI->pCI->requestNumber);
Howard Sue32dbfd2015-01-07 15:55:57 +0800590 CALL_ONREQUEST(pRI->pCI->requestNumber, NULL, 0, pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200591}
592
593/** Callee expects const char * */
594static void
595dispatchString (Parcel& p, RequestInfo *pRI) {
596 status_t status;
597 size_t datalen;
598 size_t stringlen;
599 char *string8 = NULL;
600
601 string8 = strdupReadString(p);
602
603 startRequest;
604 appendPrintBuf("%s%s", printBuf, string8);
605 closeRequest;
606 printRequest(pRI->token, pRI->pCI->requestNumber);
607
Howard Sue32dbfd2015-01-07 15:55:57 +0800608 CALL_ONREQUEST(pRI->pCI->requestNumber, string8,
609 sizeof(char *), pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200610
611#ifdef MEMSET_FREED
612 memsetString(string8);
613#endif
614
615 free(string8);
616 return;
617invalid:
618 invalidCommandBlock(pRI);
619 return;
620}
621
622/** Callee expects const char ** */
623static void
624dispatchStrings (Parcel &p, RequestInfo *pRI) {
625 int32_t countStrings;
626 status_t status;
627 size_t datalen;
628 char **pStrings;
629
630 status = p.readInt32 (&countStrings);
631
632 if (status != NO_ERROR) {
633 goto invalid;
634 }
635
636 startRequest;
637 if (countStrings == 0) {
638 // just some non-null pointer
639 pStrings = (char **)alloca(sizeof(char *));
640 datalen = 0;
641 } else if (((int)countStrings) == -1) {
642 pStrings = NULL;
643 datalen = 0;
644 } else {
645 datalen = sizeof(char *) * countStrings;
646
647 pStrings = (char **)alloca(datalen);
648
649 for (int i = 0 ; i < countStrings ; i++) {
650 pStrings[i] = strdupReadString(p);
651 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
652 }
653 }
654 removeLastChar;
655 closeRequest;
656 printRequest(pRI->token, pRI->pCI->requestNumber);
657
Howard Sue32dbfd2015-01-07 15:55:57 +0800658 CALL_ONREQUEST(pRI->pCI->requestNumber, pStrings, datalen, pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200659
660 if (pStrings != NULL) {
661 for (int i = 0 ; i < countStrings ; i++) {
662#ifdef MEMSET_FREED
663 memsetString (pStrings[i]);
664#endif
665 free(pStrings[i]);
666 }
667
668#ifdef MEMSET_FREED
669 memset(pStrings, 0, datalen);
670#endif
671 }
672
673 return;
674invalid:
675 invalidCommandBlock(pRI);
676 return;
677}
678
679/** Callee expects const int * */
680static void
681dispatchInts (Parcel &p, RequestInfo *pRI) {
682 int32_t count;
683 status_t status;
684 size_t datalen;
685 int *pInts;
686
687 status = p.readInt32 (&count);
688
689 if (status != NO_ERROR || count == 0) {
690 goto invalid;
691 }
692
693 datalen = sizeof(int) * count;
694 pInts = (int *)alloca(datalen);
695
696 startRequest;
697 for (int i = 0 ; i < count ; i++) {
698 int32_t t;
699
700 status = p.readInt32(&t);
701 pInts[i] = (int)t;
702 appendPrintBuf("%s%d,", printBuf, t);
703
704 if (status != NO_ERROR) {
705 goto invalid;
706 }
707 }
708 removeLastChar;
709 closeRequest;
710 printRequest(pRI->token, pRI->pCI->requestNumber);
711
Howard Sue32dbfd2015-01-07 15:55:57 +0800712 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<int *>(pInts),
713 datalen, pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200714
715#ifdef MEMSET_FREED
716 memset(pInts, 0, datalen);
717#endif
718
719 return;
720invalid:
721 invalidCommandBlock(pRI);
722 return;
723}
724
725
726/**
727 * Callee expects const RIL_SMS_WriteArgs *
728 * Payload is:
729 * int32_t status
730 * String pdu
731 */
732static void
733dispatchSmsWrite (Parcel &p, RequestInfo *pRI) {
734 RIL_SMS_WriteArgs args;
735 int32_t t;
736 status_t status;
737
Mark Salyzyn961fd022015-04-09 07:18:35 -0700738 RLOGD("dispatchSmsWrite");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200739 memset (&args, 0, sizeof(args));
740
741 status = p.readInt32(&t);
742 args.status = (int)t;
743
744 args.pdu = strdupReadString(p);
745
746 if (status != NO_ERROR || args.pdu == NULL) {
747 goto invalid;
748 }
749
750 args.smsc = strdupReadString(p);
751
752 startRequest;
753 appendPrintBuf("%s%d,%s,smsc=%s", printBuf, args.status,
754 (char*)args.pdu, (char*)args.smsc);
755 closeRequest;
756 printRequest(pRI->token, pRI->pCI->requestNumber);
757
Howard Sue32dbfd2015-01-07 15:55:57 +0800758 CALL_ONREQUEST(pRI->pCI->requestNumber, &args, sizeof(args), pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200759
760#ifdef MEMSET_FREED
761 memsetString (args.pdu);
762#endif
763
764 free (args.pdu);
765
766#ifdef MEMSET_FREED
767 memset(&args, 0, sizeof(args));
768#endif
769
770 return;
771invalid:
772 invalidCommandBlock(pRI);
773 return;
774}
775
776/**
777 * Callee expects const RIL_Dial *
778 * Payload is:
779 * String address
780 * int32_t clir
781 */
782static void
783dispatchDial (Parcel &p, RequestInfo *pRI) {
784 RIL_Dial dial;
785 RIL_UUS_Info uusInfo;
786 int32_t sizeOfDial;
787 int32_t t;
788 int32_t uusPresent;
Christopher N. Hesse621e63e2016-02-22 21:57:39 +0100789#ifdef SAMSUNG_NEXT_GEN_MODEM
Andreas Schneider29472682015-01-01 19:00:04 +0100790 char *csv;
791#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200792 status_t status;
793
Mark Salyzyn961fd022015-04-09 07:18:35 -0700794 RLOGD("dispatchDial");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200795 memset (&dial, 0, sizeof(dial));
796
797 dial.address = strdupReadString(p);
798
799 status = p.readInt32(&t);
800 dial.clir = (int)t;
801
802 if (status != NO_ERROR || dial.address == NULL) {
803 goto invalid;
804 }
805
Christopher N. Hesse621e63e2016-02-22 21:57:39 +0100806#ifdef SAMSUNG_NEXT_GEN_MODEM
Andreas Schneider29472682015-01-01 19:00:04 +0100807 /* CallDetails.call_type */
808 status = p.readInt32(&t);
809 if (status != NO_ERROR) {
810 goto invalid;
811 }
812 /* CallDetails.call_domain */
813 p.readInt32(&t);
814 if (status != NO_ERROR) {
815 goto invalid;
816 }
817 /* CallDetails.getCsvFromExtra */
818 csv = strdupReadString(p);
819 if (csv == NULL) {
820 goto invalid;
821 }
822 free(csv);
823#endif
824
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200825 if (s_callbacks.version < 3) { // Remove when partners upgrade to version 3
826 uusPresent = 0;
827 sizeOfDial = sizeof(dial) - sizeof(RIL_UUS_Info *);
828 } else {
829 status = p.readInt32(&uusPresent);
830
831 if (status != NO_ERROR) {
832 goto invalid;
833 }
834
835 if (uusPresent == 0) {
Christopher N. Hesse621e63e2016-02-22 21:57:39 +0100836#if defined(MODEM_TYPE_XMM6262) || defined(SAMSUNG_NEXT_GEN_MODEM)
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200837 dial.uusInfo = NULL;
Andreas Schneiderf68609b2015-04-07 19:01:34 +0200838#elif defined(MODEM_TYPE_XMM6260)
Howard Sue32dbfd2015-01-07 15:55:57 +0800839 /* Samsung hack */
840 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
841 uusInfo.uusType = (RIL_UUS_Type) 0;
842 uusInfo.uusDcs = (RIL_UUS_DCS) 0;
843 uusInfo.uusData = NULL;
844 uusInfo.uusLength = 0;
845 dial.uusInfo = &uusInfo;
846#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200847 } else {
848 int32_t len;
849
850 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
851
852 status = p.readInt32(&t);
853 uusInfo.uusType = (RIL_UUS_Type) t;
854
855 status = p.readInt32(&t);
856 uusInfo.uusDcs = (RIL_UUS_DCS) t;
857
858 status = p.readInt32(&len);
859 if (status != NO_ERROR) {
860 goto invalid;
861 }
862
863 // The java code writes -1 for null arrays
864 if (((int) len) == -1) {
865 uusInfo.uusData = NULL;
866 len = 0;
867 } else {
868 uusInfo.uusData = (char*) p.readInplace(len);
869 }
870
871 uusInfo.uusLength = len;
872 dial.uusInfo = &uusInfo;
873 }
874 sizeOfDial = sizeof(dial);
875 }
876
877 startRequest;
878 appendPrintBuf("%snum=%s,clir=%d", printBuf, dial.address, dial.clir);
879 if (uusPresent) {
880 appendPrintBuf("%s,uusType=%d,uusDcs=%d,uusLen=%d", printBuf,
881 dial.uusInfo->uusType, dial.uusInfo->uusDcs,
882 dial.uusInfo->uusLength);
883 }
884 closeRequest;
885 printRequest(pRI->token, pRI->pCI->requestNumber);
886
Howard Sue32dbfd2015-01-07 15:55:57 +0800887 CALL_ONREQUEST(pRI->pCI->requestNumber, &dial, sizeOfDial, pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200888
889#ifdef MEMSET_FREED
890 memsetString (dial.address);
891#endif
892
893 free (dial.address);
894
895#ifdef MEMSET_FREED
896 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
897 memset(&dial, 0, sizeof(dial));
898#endif
899
900 return;
901invalid:
902 invalidCommandBlock(pRI);
903 return;
904}
905
906/**
907 * Callee expects const RIL_SIM_IO *
908 * Payload is:
909 * int32_t command
910 * int32_t fileid
911 * String path
912 * int32_t p1, p2, p3
913 * String data
914 * String pin2
915 * String aidPtr
916 */
917static void
918dispatchSIM_IO (Parcel &p, RequestInfo *pRI) {
919 union RIL_SIM_IO {
920 RIL_SIM_IO_v6 v6;
921 RIL_SIM_IO_v5 v5;
922 } simIO;
923
924 int32_t t;
925 int size;
926 status_t status;
927
Robert Greenwaltbc29c432015-04-29 16:57:39 -0700928#if VDBG
Mark Salyzyn961fd022015-04-09 07:18:35 -0700929 RLOGD("dispatchSIM_IO");
Robert Greenwaltbc29c432015-04-29 16:57:39 -0700930#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200931 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
Robert Greenwaltbc29c432015-04-29 16:57:39 -07001008#if VDBG
Mark Salyzyn961fd022015-04-09 07:18:35 -07001009 RLOGD("dispatchSIM_APDU");
Robert Greenwaltbc29c432015-04-29 16:57:39 -07001010#endif
Howard Sue32dbfd2015-01-07 15:55:57 +08001011 memset (&apdu, 0, sizeof(RIL_SIM_APDU));
1012
1013 // Note we only check status at the end. Any single failure leads to
1014 // subsequent reads filing.
1015 status = p.readInt32(&t);
1016 apdu.sessionid = (int)t;
1017
1018 status = p.readInt32(&t);
1019 apdu.cla = (int)t;
1020
1021 status = p.readInt32(&t);
1022 apdu.instruction = (int)t;
1023
1024 status = p.readInt32(&t);
1025 apdu.p1 = (int)t;
1026
1027 status = p.readInt32(&t);
1028 apdu.p2 = (int)t;
1029
1030 status = p.readInt32(&t);
1031 apdu.p3 = (int)t;
1032
1033 apdu.data = strdupReadString(p);
1034
1035 startRequest;
1036 appendPrintBuf("%ssessionid=%d,cla=%d,ins=%d,p1=%d,p2=%d,p3=%d,data=%s",
1037 printBuf, apdu.sessionid, apdu.cla, apdu.instruction, apdu.p1, apdu.p2,
1038 apdu.p3, (char*)apdu.data);
1039 closeRequest;
1040 printRequest(pRI->token, pRI->pCI->requestNumber);
1041
1042 if (status != NO_ERROR) {
1043 goto invalid;
1044 }
1045
1046 CALL_ONREQUEST(pRI->pCI->requestNumber, &apdu, sizeof(RIL_SIM_APDU), pRI, pRI->socket_id);
1047
1048#ifdef MEMSET_FREED
1049 memsetString(apdu.data);
1050#endif
1051 free(apdu.data);
1052
1053#ifdef MEMSET_FREED
1054 memset(&apdu, 0, sizeof(RIL_SIM_APDU));
1055#endif
1056
1057 return;
1058invalid:
1059 invalidCommandBlock(pRI);
1060 return;
1061}
1062
Howard Subd82ef12015-04-12 10:25:05 +02001063
Howard Sue32dbfd2015-01-07 15:55:57 +08001064/**
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001065 * Callee expects const RIL_CallForwardInfo *
1066 * Payload is:
1067 * int32_t status/action
1068 * int32_t reason
1069 * int32_t serviceCode
1070 * int32_t toa
1071 * String number (0 length -> null)
1072 * int32_t timeSeconds
1073 */
1074static void
1075dispatchCallForward(Parcel &p, RequestInfo *pRI) {
1076 RIL_CallForwardInfo cff;
1077 int32_t t;
1078 status_t status;
1079
Mark Salyzyn961fd022015-04-09 07:18:35 -07001080 RLOGD("dispatchCallForward");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001081 memset (&cff, 0, sizeof(cff));
1082
1083 // note we only check status at the end
1084
1085 status = p.readInt32(&t);
1086 cff.status = (int)t;
1087
1088 status = p.readInt32(&t);
1089 cff.reason = (int)t;
1090
1091 status = p.readInt32(&t);
1092 cff.serviceClass = (int)t;
1093
1094 status = p.readInt32(&t);
1095 cff.toa = (int)t;
1096
1097 cff.number = strdupReadString(p);
1098
1099 status = p.readInt32(&t);
1100 cff.timeSeconds = (int)t;
1101
1102 if (status != NO_ERROR) {
1103 goto invalid;
1104 }
1105
1106 // special case: number 0-length fields is null
1107
1108 if (cff.number != NULL && strlen (cff.number) == 0) {
1109 cff.number = NULL;
1110 }
1111
1112 startRequest;
1113 appendPrintBuf("%sstat=%d,reason=%d,serv=%d,toa=%d,%s,tout=%d", printBuf,
1114 cff.status, cff.reason, cff.serviceClass, cff.toa,
1115 (char*)cff.number, cff.timeSeconds);
1116 closeRequest;
1117 printRequest(pRI->token, pRI->pCI->requestNumber);
1118
Howard Sue32dbfd2015-01-07 15:55:57 +08001119 CALL_ONREQUEST(pRI->pCI->requestNumber, &cff, sizeof(cff), pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001120
1121#ifdef MEMSET_FREED
1122 memsetString(cff.number);
1123#endif
1124
1125 free (cff.number);
1126
1127#ifdef MEMSET_FREED
1128 memset(&cff, 0, sizeof(cff));
1129#endif
1130
1131 return;
1132invalid:
1133 invalidCommandBlock(pRI);
1134 return;
1135}
1136
1137
1138static void
1139dispatchRaw(Parcel &p, RequestInfo *pRI) {
1140 int32_t len;
1141 status_t status;
1142 const void *data;
1143
1144 status = p.readInt32(&len);
1145
1146 if (status != NO_ERROR) {
1147 goto invalid;
1148 }
1149
1150 // The java code writes -1 for null arrays
1151 if (((int)len) == -1) {
1152 data = NULL;
1153 len = 0;
1154 }
1155
1156 data = p.readInplace(len);
1157
1158 startRequest;
1159 appendPrintBuf("%sraw_size=%d", printBuf, len);
1160 closeRequest;
1161 printRequest(pRI->token, pRI->pCI->requestNumber);
1162
Howard Sue32dbfd2015-01-07 15:55:57 +08001163 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<void *>(data), len, pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001164
1165 return;
1166invalid:
1167 invalidCommandBlock(pRI);
1168 return;
1169}
1170
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001171static status_t
1172constructCdmaSms(Parcel &p, RequestInfo *pRI, RIL_CDMA_SMS_Message& rcsm) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001173 int32_t t;
1174 uint8_t ut;
1175 status_t status;
1176 int32_t digitCount;
1177 int digitLimit;
1178
1179 memset(&rcsm, 0, sizeof(rcsm));
1180
1181 status = p.readInt32(&t);
1182 rcsm.uTeleserviceID = (int) t;
1183
1184 status = p.read(&ut,sizeof(ut));
1185 rcsm.bIsServicePresent = (uint8_t) ut;
1186
1187 status = p.readInt32(&t);
1188 rcsm.uServicecategory = (int) t;
1189
1190 status = p.readInt32(&t);
1191 rcsm.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1192
1193 status = p.readInt32(&t);
1194 rcsm.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1195
1196 status = p.readInt32(&t);
1197 rcsm.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1198
1199 status = p.readInt32(&t);
1200 rcsm.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1201
1202 status = p.read(&ut,sizeof(ut));
1203 rcsm.sAddress.number_of_digits= (uint8_t) ut;
1204
1205 digitLimit= MIN((rcsm.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
1206 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1207 status = p.read(&ut,sizeof(ut));
1208 rcsm.sAddress.digits[digitCount] = (uint8_t) ut;
1209 }
1210
1211 status = p.readInt32(&t);
1212 rcsm.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1213
1214 status = p.read(&ut,sizeof(ut));
1215 rcsm.sSubAddress.odd = (uint8_t) ut;
1216
1217 status = p.read(&ut,sizeof(ut));
1218 rcsm.sSubAddress.number_of_digits = (uint8_t) ut;
1219
1220 digitLimit= MIN((rcsm.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
1221 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1222 status = p.read(&ut,sizeof(ut));
1223 rcsm.sSubAddress.digits[digitCount] = (uint8_t) ut;
1224 }
1225
1226 status = p.readInt32(&t);
1227 rcsm.uBearerDataLen = (int) t;
1228
1229 digitLimit= MIN((rcsm.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
1230 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1231 status = p.read(&ut, sizeof(ut));
1232 rcsm.aBearerData[digitCount] = (uint8_t) ut;
1233 }
1234
1235 if (status != NO_ERROR) {
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001236 return status;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001237 }
1238
1239 startRequest;
1240 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
1241 sAddress.digit_mode=%d, sAddress.Number_mode=%d, sAddress.number_type=%d, ",
1242 printBuf, rcsm.uTeleserviceID,rcsm.bIsServicePresent,rcsm.uServicecategory,
1243 rcsm.sAddress.digit_mode, rcsm.sAddress.number_mode,rcsm.sAddress.number_type);
1244 closeRequest;
1245
1246 printRequest(pRI->token, pRI->pCI->requestNumber);
1247
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001248 return status;
1249}
1250
1251static void
1252dispatchCdmaSms(Parcel &p, RequestInfo *pRI) {
1253 RIL_CDMA_SMS_Message rcsm;
1254
Mark Salyzyn961fd022015-04-09 07:18:35 -07001255 RLOGD("dispatchCdmaSms");
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001256 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1257 goto invalid;
1258 }
1259
Howard Sue32dbfd2015-01-07 15:55:57 +08001260 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm),pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001261
1262#ifdef MEMSET_FREED
1263 memset(&rcsm, 0, sizeof(rcsm));
1264#endif
1265
1266 return;
1267
1268invalid:
1269 invalidCommandBlock(pRI);
1270 return;
1271}
1272
1273static void
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001274dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1275 RIL_IMS_SMS_Message rism;
1276 RIL_CDMA_SMS_Message rcsm;
1277
Mark Salyzyn961fd022015-04-09 07:18:35 -07001278 RLOGD("dispatchImsCdmaSms: retry=%d, messageRef=%d", retry, messageRef);
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001279
1280 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1281 goto invalid;
1282 }
1283 memset(&rism, 0, sizeof(rism));
1284 rism.tech = RADIO_TECH_3GPP2;
1285 rism.retry = retry;
1286 rism.messageRef = messageRef;
1287 rism.message.cdmaMessage = &rcsm;
1288
Howard Sue32dbfd2015-01-07 15:55:57 +08001289 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001290 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Howard Sue32dbfd2015-01-07 15:55:57 +08001291 +sizeof(rcsm),pRI, pRI->socket_id);
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001292
1293#ifdef MEMSET_FREED
1294 memset(&rcsm, 0, sizeof(rcsm));
1295 memset(&rism, 0, sizeof(rism));
1296#endif
1297
1298 return;
1299
1300invalid:
1301 invalidCommandBlock(pRI);
1302 return;
1303}
1304
1305static void
1306dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1307 RIL_IMS_SMS_Message rism;
1308 int32_t countStrings;
1309 status_t status;
1310 size_t datalen;
1311 char **pStrings;
Mark Salyzyn961fd022015-04-09 07:18:35 -07001312 RLOGD("dispatchImsGsmSms: retry=%d, messageRef=%d", retry, messageRef);
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001313
1314 status = p.readInt32 (&countStrings);
1315
1316 if (status != NO_ERROR) {
1317 goto invalid;
1318 }
1319
1320 memset(&rism, 0, sizeof(rism));
1321 rism.tech = RADIO_TECH_3GPP;
1322 rism.retry = retry;
1323 rism.messageRef = messageRef;
1324
1325 startRequest;
Howard Sue32dbfd2015-01-07 15:55:57 +08001326 appendPrintBuf("%stech=%d, retry=%d, messageRef=%d, ", printBuf,
1327 (int)rism.tech, (int)rism.retry, rism.messageRef);
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001328 if (countStrings == 0) {
1329 // just some non-null pointer
1330 pStrings = (char **)alloca(sizeof(char *));
1331 datalen = 0;
1332 } else if (((int)countStrings) == -1) {
1333 pStrings = NULL;
1334 datalen = 0;
1335 } else {
1336 datalen = sizeof(char *) * countStrings;
1337
1338 pStrings = (char **)alloca(datalen);
1339
1340 for (int i = 0 ; i < countStrings ; i++) {
1341 pStrings[i] = strdupReadString(p);
1342 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
1343 }
1344 }
1345 removeLastChar;
1346 closeRequest;
1347 printRequest(pRI->token, pRI->pCI->requestNumber);
1348
1349 rism.message.gsmMessage = pStrings;
Howard Sue32dbfd2015-01-07 15:55:57 +08001350 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001351 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Howard Sue32dbfd2015-01-07 15:55:57 +08001352 +datalen, pRI, pRI->socket_id);
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001353
1354 if (pStrings != NULL) {
1355 for (int i = 0 ; i < countStrings ; i++) {
1356#ifdef MEMSET_FREED
1357 memsetString (pStrings[i]);
1358#endif
1359 free(pStrings[i]);
1360 }
1361
1362#ifdef MEMSET_FREED
1363 memset(pStrings, 0, datalen);
1364#endif
1365 }
1366
1367#ifdef MEMSET_FREED
1368 memset(&rism, 0, sizeof(rism));
1369#endif
1370 return;
1371invalid:
1372 ALOGE("dispatchImsGsmSms invalid block");
1373 invalidCommandBlock(pRI);
1374 return;
1375}
1376
1377static void
1378dispatchImsSms(Parcel &p, RequestInfo *pRI) {
1379 int32_t t;
1380 status_t status = p.readInt32(&t);
1381 RIL_RadioTechnologyFamily format;
1382 uint8_t retry;
1383 int32_t messageRef;
1384
Mark Salyzyn961fd022015-04-09 07:18:35 -07001385 RLOGD("dispatchImsSms");
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001386 if (status != NO_ERROR) {
1387 goto invalid;
1388 }
1389 format = (RIL_RadioTechnologyFamily) t;
1390
1391 // read retry field
1392 status = p.read(&retry,sizeof(retry));
1393 if (status != NO_ERROR) {
1394 goto invalid;
1395 }
1396 // read messageRef field
1397 status = p.read(&messageRef,sizeof(messageRef));
1398 if (status != NO_ERROR) {
1399 goto invalid;
1400 }
1401
1402 if (RADIO_TECH_3GPP == format) {
1403 dispatchImsGsmSms(p, pRI, retry, messageRef);
1404 } else if (RADIO_TECH_3GPP2 == format) {
1405 dispatchImsCdmaSms(p, pRI, retry, messageRef);
1406 } else {
1407 ALOGE("requestImsSendSMS invalid format value =%d", format);
1408 }
1409
1410 return;
1411
1412invalid:
1413 invalidCommandBlock(pRI);
1414 return;
1415}
1416
1417static void
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001418dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI) {
1419 RIL_CDMA_SMS_Ack rcsa;
1420 int32_t t;
1421 status_t status;
1422 int32_t digitCount;
1423
Mark Salyzyn961fd022015-04-09 07:18:35 -07001424 RLOGD("dispatchCdmaSmsAck");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001425 memset(&rcsa, 0, sizeof(rcsa));
1426
1427 status = p.readInt32(&t);
1428 rcsa.uErrorClass = (RIL_CDMA_SMS_ErrorClass) t;
1429
1430 status = p.readInt32(&t);
1431 rcsa.uSMSCauseCode = (int) t;
1432
1433 if (status != NO_ERROR) {
1434 goto invalid;
1435 }
1436
1437 startRequest;
1438 appendPrintBuf("%suErrorClass=%d, uTLStatus=%d, ",
1439 printBuf, rcsa.uErrorClass, rcsa.uSMSCauseCode);
1440 closeRequest;
1441
1442 printRequest(pRI->token, pRI->pCI->requestNumber);
1443
Howard Sue32dbfd2015-01-07 15:55:57 +08001444 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsa, sizeof(rcsa),pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001445
1446#ifdef MEMSET_FREED
1447 memset(&rcsa, 0, sizeof(rcsa));
1448#endif
1449
1450 return;
1451
1452invalid:
1453 invalidCommandBlock(pRI);
1454 return;
1455}
1456
1457static void
1458dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1459 int32_t t;
1460 status_t status;
1461 int32_t num;
1462
1463 status = p.readInt32(&num);
1464 if (status != NO_ERROR) {
1465 goto invalid;
1466 }
1467
Ethan Chend6e30652013-08-04 22:49:56 -07001468 {
1469 RIL_GSM_BroadcastSmsConfigInfo gsmBci[num];
1470 RIL_GSM_BroadcastSmsConfigInfo *gsmBciPtrs[num];
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001471
Ethan Chend6e30652013-08-04 22:49:56 -07001472 startRequest;
1473 for (int i = 0 ; i < num ; i++ ) {
1474 gsmBciPtrs[i] = &gsmBci[i];
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001475
Ethan Chend6e30652013-08-04 22:49:56 -07001476 status = p.readInt32(&t);
1477 gsmBci[i].fromServiceId = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001478
Ethan Chend6e30652013-08-04 22:49:56 -07001479 status = p.readInt32(&t);
1480 gsmBci[i].toServiceId = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001481
Ethan Chend6e30652013-08-04 22:49:56 -07001482 status = p.readInt32(&t);
1483 gsmBci[i].fromCodeScheme = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001484
Ethan Chend6e30652013-08-04 22:49:56 -07001485 status = p.readInt32(&t);
1486 gsmBci[i].toCodeScheme = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001487
Ethan Chend6e30652013-08-04 22:49:56 -07001488 status = p.readInt32(&t);
1489 gsmBci[i].selected = (uint8_t) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001490
Ethan Chend6e30652013-08-04 22:49:56 -07001491 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId =%d, \
1492 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]", printBuf, i,
1493 gsmBci[i].fromServiceId, gsmBci[i].toServiceId,
1494 gsmBci[i].fromCodeScheme, gsmBci[i].toCodeScheme,
1495 gsmBci[i].selected);
1496 }
1497 closeRequest;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001498
Ethan Chend6e30652013-08-04 22:49:56 -07001499 if (status != NO_ERROR) {
1500 goto invalid;
1501 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001502
Howard Sue32dbfd2015-01-07 15:55:57 +08001503 CALL_ONREQUEST(pRI->pCI->requestNumber,
Ethan Chend6e30652013-08-04 22:49:56 -07001504 gsmBciPtrs,
1505 num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *),
Howard Sue32dbfd2015-01-07 15:55:57 +08001506 pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001507
1508#ifdef MEMSET_FREED
Ethan Chend6e30652013-08-04 22:49:56 -07001509 memset(gsmBci, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo));
1510 memset(gsmBciPtrs, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001511#endif
Ethan Chend6e30652013-08-04 22:49:56 -07001512 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001513
1514 return;
1515
1516invalid:
1517 invalidCommandBlock(pRI);
1518 return;
1519}
1520
1521static void
1522dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1523 int32_t t;
1524 status_t status;
1525 int32_t num;
1526
1527 status = p.readInt32(&num);
1528 if (status != NO_ERROR) {
1529 goto invalid;
1530 }
1531
Ethan Chend6e30652013-08-04 22:49:56 -07001532 {
1533 RIL_CDMA_BroadcastSmsConfigInfo cdmaBci[num];
1534 RIL_CDMA_BroadcastSmsConfigInfo *cdmaBciPtrs[num];
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001535
Ethan Chend6e30652013-08-04 22:49:56 -07001536 startRequest;
1537 for (int i = 0 ; i < num ; i++ ) {
1538 cdmaBciPtrs[i] = &cdmaBci[i];
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001539
Ethan Chend6e30652013-08-04 22:49:56 -07001540 status = p.readInt32(&t);
1541 cdmaBci[i].service_category = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001542
Ethan Chend6e30652013-08-04 22:49:56 -07001543 status = p.readInt32(&t);
1544 cdmaBci[i].language = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001545
Ethan Chend6e30652013-08-04 22:49:56 -07001546 status = p.readInt32(&t);
1547 cdmaBci[i].selected = (uint8_t) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001548
Ethan Chend6e30652013-08-04 22:49:56 -07001549 appendPrintBuf("%s [%d: service_category=%d, language =%d, \
1550 entries.bSelected =%d]", printBuf, i, cdmaBci[i].service_category,
1551 cdmaBci[i].language, cdmaBci[i].selected);
1552 }
1553 closeRequest;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001554
Ethan Chend6e30652013-08-04 22:49:56 -07001555 if (status != NO_ERROR) {
1556 goto invalid;
1557 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001558
Howard Sue32dbfd2015-01-07 15:55:57 +08001559 CALL_ONREQUEST(pRI->pCI->requestNumber,
Ethan Chend6e30652013-08-04 22:49:56 -07001560 cdmaBciPtrs,
1561 num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *),
Howard Sue32dbfd2015-01-07 15:55:57 +08001562 pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001563
1564#ifdef MEMSET_FREED
Ethan Chend6e30652013-08-04 22:49:56 -07001565 memset(cdmaBci, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo));
1566 memset(cdmaBciPtrs, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001567#endif
Ethan Chend6e30652013-08-04 22:49:56 -07001568 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001569
1570 return;
1571
1572invalid:
1573 invalidCommandBlock(pRI);
1574 return;
1575}
1576
1577static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI) {
1578 RIL_CDMA_SMS_WriteArgs rcsw;
1579 int32_t t;
1580 uint32_t ut;
1581 uint8_t uct;
1582 status_t status;
1583 int32_t digitCount;
1584
1585 memset(&rcsw, 0, sizeof(rcsw));
1586
1587 status = p.readInt32(&t);
1588 rcsw.status = t;
1589
1590 status = p.readInt32(&t);
1591 rcsw.message.uTeleserviceID = (int) t;
1592
1593 status = p.read(&uct,sizeof(uct));
1594 rcsw.message.bIsServicePresent = (uint8_t) uct;
1595
1596 status = p.readInt32(&t);
1597 rcsw.message.uServicecategory = (int) t;
1598
1599 status = p.readInt32(&t);
1600 rcsw.message.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1601
1602 status = p.readInt32(&t);
1603 rcsw.message.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1604
1605 status = p.readInt32(&t);
1606 rcsw.message.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1607
1608 status = p.readInt32(&t);
1609 rcsw.message.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1610
1611 status = p.read(&uct,sizeof(uct));
1612 rcsw.message.sAddress.number_of_digits = (uint8_t) uct;
1613
1614 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_ADDRESS_MAX; digitCount ++) {
1615 status = p.read(&uct,sizeof(uct));
1616 rcsw.message.sAddress.digits[digitCount] = (uint8_t) uct;
1617 }
1618
1619 status = p.readInt32(&t);
1620 rcsw.message.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1621
1622 status = p.read(&uct,sizeof(uct));
1623 rcsw.message.sSubAddress.odd = (uint8_t) uct;
1624
1625 status = p.read(&uct,sizeof(uct));
1626 rcsw.message.sSubAddress.number_of_digits = (uint8_t) uct;
1627
1628 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_SUBADDRESS_MAX; digitCount ++) {
1629 status = p.read(&uct,sizeof(uct));
1630 rcsw.message.sSubAddress.digits[digitCount] = (uint8_t) uct;
1631 }
1632
1633 status = p.readInt32(&t);
1634 rcsw.message.uBearerDataLen = (int) t;
1635
1636 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_BEARER_DATA_MAX; digitCount ++) {
1637 status = p.read(&uct, sizeof(uct));
1638 rcsw.message.aBearerData[digitCount] = (uint8_t) uct;
1639 }
1640
1641 if (status != NO_ERROR) {
1642 goto invalid;
1643 }
1644
1645 startRequest;
1646 appendPrintBuf("%sstatus=%d, message.uTeleserviceID=%d, message.bIsServicePresent=%d, \
1647 message.uServicecategory=%d, message.sAddress.digit_mode=%d, \
1648 message.sAddress.number_mode=%d, \
1649 message.sAddress.number_type=%d, ",
1650 printBuf, rcsw.status, rcsw.message.uTeleserviceID, rcsw.message.bIsServicePresent,
1651 rcsw.message.uServicecategory, rcsw.message.sAddress.digit_mode,
1652 rcsw.message.sAddress.number_mode,
1653 rcsw.message.sAddress.number_type);
1654 closeRequest;
1655
1656 printRequest(pRI->token, pRI->pCI->requestNumber);
1657
Howard Sue32dbfd2015-01-07 15:55:57 +08001658 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsw, sizeof(rcsw),pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001659
1660#ifdef MEMSET_FREED
1661 memset(&rcsw, 0, sizeof(rcsw));
1662#endif
1663
1664 return;
1665
1666invalid:
1667 invalidCommandBlock(pRI);
1668 return;
1669
1670}
1671
Ethan Chend6e30652013-08-04 22:49:56 -07001672// For backwards compatibility in RIL_REQUEST_SETUP_DATA_CALL.
1673// Version 4 of the RIL interface adds a new PDP type parameter to support
1674// IPv6 and dual-stack PDP contexts. When dealing with a previous version of
1675// RIL, remove the parameter from the request.
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001676static void dispatchDataCall(Parcel& p, RequestInfo *pRI) {
Ethan Chend6e30652013-08-04 22:49:56 -07001677 // In RIL v3, REQUEST_SETUP_DATA_CALL takes 6 parameters.
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001678 const int numParamsRilV3 = 6;
1679
Ethan Chend6e30652013-08-04 22:49:56 -07001680 // The first bytes of the RIL parcel contain the request number and the
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001681 // serial number - see processCommandBuffer(). Copy them over too.
1682 int pos = p.dataPosition();
1683
1684 int numParams = p.readInt32();
1685 if (s_callbacks.version < 4 && numParams > numParamsRilV3) {
1686 Parcel p2;
1687 p2.appendFrom(&p, 0, pos);
1688 p2.writeInt32(numParamsRilV3);
1689 for(int i = 0; i < numParamsRilV3; i++) {
1690 p2.writeString16(p.readString16());
1691 }
1692 p2.setDataPosition(pos);
1693 dispatchStrings(p2, pRI);
1694 } else {
1695 p.setDataPosition(pos);
1696 dispatchStrings(p, pRI);
1697 }
1698}
1699
1700// For backwards compatibility with RILs that dont support RIL_REQUEST_VOICE_RADIO_TECH.
Ethan Chend6e30652013-08-04 22:49:56 -07001701// When all RILs handle this request, this function can be removed and
1702// the request can be sent directly to the RIL using dispatchVoid.
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001703static void dispatchVoiceRadioTech(Parcel& p, RequestInfo *pRI) {
Howard Sue32dbfd2015-01-07 15:55:57 +08001704 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001705
1706 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1707 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1708 }
1709
Ethan Chend6e30652013-08-04 22:49:56 -07001710 // RILs that support RADIO_STATE_ON should support this request.
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001711 if (RADIO_STATE_ON == state) {
1712 dispatchVoid(p, pRI);
1713 return;
1714 }
1715
Ethan Chend6e30652013-08-04 22:49:56 -07001716 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1717 // will not support this new request either and decode Voice Radio Technology
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001718 // from Radio State
1719 voiceRadioTech = decodeVoiceRadioTechnology(state);
1720
1721 if (voiceRadioTech < 0)
1722 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1723 else
1724 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &voiceRadioTech, sizeof(int));
1725}
1726
Ethan Chend6e30652013-08-04 22:49:56 -07001727// For backwards compatibility in RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE:.
1728// When all RILs handle this request, this function can be removed and
1729// the request can be sent directly to the RIL using dispatchVoid.
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001730static void dispatchCdmaSubscriptionSource(Parcel& p, RequestInfo *pRI) {
Howard Sue32dbfd2015-01-07 15:55:57 +08001731 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001732
1733 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1734 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1735 }
1736
1737 // RILs that support RADIO_STATE_ON should support this request.
1738 if (RADIO_STATE_ON == state) {
1739 dispatchVoid(p, pRI);
1740 return;
1741 }
1742
Ethan Chend6e30652013-08-04 22:49:56 -07001743 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001744 // will not support this new request either and decode CDMA Subscription Source
Ethan Chend6e30652013-08-04 22:49:56 -07001745 // from Radio State
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001746 cdmaSubscriptionSource = decodeCdmaSubscriptionSource(state);
1747
1748 if (cdmaSubscriptionSource < 0)
1749 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1750 else
1751 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &cdmaSubscriptionSource, sizeof(int));
1752}
1753
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001754static void dispatchSetInitialAttachApn(Parcel &p, RequestInfo *pRI)
1755{
1756 RIL_InitialAttachApn pf;
1757 int32_t t;
1758 status_t status;
1759
1760 memset(&pf, 0, sizeof(pf));
1761
1762 pf.apn = strdupReadString(p);
1763 pf.protocol = strdupReadString(p);
1764
1765 status = p.readInt32(&t);
1766 pf.authtype = (int) t;
1767
1768 pf.username = strdupReadString(p);
1769 pf.password = strdupReadString(p);
1770
1771 startRequest;
1772 appendPrintBuf("%sapn=%s, protocol=%s, auth_type=%d, username=%s, password=%s",
Andreas Schneidera8d09502015-06-23 18:41:38 +02001773 printBuf, pf.apn, pf.protocol, pf.authtype, pf.username, pf.password);
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001774 closeRequest;
1775 printRequest(pRI->token, pRI->pCI->requestNumber);
1776
1777 if (status != NO_ERROR) {
1778 goto invalid;
1779 }
Howard Sue32dbfd2015-01-07 15:55:57 +08001780 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001781
1782#ifdef MEMSET_FREED
1783 memsetString(pf.apn);
1784 memsetString(pf.protocol);
1785 memsetString(pf.username);
1786 memsetString(pf.password);
1787#endif
1788
1789 free(pf.apn);
1790 free(pf.protocol);
1791 free(pf.username);
1792 free(pf.password);
1793
1794#ifdef MEMSET_FREED
1795 memset(&pf, 0, sizeof(pf));
1796#endif
1797
1798 return;
1799invalid:
1800 invalidCommandBlock(pRI);
1801 return;
1802}
1803
Howard Sue32dbfd2015-01-07 15:55:57 +08001804static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI) {
1805 RIL_NV_ReadItem nvri;
1806 int32_t t;
1807 status_t status;
1808
1809 memset(&nvri, 0, sizeof(nvri));
1810
1811 status = p.readInt32(&t);
1812 nvri.itemID = (RIL_NV_Item) t;
1813
1814 if (status != NO_ERROR) {
1815 goto invalid;
1816 }
1817
1818 startRequest;
1819 appendPrintBuf("%snvri.itemID=%d, ", printBuf, nvri.itemID);
1820 closeRequest;
1821
1822 printRequest(pRI->token, pRI->pCI->requestNumber);
1823
1824 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvri, sizeof(nvri), pRI, pRI->socket_id);
1825
1826#ifdef MEMSET_FREED
1827 memset(&nvri, 0, sizeof(nvri));
1828#endif
1829
1830 return;
1831
1832invalid:
1833 invalidCommandBlock(pRI);
1834 return;
1835}
1836
1837static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI) {
1838 RIL_NV_WriteItem nvwi;
1839 int32_t t;
1840 status_t status;
1841
1842 memset(&nvwi, 0, sizeof(nvwi));
1843
1844 status = p.readInt32(&t);
1845 nvwi.itemID = (RIL_NV_Item) t;
1846
1847 nvwi.value = strdupReadString(p);
1848
1849 if (status != NO_ERROR || nvwi.value == NULL) {
1850 goto invalid;
1851 }
1852
1853 startRequest;
1854 appendPrintBuf("%snvwi.itemID=%d, value=%s, ", printBuf, nvwi.itemID,
1855 nvwi.value);
1856 closeRequest;
1857
1858 printRequest(pRI->token, pRI->pCI->requestNumber);
1859
1860 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvwi, sizeof(nvwi), pRI, pRI->socket_id);
1861
1862#ifdef MEMSET_FREED
1863 memsetString(nvwi.value);
1864#endif
1865
1866 free(nvwi.value);
1867
1868#ifdef MEMSET_FREED
1869 memset(&nvwi, 0, sizeof(nvwi));
1870#endif
1871
1872 return;
1873
1874invalid:
1875 invalidCommandBlock(pRI);
1876 return;
1877}
1878
1879
1880static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI) {
1881 RIL_SelectUiccSub uicc_sub;
1882 status_t status;
1883 int32_t t;
1884 memset(&uicc_sub, 0, sizeof(uicc_sub));
1885
1886 status = p.readInt32(&t);
1887 if (status != NO_ERROR) {
1888 goto invalid;
1889 }
1890 uicc_sub.slot = (int) t;
1891
1892 status = p.readInt32(&t);
1893 if (status != NO_ERROR) {
1894 goto invalid;
1895 }
1896 uicc_sub.app_index = (int) t;
1897
1898 status = p.readInt32(&t);
1899 if (status != NO_ERROR) {
1900 goto invalid;
1901 }
1902 uicc_sub.sub_type = (RIL_SubscriptionType) t;
1903
1904 status = p.readInt32(&t);
1905 if (status != NO_ERROR) {
1906 goto invalid;
1907 }
1908 uicc_sub.act_status = (RIL_UiccSubActStatus) t;
1909
1910 startRequest;
1911 appendPrintBuf("slot=%d, app_index=%d, act_status = %d", uicc_sub.slot, uicc_sub.app_index,
1912 uicc_sub.act_status);
1913 RLOGD("dispatchUiccSubscription, slot=%d, app_index=%d, act_status = %d", uicc_sub.slot,
1914 uicc_sub.app_index, uicc_sub.act_status);
1915 closeRequest;
1916 printRequest(pRI->token, pRI->pCI->requestNumber);
1917
1918 CALL_ONREQUEST(pRI->pCI->requestNumber, &uicc_sub, sizeof(uicc_sub), pRI, pRI->socket_id);
1919
1920#ifdef MEMSET_FREED
1921 memset(&uicc_sub, 0, sizeof(uicc_sub));
1922#endif
1923 return;
1924
1925invalid:
1926 invalidCommandBlock(pRI);
1927 return;
1928}
1929
1930static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI)
1931{
1932 RIL_SimAuthentication pf;
1933 int32_t t;
1934 status_t status;
1935
1936 memset(&pf, 0, sizeof(pf));
1937
1938 status = p.readInt32(&t);
1939 pf.authContext = (int) t;
1940 pf.authData = strdupReadString(p);
1941 pf.aid = strdupReadString(p);
1942
1943 startRequest;
Andreas Schneidera8d09502015-06-23 18:41:38 +02001944 appendPrintBuf("authContext=%d, authData=%s, aid=%s", pf.authContext, pf.authData, pf.aid);
Howard Sue32dbfd2015-01-07 15:55:57 +08001945 closeRequest;
1946 printRequest(pRI->token, pRI->pCI->requestNumber);
1947
1948 if (status != NO_ERROR) {
1949 goto invalid;
1950 }
1951 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
1952
1953#ifdef MEMSET_FREED
1954 memsetString(pf.authData);
1955 memsetString(pf.aid);
1956#endif
1957
1958 free(pf.authData);
1959 free(pf.aid);
1960
1961#ifdef MEMSET_FREED
1962 memset(&pf, 0, sizeof(pf));
1963#endif
1964
1965 return;
1966invalid:
1967 invalidCommandBlock(pRI);
1968 return;
1969}
1970
1971static void dispatchDataProfile(Parcel &p, RequestInfo *pRI) {
1972 int32_t t;
1973 status_t status;
1974 int32_t num;
1975
1976 status = p.readInt32(&num);
1977 if (status != NO_ERROR) {
1978 goto invalid;
1979 }
1980
1981 {
1982 RIL_DataProfileInfo dataProfiles[num];
1983 RIL_DataProfileInfo *dataProfilePtrs[num];
1984
1985 startRequest;
1986 for (int i = 0 ; i < num ; i++ ) {
1987 dataProfilePtrs[i] = &dataProfiles[i];
1988
1989 status = p.readInt32(&t);
1990 dataProfiles[i].profileId = (int) t;
1991
1992 dataProfiles[i].apn = strdupReadString(p);
1993 dataProfiles[i].protocol = strdupReadString(p);
1994 status = p.readInt32(&t);
1995 dataProfiles[i].authType = (int) t;
1996
1997 dataProfiles[i].user = strdupReadString(p);
1998 dataProfiles[i].password = strdupReadString(p);
1999
2000 status = p.readInt32(&t);
2001 dataProfiles[i].type = (int) t;
2002
2003 status = p.readInt32(&t);
2004 dataProfiles[i].maxConnsTime = (int) t;
2005 status = p.readInt32(&t);
2006 dataProfiles[i].maxConns = (int) t;
2007 status = p.readInt32(&t);
2008 dataProfiles[i].waitTime = (int) t;
2009
2010 status = p.readInt32(&t);
2011 dataProfiles[i].enabled = (int) t;
2012
2013 appendPrintBuf("%s [%d: profileId=%d, apn =%s, protocol =%s, authType =%d, \
2014 user =%s, password =%s, type =%d, maxConnsTime =%d, maxConns =%d, \
2015 waitTime =%d, enabled =%d]", printBuf, i, dataProfiles[i].profileId,
2016 dataProfiles[i].apn, dataProfiles[i].protocol, dataProfiles[i].authType,
2017 dataProfiles[i].user, dataProfiles[i].password, dataProfiles[i].type,
2018 dataProfiles[i].maxConnsTime, dataProfiles[i].maxConns,
2019 dataProfiles[i].waitTime, dataProfiles[i].enabled);
2020 }
2021 closeRequest;
2022 printRequest(pRI->token, pRI->pCI->requestNumber);
2023
2024 if (status != NO_ERROR) {
2025 goto invalid;
2026 }
2027 CALL_ONREQUEST(pRI->pCI->requestNumber,
2028 dataProfilePtrs,
2029 num * sizeof(RIL_DataProfileInfo *),
2030 pRI, pRI->socket_id);
2031
2032#ifdef MEMSET_FREED
2033 memset(dataProfiles, 0, num * sizeof(RIL_DataProfileInfo));
2034 memset(dataProfilePtrs, 0, num * sizeof(RIL_DataProfileInfo *));
2035#endif
2036 }
2037
2038 return;
2039
2040invalid:
2041 invalidCommandBlock(pRI);
2042 return;
2043}
2044
Howard Subd82ef12015-04-12 10:25:05 +02002045static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI){
2046 RIL_RadioCapability rc;
2047 int32_t t;
2048 status_t status;
2049
2050 memset (&rc, 0, sizeof(RIL_RadioCapability));
2051
2052 status = p.readInt32(&t);
2053 rc.version = (int)t;
2054 if (status != NO_ERROR) {
2055 goto invalid;
2056 }
2057
2058 status = p.readInt32(&t);
2059 rc.session= (int)t;
2060 if (status != NO_ERROR) {
2061 goto invalid;
2062 }
2063
2064 status = p.readInt32(&t);
2065 rc.phase= (int)t;
2066 if (status != NO_ERROR) {
2067 goto invalid;
2068 }
2069
2070 status = p.readInt32(&t);
2071 rc.rat = (int)t;
2072 if (status != NO_ERROR) {
2073 goto invalid;
2074 }
2075
2076 status = readStringFromParcelInplace(p, rc.logicalModemUuid, sizeof(rc.logicalModemUuid));
2077 if (status != NO_ERROR) {
2078 goto invalid;
2079 }
2080
2081 status = p.readInt32(&t);
2082 rc.status = (int)t;
2083
2084 if (status != NO_ERROR) {
2085 goto invalid;
2086 }
2087
2088 startRequest;
2089 appendPrintBuf("%s [version:%d, session:%d, phase:%d, rat:%d, \
Andreas Schneidera8d09502015-06-23 18:41:38 +02002090 logicalModemUuid:%s, status:%d", printBuf, rc.version, rc.session,
2091 rc.phase, rc.rat, rc.logicalModemUuid, rc.status);
Howard Subd82ef12015-04-12 10:25:05 +02002092
2093 closeRequest;
2094 printRequest(pRI->token, pRI->pCI->requestNumber);
2095
2096 CALL_ONREQUEST(pRI->pCI->requestNumber,
2097 &rc,
2098 sizeof(RIL_RadioCapability),
2099 pRI, pRI->socket_id);
2100 return;
2101invalid:
2102 invalidCommandBlock(pRI);
2103 return;
2104}
2105
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002106static int
2107blockingWrite(int fd, const void *buffer, size_t len) {
2108 size_t writeOffset = 0;
2109 const uint8_t *toWrite;
2110
2111 toWrite = (const uint8_t *)buffer;
2112
2113 while (writeOffset < len) {
2114 ssize_t written;
2115 do {
2116 written = write (fd, toWrite + writeOffset,
2117 len - writeOffset);
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002118 } while (written < 0 && ((errno == EINTR) || (errno == EAGAIN)));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002119
2120 if (written >= 0) {
2121 writeOffset += written;
2122 } else { // written < 0
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002123 RLOGE ("RIL Response: unexpected error on write errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002124 close(fd);
2125 return -1;
2126 }
2127 }
Robert Greenwaltbc29c432015-04-29 16:57:39 -07002128#if VDBG
Dheeraj Shettycc231012014-07-02 21:27:57 +02002129 RLOGE("RIL Response bytes written:%d", writeOffset);
Robert Greenwaltbc29c432015-04-29 16:57:39 -07002130#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002131 return 0;
2132}
2133
2134static int
Howard Sue32dbfd2015-01-07 15:55:57 +08002135sendResponseRaw (const void *data, size_t dataSize, RIL_SOCKET_ID socket_id) {
2136 int fd = s_ril_param_socket.fdCommand;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002137 int ret;
2138 uint32_t header;
Howard Sue32dbfd2015-01-07 15:55:57 +08002139 pthread_mutex_t * writeMutexHook = &s_writeMutex;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002140
Robert Greenwaltbc29c432015-04-29 16:57:39 -07002141#if VDBG
Andreas Schneider822b70b2015-10-23 08:36:26 +02002142 RLOGD("Send Response to %s", rilSocketIdToString(socket_id));
Robert Greenwaltbc29c432015-04-29 16:57:39 -07002143#endif
Howard Sue32dbfd2015-01-07 15:55:57 +08002144
2145#if (SIM_COUNT >= 2)
2146 if (socket_id == RIL_SOCKET_2) {
2147 fd = s_ril_param_socket2.fdCommand;
2148 writeMutexHook = &s_writeMutex_socket2;
2149 }
2150#if (SIM_COUNT >= 3)
2151 else if (socket_id == RIL_SOCKET_3) {
2152 fd = s_ril_param_socket3.fdCommand;
2153 writeMutexHook = &s_writeMutex_socket3;
2154 }
2155#endif
2156#if (SIM_COUNT >= 4)
2157 else if (socket_id == RIL_SOCKET_4) {
2158 fd = s_ril_param_socket4.fdCommand;
2159 writeMutexHook = &s_writeMutex_socket4;
2160 }
2161#endif
2162#endif
2163 if (fd < 0) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002164 return -1;
2165 }
2166
Howard Subd82ef12015-04-12 10:25:05 +02002167 if (dataSize > MAX_COMMAND_BYTES) {
2168 RLOGE("RIL: packet larger than %u (%u)",
2169 MAX_COMMAND_BYTES, (unsigned int )dataSize);
2170
2171 return -1;
2172 }
2173
Howard Sue32dbfd2015-01-07 15:55:57 +08002174 pthread_mutex_lock(writeMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002175
2176 header = htonl(dataSize);
2177
2178 ret = blockingWrite(fd, (void *)&header, sizeof(header));
2179
2180 if (ret < 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002181 pthread_mutex_unlock(writeMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002182 return ret;
2183 }
2184
2185 ret = blockingWrite(fd, data, dataSize);
2186
2187 if (ret < 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002188 pthread_mutex_unlock(writeMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002189 return ret;
2190 }
2191
Howard Sue32dbfd2015-01-07 15:55:57 +08002192 pthread_mutex_unlock(writeMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002193
2194 return 0;
2195}
2196
2197static int
Howard Sue32dbfd2015-01-07 15:55:57 +08002198sendResponse (Parcel &p, RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002199 printResponse;
Howard Sue32dbfd2015-01-07 15:55:57 +08002200 return sendResponseRaw(p.data(), p.dataSize(), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002201}
2202
Howard Sue32dbfd2015-01-07 15:55:57 +08002203/** response is an int* pointing to an array of ints */
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002204
2205static int
2206responseInts(Parcel &p, void *response, size_t responselen) {
2207 int numInts;
2208
2209 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002210 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002211 return RIL_ERRNO_INVALID_RESPONSE;
2212 }
2213 if (responselen % sizeof(int) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002214 RLOGE("responseInts: invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002215 (int)responselen, (int)sizeof(int));
2216 return RIL_ERRNO_INVALID_RESPONSE;
2217 }
2218
2219 int *p_int = (int *) response;
2220
Howard Sue32dbfd2015-01-07 15:55:57 +08002221 numInts = responselen / sizeof(int);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002222 p.writeInt32 (numInts);
2223
2224 /* each int*/
2225 startResponse;
2226 for (int i = 0 ; i < numInts ; i++) {
2227 appendPrintBuf("%s%d,", printBuf, p_int[i]);
2228 p.writeInt32(p_int[i]);
2229 }
2230 removeLastChar;
2231 closeResponse;
2232
2233 return 0;
2234}
2235
Daniel Hillenbrandd0b84162015-04-12 11:53:23 +02002236static int
2237responseIntsGetPreferredNetworkType(Parcel &p, void *response, size_t responselen) {
2238 int numInts;
2239
2240 if (response == NULL && responselen != 0) {
2241 RLOGE("invalid response: NULL");
2242 return RIL_ERRNO_INVALID_RESPONSE;
2243 }
2244 if (responselen % sizeof(int) != 0) {
2245 RLOGE("responseInts: invalid response length %d expected multiple of %d\n",
2246 (int)responselen, (int)sizeof(int));
2247 return RIL_ERRNO_INVALID_RESPONSE;
2248 }
2249
2250 int *p_int = (int *) response;
2251
2252 numInts = responselen / sizeof(int);
2253 p.writeInt32 (numInts);
2254
2255 /* each int*/
2256 startResponse;
2257 for (int i = 0 ; i < numInts ; i++) {
2258 if (i == 0 && p_int[0] == 7) {
2259 RLOGD("REQUEST_GET_PREFERRED_NETWORK_TYPE: NETWORK_MODE_GLOBAL => NETWORK_MODE_WCDMA_PREF");
2260 p_int[0] = 0;
2261 }
2262 appendPrintBuf("%s%d,", printBuf, p_int[i]);
2263 p.writeInt32(p_int[i]);
2264 }
2265 removeLastChar;
2266 closeResponse;
2267
2268 return 0;
2269}
2270
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002271/** response is a char **, pointing to an array of char *'s
2272 The parcel will begin with the version */
2273static int responseStringsWithVersion(int version, Parcel &p, void *response, size_t responselen) {
2274 p.writeInt32(version);
2275 return responseStrings(p, response, responselen);
2276}
2277
2278/** response is a char **, pointing to an array of char *'s */
2279static int responseStrings(Parcel &p, void *response, size_t responselen) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002280 int numStrings;
2281
2282 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002283 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002284 return RIL_ERRNO_INVALID_RESPONSE;
2285 }
2286 if (responselen % sizeof(char *) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002287 RLOGE("responseStrings: invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002288 (int)responselen, (int)sizeof(char *));
2289 return RIL_ERRNO_INVALID_RESPONSE;
2290 }
2291
2292 if (response == NULL) {
2293 p.writeInt32 (0);
2294 } else {
2295 char **p_cur = (char **) response;
2296
2297 numStrings = responselen / sizeof(char *);
Dheeraj CVR48d3f722016-10-04 11:10:55 +04002298 p.writeInt32 (numStrings);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002299
2300 /* each string*/
2301 startResponse;
2302 for (int i = 0 ; i < numStrings ; i++) {
2303 appendPrintBuf("%s%s,", printBuf, (char*)p_cur[i]);
2304 writeStringToParcel (p, p_cur[i]);
2305 }
2306 removeLastChar;
2307 closeResponse;
2308 }
2309 return 0;
2310}
2311
Howard Subd82ef12015-04-12 10:25:05 +02002312
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002313/**
2314 * NULL strings are accepted
2315 * FIXME currently ignores responselen
2316 */
2317static int responseString(Parcel &p, void *response, size_t responselen) {
2318 /* one string only */
2319 startResponse;
2320 appendPrintBuf("%s%s", printBuf, (char*)response);
2321 closeResponse;
2322
2323 writeStringToParcel(p, (const char *)response);
2324
2325 return 0;
2326}
2327
2328static int responseVoid(Parcel &p, void *response, size_t responselen) {
2329 startResponse;
2330 removeLastChar;
2331 return 0;
2332}
2333
2334static int responseCallList(Parcel &p, void *response, size_t responselen) {
2335 int num;
2336
2337 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002338 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002339 return RIL_ERRNO_INVALID_RESPONSE;
2340 }
2341
2342 if (responselen % sizeof (RIL_Call *) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002343 RLOGE("responseCallList: invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002344 (int)responselen, (int)sizeof (RIL_Call *));
2345 return RIL_ERRNO_INVALID_RESPONSE;
2346 }
2347
2348 startResponse;
2349 /* number of call info's */
2350 num = responselen / sizeof(RIL_Call *);
2351 p.writeInt32(num);
2352
2353 for (int i = 0 ; i < num ; i++) {
2354 RIL_Call *p_cur = ((RIL_Call **) response)[i];
2355 /* each call info */
2356 p.writeInt32(p_cur->state);
2357 p.writeInt32(p_cur->index);
2358 p.writeInt32(p_cur->toa);
2359 p.writeInt32(p_cur->isMpty);
2360 p.writeInt32(p_cur->isMT);
2361 p.writeInt32(p_cur->als);
2362 p.writeInt32(p_cur->isVoice);
Andreas Schneider29472682015-01-01 19:00:04 +01002363
Christopher N. Hesse621e63e2016-02-22 21:57:39 +01002364#ifdef NEEDS_VIDEO_CALL_FIELD
Andreas Schneider29472682015-01-01 19:00:04 +01002365 p.writeInt32(p_cur->isVideo);
Sayd1052772015-12-13 17:25:01 +09002366#endif
Andreas Schneider29472682015-01-01 19:00:04 +01002367
Christopher N. Hesse621e63e2016-02-22 21:57:39 +01002368#ifdef SAMSUNG_NEXT_GEN_MODEM
Andreas Schneider29472682015-01-01 19:00:04 +01002369 /* Pass CallDetails */
2370 p.writeInt32(0);
2371 p.writeInt32(0);
2372 writeStringToParcel(p, "");
2373#endif
2374
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002375 p.writeInt32(p_cur->isVoicePrivacy);
2376 writeStringToParcel(p, p_cur->number);
2377 p.writeInt32(p_cur->numberPresentation);
2378 writeStringToParcel(p, p_cur->name);
2379 p.writeInt32(p_cur->namePresentation);
2380 // Remove when partners upgrade to version 3
2381 if ((s_callbacks.version < 3) || (p_cur->uusInfo == NULL || p_cur->uusInfo->uusData == NULL)) {
2382 p.writeInt32(0); /* UUS Information is absent */
2383 } else {
2384 RIL_UUS_Info *uusInfo = p_cur->uusInfo;
2385 p.writeInt32(1); /* UUS Information is present */
2386 p.writeInt32(uusInfo->uusType);
2387 p.writeInt32(uusInfo->uusDcs);
2388 p.writeInt32(uusInfo->uusLength);
2389 p.write(uusInfo->uusData, uusInfo->uusLength);
2390 }
2391 appendPrintBuf("%s[id=%d,%s,toa=%d,",
2392 printBuf,
2393 p_cur->index,
2394 callStateToString(p_cur->state),
2395 p_cur->toa);
2396 appendPrintBuf("%s%s,%s,als=%d,%s,%s,",
2397 printBuf,
2398 (p_cur->isMpty)?"conf":"norm",
2399 (p_cur->isMT)?"mt":"mo",
2400 p_cur->als,
2401 (p_cur->isVoice)?"voc":"nonvoc",
2402 (p_cur->isVoicePrivacy)?"evp":"noevp");
Christopher N. Hesse621e63e2016-02-22 21:57:39 +01002403#ifdef SAMSUNG_NEXT_GEN_MODEM
Andreas Schneider29472682015-01-01 19:00:04 +01002404 appendPrintBuf("%s,%s,",
2405 printBuf,
2406 (p_cur->isVideo) ? "vid" : "novid");
2407#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002408 appendPrintBuf("%s%s,cli=%d,name='%s',%d]",
2409 printBuf,
2410 p_cur->number,
2411 p_cur->numberPresentation,
2412 p_cur->name,
2413 p_cur->namePresentation);
2414 }
2415 removeLastChar;
2416 closeResponse;
2417
2418 return 0;
2419}
2420
2421static int responseSMS(Parcel &p, void *response, size_t responselen) {
2422 if (response == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002423 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002424 return RIL_ERRNO_INVALID_RESPONSE;
2425 }
2426
2427 if (responselen != sizeof (RIL_SMS_Response) ) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002428 RLOGE("invalid response length %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002429 (int)responselen, (int)sizeof (RIL_SMS_Response));
2430 return RIL_ERRNO_INVALID_RESPONSE;
2431 }
2432
2433 RIL_SMS_Response *p_cur = (RIL_SMS_Response *) response;
2434
2435 p.writeInt32(p_cur->messageRef);
2436 writeStringToParcel(p, p_cur->ackPDU);
2437 p.writeInt32(p_cur->errorCode);
2438
2439 startResponse;
2440 appendPrintBuf("%s%d,%s,%d", printBuf, p_cur->messageRef,
2441 (char*)p_cur->ackPDU, p_cur->errorCode);
2442 closeResponse;
2443
2444 return 0;
2445}
2446
2447static int responseDataCallListV4(Parcel &p, void *response, size_t responselen)
2448{
2449 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002450 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002451 return RIL_ERRNO_INVALID_RESPONSE;
2452 }
2453
2454 if (responselen % sizeof(RIL_Data_Call_Response_v4) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002455 RLOGE("responseDataCallListV4: invalid response length %d expected multiple of %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002456 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v4));
2457 return RIL_ERRNO_INVALID_RESPONSE;
2458 }
2459
Howard Sue32dbfd2015-01-07 15:55:57 +08002460 // Write version
2461 p.writeInt32(4);
2462
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002463 int num = responselen / sizeof(RIL_Data_Call_Response_v4);
2464 p.writeInt32(num);
2465
2466 RIL_Data_Call_Response_v4 *p_cur = (RIL_Data_Call_Response_v4 *) response;
2467 startResponse;
2468 int i;
2469 for (i = 0; i < num; i++) {
2470 p.writeInt32(p_cur[i].cid);
2471 p.writeInt32(p_cur[i].active);
2472 writeStringToParcel(p, p_cur[i].type);
2473 // apn is not used, so don't send.
2474 writeStringToParcel(p, p_cur[i].address);
2475 appendPrintBuf("%s[cid=%d,%s,%s,%s],", printBuf,
2476 p_cur[i].cid,
2477 (p_cur[i].active==0)?"down":"up",
2478 (char*)p_cur[i].type,
2479 (char*)p_cur[i].address);
2480 }
2481 removeLastChar;
2482 closeResponse;
2483
2484 return 0;
2485}
2486
Howard Sue32dbfd2015-01-07 15:55:57 +08002487static int responseDataCallListV6(Parcel &p, void *response, size_t responselen)
2488{
2489 if (response == NULL && responselen != 0) {
2490 RLOGE("invalid response: NULL");
2491 return RIL_ERRNO_INVALID_RESPONSE;
2492 }
2493
2494 if (responselen % sizeof(RIL_Data_Call_Response_v6) != 0) {
2495 RLOGE("responseDataCallListV6: invalid response length %d expected multiple of %d",
2496 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v6));
2497 return RIL_ERRNO_INVALID_RESPONSE;
2498 }
2499
2500 // Write version
2501 p.writeInt32(6);
2502
2503 int num = responselen / sizeof(RIL_Data_Call_Response_v6);
2504 p.writeInt32(num);
2505
2506 RIL_Data_Call_Response_v6 *p_cur = (RIL_Data_Call_Response_v6 *) response;
2507 startResponse;
2508 int i;
2509 for (i = 0; i < num; i++) {
2510 p.writeInt32((int)p_cur[i].status);
2511 p.writeInt32(p_cur[i].suggestedRetryTime);
2512 p.writeInt32(p_cur[i].cid);
2513 p.writeInt32(p_cur[i].active);
2514 writeStringToParcel(p, p_cur[i].type);
2515 writeStringToParcel(p, p_cur[i].ifname);
2516 writeStringToParcel(p, p_cur[i].addresses);
2517 writeStringToParcel(p, p_cur[i].dnses);
2518 writeStringToParcel(p, p_cur[i].addresses);
2519 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s],", printBuf,
2520 p_cur[i].status,
2521 p_cur[i].suggestedRetryTime,
2522 p_cur[i].cid,
2523 (p_cur[i].active==0)?"down":"up",
2524 (char*)p_cur[i].type,
2525 (char*)p_cur[i].ifname,
2526 (char*)p_cur[i].addresses,
2527 (char*)p_cur[i].dnses,
2528 (char*)p_cur[i].addresses);
2529 }
2530 removeLastChar;
2531 closeResponse;
2532
2533 return 0;
2534}
2535
Howard Subd82ef12015-04-12 10:25:05 +02002536static int responseDataCallListV9(Parcel &p, void *response, size_t responselen)
2537{
2538 if (response == NULL && responselen != 0) {
2539 RLOGE("invalid response: NULL");
2540 return RIL_ERRNO_INVALID_RESPONSE;
2541 }
2542
2543 if (responselen % sizeof(RIL_Data_Call_Response_v9) != 0) {
2544 RLOGE("responseDataCallListV9: invalid response length %d expected multiple of %d",
2545 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v9));
2546 return RIL_ERRNO_INVALID_RESPONSE;
2547 }
2548
2549 // Write version
2550 p.writeInt32(10);
2551
2552 int num = responselen / sizeof(RIL_Data_Call_Response_v9);
2553 p.writeInt32(num);
2554
2555 RIL_Data_Call_Response_v9 *p_cur = (RIL_Data_Call_Response_v9 *) response;
2556 startResponse;
2557 int i;
2558 for (i = 0; i < num; i++) {
2559 p.writeInt32((int)p_cur[i].status);
2560 p.writeInt32(p_cur[i].suggestedRetryTime);
2561 p.writeInt32(p_cur[i].cid);
2562 p.writeInt32(p_cur[i].active);
2563 writeStringToParcel(p, p_cur[i].type);
2564 writeStringToParcel(p, p_cur[i].ifname);
2565 writeStringToParcel(p, p_cur[i].addresses);
2566 writeStringToParcel(p, p_cur[i].dnses);
2567 writeStringToParcel(p, p_cur[i].gateways);
2568 writeStringToParcel(p, p_cur[i].pcscf);
2569 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s],", printBuf,
2570 p_cur[i].status,
2571 p_cur[i].suggestedRetryTime,
2572 p_cur[i].cid,
2573 (p_cur[i].active==0)?"down":"up",
2574 (char*)p_cur[i].type,
2575 (char*)p_cur[i].ifname,
2576 (char*)p_cur[i].addresses,
2577 (char*)p_cur[i].dnses,
2578 (char*)p_cur[i].gateways,
2579 (char*)p_cur[i].pcscf);
2580 }
2581 removeLastChar;
2582 closeResponse;
2583
2584 return 0;
2585}
2586
2587
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002588static int responseDataCallList(Parcel &p, void *response, size_t responselen)
2589{
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002590 if (s_callbacks.version < 5) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002591 RLOGD("responseDataCallList: v4");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002592 return responseDataCallListV4(p, response, responselen);
Howard Subd82ef12015-04-12 10:25:05 +02002593 } else if (responselen % sizeof(RIL_Data_Call_Response_v6) == 0) {
2594 return responseDataCallListV6(p, response, responselen);
2595 } else if (responselen % sizeof(RIL_Data_Call_Response_v9) == 0) {
2596 return responseDataCallListV9(p, response, responselen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002597 } else {
2598 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002599 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002600 return RIL_ERRNO_INVALID_RESPONSE;
2601 }
2602
Howard Subd82ef12015-04-12 10:25:05 +02002603 if (responselen % sizeof(RIL_Data_Call_Response_v11) != 0) {
2604 RLOGE("invalid response length %d expected multiple of %d",
2605 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v11));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002606 return RIL_ERRNO_INVALID_RESPONSE;
2607 }
2608
Howard Sue32dbfd2015-01-07 15:55:57 +08002609 // Write version
Howard Subd82ef12015-04-12 10:25:05 +02002610 p.writeInt32(11);
Howard Sue32dbfd2015-01-07 15:55:57 +08002611
Howard Subd82ef12015-04-12 10:25:05 +02002612 int num = responselen / sizeof(RIL_Data_Call_Response_v11);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002613 p.writeInt32(num);
2614
Howard Subd82ef12015-04-12 10:25:05 +02002615 RIL_Data_Call_Response_v11 *p_cur = (RIL_Data_Call_Response_v11 *) response;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002616 startResponse;
2617 int i;
2618 for (i = 0; i < num; i++) {
2619 p.writeInt32((int)p_cur[i].status);
2620 p.writeInt32(p_cur[i].suggestedRetryTime);
2621 p.writeInt32(p_cur[i].cid);
2622 p.writeInt32(p_cur[i].active);
2623 writeStringToParcel(p, p_cur[i].type);
2624 writeStringToParcel(p, p_cur[i].ifname);
2625 writeStringToParcel(p, p_cur[i].addresses);
2626 writeStringToParcel(p, p_cur[i].dnses);
Howard Sue32dbfd2015-01-07 15:55:57 +08002627 writeStringToParcel(p, p_cur[i].gateways);
2628 writeStringToParcel(p, p_cur[i].pcscf);
Howard Subd82ef12015-04-12 10:25:05 +02002629 p.writeInt32(p_cur[i].mtu);
2630 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 +02002631 p_cur[i].status,
2632 p_cur[i].suggestedRetryTime,
2633 p_cur[i].cid,
2634 (p_cur[i].active==0)?"down":"up",
2635 (char*)p_cur[i].type,
2636 (char*)p_cur[i].ifname,
2637 (char*)p_cur[i].addresses,
2638 (char*)p_cur[i].dnses,
Howard Sue32dbfd2015-01-07 15:55:57 +08002639 (char*)p_cur[i].gateways,
Howard Subd82ef12015-04-12 10:25:05 +02002640 (char*)p_cur[i].pcscf,
2641 p_cur[i].mtu);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002642 }
2643 removeLastChar;
2644 closeResponse;
2645 }
2646
2647 return 0;
2648}
2649
2650static int responseSetupDataCall(Parcel &p, void *response, size_t responselen)
2651{
2652 if (s_callbacks.version < 5) {
2653 return responseStringsWithVersion(s_callbacks.version, p, response, responselen);
2654 } else {
2655 return responseDataCallList(p, response, responselen);
2656 }
2657}
2658
2659static int responseRaw(Parcel &p, void *response, size_t responselen) {
2660 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002661 RLOGE("invalid response: NULL with responselen != 0");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002662 return RIL_ERRNO_INVALID_RESPONSE;
2663 }
2664
2665 // The java code reads -1 size as null byte array
2666 if (response == NULL) {
2667 p.writeInt32(-1);
2668 } else {
2669 p.writeInt32(responselen);
2670 p.write(response, responselen);
2671 }
2672
2673 return 0;
2674}
2675
2676
2677static int responseSIM_IO(Parcel &p, void *response, size_t responselen) {
2678 if (response == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002679 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002680 return RIL_ERRNO_INVALID_RESPONSE;
2681 }
2682
2683 if (responselen != sizeof (RIL_SIM_IO_Response) ) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002684 RLOGE("invalid response length was %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002685 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
2686 return RIL_ERRNO_INVALID_RESPONSE;
2687 }
2688
2689 RIL_SIM_IO_Response *p_cur = (RIL_SIM_IO_Response *) response;
2690 p.writeInt32(p_cur->sw1);
2691 p.writeInt32(p_cur->sw2);
2692 writeStringToParcel(p, p_cur->simResponse);
2693
2694 startResponse;
2695 appendPrintBuf("%ssw1=0x%X,sw2=0x%X,%s", printBuf, p_cur->sw1, p_cur->sw2,
2696 (char*)p_cur->simResponse);
2697 closeResponse;
2698
2699
2700 return 0;
2701}
2702
2703static int responseCallForwards(Parcel &p, void *response, size_t responselen) {
2704 int num;
2705
2706 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002707 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002708 return RIL_ERRNO_INVALID_RESPONSE;
2709 }
2710
2711 if (responselen % sizeof(RIL_CallForwardInfo *) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002712 RLOGE("responseCallForwards: invalid response length %d expected multiple of %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002713 (int)responselen, (int)sizeof(RIL_CallForwardInfo *));
2714 return RIL_ERRNO_INVALID_RESPONSE;
2715 }
2716
2717 /* number of call info's */
2718 num = responselen / sizeof(RIL_CallForwardInfo *);
2719 p.writeInt32(num);
2720
2721 startResponse;
2722 for (int i = 0 ; i < num ; i++) {
2723 RIL_CallForwardInfo *p_cur = ((RIL_CallForwardInfo **) response)[i];
2724
2725 p.writeInt32(p_cur->status);
2726 p.writeInt32(p_cur->reason);
2727 p.writeInt32(p_cur->serviceClass);
2728 p.writeInt32(p_cur->toa);
2729 writeStringToParcel(p, p_cur->number);
2730 p.writeInt32(p_cur->timeSeconds);
2731 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
2732 (p_cur->status==1)?"enable":"disable",
2733 p_cur->reason, p_cur->serviceClass, p_cur->toa,
2734 (char*)p_cur->number,
2735 p_cur->timeSeconds);
2736 }
2737 removeLastChar;
2738 closeResponse;
2739
2740 return 0;
2741}
2742
2743static int responseSsn(Parcel &p, void *response, size_t responselen) {
2744 if (response == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002745 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002746 return RIL_ERRNO_INVALID_RESPONSE;
2747 }
2748
2749 if (responselen != sizeof(RIL_SuppSvcNotification)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002750 RLOGE("invalid response length was %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002751 (int)responselen, (int)sizeof (RIL_SuppSvcNotification));
2752 return RIL_ERRNO_INVALID_RESPONSE;
2753 }
2754
2755 RIL_SuppSvcNotification *p_cur = (RIL_SuppSvcNotification *) response;
2756 p.writeInt32(p_cur->notificationType);
2757 p.writeInt32(p_cur->code);
2758 p.writeInt32(p_cur->index);
2759 p.writeInt32(p_cur->type);
2760 writeStringToParcel(p, p_cur->number);
2761
2762 startResponse;
2763 appendPrintBuf("%s%s,code=%d,id=%d,type=%d,%s", printBuf,
2764 (p_cur->notificationType==0)?"mo":"mt",
2765 p_cur->code, p_cur->index, p_cur->type,
2766 (char*)p_cur->number);
2767 closeResponse;
2768
2769 return 0;
2770}
2771
2772static int responseCellList(Parcel &p, void *response, size_t responselen) {
2773 int num;
2774
2775 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002776 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002777 return RIL_ERRNO_INVALID_RESPONSE;
2778 }
2779
2780 if (responselen % sizeof (RIL_NeighboringCell *) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002781 RLOGE("responseCellList: invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002782 (int)responselen, (int)sizeof (RIL_NeighboringCell *));
2783 return RIL_ERRNO_INVALID_RESPONSE;
2784 }
2785
2786 startResponse;
2787 /* number of records */
2788 num = responselen / sizeof(RIL_NeighboringCell *);
2789 p.writeInt32(num);
2790
2791 for (int i = 0 ; i < num ; i++) {
2792 RIL_NeighboringCell *p_cur = ((RIL_NeighboringCell **) response)[i];
2793
2794 p.writeInt32(p_cur->rssi);
2795 writeStringToParcel (p, p_cur->cid);
2796
2797 appendPrintBuf("%s[cid=%s,rssi=%d],", printBuf,
2798 p_cur->cid, p_cur->rssi);
2799 }
2800 removeLastChar;
2801 closeResponse;
2802
2803 return 0;
2804}
2805
2806/**
2807 * Marshall the signalInfoRecord into the parcel if it exists.
2808 */
2809static void marshallSignalInfoRecord(Parcel &p,
2810 RIL_CDMA_SignalInfoRecord &p_signalInfoRecord) {
2811 p.writeInt32(p_signalInfoRecord.isPresent);
2812 p.writeInt32(p_signalInfoRecord.signalType);
2813 p.writeInt32(p_signalInfoRecord.alertPitch);
2814 p.writeInt32(p_signalInfoRecord.signal);
2815}
2816
2817static int responseCdmaInformationRecords(Parcel &p,
2818 void *response, size_t responselen) {
2819 int num;
2820 char* string8 = NULL;
2821 int buffer_lenght;
2822 RIL_CDMA_InformationRecord *infoRec;
2823
2824 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002825 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002826 return RIL_ERRNO_INVALID_RESPONSE;
2827 }
2828
2829 if (responselen != sizeof (RIL_CDMA_InformationRecords)) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002830 RLOGE("responseCdmaInformationRecords: invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002831 (int)responselen, (int)sizeof (RIL_CDMA_InformationRecords *));
2832 return RIL_ERRNO_INVALID_RESPONSE;
2833 }
2834
2835 RIL_CDMA_InformationRecords *p_cur =
2836 (RIL_CDMA_InformationRecords *) response;
2837 num = MIN(p_cur->numberOfInfoRecs, RIL_CDMA_MAX_NUMBER_OF_INFO_RECS);
2838
2839 startResponse;
2840 p.writeInt32(num);
2841
2842 for (int i = 0 ; i < num ; i++) {
2843 infoRec = &p_cur->infoRec[i];
2844 p.writeInt32(infoRec->name);
2845 switch (infoRec->name) {
2846 case RIL_CDMA_DISPLAY_INFO_REC:
2847 case RIL_CDMA_EXTENDED_DISPLAY_INFO_REC:
2848 if (infoRec->rec.display.alpha_len >
2849 CDMA_ALPHA_INFO_BUFFER_LENGTH) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002850 RLOGE("invalid display info response length %d \
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002851 expected not more than %d\n",
2852 (int)infoRec->rec.display.alpha_len,
2853 CDMA_ALPHA_INFO_BUFFER_LENGTH);
2854 return RIL_ERRNO_INVALID_RESPONSE;
2855 }
2856 string8 = (char*) malloc((infoRec->rec.display.alpha_len + 1)
2857 * sizeof(char) );
2858 for (int i = 0 ; i < infoRec->rec.display.alpha_len ; i++) {
2859 string8[i] = infoRec->rec.display.alpha_buf[i];
2860 }
2861 string8[(int)infoRec->rec.display.alpha_len] = '\0';
2862 writeStringToParcel(p, (const char*)string8);
2863 free(string8);
2864 string8 = NULL;
2865 break;
2866 case RIL_CDMA_CALLED_PARTY_NUMBER_INFO_REC:
2867 case RIL_CDMA_CALLING_PARTY_NUMBER_INFO_REC:
2868 case RIL_CDMA_CONNECTED_NUMBER_INFO_REC:
2869 if (infoRec->rec.number.len > 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.number.len,
2873 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2874 return RIL_ERRNO_INVALID_RESPONSE;
2875 }
2876 string8 = (char*) malloc((infoRec->rec.number.len + 1)
2877 * sizeof(char) );
2878 for (int i = 0 ; i < infoRec->rec.number.len; i++) {
2879 string8[i] = infoRec->rec.number.buf[i];
2880 }
2881 string8[(int)infoRec->rec.number.len] = '\0';
2882 writeStringToParcel(p, (const char*)string8);
2883 free(string8);
2884 string8 = NULL;
2885 p.writeInt32(infoRec->rec.number.number_type);
2886 p.writeInt32(infoRec->rec.number.number_plan);
2887 p.writeInt32(infoRec->rec.number.pi);
2888 p.writeInt32(infoRec->rec.number.si);
2889 break;
2890 case RIL_CDMA_SIGNAL_INFO_REC:
2891 p.writeInt32(infoRec->rec.signal.isPresent);
2892 p.writeInt32(infoRec->rec.signal.signalType);
2893 p.writeInt32(infoRec->rec.signal.alertPitch);
2894 p.writeInt32(infoRec->rec.signal.signal);
2895
2896 appendPrintBuf("%sisPresent=%X, signalType=%X, \
2897 alertPitch=%X, signal=%X, ",
2898 printBuf, (int)infoRec->rec.signal.isPresent,
2899 (int)infoRec->rec.signal.signalType,
2900 (int)infoRec->rec.signal.alertPitch,
2901 (int)infoRec->rec.signal.signal);
2902 removeLastChar;
2903 break;
2904 case RIL_CDMA_REDIRECTING_NUMBER_INFO_REC:
2905 if (infoRec->rec.redir.redirectingNumber.len >
2906 CDMA_NUMBER_INFO_BUFFER_LENGTH) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002907 RLOGE("invalid display info response length %d \
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002908 expected not more than %d\n",
2909 (int)infoRec->rec.redir.redirectingNumber.len,
2910 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2911 return RIL_ERRNO_INVALID_RESPONSE;
2912 }
2913 string8 = (char*) malloc((infoRec->rec.redir.redirectingNumber
2914 .len + 1) * sizeof(char) );
2915 for (int i = 0;
2916 i < infoRec->rec.redir.redirectingNumber.len;
2917 i++) {
2918 string8[i] = infoRec->rec.redir.redirectingNumber.buf[i];
2919 }
2920 string8[(int)infoRec->rec.redir.redirectingNumber.len] = '\0';
2921 writeStringToParcel(p, (const char*)string8);
2922 free(string8);
2923 string8 = NULL;
2924 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_type);
2925 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_plan);
2926 p.writeInt32(infoRec->rec.redir.redirectingNumber.pi);
2927 p.writeInt32(infoRec->rec.redir.redirectingNumber.si);
2928 p.writeInt32(infoRec->rec.redir.redirectingReason);
2929 break;
2930 case RIL_CDMA_LINE_CONTROL_INFO_REC:
2931 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPolarityIncluded);
2932 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlToggle);
2933 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlReverse);
2934 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2935
2936 appendPrintBuf("%slineCtrlPolarityIncluded=%d, \
2937 lineCtrlToggle=%d, lineCtrlReverse=%d, \
2938 lineCtrlPowerDenial=%d, ", printBuf,
2939 (int)infoRec->rec.lineCtrl.lineCtrlPolarityIncluded,
2940 (int)infoRec->rec.lineCtrl.lineCtrlToggle,
2941 (int)infoRec->rec.lineCtrl.lineCtrlReverse,
2942 (int)infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2943 removeLastChar;
2944 break;
2945 case RIL_CDMA_T53_CLIR_INFO_REC:
2946 p.writeInt32((int)(infoRec->rec.clir.cause));
2947
2948 appendPrintBuf("%scause%d", printBuf, infoRec->rec.clir.cause);
2949 removeLastChar;
2950 break;
2951 case RIL_CDMA_T53_AUDIO_CONTROL_INFO_REC:
2952 p.writeInt32(infoRec->rec.audioCtrl.upLink);
2953 p.writeInt32(infoRec->rec.audioCtrl.downLink);
2954
2955 appendPrintBuf("%supLink=%d, downLink=%d, ", printBuf,
2956 infoRec->rec.audioCtrl.upLink,
2957 infoRec->rec.audioCtrl.downLink);
2958 removeLastChar;
2959 break;
2960 case RIL_CDMA_T53_RELEASE_INFO_REC:
2961 // TODO(Moto): See David Krause, he has the answer:)
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002962 RLOGE("RIL_CDMA_T53_RELEASE_INFO_REC: return INVALID_RESPONSE");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002963 return RIL_ERRNO_INVALID_RESPONSE;
2964 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002965 RLOGE("Incorrect name value");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002966 return RIL_ERRNO_INVALID_RESPONSE;
2967 }
2968 }
2969 closeResponse;
2970
2971 return 0;
2972}
2973
2974static int responseRilSignalStrength(Parcel &p,
2975 void *response, size_t responselen) {
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05302976 int gsmSignalStrength;
2977 int cdmaDbm;
2978 int evdoDbm;
2979
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002980 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002981 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002982 return RIL_ERRNO_INVALID_RESPONSE;
2983 }
2984
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002985 if (responselen >= sizeof (RIL_SignalStrength_v5)) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002986 RIL_SignalStrength_v10 *p_cur = ((RIL_SignalStrength_v10 *) response);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002987
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05302988 gsmSignalStrength = p_cur->GW_SignalStrength.signalStrength & 0xFF;
Utkarsh Gupta8ede9fa2015-04-23 13:21:49 +05302989
2990#ifdef MODEM_TYPE_XMM6260
2991 if (gsmSignalStrength < 0 ||
2992 (gsmSignalStrength > 31 && p_cur->GW_SignalStrength.signalStrength != 99)) {
2993 gsmSignalStrength = p_cur->CDMA_SignalStrength.dbm;
2994 }
2995#else
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05302996 if (gsmSignalStrength < 0) {
2997 gsmSignalStrength = 99;
2998 } else if (gsmSignalStrength > 31 && gsmSignalStrength != 99) {
2999 gsmSignalStrength = 31;
3000 }
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303001#endif
3002 p.writeInt32(gsmSignalStrength);
3003
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003004 p.writeInt32(p_cur->GW_SignalStrength.bitErrorRate);
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303005
Christopher N. Hesse621e63e2016-02-22 21:57:39 +01003006#if defined(MODEM_TYPE_XMM6262) || defined(SAMSUNG_NEXT_GEN_MODEM)
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303007 cdmaDbm = p_cur->CDMA_SignalStrength.dbm & 0xFF;
3008 if (cdmaDbm < 0) {
3009 cdmaDbm = 99;
3010 } else if (cdmaDbm > 31 && cdmaDbm != 99) {
3011 cdmaDbm = 31;
3012 }
3013#else
Caio Schnepperec042542015-04-14 08:03:43 -03003014 cdmaDbm = p_cur->CDMA_SignalStrength.dbm;
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303015#endif
3016 p.writeInt32(cdmaDbm);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003017 p.writeInt32(p_cur->CDMA_SignalStrength.ecio);
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303018
Christopher N. Hesse621e63e2016-02-22 21:57:39 +01003019#if defined(MODEM_TYPE_XMM6262) || defined(SAMSUNG_NEXT_GEN_MODEM)
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303020 evdoDbm = p_cur->EVDO_SignalStrength.dbm & 0xFF;
3021 if (evdoDbm < 0) {
3022 evdoDbm = 99;
3023 } else if (evdoDbm > 31 && evdoDbm != 99) {
3024 evdoDbm = 31;
3025 }
3026#else
3027 evdoDbm = p_cur->EVDO_SignalStrength.dbm;
3028#endif
3029 p.writeInt32(evdoDbm);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003030 p.writeInt32(p_cur->EVDO_SignalStrength.ecio);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003031 p.writeInt32(p_cur->EVDO_SignalStrength.signalNoiseRatio);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003032 if (responselen >= sizeof (RIL_SignalStrength_v6)) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003033 /*
Ethan Chend6e30652013-08-04 22:49:56 -07003034 * Fixup LTE for backwards compatibility
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003035 */
Ethan Chend6e30652013-08-04 22:49:56 -07003036 if (s_callbacks.version <= 6) {
3037 // signalStrength: -1 -> 99
3038 if (p_cur->LTE_SignalStrength.signalStrength == -1) {
3039 p_cur->LTE_SignalStrength.signalStrength = 99;
3040 }
3041 // rsrp: -1 -> INT_MAX all other negative value to positive.
3042 // So remap here
3043 if (p_cur->LTE_SignalStrength.rsrp == -1) {
3044 p_cur->LTE_SignalStrength.rsrp = INT_MAX;
3045 } else if (p_cur->LTE_SignalStrength.rsrp < -1) {
3046 p_cur->LTE_SignalStrength.rsrp = -p_cur->LTE_SignalStrength.rsrp;
3047 }
3048 // rsrq: -1 -> INT_MAX
3049 if (p_cur->LTE_SignalStrength.rsrq == -1) {
3050 p_cur->LTE_SignalStrength.rsrq = INT_MAX;
3051 }
3052 // Not remapping rssnr is already using INT_MAX
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003053
Ethan Chend6e30652013-08-04 22:49:56 -07003054 // cqi: -1 -> INT_MAX
3055 if (p_cur->LTE_SignalStrength.cqi == -1) {
3056 p_cur->LTE_SignalStrength.cqi = INT_MAX;
3057 }
3058 }
3059 p.writeInt32(p_cur->LTE_SignalStrength.signalStrength);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003060 p.writeInt32(p_cur->LTE_SignalStrength.rsrp);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003061 p.writeInt32(p_cur->LTE_SignalStrength.rsrq);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003062 p.writeInt32(p_cur->LTE_SignalStrength.rssnr);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003063 p.writeInt32(p_cur->LTE_SignalStrength.cqi);
Howard Sue32dbfd2015-01-07 15:55:57 +08003064 if (responselen >= sizeof (RIL_SignalStrength_v10)) {
3065 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
3066 } else {
3067 p.writeInt32(INT_MAX);
3068 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003069 } else {
Ethan Chend6e30652013-08-04 22:49:56 -07003070 p.writeInt32(99);
3071 p.writeInt32(INT_MAX);
3072 p.writeInt32(INT_MAX);
3073 p.writeInt32(INT_MAX);
3074 p.writeInt32(INT_MAX);
Howard Sue32dbfd2015-01-07 15:55:57 +08003075 p.writeInt32(INT_MAX);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003076 }
3077
3078 startResponse;
3079 appendPrintBuf("%s[signalStrength=%d,bitErrorRate=%d,\
3080 CDMA_SS.dbm=%d,CDMA_SSecio=%d,\
3081 EVDO_SS.dbm=%d,EVDO_SS.ecio=%d,\
3082 EVDO_SS.signalNoiseRatio=%d,\
3083 LTE_SS.signalStrength=%d,LTE_SS.rsrp=%d,LTE_SS.rsrq=%d,\
Howard Sue32dbfd2015-01-07 15:55:57 +08003084 LTE_SS.rssnr=%d,LTE_SS.cqi=%d,TDSCDMA_SS.rscp=%d]",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003085 printBuf,
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303086 gsmSignalStrength,
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003087 p_cur->GW_SignalStrength.bitErrorRate,
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303088 cdmaDbm,
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003089 p_cur->CDMA_SignalStrength.ecio,
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303090 evdoDbm,
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003091 p_cur->EVDO_SignalStrength.ecio,
3092 p_cur->EVDO_SignalStrength.signalNoiseRatio,
3093 p_cur->LTE_SignalStrength.signalStrength,
3094 p_cur->LTE_SignalStrength.rsrp,
3095 p_cur->LTE_SignalStrength.rsrq,
3096 p_cur->LTE_SignalStrength.rssnr,
Howard Sue32dbfd2015-01-07 15:55:57 +08003097 p_cur->LTE_SignalStrength.cqi,
3098 p_cur->TD_SCDMA_SignalStrength.rscp);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003099 closeResponse;
3100
3101 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003102 RLOGE("invalid response length");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003103 return RIL_ERRNO_INVALID_RESPONSE;
3104 }
3105
3106 return 0;
3107}
3108
3109static int responseCallRing(Parcel &p, void *response, size_t responselen) {
3110 if ((response == NULL) || (responselen == 0)) {
3111 return responseVoid(p, response, responselen);
3112 } else {
3113 return responseCdmaSignalInfoRecord(p, response, responselen);
3114 }
3115}
3116
3117static int responseCdmaSignalInfoRecord(Parcel &p, void *response, size_t responselen) {
3118 if (response == NULL || responselen == 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003119 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003120 return RIL_ERRNO_INVALID_RESPONSE;
3121 }
3122
3123 if (responselen != sizeof (RIL_CDMA_SignalInfoRecord)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003124 RLOGE("invalid response length %d expected sizeof (RIL_CDMA_SignalInfoRecord) of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003125 (int)responselen, (int)sizeof (RIL_CDMA_SignalInfoRecord));
3126 return RIL_ERRNO_INVALID_RESPONSE;
3127 }
3128
3129 startResponse;
3130
3131 RIL_CDMA_SignalInfoRecord *p_cur = ((RIL_CDMA_SignalInfoRecord *) response);
3132 marshallSignalInfoRecord(p, *p_cur);
3133
3134 appendPrintBuf("%s[isPresent=%d,signalType=%d,alertPitch=%d\
3135 signal=%d]",
3136 printBuf,
3137 p_cur->isPresent,
3138 p_cur->signalType,
3139 p_cur->alertPitch,
3140 p_cur->signal);
3141
3142 closeResponse;
3143 return 0;
3144}
3145
3146static int responseCdmaCallWaiting(Parcel &p, void *response,
3147 size_t responselen) {
3148 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003149 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003150 return RIL_ERRNO_INVALID_RESPONSE;
3151 }
3152
3153 if (responselen < sizeof(RIL_CDMA_CallWaiting_v6)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003154 RLOGW("Upgrade to ril version %d\n", RIL_VERSION);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003155 }
3156
3157 RIL_CDMA_CallWaiting_v6 *p_cur = ((RIL_CDMA_CallWaiting_v6 *) response);
3158
3159 writeStringToParcel(p, p_cur->number);
3160 p.writeInt32(p_cur->numberPresentation);
3161 writeStringToParcel(p, p_cur->name);
3162 marshallSignalInfoRecord(p, p_cur->signalInfoRecord);
3163
3164 if (responselen >= sizeof(RIL_CDMA_CallWaiting_v6)) {
3165 p.writeInt32(p_cur->number_type);
3166 p.writeInt32(p_cur->number_plan);
3167 } else {
3168 p.writeInt32(0);
3169 p.writeInt32(0);
3170 }
3171
3172 startResponse;
3173 appendPrintBuf("%snumber=%s,numberPresentation=%d, name=%s,\
3174 signalInfoRecord[isPresent=%d,signalType=%d,alertPitch=%d\
3175 signal=%d,number_type=%d,number_plan=%d]",
3176 printBuf,
3177 p_cur->number,
3178 p_cur->numberPresentation,
3179 p_cur->name,
3180 p_cur->signalInfoRecord.isPresent,
3181 p_cur->signalInfoRecord.signalType,
3182 p_cur->signalInfoRecord.alertPitch,
3183 p_cur->signalInfoRecord.signal,
3184 p_cur->number_type,
3185 p_cur->number_plan);
3186 closeResponse;
3187
3188 return 0;
3189}
3190
3191static int responseSimRefresh(Parcel &p, void *response, size_t responselen) {
3192 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003193 RLOGE("responseSimRefresh: invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003194 return RIL_ERRNO_INVALID_RESPONSE;
3195 }
3196
3197 startResponse;
3198 if (s_callbacks.version == 7) {
3199 RIL_SimRefreshResponse_v7 *p_cur = ((RIL_SimRefreshResponse_v7 *) response);
3200 p.writeInt32(p_cur->result);
3201 p.writeInt32(p_cur->ef_id);
3202 writeStringToParcel(p, p_cur->aid);
3203
3204 appendPrintBuf("%sresult=%d, ef_id=%d, aid=%s",
3205 printBuf,
3206 p_cur->result,
3207 p_cur->ef_id,
3208 p_cur->aid);
3209 } else {
3210 int *p_cur = ((int *) response);
3211 p.writeInt32(p_cur[0]);
3212 p.writeInt32(p_cur[1]);
3213 writeStringToParcel(p, NULL);
3214
3215 appendPrintBuf("%sresult=%d, ef_id=%d",
3216 printBuf,
3217 p_cur[0],
3218 p_cur[1]);
3219 }
3220 closeResponse;
3221
3222 return 0;
3223}
3224
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003225static int responseCellInfoList(Parcel &p, void *response, size_t responselen)
3226{
3227 if (response == NULL && responselen != 0) {
3228 RLOGE("invalid response: NULL");
3229 return RIL_ERRNO_INVALID_RESPONSE;
3230 }
3231
3232 if (responselen % sizeof(RIL_CellInfo) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08003233 RLOGE("responseCellInfoList: invalid response length %d expected multiple of %d",
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003234 (int)responselen, (int)sizeof(RIL_CellInfo));
3235 return RIL_ERRNO_INVALID_RESPONSE;
3236 }
3237
3238 int num = responselen / sizeof(RIL_CellInfo);
3239 p.writeInt32(num);
3240
3241 RIL_CellInfo *p_cur = (RIL_CellInfo *) response;
3242 startResponse;
3243 int i;
3244 for (i = 0; i < num; i++) {
3245 appendPrintBuf("%s[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", printBuf, i,
3246 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
3247 p.writeInt32((int)p_cur->cellInfoType);
3248 p.writeInt32(p_cur->registered);
3249 p.writeInt32(p_cur->timeStampType);
3250 p.writeInt64(p_cur->timeStamp);
3251 switch(p_cur->cellInfoType) {
3252 case RIL_CELL_INFO_TYPE_GSM: {
3253 appendPrintBuf("%s GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,", printBuf,
3254 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
3255 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
3256 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
3257 p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3258 appendPrintBuf("%s gsmSS: ss=%d,ber=%d],", printBuf,
3259 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
3260 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3261
3262 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
3263 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
3264 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
3265 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3266 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
3267 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3268 break;
3269 }
3270 case RIL_CELL_INFO_TYPE_WCDMA: {
3271 appendPrintBuf("%s WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,", printBuf,
3272 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
3273 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
3274 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
3275 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
3276 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3277 appendPrintBuf("%s wcdmaSS: ss=%d,ber=%d],", printBuf,
3278 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
3279 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3280
3281 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
3282 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
3283 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
3284 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
3285 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3286 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
3287 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3288 break;
3289 }
3290 case RIL_CELL_INFO_TYPE_CDMA: {
3291 appendPrintBuf("%s CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d", printBuf,
3292 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
3293 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
3294 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
3295 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
3296 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3297
3298 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
3299 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
3300 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
3301 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
3302 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3303
3304 appendPrintBuf("%s cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d", printBuf,
3305 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
3306 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
3307 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
3308 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
3309 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3310
3311 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
3312 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
3313 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
3314 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
3315 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3316 break;
3317 }
3318 case RIL_CELL_INFO_TYPE_LTE: {
3319 appendPrintBuf("%s LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d", printBuf,
3320 p_cur->CellInfo.lte.cellIdentityLte.mcc,
3321 p_cur->CellInfo.lte.cellIdentityLte.mnc,
3322 p_cur->CellInfo.lte.cellIdentityLte.ci,
3323 p_cur->CellInfo.lte.cellIdentityLte.pci,
3324 p_cur->CellInfo.lte.cellIdentityLte.tac);
3325
3326 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
3327 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
3328 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
3329 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
3330 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
3331
3332 appendPrintBuf("%s lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d", printBuf,
3333 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
3334 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
3335 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
3336 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
3337 p_cur->CellInfo.lte.signalStrengthLte.cqi,
3338 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3339 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
3340 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
3341 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
3342 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
3343 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
3344 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3345 break;
3346 }
Howard Sue32dbfd2015-01-07 15:55:57 +08003347 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
3348 appendPrintBuf("%s TDSCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,cpid=%d,", printBuf,
3349 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc,
3350 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc,
3351 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac,
3352 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid,
3353 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3354 appendPrintBuf("%s tdscdmaSS: rscp=%d],", printBuf,
3355 p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3356
3357 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
3358 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
3359 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
3360 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
3361 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3362 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3363 break;
3364 }
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003365 }
3366 p_cur += 1;
3367 }
3368 removeLastChar;
3369 closeResponse;
3370
3371 return 0;
3372}
3373
Howard Sue32dbfd2015-01-07 15:55:57 +08003374static int responseHardwareConfig(Parcel &p, void *response, size_t responselen)
3375{
3376 if (response == NULL && responselen != 0) {
3377 RLOGE("invalid response: NULL");
3378 return RIL_ERRNO_INVALID_RESPONSE;
3379 }
3380
3381 if (responselen % sizeof(RIL_HardwareConfig) != 0) {
3382 RLOGE("responseHardwareConfig: invalid response length %d expected multiple of %d",
3383 (int)responselen, (int)sizeof(RIL_HardwareConfig));
3384 return RIL_ERRNO_INVALID_RESPONSE;
3385 }
3386
3387 int num = responselen / sizeof(RIL_HardwareConfig);
3388 int i;
3389 RIL_HardwareConfig *p_cur = (RIL_HardwareConfig *) response;
3390
3391 p.writeInt32(num);
3392
3393 startResponse;
3394 for (i = 0; i < num; i++) {
3395 switch (p_cur[i].type) {
3396 case RIL_HARDWARE_CONFIG_MODEM: {
3397 writeStringToParcel(p, p_cur[i].uuid);
3398 p.writeInt32((int)p_cur[i].state);
3399 p.writeInt32(p_cur[i].cfg.modem.rat);
3400 p.writeInt32(p_cur[i].cfg.modem.maxVoice);
3401 p.writeInt32(p_cur[i].cfg.modem.maxData);
3402 p.writeInt32(p_cur[i].cfg.modem.maxStandby);
3403
3404 appendPrintBuf("%s modem: uuid=%s,state=%d,rat=%08x,maxV=%d,maxD=%d,maxS=%d", printBuf,
3405 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.modem.rat,
3406 p_cur[i].cfg.modem.maxVoice, p_cur[i].cfg.modem.maxData, p_cur[i].cfg.modem.maxStandby);
3407 break;
3408 }
3409 case RIL_HARDWARE_CONFIG_SIM: {
3410 writeStringToParcel(p, p_cur[i].uuid);
3411 p.writeInt32((int)p_cur[i].state);
3412 writeStringToParcel(p, p_cur[i].cfg.sim.modemUuid);
3413
3414 appendPrintBuf("%s sim: uuid=%s,state=%d,modem-uuid=%s", printBuf,
3415 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.sim.modemUuid);
3416 break;
3417 }
3418 }
3419 }
3420 removeLastChar;
3421 closeResponse;
3422 return 0;
3423}
3424
Howard Subd82ef12015-04-12 10:25:05 +02003425static int responseRadioCapability(Parcel &p, void *response, size_t responselen) {
3426 if (response == NULL) {
3427 RLOGE("invalid response: NULL");
3428 return RIL_ERRNO_INVALID_RESPONSE;
3429 }
3430
3431 if (responselen != sizeof (RIL_RadioCapability) ) {
3432 RLOGE("invalid response length was %d expected %d",
3433 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3434 return RIL_ERRNO_INVALID_RESPONSE;
3435 }
3436
3437 RIL_RadioCapability *p_cur = (RIL_RadioCapability *) response;
3438 p.writeInt32(p_cur->version);
3439 p.writeInt32(p_cur->session);
3440 p.writeInt32(p_cur->phase);
3441 p.writeInt32(p_cur->rat);
3442 writeStringToParcel(p, p_cur->logicalModemUuid);
3443 p.writeInt32(p_cur->status);
3444
3445 startResponse;
3446 appendPrintBuf("%s[version=%d,session=%d,phase=%d,\
Andreas Schneidera8d09502015-06-23 18:41:38 +02003447 rat=%d,logicalModemUuid=%s,status=%d]",
Howard Subd82ef12015-04-12 10:25:05 +02003448 printBuf,
3449 p_cur->version,
3450 p_cur->session,
3451 p_cur->phase,
3452 p_cur->rat,
3453 p_cur->logicalModemUuid,
3454 p_cur->status);
3455 closeResponse;
3456 return 0;
3457}
3458
3459static int responseSSData(Parcel &p, void *response, size_t responselen) {
3460 RLOGD("In responseSSData");
3461 int num;
3462
3463 if (response == NULL && responselen != 0) {
3464 RLOGE("invalid response length was %d expected %d",
3465 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3466 return RIL_ERRNO_INVALID_RESPONSE;
3467 }
3468
3469 if (responselen != sizeof(RIL_StkCcUnsolSsResponse)) {
3470 RLOGE("invalid response length %d, expected %d",
3471 (int)responselen, (int)sizeof(RIL_StkCcUnsolSsResponse));
3472 return RIL_ERRNO_INVALID_RESPONSE;
3473 }
3474
3475 startResponse;
3476 RIL_StkCcUnsolSsResponse *p_cur = (RIL_StkCcUnsolSsResponse *) response;
3477 p.writeInt32(p_cur->serviceType);
3478 p.writeInt32(p_cur->requestType);
3479 p.writeInt32(p_cur->teleserviceType);
3480 p.writeInt32(p_cur->serviceClass);
3481 p.writeInt32(p_cur->result);
3482
3483 if (isServiceTypeCfQuery(p_cur->serviceType, p_cur->requestType)) {
3484 RLOGD("responseSSData CF type, num of Cf elements %d", p_cur->cfData.numValidIndexes);
3485 if (p_cur->cfData.numValidIndexes > NUM_SERVICE_CLASSES) {
3486 RLOGE("numValidIndexes is greater than max value %d, "
3487 "truncating it to max value", NUM_SERVICE_CLASSES);
3488 p_cur->cfData.numValidIndexes = NUM_SERVICE_CLASSES;
3489 }
3490 /* number of call info's */
3491 p.writeInt32(p_cur->cfData.numValidIndexes);
3492
3493 for (int i = 0; i < p_cur->cfData.numValidIndexes; i++) {
3494 RIL_CallForwardInfo cf = p_cur->cfData.cfInfo[i];
3495
3496 p.writeInt32(cf.status);
3497 p.writeInt32(cf.reason);
3498 p.writeInt32(cf.serviceClass);
3499 p.writeInt32(cf.toa);
3500 writeStringToParcel(p, cf.number);
3501 p.writeInt32(cf.timeSeconds);
3502 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
3503 (cf.status==1)?"enable":"disable", cf.reason, cf.serviceClass, cf.toa,
3504 (char*)cf.number, cf.timeSeconds);
3505 RLOGD("Data: %d,reason=%d,cls=%d,toa=%d,num=%s,tout=%d],", cf.status,
3506 cf.reason, cf.serviceClass, cf.toa, (char*)cf.number, cf.timeSeconds);
3507 }
3508 } else {
3509 p.writeInt32 (SS_INFO_MAX);
3510
3511 /* each int*/
3512 for (int i = 0; i < SS_INFO_MAX; i++) {
3513 appendPrintBuf("%s%d,", printBuf, p_cur->ssInfo[i]);
3514 RLOGD("Data: %d",p_cur->ssInfo[i]);
3515 p.writeInt32(p_cur->ssInfo[i]);
3516 }
3517 }
3518 removeLastChar;
3519 closeResponse;
3520
3521 return 0;
3522}
3523
3524static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType) {
3525 if ((reqType == SS_INTERROGATION) &&
3526 (serType == SS_CFU ||
3527 serType == SS_CF_BUSY ||
3528 serType == SS_CF_NO_REPLY ||
3529 serType == SS_CF_NOT_REACHABLE ||
3530 serType == SS_CF_ALL ||
3531 serType == SS_CF_ALL_CONDITIONAL)) {
3532 return true;
3533 }
3534 return false;
3535}
3536
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003537static void triggerEvLoop() {
3538 int ret;
3539 if (!pthread_equal(pthread_self(), s_tid_dispatch)) {
3540 /* trigger event loop to wakeup. No reason to do this,
3541 * if we're in the event loop thread */
3542 do {
3543 ret = write (s_fdWakeupWrite, " ", 1);
3544 } while (ret < 0 && errno == EINTR);
3545 }
3546}
3547
3548static void rilEventAddWakeup(struct ril_event *ev) {
3549 ril_event_add(ev);
3550 triggerEvLoop();
3551}
3552
3553static void sendSimStatusAppInfo(Parcel &p, int num_apps, RIL_AppStatus appStatus[]) {
3554 p.writeInt32(num_apps);
3555 startResponse;
3556 for (int i = 0; i < num_apps; i++) {
3557 p.writeInt32(appStatus[i].app_type);
3558 p.writeInt32(appStatus[i].app_state);
3559 p.writeInt32(appStatus[i].perso_substate);
3560 writeStringToParcel(p, (const char*)(appStatus[i].aid_ptr));
3561 writeStringToParcel(p, (const char*)
3562 (appStatus[i].app_label_ptr));
3563 p.writeInt32(appStatus[i].pin1_replaced);
3564 p.writeInt32(appStatus[i].pin1);
3565 p.writeInt32(appStatus[i].pin2);
3566 appendPrintBuf("%s[app_type=%d,app_state=%d,perso_substate=%d,\
3567 aid_ptr=%s,app_label_ptr=%s,pin1_replaced=%d,pin1=%d,pin2=%d],",
3568 printBuf,
3569 appStatus[i].app_type,
3570 appStatus[i].app_state,
3571 appStatus[i].perso_substate,
3572 appStatus[i].aid_ptr,
3573 appStatus[i].app_label_ptr,
3574 appStatus[i].pin1_replaced,
3575 appStatus[i].pin1,
3576 appStatus[i].pin2);
3577 }
3578 closeResponse;
3579}
3580
3581static int responseSimStatus(Parcel &p, void *response, size_t responselen) {
Howard Sue32dbfd2015-01-07 15:55:57 +08003582 int i;
3583
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003584 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003585 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003586 return RIL_ERRNO_INVALID_RESPONSE;
3587 }
3588
3589 if (responselen == sizeof (RIL_CardStatus_v6)) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003590 RIL_CardStatus_v6 *p_cur = ((RIL_CardStatus_v6 *) response);
3591
3592 p.writeInt32(p_cur->card_state);
3593 p.writeInt32(p_cur->universal_pin_state);
3594 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3595 p.writeInt32(p_cur->cdma_subscription_app_index);
3596 p.writeInt32(p_cur->ims_subscription_app_index);
3597
3598 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
3599 } else if (responselen == sizeof (RIL_CardStatus_v5)) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003600 RIL_CardStatus_v5 *p_cur = ((RIL_CardStatus_v5 *) response);
3601
3602 p.writeInt32(p_cur->card_state);
3603 p.writeInt32(p_cur->universal_pin_state);
3604 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3605 p.writeInt32(p_cur->cdma_subscription_app_index);
3606 p.writeInt32(-1);
3607
3608 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
3609 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003610 RLOGE("responseSimStatus: A RilCardStatus_v6 or _v5 expected\n");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003611 return RIL_ERRNO_INVALID_RESPONSE;
3612 }
3613
3614 return 0;
3615}
3616
3617static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3618 int num = responselen / sizeof(RIL_GSM_BroadcastSmsConfigInfo *);
3619 p.writeInt32(num);
3620
3621 startResponse;
3622 RIL_GSM_BroadcastSmsConfigInfo **p_cur =
3623 (RIL_GSM_BroadcastSmsConfigInfo **) response;
3624 for (int i = 0; i < num; i++) {
3625 p.writeInt32(p_cur[i]->fromServiceId);
3626 p.writeInt32(p_cur[i]->toServiceId);
3627 p.writeInt32(p_cur[i]->fromCodeScheme);
3628 p.writeInt32(p_cur[i]->toCodeScheme);
3629 p.writeInt32(p_cur[i]->selected);
3630
3631 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId=%d, \
3632 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]",
3633 printBuf, i, p_cur[i]->fromServiceId, p_cur[i]->toServiceId,
3634 p_cur[i]->fromCodeScheme, p_cur[i]->toCodeScheme,
3635 p_cur[i]->selected);
3636 }
3637 closeResponse;
3638
3639 return 0;
3640}
3641
3642static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3643 RIL_CDMA_BroadcastSmsConfigInfo **p_cur =
3644 (RIL_CDMA_BroadcastSmsConfigInfo **) response;
3645
3646 int num = responselen / sizeof (RIL_CDMA_BroadcastSmsConfigInfo *);
3647 p.writeInt32(num);
3648
3649 startResponse;
3650 for (int i = 0 ; i < num ; i++ ) {
3651 p.writeInt32(p_cur[i]->service_category);
3652 p.writeInt32(p_cur[i]->language);
3653 p.writeInt32(p_cur[i]->selected);
3654
3655 appendPrintBuf("%s [%d: srvice_category=%d, language =%d, \
3656 selected =%d], ",
3657 printBuf, i, p_cur[i]->service_category, p_cur[i]->language,
3658 p_cur[i]->selected);
3659 }
3660 closeResponse;
3661
3662 return 0;
3663}
3664
3665static int responseCdmaSms(Parcel &p, void *response, size_t responselen) {
3666 int num;
3667 int digitCount;
3668 int digitLimit;
3669 uint8_t uct;
3670 void* dest;
3671
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003672 RLOGD("Inside responseCdmaSms");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003673
3674 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003675 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003676 return RIL_ERRNO_INVALID_RESPONSE;
3677 }
3678
3679 if (responselen != sizeof(RIL_CDMA_SMS_Message)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003680 RLOGE("invalid response length was %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003681 (int)responselen, (int)sizeof(RIL_CDMA_SMS_Message));
3682 return RIL_ERRNO_INVALID_RESPONSE;
3683 }
3684
3685 RIL_CDMA_SMS_Message *p_cur = (RIL_CDMA_SMS_Message *) response;
3686 p.writeInt32(p_cur->uTeleserviceID);
3687 p.write(&(p_cur->bIsServicePresent),sizeof(uct));
3688 p.writeInt32(p_cur->uServicecategory);
3689 p.writeInt32(p_cur->sAddress.digit_mode);
3690 p.writeInt32(p_cur->sAddress.number_mode);
3691 p.writeInt32(p_cur->sAddress.number_type);
3692 p.writeInt32(p_cur->sAddress.number_plan);
3693 p.write(&(p_cur->sAddress.number_of_digits), sizeof(uct));
3694 digitLimit= MIN((p_cur->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
3695 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3696 p.write(&(p_cur->sAddress.digits[digitCount]),sizeof(uct));
3697 }
3698
3699 p.writeInt32(p_cur->sSubAddress.subaddressType);
3700 p.write(&(p_cur->sSubAddress.odd),sizeof(uct));
3701 p.write(&(p_cur->sSubAddress.number_of_digits),sizeof(uct));
3702 digitLimit= MIN((p_cur->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
3703 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3704 p.write(&(p_cur->sSubAddress.digits[digitCount]),sizeof(uct));
3705 }
3706
3707 digitLimit= MIN((p_cur->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
3708 p.writeInt32(p_cur->uBearerDataLen);
3709 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3710 p.write(&(p_cur->aBearerData[digitCount]), sizeof(uct));
3711 }
3712
3713 startResponse;
3714 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
3715 sAddress.digit_mode=%d, sAddress.number_mode=%d, sAddress.number_type=%d, ",
3716 printBuf, p_cur->uTeleserviceID,p_cur->bIsServicePresent,p_cur->uServicecategory,
3717 p_cur->sAddress.digit_mode, p_cur->sAddress.number_mode,p_cur->sAddress.number_type);
3718 closeResponse;
3719
3720 return 0;
3721}
3722
Howard Sue32dbfd2015-01-07 15:55:57 +08003723static int responseDcRtInfo(Parcel &p, void *response, size_t responselen)
3724{
3725 int num = responselen / sizeof(RIL_DcRtInfo);
3726 if ((responselen % sizeof(RIL_DcRtInfo) != 0) || (num != 1)) {
3727 RLOGE("responseDcRtInfo: invalid response length %d expected multiple of %d",
3728 (int)responselen, (int)sizeof(RIL_DcRtInfo));
3729 return RIL_ERRNO_INVALID_RESPONSE;
3730 }
3731
3732 startResponse;
3733 RIL_DcRtInfo *pDcRtInfo = (RIL_DcRtInfo *)response;
3734 p.writeInt64(pDcRtInfo->time);
3735 p.writeInt32(pDcRtInfo->powerState);
3736 appendPrintBuf("%s[time=%d,powerState=%d]", printBuf,
3737 pDcRtInfo->time,
Andreas Schneidera8d09502015-06-23 18:41:38 +02003738 (int)pDcRtInfo->powerState);
Howard Sue32dbfd2015-01-07 15:55:57 +08003739 closeResponse;
3740
3741 return 0;
3742}
3743
fenglu9bdede02015-04-14 14:53:55 -07003744static int responseLceStatus(Parcel &p, void *response, size_t responselen) {
3745 if (response == NULL || responselen != sizeof(RIL_LceStatusInfo)) {
3746 if (response == NULL) {
3747 RLOGE("invalid response: NULL");
3748 }
3749 else {
3750 RLOGE("responseLceStatus: invalid response length %d expecting len: d%",
3751 sizeof(RIL_LceStatusInfo), responselen);
3752 }
3753 return RIL_ERRNO_INVALID_RESPONSE;
3754 }
3755
3756 RIL_LceStatusInfo *p_cur = (RIL_LceStatusInfo *)response;
3757 p.write((void *)p_cur, 1); // p_cur->lce_status takes one byte.
3758 p.writeInt32(p_cur->actual_interval_ms);
3759
3760 startResponse;
3761 appendPrintBuf("LCE Status: %d, actual_interval_ms: %d",
3762 p_cur->lce_status, p_cur->actual_interval_ms);
3763 closeResponse;
3764
3765 return 0;
3766}
3767
3768static int responseLceData(Parcel &p, void *response, size_t responselen) {
3769 if (response == NULL || responselen != sizeof(RIL_LceDataInfo)) {
3770 if (response == NULL) {
3771 RLOGE("invalid response: NULL");
3772 }
3773 else {
3774 RLOGE("responseLceData: invalid response length %d expecting len: d%",
3775 sizeof(RIL_LceDataInfo), responselen);
3776 }
3777 return RIL_ERRNO_INVALID_RESPONSE;
3778 }
3779
3780 RIL_LceDataInfo *p_cur = (RIL_LceDataInfo *)response;
3781 p.writeInt32(p_cur->last_hop_capacity_kbps);
3782
3783 /* p_cur->confidence_level and p_cur->lce_suspended take 1 byte each.*/
3784 p.write((void *)&(p_cur->confidence_level), 1);
3785 p.write((void *)&(p_cur->lce_suspended), 1);
3786
3787 startResponse;
Hyejine942c332015-09-14 16:27:28 -07003788 appendPrintBuf("LCE info received: capacity %d confidence level %d \
3789 and suspended %d",
fenglu9bdede02015-04-14 14:53:55 -07003790 p_cur->last_hop_capacity_kbps, p_cur->confidence_level,
3791 p_cur->lce_suspended);
3792 closeResponse;
3793
3794 return 0;
3795}
3796
Prerepa Viswanadham8e755592015-05-28 00:37:32 -07003797static int responseActivityData(Parcel &p, void *response, size_t responselen) {
3798 if (response == NULL || responselen != sizeof(RIL_ActivityStatsInfo)) {
3799 if (response == NULL) {
3800 RLOGE("invalid response: NULL");
3801 }
3802 else {
3803 RLOGE("responseActivityData: invalid response length %d expecting len: d%",
3804 sizeof(RIL_ActivityStatsInfo), responselen);
3805 }
3806 return RIL_ERRNO_INVALID_RESPONSE;
3807 }
3808
3809 RIL_ActivityStatsInfo *p_cur = (RIL_ActivityStatsInfo *)response;
3810 p.writeInt32(p_cur->sleep_mode_time_ms);
3811 p.writeInt32(p_cur->idle_mode_time_ms);
3812 for(int i = 0; i < RIL_NUM_TX_POWER_LEVELS; i++) {
3813 p.writeInt32(p_cur->tx_mode_time_ms[i]);
3814 }
3815 p.writeInt32(p_cur->rx_mode_time_ms);
3816
3817 startResponse;
Hyejine942c332015-09-14 16:27:28 -07003818 appendPrintBuf("Modem activity info received: sleep_mode_time_ms %d idle_mode_time_ms %d \
3819 tx_mode_time_ms %d %d %d %d %d and rx_mode_time_ms %d",
Prerepa Viswanadham8e755592015-05-28 00:37:32 -07003820 p_cur->sleep_mode_time_ms, p_cur->idle_mode_time_ms, p_cur->tx_mode_time_ms[0],
3821 p_cur->tx_mode_time_ms[1], p_cur->tx_mode_time_ms[2], p_cur->tx_mode_time_ms[3],
3822 p_cur->tx_mode_time_ms[4], p_cur->rx_mode_time_ms);
3823 closeResponse;
3824
3825 return 0;
3826}
3827
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003828/**
3829 * A write on the wakeup fd is done just to pop us out of select()
3830 * We empty the buffer here and then ril_event will reset the timers on the
3831 * way back down
3832 */
3833static void processWakeupCallback(int fd, short flags, void *param) {
3834 char buff[16];
3835 int ret;
3836
Ethan Chend6e30652013-08-04 22:49:56 -07003837 RLOGV("processWakeupCallback");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003838
3839 /* empty our wakeup socket out */
3840 do {
3841 ret = read(s_fdWakeupRead, &buff, sizeof(buff));
3842 } while (ret > 0 || (ret < 0 && errno == EINTR));
3843}
3844
Howard Sue32dbfd2015-01-07 15:55:57 +08003845static void onCommandsSocketClosed(RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003846 int ret;
3847 RequestInfo *p_cur;
Howard Sue32dbfd2015-01-07 15:55:57 +08003848 /* Hook for current context
3849 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
3850 pthread_mutex_t * pendingRequestsMutexHook = &s_pendingRequestsMutex;
3851 /* pendingRequestsHook refer to &s_pendingRequests */
3852 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003853
Howard Sue32dbfd2015-01-07 15:55:57 +08003854#if (SIM_COUNT >= 2)
3855 if (socket_id == RIL_SOCKET_2) {
3856 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
3857 pendingRequestsHook = &s_pendingRequests_socket2;
3858 }
3859#if (SIM_COUNT >= 3)
3860 else if (socket_id == RIL_SOCKET_3) {
3861 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
3862 pendingRequestsHook = &s_pendingRequests_socket3;
3863 }
3864#endif
3865#if (SIM_COUNT >= 4)
3866 else if (socket_id == RIL_SOCKET_4) {
3867 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
3868 pendingRequestsHook = &s_pendingRequests_socket4;
3869 }
3870#endif
3871#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003872 /* mark pending requests as "cancelled" so we dont report responses */
Howard Sue32dbfd2015-01-07 15:55:57 +08003873 ret = pthread_mutex_lock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003874 assert (ret == 0);
3875
Howard Sue32dbfd2015-01-07 15:55:57 +08003876 p_cur = *pendingRequestsHook;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003877
Howard Sue32dbfd2015-01-07 15:55:57 +08003878 for (p_cur = *pendingRequestsHook
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003879 ; p_cur != NULL
3880 ; p_cur = p_cur->p_next
3881 ) {
3882 p_cur->cancelled = 1;
3883 }
3884
Howard Sue32dbfd2015-01-07 15:55:57 +08003885 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003886 assert (ret == 0);
3887}
3888
3889static void processCommandsCallback(int fd, short flags, void *param) {
3890 RecordStream *p_rs;
3891 void *p_record;
3892 size_t recordlen;
3893 int ret;
Howard Sue32dbfd2015-01-07 15:55:57 +08003894 SocketListenParam *p_info = (SocketListenParam *)param;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003895
Howard Sue32dbfd2015-01-07 15:55:57 +08003896 assert(fd == p_info->fdCommand);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003897
Howard Sue32dbfd2015-01-07 15:55:57 +08003898 p_rs = p_info->p_rs;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003899
3900 for (;;) {
3901 /* loop until EAGAIN/EINTR, end of stream, or other error */
3902 ret = record_stream_get_next(p_rs, &p_record, &recordlen);
3903
3904 if (ret == 0 && p_record == NULL) {
3905 /* end-of-stream */
3906 break;
3907 } else if (ret < 0) {
3908 break;
3909 } else if (ret == 0) { /* && p_record != NULL */
Howard Sue32dbfd2015-01-07 15:55:57 +08003910 processCommandBuffer(p_record, recordlen, p_info->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003911 }
3912 }
3913
3914 if (ret == 0 || !(errno == EAGAIN || errno == EINTR)) {
3915 /* fatal error or end-of-stream */
3916 if (ret != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003917 RLOGE("error on reading command socket errno:%d\n", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003918 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003919 RLOGW("EOS. Closing command socket.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003920 }
3921
Howard Sue32dbfd2015-01-07 15:55:57 +08003922 close(fd);
3923 p_info->fdCommand = -1;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003924
Howard Sue32dbfd2015-01-07 15:55:57 +08003925 ril_event_del(p_info->commands_event);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003926
3927 record_stream_free(p_rs);
3928
3929 /* start listening for new connections again */
3930 rilEventAddWakeup(&s_listen_event);
3931
Howard Sue32dbfd2015-01-07 15:55:57 +08003932 onCommandsSocketClosed(p_info->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003933 }
3934}
3935
Howard Subd82ef12015-04-12 10:25:05 +02003936
Howard Sue32dbfd2015-01-07 15:55:57 +08003937static void onNewCommandConnect(RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003938 // Inform we are connected and the ril version
3939 int rilVer = s_callbacks.version;
Howard Sue32dbfd2015-01-07 15:55:57 +08003940 RIL_UNSOL_RESPONSE(RIL_UNSOL_RIL_CONNECTED,
3941 &rilVer, sizeof(rilVer), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003942
3943 // implicit radio state changed
Howard Sue32dbfd2015-01-07 15:55:57 +08003944 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
3945 NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003946
3947 // Send last NITZ time data, in case it was missed
3948 if (s_lastNITZTimeData != NULL) {
Howard Sue32dbfd2015-01-07 15:55:57 +08003949 sendResponseRaw(s_lastNITZTimeData, s_lastNITZTimeDataSize, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003950
3951 free(s_lastNITZTimeData);
3952 s_lastNITZTimeData = NULL;
3953 }
3954
3955 // Get version string
3956 if (s_callbacks.getVersion != NULL) {
3957 const char *version;
3958 version = s_callbacks.getVersion();
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003959 RLOGI("RIL Daemon version: %s\n", version);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003960
3961 property_set(PROPERTY_RIL_IMPL, version);
3962 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003963 RLOGI("RIL Daemon version: unavailable\n");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003964 property_set(PROPERTY_RIL_IMPL, "unavailable");
3965 }
3966
3967}
3968
3969static void listenCallback (int fd, short flags, void *param) {
3970 int ret;
3971 int err;
3972 int is_phone_socket;
Howard Sue32dbfd2015-01-07 15:55:57 +08003973 int fdCommand = -1;
Dheeraj Shettycc231012014-07-02 21:27:57 +02003974 char* processName;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003975 RecordStream *p_rs;
Dheeraj Shettycc231012014-07-02 21:27:57 +02003976 MySocketListenParam* listenParam;
3977 RilSocket *sapSocket = NULL;
3978 socketClient *sClient = NULL;
3979
Howard Sue32dbfd2015-01-07 15:55:57 +08003980 SocketListenParam *p_info = (SocketListenParam *)param;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003981
Dheeraj Shettycc231012014-07-02 21:27:57 +02003982 if(RIL_SAP_SOCKET == p_info->type) {
3983 listenParam = (MySocketListenParam *)param;
3984 sapSocket = listenParam->socket;
3985 }
3986
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003987 struct sockaddr_un peeraddr;
3988 socklen_t socklen = sizeof (peeraddr);
3989
3990 struct ucred creds;
3991 socklen_t szCreds = sizeof(creds);
3992
3993 struct passwd *pwd = NULL;
3994
Dheeraj Shettycc231012014-07-02 21:27:57 +02003995 if(NULL == sapSocket) {
3996 assert (*p_info->fdCommand < 0);
3997 assert (fd == *p_info->fdListen);
3998 processName = PHONE_PROCESS;
3999 } else {
4000 assert (sapSocket->commandFd < 0);
4001 assert (fd == sapSocket->listenFd);
4002 processName = BLUETOOTH_PROCESS;
4003 }
4004
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004005
Howard Sue32dbfd2015-01-07 15:55:57 +08004006 fdCommand = accept(fd, (sockaddr *) &peeraddr, &socklen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004007
Howard Sue32dbfd2015-01-07 15:55:57 +08004008 if (fdCommand < 0 ) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004009 RLOGE("Error on accept() errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004010 /* start listening for new connections again */
Dheeraj Shettycc231012014-07-02 21:27:57 +02004011 if(NULL == sapSocket) {
4012 rilEventAddWakeup(p_info->listen_event);
4013 } else {
4014 rilEventAddWakeup(sapSocket->getListenEvent());
4015 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004016 return;
4017 }
4018
4019 /* check the credential of the other side and only accept socket from
4020 * phone process
4021 */
4022 errno = 0;
4023 is_phone_socket = 0;
4024
Howard Sue32dbfd2015-01-07 15:55:57 +08004025 err = getsockopt(fdCommand, SOL_SOCKET, SO_PEERCRED, &creds, &szCreds);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004026
4027 if (err == 0 && szCreds > 0) {
4028 errno = 0;
4029 pwd = getpwuid(creds.uid);
4030 if (pwd != NULL) {
Dheeraj Shettycc231012014-07-02 21:27:57 +02004031 if (strcmp(pwd->pw_name, processName) == 0) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004032 is_phone_socket = 1;
4033 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004034 RLOGE("RILD can't accept socket from process %s", pwd->pw_name);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004035 }
4036 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004037 RLOGE("Error on getpwuid() errno: %d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004038 }
4039 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004040 RLOGD("Error on getsockopt() errno: %d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004041 }
4042
Howard Subd82ef12015-04-12 10:25:05 +02004043 if (!is_phone_socket) {
Dheeraj Shettycc231012014-07-02 21:27:57 +02004044 RLOGE("RILD must accept socket from %s", processName);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004045
Dheeraj Shettycc231012014-07-02 21:27:57 +02004046 close(fdCommand);
4047 fdCommand = -1;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004048
Dheeraj Shettycc231012014-07-02 21:27:57 +02004049 if(NULL == sapSocket) {
4050 onCommandsSocketClosed(p_info->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004051
Dheeraj Shettycc231012014-07-02 21:27:57 +02004052 /* start listening for new connections again */
4053 rilEventAddWakeup(p_info->listen_event);
4054 } else {
4055 sapSocket->onCommandsSocketClosed();
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004056
Dheeraj Shettycc231012014-07-02 21:27:57 +02004057 /* start listening for new connections again */
4058 rilEventAddWakeup(sapSocket->getListenEvent());
4059 }
4060
4061 return;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004062 }
4063
Howard Sue32dbfd2015-01-07 15:55:57 +08004064 ret = fcntl(fdCommand, F_SETFL, O_NONBLOCK);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004065
4066 if (ret < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004067 RLOGE ("Error setting O_NONBLOCK errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004068 }
4069
Dheeraj Shettycc231012014-07-02 21:27:57 +02004070 if(NULL == sapSocket) {
4071 RLOGI("libril: new connection to %s", rilSocketIdToString(p_info->socket_id));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004072
Dheeraj Shettycc231012014-07-02 21:27:57 +02004073 p_info->fdCommand = fdCommand;
4074 p_rs = record_stream_new(p_info->fdCommand, MAX_COMMAND_BYTES);
4075 p_info->p_rs = p_rs;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004076
Dheeraj Shettycc231012014-07-02 21:27:57 +02004077 ril_event_set (p_info->commands_event, p_info->fdCommand, 1,
Howard Sue32dbfd2015-01-07 15:55:57 +08004078 p_info->processCommandsCallback, p_info);
Dheeraj Shettycc231012014-07-02 21:27:57 +02004079 rilEventAddWakeup (p_info->commands_event);
Howard Sue32dbfd2015-01-07 15:55:57 +08004080
Dheeraj Shettycc231012014-07-02 21:27:57 +02004081 onNewCommandConnect(p_info->socket_id);
4082 } else {
4083 RLOGI("libril: new connection");
Howard Sue32dbfd2015-01-07 15:55:57 +08004084
Dheeraj Shettycc231012014-07-02 21:27:57 +02004085 sapSocket->setCommandFd(fdCommand);
4086 p_rs = record_stream_new(sapSocket->getCommandFd(), MAX_COMMAND_BYTES);
4087 sClient = new socketClient(sapSocket,p_rs);
4088 ril_event_set (sapSocket->getCallbackEvent(), sapSocket->getCommandFd(), 1,
4089 sapSocket->getCommandCb(), sClient);
4090
4091 rilEventAddWakeup(sapSocket->getCallbackEvent());
4092 sapSocket->onNewCommandConnect();
4093 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004094}
4095
4096static void freeDebugCallbackArgs(int number, char **args) {
4097 for (int i = 0; i < number; i++) {
4098 if (args[i] != NULL) {
4099 free(args[i]);
4100 }
4101 }
4102 free(args);
4103}
4104
4105static void debugCallback (int fd, short flags, void *param) {
4106 int acceptFD, option;
4107 struct sockaddr_un peeraddr;
4108 socklen_t socklen = sizeof (peeraddr);
4109 int data;
4110 unsigned int qxdm_data[6];
4111 const char *deactData[1] = {"1"};
4112 char *actData[1];
4113 RIL_Dial dialData;
4114 int hangupData[1] = {1};
4115 int number;
4116 char **args;
Howard Sue32dbfd2015-01-07 15:55:57 +08004117 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
4118 int sim_id = 0;
4119
4120 RLOGI("debugCallback for socket %s", rilSocketIdToString(socket_id));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004121
4122 acceptFD = accept (fd, (sockaddr *) &peeraddr, &socklen);
4123
4124 if (acceptFD < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004125 RLOGE ("error accepting on debug port: %d\n", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004126 return;
4127 }
4128
4129 if (recv(acceptFD, &number, sizeof(int), 0) != sizeof(int)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004130 RLOGE ("error reading on socket: number of Args: \n");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004131 return;
4132 }
4133 args = (char **) malloc(sizeof(char*) * number);
4134
4135 for (int i = 0; i < number; i++) {
4136 int len;
4137 if (recv(acceptFD, &len, sizeof(int), 0) != sizeof(int)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004138 RLOGE ("error reading on socket: Len of Args: \n");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004139 freeDebugCallbackArgs(i, args);
4140 return;
4141 }
4142 // +1 for null-term
4143 args[i] = (char *) malloc((sizeof(char) * len) + 1);
4144 if (recv(acceptFD, args[i], sizeof(char) * len, 0)
4145 != (int)sizeof(char) * len) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004146 RLOGE ("error reading on socket: Args[%d] \n", i);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004147 freeDebugCallbackArgs(i, args);
4148 return;
4149 }
4150 char * buf = args[i];
4151 buf[len] = 0;
Howard Sue32dbfd2015-01-07 15:55:57 +08004152 if ((i+1) == number) {
4153 /* The last argument should be sim id 0(SIM1)~3(SIM4) */
4154 sim_id = atoi(args[i]);
4155 switch (sim_id) {
4156 case 0:
4157 socket_id = RIL_SOCKET_1;
4158 break;
4159 #if (SIM_COUNT >= 2)
4160 case 1:
4161 socket_id = RIL_SOCKET_2;
4162 break;
4163 #endif
4164 #if (SIM_COUNT >= 3)
4165 case 2:
4166 socket_id = RIL_SOCKET_3;
4167 break;
4168 #endif
4169 #if (SIM_COUNT >= 4)
4170 case 3:
4171 socket_id = RIL_SOCKET_4;
4172 break;
4173 #endif
4174 default:
4175 socket_id = RIL_SOCKET_1;
4176 break;
4177 }
4178 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004179 }
4180
4181 switch (atoi(args[0])) {
4182 case 0:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004183 RLOGI ("Connection on debug port: issuing reset.");
Howard Sue32dbfd2015-01-07 15:55:57 +08004184 issueLocalRequest(RIL_REQUEST_RESET_RADIO, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004185 break;
4186 case 1:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004187 RLOGI ("Connection on debug port: issuing radio power off.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004188 data = 0;
Howard Sue32dbfd2015-01-07 15:55:57 +08004189 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004190 // Close the socket
Howard Subd82ef12015-04-12 10:25:05 +02004191 if (socket_id == RIL_SOCKET_1 && s_ril_param_socket.fdCommand > 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08004192 close(s_ril_param_socket.fdCommand);
4193 s_ril_param_socket.fdCommand = -1;
4194 }
4195 #if (SIM_COUNT == 2)
4196 else if (socket_id == RIL_SOCKET_2 && s_ril_param_socket2.fdCommand > 0) {
4197 close(s_ril_param_socket2.fdCommand);
4198 s_ril_param_socket2.fdCommand = -1;
4199 }
4200 #endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004201 break;
4202 case 2:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004203 RLOGI ("Debug port: issuing unsolicited voice network change.");
Howard Sue32dbfd2015-01-07 15:55:57 +08004204 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004205 break;
4206 case 3:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004207 RLOGI ("Debug port: QXDM log enable.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004208 qxdm_data[0] = 65536; // head.func_tag
4209 qxdm_data[1] = 16; // head.len
4210 qxdm_data[2] = 1; // mode: 1 for 'start logging'
4211 qxdm_data[3] = 32; // log_file_size: 32megabytes
4212 qxdm_data[4] = 0; // log_mask
4213 qxdm_data[5] = 8; // log_max_fileindex
4214 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Howard Sue32dbfd2015-01-07 15:55:57 +08004215 6 * sizeof(int), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004216 break;
4217 case 4:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004218 RLOGI ("Debug port: QXDM log disable.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004219 qxdm_data[0] = 65536;
4220 qxdm_data[1] = 16;
4221 qxdm_data[2] = 0; // mode: 0 for 'stop logging'
4222 qxdm_data[3] = 32;
4223 qxdm_data[4] = 0;
4224 qxdm_data[5] = 8;
4225 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Howard Sue32dbfd2015-01-07 15:55:57 +08004226 6 * sizeof(int), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004227 break;
4228 case 5:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004229 RLOGI("Debug port: Radio On");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004230 data = 1;
Howard Sue32dbfd2015-01-07 15:55:57 +08004231 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004232 sleep(2);
4233 // Set network selection automatic.
Howard Sue32dbfd2015-01-07 15:55:57 +08004234 issueLocalRequest(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004235 break;
4236 case 6:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004237 RLOGI("Debug port: Setup Data Call, Apn :%s\n", args[1]);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004238 actData[0] = args[1];
4239 issueLocalRequest(RIL_REQUEST_SETUP_DATA_CALL, &actData,
Howard Sue32dbfd2015-01-07 15:55:57 +08004240 sizeof(actData), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004241 break;
4242 case 7:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004243 RLOGI("Debug port: Deactivate Data Call");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004244 issueLocalRequest(RIL_REQUEST_DEACTIVATE_DATA_CALL, &deactData,
Howard Sue32dbfd2015-01-07 15:55:57 +08004245 sizeof(deactData), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004246 break;
4247 case 8:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004248 RLOGI("Debug port: Dial Call");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004249 dialData.clir = 0;
4250 dialData.address = args[1];
Howard Sue32dbfd2015-01-07 15:55:57 +08004251 issueLocalRequest(RIL_REQUEST_DIAL, &dialData, sizeof(dialData), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004252 break;
4253 case 9:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004254 RLOGI("Debug port: Answer Call");
Howard Sue32dbfd2015-01-07 15:55:57 +08004255 issueLocalRequest(RIL_REQUEST_ANSWER, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004256 break;
4257 case 10:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004258 RLOGI("Debug port: End Call");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004259 issueLocalRequest(RIL_REQUEST_HANGUP, &hangupData,
Howard Sue32dbfd2015-01-07 15:55:57 +08004260 sizeof(hangupData), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004261 break;
4262 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004263 RLOGE ("Invalid request");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004264 break;
4265 }
4266 freeDebugCallbackArgs(number, args);
4267 close(acceptFD);
4268}
4269
4270
4271static void userTimerCallback (int fd, short flags, void *param) {
4272 UserCallbackInfo *p_info;
4273
4274 p_info = (UserCallbackInfo *)param;
4275
4276 p_info->p_callback(p_info->userParam);
4277
4278
4279 // FIXME generalize this...there should be a cancel mechanism
4280 if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) {
4281 s_last_wake_timeout_info = NULL;
4282 }
4283
4284 free(p_info);
4285}
4286
4287
4288static void *
4289eventLoop(void *param) {
4290 int ret;
4291 int filedes[2];
4292
4293 ril_event_init();
4294
4295 pthread_mutex_lock(&s_startupMutex);
4296
4297 s_started = 1;
4298 pthread_cond_broadcast(&s_startupCond);
4299
4300 pthread_mutex_unlock(&s_startupMutex);
4301
4302 ret = pipe(filedes);
4303
4304 if (ret < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004305 RLOGE("Error in pipe() errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004306 return NULL;
4307 }
4308
4309 s_fdWakeupRead = filedes[0];
4310 s_fdWakeupWrite = filedes[1];
4311
4312 fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK);
4313
4314 ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,
4315 processWakeupCallback, NULL);
4316
4317 rilEventAddWakeup (&s_wakeupfd_event);
4318
4319 // Only returns on error
4320 ril_event_loop();
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004321 RLOGE ("error in event_loop_base errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004322 // kill self to restart on error
4323 kill(0, SIGKILL);
4324
4325 return NULL;
4326}
4327
4328extern "C" void
4329RIL_startEventLoop(void) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004330 /* spin up eventLoop thread and wait for it to get started */
4331 s_started = 0;
4332 pthread_mutex_lock(&s_startupMutex);
4333
Howard Sue32dbfd2015-01-07 15:55:57 +08004334 pthread_attr_t attr;
4335 pthread_attr_init(&attr);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004336 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
Howard Sue32dbfd2015-01-07 15:55:57 +08004337
4338 int result = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
4339 if (result != 0) {
4340 RLOGE("Failed to create dispatch thread: %s", strerror(result));
4341 goto done;
4342 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004343
4344 while (s_started == 0) {
4345 pthread_cond_wait(&s_startupCond, &s_startupMutex);
4346 }
4347
Howard Sue32dbfd2015-01-07 15:55:57 +08004348done:
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004349 pthread_mutex_unlock(&s_startupMutex);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004350}
4351
4352// Used for testing purpose only.
4353extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) {
4354 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4355}
4356
Howard Sue32dbfd2015-01-07 15:55:57 +08004357static void startListen(RIL_SOCKET_ID socket_id, SocketListenParam* socket_listen_p) {
4358 int fdListen = -1;
4359 int ret;
4360 char socket_name[10];
4361
4362 memset(socket_name, 0, sizeof(char)*10);
4363
4364 switch(socket_id) {
4365 case RIL_SOCKET_1:
4366 strncpy(socket_name, RIL_getRilSocketName(), 9);
4367 break;
4368 #if (SIM_COUNT >= 2)
4369 case RIL_SOCKET_2:
4370 strncpy(socket_name, SOCKET2_NAME_RIL, 9);
4371 break;
4372 #endif
4373 #if (SIM_COUNT >= 3)
4374 case RIL_SOCKET_3:
4375 strncpy(socket_name, SOCKET3_NAME_RIL, 9);
4376 break;
4377 #endif
4378 #if (SIM_COUNT >= 4)
4379 case RIL_SOCKET_4:
4380 strncpy(socket_name, SOCKET4_NAME_RIL, 9);
4381 break;
4382 #endif
4383 default:
4384 RLOGE("Socket id is wrong!!");
4385 return;
4386 }
4387
4388 RLOGI("Start to listen %s", rilSocketIdToString(socket_id));
4389
4390 fdListen = android_get_control_socket(socket_name);
4391 if (fdListen < 0) {
4392 RLOGE("Failed to get socket %s", socket_name);
4393 exit(-1);
4394 }
4395
4396 ret = listen(fdListen, 4);
4397
4398 if (ret < 0) {
4399 RLOGE("Failed to listen on control socket '%d': %s",
4400 fdListen, strerror(errno));
4401 exit(-1);
4402 }
4403 socket_listen_p->fdListen = fdListen;
4404
4405 /* note: non-persistent so we can accept only one connection at a time */
4406 ril_event_set (socket_listen_p->listen_event, fdListen, false,
4407 listenCallback, socket_listen_p);
4408
4409 rilEventAddWakeup (socket_listen_p->listen_event);
4410}
4411
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004412extern "C" void
4413RIL_register (const RIL_RadioFunctions *callbacks) {
4414 int ret;
4415 int flags;
4416
Howard Sue32dbfd2015-01-07 15:55:57 +08004417 RLOGI("SIM_COUNT: %d", SIM_COUNT);
4418
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004419 if (callbacks == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004420 RLOGE("RIL_register: RIL_RadioFunctions * null");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004421 return;
4422 }
4423 if (callbacks->version < RIL_VERSION_MIN) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004424 RLOGE("RIL_register: version %d is to old, min version is %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004425 callbacks->version, RIL_VERSION_MIN);
4426 return;
4427 }
4428 if (callbacks->version > RIL_VERSION) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004429 RLOGE("RIL_register: version %d is too new, max version is %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004430 callbacks->version, RIL_VERSION);
4431 return;
4432 }
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004433 RLOGE("RIL_register: RIL version %d", callbacks->version);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004434
4435 if (s_registerCalled > 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004436 RLOGE("RIL_register has been called more than once. "
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004437 "Subsequent call ignored");
4438 return;
4439 }
4440
4441 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4442
Howard Sue32dbfd2015-01-07 15:55:57 +08004443 /* Initialize socket1 parameters */
4444 s_ril_param_socket = {
4445 RIL_SOCKET_1, /* socket_id */
4446 -1, /* fdListen */
4447 -1, /* fdCommand */
4448 PHONE_PROCESS, /* processName */
4449 &s_commands_event, /* commands_event */
4450 &s_listen_event, /* listen_event */
4451 processCommandsCallback, /* processCommandsCallback */
4452 NULL /* p_rs */
4453 };
4454
4455#if (SIM_COUNT >= 2)
4456 s_ril_param_socket2 = {
4457 RIL_SOCKET_2, /* socket_id */
4458 -1, /* fdListen */
4459 -1, /* fdCommand */
4460 PHONE_PROCESS, /* processName */
4461 &s_commands_event_socket2, /* commands_event */
4462 &s_listen_event_socket2, /* listen_event */
4463 processCommandsCallback, /* processCommandsCallback */
4464 NULL /* p_rs */
4465 };
4466#endif
4467
4468#if (SIM_COUNT >= 3)
4469 s_ril_param_socket3 = {
4470 RIL_SOCKET_3, /* socket_id */
4471 -1, /* fdListen */
4472 -1, /* fdCommand */
4473 PHONE_PROCESS, /* processName */
4474 &s_commands_event_socket3, /* commands_event */
4475 &s_listen_event_socket3, /* listen_event */
4476 processCommandsCallback, /* processCommandsCallback */
4477 NULL /* p_rs */
4478 };
4479#endif
4480
4481#if (SIM_COUNT >= 4)
4482 s_ril_param_socket4 = {
4483 RIL_SOCKET_4, /* socket_id */
4484 -1, /* fdListen */
4485 -1, /* fdCommand */
4486 PHONE_PROCESS, /* processName */
4487 &s_commands_event_socket4, /* commands_event */
4488 &s_listen_event_socket4, /* listen_event */
4489 processCommandsCallback, /* processCommandsCallback */
4490 NULL /* p_rs */
4491 };
4492#endif
4493
Howard Subd82ef12015-04-12 10:25:05 +02004494
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004495 s_registerCalled = 1;
4496
Howard Sue32dbfd2015-01-07 15:55:57 +08004497 RLOGI("s_registerCalled flag set, %d", s_started);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004498 // Little self-check
4499
4500 for (int i = 0; i < (int)NUM_ELEMS(s_commands); i++) {
4501 assert(i == s_commands[i].requestNumber);
4502 }
4503
Howard Subd82ef12015-04-12 10:25:05 +02004504 for (int i = 0; i < (int)NUM_ELEMS(s_commands_v); i++) {
4505 assert(i + RIL_VENDOR_COMMANDS_OFFSET == s_commands[i].requestNumber);
4506 }
4507
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004508 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses); i++) {
Howard Sue32dbfd2015-01-07 15:55:57 +08004509 assert(i + RIL_UNSOL_RESPONSE_BASE
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004510 == s_unsolResponses[i].requestNumber);
4511 }
4512
Howard Subd82ef12015-04-12 10:25:05 +02004513 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses_v); i++) {
4514 assert(i + RIL_UNSOL_RESPONSE_BASE + RIL_VENDOR_COMMANDS_OFFSET
4515 == s_unsolResponses[i].requestNumber);
4516 }
4517
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004518 // New rild impl calls RIL_startEventLoop() first
4519 // old standalone impl wants it here.
4520
4521 if (s_started == 0) {
4522 RIL_startEventLoop();
4523 }
4524
Howard Sue32dbfd2015-01-07 15:55:57 +08004525 // start listen socket1
4526 startListen(RIL_SOCKET_1, &s_ril_param_socket);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004527
Howard Sue32dbfd2015-01-07 15:55:57 +08004528#if (SIM_COUNT >= 2)
4529 // start listen socket2
4530 startListen(RIL_SOCKET_2, &s_ril_param_socket2);
4531#endif /* (SIM_COUNT == 2) */
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004532
Howard Sue32dbfd2015-01-07 15:55:57 +08004533#if (SIM_COUNT >= 3)
4534 // start listen socket3
4535 startListen(RIL_SOCKET_3, &s_ril_param_socket3);
4536#endif /* (SIM_COUNT == 3) */
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004537
Howard Sue32dbfd2015-01-07 15:55:57 +08004538#if (SIM_COUNT >= 4)
4539 // start listen socket4
4540 startListen(RIL_SOCKET_4, &s_ril_param_socket4);
4541#endif /* (SIM_COUNT == 4) */
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004542
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004543
4544#if 1
4545 // start debug interface socket
4546
Howard Sue32dbfd2015-01-07 15:55:57 +08004547 char *inst = NULL;
4548 if (strlen(RIL_getRilSocketName()) >= strlen(SOCKET_NAME_RIL)) {
4549 inst = RIL_getRilSocketName() + strlen(SOCKET_NAME_RIL);
4550 }
4551
4552 char rildebug[MAX_DEBUG_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL_DEBUG;
4553 if (inst != NULL) {
Andreas Schneider3063dc12015-04-13 23:04:05 +02004554 snprintf(rildebug, sizeof(rildebug), "%s%s", SOCKET_NAME_RIL_DEBUG, inst);
Howard Sue32dbfd2015-01-07 15:55:57 +08004555 }
4556
4557 s_fdDebug = android_get_control_socket(rildebug);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004558 if (s_fdDebug < 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08004559 RLOGE("Failed to get socket : %s errno:%d", rildebug, errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004560 exit(-1);
4561 }
4562
4563 ret = listen(s_fdDebug, 4);
4564
4565 if (ret < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004566 RLOGE("Failed to listen on ril debug socket '%d': %s",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004567 s_fdDebug, strerror(errno));
4568 exit(-1);
4569 }
4570
4571 ril_event_set (&s_debug_event, s_fdDebug, true,
4572 debugCallback, NULL);
4573
4574 rilEventAddWakeup (&s_debug_event);
4575#endif
4576
4577}
4578
Dheeraj Shettycc231012014-07-02 21:27:57 +02004579extern "C" void
4580RIL_register_socket (RIL_RadioFunctions *(*Init)(const struct RIL_Env *, int, char **),RIL_SOCKET_TYPE socketType, int argc, char **argv) {
4581
4582 RIL_RadioFunctions* UimFuncs = NULL;
4583
4584 if(Init) {
4585 UimFuncs = Init(&RilSapSocket::uimRilEnv, argc, argv);
4586
4587 switch(socketType) {
4588 case RIL_SAP_SOCKET:
4589 RilSapSocket::initSapSocket("sap_uim_socket1", UimFuncs);
4590
4591#if (SIM_COUNT >= 2)
4592 RilSapSocket::initSapSocket("sap_uim_socket2", UimFuncs);
4593#endif
4594
4595#if (SIM_COUNT >= 3)
4596 RilSapSocket::initSapSocket("sap_uim_socket3", UimFuncs);
4597#endif
4598
4599#if (SIM_COUNT >= 4)
4600 RilSapSocket::initSapSocket("sap_uim_socket4", UimFuncs);
4601#endif
4602 }
4603 }
4604}
4605
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004606static int
4607checkAndDequeueRequestInfo(struct RequestInfo *pRI) {
4608 int ret = 0;
Howard Sue32dbfd2015-01-07 15:55:57 +08004609 /* Hook for current context
4610 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
4611 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
4612 /* pendingRequestsHook refer to &s_pendingRequests */
4613 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004614
4615 if (pRI == NULL) {
4616 return 0;
4617 }
4618
Howard Sue32dbfd2015-01-07 15:55:57 +08004619#if (SIM_COUNT >= 2)
4620 if (pRI->socket_id == RIL_SOCKET_2) {
4621 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
4622 pendingRequestsHook = &s_pendingRequests_socket2;
4623 }
4624#if (SIM_COUNT >= 3)
4625 if (pRI->socket_id == RIL_SOCKET_3) {
4626 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
4627 pendingRequestsHook = &s_pendingRequests_socket3;
4628 }
4629#endif
4630#if (SIM_COUNT >= 4)
4631 if (pRI->socket_id == RIL_SOCKET_4) {
4632 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
4633 pendingRequestsHook = &s_pendingRequests_socket4;
4634 }
4635#endif
4636#endif
4637 pthread_mutex_lock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004638
Howard Sue32dbfd2015-01-07 15:55:57 +08004639 for(RequestInfo **ppCur = pendingRequestsHook
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004640 ; *ppCur != NULL
4641 ; ppCur = &((*ppCur)->p_next)
4642 ) {
4643 if (pRI == *ppCur) {
4644 ret = 1;
4645
4646 *ppCur = (*ppCur)->p_next;
4647 break;
4648 }
4649 }
4650
Howard Sue32dbfd2015-01-07 15:55:57 +08004651 pthread_mutex_unlock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004652
4653 return ret;
4654}
4655
4656
4657extern "C" void
4658RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) {
4659 RequestInfo *pRI;
4660 int ret;
Howard Sue32dbfd2015-01-07 15:55:57 +08004661 int fd = s_ril_param_socket.fdCommand;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004662 size_t errorOffset;
Howard Sue32dbfd2015-01-07 15:55:57 +08004663 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004664
4665 pRI = (RequestInfo *)t;
4666
4667 if (!checkAndDequeueRequestInfo(pRI)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004668 RLOGE ("RIL_onRequestComplete: invalid RIL_Token");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004669 return;
4670 }
4671
Howard Sue32dbfd2015-01-07 15:55:57 +08004672 socket_id = pRI->socket_id;
4673#if (SIM_COUNT >= 2)
4674 if (socket_id == RIL_SOCKET_2) {
4675 fd = s_ril_param_socket2.fdCommand;
4676 }
4677#if (SIM_COUNT >= 3)
4678 if (socket_id == RIL_SOCKET_3) {
4679 fd = s_ril_param_socket3.fdCommand;
4680 }
4681#endif
4682#if (SIM_COUNT >= 4)
4683 if (socket_id == RIL_SOCKET_4) {
4684 fd = s_ril_param_socket4.fdCommand;
4685 }
4686#endif
4687#endif
Robert Greenwaltbc29c432015-04-29 16:57:39 -07004688#if VDBG
Howard Sue32dbfd2015-01-07 15:55:57 +08004689 RLOGD("RequestComplete, %s", rilSocketIdToString(socket_id));
Robert Greenwaltbc29c432015-04-29 16:57:39 -07004690#endif
Howard Sue32dbfd2015-01-07 15:55:57 +08004691
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004692 if (pRI->local > 0) {
4693 // Locally issued command...void only!
4694 // response does not go back up the command socket
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004695 RLOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004696
4697 goto done;
4698 }
4699
4700 appendPrintBuf("[%04d]< %s",
4701 pRI->token, requestToString(pRI->pCI->requestNumber));
4702
4703 if (pRI->cancelled == 0) {
4704 Parcel p;
4705
4706 p.writeInt32 (RESPONSE_SOLICITED);
4707 p.writeInt32 (pRI->token);
4708 errorOffset = p.dataPosition();
4709
4710 p.writeInt32 (e);
4711
4712 if (response != NULL) {
4713 // there is a response payload, no matter success or not.
4714 ret = pRI->pCI->responseFunction(p, response, responselen);
4715
4716 /* if an error occurred, rewind and mark it */
4717 if (ret != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08004718 RLOGE ("responseFunction error, ret %d", ret);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004719 p.setDataPosition(errorOffset);
4720 p.writeInt32 (ret);
4721 }
4722 }
4723
4724 if (e != RIL_E_SUCCESS) {
4725 appendPrintBuf("%s fails by %s", printBuf, failCauseToString(e));
4726 }
4727
Howard Sue32dbfd2015-01-07 15:55:57 +08004728 if (fd < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004729 RLOGD ("RIL onRequestComplete: Command channel closed");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004730 }
Howard Sue32dbfd2015-01-07 15:55:57 +08004731 sendResponse(p, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004732 }
4733
4734done:
4735 free(pRI);
4736}
4737
Howard Subd82ef12015-04-12 10:25:05 +02004738
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004739static void
4740grabPartialWakeLock() {
4741 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
4742}
4743
4744static void
4745releaseWakeLock() {
4746 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
4747}
4748
4749/**
4750 * Timer callback to put us back to sleep before the default timeout
4751 */
4752static void
4753wakeTimeoutCallback (void *param) {
4754 // We're using "param != NULL" as a cancellation mechanism
4755 if (param == NULL) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004756 releaseWakeLock();
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004757 }
4758}
4759
4760static int
4761decodeVoiceRadioTechnology (RIL_RadioState radioState) {
4762 switch (radioState) {
4763 case RADIO_STATE_SIM_NOT_READY:
4764 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4765 case RADIO_STATE_SIM_READY:
4766 return RADIO_TECH_UMTS;
4767
4768 case RADIO_STATE_RUIM_NOT_READY:
4769 case RADIO_STATE_RUIM_READY:
4770 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4771 case RADIO_STATE_NV_NOT_READY:
4772 case RADIO_STATE_NV_READY:
4773 return RADIO_TECH_1xRTT;
4774
4775 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004776 RLOGD("decodeVoiceRadioTechnology: Invoked with incorrect RadioState");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004777 return -1;
4778 }
4779}
4780
4781static int
4782decodeCdmaSubscriptionSource (RIL_RadioState radioState) {
4783 switch (radioState) {
4784 case RADIO_STATE_SIM_NOT_READY:
4785 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4786 case RADIO_STATE_SIM_READY:
4787 case RADIO_STATE_RUIM_NOT_READY:
4788 case RADIO_STATE_RUIM_READY:
4789 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4790 return CDMA_SUBSCRIPTION_SOURCE_RUIM_SIM;
4791
4792 case RADIO_STATE_NV_NOT_READY:
4793 case RADIO_STATE_NV_READY:
4794 return CDMA_SUBSCRIPTION_SOURCE_NV;
4795
4796 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004797 RLOGD("decodeCdmaSubscriptionSource: Invoked with incorrect RadioState");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004798 return -1;
4799 }
4800}
4801
4802static int
4803decodeSimStatus (RIL_RadioState radioState) {
4804 switch (radioState) {
4805 case RADIO_STATE_SIM_NOT_READY:
4806 case RADIO_STATE_RUIM_NOT_READY:
4807 case RADIO_STATE_NV_NOT_READY:
4808 case RADIO_STATE_NV_READY:
4809 return -1;
4810 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4811 case RADIO_STATE_SIM_READY:
4812 case RADIO_STATE_RUIM_READY:
4813 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4814 return radioState;
4815 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004816 RLOGD("decodeSimStatus: Invoked with incorrect RadioState");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004817 return -1;
4818 }
4819}
4820
4821static bool is3gpp2(int radioTech) {
4822 switch (radioTech) {
4823 case RADIO_TECH_IS95A:
4824 case RADIO_TECH_IS95B:
4825 case RADIO_TECH_1xRTT:
4826 case RADIO_TECH_EVDO_0:
4827 case RADIO_TECH_EVDO_A:
4828 case RADIO_TECH_EVDO_B:
4829 case RADIO_TECH_EHRPD:
4830 return true;
4831 default:
4832 return false;
4833 }
4834}
4835
4836/* If RIL sends SIM states or RUIM states, store the voice radio
4837 * technology and subscription source information so that they can be
4838 * returned when telephony framework requests them
4839 */
4840static RIL_RadioState
Howard Subd82ef12015-04-12 10:25:05 +02004841processRadioState(RIL_RadioState newRadioState, RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004842
4843 if((newRadioState > RADIO_STATE_UNAVAILABLE) && (newRadioState < RADIO_STATE_ON)) {
4844 int newVoiceRadioTech;
4845 int newCdmaSubscriptionSource;
4846 int newSimStatus;
4847
4848 /* This is old RIL. Decode Subscription source and Voice Radio Technology
4849 from Radio State and send change notifications if there has been a change */
4850 newVoiceRadioTech = decodeVoiceRadioTechnology(newRadioState);
4851 if(newVoiceRadioTech != voiceRadioTech) {
4852 voiceRadioTech = newVoiceRadioTech;
Howard Sue32dbfd2015-01-07 15:55:57 +08004853 RIL_UNSOL_RESPONSE(RIL_UNSOL_VOICE_RADIO_TECH_CHANGED,
4854 &voiceRadioTech, sizeof(voiceRadioTech), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004855 }
4856 if(is3gpp2(newVoiceRadioTech)) {
4857 newCdmaSubscriptionSource = decodeCdmaSubscriptionSource(newRadioState);
4858 if(newCdmaSubscriptionSource != cdmaSubscriptionSource) {
4859 cdmaSubscriptionSource = newCdmaSubscriptionSource;
Howard Sue32dbfd2015-01-07 15:55:57 +08004860 RIL_UNSOL_RESPONSE(RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED,
4861 &cdmaSubscriptionSource, sizeof(cdmaSubscriptionSource), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004862 }
4863 }
4864 newSimStatus = decodeSimStatus(newRadioState);
4865 if(newSimStatus != simRuimStatus) {
4866 simRuimStatus = newSimStatus;
Howard Sue32dbfd2015-01-07 15:55:57 +08004867 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004868 }
4869
4870 /* Send RADIO_ON to telephony */
4871 newRadioState = RADIO_STATE_ON;
4872 }
4873
4874 return newRadioState;
4875}
4876
Howard Subd82ef12015-04-12 10:25:05 +02004877
Howard Sue32dbfd2015-01-07 15:55:57 +08004878#if defined(ANDROID_MULTI_SIM)
4879extern "C"
Andreas Schneider47b2d962015-04-13 22:54:49 +02004880void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Howard Sue32dbfd2015-01-07 15:55:57 +08004881 size_t datalen, RIL_SOCKET_ID socket_id)
4882#else
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004883extern "C"
Andreas Schneider47b2d962015-04-13 22:54:49 +02004884void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004885 size_t datalen)
Howard Sue32dbfd2015-01-07 15:55:57 +08004886#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004887{
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004888 int ret;
4889 int64_t timeReceived = 0;
4890 bool shouldScheduleTimeout = false;
4891 RIL_RadioState newState;
Howard Sue32dbfd2015-01-07 15:55:57 +08004892 RIL_SOCKET_ID soc_id = RIL_SOCKET_1;
Howard Subd82ef12015-04-12 10:25:05 +02004893 UnsolResponseInfo *pRI = NULL;
Howard Sue32dbfd2015-01-07 15:55:57 +08004894
4895#if defined(ANDROID_MULTI_SIM)
4896 soc_id = socket_id;
4897#endif
4898
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004899
4900 if (s_registerCalled == 0) {
4901 // Ignore RIL_onUnsolicitedResponse before RIL_register
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004902 RLOGW("RIL_onUnsolicitedResponse called before RIL_register");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004903 return;
4904 }
Howard Sue32dbfd2015-01-07 15:55:57 +08004905
Howard Subd82ef12015-04-12 10:25:05 +02004906 /* Hack to include Samsung responses */
4907 if (unsolResponse > RIL_VENDOR_COMMANDS_OFFSET + RIL_UNSOL_RESPONSE_BASE) {
4908 int index = unsolResponse - RIL_VENDOR_COMMANDS_OFFSET - RIL_UNSOL_RESPONSE_BASE;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004909
Howard Subd82ef12015-04-12 10:25:05 +02004910 RLOGD("SAMSUNG: unsolResponse=%d, unsolResponseIndex=%d", unsolResponse, index);
4911
4912 if (index < (int32_t)NUM_ELEMS(s_unsolResponses_v))
4913 pRI = &s_unsolResponses_v[index];
4914 } else {
4915 int index = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
4916 if (index < (int32_t)NUM_ELEMS(s_unsolResponses))
4917 pRI = &s_unsolResponses[index];
4918 }
4919
4920 if (pRI == NULL || pRI->responseFunction == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004921 RLOGE("unsupported unsolicited response code %d", unsolResponse);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004922 return;
4923 }
4924
4925 // Grab a wake lock if needed for this reponse,
4926 // as we exit we'll either release it immediately
4927 // or set a timer to release it later.
Howard Subd82ef12015-04-12 10:25:05 +02004928 switch (pRI->wakeType) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004929 case WAKE_PARTIAL:
4930 grabPartialWakeLock();
4931 shouldScheduleTimeout = true;
4932 break;
4933
4934 case DONT_WAKE:
4935 default:
4936 // No wake lock is grabed so don't set timeout
4937 shouldScheduleTimeout = false;
4938 break;
4939 }
4940
4941 // Mark the time this was received, doing this
4942 // after grabing the wakelock incase getting
4943 // the elapsedRealTime might cause us to goto
4944 // sleep.
4945 if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4946 timeReceived = elapsedRealtime();
4947 }
4948
4949 appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
4950
4951 Parcel p;
4952
4953 p.writeInt32 (RESPONSE_UNSOLICITED);
4954 p.writeInt32 (unsolResponse);
4955
Howard Subd82ef12015-04-12 10:25:05 +02004956 ret = pRI->responseFunction(p, const_cast<void*>(data), datalen);
4957
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004958 if (ret != 0) {
4959 // Problem with the response. Don't continue;
4960 goto error_exit;
4961 }
4962
4963 // some things get more payload
4964 switch(unsolResponse) {
4965 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
Howard Sue32dbfd2015-01-07 15:55:57 +08004966 newState = processRadioState(CALL_ONSTATEREQUEST(soc_id), soc_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004967 p.writeInt32(newState);
4968 appendPrintBuf("%s {%s}", printBuf,
Howard Sue32dbfd2015-01-07 15:55:57 +08004969 radioStateToString(CALL_ONSTATEREQUEST(soc_id)));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004970 break;
4971
4972
4973 case RIL_UNSOL_NITZ_TIME_RECEIVED:
4974 // Store the time that this was received so the
4975 // handler of this message can account for
4976 // the time it takes to arrive and process. In
4977 // particular the system has been known to sleep
4978 // before this message can be processed.
4979 p.writeInt64(timeReceived);
4980 break;
4981 }
4982
Robert Greenwaltbc29c432015-04-29 16:57:39 -07004983#if VDBG
Howard Sue32dbfd2015-01-07 15:55:57 +08004984 RLOGI("%s UNSOLICITED: %s length:%d", rilSocketIdToString(soc_id), requestToString(unsolResponse), p.dataSize());
Robert Greenwaltbc29c432015-04-29 16:57:39 -07004985#endif
Howard Sue32dbfd2015-01-07 15:55:57 +08004986 ret = sendResponse(p, soc_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004987 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4988
4989 // Unfortunately, NITZ time is not poll/update like everything
4990 // else in the system. So, if the upstream client isn't connected,
4991 // keep a copy of the last NITZ response (with receive time noted
4992 // above) around so we can deliver it when it is connected
4993
4994 if (s_lastNITZTimeData != NULL) {
4995 free (s_lastNITZTimeData);
4996 s_lastNITZTimeData = NULL;
4997 }
4998
4999 s_lastNITZTimeData = malloc(p.dataSize());
5000 s_lastNITZTimeDataSize = p.dataSize();
5001 memcpy(s_lastNITZTimeData, p.data(), p.dataSize());
5002 }
5003
5004 // For now, we automatically go back to sleep after TIMEVAL_WAKE_TIMEOUT
5005 // FIXME The java code should handshake here to release wake lock
5006
5007 if (shouldScheduleTimeout) {
5008 // Cancel the previous request
5009 if (s_last_wake_timeout_info != NULL) {
5010 s_last_wake_timeout_info->userParam = (void *)1;
5011 }
5012
5013 s_last_wake_timeout_info
5014 = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
5015 &TIMEVAL_WAKE_TIMEOUT);
5016 }
5017
5018 // Normal exit
5019 return;
5020
5021error_exit:
5022 if (shouldScheduleTimeout) {
5023 releaseWakeLock();
5024 }
5025}
5026
5027/** FIXME generalize this if you track UserCAllbackInfo, clear it
5028 when the callback occurs
5029*/
5030static UserCallbackInfo *
5031internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
5032 const struct timeval *relativeTime)
5033{
5034 struct timeval myRelativeTime;
5035 UserCallbackInfo *p_info;
5036
5037 p_info = (UserCallbackInfo *) malloc (sizeof(UserCallbackInfo));
5038
5039 p_info->p_callback = callback;
5040 p_info->userParam = param;
5041
5042 if (relativeTime == NULL) {
5043 /* treat null parameter as a 0 relative time */
5044 memset (&myRelativeTime, 0, sizeof(myRelativeTime));
5045 } else {
5046 /* FIXME I think event_add's tv param is really const anyway */
5047 memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
5048 }
5049
5050 ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
5051
5052 ril_timer_add(&(p_info->event), &myRelativeTime);
5053
5054 triggerEvLoop();
5055 return p_info;
5056}
5057
5058
5059extern "C" void
5060RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
5061 const struct timeval *relativeTime) {
5062 internalRequestTimedCallback (callback, param, relativeTime);
5063}
5064
5065const char *
5066failCauseToString(RIL_Errno e) {
5067 switch(e) {
5068 case RIL_E_SUCCESS: return "E_SUCCESS";
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005069 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RADIO_NOT_AVAILABLE";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005070 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
5071 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
5072 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
5073 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
5074 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
5075 case RIL_E_CANCELLED: return "E_CANCELLED";
5076 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
5077 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
5078 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
5079 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
5080 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
5081#ifdef FEATURE_MULTIMODE_ANDROID
5082 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
5083 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
5084#endif
5085 default: return "<unknown error>";
5086 }
5087}
5088
5089const char *
5090radioStateToString(RIL_RadioState s) {
5091 switch(s) {
5092 case RADIO_STATE_OFF: return "RADIO_OFF";
5093 case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
5094 case RADIO_STATE_SIM_NOT_READY: return "RADIO_SIM_NOT_READY";
5095 case RADIO_STATE_SIM_LOCKED_OR_ABSENT: return "RADIO_SIM_LOCKED_OR_ABSENT";
5096 case RADIO_STATE_SIM_READY: return "RADIO_SIM_READY";
5097 case RADIO_STATE_RUIM_NOT_READY:return"RADIO_RUIM_NOT_READY";
5098 case RADIO_STATE_RUIM_READY:return"RADIO_RUIM_READY";
5099 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:return"RADIO_RUIM_LOCKED_OR_ABSENT";
5100 case RADIO_STATE_NV_NOT_READY:return"RADIO_NV_NOT_READY";
5101 case RADIO_STATE_NV_READY:return"RADIO_NV_READY";
5102 case RADIO_STATE_ON:return"RADIO_ON";
5103 default: return "<unknown state>";
5104 }
5105}
5106
5107const char *
5108callStateToString(RIL_CallState s) {
5109 switch(s) {
5110 case RIL_CALL_ACTIVE : return "ACTIVE";
5111 case RIL_CALL_HOLDING: return "HOLDING";
5112 case RIL_CALL_DIALING: return "DIALING";
5113 case RIL_CALL_ALERTING: return "ALERTING";
5114 case RIL_CALL_INCOMING: return "INCOMING";
5115 case RIL_CALL_WAITING: return "WAITING";
5116 default: return "<unknown state>";
5117 }
5118}
5119
5120const char *
5121requestToString(int request) {
5122/*
5123 cat libs/telephony/ril_commands.h \
5124 | egrep "^ *{RIL_" \
5125 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
5126
5127
5128 cat libs/telephony/ril_unsol_commands.h \
5129 | egrep "^ *{RIL_" \
5130 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
5131
5132*/
5133 switch(request) {
5134 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
5135 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
5136 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
5137 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
5138 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
5139 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
5140 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
5141 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
5142 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
5143 case RIL_REQUEST_DIAL: return "DIAL";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005144 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
5145 case RIL_REQUEST_HANGUP: return "HANGUP";
5146 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
5147 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
5148 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
5149 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
5150 case RIL_REQUEST_UDUB: return "UDUB";
5151 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
5152 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
5153 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
5154 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
5155 case RIL_REQUEST_OPERATOR: return "OPERATOR";
5156 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
5157 case RIL_REQUEST_DTMF: return "DTMF";
5158 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
5159 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
5160 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
5161 case RIL_REQUEST_SIM_IO: return "SIM_IO";
5162 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
5163 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
5164 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
5165 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
5166 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
5167 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
5168 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
5169 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
5170 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
5171 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
5172 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
5173 case RIL_REQUEST_ANSWER: return "ANSWER";
5174 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
5175 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
5176 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
5177 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
5178 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
5179 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
5180 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
5181 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";
5182 case RIL_REQUEST_DTMF_START: return "DTMF_START";
5183 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
5184 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
5185 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
5186 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
5187 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
5188 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
5189 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
5190 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
5191 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
5192 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
5193 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
5194 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
5195 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
5196 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
5197 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
5198 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
5199 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
5200 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
5201 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
5202 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
5203 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
5204 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
5205 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
5206 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005207 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE:return"CDMA_SET_SUBSCRIPTION_SOURCE";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005208 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"CDMA_SET_ROAMING_PREFERENCE";
5209 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"CDMA_QUERY_ROAMING_PREFERENCE";
5210 case RIL_REQUEST_SET_TTY_MODE:return"SET_TTY_MODE";
5211 case RIL_REQUEST_QUERY_TTY_MODE:return"QUERY_TTY_MODE";
5212 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
5213 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
5214 case RIL_REQUEST_CDMA_FLASH:return"CDMA_FLASH";
5215 case RIL_REQUEST_CDMA_BURST_DTMF:return"CDMA_BURST_DTMF";
5216 case RIL_REQUEST_CDMA_SEND_SMS:return"CDMA_SEND_SMS";
5217 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:return"CDMA_SMS_ACKNOWLEDGE";
5218 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG:return"GSM_GET_BROADCAST_SMS_CONFIG";
5219 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG:return"GSM_SET_BROADCAST_SMS_CONFIG";
5220 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG:return "CDMA_GET_BROADCAST_SMS_CONFIG";
5221 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG:return "CDMA_SET_BROADCAST_SMS_CONFIG";
5222 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION:return "CDMA_SMS_BROADCAST_ACTIVATION";
Ethan Chend6e30652013-08-04 22:49:56 -07005223 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return"CDMA_VALIDATE_AND_WRITE_AKEY";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005224 case RIL_REQUEST_CDMA_SUBSCRIPTION: return"CDMA_SUBSCRIPTION";
5225 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
5226 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
5227 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
5228 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
5229 case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
5230 case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
5231 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
5232 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
5233 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
5234 case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
5235 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
5236 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
5237 case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005238 case RIL_REQUEST_GET_CELL_INFO_LIST: return"GET_CELL_INFO_LIST";
5239 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return"SET_UNSOL_CELL_INFO_LIST_RATE";
Andrew Jiangca4a9a02014-01-18 18:04:08 -05005240 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "RIL_REQUEST_SET_INITIAL_ATTACH_APN";
5241 case RIL_REQUEST_IMS_REGISTRATION_STATE: return "IMS_REGISTRATION_STATE";
5242 case RIL_REQUEST_IMS_SEND_SMS: return "IMS_SEND_SMS";
Howard Sue32dbfd2015-01-07 15:55:57 +08005243 case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "SIM_TRANSMIT_APDU_BASIC";
5244 case RIL_REQUEST_SIM_OPEN_CHANNEL: return "SIM_OPEN_CHANNEL";
5245 case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "SIM_CLOSE_CHANNEL";
5246 case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "SIM_TRANSMIT_APDU_CHANNEL";
Howard Subd82ef12015-04-12 10:25:05 +02005247 case RIL_REQUEST_GET_RADIO_CAPABILITY: return "RIL_REQUEST_GET_RADIO_CAPABILITY";
5248 case RIL_REQUEST_SET_RADIO_CAPABILITY: return "RIL_REQUEST_SET_RADIO_CAPABILITY";
Howard Sue32dbfd2015-01-07 15:55:57 +08005249 case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "SET_UICC_SUBSCRIPTION";
5250 case RIL_REQUEST_ALLOW_DATA: return "ALLOW_DATA";
5251 case RIL_REQUEST_GET_HARDWARE_CONFIG: return "GET_HARDWARE_CONFIG";
5252 case RIL_REQUEST_SIM_AUTHENTICATION: return "SIM_AUTHENTICATION";
5253 case RIL_REQUEST_GET_DC_RT_INFO: return "GET_DC_RT_INFO";
5254 case RIL_REQUEST_SET_DC_RT_INFO_RATE: return "SET_DC_RT_INFO_RATE";
5255 case RIL_REQUEST_SET_DATA_PROFILE: return "SET_DATA_PROFILE";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005256 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
5257 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
5258 case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED";
5259 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
5260 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
5261 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
5262 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
5263 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)";
5264 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
5265 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
Howard Subd82ef12015-04-12 10:25:05 +02005266 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
5267 case RIL_UNSOL_SUPP_SVC_NOTIFICATION: return "UNSOL_SUPP_SVC_NOTIFICATION";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005268 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
5269 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
5270 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
5271 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
5272 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL";
5273 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005274 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
5275 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
5276 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_NEW_CDMA_SMS";
5277 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_NEW_BROADCAST_SMS";
5278 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
5279 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
5280 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
5281 case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
5282 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
5283 case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
5284 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
5285 case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
5286 case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
5287 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
5288 case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
5289 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
5290 case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
5291 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
Ethan Chend6e30652013-08-04 22:49:56 -07005292 case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
Andrew Jiangca4a9a02014-01-18 18:04:08 -05005293 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "RESPONSE_IMS_NETWORK_STATE_CHANGED";
Howard Sue32dbfd2015-01-07 15:55:57 +08005294 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return "UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED";
5295 case RIL_UNSOL_SRVCC_STATE_NOTIFY: return "UNSOL_SRVCC_STATE_NOTIFY";
5296 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return "HARDWARE_CONFIG_CHANGED";
5297 case RIL_UNSOL_DC_RT_INFO_CHANGED: return "UNSOL_DC_RT_INFO_CHANGED";
Howard Subd82ef12015-04-12 10:25:05 +02005298 case RIL_UNSOL_RADIO_CAPABILITY: return "UNSOL_RADIO_CAPABILITY";
5299 case RIL_UNSOL_ON_SS: return "UNSOL_ON_SS";
5300 case RIL_UNSOL_STK_CC_ALPHA_NOTIFY: return "UNSOL_STK_CC_ALPHA_NOTIFY";
Howard Sue32dbfd2015-01-07 15:55:57 +08005301 case RIL_REQUEST_SHUTDOWN: return "SHUTDOWN";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005302 default: return "<unknown request>";
5303 }
5304}
5305
Howard Sue32dbfd2015-01-07 15:55:57 +08005306const char *
5307rilSocketIdToString(RIL_SOCKET_ID socket_id)
5308{
5309 switch(socket_id) {
5310 case RIL_SOCKET_1:
5311 return "RIL_SOCKET_1";
5312#if (SIM_COUNT >= 2)
5313 case RIL_SOCKET_2:
5314 return "RIL_SOCKET_2";
5315#endif
5316#if (SIM_COUNT >= 3)
5317 case RIL_SOCKET_3:
5318 return "RIL_SOCKET_3";
5319#endif
5320#if (SIM_COUNT >= 4)
5321 case RIL_SOCKET_4:
5322 return "RIL_SOCKET_4";
5323#endif
5324 default:
5325 return "not a valid RIL";
5326 }
5327}
5328
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005329} /* namespace android */
Dheeraj Shettycc231012014-07-02 21:27:57 +02005330
5331void rilEventAddWakeup_helper(struct ril_event *ev) {
5332 android::rilEventAddWakeup(ev);
5333}
5334
5335void listenCallback_helper(int fd, short flags, void *param) {
5336 android::listenCallback(fd, flags, param);
5337}
5338
5339int blockingWrite_helper(int fd, void *buffer, size_t len) {
5340 return android::blockingWrite(fd, buffer, len);
5341}