blob: 3e3523905c03fd8392f5355de8d0af8c4ef4c34e [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"
Christopher N. Hesseb8400a22015-12-12 11:49:42 +010071#define PROPERTY_QAN_ELEMENTS "ro.ril.telephony.mqanelements"
Daniel Hillenbrand601dc852013-07-07 10:06:59 +020072
73// match with constant in RIL.java
74#define MAX_COMMAND_BYTES (8 * 1024)
75
76// Basically: memset buffers that the client library
77// shouldn't be using anymore in an attempt to find
78// memory usage issues sooner.
79#define MEMSET_FREED 1
80
81#define NUM_ELEMS(a) (sizeof (a) / sizeof (a)[0])
82
83#define MIN(a,b) ((a)<(b) ? (a) : (b))
84
85/* Constants for response types */
86#define RESPONSE_SOLICITED 0
87#define RESPONSE_UNSOLICITED 1
88
89/* Negative values for private RIL errno's */
90#define RIL_ERRNO_INVALID_RESPONSE -1
91
92// request, response, and unsolicited msg print macro
93#define PRINTBUF_SIZE 8096
94
Robert Greenwaltbc29c432015-04-29 16:57:39 -070095// Enable verbose logging
96#define VDBG 0
97
Daniel Hillenbrand601dc852013-07-07 10:06:59 +020098// Enable RILC log
99#define RILC_LOG 0
100
101#if RILC_LOG
102 #define startRequest sprintf(printBuf, "(")
103 #define closeRequest sprintf(printBuf, "%s)", printBuf)
forkbombe0568e12015-11-23 18:37:37 +1100104 #define printRequest(token, req) \
105 RLOGD("[%04d]> %s %s", token, requestToString(req), printBuf)
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200106
107 #define startResponse sprintf(printBuf, "%s {", printBuf)
108 #define closeResponse sprintf(printBuf, "%s}", printBuf)
XpLoDWilDba5c6a32013-07-27 21:12:19 +0200109 #define printResponse RLOGD("%s", printBuf)
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200110
111 #define clearPrintBuf printBuf[0] = 0
112 #define removeLastChar printBuf[strlen(printBuf)-1] = 0
113 #define appendPrintBuf(x...) sprintf(printBuf, x)
114#else
115 #define startRequest
116 #define closeRequest
117 #define printRequest(token, req)
118 #define startResponse
119 #define closeResponse
120 #define printResponse
121 #define clearPrintBuf
122 #define removeLastChar
123 #define appendPrintBuf(x...)
124#endif
125
126enum WakeType {DONT_WAKE, WAKE_PARTIAL};
127
128typedef struct {
129 int requestNumber;
130 void (*dispatchFunction) (Parcel &p, struct RequestInfo *pRI);
131 int(*responseFunction) (Parcel &p, void *response, size_t responselen);
132} CommandInfo;
133
134typedef struct {
135 int requestNumber;
136 int (*responseFunction) (Parcel &p, void *response, size_t responselen);
137 WakeType wakeType;
138} UnsolResponseInfo;
139
140typedef struct RequestInfo {
141 int32_t token; //this is not RIL_Token
142 CommandInfo *pCI;
143 struct RequestInfo *p_next;
144 char cancelled;
145 char local; // responses to local commands do not go back to command process
Howard Sue32dbfd2015-01-07 15:55:57 +0800146 RIL_SOCKET_ID socket_id;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200147} RequestInfo;
148
149typedef struct UserCallbackInfo {
150 RIL_TimedCallback p_callback;
151 void *userParam;
152 struct ril_event event;
153 struct UserCallbackInfo *p_next;
154} UserCallbackInfo;
155
Howard Sue32dbfd2015-01-07 15:55:57 +0800156extern "C" const char * requestToString(int request);
157extern "C" const char * failCauseToString(RIL_Errno);
158extern "C" const char * callStateToString(RIL_CallState);
159extern "C" const char * radioStateToString(RIL_RadioState);
160extern "C" const char * rilSocketIdToString(RIL_SOCKET_ID socket_id);
161
162extern "C"
163char rild[MAX_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200164
Howard Subd82ef12015-04-12 10:25:05 +0200165#define RIL_VENDOR_COMMANDS_OFFSET 10000
166
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200167/*******************************************************************/
168
169RIL_RadioFunctions s_callbacks = {0, NULL, NULL, NULL, NULL, NULL};
170static int s_registerCalled = 0;
171
172static pthread_t s_tid_dispatch;
173static pthread_t s_tid_reader;
174static int s_started = 0;
175
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200176static int s_fdDebug = -1;
Howard Sue32dbfd2015-01-07 15:55:57 +0800177static int s_fdDebug_socket2 = -1;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200178
179static int s_fdWakeupRead;
180static int s_fdWakeupWrite;
181
182static struct ril_event s_commands_event;
183static struct ril_event s_wakeupfd_event;
184static struct ril_event s_listen_event;
Howard Sue32dbfd2015-01-07 15:55:57 +0800185static SocketListenParam s_ril_param_socket;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200186
187static pthread_mutex_t s_pendingRequestsMutex = PTHREAD_MUTEX_INITIALIZER;
188static pthread_mutex_t s_writeMutex = PTHREAD_MUTEX_INITIALIZER;
Howard Sue32dbfd2015-01-07 15:55:57 +0800189static RequestInfo *s_pendingRequests = NULL;
190
191#if (SIM_COUNT >= 2)
192static struct ril_event s_commands_event_socket2;
193static struct ril_event s_listen_event_socket2;
194static SocketListenParam s_ril_param_socket2;
195
196static pthread_mutex_t s_pendingRequestsMutex_socket2 = PTHREAD_MUTEX_INITIALIZER;
197static pthread_mutex_t s_writeMutex_socket2 = PTHREAD_MUTEX_INITIALIZER;
198static RequestInfo *s_pendingRequests_socket2 = NULL;
199#endif
200
201#if (SIM_COUNT >= 3)
202static struct ril_event s_commands_event_socket3;
203static struct ril_event s_listen_event_socket3;
204static SocketListenParam s_ril_param_socket3;
205
206static pthread_mutex_t s_pendingRequestsMutex_socket3 = PTHREAD_MUTEX_INITIALIZER;
207static pthread_mutex_t s_writeMutex_socket3 = PTHREAD_MUTEX_INITIALIZER;
208static RequestInfo *s_pendingRequests_socket3 = NULL;
209#endif
210
211#if (SIM_COUNT >= 4)
212static struct ril_event s_commands_event_socket4;
213static struct ril_event s_listen_event_socket4;
214static SocketListenParam s_ril_param_socket4;
215
216static pthread_mutex_t s_pendingRequestsMutex_socket4 = PTHREAD_MUTEX_INITIALIZER;
217static pthread_mutex_t s_writeMutex_socket4 = PTHREAD_MUTEX_INITIALIZER;
218static RequestInfo *s_pendingRequests_socket4 = NULL;
219#endif
220
221static struct ril_event s_wake_timeout_event;
222static struct ril_event s_debug_event;
223
Howard Subd82ef12015-04-12 10:25:05 +0200224
Nathan Haroldd6306fa2015-07-28 14:54:58 -0700225static const struct timeval TIMEVAL_WAKE_TIMEOUT = {ANDROID_WAKE_LOCK_SECS,ANDROID_WAKE_LOCK_USECS};
Howard Sue32dbfd2015-01-07 15:55:57 +0800226
Howard Subd82ef12015-04-12 10:25:05 +0200227
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200228static pthread_mutex_t s_startupMutex = PTHREAD_MUTEX_INITIALIZER;
229static pthread_cond_t s_startupCond = PTHREAD_COND_INITIALIZER;
230
231static pthread_mutex_t s_dispatchMutex = PTHREAD_MUTEX_INITIALIZER;
232static pthread_cond_t s_dispatchCond = PTHREAD_COND_INITIALIZER;
233
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200234static RequestInfo *s_toDispatchHead = NULL;
235static RequestInfo *s_toDispatchTail = NULL;
236
237static UserCallbackInfo *s_last_wake_timeout_info = NULL;
238
239static void *s_lastNITZTimeData = NULL;
240static size_t s_lastNITZTimeDataSize;
241
242#if RILC_LOG
243 static char printBuf[PRINTBUF_SIZE];
244#endif
245
246/*******************************************************************/
Howard Sue32dbfd2015-01-07 15:55:57 +0800247static int sendResponse (Parcel &p, RIL_SOCKET_ID socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200248
249static void dispatchVoid (Parcel& p, RequestInfo *pRI);
250static void dispatchString (Parcel& p, RequestInfo *pRI);
251static void dispatchStrings (Parcel& p, RequestInfo *pRI);
252static void dispatchInts (Parcel& p, RequestInfo *pRI);
253static void dispatchDial (Parcel& p, RequestInfo *pRI);
254static void dispatchSIM_IO (Parcel& p, RequestInfo *pRI);
Howard Sue32dbfd2015-01-07 15:55:57 +0800255static void dispatchSIM_APDU (Parcel& p, RequestInfo *pRI);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200256static void dispatchCallForward(Parcel& p, RequestInfo *pRI);
257static void dispatchRaw(Parcel& p, RequestInfo *pRI);
258static void dispatchSmsWrite (Parcel &p, RequestInfo *pRI);
259static void dispatchDataCall (Parcel& p, RequestInfo *pRI);
260static void dispatchVoiceRadioTech (Parcel& p, RequestInfo *pRI);
Andrew Jiangca4a9a02014-01-18 18:04:08 -0500261static void dispatchSetInitialAttachApn (Parcel& p, RequestInfo *pRI);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200262static void dispatchCdmaSubscriptionSource (Parcel& p, RequestInfo *pRI);
263
264static void dispatchCdmaSms(Parcel &p, RequestInfo *pRI);
Andrew Jiangca4a9a02014-01-18 18:04:08 -0500265static void dispatchImsSms(Parcel &p, RequestInfo *pRI);
266static void dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
267static void dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200268static void dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI);
269static void dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI);
270static void dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI);
271static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI);
Howard Sue32dbfd2015-01-07 15:55:57 +0800272static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI);
273static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI);
274static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI);
275static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI);
276static void dispatchDataProfile(Parcel &p, RequestInfo *pRI);
Howard Subd82ef12015-04-12 10:25:05 +0200277static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200278static int responseInts(Parcel &p, void *response, size_t responselen);
Daniel Hillenbrandd0b84162015-04-12 11:53:23 +0200279static int responseIntsGetPreferredNetworkType(Parcel &p, void *response, size_t responselen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200280static int responseStrings(Parcel &p, void *response, size_t responselen);
Utkarsh Guptaf7a63e52015-05-10 16:53:37 +0530281static int responseStringsNetworks(Parcel &p, void *response, size_t responselen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200282static int responseStrings(Parcel &p, void *response, size_t responselen, bool network_search);
283static int responseString(Parcel &p, void *response, size_t responselen);
284static int responseVoid(Parcel &p, void *response, size_t responselen);
285static int responseCallList(Parcel &p, void *response, size_t responselen);
286static int responseSMS(Parcel &p, void *response, size_t responselen);
287static int responseSIM_IO(Parcel &p, void *response, size_t responselen);
288static int responseCallForwards(Parcel &p, void *response, size_t responselen);
289static int responseDataCallList(Parcel &p, void *response, size_t responselen);
290static int responseSetupDataCall(Parcel &p, void *response, size_t responselen);
291static int responseRaw(Parcel &p, void *response, size_t responselen);
292static int responseSsn(Parcel &p, void *response, size_t responselen);
293static int responseSimStatus(Parcel &p, void *response, size_t responselen);
294static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen);
295static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen);
296static int responseCdmaSms(Parcel &p, void *response, size_t responselen);
297static int responseCellList(Parcel &p, void *response, size_t responselen);
298static int responseCdmaInformationRecords(Parcel &p,void *response, size_t responselen);
299static int responseRilSignalStrength(Parcel &p,void *response, size_t responselen);
300static int responseCallRing(Parcel &p, void *response, size_t responselen);
301static int responseCdmaSignalInfoRecord(Parcel &p,void *response, size_t responselen);
302static int responseCdmaCallWaiting(Parcel &p,void *response, size_t responselen);
303static int responseSimRefresh(Parcel &p, void *response, size_t responselen);
XpLoDWilDba5c6a32013-07-27 21:12:19 +0200304static int responseCellInfoList(Parcel &p, void *response, size_t responselen);
Howard Sue32dbfd2015-01-07 15:55:57 +0800305static int responseHardwareConfig(Parcel &p, void *response, size_t responselen);
306static int responseDcRtInfo(Parcel &p, void *response, size_t responselen);
Howard Subd82ef12015-04-12 10:25:05 +0200307static int responseRadioCapability(Parcel &p, void *response, size_t responselen);
308static int responseSSData(Parcel &p, void *response, size_t responselen);
fenglu9bdede02015-04-14 14:53:55 -0700309static int responseLceStatus(Parcel &p, void *response, size_t responselen);
310static int responseLceData(Parcel &p, void *response, size_t responselen);
Prerepa Viswanadham8e755592015-05-28 00:37:32 -0700311static int responseActivityData(Parcel &p, void *response, size_t responselen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200312
313static int decodeVoiceRadioTechnology (RIL_RadioState radioState);
314static int decodeCdmaSubscriptionSource (RIL_RadioState radioState);
Howard Subd82ef12015-04-12 10:25:05 +0200315static RIL_RadioState processRadioState(RIL_RadioState newRadioState);
316
317static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200318
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200319#ifdef RIL_SHLIB
Howard Sue32dbfd2015-01-07 15:55:57 +0800320#if defined(ANDROID_MULTI_SIM)
Andreas Schneider47b2d962015-04-13 22:54:49 +0200321extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Howard Sue32dbfd2015-01-07 15:55:57 +0800322 size_t datalen, RIL_SOCKET_ID socket_id);
323#else
Andreas Schneider47b2d962015-04-13 22:54:49 +0200324extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200325 size_t datalen);
326#endif
Howard Sue32dbfd2015-01-07 15:55:57 +0800327#endif
328
329#if defined(ANDROID_MULTI_SIM)
330#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c), (d))
331#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d), (e))
332#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest(a)
333#else
334#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c))
335#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d))
336#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest()
337#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200338
339static UserCallbackInfo * internalRequestTimedCallback
340 (RIL_TimedCallback callback, void *param,
341 const struct timeval *relativeTime);
342
343/** Index == requestNumber */
344static CommandInfo s_commands[] = {
345#include "ril_commands.h"
346};
347
348static UnsolResponseInfo s_unsolResponses[] = {
349#include "ril_unsol_commands.h"
350};
351
Christopher N. Hessec694ff02016-03-27 21:04:38 +0200352static CommandInfo s_commands_v[] = {
353#include <telephony/ril_commands_vendor.h>
354};
355
Howard Subd82ef12015-04-12 10:25:05 +0200356static UnsolResponseInfo s_unsolResponses_v[] = {
Christopher N. Hessec694ff02016-03-27 21:04:38 +0200357#include <telephony/ril_unsol_commands_vendor.h>
Howard Subd82ef12015-04-12 10:25:05 +0200358};
359
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200360/* For older RILs that do not support new commands RIL_REQUEST_VOICE_RADIO_TECH and
361 RIL_UNSOL_VOICE_RADIO_TECH_CHANGED messages, decode the voice radio tech from
362 radio state message and store it. Every time there is a change in Radio State
363 check to see if voice radio tech changes and notify telephony
364 */
365int voiceRadioTech = -1;
366
367/* For older RILs that do not support new commands RIL_REQUEST_GET_CDMA_SUBSCRIPTION_SOURCE
368 and RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED messages, decode the subscription
369 source from radio state and store it. Every time there is a change in Radio State
370 check to see if subscription source changed and notify telephony
371 */
372int cdmaSubscriptionSource = -1;
373
374/* For older RILs that do not send RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, decode the
375 SIM/RUIM state from radio state and store it. Every time there is a change in Radio State,
376 check to see if SIM/RUIM status changed and notify telephony
377 */
378int simRuimStatus = -1;
379
Howard Sue32dbfd2015-01-07 15:55:57 +0800380static char * RIL_getRilSocketName() {
381 return rild;
382}
383
384extern "C"
Dheeraj Shettycc231012014-07-02 21:27:57 +0200385void RIL_setRilSocketName(const char * s) {
Howard Sue32dbfd2015-01-07 15:55:57 +0800386 strncpy(rild, s, MAX_SOCKET_NAME_LENGTH);
387}
388
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200389static char *
390strdupReadString(Parcel &p) {
391 size_t stringlen;
392 const char16_t *s16;
393
394 s16 = p.readString16Inplace(&stringlen);
395
396 return strndup16to8(s16, stringlen);
397}
398
Howard Subd82ef12015-04-12 10:25:05 +0200399static status_t
400readStringFromParcelInplace(Parcel &p, char *str, size_t maxLen) {
401 size_t s16Len;
402 const char16_t *s16;
403
404 s16 = p.readString16Inplace(&s16Len);
405 if (s16 == NULL) {
406 return NO_MEMORY;
407 }
408 size_t strLen = strnlen16to8(s16, s16Len);
409 if ((strLen + 1) > maxLen) {
410 return NO_MEMORY;
411 }
412 if (strncpy16to8(str, s16, strLen) == NULL) {
413 return NO_MEMORY;
414 } else {
415 return NO_ERROR;
416 }
417}
418
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200419static void writeStringToParcel(Parcel &p, const char *s) {
420 char16_t *s16;
421 size_t s16_len;
422 s16 = strdup8to16(s, &s16_len);
423 p.writeString16(s16, s16_len);
424 free(s16);
425}
426
427
428static void
429memsetString (char *s) {
430 if (s != NULL) {
431 memset (s, 0, strlen(s));
432 }
433}
434
435void nullParcelReleaseFunction (const uint8_t* data, size_t dataSize,
436 const size_t* objects, size_t objectsSize,
437 void* cookie) {
438 // do nothing -- the data reference lives longer than the Parcel object
439}
440
441/**
442 * To be called from dispatch thread
443 * Issue a single local request, ensuring that the response
444 * is not sent back up to the command process
445 */
446static void
Howard Sue32dbfd2015-01-07 15:55:57 +0800447issueLocalRequest(int request, void *data, int len, RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200448 RequestInfo *pRI;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200449 int ret;
Howard Sue32dbfd2015-01-07 15:55:57 +0800450 /* Hook for current context */
451 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
452 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
453 /* pendingRequestsHook refer to &s_pendingRequests */
454 RequestInfo** pendingRequestsHook = &s_pendingRequests;
455
456#if (SIM_COUNT == 2)
457 if (socket_id == RIL_SOCKET_2) {
458 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
459 pendingRequestsHook = &s_pendingRequests_socket2;
460 }
461#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200462
463 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
464
465 pRI->local = 1;
466 pRI->token = 0xffffffff; // token is not used in this context
467
Howard Subd82ef12015-04-12 10:25:05 +0200468 /* Check vendor commands */
469 if (request > RIL_VENDOR_COMMANDS_OFFSET) {
470 pRI->pCI = &(s_commands_v[request - RIL_VENDOR_COMMANDS_OFFSET]);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200471 } else {
472 pRI->pCI = &(s_commands[request]);
473 }
Howard Sue32dbfd2015-01-07 15:55:57 +0800474 pRI->socket_id = socket_id;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200475
Howard Sue32dbfd2015-01-07 15:55:57 +0800476 ret = pthread_mutex_lock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200477 assert (ret == 0);
478
Howard Sue32dbfd2015-01-07 15:55:57 +0800479 pRI->p_next = *pendingRequestsHook;
480 *pendingRequestsHook = pRI;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200481
Howard Sue32dbfd2015-01-07 15:55:57 +0800482 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200483 assert (ret == 0);
484
XpLoDWilDba5c6a32013-07-27 21:12:19 +0200485 RLOGD("C[locl]> %s", requestToString(request));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200486
Howard Sue32dbfd2015-01-07 15:55:57 +0800487 CALL_ONREQUEST(request, data, len, pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200488}
489
Howard Subd82ef12015-04-12 10:25:05 +0200490
491
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200492static int
Howard Sue32dbfd2015-01-07 15:55:57 +0800493processCommandBuffer(void *buffer, size_t buflen, RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200494 Parcel p;
495 status_t status;
496 int32_t request;
497 int32_t token;
498 RequestInfo *pRI;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200499 int ret;
Howard Sue32dbfd2015-01-07 15:55:57 +0800500 /* Hook for current context */
501 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
502 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
503 /* pendingRequestsHook refer to &s_pendingRequests */
504 RequestInfo** pendingRequestsHook = &s_pendingRequests;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200505
506 p.setData((uint8_t *) buffer, buflen);
507
508 // status checked at end
509 status = p.readInt32(&request);
510 status = p.readInt32 (&token);
511
Howard Sue32dbfd2015-01-07 15:55:57 +0800512#if (SIM_COUNT >= 2)
513 if (socket_id == RIL_SOCKET_2) {
514 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
515 pendingRequestsHook = &s_pendingRequests_socket2;
516 }
517#if (SIM_COUNT >= 3)
518 else if (socket_id == RIL_SOCKET_3) {
519 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
520 pendingRequestsHook = &s_pendingRequests_socket3;
521 }
522#endif
523#if (SIM_COUNT >= 4)
524 else if (socket_id == RIL_SOCKET_4) {
525 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
526 pendingRequestsHook = &s_pendingRequests_socket4;
527 }
528#endif
529#endif
530
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200531 if (status != NO_ERROR) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +0200532 RLOGE("invalid request block");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200533 return 0;
534 }
535
Howard Subd82ef12015-04-12 10:25:05 +0200536 CommandInfo *pCI = NULL;
537 if (request > RIL_VENDOR_COMMANDS_OFFSET) {
538 int index = request - RIL_VENDOR_COMMANDS_OFFSET;
539 RLOGD("processCommandBuffer: samsung request=%d, index=%d",
540 request, index);
541 if (index < (int32_t)NUM_ELEMS(s_commands_v))
542 pCI = &(s_commands_v[index]);
543 } else {
544 if (request < (int32_t)NUM_ELEMS(s_commands))
545 pCI = &(s_commands[request]);
546 }
Howard Sue32dbfd2015-01-07 15:55:57 +0800547
Howard Subd82ef12015-04-12 10:25:05 +0200548 if (pCI == NULL) {
549 Parcel pErr;
XpLoDWilDba5c6a32013-07-27 21:12:19 +0200550 RLOGE("unsupported request code %d token %d", request, token);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200551 // FIXME this should perhaps return a response
Howard Sue32dbfd2015-01-07 15:55:57 +0800552 pErr.writeInt32 (RESPONSE_SOLICITED);
553 pErr.writeInt32 (token);
554 pErr.writeInt32 (RIL_E_GENERIC_FAILURE);
555
556 sendResponse(pErr, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200557 return 0;
558 }
559
560 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
561
562 pRI->token = token;
Howard Subd82ef12015-04-12 10:25:05 +0200563 pRI->pCI = pCI;
Howard Sue32dbfd2015-01-07 15:55:57 +0800564 pRI->socket_id = socket_id;
565
566 ret = pthread_mutex_lock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200567 assert (ret == 0);
568
Howard Sue32dbfd2015-01-07 15:55:57 +0800569 pRI->p_next = *pendingRequestsHook;
570 *pendingRequestsHook = pRI;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200571
Howard Sue32dbfd2015-01-07 15:55:57 +0800572 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200573 assert (ret == 0);
574
575/* sLastDispatchedToken = token; */
576
577 pRI->pCI->dispatchFunction(p, pRI);
578
579 return 0;
580}
581
582static void
583invalidCommandBlock (RequestInfo *pRI) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +0200584 RLOGE("invalid command block for token %d request %s",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200585 pRI->token, requestToString(pRI->pCI->requestNumber));
586}
587
588/** Callee expects NULL */
589static void
590dispatchVoid (Parcel& p, RequestInfo *pRI) {
591 clearPrintBuf;
592 printRequest(pRI->token, pRI->pCI->requestNumber);
Howard Sue32dbfd2015-01-07 15:55:57 +0800593 CALL_ONREQUEST(pRI->pCI->requestNumber, NULL, 0, pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200594}
595
596/** Callee expects const char * */
597static void
598dispatchString (Parcel& p, RequestInfo *pRI) {
599 status_t status;
600 size_t datalen;
601 size_t stringlen;
602 char *string8 = NULL;
603
604 string8 = strdupReadString(p);
605
606 startRequest;
607 appendPrintBuf("%s%s", printBuf, string8);
608 closeRequest;
609 printRequest(pRI->token, pRI->pCI->requestNumber);
610
Howard Sue32dbfd2015-01-07 15:55:57 +0800611 CALL_ONREQUEST(pRI->pCI->requestNumber, string8,
612 sizeof(char *), pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200613
614#ifdef MEMSET_FREED
615 memsetString(string8);
616#endif
617
618 free(string8);
619 return;
620invalid:
621 invalidCommandBlock(pRI);
622 return;
623}
624
625/** Callee expects const char ** */
626static void
627dispatchStrings (Parcel &p, RequestInfo *pRI) {
628 int32_t countStrings;
629 status_t status;
630 size_t datalen;
631 char **pStrings;
632
633 status = p.readInt32 (&countStrings);
634
635 if (status != NO_ERROR) {
636 goto invalid;
637 }
638
639 startRequest;
640 if (countStrings == 0) {
641 // just some non-null pointer
642 pStrings = (char **)alloca(sizeof(char *));
643 datalen = 0;
644 } else if (((int)countStrings) == -1) {
645 pStrings = NULL;
646 datalen = 0;
647 } else {
648 datalen = sizeof(char *) * countStrings;
649
650 pStrings = (char **)alloca(datalen);
651
652 for (int i = 0 ; i < countStrings ; i++) {
653 pStrings[i] = strdupReadString(p);
654 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
655 }
656 }
657 removeLastChar;
658 closeRequest;
659 printRequest(pRI->token, pRI->pCI->requestNumber);
660
Howard Sue32dbfd2015-01-07 15:55:57 +0800661 CALL_ONREQUEST(pRI->pCI->requestNumber, pStrings, datalen, pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200662
663 if (pStrings != NULL) {
664 for (int i = 0 ; i < countStrings ; i++) {
665#ifdef MEMSET_FREED
666 memsetString (pStrings[i]);
667#endif
668 free(pStrings[i]);
669 }
670
671#ifdef MEMSET_FREED
672 memset(pStrings, 0, datalen);
673#endif
674 }
675
676 return;
677invalid:
678 invalidCommandBlock(pRI);
679 return;
680}
681
682/** Callee expects const int * */
683static void
684dispatchInts (Parcel &p, RequestInfo *pRI) {
685 int32_t count;
686 status_t status;
687 size_t datalen;
688 int *pInts;
689
690 status = p.readInt32 (&count);
691
692 if (status != NO_ERROR || count == 0) {
693 goto invalid;
694 }
695
696 datalen = sizeof(int) * count;
697 pInts = (int *)alloca(datalen);
698
699 startRequest;
700 for (int i = 0 ; i < count ; i++) {
701 int32_t t;
702
703 status = p.readInt32(&t);
704 pInts[i] = (int)t;
705 appendPrintBuf("%s%d,", printBuf, t);
706
707 if (status != NO_ERROR) {
708 goto invalid;
709 }
710 }
711 removeLastChar;
712 closeRequest;
713 printRequest(pRI->token, pRI->pCI->requestNumber);
714
Howard Sue32dbfd2015-01-07 15:55:57 +0800715 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<int *>(pInts),
716 datalen, pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200717
718#ifdef MEMSET_FREED
719 memset(pInts, 0, datalen);
720#endif
721
722 return;
723invalid:
724 invalidCommandBlock(pRI);
725 return;
726}
727
728
729/**
730 * Callee expects const RIL_SMS_WriteArgs *
731 * Payload is:
732 * int32_t status
733 * String pdu
734 */
735static void
736dispatchSmsWrite (Parcel &p, RequestInfo *pRI) {
737 RIL_SMS_WriteArgs args;
738 int32_t t;
739 status_t status;
740
Mark Salyzyn961fd022015-04-09 07:18:35 -0700741 RLOGD("dispatchSmsWrite");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200742 memset (&args, 0, sizeof(args));
743
744 status = p.readInt32(&t);
745 args.status = (int)t;
746
747 args.pdu = strdupReadString(p);
748
749 if (status != NO_ERROR || args.pdu == NULL) {
750 goto invalid;
751 }
752
753 args.smsc = strdupReadString(p);
754
755 startRequest;
756 appendPrintBuf("%s%d,%s,smsc=%s", printBuf, args.status,
757 (char*)args.pdu, (char*)args.smsc);
758 closeRequest;
759 printRequest(pRI->token, pRI->pCI->requestNumber);
760
Howard Sue32dbfd2015-01-07 15:55:57 +0800761 CALL_ONREQUEST(pRI->pCI->requestNumber, &args, sizeof(args), pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200762
763#ifdef MEMSET_FREED
764 memsetString (args.pdu);
765#endif
766
767 free (args.pdu);
768
769#ifdef MEMSET_FREED
770 memset(&args, 0, sizeof(args));
771#endif
772
773 return;
774invalid:
775 invalidCommandBlock(pRI);
776 return;
777}
778
779/**
780 * Callee expects const RIL_Dial *
781 * Payload is:
782 * String address
783 * int32_t clir
784 */
785static void
786dispatchDial (Parcel &p, RequestInfo *pRI) {
787 RIL_Dial dial;
788 RIL_UUS_Info uusInfo;
789 int32_t sizeOfDial;
790 int32_t t;
791 int32_t uusPresent;
Christopher N. Hesse621e63e2016-02-22 21:57:39 +0100792#ifdef SAMSUNG_NEXT_GEN_MODEM
Andreas Schneider29472682015-01-01 19:00:04 +0100793 char *csv;
794#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200795 status_t status;
796
Mark Salyzyn961fd022015-04-09 07:18:35 -0700797 RLOGD("dispatchDial");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200798 memset (&dial, 0, sizeof(dial));
799
800 dial.address = strdupReadString(p);
801
802 status = p.readInt32(&t);
803 dial.clir = (int)t;
804
805 if (status != NO_ERROR || dial.address == NULL) {
806 goto invalid;
807 }
808
Christopher N. Hesse621e63e2016-02-22 21:57:39 +0100809#ifdef SAMSUNG_NEXT_GEN_MODEM
Andreas Schneider29472682015-01-01 19:00:04 +0100810 /* CallDetails.call_type */
811 status = p.readInt32(&t);
812 if (status != NO_ERROR) {
813 goto invalid;
814 }
815 /* CallDetails.call_domain */
816 p.readInt32(&t);
817 if (status != NO_ERROR) {
818 goto invalid;
819 }
820 /* CallDetails.getCsvFromExtra */
821 csv = strdupReadString(p);
822 if (csv == NULL) {
823 goto invalid;
824 }
825 free(csv);
826#endif
827
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200828 if (s_callbacks.version < 3) { // Remove when partners upgrade to version 3
829 uusPresent = 0;
830 sizeOfDial = sizeof(dial) - sizeof(RIL_UUS_Info *);
831 } else {
832 status = p.readInt32(&uusPresent);
833
834 if (status != NO_ERROR) {
835 goto invalid;
836 }
837
838 if (uusPresent == 0) {
Christopher N. Hesse621e63e2016-02-22 21:57:39 +0100839#if defined(MODEM_TYPE_XMM6262) || defined(SAMSUNG_NEXT_GEN_MODEM)
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200840 dial.uusInfo = NULL;
Andreas Schneiderf68609b2015-04-07 19:01:34 +0200841#elif defined(MODEM_TYPE_XMM6260)
Howard Sue32dbfd2015-01-07 15:55:57 +0800842 /* Samsung hack */
843 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
844 uusInfo.uusType = (RIL_UUS_Type) 0;
845 uusInfo.uusDcs = (RIL_UUS_DCS) 0;
846 uusInfo.uusData = NULL;
847 uusInfo.uusLength = 0;
848 dial.uusInfo = &uusInfo;
849#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200850 } else {
851 int32_t len;
852
853 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
854
855 status = p.readInt32(&t);
856 uusInfo.uusType = (RIL_UUS_Type) t;
857
858 status = p.readInt32(&t);
859 uusInfo.uusDcs = (RIL_UUS_DCS) t;
860
861 status = p.readInt32(&len);
862 if (status != NO_ERROR) {
863 goto invalid;
864 }
865
866 // The java code writes -1 for null arrays
867 if (((int) len) == -1) {
868 uusInfo.uusData = NULL;
869 len = 0;
870 } else {
871 uusInfo.uusData = (char*) p.readInplace(len);
872 }
873
874 uusInfo.uusLength = len;
875 dial.uusInfo = &uusInfo;
876 }
877 sizeOfDial = sizeof(dial);
878 }
879
880 startRequest;
881 appendPrintBuf("%snum=%s,clir=%d", printBuf, dial.address, dial.clir);
882 if (uusPresent) {
883 appendPrintBuf("%s,uusType=%d,uusDcs=%d,uusLen=%d", printBuf,
884 dial.uusInfo->uusType, dial.uusInfo->uusDcs,
885 dial.uusInfo->uusLength);
886 }
887 closeRequest;
888 printRequest(pRI->token, pRI->pCI->requestNumber);
889
Howard Sue32dbfd2015-01-07 15:55:57 +0800890 CALL_ONREQUEST(pRI->pCI->requestNumber, &dial, sizeOfDial, pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200891
892#ifdef MEMSET_FREED
893 memsetString (dial.address);
894#endif
895
896 free (dial.address);
897
898#ifdef MEMSET_FREED
899 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
900 memset(&dial, 0, sizeof(dial));
901#endif
902
903 return;
904invalid:
905 invalidCommandBlock(pRI);
906 return;
907}
908
909/**
910 * Callee expects const RIL_SIM_IO *
911 * Payload is:
912 * int32_t command
913 * int32_t fileid
914 * String path
915 * int32_t p1, p2, p3
916 * String data
917 * String pin2
918 * String aidPtr
919 */
920static void
921dispatchSIM_IO (Parcel &p, RequestInfo *pRI) {
922 union RIL_SIM_IO {
923 RIL_SIM_IO_v6 v6;
924 RIL_SIM_IO_v5 v5;
925 } simIO;
926
927 int32_t t;
928 int size;
929 status_t status;
930
Robert Greenwaltbc29c432015-04-29 16:57:39 -0700931#if VDBG
Mark Salyzyn961fd022015-04-09 07:18:35 -0700932 RLOGD("dispatchSIM_IO");
Robert Greenwaltbc29c432015-04-29 16:57:39 -0700933#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200934 memset (&simIO, 0, sizeof(simIO));
935
936 // note we only check status at the end
937
938 status = p.readInt32(&t);
939 simIO.v6.command = (int)t;
940
941 status = p.readInt32(&t);
942 simIO.v6.fileid = (int)t;
943
944 simIO.v6.path = strdupReadString(p);
945
946 status = p.readInt32(&t);
947 simIO.v6.p1 = (int)t;
948
949 status = p.readInt32(&t);
950 simIO.v6.p2 = (int)t;
951
952 status = p.readInt32(&t);
953 simIO.v6.p3 = (int)t;
954
955 simIO.v6.data = strdupReadString(p);
956 simIO.v6.pin2 = strdupReadString(p);
957 simIO.v6.aidPtr = strdupReadString(p);
958
959 startRequest;
960 appendPrintBuf("%scmd=0x%X,efid=0x%X,path=%s,%d,%d,%d,%s,pin2=%s,aid=%s", printBuf,
961 simIO.v6.command, simIO.v6.fileid, (char*)simIO.v6.path,
962 simIO.v6.p1, simIO.v6.p2, simIO.v6.p3,
963 (char*)simIO.v6.data, (char*)simIO.v6.pin2, simIO.v6.aidPtr);
964 closeRequest;
965 printRequest(pRI->token, pRI->pCI->requestNumber);
966
967 if (status != NO_ERROR) {
968 goto invalid;
969 }
970
971 size = (s_callbacks.version < 6) ? sizeof(simIO.v5) : sizeof(simIO.v6);
Howard Sue32dbfd2015-01-07 15:55:57 +0800972 CALL_ONREQUEST(pRI->pCI->requestNumber, &simIO, size, pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200973
974#ifdef MEMSET_FREED
975 memsetString (simIO.v6.path);
976 memsetString (simIO.v6.data);
977 memsetString (simIO.v6.pin2);
978 memsetString (simIO.v6.aidPtr);
979#endif
980
981 free (simIO.v6.path);
982 free (simIO.v6.data);
983 free (simIO.v6.pin2);
984 free (simIO.v6.aidPtr);
985
986#ifdef MEMSET_FREED
987 memset(&simIO, 0, sizeof(simIO));
988#endif
989
990 return;
991invalid:
992 invalidCommandBlock(pRI);
993 return;
994}
995
996/**
Howard Sue32dbfd2015-01-07 15:55:57 +0800997 * Callee expects const RIL_SIM_APDU *
998 * Payload is:
999 * int32_t sessionid
1000 * int32_t cla
1001 * int32_t instruction
1002 * int32_t p1, p2, p3
1003 * String data
1004 */
1005static void
1006dispatchSIM_APDU (Parcel &p, RequestInfo *pRI) {
1007 int32_t t;
1008 status_t status;
1009 RIL_SIM_APDU apdu;
1010
Robert Greenwaltbc29c432015-04-29 16:57:39 -07001011#if VDBG
Mark Salyzyn961fd022015-04-09 07:18:35 -07001012 RLOGD("dispatchSIM_APDU");
Robert Greenwaltbc29c432015-04-29 16:57:39 -07001013#endif
Howard Sue32dbfd2015-01-07 15:55:57 +08001014 memset (&apdu, 0, sizeof(RIL_SIM_APDU));
1015
1016 // Note we only check status at the end. Any single failure leads to
1017 // subsequent reads filing.
1018 status = p.readInt32(&t);
1019 apdu.sessionid = (int)t;
1020
1021 status = p.readInt32(&t);
1022 apdu.cla = (int)t;
1023
1024 status = p.readInt32(&t);
1025 apdu.instruction = (int)t;
1026
1027 status = p.readInt32(&t);
1028 apdu.p1 = (int)t;
1029
1030 status = p.readInt32(&t);
1031 apdu.p2 = (int)t;
1032
1033 status = p.readInt32(&t);
1034 apdu.p3 = (int)t;
1035
1036 apdu.data = strdupReadString(p);
1037
1038 startRequest;
1039 appendPrintBuf("%ssessionid=%d,cla=%d,ins=%d,p1=%d,p2=%d,p3=%d,data=%s",
1040 printBuf, apdu.sessionid, apdu.cla, apdu.instruction, apdu.p1, apdu.p2,
1041 apdu.p3, (char*)apdu.data);
1042 closeRequest;
1043 printRequest(pRI->token, pRI->pCI->requestNumber);
1044
1045 if (status != NO_ERROR) {
1046 goto invalid;
1047 }
1048
1049 CALL_ONREQUEST(pRI->pCI->requestNumber, &apdu, sizeof(RIL_SIM_APDU), pRI, pRI->socket_id);
1050
1051#ifdef MEMSET_FREED
1052 memsetString(apdu.data);
1053#endif
1054 free(apdu.data);
1055
1056#ifdef MEMSET_FREED
1057 memset(&apdu, 0, sizeof(RIL_SIM_APDU));
1058#endif
1059
1060 return;
1061invalid:
1062 invalidCommandBlock(pRI);
1063 return;
1064}
1065
Howard Subd82ef12015-04-12 10:25:05 +02001066
Howard Sue32dbfd2015-01-07 15:55:57 +08001067/**
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001068 * Callee expects const RIL_CallForwardInfo *
1069 * Payload is:
1070 * int32_t status/action
1071 * int32_t reason
1072 * int32_t serviceCode
1073 * int32_t toa
1074 * String number (0 length -> null)
1075 * int32_t timeSeconds
1076 */
1077static void
1078dispatchCallForward(Parcel &p, RequestInfo *pRI) {
1079 RIL_CallForwardInfo cff;
1080 int32_t t;
1081 status_t status;
1082
Mark Salyzyn961fd022015-04-09 07:18:35 -07001083 RLOGD("dispatchCallForward");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001084 memset (&cff, 0, sizeof(cff));
1085
1086 // note we only check status at the end
1087
1088 status = p.readInt32(&t);
1089 cff.status = (int)t;
1090
1091 status = p.readInt32(&t);
1092 cff.reason = (int)t;
1093
1094 status = p.readInt32(&t);
1095 cff.serviceClass = (int)t;
1096
1097 status = p.readInt32(&t);
1098 cff.toa = (int)t;
1099
1100 cff.number = strdupReadString(p);
1101
1102 status = p.readInt32(&t);
1103 cff.timeSeconds = (int)t;
1104
1105 if (status != NO_ERROR) {
1106 goto invalid;
1107 }
1108
1109 // special case: number 0-length fields is null
1110
1111 if (cff.number != NULL && strlen (cff.number) == 0) {
1112 cff.number = NULL;
1113 }
1114
1115 startRequest;
1116 appendPrintBuf("%sstat=%d,reason=%d,serv=%d,toa=%d,%s,tout=%d", printBuf,
1117 cff.status, cff.reason, cff.serviceClass, cff.toa,
1118 (char*)cff.number, cff.timeSeconds);
1119 closeRequest;
1120 printRequest(pRI->token, pRI->pCI->requestNumber);
1121
Howard Sue32dbfd2015-01-07 15:55:57 +08001122 CALL_ONREQUEST(pRI->pCI->requestNumber, &cff, sizeof(cff), pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001123
1124#ifdef MEMSET_FREED
1125 memsetString(cff.number);
1126#endif
1127
1128 free (cff.number);
1129
1130#ifdef MEMSET_FREED
1131 memset(&cff, 0, sizeof(cff));
1132#endif
1133
1134 return;
1135invalid:
1136 invalidCommandBlock(pRI);
1137 return;
1138}
1139
1140
1141static void
1142dispatchRaw(Parcel &p, RequestInfo *pRI) {
1143 int32_t len;
1144 status_t status;
1145 const void *data;
1146
1147 status = p.readInt32(&len);
1148
1149 if (status != NO_ERROR) {
1150 goto invalid;
1151 }
1152
1153 // The java code writes -1 for null arrays
1154 if (((int)len) == -1) {
1155 data = NULL;
1156 len = 0;
1157 }
1158
1159 data = p.readInplace(len);
1160
1161 startRequest;
1162 appendPrintBuf("%sraw_size=%d", printBuf, len);
1163 closeRequest;
1164 printRequest(pRI->token, pRI->pCI->requestNumber);
1165
Howard Sue32dbfd2015-01-07 15:55:57 +08001166 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<void *>(data), len, pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001167
1168 return;
1169invalid:
1170 invalidCommandBlock(pRI);
1171 return;
1172}
1173
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001174static status_t
1175constructCdmaSms(Parcel &p, RequestInfo *pRI, RIL_CDMA_SMS_Message& rcsm) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001176 int32_t t;
1177 uint8_t ut;
1178 status_t status;
1179 int32_t digitCount;
1180 int digitLimit;
1181
1182 memset(&rcsm, 0, sizeof(rcsm));
1183
1184 status = p.readInt32(&t);
1185 rcsm.uTeleserviceID = (int) t;
1186
1187 status = p.read(&ut,sizeof(ut));
1188 rcsm.bIsServicePresent = (uint8_t) ut;
1189
1190 status = p.readInt32(&t);
1191 rcsm.uServicecategory = (int) t;
1192
1193 status = p.readInt32(&t);
1194 rcsm.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1195
1196 status = p.readInt32(&t);
1197 rcsm.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1198
1199 status = p.readInt32(&t);
1200 rcsm.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1201
1202 status = p.readInt32(&t);
1203 rcsm.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1204
1205 status = p.read(&ut,sizeof(ut));
1206 rcsm.sAddress.number_of_digits= (uint8_t) ut;
1207
1208 digitLimit= MIN((rcsm.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
1209 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1210 status = p.read(&ut,sizeof(ut));
1211 rcsm.sAddress.digits[digitCount] = (uint8_t) ut;
1212 }
1213
1214 status = p.readInt32(&t);
1215 rcsm.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1216
1217 status = p.read(&ut,sizeof(ut));
1218 rcsm.sSubAddress.odd = (uint8_t) ut;
1219
1220 status = p.read(&ut,sizeof(ut));
1221 rcsm.sSubAddress.number_of_digits = (uint8_t) ut;
1222
1223 digitLimit= MIN((rcsm.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
1224 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1225 status = p.read(&ut,sizeof(ut));
1226 rcsm.sSubAddress.digits[digitCount] = (uint8_t) ut;
1227 }
1228
1229 status = p.readInt32(&t);
1230 rcsm.uBearerDataLen = (int) t;
1231
1232 digitLimit= MIN((rcsm.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
1233 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1234 status = p.read(&ut, sizeof(ut));
1235 rcsm.aBearerData[digitCount] = (uint8_t) ut;
1236 }
1237
1238 if (status != NO_ERROR) {
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001239 return status;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001240 }
1241
1242 startRequest;
1243 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
1244 sAddress.digit_mode=%d, sAddress.Number_mode=%d, sAddress.number_type=%d, ",
1245 printBuf, rcsm.uTeleserviceID,rcsm.bIsServicePresent,rcsm.uServicecategory,
1246 rcsm.sAddress.digit_mode, rcsm.sAddress.number_mode,rcsm.sAddress.number_type);
1247 closeRequest;
1248
1249 printRequest(pRI->token, pRI->pCI->requestNumber);
1250
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001251 return status;
1252}
1253
1254static void
1255dispatchCdmaSms(Parcel &p, RequestInfo *pRI) {
1256 RIL_CDMA_SMS_Message rcsm;
1257
Mark Salyzyn961fd022015-04-09 07:18:35 -07001258 RLOGD("dispatchCdmaSms");
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001259 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1260 goto invalid;
1261 }
1262
Howard Sue32dbfd2015-01-07 15:55:57 +08001263 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm),pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001264
1265#ifdef MEMSET_FREED
1266 memset(&rcsm, 0, sizeof(rcsm));
1267#endif
1268
1269 return;
1270
1271invalid:
1272 invalidCommandBlock(pRI);
1273 return;
1274}
1275
1276static void
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001277dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1278 RIL_IMS_SMS_Message rism;
1279 RIL_CDMA_SMS_Message rcsm;
1280
Mark Salyzyn961fd022015-04-09 07:18:35 -07001281 RLOGD("dispatchImsCdmaSms: retry=%d, messageRef=%d", retry, messageRef);
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001282
1283 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1284 goto invalid;
1285 }
1286 memset(&rism, 0, sizeof(rism));
1287 rism.tech = RADIO_TECH_3GPP2;
1288 rism.retry = retry;
1289 rism.messageRef = messageRef;
1290 rism.message.cdmaMessage = &rcsm;
1291
Howard Sue32dbfd2015-01-07 15:55:57 +08001292 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001293 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Howard Sue32dbfd2015-01-07 15:55:57 +08001294 +sizeof(rcsm),pRI, pRI->socket_id);
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001295
1296#ifdef MEMSET_FREED
1297 memset(&rcsm, 0, sizeof(rcsm));
1298 memset(&rism, 0, sizeof(rism));
1299#endif
1300
1301 return;
1302
1303invalid:
1304 invalidCommandBlock(pRI);
1305 return;
1306}
1307
1308static void
1309dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1310 RIL_IMS_SMS_Message rism;
1311 int32_t countStrings;
1312 status_t status;
1313 size_t datalen;
1314 char **pStrings;
Mark Salyzyn961fd022015-04-09 07:18:35 -07001315 RLOGD("dispatchImsGsmSms: retry=%d, messageRef=%d", retry, messageRef);
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001316
1317 status = p.readInt32 (&countStrings);
1318
1319 if (status != NO_ERROR) {
1320 goto invalid;
1321 }
1322
1323 memset(&rism, 0, sizeof(rism));
1324 rism.tech = RADIO_TECH_3GPP;
1325 rism.retry = retry;
1326 rism.messageRef = messageRef;
1327
1328 startRequest;
Howard Sue32dbfd2015-01-07 15:55:57 +08001329 appendPrintBuf("%stech=%d, retry=%d, messageRef=%d, ", printBuf,
1330 (int)rism.tech, (int)rism.retry, rism.messageRef);
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001331 if (countStrings == 0) {
1332 // just some non-null pointer
1333 pStrings = (char **)alloca(sizeof(char *));
1334 datalen = 0;
1335 } else if (((int)countStrings) == -1) {
1336 pStrings = NULL;
1337 datalen = 0;
1338 } else {
1339 datalen = sizeof(char *) * countStrings;
1340
1341 pStrings = (char **)alloca(datalen);
1342
1343 for (int i = 0 ; i < countStrings ; i++) {
1344 pStrings[i] = strdupReadString(p);
1345 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
1346 }
1347 }
1348 removeLastChar;
1349 closeRequest;
1350 printRequest(pRI->token, pRI->pCI->requestNumber);
1351
1352 rism.message.gsmMessage = pStrings;
Howard Sue32dbfd2015-01-07 15:55:57 +08001353 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001354 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Howard Sue32dbfd2015-01-07 15:55:57 +08001355 +datalen, pRI, pRI->socket_id);
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001356
1357 if (pStrings != NULL) {
1358 for (int i = 0 ; i < countStrings ; i++) {
1359#ifdef MEMSET_FREED
1360 memsetString (pStrings[i]);
1361#endif
1362 free(pStrings[i]);
1363 }
1364
1365#ifdef MEMSET_FREED
1366 memset(pStrings, 0, datalen);
1367#endif
1368 }
1369
1370#ifdef MEMSET_FREED
1371 memset(&rism, 0, sizeof(rism));
1372#endif
1373 return;
1374invalid:
1375 ALOGE("dispatchImsGsmSms invalid block");
1376 invalidCommandBlock(pRI);
1377 return;
1378}
1379
1380static void
1381dispatchImsSms(Parcel &p, RequestInfo *pRI) {
1382 int32_t t;
1383 status_t status = p.readInt32(&t);
1384 RIL_RadioTechnologyFamily format;
1385 uint8_t retry;
1386 int32_t messageRef;
1387
Mark Salyzyn961fd022015-04-09 07:18:35 -07001388 RLOGD("dispatchImsSms");
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001389 if (status != NO_ERROR) {
1390 goto invalid;
1391 }
1392 format = (RIL_RadioTechnologyFamily) t;
1393
1394 // read retry field
1395 status = p.read(&retry,sizeof(retry));
1396 if (status != NO_ERROR) {
1397 goto invalid;
1398 }
1399 // read messageRef field
1400 status = p.read(&messageRef,sizeof(messageRef));
1401 if (status != NO_ERROR) {
1402 goto invalid;
1403 }
1404
1405 if (RADIO_TECH_3GPP == format) {
1406 dispatchImsGsmSms(p, pRI, retry, messageRef);
1407 } else if (RADIO_TECH_3GPP2 == format) {
1408 dispatchImsCdmaSms(p, pRI, retry, messageRef);
1409 } else {
1410 ALOGE("requestImsSendSMS invalid format value =%d", format);
1411 }
1412
1413 return;
1414
1415invalid:
1416 invalidCommandBlock(pRI);
1417 return;
1418}
1419
1420static void
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001421dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI) {
1422 RIL_CDMA_SMS_Ack rcsa;
1423 int32_t t;
1424 status_t status;
1425 int32_t digitCount;
1426
Mark Salyzyn961fd022015-04-09 07:18:35 -07001427 RLOGD("dispatchCdmaSmsAck");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001428 memset(&rcsa, 0, sizeof(rcsa));
1429
1430 status = p.readInt32(&t);
1431 rcsa.uErrorClass = (RIL_CDMA_SMS_ErrorClass) t;
1432
1433 status = p.readInt32(&t);
1434 rcsa.uSMSCauseCode = (int) t;
1435
1436 if (status != NO_ERROR) {
1437 goto invalid;
1438 }
1439
1440 startRequest;
1441 appendPrintBuf("%suErrorClass=%d, uTLStatus=%d, ",
1442 printBuf, rcsa.uErrorClass, rcsa.uSMSCauseCode);
1443 closeRequest;
1444
1445 printRequest(pRI->token, pRI->pCI->requestNumber);
1446
Howard Sue32dbfd2015-01-07 15:55:57 +08001447 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsa, sizeof(rcsa),pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001448
1449#ifdef MEMSET_FREED
1450 memset(&rcsa, 0, sizeof(rcsa));
1451#endif
1452
1453 return;
1454
1455invalid:
1456 invalidCommandBlock(pRI);
1457 return;
1458}
1459
1460static void
1461dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1462 int32_t t;
1463 status_t status;
1464 int32_t num;
1465
1466 status = p.readInt32(&num);
1467 if (status != NO_ERROR) {
1468 goto invalid;
1469 }
1470
Ethan Chend6e30652013-08-04 22:49:56 -07001471 {
1472 RIL_GSM_BroadcastSmsConfigInfo gsmBci[num];
1473 RIL_GSM_BroadcastSmsConfigInfo *gsmBciPtrs[num];
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001474
Ethan Chend6e30652013-08-04 22:49:56 -07001475 startRequest;
1476 for (int i = 0 ; i < num ; i++ ) {
1477 gsmBciPtrs[i] = &gsmBci[i];
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001478
Ethan Chend6e30652013-08-04 22:49:56 -07001479 status = p.readInt32(&t);
1480 gsmBci[i].fromServiceId = (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].toServiceId = (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].fromCodeScheme = (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].toCodeScheme = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001490
Ethan Chend6e30652013-08-04 22:49:56 -07001491 status = p.readInt32(&t);
1492 gsmBci[i].selected = (uint8_t) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001493
Ethan Chend6e30652013-08-04 22:49:56 -07001494 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId =%d, \
1495 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]", printBuf, i,
1496 gsmBci[i].fromServiceId, gsmBci[i].toServiceId,
1497 gsmBci[i].fromCodeScheme, gsmBci[i].toCodeScheme,
1498 gsmBci[i].selected);
1499 }
1500 closeRequest;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001501
Ethan Chend6e30652013-08-04 22:49:56 -07001502 if (status != NO_ERROR) {
1503 goto invalid;
1504 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001505
Howard Sue32dbfd2015-01-07 15:55:57 +08001506 CALL_ONREQUEST(pRI->pCI->requestNumber,
Ethan Chend6e30652013-08-04 22:49:56 -07001507 gsmBciPtrs,
1508 num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *),
Howard Sue32dbfd2015-01-07 15:55:57 +08001509 pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001510
1511#ifdef MEMSET_FREED
Ethan Chend6e30652013-08-04 22:49:56 -07001512 memset(gsmBci, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo));
1513 memset(gsmBciPtrs, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001514#endif
Ethan Chend6e30652013-08-04 22:49:56 -07001515 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001516
1517 return;
1518
1519invalid:
1520 invalidCommandBlock(pRI);
1521 return;
1522}
1523
1524static void
1525dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1526 int32_t t;
1527 status_t status;
1528 int32_t num;
1529
1530 status = p.readInt32(&num);
1531 if (status != NO_ERROR) {
1532 goto invalid;
1533 }
1534
Ethan Chend6e30652013-08-04 22:49:56 -07001535 {
1536 RIL_CDMA_BroadcastSmsConfigInfo cdmaBci[num];
1537 RIL_CDMA_BroadcastSmsConfigInfo *cdmaBciPtrs[num];
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001538
Ethan Chend6e30652013-08-04 22:49:56 -07001539 startRequest;
1540 for (int i = 0 ; i < num ; i++ ) {
1541 cdmaBciPtrs[i] = &cdmaBci[i];
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001542
Ethan Chend6e30652013-08-04 22:49:56 -07001543 status = p.readInt32(&t);
1544 cdmaBci[i].service_category = (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].language = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001548
Ethan Chend6e30652013-08-04 22:49:56 -07001549 status = p.readInt32(&t);
1550 cdmaBci[i].selected = (uint8_t) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001551
Ethan Chend6e30652013-08-04 22:49:56 -07001552 appendPrintBuf("%s [%d: service_category=%d, language =%d, \
1553 entries.bSelected =%d]", printBuf, i, cdmaBci[i].service_category,
1554 cdmaBci[i].language, cdmaBci[i].selected);
1555 }
1556 closeRequest;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001557
Ethan Chend6e30652013-08-04 22:49:56 -07001558 if (status != NO_ERROR) {
1559 goto invalid;
1560 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001561
Howard Sue32dbfd2015-01-07 15:55:57 +08001562 CALL_ONREQUEST(pRI->pCI->requestNumber,
Ethan Chend6e30652013-08-04 22:49:56 -07001563 cdmaBciPtrs,
1564 num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *),
Howard Sue32dbfd2015-01-07 15:55:57 +08001565 pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001566
1567#ifdef MEMSET_FREED
Ethan Chend6e30652013-08-04 22:49:56 -07001568 memset(cdmaBci, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo));
1569 memset(cdmaBciPtrs, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001570#endif
Ethan Chend6e30652013-08-04 22:49:56 -07001571 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001572
1573 return;
1574
1575invalid:
1576 invalidCommandBlock(pRI);
1577 return;
1578}
1579
1580static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI) {
1581 RIL_CDMA_SMS_WriteArgs rcsw;
1582 int32_t t;
1583 uint32_t ut;
1584 uint8_t uct;
1585 status_t status;
1586 int32_t digitCount;
1587
1588 memset(&rcsw, 0, sizeof(rcsw));
1589
1590 status = p.readInt32(&t);
1591 rcsw.status = t;
1592
1593 status = p.readInt32(&t);
1594 rcsw.message.uTeleserviceID = (int) t;
1595
1596 status = p.read(&uct,sizeof(uct));
1597 rcsw.message.bIsServicePresent = (uint8_t) uct;
1598
1599 status = p.readInt32(&t);
1600 rcsw.message.uServicecategory = (int) t;
1601
1602 status = p.readInt32(&t);
1603 rcsw.message.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1604
1605 status = p.readInt32(&t);
1606 rcsw.message.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1607
1608 status = p.readInt32(&t);
1609 rcsw.message.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1610
1611 status = p.readInt32(&t);
1612 rcsw.message.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1613
1614 status = p.read(&uct,sizeof(uct));
1615 rcsw.message.sAddress.number_of_digits = (uint8_t) uct;
1616
1617 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_ADDRESS_MAX; digitCount ++) {
1618 status = p.read(&uct,sizeof(uct));
1619 rcsw.message.sAddress.digits[digitCount] = (uint8_t) uct;
1620 }
1621
1622 status = p.readInt32(&t);
1623 rcsw.message.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1624
1625 status = p.read(&uct,sizeof(uct));
1626 rcsw.message.sSubAddress.odd = (uint8_t) uct;
1627
1628 status = p.read(&uct,sizeof(uct));
1629 rcsw.message.sSubAddress.number_of_digits = (uint8_t) uct;
1630
1631 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_SUBADDRESS_MAX; digitCount ++) {
1632 status = p.read(&uct,sizeof(uct));
1633 rcsw.message.sSubAddress.digits[digitCount] = (uint8_t) uct;
1634 }
1635
1636 status = p.readInt32(&t);
1637 rcsw.message.uBearerDataLen = (int) t;
1638
1639 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_BEARER_DATA_MAX; digitCount ++) {
1640 status = p.read(&uct, sizeof(uct));
1641 rcsw.message.aBearerData[digitCount] = (uint8_t) uct;
1642 }
1643
1644 if (status != NO_ERROR) {
1645 goto invalid;
1646 }
1647
1648 startRequest;
1649 appendPrintBuf("%sstatus=%d, message.uTeleserviceID=%d, message.bIsServicePresent=%d, \
1650 message.uServicecategory=%d, message.sAddress.digit_mode=%d, \
1651 message.sAddress.number_mode=%d, \
1652 message.sAddress.number_type=%d, ",
1653 printBuf, rcsw.status, rcsw.message.uTeleserviceID, rcsw.message.bIsServicePresent,
1654 rcsw.message.uServicecategory, rcsw.message.sAddress.digit_mode,
1655 rcsw.message.sAddress.number_mode,
1656 rcsw.message.sAddress.number_type);
1657 closeRequest;
1658
1659 printRequest(pRI->token, pRI->pCI->requestNumber);
1660
Howard Sue32dbfd2015-01-07 15:55:57 +08001661 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsw, sizeof(rcsw),pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001662
1663#ifdef MEMSET_FREED
1664 memset(&rcsw, 0, sizeof(rcsw));
1665#endif
1666
1667 return;
1668
1669invalid:
1670 invalidCommandBlock(pRI);
1671 return;
1672
1673}
1674
Ethan Chend6e30652013-08-04 22:49:56 -07001675// For backwards compatibility in RIL_REQUEST_SETUP_DATA_CALL.
1676// Version 4 of the RIL interface adds a new PDP type parameter to support
1677// IPv6 and dual-stack PDP contexts. When dealing with a previous version of
1678// RIL, remove the parameter from the request.
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001679static void dispatchDataCall(Parcel& p, RequestInfo *pRI) {
Ethan Chend6e30652013-08-04 22:49:56 -07001680 // In RIL v3, REQUEST_SETUP_DATA_CALL takes 6 parameters.
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001681 const int numParamsRilV3 = 6;
1682
Ethan Chend6e30652013-08-04 22:49:56 -07001683 // The first bytes of the RIL parcel contain the request number and the
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001684 // serial number - see processCommandBuffer(). Copy them over too.
1685 int pos = p.dataPosition();
1686
1687 int numParams = p.readInt32();
1688 if (s_callbacks.version < 4 && numParams > numParamsRilV3) {
1689 Parcel p2;
1690 p2.appendFrom(&p, 0, pos);
1691 p2.writeInt32(numParamsRilV3);
1692 for(int i = 0; i < numParamsRilV3; i++) {
1693 p2.writeString16(p.readString16());
1694 }
1695 p2.setDataPosition(pos);
1696 dispatchStrings(p2, pRI);
1697 } else {
1698 p.setDataPosition(pos);
1699 dispatchStrings(p, pRI);
1700 }
1701}
1702
1703// For backwards compatibility with RILs that dont support RIL_REQUEST_VOICE_RADIO_TECH.
Ethan Chend6e30652013-08-04 22:49:56 -07001704// When all RILs handle this request, this function can be removed and
1705// the request can be sent directly to the RIL using dispatchVoid.
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001706static void dispatchVoiceRadioTech(Parcel& p, RequestInfo *pRI) {
Howard Sue32dbfd2015-01-07 15:55:57 +08001707 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001708
1709 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1710 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1711 }
1712
Ethan Chend6e30652013-08-04 22:49:56 -07001713 // RILs that support RADIO_STATE_ON should support this request.
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001714 if (RADIO_STATE_ON == state) {
1715 dispatchVoid(p, pRI);
1716 return;
1717 }
1718
Ethan Chend6e30652013-08-04 22:49:56 -07001719 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1720 // will not support this new request either and decode Voice Radio Technology
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001721 // from Radio State
1722 voiceRadioTech = decodeVoiceRadioTechnology(state);
1723
1724 if (voiceRadioTech < 0)
1725 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1726 else
1727 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &voiceRadioTech, sizeof(int));
1728}
1729
Ethan Chend6e30652013-08-04 22:49:56 -07001730// For backwards compatibility in RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE:.
1731// When all RILs handle this request, this function can be removed and
1732// the request can be sent directly to the RIL using dispatchVoid.
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001733static void dispatchCdmaSubscriptionSource(Parcel& p, RequestInfo *pRI) {
Howard Sue32dbfd2015-01-07 15:55:57 +08001734 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001735
1736 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1737 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1738 }
1739
1740 // RILs that support RADIO_STATE_ON should support this request.
1741 if (RADIO_STATE_ON == state) {
1742 dispatchVoid(p, pRI);
1743 return;
1744 }
1745
Ethan Chend6e30652013-08-04 22:49:56 -07001746 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001747 // will not support this new request either and decode CDMA Subscription Source
Ethan Chend6e30652013-08-04 22:49:56 -07001748 // from Radio State
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001749 cdmaSubscriptionSource = decodeCdmaSubscriptionSource(state);
1750
1751 if (cdmaSubscriptionSource < 0)
1752 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1753 else
1754 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &cdmaSubscriptionSource, sizeof(int));
1755}
1756
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001757static void dispatchSetInitialAttachApn(Parcel &p, RequestInfo *pRI)
1758{
1759 RIL_InitialAttachApn pf;
1760 int32_t t;
1761 status_t status;
1762
1763 memset(&pf, 0, sizeof(pf));
1764
1765 pf.apn = strdupReadString(p);
1766 pf.protocol = strdupReadString(p);
1767
1768 status = p.readInt32(&t);
1769 pf.authtype = (int) t;
1770
1771 pf.username = strdupReadString(p);
1772 pf.password = strdupReadString(p);
1773
1774 startRequest;
1775 appendPrintBuf("%sapn=%s, protocol=%s, auth_type=%d, username=%s, password=%s",
Andreas Schneidera8d09502015-06-23 18:41:38 +02001776 printBuf, pf.apn, pf.protocol, pf.authtype, pf.username, pf.password);
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001777 closeRequest;
1778 printRequest(pRI->token, pRI->pCI->requestNumber);
1779
1780 if (status != NO_ERROR) {
1781 goto invalid;
1782 }
Howard Sue32dbfd2015-01-07 15:55:57 +08001783 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001784
1785#ifdef MEMSET_FREED
1786 memsetString(pf.apn);
1787 memsetString(pf.protocol);
1788 memsetString(pf.username);
1789 memsetString(pf.password);
1790#endif
1791
1792 free(pf.apn);
1793 free(pf.protocol);
1794 free(pf.username);
1795 free(pf.password);
1796
1797#ifdef MEMSET_FREED
1798 memset(&pf, 0, sizeof(pf));
1799#endif
1800
1801 return;
1802invalid:
1803 invalidCommandBlock(pRI);
1804 return;
1805}
1806
Howard Sue32dbfd2015-01-07 15:55:57 +08001807static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI) {
1808 RIL_NV_ReadItem nvri;
1809 int32_t t;
1810 status_t status;
1811
1812 memset(&nvri, 0, sizeof(nvri));
1813
1814 status = p.readInt32(&t);
1815 nvri.itemID = (RIL_NV_Item) t;
1816
1817 if (status != NO_ERROR) {
1818 goto invalid;
1819 }
1820
1821 startRequest;
1822 appendPrintBuf("%snvri.itemID=%d, ", printBuf, nvri.itemID);
1823 closeRequest;
1824
1825 printRequest(pRI->token, pRI->pCI->requestNumber);
1826
1827 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvri, sizeof(nvri), pRI, pRI->socket_id);
1828
1829#ifdef MEMSET_FREED
1830 memset(&nvri, 0, sizeof(nvri));
1831#endif
1832
1833 return;
1834
1835invalid:
1836 invalidCommandBlock(pRI);
1837 return;
1838}
1839
1840static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI) {
1841 RIL_NV_WriteItem nvwi;
1842 int32_t t;
1843 status_t status;
1844
1845 memset(&nvwi, 0, sizeof(nvwi));
1846
1847 status = p.readInt32(&t);
1848 nvwi.itemID = (RIL_NV_Item) t;
1849
1850 nvwi.value = strdupReadString(p);
1851
1852 if (status != NO_ERROR || nvwi.value == NULL) {
1853 goto invalid;
1854 }
1855
1856 startRequest;
1857 appendPrintBuf("%snvwi.itemID=%d, value=%s, ", printBuf, nvwi.itemID,
1858 nvwi.value);
1859 closeRequest;
1860
1861 printRequest(pRI->token, pRI->pCI->requestNumber);
1862
1863 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvwi, sizeof(nvwi), pRI, pRI->socket_id);
1864
1865#ifdef MEMSET_FREED
1866 memsetString(nvwi.value);
1867#endif
1868
1869 free(nvwi.value);
1870
1871#ifdef MEMSET_FREED
1872 memset(&nvwi, 0, sizeof(nvwi));
1873#endif
1874
1875 return;
1876
1877invalid:
1878 invalidCommandBlock(pRI);
1879 return;
1880}
1881
1882
1883static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI) {
1884 RIL_SelectUiccSub uicc_sub;
1885 status_t status;
1886 int32_t t;
1887 memset(&uicc_sub, 0, sizeof(uicc_sub));
1888
1889 status = p.readInt32(&t);
1890 if (status != NO_ERROR) {
1891 goto invalid;
1892 }
1893 uicc_sub.slot = (int) t;
1894
1895 status = p.readInt32(&t);
1896 if (status != NO_ERROR) {
1897 goto invalid;
1898 }
1899 uicc_sub.app_index = (int) t;
1900
1901 status = p.readInt32(&t);
1902 if (status != NO_ERROR) {
1903 goto invalid;
1904 }
1905 uicc_sub.sub_type = (RIL_SubscriptionType) t;
1906
1907 status = p.readInt32(&t);
1908 if (status != NO_ERROR) {
1909 goto invalid;
1910 }
1911 uicc_sub.act_status = (RIL_UiccSubActStatus) t;
1912
1913 startRequest;
1914 appendPrintBuf("slot=%d, app_index=%d, act_status = %d", uicc_sub.slot, uicc_sub.app_index,
1915 uicc_sub.act_status);
1916 RLOGD("dispatchUiccSubscription, slot=%d, app_index=%d, act_status = %d", uicc_sub.slot,
1917 uicc_sub.app_index, uicc_sub.act_status);
1918 closeRequest;
1919 printRequest(pRI->token, pRI->pCI->requestNumber);
1920
1921 CALL_ONREQUEST(pRI->pCI->requestNumber, &uicc_sub, sizeof(uicc_sub), pRI, pRI->socket_id);
1922
1923#ifdef MEMSET_FREED
1924 memset(&uicc_sub, 0, sizeof(uicc_sub));
1925#endif
1926 return;
1927
1928invalid:
1929 invalidCommandBlock(pRI);
1930 return;
1931}
1932
1933static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI)
1934{
1935 RIL_SimAuthentication pf;
1936 int32_t t;
1937 status_t status;
1938
1939 memset(&pf, 0, sizeof(pf));
1940
1941 status = p.readInt32(&t);
1942 pf.authContext = (int) t;
1943 pf.authData = strdupReadString(p);
1944 pf.aid = strdupReadString(p);
1945
1946 startRequest;
Andreas Schneidera8d09502015-06-23 18:41:38 +02001947 appendPrintBuf("authContext=%d, authData=%s, aid=%s", pf.authContext, pf.authData, pf.aid);
Howard Sue32dbfd2015-01-07 15:55:57 +08001948 closeRequest;
1949 printRequest(pRI->token, pRI->pCI->requestNumber);
1950
1951 if (status != NO_ERROR) {
1952 goto invalid;
1953 }
1954 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
1955
1956#ifdef MEMSET_FREED
1957 memsetString(pf.authData);
1958 memsetString(pf.aid);
1959#endif
1960
1961 free(pf.authData);
1962 free(pf.aid);
1963
1964#ifdef MEMSET_FREED
1965 memset(&pf, 0, sizeof(pf));
1966#endif
1967
1968 return;
1969invalid:
1970 invalidCommandBlock(pRI);
1971 return;
1972}
1973
1974static void dispatchDataProfile(Parcel &p, RequestInfo *pRI) {
1975 int32_t t;
1976 status_t status;
1977 int32_t num;
1978
1979 status = p.readInt32(&num);
1980 if (status != NO_ERROR) {
1981 goto invalid;
1982 }
1983
1984 {
1985 RIL_DataProfileInfo dataProfiles[num];
1986 RIL_DataProfileInfo *dataProfilePtrs[num];
1987
1988 startRequest;
1989 for (int i = 0 ; i < num ; i++ ) {
1990 dataProfilePtrs[i] = &dataProfiles[i];
1991
1992 status = p.readInt32(&t);
1993 dataProfiles[i].profileId = (int) t;
1994
1995 dataProfiles[i].apn = strdupReadString(p);
1996 dataProfiles[i].protocol = strdupReadString(p);
1997 status = p.readInt32(&t);
1998 dataProfiles[i].authType = (int) t;
1999
2000 dataProfiles[i].user = strdupReadString(p);
2001 dataProfiles[i].password = strdupReadString(p);
2002
2003 status = p.readInt32(&t);
2004 dataProfiles[i].type = (int) t;
2005
2006 status = p.readInt32(&t);
2007 dataProfiles[i].maxConnsTime = (int) t;
2008 status = p.readInt32(&t);
2009 dataProfiles[i].maxConns = (int) t;
2010 status = p.readInt32(&t);
2011 dataProfiles[i].waitTime = (int) t;
2012
2013 status = p.readInt32(&t);
2014 dataProfiles[i].enabled = (int) t;
2015
2016 appendPrintBuf("%s [%d: profileId=%d, apn =%s, protocol =%s, authType =%d, \
2017 user =%s, password =%s, type =%d, maxConnsTime =%d, maxConns =%d, \
2018 waitTime =%d, enabled =%d]", printBuf, i, dataProfiles[i].profileId,
2019 dataProfiles[i].apn, dataProfiles[i].protocol, dataProfiles[i].authType,
2020 dataProfiles[i].user, dataProfiles[i].password, dataProfiles[i].type,
2021 dataProfiles[i].maxConnsTime, dataProfiles[i].maxConns,
2022 dataProfiles[i].waitTime, dataProfiles[i].enabled);
2023 }
2024 closeRequest;
2025 printRequest(pRI->token, pRI->pCI->requestNumber);
2026
2027 if (status != NO_ERROR) {
2028 goto invalid;
2029 }
2030 CALL_ONREQUEST(pRI->pCI->requestNumber,
2031 dataProfilePtrs,
2032 num * sizeof(RIL_DataProfileInfo *),
2033 pRI, pRI->socket_id);
2034
2035#ifdef MEMSET_FREED
2036 memset(dataProfiles, 0, num * sizeof(RIL_DataProfileInfo));
2037 memset(dataProfilePtrs, 0, num * sizeof(RIL_DataProfileInfo *));
2038#endif
2039 }
2040
2041 return;
2042
2043invalid:
2044 invalidCommandBlock(pRI);
2045 return;
2046}
2047
Howard Subd82ef12015-04-12 10:25:05 +02002048static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI){
2049 RIL_RadioCapability rc;
2050 int32_t t;
2051 status_t status;
2052
2053 memset (&rc, 0, sizeof(RIL_RadioCapability));
2054
2055 status = p.readInt32(&t);
2056 rc.version = (int)t;
2057 if (status != NO_ERROR) {
2058 goto invalid;
2059 }
2060
2061 status = p.readInt32(&t);
2062 rc.session= (int)t;
2063 if (status != NO_ERROR) {
2064 goto invalid;
2065 }
2066
2067 status = p.readInt32(&t);
2068 rc.phase= (int)t;
2069 if (status != NO_ERROR) {
2070 goto invalid;
2071 }
2072
2073 status = p.readInt32(&t);
2074 rc.rat = (int)t;
2075 if (status != NO_ERROR) {
2076 goto invalid;
2077 }
2078
2079 status = readStringFromParcelInplace(p, rc.logicalModemUuid, sizeof(rc.logicalModemUuid));
2080 if (status != NO_ERROR) {
2081 goto invalid;
2082 }
2083
2084 status = p.readInt32(&t);
2085 rc.status = (int)t;
2086
2087 if (status != NO_ERROR) {
2088 goto invalid;
2089 }
2090
2091 startRequest;
2092 appendPrintBuf("%s [version:%d, session:%d, phase:%d, rat:%d, \
Andreas Schneidera8d09502015-06-23 18:41:38 +02002093 logicalModemUuid:%s, status:%d", printBuf, rc.version, rc.session,
2094 rc.phase, rc.rat, rc.logicalModemUuid, rc.status);
Howard Subd82ef12015-04-12 10:25:05 +02002095
2096 closeRequest;
2097 printRequest(pRI->token, pRI->pCI->requestNumber);
2098
2099 CALL_ONREQUEST(pRI->pCI->requestNumber,
2100 &rc,
2101 sizeof(RIL_RadioCapability),
2102 pRI, pRI->socket_id);
2103 return;
2104invalid:
2105 invalidCommandBlock(pRI);
2106 return;
2107}
2108
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002109static int
2110blockingWrite(int fd, const void *buffer, size_t len) {
2111 size_t writeOffset = 0;
2112 const uint8_t *toWrite;
2113
2114 toWrite = (const uint8_t *)buffer;
2115
2116 while (writeOffset < len) {
2117 ssize_t written;
2118 do {
2119 written = write (fd, toWrite + writeOffset,
2120 len - writeOffset);
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002121 } while (written < 0 && ((errno == EINTR) || (errno == EAGAIN)));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002122
2123 if (written >= 0) {
2124 writeOffset += written;
2125 } else { // written < 0
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002126 RLOGE ("RIL Response: unexpected error on write errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002127 close(fd);
2128 return -1;
2129 }
2130 }
Robert Greenwaltbc29c432015-04-29 16:57:39 -07002131#if VDBG
Dheeraj Shettycc231012014-07-02 21:27:57 +02002132 RLOGE("RIL Response bytes written:%d", writeOffset);
Robert Greenwaltbc29c432015-04-29 16:57:39 -07002133#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002134 return 0;
2135}
2136
2137static int
Howard Sue32dbfd2015-01-07 15:55:57 +08002138sendResponseRaw (const void *data, size_t dataSize, RIL_SOCKET_ID socket_id) {
2139 int fd = s_ril_param_socket.fdCommand;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002140 int ret;
2141 uint32_t header;
Howard Sue32dbfd2015-01-07 15:55:57 +08002142 pthread_mutex_t * writeMutexHook = &s_writeMutex;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002143
Robert Greenwaltbc29c432015-04-29 16:57:39 -07002144#if VDBG
Andreas Schneider822b70b2015-10-23 08:36:26 +02002145 RLOGD("Send Response to %s", rilSocketIdToString(socket_id));
Robert Greenwaltbc29c432015-04-29 16:57:39 -07002146#endif
Howard Sue32dbfd2015-01-07 15:55:57 +08002147
2148#if (SIM_COUNT >= 2)
2149 if (socket_id == RIL_SOCKET_2) {
2150 fd = s_ril_param_socket2.fdCommand;
2151 writeMutexHook = &s_writeMutex_socket2;
2152 }
2153#if (SIM_COUNT >= 3)
2154 else if (socket_id == RIL_SOCKET_3) {
2155 fd = s_ril_param_socket3.fdCommand;
2156 writeMutexHook = &s_writeMutex_socket3;
2157 }
2158#endif
2159#if (SIM_COUNT >= 4)
2160 else if (socket_id == RIL_SOCKET_4) {
2161 fd = s_ril_param_socket4.fdCommand;
2162 writeMutexHook = &s_writeMutex_socket4;
2163 }
2164#endif
2165#endif
2166 if (fd < 0) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002167 return -1;
2168 }
2169
Howard Subd82ef12015-04-12 10:25:05 +02002170 if (dataSize > MAX_COMMAND_BYTES) {
2171 RLOGE("RIL: packet larger than %u (%u)",
2172 MAX_COMMAND_BYTES, (unsigned int )dataSize);
2173
2174 return -1;
2175 }
2176
Howard Sue32dbfd2015-01-07 15:55:57 +08002177 pthread_mutex_lock(writeMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002178
2179 header = htonl(dataSize);
2180
2181 ret = blockingWrite(fd, (void *)&header, sizeof(header));
2182
2183 if (ret < 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002184 pthread_mutex_unlock(writeMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002185 return ret;
2186 }
2187
2188 ret = blockingWrite(fd, data, dataSize);
2189
2190 if (ret < 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002191 pthread_mutex_unlock(writeMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002192 return ret;
2193 }
2194
Howard Sue32dbfd2015-01-07 15:55:57 +08002195 pthread_mutex_unlock(writeMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002196
2197 return 0;
2198}
2199
2200static int
Howard Sue32dbfd2015-01-07 15:55:57 +08002201sendResponse (Parcel &p, RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002202 printResponse;
Howard Sue32dbfd2015-01-07 15:55:57 +08002203 return sendResponseRaw(p.data(), p.dataSize(), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002204}
2205
Howard Sue32dbfd2015-01-07 15:55:57 +08002206/** response is an int* pointing to an array of ints */
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002207
2208static int
2209responseInts(Parcel &p, void *response, size_t responselen) {
2210 int numInts;
2211
2212 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002213 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002214 return RIL_ERRNO_INVALID_RESPONSE;
2215 }
2216 if (responselen % sizeof(int) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002217 RLOGE("responseInts: invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002218 (int)responselen, (int)sizeof(int));
2219 return RIL_ERRNO_INVALID_RESPONSE;
2220 }
2221
2222 int *p_int = (int *) response;
2223
Howard Sue32dbfd2015-01-07 15:55:57 +08002224 numInts = responselen / sizeof(int);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002225 p.writeInt32 (numInts);
2226
2227 /* each int*/
2228 startResponse;
2229 for (int i = 0 ; i < numInts ; i++) {
2230 appendPrintBuf("%s%d,", printBuf, p_int[i]);
2231 p.writeInt32(p_int[i]);
2232 }
2233 removeLastChar;
2234 closeResponse;
2235
2236 return 0;
2237}
2238
Daniel Hillenbrandd0b84162015-04-12 11:53:23 +02002239static int
2240responseIntsGetPreferredNetworkType(Parcel &p, void *response, size_t responselen) {
2241 int numInts;
2242
2243 if (response == NULL && responselen != 0) {
2244 RLOGE("invalid response: NULL");
2245 return RIL_ERRNO_INVALID_RESPONSE;
2246 }
2247 if (responselen % sizeof(int) != 0) {
2248 RLOGE("responseInts: invalid response length %d expected multiple of %d\n",
2249 (int)responselen, (int)sizeof(int));
2250 return RIL_ERRNO_INVALID_RESPONSE;
2251 }
2252
2253 int *p_int = (int *) response;
2254
2255 numInts = responselen / sizeof(int);
2256 p.writeInt32 (numInts);
2257
2258 /* each int*/
2259 startResponse;
2260 for (int i = 0 ; i < numInts ; i++) {
2261 if (i == 0 && p_int[0] == 7) {
2262 RLOGD("REQUEST_GET_PREFERRED_NETWORK_TYPE: NETWORK_MODE_GLOBAL => NETWORK_MODE_WCDMA_PREF");
2263 p_int[0] = 0;
2264 }
2265 appendPrintBuf("%s%d,", printBuf, p_int[i]);
2266 p.writeInt32(p_int[i]);
2267 }
2268 removeLastChar;
2269 closeResponse;
2270
2271 return 0;
2272}
2273
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002274/** response is a char **, pointing to an array of char *'s
2275 The parcel will begin with the version */
2276static int responseStringsWithVersion(int version, Parcel &p, void *response, size_t responselen) {
2277 p.writeInt32(version);
2278 return responseStrings(p, response, responselen);
2279}
2280
2281/** response is a char **, pointing to an array of char *'s */
2282static int responseStrings(Parcel &p, void *response, size_t responselen) {
2283 return responseStrings(p, response, responselen, false);
2284}
2285
Utkarsh Guptaf7a63e52015-05-10 16:53:37 +05302286static int responseStringsNetworks(Parcel &p, void *response, size_t responselen) {
2287 return responseStrings(p, response, responselen, true);
2288}
2289
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002290/** response is a char **, pointing to an array of char *'s */
2291static int responseStrings(Parcel &p, void *response, size_t responselen, bool network_search) {
2292 int numStrings;
2293
2294 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002295 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002296 return RIL_ERRNO_INVALID_RESPONSE;
2297 }
2298 if (responselen % sizeof(char *) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002299 RLOGE("responseStrings: invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002300 (int)responselen, (int)sizeof(char *));
2301 return RIL_ERRNO_INVALID_RESPONSE;
2302 }
2303
2304 if (response == NULL) {
2305 p.writeInt32 (0);
2306 } else {
2307 char **p_cur = (char **) response;
2308
2309 numStrings = responselen / sizeof(char *);
Utkarsh Guptaf7a63e52015-05-10 16:53:37 +05302310 if (network_search) {
Andreas Schneiderd806de92015-10-22 16:20:51 +02002311 int32_t QANElements;
2312
2313 /*
2314 * This needs to be set to same value as mQANElements in the RIL
2315 * Telephony class.
2316 */
2317 QANElements = property_get_int32(PROPERTY_QAN_ELEMENTS, 4);
2318 p.writeInt32 ((numStrings / 5) * QANElements);
Utkarsh Guptaf7a63e52015-05-10 16:53:37 +05302319 } else {
2320 p.writeInt32 (numStrings);
2321 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002322
2323 /* each string*/
2324 startResponse;
2325 for (int i = 0 ; i < numStrings ; i++) {
NBruderman72edd422015-06-08 15:54:55 +03002326 if (network_search && ((i + 1) % 5 == 0))
Utkarsh Guptaf7a63e52015-05-10 16:53:37 +05302327 continue;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002328 appendPrintBuf("%s%s,", printBuf, (char*)p_cur[i]);
2329 writeStringToParcel (p, p_cur[i]);
2330 }
2331 removeLastChar;
2332 closeResponse;
2333 }
2334 return 0;
2335}
2336
Howard Subd82ef12015-04-12 10:25:05 +02002337
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002338/**
2339 * NULL strings are accepted
2340 * FIXME currently ignores responselen
2341 */
2342static int responseString(Parcel &p, void *response, size_t responselen) {
2343 /* one string only */
2344 startResponse;
2345 appendPrintBuf("%s%s", printBuf, (char*)response);
2346 closeResponse;
2347
2348 writeStringToParcel(p, (const char *)response);
2349
2350 return 0;
2351}
2352
2353static int responseVoid(Parcel &p, void *response, size_t responselen) {
2354 startResponse;
2355 removeLastChar;
2356 return 0;
2357}
2358
2359static int responseCallList(Parcel &p, void *response, size_t responselen) {
2360 int num;
2361
2362 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002363 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002364 return RIL_ERRNO_INVALID_RESPONSE;
2365 }
2366
2367 if (responselen % sizeof (RIL_Call *) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002368 RLOGE("responseCallList: invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002369 (int)responselen, (int)sizeof (RIL_Call *));
2370 return RIL_ERRNO_INVALID_RESPONSE;
2371 }
2372
2373 startResponse;
2374 /* number of call info's */
2375 num = responselen / sizeof(RIL_Call *);
2376 p.writeInt32(num);
2377
2378 for (int i = 0 ; i < num ; i++) {
2379 RIL_Call *p_cur = ((RIL_Call **) response)[i];
2380 /* each call info */
2381 p.writeInt32(p_cur->state);
2382 p.writeInt32(p_cur->index);
2383 p.writeInt32(p_cur->toa);
2384 p.writeInt32(p_cur->isMpty);
2385 p.writeInt32(p_cur->isMT);
2386 p.writeInt32(p_cur->als);
2387 p.writeInt32(p_cur->isVoice);
Andreas Schneider29472682015-01-01 19:00:04 +01002388
Christopher N. Hesse621e63e2016-02-22 21:57:39 +01002389#ifdef NEEDS_VIDEO_CALL_FIELD
Andreas Schneider29472682015-01-01 19:00:04 +01002390 p.writeInt32(p_cur->isVideo);
Sayd1052772015-12-13 17:25:01 +09002391#endif
Andreas Schneider29472682015-01-01 19:00:04 +01002392
Christopher N. Hesse621e63e2016-02-22 21:57:39 +01002393#ifdef SAMSUNG_NEXT_GEN_MODEM
Andreas Schneider29472682015-01-01 19:00:04 +01002394 /* Pass CallDetails */
2395 p.writeInt32(0);
2396 p.writeInt32(0);
2397 writeStringToParcel(p, "");
2398#endif
2399
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002400 p.writeInt32(p_cur->isVoicePrivacy);
2401 writeStringToParcel(p, p_cur->number);
2402 p.writeInt32(p_cur->numberPresentation);
2403 writeStringToParcel(p, p_cur->name);
2404 p.writeInt32(p_cur->namePresentation);
2405 // Remove when partners upgrade to version 3
2406 if ((s_callbacks.version < 3) || (p_cur->uusInfo == NULL || p_cur->uusInfo->uusData == NULL)) {
2407 p.writeInt32(0); /* UUS Information is absent */
2408 } else {
2409 RIL_UUS_Info *uusInfo = p_cur->uusInfo;
2410 p.writeInt32(1); /* UUS Information is present */
2411 p.writeInt32(uusInfo->uusType);
2412 p.writeInt32(uusInfo->uusDcs);
2413 p.writeInt32(uusInfo->uusLength);
2414 p.write(uusInfo->uusData, uusInfo->uusLength);
2415 }
2416 appendPrintBuf("%s[id=%d,%s,toa=%d,",
2417 printBuf,
2418 p_cur->index,
2419 callStateToString(p_cur->state),
2420 p_cur->toa);
2421 appendPrintBuf("%s%s,%s,als=%d,%s,%s,",
2422 printBuf,
2423 (p_cur->isMpty)?"conf":"norm",
2424 (p_cur->isMT)?"mt":"mo",
2425 p_cur->als,
2426 (p_cur->isVoice)?"voc":"nonvoc",
2427 (p_cur->isVoicePrivacy)?"evp":"noevp");
Christopher N. Hesse621e63e2016-02-22 21:57:39 +01002428#ifdef SAMSUNG_NEXT_GEN_MODEM
Andreas Schneider29472682015-01-01 19:00:04 +01002429 appendPrintBuf("%s,%s,",
2430 printBuf,
2431 (p_cur->isVideo) ? "vid" : "novid");
2432#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002433 appendPrintBuf("%s%s,cli=%d,name='%s',%d]",
2434 printBuf,
2435 p_cur->number,
2436 p_cur->numberPresentation,
2437 p_cur->name,
2438 p_cur->namePresentation);
2439 }
2440 removeLastChar;
2441 closeResponse;
2442
2443 return 0;
2444}
2445
2446static int responseSMS(Parcel &p, void *response, size_t responselen) {
2447 if (response == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002448 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002449 return RIL_ERRNO_INVALID_RESPONSE;
2450 }
2451
2452 if (responselen != sizeof (RIL_SMS_Response) ) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002453 RLOGE("invalid response length %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002454 (int)responselen, (int)sizeof (RIL_SMS_Response));
2455 return RIL_ERRNO_INVALID_RESPONSE;
2456 }
2457
2458 RIL_SMS_Response *p_cur = (RIL_SMS_Response *) response;
2459
2460 p.writeInt32(p_cur->messageRef);
2461 writeStringToParcel(p, p_cur->ackPDU);
2462 p.writeInt32(p_cur->errorCode);
2463
2464 startResponse;
2465 appendPrintBuf("%s%d,%s,%d", printBuf, p_cur->messageRef,
2466 (char*)p_cur->ackPDU, p_cur->errorCode);
2467 closeResponse;
2468
2469 return 0;
2470}
2471
2472static int responseDataCallListV4(Parcel &p, void *response, size_t responselen)
2473{
2474 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002475 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002476 return RIL_ERRNO_INVALID_RESPONSE;
2477 }
2478
2479 if (responselen % sizeof(RIL_Data_Call_Response_v4) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002480 RLOGE("responseDataCallListV4: invalid response length %d expected multiple of %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002481 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v4));
2482 return RIL_ERRNO_INVALID_RESPONSE;
2483 }
2484
Howard Sue32dbfd2015-01-07 15:55:57 +08002485 // Write version
2486 p.writeInt32(4);
2487
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002488 int num = responselen / sizeof(RIL_Data_Call_Response_v4);
2489 p.writeInt32(num);
2490
2491 RIL_Data_Call_Response_v4 *p_cur = (RIL_Data_Call_Response_v4 *) response;
2492 startResponse;
2493 int i;
2494 for (i = 0; i < num; i++) {
2495 p.writeInt32(p_cur[i].cid);
2496 p.writeInt32(p_cur[i].active);
2497 writeStringToParcel(p, p_cur[i].type);
2498 // apn is not used, so don't send.
2499 writeStringToParcel(p, p_cur[i].address);
2500 appendPrintBuf("%s[cid=%d,%s,%s,%s],", printBuf,
2501 p_cur[i].cid,
2502 (p_cur[i].active==0)?"down":"up",
2503 (char*)p_cur[i].type,
2504 (char*)p_cur[i].address);
2505 }
2506 removeLastChar;
2507 closeResponse;
2508
2509 return 0;
2510}
2511
Howard Sue32dbfd2015-01-07 15:55:57 +08002512static int responseDataCallListV6(Parcel &p, void *response, size_t responselen)
2513{
2514 if (response == NULL && responselen != 0) {
2515 RLOGE("invalid response: NULL");
2516 return RIL_ERRNO_INVALID_RESPONSE;
2517 }
2518
2519 if (responselen % sizeof(RIL_Data_Call_Response_v6) != 0) {
2520 RLOGE("responseDataCallListV6: invalid response length %d expected multiple of %d",
2521 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v6));
2522 return RIL_ERRNO_INVALID_RESPONSE;
2523 }
2524
2525 // Write version
2526 p.writeInt32(6);
2527
2528 int num = responselen / sizeof(RIL_Data_Call_Response_v6);
2529 p.writeInt32(num);
2530
2531 RIL_Data_Call_Response_v6 *p_cur = (RIL_Data_Call_Response_v6 *) response;
2532 startResponse;
2533 int i;
2534 for (i = 0; i < num; i++) {
2535 p.writeInt32((int)p_cur[i].status);
2536 p.writeInt32(p_cur[i].suggestedRetryTime);
2537 p.writeInt32(p_cur[i].cid);
2538 p.writeInt32(p_cur[i].active);
2539 writeStringToParcel(p, p_cur[i].type);
2540 writeStringToParcel(p, p_cur[i].ifname);
2541 writeStringToParcel(p, p_cur[i].addresses);
2542 writeStringToParcel(p, p_cur[i].dnses);
2543 writeStringToParcel(p, p_cur[i].addresses);
2544 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s],", printBuf,
2545 p_cur[i].status,
2546 p_cur[i].suggestedRetryTime,
2547 p_cur[i].cid,
2548 (p_cur[i].active==0)?"down":"up",
2549 (char*)p_cur[i].type,
2550 (char*)p_cur[i].ifname,
2551 (char*)p_cur[i].addresses,
2552 (char*)p_cur[i].dnses,
2553 (char*)p_cur[i].addresses);
2554 }
2555 removeLastChar;
2556 closeResponse;
2557
2558 return 0;
2559}
2560
Howard Subd82ef12015-04-12 10:25:05 +02002561static int responseDataCallListV9(Parcel &p, void *response, size_t responselen)
2562{
2563 if (response == NULL && responselen != 0) {
2564 RLOGE("invalid response: NULL");
2565 return RIL_ERRNO_INVALID_RESPONSE;
2566 }
2567
2568 if (responselen % sizeof(RIL_Data_Call_Response_v9) != 0) {
2569 RLOGE("responseDataCallListV9: invalid response length %d expected multiple of %d",
2570 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v9));
2571 return RIL_ERRNO_INVALID_RESPONSE;
2572 }
2573
2574 // Write version
2575 p.writeInt32(10);
2576
2577 int num = responselen / sizeof(RIL_Data_Call_Response_v9);
2578 p.writeInt32(num);
2579
2580 RIL_Data_Call_Response_v9 *p_cur = (RIL_Data_Call_Response_v9 *) response;
2581 startResponse;
2582 int i;
2583 for (i = 0; i < num; i++) {
2584 p.writeInt32((int)p_cur[i].status);
2585 p.writeInt32(p_cur[i].suggestedRetryTime);
2586 p.writeInt32(p_cur[i].cid);
2587 p.writeInt32(p_cur[i].active);
2588 writeStringToParcel(p, p_cur[i].type);
2589 writeStringToParcel(p, p_cur[i].ifname);
2590 writeStringToParcel(p, p_cur[i].addresses);
2591 writeStringToParcel(p, p_cur[i].dnses);
2592 writeStringToParcel(p, p_cur[i].gateways);
2593 writeStringToParcel(p, p_cur[i].pcscf);
2594 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s],", printBuf,
2595 p_cur[i].status,
2596 p_cur[i].suggestedRetryTime,
2597 p_cur[i].cid,
2598 (p_cur[i].active==0)?"down":"up",
2599 (char*)p_cur[i].type,
2600 (char*)p_cur[i].ifname,
2601 (char*)p_cur[i].addresses,
2602 (char*)p_cur[i].dnses,
2603 (char*)p_cur[i].gateways,
2604 (char*)p_cur[i].pcscf);
2605 }
2606 removeLastChar;
2607 closeResponse;
2608
2609 return 0;
2610}
2611
2612
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002613static int responseDataCallList(Parcel &p, void *response, size_t responselen)
2614{
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002615 if (s_callbacks.version < 5) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002616 RLOGD("responseDataCallList: v4");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002617 return responseDataCallListV4(p, response, responselen);
Howard Subd82ef12015-04-12 10:25:05 +02002618 } else if (responselen % sizeof(RIL_Data_Call_Response_v6) == 0) {
2619 return responseDataCallListV6(p, response, responselen);
2620 } else if (responselen % sizeof(RIL_Data_Call_Response_v9) == 0) {
2621 return responseDataCallListV9(p, response, responselen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002622 } else {
2623 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002624 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002625 return RIL_ERRNO_INVALID_RESPONSE;
2626 }
2627
Howard Subd82ef12015-04-12 10:25:05 +02002628 if (responselen % sizeof(RIL_Data_Call_Response_v11) != 0) {
2629 RLOGE("invalid response length %d expected multiple of %d",
2630 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v11));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002631 return RIL_ERRNO_INVALID_RESPONSE;
2632 }
2633
Howard Sue32dbfd2015-01-07 15:55:57 +08002634 // Write version
Howard Subd82ef12015-04-12 10:25:05 +02002635 p.writeInt32(11);
Howard Sue32dbfd2015-01-07 15:55:57 +08002636
Howard Subd82ef12015-04-12 10:25:05 +02002637 int num = responselen / sizeof(RIL_Data_Call_Response_v11);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002638 p.writeInt32(num);
2639
Howard Subd82ef12015-04-12 10:25:05 +02002640 RIL_Data_Call_Response_v11 *p_cur = (RIL_Data_Call_Response_v11 *) response;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002641 startResponse;
2642 int i;
2643 for (i = 0; i < num; i++) {
2644 p.writeInt32((int)p_cur[i].status);
2645 p.writeInt32(p_cur[i].suggestedRetryTime);
2646 p.writeInt32(p_cur[i].cid);
2647 p.writeInt32(p_cur[i].active);
2648 writeStringToParcel(p, p_cur[i].type);
2649 writeStringToParcel(p, p_cur[i].ifname);
2650 writeStringToParcel(p, p_cur[i].addresses);
2651 writeStringToParcel(p, p_cur[i].dnses);
Howard Sue32dbfd2015-01-07 15:55:57 +08002652 writeStringToParcel(p, p_cur[i].gateways);
2653 writeStringToParcel(p, p_cur[i].pcscf);
Howard Subd82ef12015-04-12 10:25:05 +02002654 p.writeInt32(p_cur[i].mtu);
2655 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 +02002656 p_cur[i].status,
2657 p_cur[i].suggestedRetryTime,
2658 p_cur[i].cid,
2659 (p_cur[i].active==0)?"down":"up",
2660 (char*)p_cur[i].type,
2661 (char*)p_cur[i].ifname,
2662 (char*)p_cur[i].addresses,
2663 (char*)p_cur[i].dnses,
Howard Sue32dbfd2015-01-07 15:55:57 +08002664 (char*)p_cur[i].gateways,
Howard Subd82ef12015-04-12 10:25:05 +02002665 (char*)p_cur[i].pcscf,
2666 p_cur[i].mtu);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002667 }
2668 removeLastChar;
2669 closeResponse;
2670 }
2671
2672 return 0;
2673}
2674
2675static int responseSetupDataCall(Parcel &p, void *response, size_t responselen)
2676{
2677 if (s_callbacks.version < 5) {
2678 return responseStringsWithVersion(s_callbacks.version, p, response, responselen);
2679 } else {
2680 return responseDataCallList(p, response, responselen);
2681 }
2682}
2683
2684static int responseRaw(Parcel &p, void *response, size_t responselen) {
2685 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002686 RLOGE("invalid response: NULL with responselen != 0");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002687 return RIL_ERRNO_INVALID_RESPONSE;
2688 }
2689
2690 // The java code reads -1 size as null byte array
2691 if (response == NULL) {
2692 p.writeInt32(-1);
2693 } else {
2694 p.writeInt32(responselen);
2695 p.write(response, responselen);
2696 }
2697
2698 return 0;
2699}
2700
2701
2702static int responseSIM_IO(Parcel &p, void *response, size_t responselen) {
2703 if (response == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002704 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002705 return RIL_ERRNO_INVALID_RESPONSE;
2706 }
2707
2708 if (responselen != sizeof (RIL_SIM_IO_Response) ) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002709 RLOGE("invalid response length was %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002710 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
2711 return RIL_ERRNO_INVALID_RESPONSE;
2712 }
2713
2714 RIL_SIM_IO_Response *p_cur = (RIL_SIM_IO_Response *) response;
2715 p.writeInt32(p_cur->sw1);
2716 p.writeInt32(p_cur->sw2);
2717 writeStringToParcel(p, p_cur->simResponse);
2718
2719 startResponse;
2720 appendPrintBuf("%ssw1=0x%X,sw2=0x%X,%s", printBuf, p_cur->sw1, p_cur->sw2,
2721 (char*)p_cur->simResponse);
2722 closeResponse;
2723
2724
2725 return 0;
2726}
2727
2728static int responseCallForwards(Parcel &p, void *response, size_t responselen) {
2729 int num;
2730
2731 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002732 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002733 return RIL_ERRNO_INVALID_RESPONSE;
2734 }
2735
2736 if (responselen % sizeof(RIL_CallForwardInfo *) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002737 RLOGE("responseCallForwards: invalid response length %d expected multiple of %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002738 (int)responselen, (int)sizeof(RIL_CallForwardInfo *));
2739 return RIL_ERRNO_INVALID_RESPONSE;
2740 }
2741
2742 /* number of call info's */
2743 num = responselen / sizeof(RIL_CallForwardInfo *);
2744 p.writeInt32(num);
2745
2746 startResponse;
2747 for (int i = 0 ; i < num ; i++) {
2748 RIL_CallForwardInfo *p_cur = ((RIL_CallForwardInfo **) response)[i];
2749
2750 p.writeInt32(p_cur->status);
2751 p.writeInt32(p_cur->reason);
2752 p.writeInt32(p_cur->serviceClass);
2753 p.writeInt32(p_cur->toa);
2754 writeStringToParcel(p, p_cur->number);
2755 p.writeInt32(p_cur->timeSeconds);
2756 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
2757 (p_cur->status==1)?"enable":"disable",
2758 p_cur->reason, p_cur->serviceClass, p_cur->toa,
2759 (char*)p_cur->number,
2760 p_cur->timeSeconds);
2761 }
2762 removeLastChar;
2763 closeResponse;
2764
2765 return 0;
2766}
2767
2768static int responseSsn(Parcel &p, void *response, size_t responselen) {
2769 if (response == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002770 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002771 return RIL_ERRNO_INVALID_RESPONSE;
2772 }
2773
2774 if (responselen != sizeof(RIL_SuppSvcNotification)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002775 RLOGE("invalid response length was %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002776 (int)responselen, (int)sizeof (RIL_SuppSvcNotification));
2777 return RIL_ERRNO_INVALID_RESPONSE;
2778 }
2779
2780 RIL_SuppSvcNotification *p_cur = (RIL_SuppSvcNotification *) response;
2781 p.writeInt32(p_cur->notificationType);
2782 p.writeInt32(p_cur->code);
2783 p.writeInt32(p_cur->index);
2784 p.writeInt32(p_cur->type);
2785 writeStringToParcel(p, p_cur->number);
2786
2787 startResponse;
2788 appendPrintBuf("%s%s,code=%d,id=%d,type=%d,%s", printBuf,
2789 (p_cur->notificationType==0)?"mo":"mt",
2790 p_cur->code, p_cur->index, p_cur->type,
2791 (char*)p_cur->number);
2792 closeResponse;
2793
2794 return 0;
2795}
2796
2797static int responseCellList(Parcel &p, void *response, size_t responselen) {
2798 int num;
2799
2800 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002801 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002802 return RIL_ERRNO_INVALID_RESPONSE;
2803 }
2804
2805 if (responselen % sizeof (RIL_NeighboringCell *) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002806 RLOGE("responseCellList: invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002807 (int)responselen, (int)sizeof (RIL_NeighboringCell *));
2808 return RIL_ERRNO_INVALID_RESPONSE;
2809 }
2810
2811 startResponse;
2812 /* number of records */
2813 num = responselen / sizeof(RIL_NeighboringCell *);
2814 p.writeInt32(num);
2815
2816 for (int i = 0 ; i < num ; i++) {
2817 RIL_NeighboringCell *p_cur = ((RIL_NeighboringCell **) response)[i];
2818
2819 p.writeInt32(p_cur->rssi);
2820 writeStringToParcel (p, p_cur->cid);
2821
2822 appendPrintBuf("%s[cid=%s,rssi=%d],", printBuf,
2823 p_cur->cid, p_cur->rssi);
2824 }
2825 removeLastChar;
2826 closeResponse;
2827
2828 return 0;
2829}
2830
2831/**
2832 * Marshall the signalInfoRecord into the parcel if it exists.
2833 */
2834static void marshallSignalInfoRecord(Parcel &p,
2835 RIL_CDMA_SignalInfoRecord &p_signalInfoRecord) {
2836 p.writeInt32(p_signalInfoRecord.isPresent);
2837 p.writeInt32(p_signalInfoRecord.signalType);
2838 p.writeInt32(p_signalInfoRecord.alertPitch);
2839 p.writeInt32(p_signalInfoRecord.signal);
2840}
2841
2842static int responseCdmaInformationRecords(Parcel &p,
2843 void *response, size_t responselen) {
2844 int num;
2845 char* string8 = NULL;
2846 int buffer_lenght;
2847 RIL_CDMA_InformationRecord *infoRec;
2848
2849 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002850 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002851 return RIL_ERRNO_INVALID_RESPONSE;
2852 }
2853
2854 if (responselen != sizeof (RIL_CDMA_InformationRecords)) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002855 RLOGE("responseCdmaInformationRecords: invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002856 (int)responselen, (int)sizeof (RIL_CDMA_InformationRecords *));
2857 return RIL_ERRNO_INVALID_RESPONSE;
2858 }
2859
2860 RIL_CDMA_InformationRecords *p_cur =
2861 (RIL_CDMA_InformationRecords *) response;
2862 num = MIN(p_cur->numberOfInfoRecs, RIL_CDMA_MAX_NUMBER_OF_INFO_RECS);
2863
2864 startResponse;
2865 p.writeInt32(num);
2866
2867 for (int i = 0 ; i < num ; i++) {
2868 infoRec = &p_cur->infoRec[i];
2869 p.writeInt32(infoRec->name);
2870 switch (infoRec->name) {
2871 case RIL_CDMA_DISPLAY_INFO_REC:
2872 case RIL_CDMA_EXTENDED_DISPLAY_INFO_REC:
2873 if (infoRec->rec.display.alpha_len >
2874 CDMA_ALPHA_INFO_BUFFER_LENGTH) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002875 RLOGE("invalid display info response length %d \
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002876 expected not more than %d\n",
2877 (int)infoRec->rec.display.alpha_len,
2878 CDMA_ALPHA_INFO_BUFFER_LENGTH);
2879 return RIL_ERRNO_INVALID_RESPONSE;
2880 }
2881 string8 = (char*) malloc((infoRec->rec.display.alpha_len + 1)
2882 * sizeof(char) );
2883 for (int i = 0 ; i < infoRec->rec.display.alpha_len ; i++) {
2884 string8[i] = infoRec->rec.display.alpha_buf[i];
2885 }
2886 string8[(int)infoRec->rec.display.alpha_len] = '\0';
2887 writeStringToParcel(p, (const char*)string8);
2888 free(string8);
2889 string8 = NULL;
2890 break;
2891 case RIL_CDMA_CALLED_PARTY_NUMBER_INFO_REC:
2892 case RIL_CDMA_CALLING_PARTY_NUMBER_INFO_REC:
2893 case RIL_CDMA_CONNECTED_NUMBER_INFO_REC:
2894 if (infoRec->rec.number.len > CDMA_NUMBER_INFO_BUFFER_LENGTH) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002895 RLOGE("invalid display info response length %d \
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002896 expected not more than %d\n",
2897 (int)infoRec->rec.number.len,
2898 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2899 return RIL_ERRNO_INVALID_RESPONSE;
2900 }
2901 string8 = (char*) malloc((infoRec->rec.number.len + 1)
2902 * sizeof(char) );
2903 for (int i = 0 ; i < infoRec->rec.number.len; i++) {
2904 string8[i] = infoRec->rec.number.buf[i];
2905 }
2906 string8[(int)infoRec->rec.number.len] = '\0';
2907 writeStringToParcel(p, (const char*)string8);
2908 free(string8);
2909 string8 = NULL;
2910 p.writeInt32(infoRec->rec.number.number_type);
2911 p.writeInt32(infoRec->rec.number.number_plan);
2912 p.writeInt32(infoRec->rec.number.pi);
2913 p.writeInt32(infoRec->rec.number.si);
2914 break;
2915 case RIL_CDMA_SIGNAL_INFO_REC:
2916 p.writeInt32(infoRec->rec.signal.isPresent);
2917 p.writeInt32(infoRec->rec.signal.signalType);
2918 p.writeInt32(infoRec->rec.signal.alertPitch);
2919 p.writeInt32(infoRec->rec.signal.signal);
2920
2921 appendPrintBuf("%sisPresent=%X, signalType=%X, \
2922 alertPitch=%X, signal=%X, ",
2923 printBuf, (int)infoRec->rec.signal.isPresent,
2924 (int)infoRec->rec.signal.signalType,
2925 (int)infoRec->rec.signal.alertPitch,
2926 (int)infoRec->rec.signal.signal);
2927 removeLastChar;
2928 break;
2929 case RIL_CDMA_REDIRECTING_NUMBER_INFO_REC:
2930 if (infoRec->rec.redir.redirectingNumber.len >
2931 CDMA_NUMBER_INFO_BUFFER_LENGTH) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002932 RLOGE("invalid display info response length %d \
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002933 expected not more than %d\n",
2934 (int)infoRec->rec.redir.redirectingNumber.len,
2935 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2936 return RIL_ERRNO_INVALID_RESPONSE;
2937 }
2938 string8 = (char*) malloc((infoRec->rec.redir.redirectingNumber
2939 .len + 1) * sizeof(char) );
2940 for (int i = 0;
2941 i < infoRec->rec.redir.redirectingNumber.len;
2942 i++) {
2943 string8[i] = infoRec->rec.redir.redirectingNumber.buf[i];
2944 }
2945 string8[(int)infoRec->rec.redir.redirectingNumber.len] = '\0';
2946 writeStringToParcel(p, (const char*)string8);
2947 free(string8);
2948 string8 = NULL;
2949 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_type);
2950 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_plan);
2951 p.writeInt32(infoRec->rec.redir.redirectingNumber.pi);
2952 p.writeInt32(infoRec->rec.redir.redirectingNumber.si);
2953 p.writeInt32(infoRec->rec.redir.redirectingReason);
2954 break;
2955 case RIL_CDMA_LINE_CONTROL_INFO_REC:
2956 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPolarityIncluded);
2957 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlToggle);
2958 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlReverse);
2959 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2960
2961 appendPrintBuf("%slineCtrlPolarityIncluded=%d, \
2962 lineCtrlToggle=%d, lineCtrlReverse=%d, \
2963 lineCtrlPowerDenial=%d, ", printBuf,
2964 (int)infoRec->rec.lineCtrl.lineCtrlPolarityIncluded,
2965 (int)infoRec->rec.lineCtrl.lineCtrlToggle,
2966 (int)infoRec->rec.lineCtrl.lineCtrlReverse,
2967 (int)infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2968 removeLastChar;
2969 break;
2970 case RIL_CDMA_T53_CLIR_INFO_REC:
2971 p.writeInt32((int)(infoRec->rec.clir.cause));
2972
2973 appendPrintBuf("%scause%d", printBuf, infoRec->rec.clir.cause);
2974 removeLastChar;
2975 break;
2976 case RIL_CDMA_T53_AUDIO_CONTROL_INFO_REC:
2977 p.writeInt32(infoRec->rec.audioCtrl.upLink);
2978 p.writeInt32(infoRec->rec.audioCtrl.downLink);
2979
2980 appendPrintBuf("%supLink=%d, downLink=%d, ", printBuf,
2981 infoRec->rec.audioCtrl.upLink,
2982 infoRec->rec.audioCtrl.downLink);
2983 removeLastChar;
2984 break;
2985 case RIL_CDMA_T53_RELEASE_INFO_REC:
2986 // TODO(Moto): See David Krause, he has the answer:)
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002987 RLOGE("RIL_CDMA_T53_RELEASE_INFO_REC: return INVALID_RESPONSE");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002988 return RIL_ERRNO_INVALID_RESPONSE;
2989 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002990 RLOGE("Incorrect name value");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002991 return RIL_ERRNO_INVALID_RESPONSE;
2992 }
2993 }
2994 closeResponse;
2995
2996 return 0;
2997}
2998
2999static int responseRilSignalStrength(Parcel &p,
3000 void *response, size_t responselen) {
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303001 int gsmSignalStrength;
3002 int cdmaDbm;
3003 int evdoDbm;
3004
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003005 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003006 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003007 return RIL_ERRNO_INVALID_RESPONSE;
3008 }
3009
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003010 if (responselen >= sizeof (RIL_SignalStrength_v5)) {
Howard Sue32dbfd2015-01-07 15:55:57 +08003011 RIL_SignalStrength_v10 *p_cur = ((RIL_SignalStrength_v10 *) response);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003012
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303013 gsmSignalStrength = p_cur->GW_SignalStrength.signalStrength & 0xFF;
Utkarsh Gupta8ede9fa2015-04-23 13:21:49 +05303014
3015#ifdef MODEM_TYPE_XMM6260
3016 if (gsmSignalStrength < 0 ||
3017 (gsmSignalStrength > 31 && p_cur->GW_SignalStrength.signalStrength != 99)) {
3018 gsmSignalStrength = p_cur->CDMA_SignalStrength.dbm;
3019 }
3020#else
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303021 if (gsmSignalStrength < 0) {
3022 gsmSignalStrength = 99;
3023 } else if (gsmSignalStrength > 31 && gsmSignalStrength != 99) {
3024 gsmSignalStrength = 31;
3025 }
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303026#endif
3027 p.writeInt32(gsmSignalStrength);
3028
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003029 p.writeInt32(p_cur->GW_SignalStrength.bitErrorRate);
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303030
Christopher N. Hesse621e63e2016-02-22 21:57:39 +01003031#if defined(MODEM_TYPE_XMM6262) || defined(SAMSUNG_NEXT_GEN_MODEM)
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303032 cdmaDbm = p_cur->CDMA_SignalStrength.dbm & 0xFF;
3033 if (cdmaDbm < 0) {
3034 cdmaDbm = 99;
3035 } else if (cdmaDbm > 31 && cdmaDbm != 99) {
3036 cdmaDbm = 31;
3037 }
3038#else
Caio Schnepperec042542015-04-14 08:03:43 -03003039 cdmaDbm = p_cur->CDMA_SignalStrength.dbm;
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303040#endif
3041 p.writeInt32(cdmaDbm);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003042 p.writeInt32(p_cur->CDMA_SignalStrength.ecio);
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303043
Christopher N. Hesse621e63e2016-02-22 21:57:39 +01003044#if defined(MODEM_TYPE_XMM6262) || defined(SAMSUNG_NEXT_GEN_MODEM)
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303045 evdoDbm = p_cur->EVDO_SignalStrength.dbm & 0xFF;
3046 if (evdoDbm < 0) {
3047 evdoDbm = 99;
3048 } else if (evdoDbm > 31 && evdoDbm != 99) {
3049 evdoDbm = 31;
3050 }
3051#else
3052 evdoDbm = p_cur->EVDO_SignalStrength.dbm;
3053#endif
3054 p.writeInt32(evdoDbm);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003055 p.writeInt32(p_cur->EVDO_SignalStrength.ecio);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003056 p.writeInt32(p_cur->EVDO_SignalStrength.signalNoiseRatio);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003057 if (responselen >= sizeof (RIL_SignalStrength_v6)) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003058 /*
Ethan Chend6e30652013-08-04 22:49:56 -07003059 * Fixup LTE for backwards compatibility
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003060 */
Ethan Chend6e30652013-08-04 22:49:56 -07003061 if (s_callbacks.version <= 6) {
3062 // signalStrength: -1 -> 99
3063 if (p_cur->LTE_SignalStrength.signalStrength == -1) {
3064 p_cur->LTE_SignalStrength.signalStrength = 99;
3065 }
3066 // rsrp: -1 -> INT_MAX all other negative value to positive.
3067 // So remap here
3068 if (p_cur->LTE_SignalStrength.rsrp == -1) {
3069 p_cur->LTE_SignalStrength.rsrp = INT_MAX;
3070 } else if (p_cur->LTE_SignalStrength.rsrp < -1) {
3071 p_cur->LTE_SignalStrength.rsrp = -p_cur->LTE_SignalStrength.rsrp;
3072 }
3073 // rsrq: -1 -> INT_MAX
3074 if (p_cur->LTE_SignalStrength.rsrq == -1) {
3075 p_cur->LTE_SignalStrength.rsrq = INT_MAX;
3076 }
3077 // Not remapping rssnr is already using INT_MAX
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003078
Ethan Chend6e30652013-08-04 22:49:56 -07003079 // cqi: -1 -> INT_MAX
3080 if (p_cur->LTE_SignalStrength.cqi == -1) {
3081 p_cur->LTE_SignalStrength.cqi = INT_MAX;
3082 }
3083 }
3084 p.writeInt32(p_cur->LTE_SignalStrength.signalStrength);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003085 p.writeInt32(p_cur->LTE_SignalStrength.rsrp);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003086 p.writeInt32(p_cur->LTE_SignalStrength.rsrq);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003087 p.writeInt32(p_cur->LTE_SignalStrength.rssnr);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003088 p.writeInt32(p_cur->LTE_SignalStrength.cqi);
Howard Sue32dbfd2015-01-07 15:55:57 +08003089 if (responselen >= sizeof (RIL_SignalStrength_v10)) {
3090 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
3091 } else {
3092 p.writeInt32(INT_MAX);
3093 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003094 } else {
Ethan Chend6e30652013-08-04 22:49:56 -07003095 p.writeInt32(99);
3096 p.writeInt32(INT_MAX);
3097 p.writeInt32(INT_MAX);
3098 p.writeInt32(INT_MAX);
3099 p.writeInt32(INT_MAX);
Howard Sue32dbfd2015-01-07 15:55:57 +08003100 p.writeInt32(INT_MAX);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003101 }
3102
3103 startResponse;
3104 appendPrintBuf("%s[signalStrength=%d,bitErrorRate=%d,\
3105 CDMA_SS.dbm=%d,CDMA_SSecio=%d,\
3106 EVDO_SS.dbm=%d,EVDO_SS.ecio=%d,\
3107 EVDO_SS.signalNoiseRatio=%d,\
3108 LTE_SS.signalStrength=%d,LTE_SS.rsrp=%d,LTE_SS.rsrq=%d,\
Howard Sue32dbfd2015-01-07 15:55:57 +08003109 LTE_SS.rssnr=%d,LTE_SS.cqi=%d,TDSCDMA_SS.rscp=%d]",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003110 printBuf,
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303111 gsmSignalStrength,
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003112 p_cur->GW_SignalStrength.bitErrorRate,
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303113 cdmaDbm,
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003114 p_cur->CDMA_SignalStrength.ecio,
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303115 evdoDbm,
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003116 p_cur->EVDO_SignalStrength.ecio,
3117 p_cur->EVDO_SignalStrength.signalNoiseRatio,
3118 p_cur->LTE_SignalStrength.signalStrength,
3119 p_cur->LTE_SignalStrength.rsrp,
3120 p_cur->LTE_SignalStrength.rsrq,
3121 p_cur->LTE_SignalStrength.rssnr,
Howard Sue32dbfd2015-01-07 15:55:57 +08003122 p_cur->LTE_SignalStrength.cqi,
3123 p_cur->TD_SCDMA_SignalStrength.rscp);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003124 closeResponse;
3125
3126 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003127 RLOGE("invalid response length");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003128 return RIL_ERRNO_INVALID_RESPONSE;
3129 }
3130
3131 return 0;
3132}
3133
3134static int responseCallRing(Parcel &p, void *response, size_t responselen) {
3135 if ((response == NULL) || (responselen == 0)) {
3136 return responseVoid(p, response, responselen);
3137 } else {
3138 return responseCdmaSignalInfoRecord(p, response, responselen);
3139 }
3140}
3141
3142static int responseCdmaSignalInfoRecord(Parcel &p, void *response, size_t responselen) {
3143 if (response == NULL || responselen == 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003144 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003145 return RIL_ERRNO_INVALID_RESPONSE;
3146 }
3147
3148 if (responselen != sizeof (RIL_CDMA_SignalInfoRecord)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003149 RLOGE("invalid response length %d expected sizeof (RIL_CDMA_SignalInfoRecord) of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003150 (int)responselen, (int)sizeof (RIL_CDMA_SignalInfoRecord));
3151 return RIL_ERRNO_INVALID_RESPONSE;
3152 }
3153
3154 startResponse;
3155
3156 RIL_CDMA_SignalInfoRecord *p_cur = ((RIL_CDMA_SignalInfoRecord *) response);
3157 marshallSignalInfoRecord(p, *p_cur);
3158
3159 appendPrintBuf("%s[isPresent=%d,signalType=%d,alertPitch=%d\
3160 signal=%d]",
3161 printBuf,
3162 p_cur->isPresent,
3163 p_cur->signalType,
3164 p_cur->alertPitch,
3165 p_cur->signal);
3166
3167 closeResponse;
3168 return 0;
3169}
3170
3171static int responseCdmaCallWaiting(Parcel &p, void *response,
3172 size_t responselen) {
3173 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003174 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003175 return RIL_ERRNO_INVALID_RESPONSE;
3176 }
3177
3178 if (responselen < sizeof(RIL_CDMA_CallWaiting_v6)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003179 RLOGW("Upgrade to ril version %d\n", RIL_VERSION);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003180 }
3181
3182 RIL_CDMA_CallWaiting_v6 *p_cur = ((RIL_CDMA_CallWaiting_v6 *) response);
3183
3184 writeStringToParcel(p, p_cur->number);
3185 p.writeInt32(p_cur->numberPresentation);
3186 writeStringToParcel(p, p_cur->name);
3187 marshallSignalInfoRecord(p, p_cur->signalInfoRecord);
3188
3189 if (responselen >= sizeof(RIL_CDMA_CallWaiting_v6)) {
3190 p.writeInt32(p_cur->number_type);
3191 p.writeInt32(p_cur->number_plan);
3192 } else {
3193 p.writeInt32(0);
3194 p.writeInt32(0);
3195 }
3196
3197 startResponse;
3198 appendPrintBuf("%snumber=%s,numberPresentation=%d, name=%s,\
3199 signalInfoRecord[isPresent=%d,signalType=%d,alertPitch=%d\
3200 signal=%d,number_type=%d,number_plan=%d]",
3201 printBuf,
3202 p_cur->number,
3203 p_cur->numberPresentation,
3204 p_cur->name,
3205 p_cur->signalInfoRecord.isPresent,
3206 p_cur->signalInfoRecord.signalType,
3207 p_cur->signalInfoRecord.alertPitch,
3208 p_cur->signalInfoRecord.signal,
3209 p_cur->number_type,
3210 p_cur->number_plan);
3211 closeResponse;
3212
3213 return 0;
3214}
3215
3216static int responseSimRefresh(Parcel &p, void *response, size_t responselen) {
3217 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003218 RLOGE("responseSimRefresh: invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003219 return RIL_ERRNO_INVALID_RESPONSE;
3220 }
3221
3222 startResponse;
3223 if (s_callbacks.version == 7) {
3224 RIL_SimRefreshResponse_v7 *p_cur = ((RIL_SimRefreshResponse_v7 *) response);
3225 p.writeInt32(p_cur->result);
3226 p.writeInt32(p_cur->ef_id);
3227 writeStringToParcel(p, p_cur->aid);
3228
3229 appendPrintBuf("%sresult=%d, ef_id=%d, aid=%s",
3230 printBuf,
3231 p_cur->result,
3232 p_cur->ef_id,
3233 p_cur->aid);
3234 } else {
3235 int *p_cur = ((int *) response);
3236 p.writeInt32(p_cur[0]);
3237 p.writeInt32(p_cur[1]);
3238 writeStringToParcel(p, NULL);
3239
3240 appendPrintBuf("%sresult=%d, ef_id=%d",
3241 printBuf,
3242 p_cur[0],
3243 p_cur[1]);
3244 }
3245 closeResponse;
3246
3247 return 0;
3248}
3249
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003250static int responseCellInfoList(Parcel &p, void *response, size_t responselen)
3251{
3252 if (response == NULL && responselen != 0) {
3253 RLOGE("invalid response: NULL");
3254 return RIL_ERRNO_INVALID_RESPONSE;
3255 }
3256
3257 if (responselen % sizeof(RIL_CellInfo) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08003258 RLOGE("responseCellInfoList: invalid response length %d expected multiple of %d",
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003259 (int)responselen, (int)sizeof(RIL_CellInfo));
3260 return RIL_ERRNO_INVALID_RESPONSE;
3261 }
3262
3263 int num = responselen / sizeof(RIL_CellInfo);
3264 p.writeInt32(num);
3265
3266 RIL_CellInfo *p_cur = (RIL_CellInfo *) response;
3267 startResponse;
3268 int i;
3269 for (i = 0; i < num; i++) {
3270 appendPrintBuf("%s[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", printBuf, i,
3271 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
3272 p.writeInt32((int)p_cur->cellInfoType);
3273 p.writeInt32(p_cur->registered);
3274 p.writeInt32(p_cur->timeStampType);
3275 p.writeInt64(p_cur->timeStamp);
3276 switch(p_cur->cellInfoType) {
3277 case RIL_CELL_INFO_TYPE_GSM: {
3278 appendPrintBuf("%s GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,", printBuf,
3279 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
3280 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
3281 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
3282 p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3283 appendPrintBuf("%s gsmSS: ss=%d,ber=%d],", printBuf,
3284 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
3285 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3286
3287 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
3288 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
3289 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
3290 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3291 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
3292 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3293 break;
3294 }
3295 case RIL_CELL_INFO_TYPE_WCDMA: {
3296 appendPrintBuf("%s WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,", printBuf,
3297 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
3298 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
3299 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
3300 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
3301 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3302 appendPrintBuf("%s wcdmaSS: ss=%d,ber=%d],", printBuf,
3303 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
3304 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3305
3306 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
3307 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
3308 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
3309 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
3310 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3311 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
3312 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3313 break;
3314 }
3315 case RIL_CELL_INFO_TYPE_CDMA: {
3316 appendPrintBuf("%s CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d", printBuf,
3317 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
3318 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
3319 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
3320 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
3321 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3322
3323 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
3324 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
3325 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
3326 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
3327 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3328
3329 appendPrintBuf("%s cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d", printBuf,
3330 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
3331 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
3332 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
3333 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
3334 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3335
3336 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
3337 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
3338 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
3339 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
3340 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3341 break;
3342 }
3343 case RIL_CELL_INFO_TYPE_LTE: {
3344 appendPrintBuf("%s LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d", printBuf,
3345 p_cur->CellInfo.lte.cellIdentityLte.mcc,
3346 p_cur->CellInfo.lte.cellIdentityLte.mnc,
3347 p_cur->CellInfo.lte.cellIdentityLte.ci,
3348 p_cur->CellInfo.lte.cellIdentityLte.pci,
3349 p_cur->CellInfo.lte.cellIdentityLte.tac);
3350
3351 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
3352 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
3353 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
3354 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
3355 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
3356
3357 appendPrintBuf("%s lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d", printBuf,
3358 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
3359 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
3360 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
3361 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
3362 p_cur->CellInfo.lte.signalStrengthLte.cqi,
3363 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3364 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
3365 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
3366 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
3367 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
3368 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
3369 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3370 break;
3371 }
Howard Sue32dbfd2015-01-07 15:55:57 +08003372 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
3373 appendPrintBuf("%s TDSCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,cpid=%d,", printBuf,
3374 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc,
3375 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc,
3376 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac,
3377 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid,
3378 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3379 appendPrintBuf("%s tdscdmaSS: rscp=%d],", printBuf,
3380 p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3381
3382 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
3383 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
3384 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
3385 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
3386 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3387 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3388 break;
3389 }
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003390 }
3391 p_cur += 1;
3392 }
3393 removeLastChar;
3394 closeResponse;
3395
3396 return 0;
3397}
3398
Howard Sue32dbfd2015-01-07 15:55:57 +08003399static int responseHardwareConfig(Parcel &p, void *response, size_t responselen)
3400{
3401 if (response == NULL && responselen != 0) {
3402 RLOGE("invalid response: NULL");
3403 return RIL_ERRNO_INVALID_RESPONSE;
3404 }
3405
3406 if (responselen % sizeof(RIL_HardwareConfig) != 0) {
3407 RLOGE("responseHardwareConfig: invalid response length %d expected multiple of %d",
3408 (int)responselen, (int)sizeof(RIL_HardwareConfig));
3409 return RIL_ERRNO_INVALID_RESPONSE;
3410 }
3411
3412 int num = responselen / sizeof(RIL_HardwareConfig);
3413 int i;
3414 RIL_HardwareConfig *p_cur = (RIL_HardwareConfig *) response;
3415
3416 p.writeInt32(num);
3417
3418 startResponse;
3419 for (i = 0; i < num; i++) {
3420 switch (p_cur[i].type) {
3421 case RIL_HARDWARE_CONFIG_MODEM: {
3422 writeStringToParcel(p, p_cur[i].uuid);
3423 p.writeInt32((int)p_cur[i].state);
3424 p.writeInt32(p_cur[i].cfg.modem.rat);
3425 p.writeInt32(p_cur[i].cfg.modem.maxVoice);
3426 p.writeInt32(p_cur[i].cfg.modem.maxData);
3427 p.writeInt32(p_cur[i].cfg.modem.maxStandby);
3428
3429 appendPrintBuf("%s modem: uuid=%s,state=%d,rat=%08x,maxV=%d,maxD=%d,maxS=%d", printBuf,
3430 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.modem.rat,
3431 p_cur[i].cfg.modem.maxVoice, p_cur[i].cfg.modem.maxData, p_cur[i].cfg.modem.maxStandby);
3432 break;
3433 }
3434 case RIL_HARDWARE_CONFIG_SIM: {
3435 writeStringToParcel(p, p_cur[i].uuid);
3436 p.writeInt32((int)p_cur[i].state);
3437 writeStringToParcel(p, p_cur[i].cfg.sim.modemUuid);
3438
3439 appendPrintBuf("%s sim: uuid=%s,state=%d,modem-uuid=%s", printBuf,
3440 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.sim.modemUuid);
3441 break;
3442 }
3443 }
3444 }
3445 removeLastChar;
3446 closeResponse;
3447 return 0;
3448}
3449
Howard Subd82ef12015-04-12 10:25:05 +02003450static int responseRadioCapability(Parcel &p, void *response, size_t responselen) {
3451 if (response == NULL) {
3452 RLOGE("invalid response: NULL");
3453 return RIL_ERRNO_INVALID_RESPONSE;
3454 }
3455
3456 if (responselen != sizeof (RIL_RadioCapability) ) {
3457 RLOGE("invalid response length was %d expected %d",
3458 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3459 return RIL_ERRNO_INVALID_RESPONSE;
3460 }
3461
3462 RIL_RadioCapability *p_cur = (RIL_RadioCapability *) response;
3463 p.writeInt32(p_cur->version);
3464 p.writeInt32(p_cur->session);
3465 p.writeInt32(p_cur->phase);
3466 p.writeInt32(p_cur->rat);
3467 writeStringToParcel(p, p_cur->logicalModemUuid);
3468 p.writeInt32(p_cur->status);
3469
3470 startResponse;
3471 appendPrintBuf("%s[version=%d,session=%d,phase=%d,\
Andreas Schneidera8d09502015-06-23 18:41:38 +02003472 rat=%d,logicalModemUuid=%s,status=%d]",
Howard Subd82ef12015-04-12 10:25:05 +02003473 printBuf,
3474 p_cur->version,
3475 p_cur->session,
3476 p_cur->phase,
3477 p_cur->rat,
3478 p_cur->logicalModemUuid,
3479 p_cur->status);
3480 closeResponse;
3481 return 0;
3482}
3483
3484static int responseSSData(Parcel &p, void *response, size_t responselen) {
3485 RLOGD("In responseSSData");
3486 int num;
3487
3488 if (response == NULL && responselen != 0) {
3489 RLOGE("invalid response length was %d expected %d",
3490 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3491 return RIL_ERRNO_INVALID_RESPONSE;
3492 }
3493
3494 if (responselen != sizeof(RIL_StkCcUnsolSsResponse)) {
3495 RLOGE("invalid response length %d, expected %d",
3496 (int)responselen, (int)sizeof(RIL_StkCcUnsolSsResponse));
3497 return RIL_ERRNO_INVALID_RESPONSE;
3498 }
3499
3500 startResponse;
3501 RIL_StkCcUnsolSsResponse *p_cur = (RIL_StkCcUnsolSsResponse *) response;
3502 p.writeInt32(p_cur->serviceType);
3503 p.writeInt32(p_cur->requestType);
3504 p.writeInt32(p_cur->teleserviceType);
3505 p.writeInt32(p_cur->serviceClass);
3506 p.writeInt32(p_cur->result);
3507
3508 if (isServiceTypeCfQuery(p_cur->serviceType, p_cur->requestType)) {
3509 RLOGD("responseSSData CF type, num of Cf elements %d", p_cur->cfData.numValidIndexes);
3510 if (p_cur->cfData.numValidIndexes > NUM_SERVICE_CLASSES) {
3511 RLOGE("numValidIndexes is greater than max value %d, "
3512 "truncating it to max value", NUM_SERVICE_CLASSES);
3513 p_cur->cfData.numValidIndexes = NUM_SERVICE_CLASSES;
3514 }
3515 /* number of call info's */
3516 p.writeInt32(p_cur->cfData.numValidIndexes);
3517
3518 for (int i = 0; i < p_cur->cfData.numValidIndexes; i++) {
3519 RIL_CallForwardInfo cf = p_cur->cfData.cfInfo[i];
3520
3521 p.writeInt32(cf.status);
3522 p.writeInt32(cf.reason);
3523 p.writeInt32(cf.serviceClass);
3524 p.writeInt32(cf.toa);
3525 writeStringToParcel(p, cf.number);
3526 p.writeInt32(cf.timeSeconds);
3527 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
3528 (cf.status==1)?"enable":"disable", cf.reason, cf.serviceClass, cf.toa,
3529 (char*)cf.number, cf.timeSeconds);
3530 RLOGD("Data: %d,reason=%d,cls=%d,toa=%d,num=%s,tout=%d],", cf.status,
3531 cf.reason, cf.serviceClass, cf.toa, (char*)cf.number, cf.timeSeconds);
3532 }
3533 } else {
3534 p.writeInt32 (SS_INFO_MAX);
3535
3536 /* each int*/
3537 for (int i = 0; i < SS_INFO_MAX; i++) {
3538 appendPrintBuf("%s%d,", printBuf, p_cur->ssInfo[i]);
3539 RLOGD("Data: %d",p_cur->ssInfo[i]);
3540 p.writeInt32(p_cur->ssInfo[i]);
3541 }
3542 }
3543 removeLastChar;
3544 closeResponse;
3545
3546 return 0;
3547}
3548
3549static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType) {
3550 if ((reqType == SS_INTERROGATION) &&
3551 (serType == SS_CFU ||
3552 serType == SS_CF_BUSY ||
3553 serType == SS_CF_NO_REPLY ||
3554 serType == SS_CF_NOT_REACHABLE ||
3555 serType == SS_CF_ALL ||
3556 serType == SS_CF_ALL_CONDITIONAL)) {
3557 return true;
3558 }
3559 return false;
3560}
3561
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003562static void triggerEvLoop() {
3563 int ret;
3564 if (!pthread_equal(pthread_self(), s_tid_dispatch)) {
3565 /* trigger event loop to wakeup. No reason to do this,
3566 * if we're in the event loop thread */
3567 do {
3568 ret = write (s_fdWakeupWrite, " ", 1);
3569 } while (ret < 0 && errno == EINTR);
3570 }
3571}
3572
3573static void rilEventAddWakeup(struct ril_event *ev) {
3574 ril_event_add(ev);
3575 triggerEvLoop();
3576}
3577
3578static void sendSimStatusAppInfo(Parcel &p, int num_apps, RIL_AppStatus appStatus[]) {
3579 p.writeInt32(num_apps);
3580 startResponse;
3581 for (int i = 0; i < num_apps; i++) {
3582 p.writeInt32(appStatus[i].app_type);
3583 p.writeInt32(appStatus[i].app_state);
3584 p.writeInt32(appStatus[i].perso_substate);
3585 writeStringToParcel(p, (const char*)(appStatus[i].aid_ptr));
3586 writeStringToParcel(p, (const char*)
3587 (appStatus[i].app_label_ptr));
3588 p.writeInt32(appStatus[i].pin1_replaced);
3589 p.writeInt32(appStatus[i].pin1);
3590 p.writeInt32(appStatus[i].pin2);
3591 appendPrintBuf("%s[app_type=%d,app_state=%d,perso_substate=%d,\
3592 aid_ptr=%s,app_label_ptr=%s,pin1_replaced=%d,pin1=%d,pin2=%d],",
3593 printBuf,
3594 appStatus[i].app_type,
3595 appStatus[i].app_state,
3596 appStatus[i].perso_substate,
3597 appStatus[i].aid_ptr,
3598 appStatus[i].app_label_ptr,
3599 appStatus[i].pin1_replaced,
3600 appStatus[i].pin1,
3601 appStatus[i].pin2);
3602 }
3603 closeResponse;
3604}
3605
3606static int responseSimStatus(Parcel &p, void *response, size_t responselen) {
Howard Sue32dbfd2015-01-07 15:55:57 +08003607 int i;
3608
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003609 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003610 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003611 return RIL_ERRNO_INVALID_RESPONSE;
3612 }
3613
3614 if (responselen == sizeof (RIL_CardStatus_v6)) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003615 RIL_CardStatus_v6 *p_cur = ((RIL_CardStatus_v6 *) response);
3616
3617 p.writeInt32(p_cur->card_state);
3618 p.writeInt32(p_cur->universal_pin_state);
3619 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3620 p.writeInt32(p_cur->cdma_subscription_app_index);
3621 p.writeInt32(p_cur->ims_subscription_app_index);
3622
3623 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
3624 } else if (responselen == sizeof (RIL_CardStatus_v5)) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003625 RIL_CardStatus_v5 *p_cur = ((RIL_CardStatus_v5 *) response);
3626
3627 p.writeInt32(p_cur->card_state);
3628 p.writeInt32(p_cur->universal_pin_state);
3629 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3630 p.writeInt32(p_cur->cdma_subscription_app_index);
3631 p.writeInt32(-1);
3632
3633 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
3634 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003635 RLOGE("responseSimStatus: A RilCardStatus_v6 or _v5 expected\n");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003636 return RIL_ERRNO_INVALID_RESPONSE;
3637 }
3638
3639 return 0;
3640}
3641
3642static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3643 int num = responselen / sizeof(RIL_GSM_BroadcastSmsConfigInfo *);
3644 p.writeInt32(num);
3645
3646 startResponse;
3647 RIL_GSM_BroadcastSmsConfigInfo **p_cur =
3648 (RIL_GSM_BroadcastSmsConfigInfo **) response;
3649 for (int i = 0; i < num; i++) {
3650 p.writeInt32(p_cur[i]->fromServiceId);
3651 p.writeInt32(p_cur[i]->toServiceId);
3652 p.writeInt32(p_cur[i]->fromCodeScheme);
3653 p.writeInt32(p_cur[i]->toCodeScheme);
3654 p.writeInt32(p_cur[i]->selected);
3655
3656 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId=%d, \
3657 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]",
3658 printBuf, i, p_cur[i]->fromServiceId, p_cur[i]->toServiceId,
3659 p_cur[i]->fromCodeScheme, p_cur[i]->toCodeScheme,
3660 p_cur[i]->selected);
3661 }
3662 closeResponse;
3663
3664 return 0;
3665}
3666
3667static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3668 RIL_CDMA_BroadcastSmsConfigInfo **p_cur =
3669 (RIL_CDMA_BroadcastSmsConfigInfo **) response;
3670
3671 int num = responselen / sizeof (RIL_CDMA_BroadcastSmsConfigInfo *);
3672 p.writeInt32(num);
3673
3674 startResponse;
3675 for (int i = 0 ; i < num ; i++ ) {
3676 p.writeInt32(p_cur[i]->service_category);
3677 p.writeInt32(p_cur[i]->language);
3678 p.writeInt32(p_cur[i]->selected);
3679
3680 appendPrintBuf("%s [%d: srvice_category=%d, language =%d, \
3681 selected =%d], ",
3682 printBuf, i, p_cur[i]->service_category, p_cur[i]->language,
3683 p_cur[i]->selected);
3684 }
3685 closeResponse;
3686
3687 return 0;
3688}
3689
3690static int responseCdmaSms(Parcel &p, void *response, size_t responselen) {
3691 int num;
3692 int digitCount;
3693 int digitLimit;
3694 uint8_t uct;
3695 void* dest;
3696
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003697 RLOGD("Inside responseCdmaSms");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003698
3699 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003700 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003701 return RIL_ERRNO_INVALID_RESPONSE;
3702 }
3703
3704 if (responselen != sizeof(RIL_CDMA_SMS_Message)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003705 RLOGE("invalid response length was %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003706 (int)responselen, (int)sizeof(RIL_CDMA_SMS_Message));
3707 return RIL_ERRNO_INVALID_RESPONSE;
3708 }
3709
3710 RIL_CDMA_SMS_Message *p_cur = (RIL_CDMA_SMS_Message *) response;
3711 p.writeInt32(p_cur->uTeleserviceID);
3712 p.write(&(p_cur->bIsServicePresent),sizeof(uct));
3713 p.writeInt32(p_cur->uServicecategory);
3714 p.writeInt32(p_cur->sAddress.digit_mode);
3715 p.writeInt32(p_cur->sAddress.number_mode);
3716 p.writeInt32(p_cur->sAddress.number_type);
3717 p.writeInt32(p_cur->sAddress.number_plan);
3718 p.write(&(p_cur->sAddress.number_of_digits), sizeof(uct));
3719 digitLimit= MIN((p_cur->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
3720 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3721 p.write(&(p_cur->sAddress.digits[digitCount]),sizeof(uct));
3722 }
3723
3724 p.writeInt32(p_cur->sSubAddress.subaddressType);
3725 p.write(&(p_cur->sSubAddress.odd),sizeof(uct));
3726 p.write(&(p_cur->sSubAddress.number_of_digits),sizeof(uct));
3727 digitLimit= MIN((p_cur->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
3728 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3729 p.write(&(p_cur->sSubAddress.digits[digitCount]),sizeof(uct));
3730 }
3731
3732 digitLimit= MIN((p_cur->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
3733 p.writeInt32(p_cur->uBearerDataLen);
3734 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3735 p.write(&(p_cur->aBearerData[digitCount]), sizeof(uct));
3736 }
3737
3738 startResponse;
3739 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
3740 sAddress.digit_mode=%d, sAddress.number_mode=%d, sAddress.number_type=%d, ",
3741 printBuf, p_cur->uTeleserviceID,p_cur->bIsServicePresent,p_cur->uServicecategory,
3742 p_cur->sAddress.digit_mode, p_cur->sAddress.number_mode,p_cur->sAddress.number_type);
3743 closeResponse;
3744
3745 return 0;
3746}
3747
Howard Sue32dbfd2015-01-07 15:55:57 +08003748static int responseDcRtInfo(Parcel &p, void *response, size_t responselen)
3749{
3750 int num = responselen / sizeof(RIL_DcRtInfo);
3751 if ((responselen % sizeof(RIL_DcRtInfo) != 0) || (num != 1)) {
3752 RLOGE("responseDcRtInfo: invalid response length %d expected multiple of %d",
3753 (int)responselen, (int)sizeof(RIL_DcRtInfo));
3754 return RIL_ERRNO_INVALID_RESPONSE;
3755 }
3756
3757 startResponse;
3758 RIL_DcRtInfo *pDcRtInfo = (RIL_DcRtInfo *)response;
3759 p.writeInt64(pDcRtInfo->time);
3760 p.writeInt32(pDcRtInfo->powerState);
3761 appendPrintBuf("%s[time=%d,powerState=%d]", printBuf,
3762 pDcRtInfo->time,
Andreas Schneidera8d09502015-06-23 18:41:38 +02003763 (int)pDcRtInfo->powerState);
Howard Sue32dbfd2015-01-07 15:55:57 +08003764 closeResponse;
3765
3766 return 0;
3767}
3768
fenglu9bdede02015-04-14 14:53:55 -07003769static int responseLceStatus(Parcel &p, void *response, size_t responselen) {
3770 if (response == NULL || responselen != sizeof(RIL_LceStatusInfo)) {
3771 if (response == NULL) {
3772 RLOGE("invalid response: NULL");
3773 }
3774 else {
3775 RLOGE("responseLceStatus: invalid response length %d expecting len: d%",
3776 sizeof(RIL_LceStatusInfo), responselen);
3777 }
3778 return RIL_ERRNO_INVALID_RESPONSE;
3779 }
3780
3781 RIL_LceStatusInfo *p_cur = (RIL_LceStatusInfo *)response;
3782 p.write((void *)p_cur, 1); // p_cur->lce_status takes one byte.
3783 p.writeInt32(p_cur->actual_interval_ms);
3784
3785 startResponse;
3786 appendPrintBuf("LCE Status: %d, actual_interval_ms: %d",
3787 p_cur->lce_status, p_cur->actual_interval_ms);
3788 closeResponse;
3789
3790 return 0;
3791}
3792
3793static int responseLceData(Parcel &p, void *response, size_t responselen) {
3794 if (response == NULL || responselen != sizeof(RIL_LceDataInfo)) {
3795 if (response == NULL) {
3796 RLOGE("invalid response: NULL");
3797 }
3798 else {
3799 RLOGE("responseLceData: invalid response length %d expecting len: d%",
3800 sizeof(RIL_LceDataInfo), responselen);
3801 }
3802 return RIL_ERRNO_INVALID_RESPONSE;
3803 }
3804
3805 RIL_LceDataInfo *p_cur = (RIL_LceDataInfo *)response;
3806 p.writeInt32(p_cur->last_hop_capacity_kbps);
3807
3808 /* p_cur->confidence_level and p_cur->lce_suspended take 1 byte each.*/
3809 p.write((void *)&(p_cur->confidence_level), 1);
3810 p.write((void *)&(p_cur->lce_suspended), 1);
3811
3812 startResponse;
forkbombe0568e12015-11-23 18:37:37 +11003813 appendPrintBuf("LCE info received: capacity %d confidence level %d"
3814 "and suspended %d",
fenglu9bdede02015-04-14 14:53:55 -07003815 p_cur->last_hop_capacity_kbps, p_cur->confidence_level,
3816 p_cur->lce_suspended);
3817 closeResponse;
3818
3819 return 0;
3820}
3821
Prerepa Viswanadham8e755592015-05-28 00:37:32 -07003822static int responseActivityData(Parcel &p, void *response, size_t responselen) {
3823 if (response == NULL || responselen != sizeof(RIL_ActivityStatsInfo)) {
3824 if (response == NULL) {
3825 RLOGE("invalid response: NULL");
3826 }
3827 else {
3828 RLOGE("responseActivityData: invalid response length %d expecting len: d%",
3829 sizeof(RIL_ActivityStatsInfo), responselen);
3830 }
3831 return RIL_ERRNO_INVALID_RESPONSE;
3832 }
3833
3834 RIL_ActivityStatsInfo *p_cur = (RIL_ActivityStatsInfo *)response;
3835 p.writeInt32(p_cur->sleep_mode_time_ms);
3836 p.writeInt32(p_cur->idle_mode_time_ms);
3837 for(int i = 0; i < RIL_NUM_TX_POWER_LEVELS; i++) {
3838 p.writeInt32(p_cur->tx_mode_time_ms[i]);
3839 }
3840 p.writeInt32(p_cur->rx_mode_time_ms);
3841
3842 startResponse;
forkbombe0568e12015-11-23 18:37:37 +11003843 appendPrintBuf("Modem activity info received: sleep_mode_time_ms %d idle_mode_time_ms %d"
3844 "tx_mode_time_ms %d %d %d %d %d and rx_mode_time_ms %d",
Prerepa Viswanadham8e755592015-05-28 00:37:32 -07003845 p_cur->sleep_mode_time_ms, p_cur->idle_mode_time_ms, p_cur->tx_mode_time_ms[0],
3846 p_cur->tx_mode_time_ms[1], p_cur->tx_mode_time_ms[2], p_cur->tx_mode_time_ms[3],
3847 p_cur->tx_mode_time_ms[4], p_cur->rx_mode_time_ms);
3848 closeResponse;
3849
3850 return 0;
3851}
3852
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003853/**
3854 * A write on the wakeup fd is done just to pop us out of select()
3855 * We empty the buffer here and then ril_event will reset the timers on the
3856 * way back down
3857 */
3858static void processWakeupCallback(int fd, short flags, void *param) {
3859 char buff[16];
3860 int ret;
3861
Ethan Chend6e30652013-08-04 22:49:56 -07003862 RLOGV("processWakeupCallback");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003863
3864 /* empty our wakeup socket out */
3865 do {
3866 ret = read(s_fdWakeupRead, &buff, sizeof(buff));
3867 } while (ret > 0 || (ret < 0 && errno == EINTR));
3868}
3869
Howard Sue32dbfd2015-01-07 15:55:57 +08003870static void onCommandsSocketClosed(RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003871 int ret;
3872 RequestInfo *p_cur;
Howard Sue32dbfd2015-01-07 15:55:57 +08003873 /* Hook for current context
3874 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
3875 pthread_mutex_t * pendingRequestsMutexHook = &s_pendingRequestsMutex;
3876 /* pendingRequestsHook refer to &s_pendingRequests */
3877 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003878
Howard Sue32dbfd2015-01-07 15:55:57 +08003879#if (SIM_COUNT >= 2)
3880 if (socket_id == RIL_SOCKET_2) {
3881 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
3882 pendingRequestsHook = &s_pendingRequests_socket2;
3883 }
3884#if (SIM_COUNT >= 3)
3885 else if (socket_id == RIL_SOCKET_3) {
3886 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
3887 pendingRequestsHook = &s_pendingRequests_socket3;
3888 }
3889#endif
3890#if (SIM_COUNT >= 4)
3891 else if (socket_id == RIL_SOCKET_4) {
3892 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
3893 pendingRequestsHook = &s_pendingRequests_socket4;
3894 }
3895#endif
3896#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003897 /* mark pending requests as "cancelled" so we dont report responses */
Howard Sue32dbfd2015-01-07 15:55:57 +08003898 ret = pthread_mutex_lock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003899 assert (ret == 0);
3900
Howard Sue32dbfd2015-01-07 15:55:57 +08003901 p_cur = *pendingRequestsHook;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003902
Howard Sue32dbfd2015-01-07 15:55:57 +08003903 for (p_cur = *pendingRequestsHook
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003904 ; p_cur != NULL
3905 ; p_cur = p_cur->p_next
3906 ) {
3907 p_cur->cancelled = 1;
3908 }
3909
Howard Sue32dbfd2015-01-07 15:55:57 +08003910 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003911 assert (ret == 0);
3912}
3913
3914static void processCommandsCallback(int fd, short flags, void *param) {
3915 RecordStream *p_rs;
3916 void *p_record;
3917 size_t recordlen;
3918 int ret;
Howard Sue32dbfd2015-01-07 15:55:57 +08003919 SocketListenParam *p_info = (SocketListenParam *)param;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003920
Howard Sue32dbfd2015-01-07 15:55:57 +08003921 assert(fd == p_info->fdCommand);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003922
Howard Sue32dbfd2015-01-07 15:55:57 +08003923 p_rs = p_info->p_rs;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003924
3925 for (;;) {
3926 /* loop until EAGAIN/EINTR, end of stream, or other error */
3927 ret = record_stream_get_next(p_rs, &p_record, &recordlen);
3928
3929 if (ret == 0 && p_record == NULL) {
3930 /* end-of-stream */
3931 break;
3932 } else if (ret < 0) {
3933 break;
3934 } else if (ret == 0) { /* && p_record != NULL */
Howard Sue32dbfd2015-01-07 15:55:57 +08003935 processCommandBuffer(p_record, recordlen, p_info->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003936 }
3937 }
3938
3939 if (ret == 0 || !(errno == EAGAIN || errno == EINTR)) {
3940 /* fatal error or end-of-stream */
3941 if (ret != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003942 RLOGE("error on reading command socket errno:%d\n", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003943 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003944 RLOGW("EOS. Closing command socket.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003945 }
3946
Howard Sue32dbfd2015-01-07 15:55:57 +08003947 close(fd);
3948 p_info->fdCommand = -1;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003949
Howard Sue32dbfd2015-01-07 15:55:57 +08003950 ril_event_del(p_info->commands_event);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003951
3952 record_stream_free(p_rs);
3953
3954 /* start listening for new connections again */
3955 rilEventAddWakeup(&s_listen_event);
3956
Howard Sue32dbfd2015-01-07 15:55:57 +08003957 onCommandsSocketClosed(p_info->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003958 }
3959}
3960
Howard Subd82ef12015-04-12 10:25:05 +02003961
Howard Sue32dbfd2015-01-07 15:55:57 +08003962static void onNewCommandConnect(RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003963 // Inform we are connected and the ril version
3964 int rilVer = s_callbacks.version;
Howard Sue32dbfd2015-01-07 15:55:57 +08003965 RIL_UNSOL_RESPONSE(RIL_UNSOL_RIL_CONNECTED,
3966 &rilVer, sizeof(rilVer), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003967
3968 // implicit radio state changed
Howard Sue32dbfd2015-01-07 15:55:57 +08003969 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
3970 NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003971
3972 // Send last NITZ time data, in case it was missed
3973 if (s_lastNITZTimeData != NULL) {
Howard Sue32dbfd2015-01-07 15:55:57 +08003974 sendResponseRaw(s_lastNITZTimeData, s_lastNITZTimeDataSize, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003975
3976 free(s_lastNITZTimeData);
3977 s_lastNITZTimeData = NULL;
3978 }
3979
3980 // Get version string
3981 if (s_callbacks.getVersion != NULL) {
3982 const char *version;
3983 version = s_callbacks.getVersion();
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003984 RLOGI("RIL Daemon version: %s\n", version);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003985
3986 property_set(PROPERTY_RIL_IMPL, version);
3987 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003988 RLOGI("RIL Daemon version: unavailable\n");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003989 property_set(PROPERTY_RIL_IMPL, "unavailable");
3990 }
3991
3992}
3993
3994static void listenCallback (int fd, short flags, void *param) {
3995 int ret;
3996 int err;
3997 int is_phone_socket;
Howard Sue32dbfd2015-01-07 15:55:57 +08003998 int fdCommand = -1;
Dheeraj Shettycc231012014-07-02 21:27:57 +02003999 char* processName;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004000 RecordStream *p_rs;
Dheeraj Shettycc231012014-07-02 21:27:57 +02004001 MySocketListenParam* listenParam;
4002 RilSocket *sapSocket = NULL;
4003 socketClient *sClient = NULL;
4004
Howard Sue32dbfd2015-01-07 15:55:57 +08004005 SocketListenParam *p_info = (SocketListenParam *)param;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004006
Dheeraj Shettycc231012014-07-02 21:27:57 +02004007 if(RIL_SAP_SOCKET == p_info->type) {
4008 listenParam = (MySocketListenParam *)param;
4009 sapSocket = listenParam->socket;
4010 }
4011
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004012 struct sockaddr_un peeraddr;
4013 socklen_t socklen = sizeof (peeraddr);
4014
4015 struct ucred creds;
4016 socklen_t szCreds = sizeof(creds);
4017
4018 struct passwd *pwd = NULL;
4019
Dheeraj Shettycc231012014-07-02 21:27:57 +02004020 if(NULL == sapSocket) {
4021 assert (*p_info->fdCommand < 0);
4022 assert (fd == *p_info->fdListen);
4023 processName = PHONE_PROCESS;
4024 } else {
4025 assert (sapSocket->commandFd < 0);
4026 assert (fd == sapSocket->listenFd);
4027 processName = BLUETOOTH_PROCESS;
4028 }
4029
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004030
Howard Sue32dbfd2015-01-07 15:55:57 +08004031 fdCommand = accept(fd, (sockaddr *) &peeraddr, &socklen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004032
Howard Sue32dbfd2015-01-07 15:55:57 +08004033 if (fdCommand < 0 ) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004034 RLOGE("Error on accept() errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004035 /* start listening for new connections again */
Dheeraj Shettycc231012014-07-02 21:27:57 +02004036 if(NULL == sapSocket) {
4037 rilEventAddWakeup(p_info->listen_event);
4038 } else {
4039 rilEventAddWakeup(sapSocket->getListenEvent());
4040 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004041 return;
4042 }
4043
4044 /* check the credential of the other side and only accept socket from
4045 * phone process
4046 */
4047 errno = 0;
4048 is_phone_socket = 0;
4049
Howard Sue32dbfd2015-01-07 15:55:57 +08004050 err = getsockopt(fdCommand, SOL_SOCKET, SO_PEERCRED, &creds, &szCreds);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004051
4052 if (err == 0 && szCreds > 0) {
4053 errno = 0;
4054 pwd = getpwuid(creds.uid);
4055 if (pwd != NULL) {
Dheeraj Shettycc231012014-07-02 21:27:57 +02004056 if (strcmp(pwd->pw_name, processName) == 0) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004057 is_phone_socket = 1;
4058 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004059 RLOGE("RILD can't accept socket from process %s", pwd->pw_name);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004060 }
4061 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004062 RLOGE("Error on getpwuid() errno: %d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004063 }
4064 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004065 RLOGD("Error on getsockopt() errno: %d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004066 }
4067
Howard Subd82ef12015-04-12 10:25:05 +02004068 if (!is_phone_socket) {
Dheeraj Shettycc231012014-07-02 21:27:57 +02004069 RLOGE("RILD must accept socket from %s", processName);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004070
Dheeraj Shettycc231012014-07-02 21:27:57 +02004071 close(fdCommand);
4072 fdCommand = -1;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004073
Dheeraj Shettycc231012014-07-02 21:27:57 +02004074 if(NULL == sapSocket) {
4075 onCommandsSocketClosed(p_info->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004076
Dheeraj Shettycc231012014-07-02 21:27:57 +02004077 /* start listening for new connections again */
4078 rilEventAddWakeup(p_info->listen_event);
4079 } else {
4080 sapSocket->onCommandsSocketClosed();
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004081
Dheeraj Shettycc231012014-07-02 21:27:57 +02004082 /* start listening for new connections again */
4083 rilEventAddWakeup(sapSocket->getListenEvent());
4084 }
4085
4086 return;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004087 }
4088
Howard Sue32dbfd2015-01-07 15:55:57 +08004089 ret = fcntl(fdCommand, F_SETFL, O_NONBLOCK);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004090
4091 if (ret < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004092 RLOGE ("Error setting O_NONBLOCK errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004093 }
4094
Dheeraj Shettycc231012014-07-02 21:27:57 +02004095 if(NULL == sapSocket) {
4096 RLOGI("libril: new connection to %s", rilSocketIdToString(p_info->socket_id));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004097
Dheeraj Shettycc231012014-07-02 21:27:57 +02004098 p_info->fdCommand = fdCommand;
4099 p_rs = record_stream_new(p_info->fdCommand, MAX_COMMAND_BYTES);
4100 p_info->p_rs = p_rs;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004101
Dheeraj Shettycc231012014-07-02 21:27:57 +02004102 ril_event_set (p_info->commands_event, p_info->fdCommand, 1,
Howard Sue32dbfd2015-01-07 15:55:57 +08004103 p_info->processCommandsCallback, p_info);
Dheeraj Shettycc231012014-07-02 21:27:57 +02004104 rilEventAddWakeup (p_info->commands_event);
Howard Sue32dbfd2015-01-07 15:55:57 +08004105
Dheeraj Shettycc231012014-07-02 21:27:57 +02004106 onNewCommandConnect(p_info->socket_id);
4107 } else {
4108 RLOGI("libril: new connection");
Howard Sue32dbfd2015-01-07 15:55:57 +08004109
Dheeraj Shettycc231012014-07-02 21:27:57 +02004110 sapSocket->setCommandFd(fdCommand);
4111 p_rs = record_stream_new(sapSocket->getCommandFd(), MAX_COMMAND_BYTES);
4112 sClient = new socketClient(sapSocket,p_rs);
4113 ril_event_set (sapSocket->getCallbackEvent(), sapSocket->getCommandFd(), 1,
4114 sapSocket->getCommandCb(), sClient);
4115
4116 rilEventAddWakeup(sapSocket->getCallbackEvent());
4117 sapSocket->onNewCommandConnect();
4118 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004119}
4120
4121static void freeDebugCallbackArgs(int number, char **args) {
4122 for (int i = 0; i < number; i++) {
4123 if (args[i] != NULL) {
4124 free(args[i]);
4125 }
4126 }
4127 free(args);
4128}
4129
4130static void debugCallback (int fd, short flags, void *param) {
4131 int acceptFD, option;
4132 struct sockaddr_un peeraddr;
4133 socklen_t socklen = sizeof (peeraddr);
4134 int data;
4135 unsigned int qxdm_data[6];
4136 const char *deactData[1] = {"1"};
4137 char *actData[1];
4138 RIL_Dial dialData;
4139 int hangupData[1] = {1};
4140 int number;
4141 char **args;
Howard Sue32dbfd2015-01-07 15:55:57 +08004142 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
4143 int sim_id = 0;
4144
4145 RLOGI("debugCallback for socket %s", rilSocketIdToString(socket_id));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004146
4147 acceptFD = accept (fd, (sockaddr *) &peeraddr, &socklen);
4148
4149 if (acceptFD < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004150 RLOGE ("error accepting on debug port: %d\n", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004151 return;
4152 }
4153
4154 if (recv(acceptFD, &number, sizeof(int), 0) != sizeof(int)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004155 RLOGE ("error reading on socket: number of Args: \n");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004156 return;
4157 }
4158 args = (char **) malloc(sizeof(char*) * number);
4159
4160 for (int i = 0; i < number; i++) {
4161 int len;
4162 if (recv(acceptFD, &len, sizeof(int), 0) != sizeof(int)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004163 RLOGE ("error reading on socket: Len of Args: \n");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004164 freeDebugCallbackArgs(i, args);
4165 return;
4166 }
4167 // +1 for null-term
4168 args[i] = (char *) malloc((sizeof(char) * len) + 1);
4169 if (recv(acceptFD, args[i], sizeof(char) * len, 0)
4170 != (int)sizeof(char) * len) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004171 RLOGE ("error reading on socket: Args[%d] \n", i);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004172 freeDebugCallbackArgs(i, args);
4173 return;
4174 }
4175 char * buf = args[i];
4176 buf[len] = 0;
Howard Sue32dbfd2015-01-07 15:55:57 +08004177 if ((i+1) == number) {
4178 /* The last argument should be sim id 0(SIM1)~3(SIM4) */
4179 sim_id = atoi(args[i]);
4180 switch (sim_id) {
4181 case 0:
4182 socket_id = RIL_SOCKET_1;
4183 break;
4184 #if (SIM_COUNT >= 2)
4185 case 1:
4186 socket_id = RIL_SOCKET_2;
4187 break;
4188 #endif
4189 #if (SIM_COUNT >= 3)
4190 case 2:
4191 socket_id = RIL_SOCKET_3;
4192 break;
4193 #endif
4194 #if (SIM_COUNT >= 4)
4195 case 3:
4196 socket_id = RIL_SOCKET_4;
4197 break;
4198 #endif
4199 default:
4200 socket_id = RIL_SOCKET_1;
4201 break;
4202 }
4203 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004204 }
4205
4206 switch (atoi(args[0])) {
4207 case 0:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004208 RLOGI ("Connection on debug port: issuing reset.");
Howard Sue32dbfd2015-01-07 15:55:57 +08004209 issueLocalRequest(RIL_REQUEST_RESET_RADIO, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004210 break;
4211 case 1:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004212 RLOGI ("Connection on debug port: issuing radio power off.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004213 data = 0;
Howard Sue32dbfd2015-01-07 15:55:57 +08004214 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004215 // Close the socket
Howard Subd82ef12015-04-12 10:25:05 +02004216 if (socket_id == RIL_SOCKET_1 && s_ril_param_socket.fdCommand > 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08004217 close(s_ril_param_socket.fdCommand);
4218 s_ril_param_socket.fdCommand = -1;
4219 }
4220 #if (SIM_COUNT == 2)
4221 else if (socket_id == RIL_SOCKET_2 && s_ril_param_socket2.fdCommand > 0) {
4222 close(s_ril_param_socket2.fdCommand);
4223 s_ril_param_socket2.fdCommand = -1;
4224 }
4225 #endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004226 break;
4227 case 2:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004228 RLOGI ("Debug port: issuing unsolicited voice network change.");
Howard Sue32dbfd2015-01-07 15:55:57 +08004229 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004230 break;
4231 case 3:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004232 RLOGI ("Debug port: QXDM log enable.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004233 qxdm_data[0] = 65536; // head.func_tag
4234 qxdm_data[1] = 16; // head.len
4235 qxdm_data[2] = 1; // mode: 1 for 'start logging'
4236 qxdm_data[3] = 32; // log_file_size: 32megabytes
4237 qxdm_data[4] = 0; // log_mask
4238 qxdm_data[5] = 8; // log_max_fileindex
4239 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Howard Sue32dbfd2015-01-07 15:55:57 +08004240 6 * sizeof(int), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004241 break;
4242 case 4:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004243 RLOGI ("Debug port: QXDM log disable.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004244 qxdm_data[0] = 65536;
4245 qxdm_data[1] = 16;
4246 qxdm_data[2] = 0; // mode: 0 for 'stop logging'
4247 qxdm_data[3] = 32;
4248 qxdm_data[4] = 0;
4249 qxdm_data[5] = 8;
4250 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Howard Sue32dbfd2015-01-07 15:55:57 +08004251 6 * sizeof(int), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004252 break;
4253 case 5:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004254 RLOGI("Debug port: Radio On");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004255 data = 1;
Howard Sue32dbfd2015-01-07 15:55:57 +08004256 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004257 sleep(2);
4258 // Set network selection automatic.
Howard Sue32dbfd2015-01-07 15:55:57 +08004259 issueLocalRequest(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004260 break;
4261 case 6:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004262 RLOGI("Debug port: Setup Data Call, Apn :%s\n", args[1]);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004263 actData[0] = args[1];
4264 issueLocalRequest(RIL_REQUEST_SETUP_DATA_CALL, &actData,
Howard Sue32dbfd2015-01-07 15:55:57 +08004265 sizeof(actData), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004266 break;
4267 case 7:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004268 RLOGI("Debug port: Deactivate Data Call");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004269 issueLocalRequest(RIL_REQUEST_DEACTIVATE_DATA_CALL, &deactData,
Howard Sue32dbfd2015-01-07 15:55:57 +08004270 sizeof(deactData), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004271 break;
4272 case 8:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004273 RLOGI("Debug port: Dial Call");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004274 dialData.clir = 0;
4275 dialData.address = args[1];
Howard Sue32dbfd2015-01-07 15:55:57 +08004276 issueLocalRequest(RIL_REQUEST_DIAL, &dialData, sizeof(dialData), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004277 break;
4278 case 9:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004279 RLOGI("Debug port: Answer Call");
Howard Sue32dbfd2015-01-07 15:55:57 +08004280 issueLocalRequest(RIL_REQUEST_ANSWER, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004281 break;
4282 case 10:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004283 RLOGI("Debug port: End Call");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004284 issueLocalRequest(RIL_REQUEST_HANGUP, &hangupData,
Howard Sue32dbfd2015-01-07 15:55:57 +08004285 sizeof(hangupData), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004286 break;
4287 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004288 RLOGE ("Invalid request");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004289 break;
4290 }
4291 freeDebugCallbackArgs(number, args);
4292 close(acceptFD);
4293}
4294
4295
4296static void userTimerCallback (int fd, short flags, void *param) {
4297 UserCallbackInfo *p_info;
4298
4299 p_info = (UserCallbackInfo *)param;
4300
4301 p_info->p_callback(p_info->userParam);
4302
4303
4304 // FIXME generalize this...there should be a cancel mechanism
4305 if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) {
4306 s_last_wake_timeout_info = NULL;
4307 }
4308
4309 free(p_info);
4310}
4311
4312
4313static void *
4314eventLoop(void *param) {
4315 int ret;
4316 int filedes[2];
4317
4318 ril_event_init();
4319
4320 pthread_mutex_lock(&s_startupMutex);
4321
4322 s_started = 1;
4323 pthread_cond_broadcast(&s_startupCond);
4324
4325 pthread_mutex_unlock(&s_startupMutex);
4326
4327 ret = pipe(filedes);
4328
4329 if (ret < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004330 RLOGE("Error in pipe() errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004331 return NULL;
4332 }
4333
4334 s_fdWakeupRead = filedes[0];
4335 s_fdWakeupWrite = filedes[1];
4336
4337 fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK);
4338
4339 ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,
4340 processWakeupCallback, NULL);
4341
4342 rilEventAddWakeup (&s_wakeupfd_event);
4343
4344 // Only returns on error
4345 ril_event_loop();
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004346 RLOGE ("error in event_loop_base errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004347 // kill self to restart on error
4348 kill(0, SIGKILL);
4349
4350 return NULL;
4351}
4352
4353extern "C" void
4354RIL_startEventLoop(void) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004355 /* spin up eventLoop thread and wait for it to get started */
4356 s_started = 0;
4357 pthread_mutex_lock(&s_startupMutex);
4358
Howard Sue32dbfd2015-01-07 15:55:57 +08004359 pthread_attr_t attr;
4360 pthread_attr_init(&attr);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004361 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
Howard Sue32dbfd2015-01-07 15:55:57 +08004362
4363 int result = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
4364 if (result != 0) {
4365 RLOGE("Failed to create dispatch thread: %s", strerror(result));
4366 goto done;
4367 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004368
4369 while (s_started == 0) {
4370 pthread_cond_wait(&s_startupCond, &s_startupMutex);
4371 }
4372
Howard Sue32dbfd2015-01-07 15:55:57 +08004373done:
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004374 pthread_mutex_unlock(&s_startupMutex);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004375}
4376
4377// Used for testing purpose only.
4378extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) {
4379 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4380}
4381
Howard Sue32dbfd2015-01-07 15:55:57 +08004382static void startListen(RIL_SOCKET_ID socket_id, SocketListenParam* socket_listen_p) {
4383 int fdListen = -1;
4384 int ret;
4385 char socket_name[10];
4386
4387 memset(socket_name, 0, sizeof(char)*10);
4388
4389 switch(socket_id) {
4390 case RIL_SOCKET_1:
4391 strncpy(socket_name, RIL_getRilSocketName(), 9);
4392 break;
4393 #if (SIM_COUNT >= 2)
4394 case RIL_SOCKET_2:
4395 strncpy(socket_name, SOCKET2_NAME_RIL, 9);
4396 break;
4397 #endif
4398 #if (SIM_COUNT >= 3)
4399 case RIL_SOCKET_3:
4400 strncpy(socket_name, SOCKET3_NAME_RIL, 9);
4401 break;
4402 #endif
4403 #if (SIM_COUNT >= 4)
4404 case RIL_SOCKET_4:
4405 strncpy(socket_name, SOCKET4_NAME_RIL, 9);
4406 break;
4407 #endif
4408 default:
4409 RLOGE("Socket id is wrong!!");
4410 return;
4411 }
4412
4413 RLOGI("Start to listen %s", rilSocketIdToString(socket_id));
4414
4415 fdListen = android_get_control_socket(socket_name);
4416 if (fdListen < 0) {
4417 RLOGE("Failed to get socket %s", socket_name);
4418 exit(-1);
4419 }
4420
4421 ret = listen(fdListen, 4);
4422
4423 if (ret < 0) {
4424 RLOGE("Failed to listen on control socket '%d': %s",
4425 fdListen, strerror(errno));
4426 exit(-1);
4427 }
4428 socket_listen_p->fdListen = fdListen;
4429
4430 /* note: non-persistent so we can accept only one connection at a time */
4431 ril_event_set (socket_listen_p->listen_event, fdListen, false,
4432 listenCallback, socket_listen_p);
4433
4434 rilEventAddWakeup (socket_listen_p->listen_event);
4435}
4436
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004437extern "C" void
4438RIL_register (const RIL_RadioFunctions *callbacks) {
4439 int ret;
4440 int flags;
4441
Howard Sue32dbfd2015-01-07 15:55:57 +08004442 RLOGI("SIM_COUNT: %d", SIM_COUNT);
4443
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004444 if (callbacks == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004445 RLOGE("RIL_register: RIL_RadioFunctions * null");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004446 return;
4447 }
4448 if (callbacks->version < RIL_VERSION_MIN) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004449 RLOGE("RIL_register: version %d is to old, min version is %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004450 callbacks->version, RIL_VERSION_MIN);
4451 return;
4452 }
4453 if (callbacks->version > RIL_VERSION) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004454 RLOGE("RIL_register: version %d is too new, max version is %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004455 callbacks->version, RIL_VERSION);
4456 return;
4457 }
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004458 RLOGE("RIL_register: RIL version %d", callbacks->version);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004459
4460 if (s_registerCalled > 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004461 RLOGE("RIL_register has been called more than once. "
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004462 "Subsequent call ignored");
4463 return;
4464 }
4465
4466 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4467
Howard Sue32dbfd2015-01-07 15:55:57 +08004468 /* Initialize socket1 parameters */
4469 s_ril_param_socket = {
4470 RIL_SOCKET_1, /* socket_id */
4471 -1, /* fdListen */
4472 -1, /* fdCommand */
4473 PHONE_PROCESS, /* processName */
4474 &s_commands_event, /* commands_event */
4475 &s_listen_event, /* listen_event */
4476 processCommandsCallback, /* processCommandsCallback */
4477 NULL /* p_rs */
4478 };
4479
4480#if (SIM_COUNT >= 2)
4481 s_ril_param_socket2 = {
4482 RIL_SOCKET_2, /* socket_id */
4483 -1, /* fdListen */
4484 -1, /* fdCommand */
4485 PHONE_PROCESS, /* processName */
4486 &s_commands_event_socket2, /* commands_event */
4487 &s_listen_event_socket2, /* listen_event */
4488 processCommandsCallback, /* processCommandsCallback */
4489 NULL /* p_rs */
4490 };
4491#endif
4492
4493#if (SIM_COUNT >= 3)
4494 s_ril_param_socket3 = {
4495 RIL_SOCKET_3, /* socket_id */
4496 -1, /* fdListen */
4497 -1, /* fdCommand */
4498 PHONE_PROCESS, /* processName */
4499 &s_commands_event_socket3, /* commands_event */
4500 &s_listen_event_socket3, /* listen_event */
4501 processCommandsCallback, /* processCommandsCallback */
4502 NULL /* p_rs */
4503 };
4504#endif
4505
4506#if (SIM_COUNT >= 4)
4507 s_ril_param_socket4 = {
4508 RIL_SOCKET_4, /* socket_id */
4509 -1, /* fdListen */
4510 -1, /* fdCommand */
4511 PHONE_PROCESS, /* processName */
4512 &s_commands_event_socket4, /* commands_event */
4513 &s_listen_event_socket4, /* listen_event */
4514 processCommandsCallback, /* processCommandsCallback */
4515 NULL /* p_rs */
4516 };
4517#endif
4518
Howard Subd82ef12015-04-12 10:25:05 +02004519
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004520 s_registerCalled = 1;
4521
Howard Sue32dbfd2015-01-07 15:55:57 +08004522 RLOGI("s_registerCalled flag set, %d", s_started);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004523 // Little self-check
4524
4525 for (int i = 0; i < (int)NUM_ELEMS(s_commands); i++) {
4526 assert(i == s_commands[i].requestNumber);
4527 }
4528
Howard Subd82ef12015-04-12 10:25:05 +02004529 for (int i = 0; i < (int)NUM_ELEMS(s_commands_v); i++) {
4530 assert(i + RIL_VENDOR_COMMANDS_OFFSET == s_commands[i].requestNumber);
4531 }
4532
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004533 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses); i++) {
Howard Sue32dbfd2015-01-07 15:55:57 +08004534 assert(i + RIL_UNSOL_RESPONSE_BASE
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004535 == s_unsolResponses[i].requestNumber);
4536 }
4537
Howard Subd82ef12015-04-12 10:25:05 +02004538 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses_v); i++) {
4539 assert(i + RIL_UNSOL_RESPONSE_BASE + RIL_VENDOR_COMMANDS_OFFSET
4540 == s_unsolResponses[i].requestNumber);
4541 }
4542
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004543 // New rild impl calls RIL_startEventLoop() first
4544 // old standalone impl wants it here.
4545
4546 if (s_started == 0) {
4547 RIL_startEventLoop();
4548 }
4549
Howard Sue32dbfd2015-01-07 15:55:57 +08004550 // start listen socket1
4551 startListen(RIL_SOCKET_1, &s_ril_param_socket);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004552
Howard Sue32dbfd2015-01-07 15:55:57 +08004553#if (SIM_COUNT >= 2)
4554 // start listen socket2
4555 startListen(RIL_SOCKET_2, &s_ril_param_socket2);
4556#endif /* (SIM_COUNT == 2) */
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004557
Howard Sue32dbfd2015-01-07 15:55:57 +08004558#if (SIM_COUNT >= 3)
4559 // start listen socket3
4560 startListen(RIL_SOCKET_3, &s_ril_param_socket3);
4561#endif /* (SIM_COUNT == 3) */
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004562
Howard Sue32dbfd2015-01-07 15:55:57 +08004563#if (SIM_COUNT >= 4)
4564 // start listen socket4
4565 startListen(RIL_SOCKET_4, &s_ril_param_socket4);
4566#endif /* (SIM_COUNT == 4) */
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004567
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004568
4569#if 1
4570 // start debug interface socket
4571
Howard Sue32dbfd2015-01-07 15:55:57 +08004572 char *inst = NULL;
4573 if (strlen(RIL_getRilSocketName()) >= strlen(SOCKET_NAME_RIL)) {
4574 inst = RIL_getRilSocketName() + strlen(SOCKET_NAME_RIL);
4575 }
4576
4577 char rildebug[MAX_DEBUG_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL_DEBUG;
4578 if (inst != NULL) {
Andreas Schneider3063dc12015-04-13 23:04:05 +02004579 snprintf(rildebug, sizeof(rildebug), "%s%s", SOCKET_NAME_RIL_DEBUG, inst);
Howard Sue32dbfd2015-01-07 15:55:57 +08004580 }
4581
4582 s_fdDebug = android_get_control_socket(rildebug);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004583 if (s_fdDebug < 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08004584 RLOGE("Failed to get socket : %s errno:%d", rildebug, errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004585 exit(-1);
4586 }
4587
4588 ret = listen(s_fdDebug, 4);
4589
4590 if (ret < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004591 RLOGE("Failed to listen on ril debug socket '%d': %s",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004592 s_fdDebug, strerror(errno));
4593 exit(-1);
4594 }
4595
4596 ril_event_set (&s_debug_event, s_fdDebug, true,
4597 debugCallback, NULL);
4598
4599 rilEventAddWakeup (&s_debug_event);
4600#endif
4601
4602}
4603
Dheeraj Shettycc231012014-07-02 21:27:57 +02004604extern "C" void
4605RIL_register_socket (RIL_RadioFunctions *(*Init)(const struct RIL_Env *, int, char **),RIL_SOCKET_TYPE socketType, int argc, char **argv) {
4606
4607 RIL_RadioFunctions* UimFuncs = NULL;
4608
4609 if(Init) {
4610 UimFuncs = Init(&RilSapSocket::uimRilEnv, argc, argv);
4611
4612 switch(socketType) {
4613 case RIL_SAP_SOCKET:
4614 RilSapSocket::initSapSocket("sap_uim_socket1", UimFuncs);
4615
4616#if (SIM_COUNT >= 2)
4617 RilSapSocket::initSapSocket("sap_uim_socket2", UimFuncs);
4618#endif
4619
4620#if (SIM_COUNT >= 3)
4621 RilSapSocket::initSapSocket("sap_uim_socket3", UimFuncs);
4622#endif
4623
4624#if (SIM_COUNT >= 4)
4625 RilSapSocket::initSapSocket("sap_uim_socket4", UimFuncs);
4626#endif
4627 }
4628 }
4629}
4630
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004631static int
4632checkAndDequeueRequestInfo(struct RequestInfo *pRI) {
4633 int ret = 0;
Howard Sue32dbfd2015-01-07 15:55:57 +08004634 /* Hook for current context
4635 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
4636 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
4637 /* pendingRequestsHook refer to &s_pendingRequests */
4638 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004639
4640 if (pRI == NULL) {
4641 return 0;
4642 }
4643
Howard Sue32dbfd2015-01-07 15:55:57 +08004644#if (SIM_COUNT >= 2)
4645 if (pRI->socket_id == RIL_SOCKET_2) {
4646 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
4647 pendingRequestsHook = &s_pendingRequests_socket2;
4648 }
4649#if (SIM_COUNT >= 3)
4650 if (pRI->socket_id == RIL_SOCKET_3) {
4651 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
4652 pendingRequestsHook = &s_pendingRequests_socket3;
4653 }
4654#endif
4655#if (SIM_COUNT >= 4)
4656 if (pRI->socket_id == RIL_SOCKET_4) {
4657 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
4658 pendingRequestsHook = &s_pendingRequests_socket4;
4659 }
4660#endif
4661#endif
4662 pthread_mutex_lock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004663
Howard Sue32dbfd2015-01-07 15:55:57 +08004664 for(RequestInfo **ppCur = pendingRequestsHook
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004665 ; *ppCur != NULL
4666 ; ppCur = &((*ppCur)->p_next)
4667 ) {
4668 if (pRI == *ppCur) {
4669 ret = 1;
4670
4671 *ppCur = (*ppCur)->p_next;
4672 break;
4673 }
4674 }
4675
Howard Sue32dbfd2015-01-07 15:55:57 +08004676 pthread_mutex_unlock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004677
4678 return ret;
4679}
4680
4681
4682extern "C" void
4683RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) {
4684 RequestInfo *pRI;
4685 int ret;
Howard Sue32dbfd2015-01-07 15:55:57 +08004686 int fd = s_ril_param_socket.fdCommand;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004687 size_t errorOffset;
Howard Sue32dbfd2015-01-07 15:55:57 +08004688 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004689
4690 pRI = (RequestInfo *)t;
4691
4692 if (!checkAndDequeueRequestInfo(pRI)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004693 RLOGE ("RIL_onRequestComplete: invalid RIL_Token");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004694 return;
4695 }
4696
Howard Sue32dbfd2015-01-07 15:55:57 +08004697 socket_id = pRI->socket_id;
4698#if (SIM_COUNT >= 2)
4699 if (socket_id == RIL_SOCKET_2) {
4700 fd = s_ril_param_socket2.fdCommand;
4701 }
4702#if (SIM_COUNT >= 3)
4703 if (socket_id == RIL_SOCKET_3) {
4704 fd = s_ril_param_socket3.fdCommand;
4705 }
4706#endif
4707#if (SIM_COUNT >= 4)
4708 if (socket_id == RIL_SOCKET_4) {
4709 fd = s_ril_param_socket4.fdCommand;
4710 }
4711#endif
4712#endif
Robert Greenwaltbc29c432015-04-29 16:57:39 -07004713#if VDBG
Howard Sue32dbfd2015-01-07 15:55:57 +08004714 RLOGD("RequestComplete, %s", rilSocketIdToString(socket_id));
Robert Greenwaltbc29c432015-04-29 16:57:39 -07004715#endif
Howard Sue32dbfd2015-01-07 15:55:57 +08004716
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004717 if (pRI->local > 0) {
4718 // Locally issued command...void only!
4719 // response does not go back up the command socket
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004720 RLOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004721
4722 goto done;
4723 }
4724
4725 appendPrintBuf("[%04d]< %s",
4726 pRI->token, requestToString(pRI->pCI->requestNumber));
4727
4728 if (pRI->cancelled == 0) {
4729 Parcel p;
4730
4731 p.writeInt32 (RESPONSE_SOLICITED);
4732 p.writeInt32 (pRI->token);
4733 errorOffset = p.dataPosition();
4734
4735 p.writeInt32 (e);
4736
4737 if (response != NULL) {
4738 // there is a response payload, no matter success or not.
4739 ret = pRI->pCI->responseFunction(p, response, responselen);
4740
4741 /* if an error occurred, rewind and mark it */
4742 if (ret != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08004743 RLOGE ("responseFunction error, ret %d", ret);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004744 p.setDataPosition(errorOffset);
4745 p.writeInt32 (ret);
4746 }
4747 }
4748
4749 if (e != RIL_E_SUCCESS) {
4750 appendPrintBuf("%s fails by %s", printBuf, failCauseToString(e));
4751 }
4752
Howard Sue32dbfd2015-01-07 15:55:57 +08004753 if (fd < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004754 RLOGD ("RIL onRequestComplete: Command channel closed");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004755 }
Howard Sue32dbfd2015-01-07 15:55:57 +08004756 sendResponse(p, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004757 }
4758
4759done:
4760 free(pRI);
4761}
4762
Howard Subd82ef12015-04-12 10:25:05 +02004763
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004764static void
4765grabPartialWakeLock() {
4766 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
4767}
4768
4769static void
4770releaseWakeLock() {
4771 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
4772}
4773
4774/**
4775 * Timer callback to put us back to sleep before the default timeout
4776 */
4777static void
4778wakeTimeoutCallback (void *param) {
4779 // We're using "param != NULL" as a cancellation mechanism
4780 if (param == NULL) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004781 releaseWakeLock();
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004782 }
4783}
4784
4785static int
4786decodeVoiceRadioTechnology (RIL_RadioState radioState) {
4787 switch (radioState) {
4788 case RADIO_STATE_SIM_NOT_READY:
4789 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4790 case RADIO_STATE_SIM_READY:
4791 return RADIO_TECH_UMTS;
4792
4793 case RADIO_STATE_RUIM_NOT_READY:
4794 case RADIO_STATE_RUIM_READY:
4795 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4796 case RADIO_STATE_NV_NOT_READY:
4797 case RADIO_STATE_NV_READY:
4798 return RADIO_TECH_1xRTT;
4799
4800 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004801 RLOGD("decodeVoiceRadioTechnology: Invoked with incorrect RadioState");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004802 return -1;
4803 }
4804}
4805
4806static int
4807decodeCdmaSubscriptionSource (RIL_RadioState radioState) {
4808 switch (radioState) {
4809 case RADIO_STATE_SIM_NOT_READY:
4810 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4811 case RADIO_STATE_SIM_READY:
4812 case RADIO_STATE_RUIM_NOT_READY:
4813 case RADIO_STATE_RUIM_READY:
4814 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4815 return CDMA_SUBSCRIPTION_SOURCE_RUIM_SIM;
4816
4817 case RADIO_STATE_NV_NOT_READY:
4818 case RADIO_STATE_NV_READY:
4819 return CDMA_SUBSCRIPTION_SOURCE_NV;
4820
4821 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004822 RLOGD("decodeCdmaSubscriptionSource: Invoked with incorrect RadioState");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004823 return -1;
4824 }
4825}
4826
4827static int
4828decodeSimStatus (RIL_RadioState radioState) {
4829 switch (radioState) {
4830 case RADIO_STATE_SIM_NOT_READY:
4831 case RADIO_STATE_RUIM_NOT_READY:
4832 case RADIO_STATE_NV_NOT_READY:
4833 case RADIO_STATE_NV_READY:
4834 return -1;
4835 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4836 case RADIO_STATE_SIM_READY:
4837 case RADIO_STATE_RUIM_READY:
4838 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4839 return radioState;
4840 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004841 RLOGD("decodeSimStatus: Invoked with incorrect RadioState");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004842 return -1;
4843 }
4844}
4845
4846static bool is3gpp2(int radioTech) {
4847 switch (radioTech) {
4848 case RADIO_TECH_IS95A:
4849 case RADIO_TECH_IS95B:
4850 case RADIO_TECH_1xRTT:
4851 case RADIO_TECH_EVDO_0:
4852 case RADIO_TECH_EVDO_A:
4853 case RADIO_TECH_EVDO_B:
4854 case RADIO_TECH_EHRPD:
4855 return true;
4856 default:
4857 return false;
4858 }
4859}
4860
4861/* If RIL sends SIM states or RUIM states, store the voice radio
4862 * technology and subscription source information so that they can be
4863 * returned when telephony framework requests them
4864 */
4865static RIL_RadioState
Howard Subd82ef12015-04-12 10:25:05 +02004866processRadioState(RIL_RadioState newRadioState, RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004867
4868 if((newRadioState > RADIO_STATE_UNAVAILABLE) && (newRadioState < RADIO_STATE_ON)) {
4869 int newVoiceRadioTech;
4870 int newCdmaSubscriptionSource;
4871 int newSimStatus;
4872
4873 /* This is old RIL. Decode Subscription source and Voice Radio Technology
4874 from Radio State and send change notifications if there has been a change */
4875 newVoiceRadioTech = decodeVoiceRadioTechnology(newRadioState);
4876 if(newVoiceRadioTech != voiceRadioTech) {
4877 voiceRadioTech = newVoiceRadioTech;
Howard Sue32dbfd2015-01-07 15:55:57 +08004878 RIL_UNSOL_RESPONSE(RIL_UNSOL_VOICE_RADIO_TECH_CHANGED,
4879 &voiceRadioTech, sizeof(voiceRadioTech), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004880 }
4881 if(is3gpp2(newVoiceRadioTech)) {
4882 newCdmaSubscriptionSource = decodeCdmaSubscriptionSource(newRadioState);
4883 if(newCdmaSubscriptionSource != cdmaSubscriptionSource) {
4884 cdmaSubscriptionSource = newCdmaSubscriptionSource;
Howard Sue32dbfd2015-01-07 15:55:57 +08004885 RIL_UNSOL_RESPONSE(RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED,
4886 &cdmaSubscriptionSource, sizeof(cdmaSubscriptionSource), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004887 }
4888 }
4889 newSimStatus = decodeSimStatus(newRadioState);
4890 if(newSimStatus != simRuimStatus) {
4891 simRuimStatus = newSimStatus;
Howard Sue32dbfd2015-01-07 15:55:57 +08004892 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004893 }
4894
4895 /* Send RADIO_ON to telephony */
4896 newRadioState = RADIO_STATE_ON;
4897 }
4898
4899 return newRadioState;
4900}
4901
Howard Subd82ef12015-04-12 10:25:05 +02004902
Howard Sue32dbfd2015-01-07 15:55:57 +08004903#if defined(ANDROID_MULTI_SIM)
4904extern "C"
Andreas Schneider47b2d962015-04-13 22:54:49 +02004905void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Howard Sue32dbfd2015-01-07 15:55:57 +08004906 size_t datalen, RIL_SOCKET_ID socket_id)
4907#else
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004908extern "C"
Andreas Schneider47b2d962015-04-13 22:54:49 +02004909void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004910 size_t datalen)
Howard Sue32dbfd2015-01-07 15:55:57 +08004911#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004912{
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004913 int ret;
4914 int64_t timeReceived = 0;
4915 bool shouldScheduleTimeout = false;
4916 RIL_RadioState newState;
Howard Sue32dbfd2015-01-07 15:55:57 +08004917 RIL_SOCKET_ID soc_id = RIL_SOCKET_1;
Howard Subd82ef12015-04-12 10:25:05 +02004918 UnsolResponseInfo *pRI = NULL;
Howard Sue32dbfd2015-01-07 15:55:57 +08004919
4920#if defined(ANDROID_MULTI_SIM)
4921 soc_id = socket_id;
4922#endif
4923
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004924
4925 if (s_registerCalled == 0) {
4926 // Ignore RIL_onUnsolicitedResponse before RIL_register
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004927 RLOGW("RIL_onUnsolicitedResponse called before RIL_register");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004928 return;
4929 }
Howard Sue32dbfd2015-01-07 15:55:57 +08004930
Howard Subd82ef12015-04-12 10:25:05 +02004931 /* Hack to include Samsung responses */
4932 if (unsolResponse > RIL_VENDOR_COMMANDS_OFFSET + RIL_UNSOL_RESPONSE_BASE) {
4933 int index = unsolResponse - RIL_VENDOR_COMMANDS_OFFSET - RIL_UNSOL_RESPONSE_BASE;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004934
Howard Subd82ef12015-04-12 10:25:05 +02004935 RLOGD("SAMSUNG: unsolResponse=%d, unsolResponseIndex=%d", unsolResponse, index);
4936
4937 if (index < (int32_t)NUM_ELEMS(s_unsolResponses_v))
4938 pRI = &s_unsolResponses_v[index];
4939 } else {
4940 int index = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
4941 if (index < (int32_t)NUM_ELEMS(s_unsolResponses))
4942 pRI = &s_unsolResponses[index];
4943 }
4944
4945 if (pRI == NULL || pRI->responseFunction == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004946 RLOGE("unsupported unsolicited response code %d", unsolResponse);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004947 return;
4948 }
4949
4950 // Grab a wake lock if needed for this reponse,
4951 // as we exit we'll either release it immediately
4952 // or set a timer to release it later.
Howard Subd82ef12015-04-12 10:25:05 +02004953 switch (pRI->wakeType) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004954 case WAKE_PARTIAL:
4955 grabPartialWakeLock();
4956 shouldScheduleTimeout = true;
4957 break;
4958
4959 case DONT_WAKE:
4960 default:
4961 // No wake lock is grabed so don't set timeout
4962 shouldScheduleTimeout = false;
4963 break;
4964 }
4965
4966 // Mark the time this was received, doing this
4967 // after grabing the wakelock incase getting
4968 // the elapsedRealTime might cause us to goto
4969 // sleep.
4970 if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4971 timeReceived = elapsedRealtime();
4972 }
4973
4974 appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
4975
4976 Parcel p;
4977
4978 p.writeInt32 (RESPONSE_UNSOLICITED);
4979 p.writeInt32 (unsolResponse);
4980
Howard Subd82ef12015-04-12 10:25:05 +02004981 ret = pRI->responseFunction(p, const_cast<void*>(data), datalen);
4982
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004983 if (ret != 0) {
4984 // Problem with the response. Don't continue;
4985 goto error_exit;
4986 }
4987
4988 // some things get more payload
4989 switch(unsolResponse) {
4990 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
Howard Sue32dbfd2015-01-07 15:55:57 +08004991 newState = processRadioState(CALL_ONSTATEREQUEST(soc_id), soc_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004992 p.writeInt32(newState);
4993 appendPrintBuf("%s {%s}", printBuf,
Howard Sue32dbfd2015-01-07 15:55:57 +08004994 radioStateToString(CALL_ONSTATEREQUEST(soc_id)));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004995 break;
4996
4997
4998 case RIL_UNSOL_NITZ_TIME_RECEIVED:
4999 // Store the time that this was received so the
5000 // handler of this message can account for
5001 // the time it takes to arrive and process. In
5002 // particular the system has been known to sleep
5003 // before this message can be processed.
5004 p.writeInt64(timeReceived);
5005 break;
5006 }
5007
Robert Greenwaltbc29c432015-04-29 16:57:39 -07005008#if VDBG
Howard Sue32dbfd2015-01-07 15:55:57 +08005009 RLOGI("%s UNSOLICITED: %s length:%d", rilSocketIdToString(soc_id), requestToString(unsolResponse), p.dataSize());
Robert Greenwaltbc29c432015-04-29 16:57:39 -07005010#endif
Howard Sue32dbfd2015-01-07 15:55:57 +08005011 ret = sendResponse(p, soc_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005012 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
5013
5014 // Unfortunately, NITZ time is not poll/update like everything
5015 // else in the system. So, if the upstream client isn't connected,
5016 // keep a copy of the last NITZ response (with receive time noted
5017 // above) around so we can deliver it when it is connected
5018
5019 if (s_lastNITZTimeData != NULL) {
5020 free (s_lastNITZTimeData);
5021 s_lastNITZTimeData = NULL;
5022 }
5023
5024 s_lastNITZTimeData = malloc(p.dataSize());
5025 s_lastNITZTimeDataSize = p.dataSize();
5026 memcpy(s_lastNITZTimeData, p.data(), p.dataSize());
5027 }
5028
5029 // For now, we automatically go back to sleep after TIMEVAL_WAKE_TIMEOUT
5030 // FIXME The java code should handshake here to release wake lock
5031
5032 if (shouldScheduleTimeout) {
5033 // Cancel the previous request
5034 if (s_last_wake_timeout_info != NULL) {
5035 s_last_wake_timeout_info->userParam = (void *)1;
5036 }
5037
5038 s_last_wake_timeout_info
5039 = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
5040 &TIMEVAL_WAKE_TIMEOUT);
5041 }
5042
5043 // Normal exit
5044 return;
5045
5046error_exit:
5047 if (shouldScheduleTimeout) {
5048 releaseWakeLock();
5049 }
5050}
5051
5052/** FIXME generalize this if you track UserCAllbackInfo, clear it
5053 when the callback occurs
5054*/
5055static UserCallbackInfo *
5056internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
5057 const struct timeval *relativeTime)
5058{
5059 struct timeval myRelativeTime;
5060 UserCallbackInfo *p_info;
5061
5062 p_info = (UserCallbackInfo *) malloc (sizeof(UserCallbackInfo));
5063
5064 p_info->p_callback = callback;
5065 p_info->userParam = param;
5066
5067 if (relativeTime == NULL) {
5068 /* treat null parameter as a 0 relative time */
5069 memset (&myRelativeTime, 0, sizeof(myRelativeTime));
5070 } else {
5071 /* FIXME I think event_add's tv param is really const anyway */
5072 memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
5073 }
5074
5075 ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
5076
5077 ril_timer_add(&(p_info->event), &myRelativeTime);
5078
5079 triggerEvLoop();
5080 return p_info;
5081}
5082
5083
5084extern "C" void
5085RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
5086 const struct timeval *relativeTime) {
5087 internalRequestTimedCallback (callback, param, relativeTime);
5088}
5089
5090const char *
5091failCauseToString(RIL_Errno e) {
5092 switch(e) {
5093 case RIL_E_SUCCESS: return "E_SUCCESS";
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005094 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RADIO_NOT_AVAILABLE";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005095 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
5096 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
5097 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
5098 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
5099 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
5100 case RIL_E_CANCELLED: return "E_CANCELLED";
5101 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
5102 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
5103 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
5104 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
5105 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
5106#ifdef FEATURE_MULTIMODE_ANDROID
5107 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
5108 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
5109#endif
5110 default: return "<unknown error>";
5111 }
5112}
5113
5114const char *
5115radioStateToString(RIL_RadioState s) {
5116 switch(s) {
5117 case RADIO_STATE_OFF: return "RADIO_OFF";
5118 case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
5119 case RADIO_STATE_SIM_NOT_READY: return "RADIO_SIM_NOT_READY";
5120 case RADIO_STATE_SIM_LOCKED_OR_ABSENT: return "RADIO_SIM_LOCKED_OR_ABSENT";
5121 case RADIO_STATE_SIM_READY: return "RADIO_SIM_READY";
5122 case RADIO_STATE_RUIM_NOT_READY:return"RADIO_RUIM_NOT_READY";
5123 case RADIO_STATE_RUIM_READY:return"RADIO_RUIM_READY";
5124 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:return"RADIO_RUIM_LOCKED_OR_ABSENT";
5125 case RADIO_STATE_NV_NOT_READY:return"RADIO_NV_NOT_READY";
5126 case RADIO_STATE_NV_READY:return"RADIO_NV_READY";
5127 case RADIO_STATE_ON:return"RADIO_ON";
5128 default: return "<unknown state>";
5129 }
5130}
5131
5132const char *
5133callStateToString(RIL_CallState s) {
5134 switch(s) {
5135 case RIL_CALL_ACTIVE : return "ACTIVE";
5136 case RIL_CALL_HOLDING: return "HOLDING";
5137 case RIL_CALL_DIALING: return "DIALING";
5138 case RIL_CALL_ALERTING: return "ALERTING";
5139 case RIL_CALL_INCOMING: return "INCOMING";
5140 case RIL_CALL_WAITING: return "WAITING";
5141 default: return "<unknown state>";
5142 }
5143}
5144
5145const char *
5146requestToString(int request) {
5147/*
5148 cat libs/telephony/ril_commands.h \
5149 | egrep "^ *{RIL_" \
5150 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
5151
5152
5153 cat libs/telephony/ril_unsol_commands.h \
5154 | egrep "^ *{RIL_" \
5155 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
5156
5157*/
5158 switch(request) {
5159 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
5160 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
5161 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
5162 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
5163 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
5164 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
5165 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
5166 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
5167 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
5168 case RIL_REQUEST_DIAL: return "DIAL";
5169 case RIL_REQUEST_DIAL_EMERGENCY: return "DIAL";
5170 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
5171 case RIL_REQUEST_HANGUP: return "HANGUP";
5172 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
5173 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
5174 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
5175 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
5176 case RIL_REQUEST_UDUB: return "UDUB";
5177 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
5178 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
5179 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
5180 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
5181 case RIL_REQUEST_OPERATOR: return "OPERATOR";
5182 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
5183 case RIL_REQUEST_DTMF: return "DTMF";
5184 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
5185 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
5186 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
5187 case RIL_REQUEST_SIM_IO: return "SIM_IO";
5188 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
5189 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
5190 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
5191 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
5192 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
5193 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
5194 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
5195 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
5196 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
5197 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
5198 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
5199 case RIL_REQUEST_ANSWER: return "ANSWER";
5200 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
5201 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
5202 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
5203 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
5204 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
5205 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
5206 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
5207 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";
5208 case RIL_REQUEST_DTMF_START: return "DTMF_START";
5209 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
5210 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
5211 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
5212 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
5213 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
5214 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
5215 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
5216 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
5217 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
5218 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
5219 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
5220 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
5221 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
5222 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
5223 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
5224 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
5225 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
5226 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
5227 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
5228 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
5229 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
5230 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
5231 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
5232 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005233 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE:return"CDMA_SET_SUBSCRIPTION_SOURCE";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005234 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"CDMA_SET_ROAMING_PREFERENCE";
5235 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"CDMA_QUERY_ROAMING_PREFERENCE";
5236 case RIL_REQUEST_SET_TTY_MODE:return"SET_TTY_MODE";
5237 case RIL_REQUEST_QUERY_TTY_MODE:return"QUERY_TTY_MODE";
5238 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
5239 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
5240 case RIL_REQUEST_CDMA_FLASH:return"CDMA_FLASH";
5241 case RIL_REQUEST_CDMA_BURST_DTMF:return"CDMA_BURST_DTMF";
5242 case RIL_REQUEST_CDMA_SEND_SMS:return"CDMA_SEND_SMS";
5243 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:return"CDMA_SMS_ACKNOWLEDGE";
5244 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG:return"GSM_GET_BROADCAST_SMS_CONFIG";
5245 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG:return"GSM_SET_BROADCAST_SMS_CONFIG";
5246 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG:return "CDMA_GET_BROADCAST_SMS_CONFIG";
5247 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG:return "CDMA_SET_BROADCAST_SMS_CONFIG";
5248 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION:return "CDMA_SMS_BROADCAST_ACTIVATION";
Ethan Chend6e30652013-08-04 22:49:56 -07005249 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return"CDMA_VALIDATE_AND_WRITE_AKEY";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005250 case RIL_REQUEST_CDMA_SUBSCRIPTION: return"CDMA_SUBSCRIPTION";
5251 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
5252 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
5253 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
5254 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
5255 case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
5256 case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
5257 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
5258 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
5259 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
5260 case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
5261 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
5262 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
5263 case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005264 case RIL_REQUEST_GET_CELL_INFO_LIST: return"GET_CELL_INFO_LIST";
5265 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return"SET_UNSOL_CELL_INFO_LIST_RATE";
Andrew Jiangca4a9a02014-01-18 18:04:08 -05005266 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "RIL_REQUEST_SET_INITIAL_ATTACH_APN";
5267 case RIL_REQUEST_IMS_REGISTRATION_STATE: return "IMS_REGISTRATION_STATE";
5268 case RIL_REQUEST_IMS_SEND_SMS: return "IMS_SEND_SMS";
Howard Sue32dbfd2015-01-07 15:55:57 +08005269 case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "SIM_TRANSMIT_APDU_BASIC";
5270 case RIL_REQUEST_SIM_OPEN_CHANNEL: return "SIM_OPEN_CHANNEL";
5271 case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "SIM_CLOSE_CHANNEL";
5272 case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "SIM_TRANSMIT_APDU_CHANNEL";
Howard Subd82ef12015-04-12 10:25:05 +02005273 case RIL_REQUEST_GET_RADIO_CAPABILITY: return "RIL_REQUEST_GET_RADIO_CAPABILITY";
5274 case RIL_REQUEST_SET_RADIO_CAPABILITY: return "RIL_REQUEST_SET_RADIO_CAPABILITY";
Howard Sue32dbfd2015-01-07 15:55:57 +08005275 case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "SET_UICC_SUBSCRIPTION";
5276 case RIL_REQUEST_ALLOW_DATA: return "ALLOW_DATA";
5277 case RIL_REQUEST_GET_HARDWARE_CONFIG: return "GET_HARDWARE_CONFIG";
5278 case RIL_REQUEST_SIM_AUTHENTICATION: return "SIM_AUTHENTICATION";
5279 case RIL_REQUEST_GET_DC_RT_INFO: return "GET_DC_RT_INFO";
5280 case RIL_REQUEST_SET_DC_RT_INFO_RATE: return "SET_DC_RT_INFO_RATE";
5281 case RIL_REQUEST_SET_DATA_PROFILE: return "SET_DATA_PROFILE";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005282 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
5283 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
5284 case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED";
5285 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
5286 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
5287 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
5288 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
5289 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)";
5290 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
5291 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
Howard Subd82ef12015-04-12 10:25:05 +02005292 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
5293 case RIL_UNSOL_SUPP_SVC_NOTIFICATION: return "UNSOL_SUPP_SVC_NOTIFICATION";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005294 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
5295 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
5296 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
5297 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
5298 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL";
5299 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005300 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
5301 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
5302 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_NEW_CDMA_SMS";
5303 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_NEW_BROADCAST_SMS";
5304 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
5305 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
5306 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
5307 case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
5308 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
5309 case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
5310 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
5311 case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
5312 case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
5313 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
5314 case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
5315 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
5316 case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
5317 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
Ethan Chend6e30652013-08-04 22:49:56 -07005318 case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
Andrew Jiangca4a9a02014-01-18 18:04:08 -05005319 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "RESPONSE_IMS_NETWORK_STATE_CHANGED";
Howard Sue32dbfd2015-01-07 15:55:57 +08005320 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return "UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED";
5321 case RIL_UNSOL_SRVCC_STATE_NOTIFY: return "UNSOL_SRVCC_STATE_NOTIFY";
5322 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return "HARDWARE_CONFIG_CHANGED";
5323 case RIL_UNSOL_DC_RT_INFO_CHANGED: return "UNSOL_DC_RT_INFO_CHANGED";
Howard Subd82ef12015-04-12 10:25:05 +02005324 case RIL_UNSOL_RADIO_CAPABILITY: return "UNSOL_RADIO_CAPABILITY";
5325 case RIL_UNSOL_ON_SS: return "UNSOL_ON_SS";
5326 case RIL_UNSOL_STK_CC_ALPHA_NOTIFY: return "UNSOL_STK_CC_ALPHA_NOTIFY";
Howard Sue32dbfd2015-01-07 15:55:57 +08005327 case RIL_REQUEST_SHUTDOWN: return "SHUTDOWN";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005328 default: return "<unknown request>";
5329 }
5330}
5331
Howard Sue32dbfd2015-01-07 15:55:57 +08005332const char *
5333rilSocketIdToString(RIL_SOCKET_ID socket_id)
5334{
5335 switch(socket_id) {
5336 case RIL_SOCKET_1:
5337 return "RIL_SOCKET_1";
5338#if (SIM_COUNT >= 2)
5339 case RIL_SOCKET_2:
5340 return "RIL_SOCKET_2";
5341#endif
5342#if (SIM_COUNT >= 3)
5343 case RIL_SOCKET_3:
5344 return "RIL_SOCKET_3";
5345#endif
5346#if (SIM_COUNT >= 4)
5347 case RIL_SOCKET_4:
5348 return "RIL_SOCKET_4";
5349#endif
5350 default:
5351 return "not a valid RIL";
5352 }
5353}
5354
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005355} /* namespace android */
Dheeraj Shettycc231012014-07-02 21:27:57 +02005356
5357void rilEventAddWakeup_helper(struct ril_event *ev) {
5358 android::rilEventAddWakeup(ev);
5359}
5360
5361void listenCallback_helper(int fd, short flags, void *param) {
5362 android::listenCallback(fd, flags, param);
5363}
5364
5365int blockingWrite_helper(int fd, void *buffer, size_t len) {
5366 return android::blockingWrite(fd, buffer, len);
5367}