blob: bb60703af65a991a44f826a96e083984012fab6a [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"
Andreas Schneiderd806de92015-10-22 16:20:51 +020071#define PROPERTY_QAN_ELEMENTS "ro.ril.qanelements"
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
Howard Subd82ef12015-04-12 10:25:05 +0200348static CommandInfo s_commands_v[] = {
349#include "ril_commands_vendor.h"
350};
351
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200352static UnsolResponseInfo s_unsolResponses[] = {
353#include "ril_unsol_commands.h"
354};
355
Howard Subd82ef12015-04-12 10:25:05 +0200356static UnsolResponseInfo s_unsolResponses_v[] = {
357#include "ril_unsol_commands_vendor.h"
358};
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. Hesse7bf409e2015-06-26 14:53:56 +0200792#if defined(MODEM_TYPE_XMM7260) || defined(MODEM_TYPE_M7450)
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. Hesse7bf409e2015-06-26 14:53:56 +0200809#if defined(MODEM_TYPE_XMM7260) || defined(MODEM_TYPE_M7450)
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. Hesse7bf409e2015-06-26 14:53:56 +0200839#if defined(MODEM_TYPE_XMM6262) || defined(MODEM_TYPE_XMM7260) || defined(MODEM_TYPE_M7450)
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. Hesse7bf409e2015-06-26 14:53:56 +02002389#if defined(MODEM_TYPE_XMM7260) || defined(MODEM_TYPE_M7450)
Andreas Schneider29472682015-01-01 19:00:04 +01002390 p.writeInt32(p_cur->isVideo);
2391
2392 /* Pass CallDetails */
2393 p.writeInt32(0);
2394 p.writeInt32(0);
2395 writeStringToParcel(p, "");
2396#endif
2397
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002398 p.writeInt32(p_cur->isVoicePrivacy);
2399 writeStringToParcel(p, p_cur->number);
2400 p.writeInt32(p_cur->numberPresentation);
2401 writeStringToParcel(p, p_cur->name);
2402 p.writeInt32(p_cur->namePresentation);
2403 // Remove when partners upgrade to version 3
2404 if ((s_callbacks.version < 3) || (p_cur->uusInfo == NULL || p_cur->uusInfo->uusData == NULL)) {
2405 p.writeInt32(0); /* UUS Information is absent */
2406 } else {
2407 RIL_UUS_Info *uusInfo = p_cur->uusInfo;
2408 p.writeInt32(1); /* UUS Information is present */
2409 p.writeInt32(uusInfo->uusType);
2410 p.writeInt32(uusInfo->uusDcs);
2411 p.writeInt32(uusInfo->uusLength);
2412 p.write(uusInfo->uusData, uusInfo->uusLength);
2413 }
2414 appendPrintBuf("%s[id=%d,%s,toa=%d,",
2415 printBuf,
2416 p_cur->index,
2417 callStateToString(p_cur->state),
2418 p_cur->toa);
2419 appendPrintBuf("%s%s,%s,als=%d,%s,%s,",
2420 printBuf,
2421 (p_cur->isMpty)?"conf":"norm",
2422 (p_cur->isMT)?"mt":"mo",
2423 p_cur->als,
2424 (p_cur->isVoice)?"voc":"nonvoc",
2425 (p_cur->isVoicePrivacy)?"evp":"noevp");
Christopher N. Hesse7bf409e2015-06-26 14:53:56 +02002426#if defined(MODEM_TYPE_XMM7260) || defined(MODEM_TYPE_M7450)
Andreas Schneider29472682015-01-01 19:00:04 +01002427 appendPrintBuf("%s,%s,",
2428 printBuf,
2429 (p_cur->isVideo) ? "vid" : "novid");
2430#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002431 appendPrintBuf("%s%s,cli=%d,name='%s',%d]",
2432 printBuf,
2433 p_cur->number,
2434 p_cur->numberPresentation,
2435 p_cur->name,
2436 p_cur->namePresentation);
2437 }
2438 removeLastChar;
2439 closeResponse;
2440
2441 return 0;
2442}
2443
2444static int responseSMS(Parcel &p, void *response, size_t responselen) {
2445 if (response == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002446 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002447 return RIL_ERRNO_INVALID_RESPONSE;
2448 }
2449
2450 if (responselen != sizeof (RIL_SMS_Response) ) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002451 RLOGE("invalid response length %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002452 (int)responselen, (int)sizeof (RIL_SMS_Response));
2453 return RIL_ERRNO_INVALID_RESPONSE;
2454 }
2455
2456 RIL_SMS_Response *p_cur = (RIL_SMS_Response *) response;
2457
2458 p.writeInt32(p_cur->messageRef);
2459 writeStringToParcel(p, p_cur->ackPDU);
2460 p.writeInt32(p_cur->errorCode);
2461
2462 startResponse;
2463 appendPrintBuf("%s%d,%s,%d", printBuf, p_cur->messageRef,
2464 (char*)p_cur->ackPDU, p_cur->errorCode);
2465 closeResponse;
2466
2467 return 0;
2468}
2469
2470static int responseDataCallListV4(Parcel &p, void *response, size_t responselen)
2471{
2472 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002473 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002474 return RIL_ERRNO_INVALID_RESPONSE;
2475 }
2476
2477 if (responselen % sizeof(RIL_Data_Call_Response_v4) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002478 RLOGE("responseDataCallListV4: invalid response length %d expected multiple of %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002479 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v4));
2480 return RIL_ERRNO_INVALID_RESPONSE;
2481 }
2482
Howard Sue32dbfd2015-01-07 15:55:57 +08002483 // Write version
2484 p.writeInt32(4);
2485
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002486 int num = responselen / sizeof(RIL_Data_Call_Response_v4);
2487 p.writeInt32(num);
2488
2489 RIL_Data_Call_Response_v4 *p_cur = (RIL_Data_Call_Response_v4 *) response;
2490 startResponse;
2491 int i;
2492 for (i = 0; i < num; i++) {
2493 p.writeInt32(p_cur[i].cid);
2494 p.writeInt32(p_cur[i].active);
2495 writeStringToParcel(p, p_cur[i].type);
2496 // apn is not used, so don't send.
2497 writeStringToParcel(p, p_cur[i].address);
2498 appendPrintBuf("%s[cid=%d,%s,%s,%s],", printBuf,
2499 p_cur[i].cid,
2500 (p_cur[i].active==0)?"down":"up",
2501 (char*)p_cur[i].type,
2502 (char*)p_cur[i].address);
2503 }
2504 removeLastChar;
2505 closeResponse;
2506
2507 return 0;
2508}
2509
Howard Sue32dbfd2015-01-07 15:55:57 +08002510static int responseDataCallListV6(Parcel &p, void *response, size_t responselen)
2511{
2512 if (response == NULL && responselen != 0) {
2513 RLOGE("invalid response: NULL");
2514 return RIL_ERRNO_INVALID_RESPONSE;
2515 }
2516
2517 if (responselen % sizeof(RIL_Data_Call_Response_v6) != 0) {
2518 RLOGE("responseDataCallListV6: invalid response length %d expected multiple of %d",
2519 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v6));
2520 return RIL_ERRNO_INVALID_RESPONSE;
2521 }
2522
2523 // Write version
2524 p.writeInt32(6);
2525
2526 int num = responselen / sizeof(RIL_Data_Call_Response_v6);
2527 p.writeInt32(num);
2528
2529 RIL_Data_Call_Response_v6 *p_cur = (RIL_Data_Call_Response_v6 *) response;
2530 startResponse;
2531 int i;
2532 for (i = 0; i < num; i++) {
2533 p.writeInt32((int)p_cur[i].status);
2534 p.writeInt32(p_cur[i].suggestedRetryTime);
2535 p.writeInt32(p_cur[i].cid);
2536 p.writeInt32(p_cur[i].active);
2537 writeStringToParcel(p, p_cur[i].type);
2538 writeStringToParcel(p, p_cur[i].ifname);
2539 writeStringToParcel(p, p_cur[i].addresses);
2540 writeStringToParcel(p, p_cur[i].dnses);
2541 writeStringToParcel(p, p_cur[i].addresses);
2542 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s],", printBuf,
2543 p_cur[i].status,
2544 p_cur[i].suggestedRetryTime,
2545 p_cur[i].cid,
2546 (p_cur[i].active==0)?"down":"up",
2547 (char*)p_cur[i].type,
2548 (char*)p_cur[i].ifname,
2549 (char*)p_cur[i].addresses,
2550 (char*)p_cur[i].dnses,
2551 (char*)p_cur[i].addresses);
2552 }
2553 removeLastChar;
2554 closeResponse;
2555
2556 return 0;
2557}
2558
Howard Subd82ef12015-04-12 10:25:05 +02002559static int responseDataCallListV9(Parcel &p, void *response, size_t responselen)
2560{
2561 if (response == NULL && responselen != 0) {
2562 RLOGE("invalid response: NULL");
2563 return RIL_ERRNO_INVALID_RESPONSE;
2564 }
2565
2566 if (responselen % sizeof(RIL_Data_Call_Response_v9) != 0) {
2567 RLOGE("responseDataCallListV9: invalid response length %d expected multiple of %d",
2568 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v9));
2569 return RIL_ERRNO_INVALID_RESPONSE;
2570 }
2571
2572 // Write version
2573 p.writeInt32(10);
2574
2575 int num = responselen / sizeof(RIL_Data_Call_Response_v9);
2576 p.writeInt32(num);
2577
2578 RIL_Data_Call_Response_v9 *p_cur = (RIL_Data_Call_Response_v9 *) response;
2579 startResponse;
2580 int i;
2581 for (i = 0; i < num; i++) {
2582 p.writeInt32((int)p_cur[i].status);
2583 p.writeInt32(p_cur[i].suggestedRetryTime);
2584 p.writeInt32(p_cur[i].cid);
2585 p.writeInt32(p_cur[i].active);
2586 writeStringToParcel(p, p_cur[i].type);
2587 writeStringToParcel(p, p_cur[i].ifname);
2588 writeStringToParcel(p, p_cur[i].addresses);
2589 writeStringToParcel(p, p_cur[i].dnses);
2590 writeStringToParcel(p, p_cur[i].gateways);
2591 writeStringToParcel(p, p_cur[i].pcscf);
2592 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s],", printBuf,
2593 p_cur[i].status,
2594 p_cur[i].suggestedRetryTime,
2595 p_cur[i].cid,
2596 (p_cur[i].active==0)?"down":"up",
2597 (char*)p_cur[i].type,
2598 (char*)p_cur[i].ifname,
2599 (char*)p_cur[i].addresses,
2600 (char*)p_cur[i].dnses,
2601 (char*)p_cur[i].gateways,
2602 (char*)p_cur[i].pcscf);
2603 }
2604 removeLastChar;
2605 closeResponse;
2606
2607 return 0;
2608}
2609
2610
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002611static int responseDataCallList(Parcel &p, void *response, size_t responselen)
2612{
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002613 if (s_callbacks.version < 5) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002614 RLOGD("responseDataCallList: v4");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002615 return responseDataCallListV4(p, response, responselen);
Howard Subd82ef12015-04-12 10:25:05 +02002616 } else if (responselen % sizeof(RIL_Data_Call_Response_v6) == 0) {
2617 return responseDataCallListV6(p, response, responselen);
2618 } else if (responselen % sizeof(RIL_Data_Call_Response_v9) == 0) {
2619 return responseDataCallListV9(p, response, responselen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002620 } else {
2621 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002622 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002623 return RIL_ERRNO_INVALID_RESPONSE;
2624 }
2625
Howard Subd82ef12015-04-12 10:25:05 +02002626 if (responselen % sizeof(RIL_Data_Call_Response_v11) != 0) {
2627 RLOGE("invalid response length %d expected multiple of %d",
2628 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v11));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002629 return RIL_ERRNO_INVALID_RESPONSE;
2630 }
2631
Howard Sue32dbfd2015-01-07 15:55:57 +08002632 // Write version
Howard Subd82ef12015-04-12 10:25:05 +02002633 p.writeInt32(11);
Howard Sue32dbfd2015-01-07 15:55:57 +08002634
Howard Subd82ef12015-04-12 10:25:05 +02002635 int num = responselen / sizeof(RIL_Data_Call_Response_v11);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002636 p.writeInt32(num);
2637
Howard Subd82ef12015-04-12 10:25:05 +02002638 RIL_Data_Call_Response_v11 *p_cur = (RIL_Data_Call_Response_v11 *) response;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002639 startResponse;
2640 int i;
2641 for (i = 0; i < num; i++) {
2642 p.writeInt32((int)p_cur[i].status);
2643 p.writeInt32(p_cur[i].suggestedRetryTime);
2644 p.writeInt32(p_cur[i].cid);
2645 p.writeInt32(p_cur[i].active);
2646 writeStringToParcel(p, p_cur[i].type);
2647 writeStringToParcel(p, p_cur[i].ifname);
2648 writeStringToParcel(p, p_cur[i].addresses);
2649 writeStringToParcel(p, p_cur[i].dnses);
Howard Sue32dbfd2015-01-07 15:55:57 +08002650 writeStringToParcel(p, p_cur[i].gateways);
2651 writeStringToParcel(p, p_cur[i].pcscf);
Howard Subd82ef12015-04-12 10:25:05 +02002652 p.writeInt32(p_cur[i].mtu);
2653 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 +02002654 p_cur[i].status,
2655 p_cur[i].suggestedRetryTime,
2656 p_cur[i].cid,
2657 (p_cur[i].active==0)?"down":"up",
2658 (char*)p_cur[i].type,
2659 (char*)p_cur[i].ifname,
2660 (char*)p_cur[i].addresses,
2661 (char*)p_cur[i].dnses,
Howard Sue32dbfd2015-01-07 15:55:57 +08002662 (char*)p_cur[i].gateways,
Howard Subd82ef12015-04-12 10:25:05 +02002663 (char*)p_cur[i].pcscf,
2664 p_cur[i].mtu);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002665 }
2666 removeLastChar;
2667 closeResponse;
2668 }
2669
2670 return 0;
2671}
2672
2673static int responseSetupDataCall(Parcel &p, void *response, size_t responselen)
2674{
2675 if (s_callbacks.version < 5) {
2676 return responseStringsWithVersion(s_callbacks.version, p, response, responselen);
2677 } else {
2678 return responseDataCallList(p, response, responselen);
2679 }
2680}
2681
2682static int responseRaw(Parcel &p, void *response, size_t responselen) {
2683 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002684 RLOGE("invalid response: NULL with responselen != 0");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002685 return RIL_ERRNO_INVALID_RESPONSE;
2686 }
2687
2688 // The java code reads -1 size as null byte array
2689 if (response == NULL) {
2690 p.writeInt32(-1);
2691 } else {
2692 p.writeInt32(responselen);
2693 p.write(response, responselen);
2694 }
2695
2696 return 0;
2697}
2698
2699
2700static int responseSIM_IO(Parcel &p, void *response, size_t responselen) {
2701 if (response == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002702 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002703 return RIL_ERRNO_INVALID_RESPONSE;
2704 }
2705
2706 if (responselen != sizeof (RIL_SIM_IO_Response) ) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002707 RLOGE("invalid response length was %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002708 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
2709 return RIL_ERRNO_INVALID_RESPONSE;
2710 }
2711
2712 RIL_SIM_IO_Response *p_cur = (RIL_SIM_IO_Response *) response;
2713 p.writeInt32(p_cur->sw1);
2714 p.writeInt32(p_cur->sw2);
2715 writeStringToParcel(p, p_cur->simResponse);
2716
2717 startResponse;
2718 appendPrintBuf("%ssw1=0x%X,sw2=0x%X,%s", printBuf, p_cur->sw1, p_cur->sw2,
2719 (char*)p_cur->simResponse);
2720 closeResponse;
2721
2722
2723 return 0;
2724}
2725
2726static int responseCallForwards(Parcel &p, void *response, size_t responselen) {
2727 int num;
2728
2729 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002730 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002731 return RIL_ERRNO_INVALID_RESPONSE;
2732 }
2733
2734 if (responselen % sizeof(RIL_CallForwardInfo *) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002735 RLOGE("responseCallForwards: invalid response length %d expected multiple of %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002736 (int)responselen, (int)sizeof(RIL_CallForwardInfo *));
2737 return RIL_ERRNO_INVALID_RESPONSE;
2738 }
2739
2740 /* number of call info's */
2741 num = responselen / sizeof(RIL_CallForwardInfo *);
2742 p.writeInt32(num);
2743
2744 startResponse;
2745 for (int i = 0 ; i < num ; i++) {
2746 RIL_CallForwardInfo *p_cur = ((RIL_CallForwardInfo **) response)[i];
2747
2748 p.writeInt32(p_cur->status);
2749 p.writeInt32(p_cur->reason);
2750 p.writeInt32(p_cur->serviceClass);
2751 p.writeInt32(p_cur->toa);
2752 writeStringToParcel(p, p_cur->number);
2753 p.writeInt32(p_cur->timeSeconds);
2754 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
2755 (p_cur->status==1)?"enable":"disable",
2756 p_cur->reason, p_cur->serviceClass, p_cur->toa,
2757 (char*)p_cur->number,
2758 p_cur->timeSeconds);
2759 }
2760 removeLastChar;
2761 closeResponse;
2762
2763 return 0;
2764}
2765
2766static int responseSsn(Parcel &p, void *response, size_t responselen) {
2767 if (response == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002768 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002769 return RIL_ERRNO_INVALID_RESPONSE;
2770 }
2771
2772 if (responselen != sizeof(RIL_SuppSvcNotification)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002773 RLOGE("invalid response length was %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002774 (int)responselen, (int)sizeof (RIL_SuppSvcNotification));
2775 return RIL_ERRNO_INVALID_RESPONSE;
2776 }
2777
2778 RIL_SuppSvcNotification *p_cur = (RIL_SuppSvcNotification *) response;
2779 p.writeInt32(p_cur->notificationType);
2780 p.writeInt32(p_cur->code);
2781 p.writeInt32(p_cur->index);
2782 p.writeInt32(p_cur->type);
2783 writeStringToParcel(p, p_cur->number);
2784
2785 startResponse;
2786 appendPrintBuf("%s%s,code=%d,id=%d,type=%d,%s", printBuf,
2787 (p_cur->notificationType==0)?"mo":"mt",
2788 p_cur->code, p_cur->index, p_cur->type,
2789 (char*)p_cur->number);
2790 closeResponse;
2791
2792 return 0;
2793}
2794
2795static int responseCellList(Parcel &p, void *response, size_t responselen) {
2796 int num;
2797
2798 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002799 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002800 return RIL_ERRNO_INVALID_RESPONSE;
2801 }
2802
2803 if (responselen % sizeof (RIL_NeighboringCell *) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002804 RLOGE("responseCellList: invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002805 (int)responselen, (int)sizeof (RIL_NeighboringCell *));
2806 return RIL_ERRNO_INVALID_RESPONSE;
2807 }
2808
2809 startResponse;
2810 /* number of records */
2811 num = responselen / sizeof(RIL_NeighboringCell *);
2812 p.writeInt32(num);
2813
2814 for (int i = 0 ; i < num ; i++) {
2815 RIL_NeighboringCell *p_cur = ((RIL_NeighboringCell **) response)[i];
2816
2817 p.writeInt32(p_cur->rssi);
2818 writeStringToParcel (p, p_cur->cid);
2819
2820 appendPrintBuf("%s[cid=%s,rssi=%d],", printBuf,
2821 p_cur->cid, p_cur->rssi);
2822 }
2823 removeLastChar;
2824 closeResponse;
2825
2826 return 0;
2827}
2828
2829/**
2830 * Marshall the signalInfoRecord into the parcel if it exists.
2831 */
2832static void marshallSignalInfoRecord(Parcel &p,
2833 RIL_CDMA_SignalInfoRecord &p_signalInfoRecord) {
2834 p.writeInt32(p_signalInfoRecord.isPresent);
2835 p.writeInt32(p_signalInfoRecord.signalType);
2836 p.writeInt32(p_signalInfoRecord.alertPitch);
2837 p.writeInt32(p_signalInfoRecord.signal);
2838}
2839
2840static int responseCdmaInformationRecords(Parcel &p,
2841 void *response, size_t responselen) {
2842 int num;
2843 char* string8 = NULL;
2844 int buffer_lenght;
2845 RIL_CDMA_InformationRecord *infoRec;
2846
2847 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002848 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002849 return RIL_ERRNO_INVALID_RESPONSE;
2850 }
2851
2852 if (responselen != sizeof (RIL_CDMA_InformationRecords)) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002853 RLOGE("responseCdmaInformationRecords: invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002854 (int)responselen, (int)sizeof (RIL_CDMA_InformationRecords *));
2855 return RIL_ERRNO_INVALID_RESPONSE;
2856 }
2857
2858 RIL_CDMA_InformationRecords *p_cur =
2859 (RIL_CDMA_InformationRecords *) response;
2860 num = MIN(p_cur->numberOfInfoRecs, RIL_CDMA_MAX_NUMBER_OF_INFO_RECS);
2861
2862 startResponse;
2863 p.writeInt32(num);
2864
2865 for (int i = 0 ; i < num ; i++) {
2866 infoRec = &p_cur->infoRec[i];
2867 p.writeInt32(infoRec->name);
2868 switch (infoRec->name) {
2869 case RIL_CDMA_DISPLAY_INFO_REC:
2870 case RIL_CDMA_EXTENDED_DISPLAY_INFO_REC:
2871 if (infoRec->rec.display.alpha_len >
2872 CDMA_ALPHA_INFO_BUFFER_LENGTH) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002873 RLOGE("invalid display info response length %d \
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002874 expected not more than %d\n",
2875 (int)infoRec->rec.display.alpha_len,
2876 CDMA_ALPHA_INFO_BUFFER_LENGTH);
2877 return RIL_ERRNO_INVALID_RESPONSE;
2878 }
2879 string8 = (char*) malloc((infoRec->rec.display.alpha_len + 1)
2880 * sizeof(char) );
2881 for (int i = 0 ; i < infoRec->rec.display.alpha_len ; i++) {
2882 string8[i] = infoRec->rec.display.alpha_buf[i];
2883 }
2884 string8[(int)infoRec->rec.display.alpha_len] = '\0';
2885 writeStringToParcel(p, (const char*)string8);
2886 free(string8);
2887 string8 = NULL;
2888 break;
2889 case RIL_CDMA_CALLED_PARTY_NUMBER_INFO_REC:
2890 case RIL_CDMA_CALLING_PARTY_NUMBER_INFO_REC:
2891 case RIL_CDMA_CONNECTED_NUMBER_INFO_REC:
2892 if (infoRec->rec.number.len > CDMA_NUMBER_INFO_BUFFER_LENGTH) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002893 RLOGE("invalid display info response length %d \
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002894 expected not more than %d\n",
2895 (int)infoRec->rec.number.len,
2896 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2897 return RIL_ERRNO_INVALID_RESPONSE;
2898 }
2899 string8 = (char*) malloc((infoRec->rec.number.len + 1)
2900 * sizeof(char) );
2901 for (int i = 0 ; i < infoRec->rec.number.len; i++) {
2902 string8[i] = infoRec->rec.number.buf[i];
2903 }
2904 string8[(int)infoRec->rec.number.len] = '\0';
2905 writeStringToParcel(p, (const char*)string8);
2906 free(string8);
2907 string8 = NULL;
2908 p.writeInt32(infoRec->rec.number.number_type);
2909 p.writeInt32(infoRec->rec.number.number_plan);
2910 p.writeInt32(infoRec->rec.number.pi);
2911 p.writeInt32(infoRec->rec.number.si);
2912 break;
2913 case RIL_CDMA_SIGNAL_INFO_REC:
2914 p.writeInt32(infoRec->rec.signal.isPresent);
2915 p.writeInt32(infoRec->rec.signal.signalType);
2916 p.writeInt32(infoRec->rec.signal.alertPitch);
2917 p.writeInt32(infoRec->rec.signal.signal);
2918
2919 appendPrintBuf("%sisPresent=%X, signalType=%X, \
2920 alertPitch=%X, signal=%X, ",
2921 printBuf, (int)infoRec->rec.signal.isPresent,
2922 (int)infoRec->rec.signal.signalType,
2923 (int)infoRec->rec.signal.alertPitch,
2924 (int)infoRec->rec.signal.signal);
2925 removeLastChar;
2926 break;
2927 case RIL_CDMA_REDIRECTING_NUMBER_INFO_REC:
2928 if (infoRec->rec.redir.redirectingNumber.len >
2929 CDMA_NUMBER_INFO_BUFFER_LENGTH) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002930 RLOGE("invalid display info response length %d \
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002931 expected not more than %d\n",
2932 (int)infoRec->rec.redir.redirectingNumber.len,
2933 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2934 return RIL_ERRNO_INVALID_RESPONSE;
2935 }
2936 string8 = (char*) malloc((infoRec->rec.redir.redirectingNumber
2937 .len + 1) * sizeof(char) );
2938 for (int i = 0;
2939 i < infoRec->rec.redir.redirectingNumber.len;
2940 i++) {
2941 string8[i] = infoRec->rec.redir.redirectingNumber.buf[i];
2942 }
2943 string8[(int)infoRec->rec.redir.redirectingNumber.len] = '\0';
2944 writeStringToParcel(p, (const char*)string8);
2945 free(string8);
2946 string8 = NULL;
2947 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_type);
2948 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_plan);
2949 p.writeInt32(infoRec->rec.redir.redirectingNumber.pi);
2950 p.writeInt32(infoRec->rec.redir.redirectingNumber.si);
2951 p.writeInt32(infoRec->rec.redir.redirectingReason);
2952 break;
2953 case RIL_CDMA_LINE_CONTROL_INFO_REC:
2954 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPolarityIncluded);
2955 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlToggle);
2956 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlReverse);
2957 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2958
2959 appendPrintBuf("%slineCtrlPolarityIncluded=%d, \
2960 lineCtrlToggle=%d, lineCtrlReverse=%d, \
2961 lineCtrlPowerDenial=%d, ", printBuf,
2962 (int)infoRec->rec.lineCtrl.lineCtrlPolarityIncluded,
2963 (int)infoRec->rec.lineCtrl.lineCtrlToggle,
2964 (int)infoRec->rec.lineCtrl.lineCtrlReverse,
2965 (int)infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2966 removeLastChar;
2967 break;
2968 case RIL_CDMA_T53_CLIR_INFO_REC:
2969 p.writeInt32((int)(infoRec->rec.clir.cause));
2970
2971 appendPrintBuf("%scause%d", printBuf, infoRec->rec.clir.cause);
2972 removeLastChar;
2973 break;
2974 case RIL_CDMA_T53_AUDIO_CONTROL_INFO_REC:
2975 p.writeInt32(infoRec->rec.audioCtrl.upLink);
2976 p.writeInt32(infoRec->rec.audioCtrl.downLink);
2977
2978 appendPrintBuf("%supLink=%d, downLink=%d, ", printBuf,
2979 infoRec->rec.audioCtrl.upLink,
2980 infoRec->rec.audioCtrl.downLink);
2981 removeLastChar;
2982 break;
2983 case RIL_CDMA_T53_RELEASE_INFO_REC:
2984 // TODO(Moto): See David Krause, he has the answer:)
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002985 RLOGE("RIL_CDMA_T53_RELEASE_INFO_REC: return INVALID_RESPONSE");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002986 return RIL_ERRNO_INVALID_RESPONSE;
2987 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002988 RLOGE("Incorrect name value");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002989 return RIL_ERRNO_INVALID_RESPONSE;
2990 }
2991 }
2992 closeResponse;
2993
2994 return 0;
2995}
2996
2997static int responseRilSignalStrength(Parcel &p,
2998 void *response, size_t responselen) {
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05302999 int gsmSignalStrength;
3000 int cdmaDbm;
3001 int evdoDbm;
3002
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003003 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003004 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003005 return RIL_ERRNO_INVALID_RESPONSE;
3006 }
3007
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003008 if (responselen >= sizeof (RIL_SignalStrength_v5)) {
Howard Sue32dbfd2015-01-07 15:55:57 +08003009 RIL_SignalStrength_v10 *p_cur = ((RIL_SignalStrength_v10 *) response);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003010
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303011 gsmSignalStrength = p_cur->GW_SignalStrength.signalStrength & 0xFF;
Utkarsh Gupta8ede9fa2015-04-23 13:21:49 +05303012
3013#ifdef MODEM_TYPE_XMM6260
3014 if (gsmSignalStrength < 0 ||
3015 (gsmSignalStrength > 31 && p_cur->GW_SignalStrength.signalStrength != 99)) {
3016 gsmSignalStrength = p_cur->CDMA_SignalStrength.dbm;
3017 }
3018#else
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303019 if (gsmSignalStrength < 0) {
3020 gsmSignalStrength = 99;
3021 } else if (gsmSignalStrength > 31 && gsmSignalStrength != 99) {
3022 gsmSignalStrength = 31;
3023 }
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303024#endif
3025 p.writeInt32(gsmSignalStrength);
3026
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003027 p.writeInt32(p_cur->GW_SignalStrength.bitErrorRate);
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303028
Christopher N. Hesse7bf409e2015-06-26 14:53:56 +02003029#if defined(MODEM_TYPE_XMM6262) || defined(MODEM_TYPE_XMM7260) || defined(MODEM_TYPE_M7450)
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303030 cdmaDbm = p_cur->CDMA_SignalStrength.dbm & 0xFF;
3031 if (cdmaDbm < 0) {
3032 cdmaDbm = 99;
3033 } else if (cdmaDbm > 31 && cdmaDbm != 99) {
3034 cdmaDbm = 31;
3035 }
3036#else
Caio Schnepperec042542015-04-14 08:03:43 -03003037 cdmaDbm = p_cur->CDMA_SignalStrength.dbm;
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303038#endif
3039 p.writeInt32(cdmaDbm);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003040 p.writeInt32(p_cur->CDMA_SignalStrength.ecio);
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303041
Christopher N. Hesse7bf409e2015-06-26 14:53:56 +02003042#if defined(MODEM_TYPE_XMM6262) || defined(MODEM_TYPE_XMM7260) || defined(MODEM_TYPE_M7450)
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303043 evdoDbm = p_cur->EVDO_SignalStrength.dbm & 0xFF;
3044 if (evdoDbm < 0) {
3045 evdoDbm = 99;
3046 } else if (evdoDbm > 31 && evdoDbm != 99) {
3047 evdoDbm = 31;
3048 }
3049#else
3050 evdoDbm = p_cur->EVDO_SignalStrength.dbm;
3051#endif
3052 p.writeInt32(evdoDbm);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003053 p.writeInt32(p_cur->EVDO_SignalStrength.ecio);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003054 p.writeInt32(p_cur->EVDO_SignalStrength.signalNoiseRatio);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003055 if (responselen >= sizeof (RIL_SignalStrength_v6)) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003056 /*
Ethan Chend6e30652013-08-04 22:49:56 -07003057 * Fixup LTE for backwards compatibility
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003058 */
Ethan Chend6e30652013-08-04 22:49:56 -07003059 if (s_callbacks.version <= 6) {
3060 // signalStrength: -1 -> 99
3061 if (p_cur->LTE_SignalStrength.signalStrength == -1) {
3062 p_cur->LTE_SignalStrength.signalStrength = 99;
3063 }
3064 // rsrp: -1 -> INT_MAX all other negative value to positive.
3065 // So remap here
3066 if (p_cur->LTE_SignalStrength.rsrp == -1) {
3067 p_cur->LTE_SignalStrength.rsrp = INT_MAX;
3068 } else if (p_cur->LTE_SignalStrength.rsrp < -1) {
3069 p_cur->LTE_SignalStrength.rsrp = -p_cur->LTE_SignalStrength.rsrp;
3070 }
3071 // rsrq: -1 -> INT_MAX
3072 if (p_cur->LTE_SignalStrength.rsrq == -1) {
3073 p_cur->LTE_SignalStrength.rsrq = INT_MAX;
3074 }
3075 // Not remapping rssnr is already using INT_MAX
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003076
Ethan Chend6e30652013-08-04 22:49:56 -07003077 // cqi: -1 -> INT_MAX
3078 if (p_cur->LTE_SignalStrength.cqi == -1) {
3079 p_cur->LTE_SignalStrength.cqi = INT_MAX;
3080 }
3081 }
3082 p.writeInt32(p_cur->LTE_SignalStrength.signalStrength);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003083 p.writeInt32(p_cur->LTE_SignalStrength.rsrp);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003084 p.writeInt32(p_cur->LTE_SignalStrength.rsrq);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003085 p.writeInt32(p_cur->LTE_SignalStrength.rssnr);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003086 p.writeInt32(p_cur->LTE_SignalStrength.cqi);
Howard Sue32dbfd2015-01-07 15:55:57 +08003087 if (responselen >= sizeof (RIL_SignalStrength_v10)) {
3088 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
3089 } else {
3090 p.writeInt32(INT_MAX);
3091 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003092 } else {
Ethan Chend6e30652013-08-04 22:49:56 -07003093 p.writeInt32(99);
3094 p.writeInt32(INT_MAX);
3095 p.writeInt32(INT_MAX);
3096 p.writeInt32(INT_MAX);
3097 p.writeInt32(INT_MAX);
Howard Sue32dbfd2015-01-07 15:55:57 +08003098 p.writeInt32(INT_MAX);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003099 }
3100
3101 startResponse;
3102 appendPrintBuf("%s[signalStrength=%d,bitErrorRate=%d,\
3103 CDMA_SS.dbm=%d,CDMA_SSecio=%d,\
3104 EVDO_SS.dbm=%d,EVDO_SS.ecio=%d,\
3105 EVDO_SS.signalNoiseRatio=%d,\
3106 LTE_SS.signalStrength=%d,LTE_SS.rsrp=%d,LTE_SS.rsrq=%d,\
Howard Sue32dbfd2015-01-07 15:55:57 +08003107 LTE_SS.rssnr=%d,LTE_SS.cqi=%d,TDSCDMA_SS.rscp=%d]",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003108 printBuf,
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303109 gsmSignalStrength,
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003110 p_cur->GW_SignalStrength.bitErrorRate,
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303111 cdmaDbm,
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003112 p_cur->CDMA_SignalStrength.ecio,
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303113 evdoDbm,
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003114 p_cur->EVDO_SignalStrength.ecio,
3115 p_cur->EVDO_SignalStrength.signalNoiseRatio,
3116 p_cur->LTE_SignalStrength.signalStrength,
3117 p_cur->LTE_SignalStrength.rsrp,
3118 p_cur->LTE_SignalStrength.rsrq,
3119 p_cur->LTE_SignalStrength.rssnr,
Howard Sue32dbfd2015-01-07 15:55:57 +08003120 p_cur->LTE_SignalStrength.cqi,
3121 p_cur->TD_SCDMA_SignalStrength.rscp);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003122 closeResponse;
3123
3124 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003125 RLOGE("invalid response length");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003126 return RIL_ERRNO_INVALID_RESPONSE;
3127 }
3128
3129 return 0;
3130}
3131
3132static int responseCallRing(Parcel &p, void *response, size_t responselen) {
3133 if ((response == NULL) || (responselen == 0)) {
3134 return responseVoid(p, response, responselen);
3135 } else {
3136 return responseCdmaSignalInfoRecord(p, response, responselen);
3137 }
3138}
3139
3140static int responseCdmaSignalInfoRecord(Parcel &p, void *response, size_t responselen) {
3141 if (response == NULL || responselen == 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003142 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003143 return RIL_ERRNO_INVALID_RESPONSE;
3144 }
3145
3146 if (responselen != sizeof (RIL_CDMA_SignalInfoRecord)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003147 RLOGE("invalid response length %d expected sizeof (RIL_CDMA_SignalInfoRecord) of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003148 (int)responselen, (int)sizeof (RIL_CDMA_SignalInfoRecord));
3149 return RIL_ERRNO_INVALID_RESPONSE;
3150 }
3151
3152 startResponse;
3153
3154 RIL_CDMA_SignalInfoRecord *p_cur = ((RIL_CDMA_SignalInfoRecord *) response);
3155 marshallSignalInfoRecord(p, *p_cur);
3156
3157 appendPrintBuf("%s[isPresent=%d,signalType=%d,alertPitch=%d\
3158 signal=%d]",
3159 printBuf,
3160 p_cur->isPresent,
3161 p_cur->signalType,
3162 p_cur->alertPitch,
3163 p_cur->signal);
3164
3165 closeResponse;
3166 return 0;
3167}
3168
3169static int responseCdmaCallWaiting(Parcel &p, void *response,
3170 size_t responselen) {
3171 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003172 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003173 return RIL_ERRNO_INVALID_RESPONSE;
3174 }
3175
3176 if (responselen < sizeof(RIL_CDMA_CallWaiting_v6)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003177 RLOGW("Upgrade to ril version %d\n", RIL_VERSION);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003178 }
3179
3180 RIL_CDMA_CallWaiting_v6 *p_cur = ((RIL_CDMA_CallWaiting_v6 *) response);
3181
3182 writeStringToParcel(p, p_cur->number);
3183 p.writeInt32(p_cur->numberPresentation);
3184 writeStringToParcel(p, p_cur->name);
3185 marshallSignalInfoRecord(p, p_cur->signalInfoRecord);
3186
3187 if (responselen >= sizeof(RIL_CDMA_CallWaiting_v6)) {
3188 p.writeInt32(p_cur->number_type);
3189 p.writeInt32(p_cur->number_plan);
3190 } else {
3191 p.writeInt32(0);
3192 p.writeInt32(0);
3193 }
3194
3195 startResponse;
3196 appendPrintBuf("%snumber=%s,numberPresentation=%d, name=%s,\
3197 signalInfoRecord[isPresent=%d,signalType=%d,alertPitch=%d\
3198 signal=%d,number_type=%d,number_plan=%d]",
3199 printBuf,
3200 p_cur->number,
3201 p_cur->numberPresentation,
3202 p_cur->name,
3203 p_cur->signalInfoRecord.isPresent,
3204 p_cur->signalInfoRecord.signalType,
3205 p_cur->signalInfoRecord.alertPitch,
3206 p_cur->signalInfoRecord.signal,
3207 p_cur->number_type,
3208 p_cur->number_plan);
3209 closeResponse;
3210
3211 return 0;
3212}
3213
3214static int responseSimRefresh(Parcel &p, void *response, size_t responselen) {
3215 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003216 RLOGE("responseSimRefresh: invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003217 return RIL_ERRNO_INVALID_RESPONSE;
3218 }
3219
3220 startResponse;
3221 if (s_callbacks.version == 7) {
3222 RIL_SimRefreshResponse_v7 *p_cur = ((RIL_SimRefreshResponse_v7 *) response);
3223 p.writeInt32(p_cur->result);
3224 p.writeInt32(p_cur->ef_id);
3225 writeStringToParcel(p, p_cur->aid);
3226
3227 appendPrintBuf("%sresult=%d, ef_id=%d, aid=%s",
3228 printBuf,
3229 p_cur->result,
3230 p_cur->ef_id,
3231 p_cur->aid);
3232 } else {
3233 int *p_cur = ((int *) response);
3234 p.writeInt32(p_cur[0]);
3235 p.writeInt32(p_cur[1]);
3236 writeStringToParcel(p, NULL);
3237
3238 appendPrintBuf("%sresult=%d, ef_id=%d",
3239 printBuf,
3240 p_cur[0],
3241 p_cur[1]);
3242 }
3243 closeResponse;
3244
3245 return 0;
3246}
3247
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003248static int responseCellInfoList(Parcel &p, void *response, size_t responselen)
3249{
3250 if (response == NULL && responselen != 0) {
3251 RLOGE("invalid response: NULL");
3252 return RIL_ERRNO_INVALID_RESPONSE;
3253 }
3254
3255 if (responselen % sizeof(RIL_CellInfo) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08003256 RLOGE("responseCellInfoList: invalid response length %d expected multiple of %d",
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003257 (int)responselen, (int)sizeof(RIL_CellInfo));
3258 return RIL_ERRNO_INVALID_RESPONSE;
3259 }
3260
3261 int num = responselen / sizeof(RIL_CellInfo);
3262 p.writeInt32(num);
3263
3264 RIL_CellInfo *p_cur = (RIL_CellInfo *) response;
3265 startResponse;
3266 int i;
3267 for (i = 0; i < num; i++) {
3268 appendPrintBuf("%s[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", printBuf, i,
3269 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
3270 p.writeInt32((int)p_cur->cellInfoType);
3271 p.writeInt32(p_cur->registered);
3272 p.writeInt32(p_cur->timeStampType);
3273 p.writeInt64(p_cur->timeStamp);
3274 switch(p_cur->cellInfoType) {
3275 case RIL_CELL_INFO_TYPE_GSM: {
3276 appendPrintBuf("%s GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,", printBuf,
3277 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
3278 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
3279 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
3280 p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3281 appendPrintBuf("%s gsmSS: ss=%d,ber=%d],", printBuf,
3282 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
3283 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3284
3285 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
3286 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
3287 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
3288 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3289 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
3290 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3291 break;
3292 }
3293 case RIL_CELL_INFO_TYPE_WCDMA: {
3294 appendPrintBuf("%s WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,", printBuf,
3295 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
3296 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
3297 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
3298 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
3299 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3300 appendPrintBuf("%s wcdmaSS: ss=%d,ber=%d],", printBuf,
3301 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
3302 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3303
3304 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
3305 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
3306 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
3307 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
3308 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3309 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
3310 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3311 break;
3312 }
3313 case RIL_CELL_INFO_TYPE_CDMA: {
3314 appendPrintBuf("%s CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d", printBuf,
3315 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
3316 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
3317 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
3318 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
3319 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3320
3321 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
3322 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
3323 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
3324 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
3325 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3326
3327 appendPrintBuf("%s cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d", printBuf,
3328 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
3329 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
3330 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
3331 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
3332 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3333
3334 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
3335 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
3336 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
3337 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
3338 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3339 break;
3340 }
3341 case RIL_CELL_INFO_TYPE_LTE: {
3342 appendPrintBuf("%s LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d", printBuf,
3343 p_cur->CellInfo.lte.cellIdentityLte.mcc,
3344 p_cur->CellInfo.lte.cellIdentityLte.mnc,
3345 p_cur->CellInfo.lte.cellIdentityLte.ci,
3346 p_cur->CellInfo.lte.cellIdentityLte.pci,
3347 p_cur->CellInfo.lte.cellIdentityLte.tac);
3348
3349 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
3350 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
3351 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
3352 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
3353 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
3354
3355 appendPrintBuf("%s lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d", printBuf,
3356 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
3357 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
3358 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
3359 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
3360 p_cur->CellInfo.lte.signalStrengthLte.cqi,
3361 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3362 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
3363 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
3364 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
3365 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
3366 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
3367 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3368 break;
3369 }
Howard Sue32dbfd2015-01-07 15:55:57 +08003370 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
3371 appendPrintBuf("%s TDSCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,cpid=%d,", printBuf,
3372 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc,
3373 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc,
3374 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac,
3375 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid,
3376 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3377 appendPrintBuf("%s tdscdmaSS: rscp=%d],", printBuf,
3378 p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3379
3380 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
3381 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
3382 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
3383 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
3384 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3385 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3386 break;
3387 }
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003388 }
3389 p_cur += 1;
3390 }
3391 removeLastChar;
3392 closeResponse;
3393
3394 return 0;
3395}
3396
Howard Sue32dbfd2015-01-07 15:55:57 +08003397static int responseHardwareConfig(Parcel &p, void *response, size_t responselen)
3398{
3399 if (response == NULL && responselen != 0) {
3400 RLOGE("invalid response: NULL");
3401 return RIL_ERRNO_INVALID_RESPONSE;
3402 }
3403
3404 if (responselen % sizeof(RIL_HardwareConfig) != 0) {
3405 RLOGE("responseHardwareConfig: invalid response length %d expected multiple of %d",
3406 (int)responselen, (int)sizeof(RIL_HardwareConfig));
3407 return RIL_ERRNO_INVALID_RESPONSE;
3408 }
3409
3410 int num = responselen / sizeof(RIL_HardwareConfig);
3411 int i;
3412 RIL_HardwareConfig *p_cur = (RIL_HardwareConfig *) response;
3413
3414 p.writeInt32(num);
3415
3416 startResponse;
3417 for (i = 0; i < num; i++) {
3418 switch (p_cur[i].type) {
3419 case RIL_HARDWARE_CONFIG_MODEM: {
3420 writeStringToParcel(p, p_cur[i].uuid);
3421 p.writeInt32((int)p_cur[i].state);
3422 p.writeInt32(p_cur[i].cfg.modem.rat);
3423 p.writeInt32(p_cur[i].cfg.modem.maxVoice);
3424 p.writeInt32(p_cur[i].cfg.modem.maxData);
3425 p.writeInt32(p_cur[i].cfg.modem.maxStandby);
3426
3427 appendPrintBuf("%s modem: uuid=%s,state=%d,rat=%08x,maxV=%d,maxD=%d,maxS=%d", printBuf,
3428 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.modem.rat,
3429 p_cur[i].cfg.modem.maxVoice, p_cur[i].cfg.modem.maxData, p_cur[i].cfg.modem.maxStandby);
3430 break;
3431 }
3432 case RIL_HARDWARE_CONFIG_SIM: {
3433 writeStringToParcel(p, p_cur[i].uuid);
3434 p.writeInt32((int)p_cur[i].state);
3435 writeStringToParcel(p, p_cur[i].cfg.sim.modemUuid);
3436
3437 appendPrintBuf("%s sim: uuid=%s,state=%d,modem-uuid=%s", printBuf,
3438 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.sim.modemUuid);
3439 break;
3440 }
3441 }
3442 }
3443 removeLastChar;
3444 closeResponse;
3445 return 0;
3446}
3447
Howard Subd82ef12015-04-12 10:25:05 +02003448static int responseRadioCapability(Parcel &p, void *response, size_t responselen) {
3449 if (response == NULL) {
3450 RLOGE("invalid response: NULL");
3451 return RIL_ERRNO_INVALID_RESPONSE;
3452 }
3453
3454 if (responselen != sizeof (RIL_RadioCapability) ) {
3455 RLOGE("invalid response length was %d expected %d",
3456 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3457 return RIL_ERRNO_INVALID_RESPONSE;
3458 }
3459
3460 RIL_RadioCapability *p_cur = (RIL_RadioCapability *) response;
3461 p.writeInt32(p_cur->version);
3462 p.writeInt32(p_cur->session);
3463 p.writeInt32(p_cur->phase);
3464 p.writeInt32(p_cur->rat);
3465 writeStringToParcel(p, p_cur->logicalModemUuid);
3466 p.writeInt32(p_cur->status);
3467
3468 startResponse;
3469 appendPrintBuf("%s[version=%d,session=%d,phase=%d,\
Andreas Schneidera8d09502015-06-23 18:41:38 +02003470 rat=%d,logicalModemUuid=%s,status=%d]",
Howard Subd82ef12015-04-12 10:25:05 +02003471 printBuf,
3472 p_cur->version,
3473 p_cur->session,
3474 p_cur->phase,
3475 p_cur->rat,
3476 p_cur->logicalModemUuid,
3477 p_cur->status);
3478 closeResponse;
3479 return 0;
3480}
3481
3482static int responseSSData(Parcel &p, void *response, size_t responselen) {
3483 RLOGD("In responseSSData");
3484 int num;
3485
3486 if (response == NULL && responselen != 0) {
3487 RLOGE("invalid response length was %d expected %d",
3488 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3489 return RIL_ERRNO_INVALID_RESPONSE;
3490 }
3491
3492 if (responselen != sizeof(RIL_StkCcUnsolSsResponse)) {
3493 RLOGE("invalid response length %d, expected %d",
3494 (int)responselen, (int)sizeof(RIL_StkCcUnsolSsResponse));
3495 return RIL_ERRNO_INVALID_RESPONSE;
3496 }
3497
3498 startResponse;
3499 RIL_StkCcUnsolSsResponse *p_cur = (RIL_StkCcUnsolSsResponse *) response;
3500 p.writeInt32(p_cur->serviceType);
3501 p.writeInt32(p_cur->requestType);
3502 p.writeInt32(p_cur->teleserviceType);
3503 p.writeInt32(p_cur->serviceClass);
3504 p.writeInt32(p_cur->result);
3505
3506 if (isServiceTypeCfQuery(p_cur->serviceType, p_cur->requestType)) {
3507 RLOGD("responseSSData CF type, num of Cf elements %d", p_cur->cfData.numValidIndexes);
3508 if (p_cur->cfData.numValidIndexes > NUM_SERVICE_CLASSES) {
3509 RLOGE("numValidIndexes is greater than max value %d, "
3510 "truncating it to max value", NUM_SERVICE_CLASSES);
3511 p_cur->cfData.numValidIndexes = NUM_SERVICE_CLASSES;
3512 }
3513 /* number of call info's */
3514 p.writeInt32(p_cur->cfData.numValidIndexes);
3515
3516 for (int i = 0; i < p_cur->cfData.numValidIndexes; i++) {
3517 RIL_CallForwardInfo cf = p_cur->cfData.cfInfo[i];
3518
3519 p.writeInt32(cf.status);
3520 p.writeInt32(cf.reason);
3521 p.writeInt32(cf.serviceClass);
3522 p.writeInt32(cf.toa);
3523 writeStringToParcel(p, cf.number);
3524 p.writeInt32(cf.timeSeconds);
3525 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
3526 (cf.status==1)?"enable":"disable", cf.reason, cf.serviceClass, cf.toa,
3527 (char*)cf.number, cf.timeSeconds);
3528 RLOGD("Data: %d,reason=%d,cls=%d,toa=%d,num=%s,tout=%d],", cf.status,
3529 cf.reason, cf.serviceClass, cf.toa, (char*)cf.number, cf.timeSeconds);
3530 }
3531 } else {
3532 p.writeInt32 (SS_INFO_MAX);
3533
3534 /* each int*/
3535 for (int i = 0; i < SS_INFO_MAX; i++) {
3536 appendPrintBuf("%s%d,", printBuf, p_cur->ssInfo[i]);
3537 RLOGD("Data: %d",p_cur->ssInfo[i]);
3538 p.writeInt32(p_cur->ssInfo[i]);
3539 }
3540 }
3541 removeLastChar;
3542 closeResponse;
3543
3544 return 0;
3545}
3546
3547static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType) {
3548 if ((reqType == SS_INTERROGATION) &&
3549 (serType == SS_CFU ||
3550 serType == SS_CF_BUSY ||
3551 serType == SS_CF_NO_REPLY ||
3552 serType == SS_CF_NOT_REACHABLE ||
3553 serType == SS_CF_ALL ||
3554 serType == SS_CF_ALL_CONDITIONAL)) {
3555 return true;
3556 }
3557 return false;
3558}
3559
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003560static void triggerEvLoop() {
3561 int ret;
3562 if (!pthread_equal(pthread_self(), s_tid_dispatch)) {
3563 /* trigger event loop to wakeup. No reason to do this,
3564 * if we're in the event loop thread */
3565 do {
3566 ret = write (s_fdWakeupWrite, " ", 1);
3567 } while (ret < 0 && errno == EINTR);
3568 }
3569}
3570
3571static void rilEventAddWakeup(struct ril_event *ev) {
3572 ril_event_add(ev);
3573 triggerEvLoop();
3574}
3575
3576static void sendSimStatusAppInfo(Parcel &p, int num_apps, RIL_AppStatus appStatus[]) {
3577 p.writeInt32(num_apps);
3578 startResponse;
3579 for (int i = 0; i < num_apps; i++) {
3580 p.writeInt32(appStatus[i].app_type);
3581 p.writeInt32(appStatus[i].app_state);
3582 p.writeInt32(appStatus[i].perso_substate);
3583 writeStringToParcel(p, (const char*)(appStatus[i].aid_ptr));
3584 writeStringToParcel(p, (const char*)
3585 (appStatus[i].app_label_ptr));
3586 p.writeInt32(appStatus[i].pin1_replaced);
3587 p.writeInt32(appStatus[i].pin1);
3588 p.writeInt32(appStatus[i].pin2);
3589 appendPrintBuf("%s[app_type=%d,app_state=%d,perso_substate=%d,\
3590 aid_ptr=%s,app_label_ptr=%s,pin1_replaced=%d,pin1=%d,pin2=%d],",
3591 printBuf,
3592 appStatus[i].app_type,
3593 appStatus[i].app_state,
3594 appStatus[i].perso_substate,
3595 appStatus[i].aid_ptr,
3596 appStatus[i].app_label_ptr,
3597 appStatus[i].pin1_replaced,
3598 appStatus[i].pin1,
3599 appStatus[i].pin2);
3600 }
3601 closeResponse;
3602}
3603
3604static int responseSimStatus(Parcel &p, void *response, size_t responselen) {
Howard Sue32dbfd2015-01-07 15:55:57 +08003605 int i;
3606
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003607 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003608 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003609 return RIL_ERRNO_INVALID_RESPONSE;
3610 }
3611
3612 if (responselen == sizeof (RIL_CardStatus_v6)) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003613 RIL_CardStatus_v6 *p_cur = ((RIL_CardStatus_v6 *) response);
3614
3615 p.writeInt32(p_cur->card_state);
3616 p.writeInt32(p_cur->universal_pin_state);
3617 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3618 p.writeInt32(p_cur->cdma_subscription_app_index);
3619 p.writeInt32(p_cur->ims_subscription_app_index);
3620
3621 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
3622 } else if (responselen == sizeof (RIL_CardStatus_v5)) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003623 RIL_CardStatus_v5 *p_cur = ((RIL_CardStatus_v5 *) response);
3624
3625 p.writeInt32(p_cur->card_state);
3626 p.writeInt32(p_cur->universal_pin_state);
3627 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3628 p.writeInt32(p_cur->cdma_subscription_app_index);
3629 p.writeInt32(-1);
3630
3631 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
3632 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003633 RLOGE("responseSimStatus: A RilCardStatus_v6 or _v5 expected\n");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003634 return RIL_ERRNO_INVALID_RESPONSE;
3635 }
3636
3637 return 0;
3638}
3639
3640static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3641 int num = responselen / sizeof(RIL_GSM_BroadcastSmsConfigInfo *);
3642 p.writeInt32(num);
3643
3644 startResponse;
3645 RIL_GSM_BroadcastSmsConfigInfo **p_cur =
3646 (RIL_GSM_BroadcastSmsConfigInfo **) response;
3647 for (int i = 0; i < num; i++) {
3648 p.writeInt32(p_cur[i]->fromServiceId);
3649 p.writeInt32(p_cur[i]->toServiceId);
3650 p.writeInt32(p_cur[i]->fromCodeScheme);
3651 p.writeInt32(p_cur[i]->toCodeScheme);
3652 p.writeInt32(p_cur[i]->selected);
3653
3654 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId=%d, \
3655 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]",
3656 printBuf, i, p_cur[i]->fromServiceId, p_cur[i]->toServiceId,
3657 p_cur[i]->fromCodeScheme, p_cur[i]->toCodeScheme,
3658 p_cur[i]->selected);
3659 }
3660 closeResponse;
3661
3662 return 0;
3663}
3664
3665static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3666 RIL_CDMA_BroadcastSmsConfigInfo **p_cur =
3667 (RIL_CDMA_BroadcastSmsConfigInfo **) response;
3668
3669 int num = responselen / sizeof (RIL_CDMA_BroadcastSmsConfigInfo *);
3670 p.writeInt32(num);
3671
3672 startResponse;
3673 for (int i = 0 ; i < num ; i++ ) {
3674 p.writeInt32(p_cur[i]->service_category);
3675 p.writeInt32(p_cur[i]->language);
3676 p.writeInt32(p_cur[i]->selected);
3677
3678 appendPrintBuf("%s [%d: srvice_category=%d, language =%d, \
3679 selected =%d], ",
3680 printBuf, i, p_cur[i]->service_category, p_cur[i]->language,
3681 p_cur[i]->selected);
3682 }
3683 closeResponse;
3684
3685 return 0;
3686}
3687
3688static int responseCdmaSms(Parcel &p, void *response, size_t responselen) {
3689 int num;
3690 int digitCount;
3691 int digitLimit;
3692 uint8_t uct;
3693 void* dest;
3694
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003695 RLOGD("Inside responseCdmaSms");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003696
3697 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003698 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003699 return RIL_ERRNO_INVALID_RESPONSE;
3700 }
3701
3702 if (responselen != sizeof(RIL_CDMA_SMS_Message)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003703 RLOGE("invalid response length was %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003704 (int)responselen, (int)sizeof(RIL_CDMA_SMS_Message));
3705 return RIL_ERRNO_INVALID_RESPONSE;
3706 }
3707
3708 RIL_CDMA_SMS_Message *p_cur = (RIL_CDMA_SMS_Message *) response;
3709 p.writeInt32(p_cur->uTeleserviceID);
3710 p.write(&(p_cur->bIsServicePresent),sizeof(uct));
3711 p.writeInt32(p_cur->uServicecategory);
3712 p.writeInt32(p_cur->sAddress.digit_mode);
3713 p.writeInt32(p_cur->sAddress.number_mode);
3714 p.writeInt32(p_cur->sAddress.number_type);
3715 p.writeInt32(p_cur->sAddress.number_plan);
3716 p.write(&(p_cur->sAddress.number_of_digits), sizeof(uct));
3717 digitLimit= MIN((p_cur->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
3718 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3719 p.write(&(p_cur->sAddress.digits[digitCount]),sizeof(uct));
3720 }
3721
3722 p.writeInt32(p_cur->sSubAddress.subaddressType);
3723 p.write(&(p_cur->sSubAddress.odd),sizeof(uct));
3724 p.write(&(p_cur->sSubAddress.number_of_digits),sizeof(uct));
3725 digitLimit= MIN((p_cur->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
3726 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3727 p.write(&(p_cur->sSubAddress.digits[digitCount]),sizeof(uct));
3728 }
3729
3730 digitLimit= MIN((p_cur->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
3731 p.writeInt32(p_cur->uBearerDataLen);
3732 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3733 p.write(&(p_cur->aBearerData[digitCount]), sizeof(uct));
3734 }
3735
3736 startResponse;
3737 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
3738 sAddress.digit_mode=%d, sAddress.number_mode=%d, sAddress.number_type=%d, ",
3739 printBuf, p_cur->uTeleserviceID,p_cur->bIsServicePresent,p_cur->uServicecategory,
3740 p_cur->sAddress.digit_mode, p_cur->sAddress.number_mode,p_cur->sAddress.number_type);
3741 closeResponse;
3742
3743 return 0;
3744}
3745
Howard Sue32dbfd2015-01-07 15:55:57 +08003746static int responseDcRtInfo(Parcel &p, void *response, size_t responselen)
3747{
3748 int num = responselen / sizeof(RIL_DcRtInfo);
3749 if ((responselen % sizeof(RIL_DcRtInfo) != 0) || (num != 1)) {
3750 RLOGE("responseDcRtInfo: invalid response length %d expected multiple of %d",
3751 (int)responselen, (int)sizeof(RIL_DcRtInfo));
3752 return RIL_ERRNO_INVALID_RESPONSE;
3753 }
3754
3755 startResponse;
3756 RIL_DcRtInfo *pDcRtInfo = (RIL_DcRtInfo *)response;
3757 p.writeInt64(pDcRtInfo->time);
3758 p.writeInt32(pDcRtInfo->powerState);
3759 appendPrintBuf("%s[time=%d,powerState=%d]", printBuf,
3760 pDcRtInfo->time,
Andreas Schneidera8d09502015-06-23 18:41:38 +02003761 (int)pDcRtInfo->powerState);
Howard Sue32dbfd2015-01-07 15:55:57 +08003762 closeResponse;
3763
3764 return 0;
3765}
3766
fenglu9bdede02015-04-14 14:53:55 -07003767static int responseLceStatus(Parcel &p, void *response, size_t responselen) {
3768 if (response == NULL || responselen != sizeof(RIL_LceStatusInfo)) {
3769 if (response == NULL) {
3770 RLOGE("invalid response: NULL");
3771 }
3772 else {
3773 RLOGE("responseLceStatus: invalid response length %d expecting len: d%",
3774 sizeof(RIL_LceStatusInfo), responselen);
3775 }
3776 return RIL_ERRNO_INVALID_RESPONSE;
3777 }
3778
3779 RIL_LceStatusInfo *p_cur = (RIL_LceStatusInfo *)response;
3780 p.write((void *)p_cur, 1); // p_cur->lce_status takes one byte.
3781 p.writeInt32(p_cur->actual_interval_ms);
3782
3783 startResponse;
3784 appendPrintBuf("LCE Status: %d, actual_interval_ms: %d",
3785 p_cur->lce_status, p_cur->actual_interval_ms);
3786 closeResponse;
3787
3788 return 0;
3789}
3790
3791static int responseLceData(Parcel &p, void *response, size_t responselen) {
3792 if (response == NULL || responselen != sizeof(RIL_LceDataInfo)) {
3793 if (response == NULL) {
3794 RLOGE("invalid response: NULL");
3795 }
3796 else {
3797 RLOGE("responseLceData: invalid response length %d expecting len: d%",
3798 sizeof(RIL_LceDataInfo), responselen);
3799 }
3800 return RIL_ERRNO_INVALID_RESPONSE;
3801 }
3802
3803 RIL_LceDataInfo *p_cur = (RIL_LceDataInfo *)response;
3804 p.writeInt32(p_cur->last_hop_capacity_kbps);
3805
3806 /* p_cur->confidence_level and p_cur->lce_suspended take 1 byte each.*/
3807 p.write((void *)&(p_cur->confidence_level), 1);
3808 p.write((void *)&(p_cur->lce_suspended), 1);
3809
3810 startResponse;
forkbombe0568e12015-11-23 18:37:37 +11003811 appendPrintBuf("LCE info received: capacity %d confidence level %d"
3812 "and suspended %d",
fenglu9bdede02015-04-14 14:53:55 -07003813 p_cur->last_hop_capacity_kbps, p_cur->confidence_level,
3814 p_cur->lce_suspended);
3815 closeResponse;
3816
3817 return 0;
3818}
3819
Prerepa Viswanadham8e755592015-05-28 00:37:32 -07003820static int responseActivityData(Parcel &p, void *response, size_t responselen) {
3821 if (response == NULL || responselen != sizeof(RIL_ActivityStatsInfo)) {
3822 if (response == NULL) {
3823 RLOGE("invalid response: NULL");
3824 }
3825 else {
3826 RLOGE("responseActivityData: invalid response length %d expecting len: d%",
3827 sizeof(RIL_ActivityStatsInfo), responselen);
3828 }
3829 return RIL_ERRNO_INVALID_RESPONSE;
3830 }
3831
3832 RIL_ActivityStatsInfo *p_cur = (RIL_ActivityStatsInfo *)response;
3833 p.writeInt32(p_cur->sleep_mode_time_ms);
3834 p.writeInt32(p_cur->idle_mode_time_ms);
3835 for(int i = 0; i < RIL_NUM_TX_POWER_LEVELS; i++) {
3836 p.writeInt32(p_cur->tx_mode_time_ms[i]);
3837 }
3838 p.writeInt32(p_cur->rx_mode_time_ms);
3839
3840 startResponse;
forkbombe0568e12015-11-23 18:37:37 +11003841 appendPrintBuf("Modem activity info received: sleep_mode_time_ms %d idle_mode_time_ms %d"
3842 "tx_mode_time_ms %d %d %d %d %d and rx_mode_time_ms %d",
Prerepa Viswanadham8e755592015-05-28 00:37:32 -07003843 p_cur->sleep_mode_time_ms, p_cur->idle_mode_time_ms, p_cur->tx_mode_time_ms[0],
3844 p_cur->tx_mode_time_ms[1], p_cur->tx_mode_time_ms[2], p_cur->tx_mode_time_ms[3],
3845 p_cur->tx_mode_time_ms[4], p_cur->rx_mode_time_ms);
3846 closeResponse;
3847
3848 return 0;
3849}
3850
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003851/**
3852 * A write on the wakeup fd is done just to pop us out of select()
3853 * We empty the buffer here and then ril_event will reset the timers on the
3854 * way back down
3855 */
3856static void processWakeupCallback(int fd, short flags, void *param) {
3857 char buff[16];
3858 int ret;
3859
Ethan Chend6e30652013-08-04 22:49:56 -07003860 RLOGV("processWakeupCallback");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003861
3862 /* empty our wakeup socket out */
3863 do {
3864 ret = read(s_fdWakeupRead, &buff, sizeof(buff));
3865 } while (ret > 0 || (ret < 0 && errno == EINTR));
3866}
3867
Howard Sue32dbfd2015-01-07 15:55:57 +08003868static void onCommandsSocketClosed(RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003869 int ret;
3870 RequestInfo *p_cur;
Howard Sue32dbfd2015-01-07 15:55:57 +08003871 /* Hook for current context
3872 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
3873 pthread_mutex_t * pendingRequestsMutexHook = &s_pendingRequestsMutex;
3874 /* pendingRequestsHook refer to &s_pendingRequests */
3875 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003876
Howard Sue32dbfd2015-01-07 15:55:57 +08003877#if (SIM_COUNT >= 2)
3878 if (socket_id == RIL_SOCKET_2) {
3879 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
3880 pendingRequestsHook = &s_pendingRequests_socket2;
3881 }
3882#if (SIM_COUNT >= 3)
3883 else if (socket_id == RIL_SOCKET_3) {
3884 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
3885 pendingRequestsHook = &s_pendingRequests_socket3;
3886 }
3887#endif
3888#if (SIM_COUNT >= 4)
3889 else if (socket_id == RIL_SOCKET_4) {
3890 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
3891 pendingRequestsHook = &s_pendingRequests_socket4;
3892 }
3893#endif
3894#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003895 /* mark pending requests as "cancelled" so we dont report responses */
Howard Sue32dbfd2015-01-07 15:55:57 +08003896 ret = pthread_mutex_lock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003897 assert (ret == 0);
3898
Howard Sue32dbfd2015-01-07 15:55:57 +08003899 p_cur = *pendingRequestsHook;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003900
Howard Sue32dbfd2015-01-07 15:55:57 +08003901 for (p_cur = *pendingRequestsHook
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003902 ; p_cur != NULL
3903 ; p_cur = p_cur->p_next
3904 ) {
3905 p_cur->cancelled = 1;
3906 }
3907
Howard Sue32dbfd2015-01-07 15:55:57 +08003908 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003909 assert (ret == 0);
3910}
3911
3912static void processCommandsCallback(int fd, short flags, void *param) {
3913 RecordStream *p_rs;
3914 void *p_record;
3915 size_t recordlen;
3916 int ret;
Howard Sue32dbfd2015-01-07 15:55:57 +08003917 SocketListenParam *p_info = (SocketListenParam *)param;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003918
Howard Sue32dbfd2015-01-07 15:55:57 +08003919 assert(fd == p_info->fdCommand);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003920
Howard Sue32dbfd2015-01-07 15:55:57 +08003921 p_rs = p_info->p_rs;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003922
3923 for (;;) {
3924 /* loop until EAGAIN/EINTR, end of stream, or other error */
3925 ret = record_stream_get_next(p_rs, &p_record, &recordlen);
3926
3927 if (ret == 0 && p_record == NULL) {
3928 /* end-of-stream */
3929 break;
3930 } else if (ret < 0) {
3931 break;
3932 } else if (ret == 0) { /* && p_record != NULL */
Howard Sue32dbfd2015-01-07 15:55:57 +08003933 processCommandBuffer(p_record, recordlen, p_info->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003934 }
3935 }
3936
3937 if (ret == 0 || !(errno == EAGAIN || errno == EINTR)) {
3938 /* fatal error or end-of-stream */
3939 if (ret != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003940 RLOGE("error on reading command socket errno:%d\n", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003941 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003942 RLOGW("EOS. Closing command socket.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003943 }
3944
Howard Sue32dbfd2015-01-07 15:55:57 +08003945 close(fd);
3946 p_info->fdCommand = -1;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003947
Howard Sue32dbfd2015-01-07 15:55:57 +08003948 ril_event_del(p_info->commands_event);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003949
3950 record_stream_free(p_rs);
3951
3952 /* start listening for new connections again */
3953 rilEventAddWakeup(&s_listen_event);
3954
Howard Sue32dbfd2015-01-07 15:55:57 +08003955 onCommandsSocketClosed(p_info->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003956 }
3957}
3958
Howard Subd82ef12015-04-12 10:25:05 +02003959
Howard Sue32dbfd2015-01-07 15:55:57 +08003960static void onNewCommandConnect(RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003961 // Inform we are connected and the ril version
3962 int rilVer = s_callbacks.version;
Howard Sue32dbfd2015-01-07 15:55:57 +08003963 RIL_UNSOL_RESPONSE(RIL_UNSOL_RIL_CONNECTED,
3964 &rilVer, sizeof(rilVer), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003965
3966 // implicit radio state changed
Howard Sue32dbfd2015-01-07 15:55:57 +08003967 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
3968 NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003969
3970 // Send last NITZ time data, in case it was missed
3971 if (s_lastNITZTimeData != NULL) {
Howard Sue32dbfd2015-01-07 15:55:57 +08003972 sendResponseRaw(s_lastNITZTimeData, s_lastNITZTimeDataSize, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003973
3974 free(s_lastNITZTimeData);
3975 s_lastNITZTimeData = NULL;
3976 }
3977
3978 // Get version string
3979 if (s_callbacks.getVersion != NULL) {
3980 const char *version;
3981 version = s_callbacks.getVersion();
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003982 RLOGI("RIL Daemon version: %s\n", version);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003983
3984 property_set(PROPERTY_RIL_IMPL, version);
3985 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003986 RLOGI("RIL Daemon version: unavailable\n");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003987 property_set(PROPERTY_RIL_IMPL, "unavailable");
3988 }
3989
3990}
3991
3992static void listenCallback (int fd, short flags, void *param) {
3993 int ret;
3994 int err;
3995 int is_phone_socket;
Howard Sue32dbfd2015-01-07 15:55:57 +08003996 int fdCommand = -1;
Dheeraj Shettycc231012014-07-02 21:27:57 +02003997 char* processName;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003998 RecordStream *p_rs;
Dheeraj Shettycc231012014-07-02 21:27:57 +02003999 MySocketListenParam* listenParam;
4000 RilSocket *sapSocket = NULL;
4001 socketClient *sClient = NULL;
4002
Howard Sue32dbfd2015-01-07 15:55:57 +08004003 SocketListenParam *p_info = (SocketListenParam *)param;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004004
Dheeraj Shettycc231012014-07-02 21:27:57 +02004005 if(RIL_SAP_SOCKET == p_info->type) {
4006 listenParam = (MySocketListenParam *)param;
4007 sapSocket = listenParam->socket;
4008 }
4009
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004010 struct sockaddr_un peeraddr;
4011 socklen_t socklen = sizeof (peeraddr);
4012
4013 struct ucred creds;
4014 socklen_t szCreds = sizeof(creds);
4015
4016 struct passwd *pwd = NULL;
4017
Dheeraj Shettycc231012014-07-02 21:27:57 +02004018 if(NULL == sapSocket) {
4019 assert (*p_info->fdCommand < 0);
4020 assert (fd == *p_info->fdListen);
4021 processName = PHONE_PROCESS;
4022 } else {
4023 assert (sapSocket->commandFd < 0);
4024 assert (fd == sapSocket->listenFd);
4025 processName = BLUETOOTH_PROCESS;
4026 }
4027
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004028
Howard Sue32dbfd2015-01-07 15:55:57 +08004029 fdCommand = accept(fd, (sockaddr *) &peeraddr, &socklen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004030
Howard Sue32dbfd2015-01-07 15:55:57 +08004031 if (fdCommand < 0 ) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004032 RLOGE("Error on accept() errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004033 /* start listening for new connections again */
Dheeraj Shettycc231012014-07-02 21:27:57 +02004034 if(NULL == sapSocket) {
4035 rilEventAddWakeup(p_info->listen_event);
4036 } else {
4037 rilEventAddWakeup(sapSocket->getListenEvent());
4038 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004039 return;
4040 }
4041
4042 /* check the credential of the other side and only accept socket from
4043 * phone process
4044 */
4045 errno = 0;
4046 is_phone_socket = 0;
4047
Howard Sue32dbfd2015-01-07 15:55:57 +08004048 err = getsockopt(fdCommand, SOL_SOCKET, SO_PEERCRED, &creds, &szCreds);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004049
4050 if (err == 0 && szCreds > 0) {
4051 errno = 0;
4052 pwd = getpwuid(creds.uid);
4053 if (pwd != NULL) {
Dheeraj Shettycc231012014-07-02 21:27:57 +02004054 if (strcmp(pwd->pw_name, processName) == 0) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004055 is_phone_socket = 1;
4056 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004057 RLOGE("RILD can't accept socket from process %s", pwd->pw_name);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004058 }
4059 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004060 RLOGE("Error on getpwuid() errno: %d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004061 }
4062 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004063 RLOGD("Error on getsockopt() errno: %d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004064 }
4065
Howard Subd82ef12015-04-12 10:25:05 +02004066 if (!is_phone_socket) {
Dheeraj Shettycc231012014-07-02 21:27:57 +02004067 RLOGE("RILD must accept socket from %s", processName);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004068
Dheeraj Shettycc231012014-07-02 21:27:57 +02004069 close(fdCommand);
4070 fdCommand = -1;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004071
Dheeraj Shettycc231012014-07-02 21:27:57 +02004072 if(NULL == sapSocket) {
4073 onCommandsSocketClosed(p_info->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004074
Dheeraj Shettycc231012014-07-02 21:27:57 +02004075 /* start listening for new connections again */
4076 rilEventAddWakeup(p_info->listen_event);
4077 } else {
4078 sapSocket->onCommandsSocketClosed();
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004079
Dheeraj Shettycc231012014-07-02 21:27:57 +02004080 /* start listening for new connections again */
4081 rilEventAddWakeup(sapSocket->getListenEvent());
4082 }
4083
4084 return;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004085 }
4086
Howard Sue32dbfd2015-01-07 15:55:57 +08004087 ret = fcntl(fdCommand, F_SETFL, O_NONBLOCK);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004088
4089 if (ret < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004090 RLOGE ("Error setting O_NONBLOCK errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004091 }
4092
Dheeraj Shettycc231012014-07-02 21:27:57 +02004093 if(NULL == sapSocket) {
4094 RLOGI("libril: new connection to %s", rilSocketIdToString(p_info->socket_id));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004095
Dheeraj Shettycc231012014-07-02 21:27:57 +02004096 p_info->fdCommand = fdCommand;
4097 p_rs = record_stream_new(p_info->fdCommand, MAX_COMMAND_BYTES);
4098 p_info->p_rs = p_rs;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004099
Dheeraj Shettycc231012014-07-02 21:27:57 +02004100 ril_event_set (p_info->commands_event, p_info->fdCommand, 1,
Howard Sue32dbfd2015-01-07 15:55:57 +08004101 p_info->processCommandsCallback, p_info);
Dheeraj Shettycc231012014-07-02 21:27:57 +02004102 rilEventAddWakeup (p_info->commands_event);
Howard Sue32dbfd2015-01-07 15:55:57 +08004103
Dheeraj Shettycc231012014-07-02 21:27:57 +02004104 onNewCommandConnect(p_info->socket_id);
4105 } else {
4106 RLOGI("libril: new connection");
Howard Sue32dbfd2015-01-07 15:55:57 +08004107
Dheeraj Shettycc231012014-07-02 21:27:57 +02004108 sapSocket->setCommandFd(fdCommand);
4109 p_rs = record_stream_new(sapSocket->getCommandFd(), MAX_COMMAND_BYTES);
4110 sClient = new socketClient(sapSocket,p_rs);
4111 ril_event_set (sapSocket->getCallbackEvent(), sapSocket->getCommandFd(), 1,
4112 sapSocket->getCommandCb(), sClient);
4113
4114 rilEventAddWakeup(sapSocket->getCallbackEvent());
4115 sapSocket->onNewCommandConnect();
4116 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004117}
4118
4119static void freeDebugCallbackArgs(int number, char **args) {
4120 for (int i = 0; i < number; i++) {
4121 if (args[i] != NULL) {
4122 free(args[i]);
4123 }
4124 }
4125 free(args);
4126}
4127
4128static void debugCallback (int fd, short flags, void *param) {
4129 int acceptFD, option;
4130 struct sockaddr_un peeraddr;
4131 socklen_t socklen = sizeof (peeraddr);
4132 int data;
4133 unsigned int qxdm_data[6];
4134 const char *deactData[1] = {"1"};
4135 char *actData[1];
4136 RIL_Dial dialData;
4137 int hangupData[1] = {1};
4138 int number;
4139 char **args;
Howard Sue32dbfd2015-01-07 15:55:57 +08004140 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
4141 int sim_id = 0;
4142
4143 RLOGI("debugCallback for socket %s", rilSocketIdToString(socket_id));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004144
4145 acceptFD = accept (fd, (sockaddr *) &peeraddr, &socklen);
4146
4147 if (acceptFD < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004148 RLOGE ("error accepting on debug port: %d\n", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004149 return;
4150 }
4151
4152 if (recv(acceptFD, &number, sizeof(int), 0) != sizeof(int)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004153 RLOGE ("error reading on socket: number of Args: \n");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004154 return;
4155 }
4156 args = (char **) malloc(sizeof(char*) * number);
4157
4158 for (int i = 0; i < number; i++) {
4159 int len;
4160 if (recv(acceptFD, &len, sizeof(int), 0) != sizeof(int)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004161 RLOGE ("error reading on socket: Len of Args: \n");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004162 freeDebugCallbackArgs(i, args);
4163 return;
4164 }
4165 // +1 for null-term
4166 args[i] = (char *) malloc((sizeof(char) * len) + 1);
4167 if (recv(acceptFD, args[i], sizeof(char) * len, 0)
4168 != (int)sizeof(char) * len) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004169 RLOGE ("error reading on socket: Args[%d] \n", i);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004170 freeDebugCallbackArgs(i, args);
4171 return;
4172 }
4173 char * buf = args[i];
4174 buf[len] = 0;
Howard Sue32dbfd2015-01-07 15:55:57 +08004175 if ((i+1) == number) {
4176 /* The last argument should be sim id 0(SIM1)~3(SIM4) */
4177 sim_id = atoi(args[i]);
4178 switch (sim_id) {
4179 case 0:
4180 socket_id = RIL_SOCKET_1;
4181 break;
4182 #if (SIM_COUNT >= 2)
4183 case 1:
4184 socket_id = RIL_SOCKET_2;
4185 break;
4186 #endif
4187 #if (SIM_COUNT >= 3)
4188 case 2:
4189 socket_id = RIL_SOCKET_3;
4190 break;
4191 #endif
4192 #if (SIM_COUNT >= 4)
4193 case 3:
4194 socket_id = RIL_SOCKET_4;
4195 break;
4196 #endif
4197 default:
4198 socket_id = RIL_SOCKET_1;
4199 break;
4200 }
4201 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004202 }
4203
4204 switch (atoi(args[0])) {
4205 case 0:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004206 RLOGI ("Connection on debug port: issuing reset.");
Howard Sue32dbfd2015-01-07 15:55:57 +08004207 issueLocalRequest(RIL_REQUEST_RESET_RADIO, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004208 break;
4209 case 1:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004210 RLOGI ("Connection on debug port: issuing radio power off.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004211 data = 0;
Howard Sue32dbfd2015-01-07 15:55:57 +08004212 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004213 // Close the socket
Howard Subd82ef12015-04-12 10:25:05 +02004214 if (socket_id == RIL_SOCKET_1 && s_ril_param_socket.fdCommand > 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08004215 close(s_ril_param_socket.fdCommand);
4216 s_ril_param_socket.fdCommand = -1;
4217 }
4218 #if (SIM_COUNT == 2)
4219 else if (socket_id == RIL_SOCKET_2 && s_ril_param_socket2.fdCommand > 0) {
4220 close(s_ril_param_socket2.fdCommand);
4221 s_ril_param_socket2.fdCommand = -1;
4222 }
4223 #endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004224 break;
4225 case 2:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004226 RLOGI ("Debug port: issuing unsolicited voice network change.");
Howard Sue32dbfd2015-01-07 15:55:57 +08004227 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004228 break;
4229 case 3:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004230 RLOGI ("Debug port: QXDM log enable.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004231 qxdm_data[0] = 65536; // head.func_tag
4232 qxdm_data[1] = 16; // head.len
4233 qxdm_data[2] = 1; // mode: 1 for 'start logging'
4234 qxdm_data[3] = 32; // log_file_size: 32megabytes
4235 qxdm_data[4] = 0; // log_mask
4236 qxdm_data[5] = 8; // log_max_fileindex
4237 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Howard Sue32dbfd2015-01-07 15:55:57 +08004238 6 * sizeof(int), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004239 break;
4240 case 4:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004241 RLOGI ("Debug port: QXDM log disable.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004242 qxdm_data[0] = 65536;
4243 qxdm_data[1] = 16;
4244 qxdm_data[2] = 0; // mode: 0 for 'stop logging'
4245 qxdm_data[3] = 32;
4246 qxdm_data[4] = 0;
4247 qxdm_data[5] = 8;
4248 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Howard Sue32dbfd2015-01-07 15:55:57 +08004249 6 * sizeof(int), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004250 break;
4251 case 5:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004252 RLOGI("Debug port: Radio On");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004253 data = 1;
Howard Sue32dbfd2015-01-07 15:55:57 +08004254 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004255 sleep(2);
4256 // Set network selection automatic.
Howard Sue32dbfd2015-01-07 15:55:57 +08004257 issueLocalRequest(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004258 break;
4259 case 6:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004260 RLOGI("Debug port: Setup Data Call, Apn :%s\n", args[1]);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004261 actData[0] = args[1];
4262 issueLocalRequest(RIL_REQUEST_SETUP_DATA_CALL, &actData,
Howard Sue32dbfd2015-01-07 15:55:57 +08004263 sizeof(actData), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004264 break;
4265 case 7:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004266 RLOGI("Debug port: Deactivate Data Call");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004267 issueLocalRequest(RIL_REQUEST_DEACTIVATE_DATA_CALL, &deactData,
Howard Sue32dbfd2015-01-07 15:55:57 +08004268 sizeof(deactData), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004269 break;
4270 case 8:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004271 RLOGI("Debug port: Dial Call");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004272 dialData.clir = 0;
4273 dialData.address = args[1];
Howard Sue32dbfd2015-01-07 15:55:57 +08004274 issueLocalRequest(RIL_REQUEST_DIAL, &dialData, sizeof(dialData), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004275 break;
4276 case 9:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004277 RLOGI("Debug port: Answer Call");
Howard Sue32dbfd2015-01-07 15:55:57 +08004278 issueLocalRequest(RIL_REQUEST_ANSWER, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004279 break;
4280 case 10:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004281 RLOGI("Debug port: End Call");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004282 issueLocalRequest(RIL_REQUEST_HANGUP, &hangupData,
Howard Sue32dbfd2015-01-07 15:55:57 +08004283 sizeof(hangupData), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004284 break;
4285 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004286 RLOGE ("Invalid request");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004287 break;
4288 }
4289 freeDebugCallbackArgs(number, args);
4290 close(acceptFD);
4291}
4292
4293
4294static void userTimerCallback (int fd, short flags, void *param) {
4295 UserCallbackInfo *p_info;
4296
4297 p_info = (UserCallbackInfo *)param;
4298
4299 p_info->p_callback(p_info->userParam);
4300
4301
4302 // FIXME generalize this...there should be a cancel mechanism
4303 if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) {
4304 s_last_wake_timeout_info = NULL;
4305 }
4306
4307 free(p_info);
4308}
4309
4310
4311static void *
4312eventLoop(void *param) {
4313 int ret;
4314 int filedes[2];
4315
4316 ril_event_init();
4317
4318 pthread_mutex_lock(&s_startupMutex);
4319
4320 s_started = 1;
4321 pthread_cond_broadcast(&s_startupCond);
4322
4323 pthread_mutex_unlock(&s_startupMutex);
4324
4325 ret = pipe(filedes);
4326
4327 if (ret < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004328 RLOGE("Error in pipe() errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004329 return NULL;
4330 }
4331
4332 s_fdWakeupRead = filedes[0];
4333 s_fdWakeupWrite = filedes[1];
4334
4335 fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK);
4336
4337 ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,
4338 processWakeupCallback, NULL);
4339
4340 rilEventAddWakeup (&s_wakeupfd_event);
4341
4342 // Only returns on error
4343 ril_event_loop();
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004344 RLOGE ("error in event_loop_base errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004345 // kill self to restart on error
4346 kill(0, SIGKILL);
4347
4348 return NULL;
4349}
4350
4351extern "C" void
4352RIL_startEventLoop(void) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004353 /* spin up eventLoop thread and wait for it to get started */
4354 s_started = 0;
4355 pthread_mutex_lock(&s_startupMutex);
4356
Howard Sue32dbfd2015-01-07 15:55:57 +08004357 pthread_attr_t attr;
4358 pthread_attr_init(&attr);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004359 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
Howard Sue32dbfd2015-01-07 15:55:57 +08004360
4361 int result = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
4362 if (result != 0) {
4363 RLOGE("Failed to create dispatch thread: %s", strerror(result));
4364 goto done;
4365 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004366
4367 while (s_started == 0) {
4368 pthread_cond_wait(&s_startupCond, &s_startupMutex);
4369 }
4370
Howard Sue32dbfd2015-01-07 15:55:57 +08004371done:
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004372 pthread_mutex_unlock(&s_startupMutex);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004373}
4374
4375// Used for testing purpose only.
4376extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) {
4377 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4378}
4379
Howard Sue32dbfd2015-01-07 15:55:57 +08004380static void startListen(RIL_SOCKET_ID socket_id, SocketListenParam* socket_listen_p) {
4381 int fdListen = -1;
4382 int ret;
4383 char socket_name[10];
4384
4385 memset(socket_name, 0, sizeof(char)*10);
4386
4387 switch(socket_id) {
4388 case RIL_SOCKET_1:
4389 strncpy(socket_name, RIL_getRilSocketName(), 9);
4390 break;
4391 #if (SIM_COUNT >= 2)
4392 case RIL_SOCKET_2:
4393 strncpy(socket_name, SOCKET2_NAME_RIL, 9);
4394 break;
4395 #endif
4396 #if (SIM_COUNT >= 3)
4397 case RIL_SOCKET_3:
4398 strncpy(socket_name, SOCKET3_NAME_RIL, 9);
4399 break;
4400 #endif
4401 #if (SIM_COUNT >= 4)
4402 case RIL_SOCKET_4:
4403 strncpy(socket_name, SOCKET4_NAME_RIL, 9);
4404 break;
4405 #endif
4406 default:
4407 RLOGE("Socket id is wrong!!");
4408 return;
4409 }
4410
4411 RLOGI("Start to listen %s", rilSocketIdToString(socket_id));
4412
4413 fdListen = android_get_control_socket(socket_name);
4414 if (fdListen < 0) {
4415 RLOGE("Failed to get socket %s", socket_name);
4416 exit(-1);
4417 }
4418
4419 ret = listen(fdListen, 4);
4420
4421 if (ret < 0) {
4422 RLOGE("Failed to listen on control socket '%d': %s",
4423 fdListen, strerror(errno));
4424 exit(-1);
4425 }
4426 socket_listen_p->fdListen = fdListen;
4427
4428 /* note: non-persistent so we can accept only one connection at a time */
4429 ril_event_set (socket_listen_p->listen_event, fdListen, false,
4430 listenCallback, socket_listen_p);
4431
4432 rilEventAddWakeup (socket_listen_p->listen_event);
4433}
4434
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004435extern "C" void
4436RIL_register (const RIL_RadioFunctions *callbacks) {
4437 int ret;
4438 int flags;
4439
Howard Sue32dbfd2015-01-07 15:55:57 +08004440 RLOGI("SIM_COUNT: %d", SIM_COUNT);
4441
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004442 if (callbacks == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004443 RLOGE("RIL_register: RIL_RadioFunctions * null");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004444 return;
4445 }
4446 if (callbacks->version < RIL_VERSION_MIN) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004447 RLOGE("RIL_register: version %d is to old, min version is %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004448 callbacks->version, RIL_VERSION_MIN);
4449 return;
4450 }
4451 if (callbacks->version > RIL_VERSION) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004452 RLOGE("RIL_register: version %d is too new, max version is %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004453 callbacks->version, RIL_VERSION);
4454 return;
4455 }
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004456 RLOGE("RIL_register: RIL version %d", callbacks->version);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004457
4458 if (s_registerCalled > 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004459 RLOGE("RIL_register has been called more than once. "
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004460 "Subsequent call ignored");
4461 return;
4462 }
4463
4464 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4465
Howard Sue32dbfd2015-01-07 15:55:57 +08004466 /* Initialize socket1 parameters */
4467 s_ril_param_socket = {
4468 RIL_SOCKET_1, /* socket_id */
4469 -1, /* fdListen */
4470 -1, /* fdCommand */
4471 PHONE_PROCESS, /* processName */
4472 &s_commands_event, /* commands_event */
4473 &s_listen_event, /* listen_event */
4474 processCommandsCallback, /* processCommandsCallback */
4475 NULL /* p_rs */
4476 };
4477
4478#if (SIM_COUNT >= 2)
4479 s_ril_param_socket2 = {
4480 RIL_SOCKET_2, /* socket_id */
4481 -1, /* fdListen */
4482 -1, /* fdCommand */
4483 PHONE_PROCESS, /* processName */
4484 &s_commands_event_socket2, /* commands_event */
4485 &s_listen_event_socket2, /* listen_event */
4486 processCommandsCallback, /* processCommandsCallback */
4487 NULL /* p_rs */
4488 };
4489#endif
4490
4491#if (SIM_COUNT >= 3)
4492 s_ril_param_socket3 = {
4493 RIL_SOCKET_3, /* socket_id */
4494 -1, /* fdListen */
4495 -1, /* fdCommand */
4496 PHONE_PROCESS, /* processName */
4497 &s_commands_event_socket3, /* commands_event */
4498 &s_listen_event_socket3, /* listen_event */
4499 processCommandsCallback, /* processCommandsCallback */
4500 NULL /* p_rs */
4501 };
4502#endif
4503
4504#if (SIM_COUNT >= 4)
4505 s_ril_param_socket4 = {
4506 RIL_SOCKET_4, /* socket_id */
4507 -1, /* fdListen */
4508 -1, /* fdCommand */
4509 PHONE_PROCESS, /* processName */
4510 &s_commands_event_socket4, /* commands_event */
4511 &s_listen_event_socket4, /* listen_event */
4512 processCommandsCallback, /* processCommandsCallback */
4513 NULL /* p_rs */
4514 };
4515#endif
4516
Howard Subd82ef12015-04-12 10:25:05 +02004517
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004518 s_registerCalled = 1;
4519
Howard Sue32dbfd2015-01-07 15:55:57 +08004520 RLOGI("s_registerCalled flag set, %d", s_started);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004521 // Little self-check
4522
4523 for (int i = 0; i < (int)NUM_ELEMS(s_commands); i++) {
4524 assert(i == s_commands[i].requestNumber);
4525 }
4526
Howard Subd82ef12015-04-12 10:25:05 +02004527 for (int i = 0; i < (int)NUM_ELEMS(s_commands_v); i++) {
4528 assert(i + RIL_VENDOR_COMMANDS_OFFSET == s_commands[i].requestNumber);
4529 }
4530
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004531 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses); i++) {
Howard Sue32dbfd2015-01-07 15:55:57 +08004532 assert(i + RIL_UNSOL_RESPONSE_BASE
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004533 == s_unsolResponses[i].requestNumber);
4534 }
4535
Howard Subd82ef12015-04-12 10:25:05 +02004536 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses_v); i++) {
4537 assert(i + RIL_UNSOL_RESPONSE_BASE + RIL_VENDOR_COMMANDS_OFFSET
4538 == s_unsolResponses[i].requestNumber);
4539 }
4540
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004541 // New rild impl calls RIL_startEventLoop() first
4542 // old standalone impl wants it here.
4543
4544 if (s_started == 0) {
4545 RIL_startEventLoop();
4546 }
4547
Howard Sue32dbfd2015-01-07 15:55:57 +08004548 // start listen socket1
4549 startListen(RIL_SOCKET_1, &s_ril_param_socket);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004550
Howard Sue32dbfd2015-01-07 15:55:57 +08004551#if (SIM_COUNT >= 2)
4552 // start listen socket2
4553 startListen(RIL_SOCKET_2, &s_ril_param_socket2);
4554#endif /* (SIM_COUNT == 2) */
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004555
Howard Sue32dbfd2015-01-07 15:55:57 +08004556#if (SIM_COUNT >= 3)
4557 // start listen socket3
4558 startListen(RIL_SOCKET_3, &s_ril_param_socket3);
4559#endif /* (SIM_COUNT == 3) */
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004560
Howard Sue32dbfd2015-01-07 15:55:57 +08004561#if (SIM_COUNT >= 4)
4562 // start listen socket4
4563 startListen(RIL_SOCKET_4, &s_ril_param_socket4);
4564#endif /* (SIM_COUNT == 4) */
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004565
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004566
4567#if 1
4568 // start debug interface socket
4569
Howard Sue32dbfd2015-01-07 15:55:57 +08004570 char *inst = NULL;
4571 if (strlen(RIL_getRilSocketName()) >= strlen(SOCKET_NAME_RIL)) {
4572 inst = RIL_getRilSocketName() + strlen(SOCKET_NAME_RIL);
4573 }
4574
4575 char rildebug[MAX_DEBUG_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL_DEBUG;
4576 if (inst != NULL) {
Andreas Schneider3063dc12015-04-13 23:04:05 +02004577 snprintf(rildebug, sizeof(rildebug), "%s%s", SOCKET_NAME_RIL_DEBUG, inst);
Howard Sue32dbfd2015-01-07 15:55:57 +08004578 }
4579
4580 s_fdDebug = android_get_control_socket(rildebug);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004581 if (s_fdDebug < 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08004582 RLOGE("Failed to get socket : %s errno:%d", rildebug, errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004583 exit(-1);
4584 }
4585
4586 ret = listen(s_fdDebug, 4);
4587
4588 if (ret < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004589 RLOGE("Failed to listen on ril debug socket '%d': %s",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004590 s_fdDebug, strerror(errno));
4591 exit(-1);
4592 }
4593
4594 ril_event_set (&s_debug_event, s_fdDebug, true,
4595 debugCallback, NULL);
4596
4597 rilEventAddWakeup (&s_debug_event);
4598#endif
4599
4600}
4601
Dheeraj Shettycc231012014-07-02 21:27:57 +02004602extern "C" void
4603RIL_register_socket (RIL_RadioFunctions *(*Init)(const struct RIL_Env *, int, char **),RIL_SOCKET_TYPE socketType, int argc, char **argv) {
4604
4605 RIL_RadioFunctions* UimFuncs = NULL;
4606
4607 if(Init) {
4608 UimFuncs = Init(&RilSapSocket::uimRilEnv, argc, argv);
4609
4610 switch(socketType) {
4611 case RIL_SAP_SOCKET:
4612 RilSapSocket::initSapSocket("sap_uim_socket1", UimFuncs);
4613
4614#if (SIM_COUNT >= 2)
4615 RilSapSocket::initSapSocket("sap_uim_socket2", UimFuncs);
4616#endif
4617
4618#if (SIM_COUNT >= 3)
4619 RilSapSocket::initSapSocket("sap_uim_socket3", UimFuncs);
4620#endif
4621
4622#if (SIM_COUNT >= 4)
4623 RilSapSocket::initSapSocket("sap_uim_socket4", UimFuncs);
4624#endif
4625 }
4626 }
4627}
4628
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004629static int
4630checkAndDequeueRequestInfo(struct RequestInfo *pRI) {
4631 int ret = 0;
Howard Sue32dbfd2015-01-07 15:55:57 +08004632 /* Hook for current context
4633 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
4634 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
4635 /* pendingRequestsHook refer to &s_pendingRequests */
4636 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004637
4638 if (pRI == NULL) {
4639 return 0;
4640 }
4641
Howard Sue32dbfd2015-01-07 15:55:57 +08004642#if (SIM_COUNT >= 2)
4643 if (pRI->socket_id == RIL_SOCKET_2) {
4644 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
4645 pendingRequestsHook = &s_pendingRequests_socket2;
4646 }
4647#if (SIM_COUNT >= 3)
4648 if (pRI->socket_id == RIL_SOCKET_3) {
4649 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
4650 pendingRequestsHook = &s_pendingRequests_socket3;
4651 }
4652#endif
4653#if (SIM_COUNT >= 4)
4654 if (pRI->socket_id == RIL_SOCKET_4) {
4655 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
4656 pendingRequestsHook = &s_pendingRequests_socket4;
4657 }
4658#endif
4659#endif
4660 pthread_mutex_lock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004661
Howard Sue32dbfd2015-01-07 15:55:57 +08004662 for(RequestInfo **ppCur = pendingRequestsHook
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004663 ; *ppCur != NULL
4664 ; ppCur = &((*ppCur)->p_next)
4665 ) {
4666 if (pRI == *ppCur) {
4667 ret = 1;
4668
4669 *ppCur = (*ppCur)->p_next;
4670 break;
4671 }
4672 }
4673
Howard Sue32dbfd2015-01-07 15:55:57 +08004674 pthread_mutex_unlock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004675
4676 return ret;
4677}
4678
4679
4680extern "C" void
4681RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) {
4682 RequestInfo *pRI;
4683 int ret;
Howard Sue32dbfd2015-01-07 15:55:57 +08004684 int fd = s_ril_param_socket.fdCommand;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004685 size_t errorOffset;
Howard Sue32dbfd2015-01-07 15:55:57 +08004686 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004687
4688 pRI = (RequestInfo *)t;
4689
4690 if (!checkAndDequeueRequestInfo(pRI)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004691 RLOGE ("RIL_onRequestComplete: invalid RIL_Token");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004692 return;
4693 }
4694
Howard Sue32dbfd2015-01-07 15:55:57 +08004695 socket_id = pRI->socket_id;
4696#if (SIM_COUNT >= 2)
4697 if (socket_id == RIL_SOCKET_2) {
4698 fd = s_ril_param_socket2.fdCommand;
4699 }
4700#if (SIM_COUNT >= 3)
4701 if (socket_id == RIL_SOCKET_3) {
4702 fd = s_ril_param_socket3.fdCommand;
4703 }
4704#endif
4705#if (SIM_COUNT >= 4)
4706 if (socket_id == RIL_SOCKET_4) {
4707 fd = s_ril_param_socket4.fdCommand;
4708 }
4709#endif
4710#endif
Robert Greenwaltbc29c432015-04-29 16:57:39 -07004711#if VDBG
Howard Sue32dbfd2015-01-07 15:55:57 +08004712 RLOGD("RequestComplete, %s", rilSocketIdToString(socket_id));
Robert Greenwaltbc29c432015-04-29 16:57:39 -07004713#endif
Howard Sue32dbfd2015-01-07 15:55:57 +08004714
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004715 if (pRI->local > 0) {
4716 // Locally issued command...void only!
4717 // response does not go back up the command socket
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004718 RLOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004719
4720 goto done;
4721 }
4722
4723 appendPrintBuf("[%04d]< %s",
4724 pRI->token, requestToString(pRI->pCI->requestNumber));
4725
4726 if (pRI->cancelled == 0) {
4727 Parcel p;
4728
4729 p.writeInt32 (RESPONSE_SOLICITED);
4730 p.writeInt32 (pRI->token);
4731 errorOffset = p.dataPosition();
4732
4733 p.writeInt32 (e);
4734
4735 if (response != NULL) {
4736 // there is a response payload, no matter success or not.
4737 ret = pRI->pCI->responseFunction(p, response, responselen);
4738
4739 /* if an error occurred, rewind and mark it */
4740 if (ret != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08004741 RLOGE ("responseFunction error, ret %d", ret);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004742 p.setDataPosition(errorOffset);
4743 p.writeInt32 (ret);
4744 }
4745 }
4746
4747 if (e != RIL_E_SUCCESS) {
4748 appendPrintBuf("%s fails by %s", printBuf, failCauseToString(e));
4749 }
4750
Howard Sue32dbfd2015-01-07 15:55:57 +08004751 if (fd < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004752 RLOGD ("RIL onRequestComplete: Command channel closed");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004753 }
Howard Sue32dbfd2015-01-07 15:55:57 +08004754 sendResponse(p, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004755 }
4756
4757done:
4758 free(pRI);
4759}
4760
Howard Subd82ef12015-04-12 10:25:05 +02004761
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004762static void
4763grabPartialWakeLock() {
4764 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
4765}
4766
4767static void
4768releaseWakeLock() {
4769 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
4770}
4771
4772/**
4773 * Timer callback to put us back to sleep before the default timeout
4774 */
4775static void
4776wakeTimeoutCallback (void *param) {
4777 // We're using "param != NULL" as a cancellation mechanism
4778 if (param == NULL) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004779 releaseWakeLock();
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004780 }
4781}
4782
4783static int
4784decodeVoiceRadioTechnology (RIL_RadioState radioState) {
4785 switch (radioState) {
4786 case RADIO_STATE_SIM_NOT_READY:
4787 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4788 case RADIO_STATE_SIM_READY:
4789 return RADIO_TECH_UMTS;
4790
4791 case RADIO_STATE_RUIM_NOT_READY:
4792 case RADIO_STATE_RUIM_READY:
4793 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4794 case RADIO_STATE_NV_NOT_READY:
4795 case RADIO_STATE_NV_READY:
4796 return RADIO_TECH_1xRTT;
4797
4798 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004799 RLOGD("decodeVoiceRadioTechnology: Invoked with incorrect RadioState");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004800 return -1;
4801 }
4802}
4803
4804static int
4805decodeCdmaSubscriptionSource (RIL_RadioState radioState) {
4806 switch (radioState) {
4807 case RADIO_STATE_SIM_NOT_READY:
4808 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4809 case RADIO_STATE_SIM_READY:
4810 case RADIO_STATE_RUIM_NOT_READY:
4811 case RADIO_STATE_RUIM_READY:
4812 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4813 return CDMA_SUBSCRIPTION_SOURCE_RUIM_SIM;
4814
4815 case RADIO_STATE_NV_NOT_READY:
4816 case RADIO_STATE_NV_READY:
4817 return CDMA_SUBSCRIPTION_SOURCE_NV;
4818
4819 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004820 RLOGD("decodeCdmaSubscriptionSource: Invoked with incorrect RadioState");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004821 return -1;
4822 }
4823}
4824
4825static int
4826decodeSimStatus (RIL_RadioState radioState) {
4827 switch (radioState) {
4828 case RADIO_STATE_SIM_NOT_READY:
4829 case RADIO_STATE_RUIM_NOT_READY:
4830 case RADIO_STATE_NV_NOT_READY:
4831 case RADIO_STATE_NV_READY:
4832 return -1;
4833 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4834 case RADIO_STATE_SIM_READY:
4835 case RADIO_STATE_RUIM_READY:
4836 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4837 return radioState;
4838 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004839 RLOGD("decodeSimStatus: Invoked with incorrect RadioState");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004840 return -1;
4841 }
4842}
4843
4844static bool is3gpp2(int radioTech) {
4845 switch (radioTech) {
4846 case RADIO_TECH_IS95A:
4847 case RADIO_TECH_IS95B:
4848 case RADIO_TECH_1xRTT:
4849 case RADIO_TECH_EVDO_0:
4850 case RADIO_TECH_EVDO_A:
4851 case RADIO_TECH_EVDO_B:
4852 case RADIO_TECH_EHRPD:
4853 return true;
4854 default:
4855 return false;
4856 }
4857}
4858
4859/* If RIL sends SIM states or RUIM states, store the voice radio
4860 * technology and subscription source information so that they can be
4861 * returned when telephony framework requests them
4862 */
4863static RIL_RadioState
Howard Subd82ef12015-04-12 10:25:05 +02004864processRadioState(RIL_RadioState newRadioState, RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004865
4866 if((newRadioState > RADIO_STATE_UNAVAILABLE) && (newRadioState < RADIO_STATE_ON)) {
4867 int newVoiceRadioTech;
4868 int newCdmaSubscriptionSource;
4869 int newSimStatus;
4870
4871 /* This is old RIL. Decode Subscription source and Voice Radio Technology
4872 from Radio State and send change notifications if there has been a change */
4873 newVoiceRadioTech = decodeVoiceRadioTechnology(newRadioState);
4874 if(newVoiceRadioTech != voiceRadioTech) {
4875 voiceRadioTech = newVoiceRadioTech;
Howard Sue32dbfd2015-01-07 15:55:57 +08004876 RIL_UNSOL_RESPONSE(RIL_UNSOL_VOICE_RADIO_TECH_CHANGED,
4877 &voiceRadioTech, sizeof(voiceRadioTech), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004878 }
4879 if(is3gpp2(newVoiceRadioTech)) {
4880 newCdmaSubscriptionSource = decodeCdmaSubscriptionSource(newRadioState);
4881 if(newCdmaSubscriptionSource != cdmaSubscriptionSource) {
4882 cdmaSubscriptionSource = newCdmaSubscriptionSource;
Howard Sue32dbfd2015-01-07 15:55:57 +08004883 RIL_UNSOL_RESPONSE(RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED,
4884 &cdmaSubscriptionSource, sizeof(cdmaSubscriptionSource), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004885 }
4886 }
4887 newSimStatus = decodeSimStatus(newRadioState);
4888 if(newSimStatus != simRuimStatus) {
4889 simRuimStatus = newSimStatus;
Howard Sue32dbfd2015-01-07 15:55:57 +08004890 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004891 }
4892
4893 /* Send RADIO_ON to telephony */
4894 newRadioState = RADIO_STATE_ON;
4895 }
4896
4897 return newRadioState;
4898}
4899
Howard Subd82ef12015-04-12 10:25:05 +02004900
Howard Sue32dbfd2015-01-07 15:55:57 +08004901#if defined(ANDROID_MULTI_SIM)
4902extern "C"
Andreas Schneider47b2d962015-04-13 22:54:49 +02004903void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Howard Sue32dbfd2015-01-07 15:55:57 +08004904 size_t datalen, RIL_SOCKET_ID socket_id)
4905#else
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004906extern "C"
Andreas Schneider47b2d962015-04-13 22:54:49 +02004907void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004908 size_t datalen)
Howard Sue32dbfd2015-01-07 15:55:57 +08004909#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004910{
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004911 int ret;
4912 int64_t timeReceived = 0;
4913 bool shouldScheduleTimeout = false;
4914 RIL_RadioState newState;
Howard Sue32dbfd2015-01-07 15:55:57 +08004915 RIL_SOCKET_ID soc_id = RIL_SOCKET_1;
Howard Subd82ef12015-04-12 10:25:05 +02004916 UnsolResponseInfo *pRI = NULL;
Howard Sue32dbfd2015-01-07 15:55:57 +08004917
4918#if defined(ANDROID_MULTI_SIM)
4919 soc_id = socket_id;
4920#endif
4921
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004922
4923 if (s_registerCalled == 0) {
4924 // Ignore RIL_onUnsolicitedResponse before RIL_register
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004925 RLOGW("RIL_onUnsolicitedResponse called before RIL_register");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004926 return;
4927 }
Howard Sue32dbfd2015-01-07 15:55:57 +08004928
Howard Subd82ef12015-04-12 10:25:05 +02004929 /* Hack to include Samsung responses */
4930 if (unsolResponse > RIL_VENDOR_COMMANDS_OFFSET + RIL_UNSOL_RESPONSE_BASE) {
4931 int index = unsolResponse - RIL_VENDOR_COMMANDS_OFFSET - RIL_UNSOL_RESPONSE_BASE;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004932
Howard Subd82ef12015-04-12 10:25:05 +02004933 RLOGD("SAMSUNG: unsolResponse=%d, unsolResponseIndex=%d", unsolResponse, index);
4934
4935 if (index < (int32_t)NUM_ELEMS(s_unsolResponses_v))
4936 pRI = &s_unsolResponses_v[index];
4937 } else {
4938 int index = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
4939 if (index < (int32_t)NUM_ELEMS(s_unsolResponses))
4940 pRI = &s_unsolResponses[index];
4941 }
4942
4943 if (pRI == NULL || pRI->responseFunction == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004944 RLOGE("unsupported unsolicited response code %d", unsolResponse);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004945 return;
4946 }
4947
4948 // Grab a wake lock if needed for this reponse,
4949 // as we exit we'll either release it immediately
4950 // or set a timer to release it later.
Howard Subd82ef12015-04-12 10:25:05 +02004951 switch (pRI->wakeType) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004952 case WAKE_PARTIAL:
4953 grabPartialWakeLock();
4954 shouldScheduleTimeout = true;
4955 break;
4956
4957 case DONT_WAKE:
4958 default:
4959 // No wake lock is grabed so don't set timeout
4960 shouldScheduleTimeout = false;
4961 break;
4962 }
4963
4964 // Mark the time this was received, doing this
4965 // after grabing the wakelock incase getting
4966 // the elapsedRealTime might cause us to goto
4967 // sleep.
4968 if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4969 timeReceived = elapsedRealtime();
4970 }
4971
4972 appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
4973
4974 Parcel p;
4975
4976 p.writeInt32 (RESPONSE_UNSOLICITED);
4977 p.writeInt32 (unsolResponse);
4978
Howard Subd82ef12015-04-12 10:25:05 +02004979 ret = pRI->responseFunction(p, const_cast<void*>(data), datalen);
4980
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004981 if (ret != 0) {
4982 // Problem with the response. Don't continue;
4983 goto error_exit;
4984 }
4985
4986 // some things get more payload
4987 switch(unsolResponse) {
4988 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
Howard Sue32dbfd2015-01-07 15:55:57 +08004989 newState = processRadioState(CALL_ONSTATEREQUEST(soc_id), soc_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004990 p.writeInt32(newState);
4991 appendPrintBuf("%s {%s}", printBuf,
Howard Sue32dbfd2015-01-07 15:55:57 +08004992 radioStateToString(CALL_ONSTATEREQUEST(soc_id)));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004993 break;
4994
4995
4996 case RIL_UNSOL_NITZ_TIME_RECEIVED:
4997 // Store the time that this was received so the
4998 // handler of this message can account for
4999 // the time it takes to arrive and process. In
5000 // particular the system has been known to sleep
5001 // before this message can be processed.
5002 p.writeInt64(timeReceived);
5003 break;
5004 }
5005
Robert Greenwaltbc29c432015-04-29 16:57:39 -07005006#if VDBG
Howard Sue32dbfd2015-01-07 15:55:57 +08005007 RLOGI("%s UNSOLICITED: %s length:%d", rilSocketIdToString(soc_id), requestToString(unsolResponse), p.dataSize());
Robert Greenwaltbc29c432015-04-29 16:57:39 -07005008#endif
Howard Sue32dbfd2015-01-07 15:55:57 +08005009 ret = sendResponse(p, soc_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005010 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
5011
5012 // Unfortunately, NITZ time is not poll/update like everything
5013 // else in the system. So, if the upstream client isn't connected,
5014 // keep a copy of the last NITZ response (with receive time noted
5015 // above) around so we can deliver it when it is connected
5016
5017 if (s_lastNITZTimeData != NULL) {
5018 free (s_lastNITZTimeData);
5019 s_lastNITZTimeData = NULL;
5020 }
5021
5022 s_lastNITZTimeData = malloc(p.dataSize());
5023 s_lastNITZTimeDataSize = p.dataSize();
5024 memcpy(s_lastNITZTimeData, p.data(), p.dataSize());
5025 }
5026
5027 // For now, we automatically go back to sleep after TIMEVAL_WAKE_TIMEOUT
5028 // FIXME The java code should handshake here to release wake lock
5029
5030 if (shouldScheduleTimeout) {
5031 // Cancel the previous request
5032 if (s_last_wake_timeout_info != NULL) {
5033 s_last_wake_timeout_info->userParam = (void *)1;
5034 }
5035
5036 s_last_wake_timeout_info
5037 = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
5038 &TIMEVAL_WAKE_TIMEOUT);
5039 }
5040
5041 // Normal exit
5042 return;
5043
5044error_exit:
5045 if (shouldScheduleTimeout) {
5046 releaseWakeLock();
5047 }
5048}
5049
5050/** FIXME generalize this if you track UserCAllbackInfo, clear it
5051 when the callback occurs
5052*/
5053static UserCallbackInfo *
5054internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
5055 const struct timeval *relativeTime)
5056{
5057 struct timeval myRelativeTime;
5058 UserCallbackInfo *p_info;
5059
5060 p_info = (UserCallbackInfo *) malloc (sizeof(UserCallbackInfo));
5061
5062 p_info->p_callback = callback;
5063 p_info->userParam = param;
5064
5065 if (relativeTime == NULL) {
5066 /* treat null parameter as a 0 relative time */
5067 memset (&myRelativeTime, 0, sizeof(myRelativeTime));
5068 } else {
5069 /* FIXME I think event_add's tv param is really const anyway */
5070 memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
5071 }
5072
5073 ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
5074
5075 ril_timer_add(&(p_info->event), &myRelativeTime);
5076
5077 triggerEvLoop();
5078 return p_info;
5079}
5080
5081
5082extern "C" void
5083RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
5084 const struct timeval *relativeTime) {
5085 internalRequestTimedCallback (callback, param, relativeTime);
5086}
5087
5088const char *
5089failCauseToString(RIL_Errno e) {
5090 switch(e) {
5091 case RIL_E_SUCCESS: return "E_SUCCESS";
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005092 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RADIO_NOT_AVAILABLE";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005093 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
5094 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
5095 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
5096 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
5097 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
5098 case RIL_E_CANCELLED: return "E_CANCELLED";
5099 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
5100 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
5101 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
5102 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
5103 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
5104#ifdef FEATURE_MULTIMODE_ANDROID
5105 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
5106 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
5107#endif
5108 default: return "<unknown error>";
5109 }
5110}
5111
5112const char *
5113radioStateToString(RIL_RadioState s) {
5114 switch(s) {
5115 case RADIO_STATE_OFF: return "RADIO_OFF";
5116 case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
5117 case RADIO_STATE_SIM_NOT_READY: return "RADIO_SIM_NOT_READY";
5118 case RADIO_STATE_SIM_LOCKED_OR_ABSENT: return "RADIO_SIM_LOCKED_OR_ABSENT";
5119 case RADIO_STATE_SIM_READY: return "RADIO_SIM_READY";
5120 case RADIO_STATE_RUIM_NOT_READY:return"RADIO_RUIM_NOT_READY";
5121 case RADIO_STATE_RUIM_READY:return"RADIO_RUIM_READY";
5122 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:return"RADIO_RUIM_LOCKED_OR_ABSENT";
5123 case RADIO_STATE_NV_NOT_READY:return"RADIO_NV_NOT_READY";
5124 case RADIO_STATE_NV_READY:return"RADIO_NV_READY";
5125 case RADIO_STATE_ON:return"RADIO_ON";
5126 default: return "<unknown state>";
5127 }
5128}
5129
5130const char *
5131callStateToString(RIL_CallState s) {
5132 switch(s) {
5133 case RIL_CALL_ACTIVE : return "ACTIVE";
5134 case RIL_CALL_HOLDING: return "HOLDING";
5135 case RIL_CALL_DIALING: return "DIALING";
5136 case RIL_CALL_ALERTING: return "ALERTING";
5137 case RIL_CALL_INCOMING: return "INCOMING";
5138 case RIL_CALL_WAITING: return "WAITING";
5139 default: return "<unknown state>";
5140 }
5141}
5142
5143const char *
5144requestToString(int request) {
5145/*
5146 cat libs/telephony/ril_commands.h \
5147 | egrep "^ *{RIL_" \
5148 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
5149
5150
5151 cat libs/telephony/ril_unsol_commands.h \
5152 | egrep "^ *{RIL_" \
5153 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
5154
5155*/
5156 switch(request) {
5157 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
5158 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
5159 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
5160 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
5161 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
5162 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
5163 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
5164 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
5165 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
5166 case RIL_REQUEST_DIAL: return "DIAL";
5167 case RIL_REQUEST_DIAL_EMERGENCY: return "DIAL";
5168 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
5169 case RIL_REQUEST_HANGUP: return "HANGUP";
5170 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
5171 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
5172 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
5173 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
5174 case RIL_REQUEST_UDUB: return "UDUB";
5175 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
5176 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
5177 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
5178 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
5179 case RIL_REQUEST_OPERATOR: return "OPERATOR";
5180 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
5181 case RIL_REQUEST_DTMF: return "DTMF";
5182 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
5183 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
5184 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
5185 case RIL_REQUEST_SIM_IO: return "SIM_IO";
5186 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
5187 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
5188 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
5189 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
5190 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
5191 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
5192 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
5193 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
5194 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
5195 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
5196 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
5197 case RIL_REQUEST_ANSWER: return "ANSWER";
5198 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
5199 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
5200 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
5201 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
5202 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
5203 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
5204 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
5205 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";
5206 case RIL_REQUEST_DTMF_START: return "DTMF_START";
5207 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
5208 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
5209 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
5210 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
5211 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
5212 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
5213 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
5214 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
5215 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
5216 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
5217 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
5218 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
5219 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
5220 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
5221 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
5222 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
5223 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
5224 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
5225 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
5226 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
5227 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
5228 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
5229 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
5230 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005231 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE:return"CDMA_SET_SUBSCRIPTION_SOURCE";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005232 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"CDMA_SET_ROAMING_PREFERENCE";
5233 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"CDMA_QUERY_ROAMING_PREFERENCE";
5234 case RIL_REQUEST_SET_TTY_MODE:return"SET_TTY_MODE";
5235 case RIL_REQUEST_QUERY_TTY_MODE:return"QUERY_TTY_MODE";
5236 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
5237 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
5238 case RIL_REQUEST_CDMA_FLASH:return"CDMA_FLASH";
5239 case RIL_REQUEST_CDMA_BURST_DTMF:return"CDMA_BURST_DTMF";
5240 case RIL_REQUEST_CDMA_SEND_SMS:return"CDMA_SEND_SMS";
5241 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:return"CDMA_SMS_ACKNOWLEDGE";
5242 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG:return"GSM_GET_BROADCAST_SMS_CONFIG";
5243 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG:return"GSM_SET_BROADCAST_SMS_CONFIG";
5244 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG:return "CDMA_GET_BROADCAST_SMS_CONFIG";
5245 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG:return "CDMA_SET_BROADCAST_SMS_CONFIG";
5246 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION:return "CDMA_SMS_BROADCAST_ACTIVATION";
Ethan Chend6e30652013-08-04 22:49:56 -07005247 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return"CDMA_VALIDATE_AND_WRITE_AKEY";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005248 case RIL_REQUEST_CDMA_SUBSCRIPTION: return"CDMA_SUBSCRIPTION";
5249 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
5250 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
5251 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
5252 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
5253 case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
5254 case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
5255 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
5256 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
5257 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
5258 case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
5259 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
5260 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
5261 case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005262 case RIL_REQUEST_GET_CELL_INFO_LIST: return"GET_CELL_INFO_LIST";
5263 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return"SET_UNSOL_CELL_INFO_LIST_RATE";
Andrew Jiangca4a9a02014-01-18 18:04:08 -05005264 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "RIL_REQUEST_SET_INITIAL_ATTACH_APN";
5265 case RIL_REQUEST_IMS_REGISTRATION_STATE: return "IMS_REGISTRATION_STATE";
5266 case RIL_REQUEST_IMS_SEND_SMS: return "IMS_SEND_SMS";
Howard Sue32dbfd2015-01-07 15:55:57 +08005267 case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "SIM_TRANSMIT_APDU_BASIC";
5268 case RIL_REQUEST_SIM_OPEN_CHANNEL: return "SIM_OPEN_CHANNEL";
5269 case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "SIM_CLOSE_CHANNEL";
5270 case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "SIM_TRANSMIT_APDU_CHANNEL";
Howard Subd82ef12015-04-12 10:25:05 +02005271 case RIL_REQUEST_GET_RADIO_CAPABILITY: return "RIL_REQUEST_GET_RADIO_CAPABILITY";
5272 case RIL_REQUEST_SET_RADIO_CAPABILITY: return "RIL_REQUEST_SET_RADIO_CAPABILITY";
Howard Sue32dbfd2015-01-07 15:55:57 +08005273 case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "SET_UICC_SUBSCRIPTION";
5274 case RIL_REQUEST_ALLOW_DATA: return "ALLOW_DATA";
5275 case RIL_REQUEST_GET_HARDWARE_CONFIG: return "GET_HARDWARE_CONFIG";
5276 case RIL_REQUEST_SIM_AUTHENTICATION: return "SIM_AUTHENTICATION";
5277 case RIL_REQUEST_GET_DC_RT_INFO: return "GET_DC_RT_INFO";
5278 case RIL_REQUEST_SET_DC_RT_INFO_RATE: return "SET_DC_RT_INFO_RATE";
5279 case RIL_REQUEST_SET_DATA_PROFILE: return "SET_DATA_PROFILE";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005280 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
5281 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
5282 case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED";
5283 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
5284 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
5285 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
5286 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
5287 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)";
5288 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
5289 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
Howard Subd82ef12015-04-12 10:25:05 +02005290 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
5291 case RIL_UNSOL_SUPP_SVC_NOTIFICATION: return "UNSOL_SUPP_SVC_NOTIFICATION";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005292 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
5293 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
5294 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
5295 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
5296 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL";
5297 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005298 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
5299 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
5300 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_NEW_CDMA_SMS";
5301 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_NEW_BROADCAST_SMS";
5302 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
5303 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
5304 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
5305 case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
5306 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
5307 case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
5308 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
5309 case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
5310 case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
5311 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
5312 case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
5313 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
5314 case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
5315 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
Ethan Chend6e30652013-08-04 22:49:56 -07005316 case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
Andrew Jiangca4a9a02014-01-18 18:04:08 -05005317 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "RESPONSE_IMS_NETWORK_STATE_CHANGED";
Howard Sue32dbfd2015-01-07 15:55:57 +08005318 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return "UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED";
5319 case RIL_UNSOL_SRVCC_STATE_NOTIFY: return "UNSOL_SRVCC_STATE_NOTIFY";
5320 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return "HARDWARE_CONFIG_CHANGED";
5321 case RIL_UNSOL_DC_RT_INFO_CHANGED: return "UNSOL_DC_RT_INFO_CHANGED";
Howard Subd82ef12015-04-12 10:25:05 +02005322 case RIL_UNSOL_RADIO_CAPABILITY: return "UNSOL_RADIO_CAPABILITY";
5323 case RIL_UNSOL_ON_SS: return "UNSOL_ON_SS";
5324 case RIL_UNSOL_STK_CC_ALPHA_NOTIFY: return "UNSOL_STK_CC_ALPHA_NOTIFY";
Howard Sue32dbfd2015-01-07 15:55:57 +08005325 case RIL_REQUEST_SHUTDOWN: return "SHUTDOWN";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005326 default: return "<unknown request>";
5327 }
5328}
5329
Howard Sue32dbfd2015-01-07 15:55:57 +08005330const char *
5331rilSocketIdToString(RIL_SOCKET_ID socket_id)
5332{
5333 switch(socket_id) {
5334 case RIL_SOCKET_1:
5335 return "RIL_SOCKET_1";
5336#if (SIM_COUNT >= 2)
5337 case RIL_SOCKET_2:
5338 return "RIL_SOCKET_2";
5339#endif
5340#if (SIM_COUNT >= 3)
5341 case RIL_SOCKET_3:
5342 return "RIL_SOCKET_3";
5343#endif
5344#if (SIM_COUNT >= 4)
5345 case RIL_SOCKET_4:
5346 return "RIL_SOCKET_4";
5347#endif
5348 default:
5349 return "not a valid RIL";
5350 }
5351}
5352
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005353} /* namespace android */
Dheeraj Shettycc231012014-07-02 21:27:57 +02005354
5355void rilEventAddWakeup_helper(struct ril_event *ev) {
5356 android::rilEventAddWakeup(ev);
5357}
5358
5359void listenCallback_helper(int fd, short flags, void *param) {
5360 android::listenCallback(fd, flags, param);
5361}
5362
5363int blockingWrite_helper(int fd, void *buffer, size_t len) {
5364 return android::blockingWrite(fd, buffer, len);
5365}