blob: a044049a0e9a937acd3814f1f26c35a43f713415 [file] [log] [blame]
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001/* //device/libs/telephony/ril.cpp
2**
3** Copyright 2006, The Android Open Source Project
4**
Wink Saville7f856802009-06-09 10:23:37 -07005** 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
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08008**
Wink Saville7f856802009-06-09 10:23:37 -07009** http://www.apache.org/licenses/LICENSE-2.0
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080010**
Wink Saville7f856802009-06-09 10:23:37 -070011** 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
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080015** limitations under the License.
16*/
17
18#define LOG_TAG "RILC"
19
20#include <hardware_legacy/power.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080021#include <telephony/ril.h>
Wink Savillef4c4d362009-04-02 01:37:03 -070022#include <telephony/ril_cdma_sms.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080023#include <cutils/sockets.h>
24#include <cutils/jstring.h>
Dima Zavin622bf2b2013-05-22 11:29:34 -070025#include <telephony/record_stream.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080026#include <utils/Log.h>
27#include <utils/SystemClock.h>
28#include <pthread.h>
Mathias Agopian8a3c48c2009-05-19 19:11:50 -070029#include <binder/Parcel.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080030#include <cutils/jstring.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080031#include <sys/types.h>
Wink Saville18e4ab12013-04-07 17:31:04 -070032#include <sys/limits.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080033#include <pwd.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080034#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 Shetty27976c42014-07-02 21:27:57 +020049#include <RilSapSocket.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080050
Dheeraj Shetty27976c42014-07-02 21:27:57 +020051extern "C" void
52RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080053namespace android {
54
55#define PHONE_PROCESS "radio"
Dheeraj Shetty27976c42014-07-02 21:27:57 +020056#define BLUETOOTH_PROCESS "bluetooth"
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080057
58#define SOCKET_NAME_RIL "rild"
Etan Cohend3652192014-06-20 08:28:44 -070059#define SOCKET2_NAME_RIL "rild2"
60#define SOCKET3_NAME_RIL "rild3"
61#define SOCKET4_NAME_RIL "rild4"
62
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080063#define SOCKET_NAME_RIL_DEBUG "rild-debug"
64
65#define ANDROID_WAKE_LOCK_NAME "radio-interface"
66
67
68#define PROPERTY_RIL_IMPL "gsm.version.ril-impl"
69
70// match with constant in RIL.java
71#define MAX_COMMAND_BYTES (8 * 1024)
72
73// Basically: memset buffers that the client library
74// shouldn't be using anymore in an attempt to find
75// memory usage issues sooner.
76#define MEMSET_FREED 1
77
78#define NUM_ELEMS(a) (sizeof (a) / sizeof (a)[0])
79
Wink Savillef4c4d362009-04-02 01:37:03 -070080#define MIN(a,b) ((a)<(b) ? (a) : (b))
81
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080082/* Constants for response types */
83#define RESPONSE_SOLICITED 0
84#define RESPONSE_UNSOLICITED 1
85
86/* Negative values for private RIL errno's */
87#define RIL_ERRNO_INVALID_RESPONSE -1
88
89// request, response, and unsolicited msg print macro
90#define PRINTBUF_SIZE 8096
91
92// Enable RILC log
93#define RILC_LOG 0
94
95#if RILC_LOG
96 #define startRequest sprintf(printBuf, "(")
97 #define closeRequest sprintf(printBuf, "%s)", printBuf)
98 #define printRequest(token, req) \
Wink Saville8eb2a122012-11-19 16:05:13 -080099 RLOGD("[%04d]> %s %s", token, requestToString(req), printBuf)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800100
101 #define startResponse sprintf(printBuf, "%s {", printBuf)
102 #define closeResponse sprintf(printBuf, "%s}", printBuf)
Wink Saville8eb2a122012-11-19 16:05:13 -0800103 #define printResponse RLOGD("%s", printBuf)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800104
105 #define clearPrintBuf printBuf[0] = 0
106 #define removeLastChar printBuf[strlen(printBuf)-1] = 0
107 #define appendPrintBuf(x...) sprintf(printBuf, x)
108#else
109 #define startRequest
110 #define closeRequest
111 #define printRequest(token, req)
112 #define startResponse
113 #define closeResponse
114 #define printResponse
115 #define clearPrintBuf
116 #define removeLastChar
117 #define appendPrintBuf(x...)
118#endif
119
120enum WakeType {DONT_WAKE, WAKE_PARTIAL};
121
122typedef struct {
123 int requestNumber;
124 void (*dispatchFunction) (Parcel &p, struct RequestInfo *pRI);
125 int(*responseFunction) (Parcel &p, void *response, size_t responselen);
126} CommandInfo;
127
128typedef struct {
129 int requestNumber;
130 int (*responseFunction) (Parcel &p, void *response, size_t responselen);
131 WakeType wakeType;
132} UnsolResponseInfo;
133
134typedef struct RequestInfo {
Wink Saville7f856802009-06-09 10:23:37 -0700135 int32_t token; //this is not RIL_Token
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800136 CommandInfo *pCI;
137 struct RequestInfo *p_next;
138 char cancelled;
139 char local; // responses to local commands do not go back to command process
Etan Cohend3652192014-06-20 08:28:44 -0700140 RIL_SOCKET_ID socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800141} RequestInfo;
142
Wink Saville3d54e742009-05-18 18:00:44 -0700143typedef struct UserCallbackInfo {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800144 RIL_TimedCallback p_callback;
145 void *userParam;
146 struct ril_event event;
147 struct UserCallbackInfo *p_next;
148} UserCallbackInfo;
149
Etan Cohend3652192014-06-20 08:28:44 -0700150extern "C" const char * requestToString(int request);
151extern "C" const char * failCauseToString(RIL_Errno);
152extern "C" const char * callStateToString(RIL_CallState);
153extern "C" const char * radioStateToString(RIL_RadioState);
154extern "C" const char * rilSocketIdToString(RIL_SOCKET_ID socket_id);
155
156extern "C"
157char rild[MAX_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800158/*******************************************************************/
159
160RIL_RadioFunctions s_callbacks = {0, NULL, NULL, NULL, NULL, NULL};
161static int s_registerCalled = 0;
162
163static pthread_t s_tid_dispatch;
164static pthread_t s_tid_reader;
165static int s_started = 0;
166
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800167static int s_fdDebug = -1;
Etan Cohend3652192014-06-20 08:28:44 -0700168static int s_fdDebug_socket2 = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800169
170static int s_fdWakeupRead;
171static int s_fdWakeupWrite;
172
173static struct ril_event s_commands_event;
174static struct ril_event s_wakeupfd_event;
175static struct ril_event s_listen_event;
Etan Cohend3652192014-06-20 08:28:44 -0700176static SocketListenParam s_ril_param_socket;
177
178static pthread_mutex_t s_pendingRequestsMutex = PTHREAD_MUTEX_INITIALIZER;
179static pthread_mutex_t s_writeMutex = PTHREAD_MUTEX_INITIALIZER;
180static RequestInfo *s_pendingRequests = NULL;
181
182#if (SIM_COUNT >= 2)
183static struct ril_event s_commands_event_socket2;
184static struct ril_event s_listen_event_socket2;
185static SocketListenParam s_ril_param_socket2;
186
187static pthread_mutex_t s_pendingRequestsMutex_socket2 = PTHREAD_MUTEX_INITIALIZER;
188static pthread_mutex_t s_writeMutex_socket2 = PTHREAD_MUTEX_INITIALIZER;
189static RequestInfo *s_pendingRequests_socket2 = NULL;
190#endif
191
192#if (SIM_COUNT >= 3)
193static struct ril_event s_commands_event_socket3;
194static struct ril_event s_listen_event_socket3;
195static SocketListenParam s_ril_param_socket3;
196
197static pthread_mutex_t s_pendingRequestsMutex_socket3 = PTHREAD_MUTEX_INITIALIZER;
198static pthread_mutex_t s_writeMutex_socket3 = PTHREAD_MUTEX_INITIALIZER;
199static RequestInfo *s_pendingRequests_socket3 = NULL;
200#endif
201
202#if (SIM_COUNT >= 4)
203static struct ril_event s_commands_event_socket4;
204static struct ril_event s_listen_event_socket4;
205static SocketListenParam s_ril_param_socket4;
206
207static pthread_mutex_t s_pendingRequestsMutex_socket4 = PTHREAD_MUTEX_INITIALIZER;
208static pthread_mutex_t s_writeMutex_socket4 = PTHREAD_MUTEX_INITIALIZER;
209static RequestInfo *s_pendingRequests_socket4 = NULL;
210#endif
211
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800212static struct ril_event s_wake_timeout_event;
213static struct ril_event s_debug_event;
214
215
216static const struct timeval TIMEVAL_WAKE_TIMEOUT = {1,0};
217
Etan Cohend3652192014-06-20 08:28:44 -0700218
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800219static pthread_mutex_t s_startupMutex = PTHREAD_MUTEX_INITIALIZER;
220static pthread_cond_t s_startupCond = PTHREAD_COND_INITIALIZER;
221
222static pthread_mutex_t s_dispatchMutex = PTHREAD_MUTEX_INITIALIZER;
223static pthread_cond_t s_dispatchCond = PTHREAD_COND_INITIALIZER;
224
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800225static RequestInfo *s_toDispatchHead = NULL;
226static RequestInfo *s_toDispatchTail = NULL;
227
228static UserCallbackInfo *s_last_wake_timeout_info = NULL;
229
230static void *s_lastNITZTimeData = NULL;
231static size_t s_lastNITZTimeDataSize;
232
233#if RILC_LOG
234 static char printBuf[PRINTBUF_SIZE];
235#endif
236
237/*******************************************************************/
Etan Cohend3652192014-06-20 08:28:44 -0700238static int sendResponse (Parcel &p, RIL_SOCKET_ID socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800239
240static void dispatchVoid (Parcel& p, RequestInfo *pRI);
241static void dispatchString (Parcel& p, RequestInfo *pRI);
242static void dispatchStrings (Parcel& p, RequestInfo *pRI);
243static void dispatchInts (Parcel& p, RequestInfo *pRI);
244static void dispatchDial (Parcel& p, RequestInfo *pRI);
245static void dispatchSIM_IO (Parcel& p, RequestInfo *pRI);
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800246static void dispatchSIM_APDU (Parcel& p, RequestInfo *pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800247static void dispatchCallForward(Parcel& p, RequestInfo *pRI);
248static void dispatchRaw(Parcel& p, RequestInfo *pRI);
249static void dispatchSmsWrite (Parcel &p, RequestInfo *pRI);
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -0700250static void dispatchDataCall (Parcel& p, RequestInfo *pRI);
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800251static void dispatchVoiceRadioTech (Parcel& p, RequestInfo *pRI);
Sungmin Choi75697532013-04-26 15:04:45 -0700252static void dispatchSetInitialAttachApn (Parcel& p, RequestInfo *pRI);
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800253static void dispatchCdmaSubscriptionSource (Parcel& p, RequestInfo *pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800254
Wink Savillef4c4d362009-04-02 01:37:03 -0700255static void dispatchCdmaSms(Parcel &p, RequestInfo *pRI);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -0700256static void dispatchImsSms(Parcel &p, RequestInfo *pRI);
257static void dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
258static void dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
Wink Savillef4c4d362009-04-02 01:37:03 -0700259static void dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI);
Wink Savillea592eeb2009-05-22 13:26:36 -0700260static void dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI);
Wink Savillef4c4d362009-04-02 01:37:03 -0700261static void dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI);
262static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI);
Jake Hamby8a4a2332014-01-15 13:12:05 -0800263static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI);
264static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI);
Etan Cohend3652192014-06-20 08:28:44 -0700265static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI);
Amit Mahajan90530a62014-07-01 15:54:08 -0700266static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI);
Amit Mahajanc796e222014-08-13 16:54:01 +0000267static void dispatchDataProfile(Parcel &p, RequestInfo *pRI);
Wink Saville8b4e4f72014-10-17 15:01:45 -0700268static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800269static int responseInts(Parcel &p, void *response, size_t responselen);
270static int responseStrings(Parcel &p, void *response, size_t responselen);
271static int responseString(Parcel &p, void *response, size_t responselen);
272static int responseVoid(Parcel &p, void *response, size_t responselen);
273static int responseCallList(Parcel &p, void *response, size_t responselen);
274static int responseSMS(Parcel &p, void *response, size_t responselen);
275static int responseSIM_IO(Parcel &p, void *response, size_t responselen);
276static int responseCallForwards(Parcel &p, void *response, size_t responselen);
Wink Savillef4c4d362009-04-02 01:37:03 -0700277static int responseDataCallList(Parcel &p, void *response, size_t responselen);
Wink Saville43808972011-01-13 17:39:51 -0800278static int responseSetupDataCall(Parcel &p, void *response, size_t responselen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800279static int responseRaw(Parcel &p, void *response, size_t responselen);
280static int responseSsn(Parcel &p, void *response, size_t responselen);
Wink Savillef4c4d362009-04-02 01:37:03 -0700281static int responseSimStatus(Parcel &p, void *response, size_t responselen);
Wink Savillea592eeb2009-05-22 13:26:36 -0700282static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen);
283static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen);
Wink Savillef4c4d362009-04-02 01:37:03 -0700284static int responseCdmaSms(Parcel &p, void *response, size_t responselen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800285static int responseCellList(Parcel &p, void *response, size_t responselen);
Wink Saville3d54e742009-05-18 18:00:44 -0700286static int responseCdmaInformationRecords(Parcel &p,void *response, size_t responselen);
287static int responseRilSignalStrength(Parcel &p,void *response, size_t responselen);
288static int responseCallRing(Parcel &p, void *response, size_t responselen);
289static int responseCdmaSignalInfoRecord(Parcel &p,void *response, size_t responselen);
290static int responseCdmaCallWaiting(Parcel &p,void *response, size_t responselen);
Alex Yakavenka45e740e2012-01-31 11:48:27 -0800291static int responseSimRefresh(Parcel &p, void *response, size_t responselen);
Wink Saville8a9e0212013-04-09 12:11:38 -0700292static int responseCellInfoList(Parcel &p, void *response, size_t responselen);
Etan Cohend3652192014-06-20 08:28:44 -0700293static int responseHardwareConfig(Parcel &p, void *response, size_t responselen);
Wink Savillec29360a2014-07-13 05:17:28 -0700294static int responseDcRtInfo(Parcel &p, void *response, size_t responselen);
Wink Saville8b4e4f72014-10-17 15:01:45 -0700295static int responseRadioCapability(Parcel &p, void *response, size_t responselen);
Amit Mahajan54563d32014-11-22 00:54:49 +0000296static int responseSSData(Parcel &p, void *response, size_t responselen);
fengluf7408292015-04-14 14:53:55 -0700297static int responseLceStatus(Parcel &p, void *response, size_t responselen);
298static int responseLceData(Parcel &p, void *response, size_t responselen);
Amit Mahajan54563d32014-11-22 00:54:49 +0000299
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800300static int decodeVoiceRadioTechnology (RIL_RadioState radioState);
301static int decodeCdmaSubscriptionSource (RIL_RadioState radioState);
302static RIL_RadioState processRadioState(RIL_RadioState newRadioState);
303
Amit Mahajan54563d32014-11-22 00:54:49 +0000304static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType);
305
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800306#ifdef RIL_SHLIB
Etan Cohend3652192014-06-20 08:28:44 -0700307#if defined(ANDROID_MULTI_SIM)
Vinit Deshpande1b1ec2d2015-04-15 13:31:05 -0700308extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Etan Cohend3652192014-06-20 08:28:44 -0700309 size_t datalen, RIL_SOCKET_ID socket_id);
310#else
Vinit Deshpande1b1ec2d2015-04-15 13:31:05 -0700311extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800312 size_t datalen);
313#endif
Etan Cohend3652192014-06-20 08:28:44 -0700314#endif
315
316#if defined(ANDROID_MULTI_SIM)
317#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c), (d))
318#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d), (e))
319#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest(a)
320#else
321#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c))
322#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d))
323#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest()
324#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800325
Wink Saville7f856802009-06-09 10:23:37 -0700326static UserCallbackInfo * internalRequestTimedCallback
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -0700327 (RIL_TimedCallback callback, void *param,
328 const struct timeval *relativeTime);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800329
330/** Index == requestNumber */
331static CommandInfo s_commands[] = {
332#include "ril_commands.h"
333};
334
335static UnsolResponseInfo s_unsolResponses[] = {
336#include "ril_unsol_commands.h"
337};
338
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800339/* For older RILs that do not support new commands RIL_REQUEST_VOICE_RADIO_TECH and
340 RIL_UNSOL_VOICE_RADIO_TECH_CHANGED messages, decode the voice radio tech from
341 radio state message and store it. Every time there is a change in Radio State
342 check to see if voice radio tech changes and notify telephony
343 */
344int voiceRadioTech = -1;
345
346/* For older RILs that do not support new commands RIL_REQUEST_GET_CDMA_SUBSCRIPTION_SOURCE
347 and RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED messages, decode the subscription
348 source from radio state and store it. Every time there is a change in Radio State
349 check to see if subscription source changed and notify telephony
350 */
351int cdmaSubscriptionSource = -1;
352
353/* For older RILs that do not send RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, decode the
354 SIM/RUIM state from radio state and store it. Every time there is a change in Radio State,
355 check to see if SIM/RUIM status changed and notify telephony
356 */
357int simRuimStatus = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800358
Etan Cohend3652192014-06-20 08:28:44 -0700359static char * RIL_getRilSocketName() {
360 return rild;
361}
362
363extern "C"
Dheeraj Shetty27976c42014-07-02 21:27:57 +0200364void RIL_setRilSocketName(const char * s) {
Etan Cohend3652192014-06-20 08:28:44 -0700365 strncpy(rild, s, MAX_SOCKET_NAME_LENGTH);
366}
367
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800368static char *
Wink Savillef4c4d362009-04-02 01:37:03 -0700369strdupReadString(Parcel &p) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800370 size_t stringlen;
371 const char16_t *s16;
Wink Saville7f856802009-06-09 10:23:37 -0700372
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800373 s16 = p.readString16Inplace(&stringlen);
Wink Saville7f856802009-06-09 10:23:37 -0700374
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800375 return strndup16to8(s16, stringlen);
376}
377
Wink Saville8b4e4f72014-10-17 15:01:45 -0700378static status_t
379readStringFromParcelInplace(Parcel &p, char *str, size_t maxLen) {
380 size_t s16Len;
381 const char16_t *s16;
382
383 s16 = p.readString16Inplace(&s16Len);
384 if (s16 == NULL) {
385 return NO_MEMORY;
386 }
387 size_t strLen = strnlen16to8(s16, s16Len);
388 if ((strLen + 1) > maxLen) {
389 return NO_MEMORY;
390 }
391 if (strncpy16to8(str, s16, strLen) == NULL) {
392 return NO_MEMORY;
393 } else {
394 return NO_ERROR;
395 }
396}
397
Wink Savillef4c4d362009-04-02 01:37:03 -0700398static void writeStringToParcel(Parcel &p, const char *s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800399 char16_t *s16;
400 size_t s16_len;
401 s16 = strdup8to16(s, &s16_len);
402 p.writeString16(s16, s16_len);
403 free(s16);
404}
405
406
407static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700408memsetString (char *s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800409 if (s != NULL) {
410 memset (s, 0, strlen(s));
411 }
412}
413
414void nullParcelReleaseFunction (const uint8_t* data, size_t dataSize,
415 const size_t* objects, size_t objectsSize,
Wink Savillef4c4d362009-04-02 01:37:03 -0700416 void* cookie) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800417 // do nothing -- the data reference lives longer than the Parcel object
418}
419
Wink Saville7f856802009-06-09 10:23:37 -0700420/**
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800421 * To be called from dispatch thread
422 * Issue a single local request, ensuring that the response
Wink Saville7f856802009-06-09 10:23:37 -0700423 * is not sent back up to the command process
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800424 */
425static void
Etan Cohend3652192014-06-20 08:28:44 -0700426issueLocalRequest(int request, void *data, int len, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800427 RequestInfo *pRI;
428 int ret;
Etan Cohend3652192014-06-20 08:28:44 -0700429 /* Hook for current context */
430 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
431 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
432 /* pendingRequestsHook refer to &s_pendingRequests */
433 RequestInfo** pendingRequestsHook = &s_pendingRequests;
434
435#if (SIM_COUNT == 2)
436 if (socket_id == RIL_SOCKET_2) {
437 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
438 pendingRequestsHook = &s_pendingRequests_socket2;
439 }
440#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800441
442 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
443
444 pRI->local = 1;
445 pRI->token = 0xffffffff; // token is not used in this context
446 pRI->pCI = &(s_commands[request]);
Etan Cohend3652192014-06-20 08:28:44 -0700447 pRI->socket_id = socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800448
Etan Cohend3652192014-06-20 08:28:44 -0700449 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800450 assert (ret == 0);
451
Etan Cohend3652192014-06-20 08:28:44 -0700452 pRI->p_next = *pendingRequestsHook;
453 *pendingRequestsHook = pRI;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800454
Etan Cohend3652192014-06-20 08:28:44 -0700455 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800456 assert (ret == 0);
457
Wink Saville8eb2a122012-11-19 16:05:13 -0800458 RLOGD("C[locl]> %s", requestToString(request));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800459
Etan Cohend3652192014-06-20 08:28:44 -0700460 CALL_ONREQUEST(request, data, len, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800461}
462
463
464
465static int
Etan Cohend3652192014-06-20 08:28:44 -0700466processCommandBuffer(void *buffer, size_t buflen, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800467 Parcel p;
468 status_t status;
469 int32_t request;
470 int32_t token;
471 RequestInfo *pRI;
472 int ret;
Etan Cohend3652192014-06-20 08:28:44 -0700473 /* Hook for current context */
474 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
475 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
476 /* pendingRequestsHook refer to &s_pendingRequests */
477 RequestInfo** pendingRequestsHook = &s_pendingRequests;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800478
479 p.setData((uint8_t *) buffer, buflen);
480
481 // status checked at end
482 status = p.readInt32(&request);
483 status = p.readInt32 (&token);
484
Etan Cohend3652192014-06-20 08:28:44 -0700485#if (SIM_COUNT >= 2)
486 if (socket_id == RIL_SOCKET_2) {
487 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
488 pendingRequestsHook = &s_pendingRequests_socket2;
489 }
490#if (SIM_COUNT >= 3)
491 else if (socket_id == RIL_SOCKET_3) {
492 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
493 pendingRequestsHook = &s_pendingRequests_socket3;
494 }
495#endif
496#if (SIM_COUNT >= 4)
497 else if (socket_id == RIL_SOCKET_4) {
498 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
499 pendingRequestsHook = &s_pendingRequests_socket4;
500 }
501#endif
502#endif
503
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800504 if (status != NO_ERROR) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800505 RLOGE("invalid request block");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800506 return 0;
507 }
508
509 if (request < 1 || request >= (int32_t)NUM_ELEMS(s_commands)) {
Etan Cohend3652192014-06-20 08:28:44 -0700510 Parcel pErr;
Wink Saville8eb2a122012-11-19 16:05:13 -0800511 RLOGE("unsupported request code %d token %d", request, token);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800512 // FIXME this should perhaps return a response
Etan Cohend3652192014-06-20 08:28:44 -0700513 pErr.writeInt32 (RESPONSE_SOLICITED);
514 pErr.writeInt32 (token);
515 pErr.writeInt32 (RIL_E_GENERIC_FAILURE);
516
517 sendResponse(pErr, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800518 return 0;
519 }
520
521
522 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
523
524 pRI->token = token;
525 pRI->pCI = &(s_commands[request]);
Etan Cohend3652192014-06-20 08:28:44 -0700526 pRI->socket_id = socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800527
Etan Cohend3652192014-06-20 08:28:44 -0700528 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800529 assert (ret == 0);
530
Etan Cohend3652192014-06-20 08:28:44 -0700531 pRI->p_next = *pendingRequestsHook;
532 *pendingRequestsHook = pRI;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800533
Etan Cohend3652192014-06-20 08:28:44 -0700534 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800535 assert (ret == 0);
536
537/* sLastDispatchedToken = token; */
538
Wink Saville7f856802009-06-09 10:23:37 -0700539 pRI->pCI->dispatchFunction(p, pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800540
541 return 0;
542}
543
544static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700545invalidCommandBlock (RequestInfo *pRI) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800546 RLOGE("invalid command block for token %d request %s",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800547 pRI->token, requestToString(pRI->pCI->requestNumber));
548}
549
550/** Callee expects NULL */
Wink Saville7f856802009-06-09 10:23:37 -0700551static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700552dispatchVoid (Parcel& p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800553 clearPrintBuf;
554 printRequest(pRI->token, pRI->pCI->requestNumber);
Etan Cohend3652192014-06-20 08:28:44 -0700555 CALL_ONREQUEST(pRI->pCI->requestNumber, NULL, 0, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800556}
557
558/** Callee expects const char * */
559static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700560dispatchString (Parcel& p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800561 status_t status;
562 size_t datalen;
563 size_t stringlen;
564 char *string8 = NULL;
565
566 string8 = strdupReadString(p);
567
568 startRequest;
569 appendPrintBuf("%s%s", printBuf, string8);
570 closeRequest;
571 printRequest(pRI->token, pRI->pCI->requestNumber);
572
Etan Cohend3652192014-06-20 08:28:44 -0700573 CALL_ONREQUEST(pRI->pCI->requestNumber, string8,
574 sizeof(char *), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800575
576#ifdef MEMSET_FREED
577 memsetString(string8);
578#endif
579
580 free(string8);
581 return;
582invalid:
583 invalidCommandBlock(pRI);
584 return;
585}
586
587/** Callee expects const char ** */
588static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700589dispatchStrings (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800590 int32_t countStrings;
591 status_t status;
592 size_t datalen;
593 char **pStrings;
594
595 status = p.readInt32 (&countStrings);
596
597 if (status != NO_ERROR) {
598 goto invalid;
599 }
600
601 startRequest;
602 if (countStrings == 0) {
603 // just some non-null pointer
604 pStrings = (char **)alloca(sizeof(char *));
605 datalen = 0;
606 } else if (((int)countStrings) == -1) {
607 pStrings = NULL;
608 datalen = 0;
609 } else {
610 datalen = sizeof(char *) * countStrings;
Wink Saville7f856802009-06-09 10:23:37 -0700611
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800612 pStrings = (char **)alloca(datalen);
613
614 for (int i = 0 ; i < countStrings ; i++) {
615 pStrings[i] = strdupReadString(p);
616 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
617 }
618 }
619 removeLastChar;
620 closeRequest;
621 printRequest(pRI->token, pRI->pCI->requestNumber);
622
Etan Cohend3652192014-06-20 08:28:44 -0700623 CALL_ONREQUEST(pRI->pCI->requestNumber, pStrings, datalen, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800624
625 if (pStrings != NULL) {
626 for (int i = 0 ; i < countStrings ; i++) {
627#ifdef MEMSET_FREED
628 memsetString (pStrings[i]);
629#endif
630 free(pStrings[i]);
631 }
632
633#ifdef MEMSET_FREED
634 memset(pStrings, 0, datalen);
635#endif
636 }
Wink Saville7f856802009-06-09 10:23:37 -0700637
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800638 return;
639invalid:
640 invalidCommandBlock(pRI);
641 return;
642}
643
644/** Callee expects const int * */
645static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700646dispatchInts (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800647 int32_t count;
648 status_t status;
649 size_t datalen;
650 int *pInts;
651
652 status = p.readInt32 (&count);
653
654 if (status != NO_ERROR || count == 0) {
655 goto invalid;
656 }
657
658 datalen = sizeof(int) * count;
659 pInts = (int *)alloca(datalen);
660
661 startRequest;
662 for (int i = 0 ; i < count ; i++) {
663 int32_t t;
664
665 status = p.readInt32(&t);
666 pInts[i] = (int)t;
667 appendPrintBuf("%s%d,", printBuf, t);
668
669 if (status != NO_ERROR) {
670 goto invalid;
671 }
672 }
673 removeLastChar;
674 closeRequest;
675 printRequest(pRI->token, pRI->pCI->requestNumber);
676
Etan Cohend3652192014-06-20 08:28:44 -0700677 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<int *>(pInts),
678 datalen, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800679
680#ifdef MEMSET_FREED
681 memset(pInts, 0, datalen);
682#endif
683
684 return;
685invalid:
686 invalidCommandBlock(pRI);
687 return;
688}
689
690
Wink Saville7f856802009-06-09 10:23:37 -0700691/**
692 * Callee expects const RIL_SMS_WriteArgs *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800693 * Payload is:
694 * int32_t status
695 * String pdu
696 */
697static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700698dispatchSmsWrite (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800699 RIL_SMS_WriteArgs args;
700 int32_t t;
701 status_t status;
702
Mark Salyzyndba25612015-04-09 07:18:35 -0700703 RLOGD("dispatchSmsWrite");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800704 memset (&args, 0, sizeof(args));
705
706 status = p.readInt32(&t);
707 args.status = (int)t;
708
709 args.pdu = strdupReadString(p);
710
711 if (status != NO_ERROR || args.pdu == NULL) {
712 goto invalid;
713 }
714
715 args.smsc = strdupReadString(p);
716
717 startRequest;
718 appendPrintBuf("%s%d,%s,smsc=%s", printBuf, args.status,
719 (char*)args.pdu, (char*)args.smsc);
720 closeRequest;
721 printRequest(pRI->token, pRI->pCI->requestNumber);
Wink Saville7f856802009-06-09 10:23:37 -0700722
Etan Cohend3652192014-06-20 08:28:44 -0700723 CALL_ONREQUEST(pRI->pCI->requestNumber, &args, sizeof(args), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800724
725#ifdef MEMSET_FREED
726 memsetString (args.pdu);
727#endif
728
729 free (args.pdu);
Wink Saville7f856802009-06-09 10:23:37 -0700730
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800731#ifdef MEMSET_FREED
732 memset(&args, 0, sizeof(args));
733#endif
734
735 return;
736invalid:
737 invalidCommandBlock(pRI);
738 return;
739}
740
Wink Saville7f856802009-06-09 10:23:37 -0700741/**
742 * Callee expects const RIL_Dial *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800743 * Payload is:
744 * String address
745 * int32_t clir
746 */
747static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700748dispatchDial (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800749 RIL_Dial dial;
Wink Saville74fa3882009-12-22 15:35:41 -0800750 RIL_UUS_Info uusInfo;
Wink Saville7bce0822010-01-08 15:20:12 -0800751 int32_t sizeOfDial;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800752 int32_t t;
Wink Saville74fa3882009-12-22 15:35:41 -0800753 int32_t uusPresent;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800754 status_t status;
755
Mark Salyzyndba25612015-04-09 07:18:35 -0700756 RLOGD("dispatchDial");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800757 memset (&dial, 0, sizeof(dial));
758
759 dial.address = strdupReadString(p);
760
761 status = p.readInt32(&t);
762 dial.clir = (int)t;
763
764 if (status != NO_ERROR || dial.address == NULL) {
765 goto invalid;
766 }
767
Wink Saville3a4840b2010-04-07 13:29:58 -0700768 if (s_callbacks.version < 3) { // Remove when partners upgrade to version 3
Wink Saville74fa3882009-12-22 15:35:41 -0800769 uusPresent = 0;
Wink Saville7bce0822010-01-08 15:20:12 -0800770 sizeOfDial = sizeof(dial) - sizeof(RIL_UUS_Info *);
Wink Saville74fa3882009-12-22 15:35:41 -0800771 } else {
772 status = p.readInt32(&uusPresent);
773
774 if (status != NO_ERROR) {
775 goto invalid;
776 }
777
778 if (uusPresent == 0) {
779 dial.uusInfo = NULL;
780 } else {
781 int32_t len;
782
783 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
784
785 status = p.readInt32(&t);
786 uusInfo.uusType = (RIL_UUS_Type) t;
787
788 status = p.readInt32(&t);
789 uusInfo.uusDcs = (RIL_UUS_DCS) t;
790
791 status = p.readInt32(&len);
792 if (status != NO_ERROR) {
793 goto invalid;
794 }
795
796 // The java code writes -1 for null arrays
797 if (((int) len) == -1) {
798 uusInfo.uusData = NULL;
799 len = 0;
800 } else {
801 uusInfo.uusData = (char*) p.readInplace(len);
802 }
803
804 uusInfo.uusLength = len;
805 dial.uusInfo = &uusInfo;
806 }
Wink Saville7bce0822010-01-08 15:20:12 -0800807 sizeOfDial = sizeof(dial);
Wink Saville74fa3882009-12-22 15:35:41 -0800808 }
809
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800810 startRequest;
811 appendPrintBuf("%snum=%s,clir=%d", printBuf, dial.address, dial.clir);
Wink Saville74fa3882009-12-22 15:35:41 -0800812 if (uusPresent) {
813 appendPrintBuf("%s,uusType=%d,uusDcs=%d,uusLen=%d", printBuf,
814 dial.uusInfo->uusType, dial.uusInfo->uusDcs,
815 dial.uusInfo->uusLength);
816 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800817 closeRequest;
818 printRequest(pRI->token, pRI->pCI->requestNumber);
819
Etan Cohend3652192014-06-20 08:28:44 -0700820 CALL_ONREQUEST(pRI->pCI->requestNumber, &dial, sizeOfDial, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800821
822#ifdef MEMSET_FREED
823 memsetString (dial.address);
824#endif
825
826 free (dial.address);
Wink Saville7f856802009-06-09 10:23:37 -0700827
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800828#ifdef MEMSET_FREED
Wink Saville74fa3882009-12-22 15:35:41 -0800829 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800830 memset(&dial, 0, sizeof(dial));
831#endif
832
833 return;
834invalid:
835 invalidCommandBlock(pRI);
836 return;
837}
838
Wink Saville7f856802009-06-09 10:23:37 -0700839/**
840 * Callee expects const RIL_SIM_IO *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800841 * Payload is:
842 * int32_t command
843 * int32_t fileid
844 * String path
845 * int32_t p1, p2, p3
Wink Saville7f856802009-06-09 10:23:37 -0700846 * String data
847 * String pin2
Wink Savillec0114b32011-02-18 10:14:07 -0800848 * String aidPtr
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800849 */
850static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700851dispatchSIM_IO (Parcel &p, RequestInfo *pRI) {
Wink Savillec0114b32011-02-18 10:14:07 -0800852 union RIL_SIM_IO {
853 RIL_SIM_IO_v6 v6;
854 RIL_SIM_IO_v5 v5;
855 } simIO;
856
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800857 int32_t t;
Wink Savillec0114b32011-02-18 10:14:07 -0800858 int size;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800859 status_t status;
860
Mark Salyzyndba25612015-04-09 07:18:35 -0700861 RLOGD("dispatchSIM_IO");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800862 memset (&simIO, 0, sizeof(simIO));
863
Wink Saville7f856802009-06-09 10:23:37 -0700864 // note we only check status at the end
865
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800866 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800867 simIO.v6.command = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800868
869 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800870 simIO.v6.fileid = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800871
Wink Savillec0114b32011-02-18 10:14:07 -0800872 simIO.v6.path = strdupReadString(p);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800873
874 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800875 simIO.v6.p1 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800876
877 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800878 simIO.v6.p2 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800879
880 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800881 simIO.v6.p3 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800882
Wink Savillec0114b32011-02-18 10:14:07 -0800883 simIO.v6.data = strdupReadString(p);
884 simIO.v6.pin2 = strdupReadString(p);
885 simIO.v6.aidPtr = strdupReadString(p);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800886
887 startRequest;
Wink Savillec0114b32011-02-18 10:14:07 -0800888 appendPrintBuf("%scmd=0x%X,efid=0x%X,path=%s,%d,%d,%d,%s,pin2=%s,aid=%s", printBuf,
889 simIO.v6.command, simIO.v6.fileid, (char*)simIO.v6.path,
890 simIO.v6.p1, simIO.v6.p2, simIO.v6.p3,
891 (char*)simIO.v6.data, (char*)simIO.v6.pin2, simIO.v6.aidPtr);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800892 closeRequest;
893 printRequest(pRI->token, pRI->pCI->requestNumber);
Wink Saville7f856802009-06-09 10:23:37 -0700894
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800895 if (status != NO_ERROR) {
896 goto invalid;
897 }
898
Wink Savillec0114b32011-02-18 10:14:07 -0800899 size = (s_callbacks.version < 6) ? sizeof(simIO.v5) : sizeof(simIO.v6);
Etan Cohend3652192014-06-20 08:28:44 -0700900 CALL_ONREQUEST(pRI->pCI->requestNumber, &simIO, size, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800901
902#ifdef MEMSET_FREED
Wink Savillec0114b32011-02-18 10:14:07 -0800903 memsetString (simIO.v6.path);
904 memsetString (simIO.v6.data);
905 memsetString (simIO.v6.pin2);
906 memsetString (simIO.v6.aidPtr);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800907#endif
908
Wink Savillec0114b32011-02-18 10:14:07 -0800909 free (simIO.v6.path);
910 free (simIO.v6.data);
911 free (simIO.v6.pin2);
912 free (simIO.v6.aidPtr);
Wink Saville7f856802009-06-09 10:23:37 -0700913
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800914#ifdef MEMSET_FREED
915 memset(&simIO, 0, sizeof(simIO));
916#endif
917
918 return;
919invalid:
920 invalidCommandBlock(pRI);
921 return;
922}
923
924/**
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800925 * Callee expects const RIL_SIM_APDU *
926 * Payload is:
927 * int32_t sessionid
928 * int32_t cla
929 * int32_t instruction
930 * int32_t p1, p2, p3
931 * String data
932 */
933static void
934dispatchSIM_APDU (Parcel &p, RequestInfo *pRI) {
935 int32_t t;
936 status_t status;
937 RIL_SIM_APDU apdu;
938
Mark Salyzyndba25612015-04-09 07:18:35 -0700939 RLOGD("dispatchSIM_APDU");
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800940 memset (&apdu, 0, sizeof(RIL_SIM_APDU));
941
942 // Note we only check status at the end. Any single failure leads to
943 // subsequent reads filing.
944 status = p.readInt32(&t);
945 apdu.sessionid = (int)t;
946
947 status = p.readInt32(&t);
948 apdu.cla = (int)t;
949
950 status = p.readInt32(&t);
951 apdu.instruction = (int)t;
952
953 status = p.readInt32(&t);
954 apdu.p1 = (int)t;
955
956 status = p.readInt32(&t);
957 apdu.p2 = (int)t;
958
959 status = p.readInt32(&t);
960 apdu.p3 = (int)t;
961
962 apdu.data = strdupReadString(p);
963
964 startRequest;
965 appendPrintBuf("%ssessionid=%d,cla=%d,ins=%d,p1=%d,p2=%d,p3=%d,data=%s",
966 printBuf, apdu.sessionid, apdu.cla, apdu.instruction, apdu.p1, apdu.p2,
967 apdu.p3, (char*)apdu.data);
968 closeRequest;
969 printRequest(pRI->token, pRI->pCI->requestNumber);
970
971 if (status != NO_ERROR) {
972 goto invalid;
973 }
974
Etan Cohend3652192014-06-20 08:28:44 -0700975 CALL_ONREQUEST(pRI->pCI->requestNumber, &apdu, sizeof(RIL_SIM_APDU), pRI, pRI->socket_id);
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800976
977#ifdef MEMSET_FREED
978 memsetString(apdu.data);
979#endif
980 free(apdu.data);
981
982#ifdef MEMSET_FREED
983 memset(&apdu, 0, sizeof(RIL_SIM_APDU));
984#endif
985
986 return;
987invalid:
988 invalidCommandBlock(pRI);
989 return;
990}
991
992
993/**
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800994 * Callee expects const RIL_CallForwardInfo *
995 * Payload is:
996 * int32_t status/action
997 * int32_t reason
998 * int32_t serviceCode
999 * int32_t toa
1000 * String number (0 length -> null)
1001 * int32_t timeSeconds
1002 */
Wink Saville7f856802009-06-09 10:23:37 -07001003static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001004dispatchCallForward(Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001005 RIL_CallForwardInfo cff;
1006 int32_t t;
1007 status_t status;
1008
Mark Salyzyndba25612015-04-09 07:18:35 -07001009 RLOGD("dispatchCallForward");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001010 memset (&cff, 0, sizeof(cff));
1011
Wink Saville7f856802009-06-09 10:23:37 -07001012 // note we only check status at the end
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001013
1014 status = p.readInt32(&t);
1015 cff.status = (int)t;
Wink Saville7f856802009-06-09 10:23:37 -07001016
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001017 status = p.readInt32(&t);
1018 cff.reason = (int)t;
1019
1020 status = p.readInt32(&t);
1021 cff.serviceClass = (int)t;
1022
1023 status = p.readInt32(&t);
1024 cff.toa = (int)t;
1025
1026 cff.number = strdupReadString(p);
1027
1028 status = p.readInt32(&t);
1029 cff.timeSeconds = (int)t;
1030
1031 if (status != NO_ERROR) {
1032 goto invalid;
1033 }
1034
1035 // special case: number 0-length fields is null
1036
1037 if (cff.number != NULL && strlen (cff.number) == 0) {
1038 cff.number = NULL;
1039 }
1040
1041 startRequest;
1042 appendPrintBuf("%sstat=%d,reason=%d,serv=%d,toa=%d,%s,tout=%d", printBuf,
1043 cff.status, cff.reason, cff.serviceClass, cff.toa,
1044 (char*)cff.number, cff.timeSeconds);
1045 closeRequest;
1046 printRequest(pRI->token, pRI->pCI->requestNumber);
1047
Etan Cohend3652192014-06-20 08:28:44 -07001048 CALL_ONREQUEST(pRI->pCI->requestNumber, &cff, sizeof(cff), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001049
1050#ifdef MEMSET_FREED
1051 memsetString(cff.number);
1052#endif
1053
1054 free (cff.number);
1055
1056#ifdef MEMSET_FREED
1057 memset(&cff, 0, sizeof(cff));
1058#endif
1059
1060 return;
1061invalid:
1062 invalidCommandBlock(pRI);
1063 return;
1064}
1065
1066
Wink Saville7f856802009-06-09 10:23:37 -07001067static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001068dispatchRaw(Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001069 int32_t len;
1070 status_t status;
1071 const void *data;
1072
1073 status = p.readInt32(&len);
1074
1075 if (status != NO_ERROR) {
1076 goto invalid;
1077 }
1078
1079 // The java code writes -1 for null arrays
1080 if (((int)len) == -1) {
1081 data = NULL;
1082 len = 0;
Wink Saville7f856802009-06-09 10:23:37 -07001083 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001084
1085 data = p.readInplace(len);
1086
1087 startRequest;
1088 appendPrintBuf("%sraw_size=%d", printBuf, len);
1089 closeRequest;
1090 printRequest(pRI->token, pRI->pCI->requestNumber);
1091
Etan Cohend3652192014-06-20 08:28:44 -07001092 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<void *>(data), len, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001093
1094 return;
1095invalid:
1096 invalidCommandBlock(pRI);
1097 return;
1098}
1099
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001100static status_t
1101constructCdmaSms(Parcel &p, RequestInfo *pRI, RIL_CDMA_SMS_Message& rcsm) {
Wink Savillef4c4d362009-04-02 01:37:03 -07001102 int32_t t;
1103 uint8_t ut;
1104 status_t status;
1105 int32_t digitCount;
1106 int digitLimit;
Wink Saville7f856802009-06-09 10:23:37 -07001107
Wink Savillef4c4d362009-04-02 01:37:03 -07001108 memset(&rcsm, 0, sizeof(rcsm));
1109
1110 status = p.readInt32(&t);
1111 rcsm.uTeleserviceID = (int) t;
1112
1113 status = p.read(&ut,sizeof(ut));
1114 rcsm.bIsServicePresent = (uint8_t) ut;
1115
1116 status = p.readInt32(&t);
1117 rcsm.uServicecategory = (int) t;
1118
1119 status = p.readInt32(&t);
1120 rcsm.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1121
1122 status = p.readInt32(&t);
1123 rcsm.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1124
1125 status = p.readInt32(&t);
1126 rcsm.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1127
1128 status = p.readInt32(&t);
1129 rcsm.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1130
1131 status = p.read(&ut,sizeof(ut));
1132 rcsm.sAddress.number_of_digits= (uint8_t) ut;
1133
1134 digitLimit= MIN((rcsm.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
1135 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1136 status = p.read(&ut,sizeof(ut));
1137 rcsm.sAddress.digits[digitCount] = (uint8_t) ut;
1138 }
1139
Wink Saville7f856802009-06-09 10:23:37 -07001140 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001141 rcsm.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1142
Wink Saville7f856802009-06-09 10:23:37 -07001143 status = p.read(&ut,sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001144 rcsm.sSubAddress.odd = (uint8_t) ut;
1145
1146 status = p.read(&ut,sizeof(ut));
1147 rcsm.sSubAddress.number_of_digits = (uint8_t) ut;
1148
1149 digitLimit= MIN((rcsm.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
Wink Saville7f856802009-06-09 10:23:37 -07001150 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1151 status = p.read(&ut,sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001152 rcsm.sSubAddress.digits[digitCount] = (uint8_t) ut;
1153 }
1154
Wink Saville7f856802009-06-09 10:23:37 -07001155 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001156 rcsm.uBearerDataLen = (int) t;
1157
1158 digitLimit= MIN((rcsm.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
Wink Saville7f856802009-06-09 10:23:37 -07001159 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1160 status = p.read(&ut, sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001161 rcsm.aBearerData[digitCount] = (uint8_t) ut;
1162 }
1163
1164 if (status != NO_ERROR) {
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001165 return status;
Wink Savillef4c4d362009-04-02 01:37:03 -07001166 }
1167
1168 startRequest;
1169 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
Wink Saville1b5fd232009-04-22 14:50:00 -07001170 sAddress.digit_mode=%d, sAddress.Number_mode=%d, sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07001171 printBuf, rcsm.uTeleserviceID,rcsm.bIsServicePresent,rcsm.uServicecategory,
Wink Saville1b5fd232009-04-22 14:50:00 -07001172 rcsm.sAddress.digit_mode, rcsm.sAddress.number_mode,rcsm.sAddress.number_type);
Wink Savillef4c4d362009-04-02 01:37:03 -07001173 closeRequest;
Wink Saville7f856802009-06-09 10:23:37 -07001174
Wink Savillef4c4d362009-04-02 01:37:03 -07001175 printRequest(pRI->token, pRI->pCI->requestNumber);
1176
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001177 return status;
1178}
1179
1180static void
1181dispatchCdmaSms(Parcel &p, RequestInfo *pRI) {
1182 RIL_CDMA_SMS_Message rcsm;
1183
Mark Salyzyndba25612015-04-09 07:18:35 -07001184 RLOGD("dispatchCdmaSms");
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001185 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1186 goto invalid;
1187 }
1188
Etan Cohend3652192014-06-20 08:28:44 -07001189 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001190
1191#ifdef MEMSET_FREED
1192 memset(&rcsm, 0, sizeof(rcsm));
1193#endif
1194
1195 return;
1196
1197invalid:
1198 invalidCommandBlock(pRI);
1199 return;
1200}
1201
Wink Saville7f856802009-06-09 10:23:37 -07001202static void
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001203dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1204 RIL_IMS_SMS_Message rism;
1205 RIL_CDMA_SMS_Message rcsm;
1206
Mark Salyzyndba25612015-04-09 07:18:35 -07001207 RLOGD("dispatchImsCdmaSms: retry=%d, messageRef=%d", retry, messageRef);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001208
1209 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1210 goto invalid;
1211 }
1212 memset(&rism, 0, sizeof(rism));
1213 rism.tech = RADIO_TECH_3GPP2;
1214 rism.retry = retry;
1215 rism.messageRef = messageRef;
1216 rism.message.cdmaMessage = &rcsm;
1217
Etan Cohend3652192014-06-20 08:28:44 -07001218 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001219 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Etan Cohend3652192014-06-20 08:28:44 -07001220 +sizeof(rcsm),pRI, pRI->socket_id);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001221
1222#ifdef MEMSET_FREED
1223 memset(&rcsm, 0, sizeof(rcsm));
1224 memset(&rism, 0, sizeof(rism));
1225#endif
1226
1227 return;
1228
1229invalid:
1230 invalidCommandBlock(pRI);
1231 return;
1232}
1233
1234static void
1235dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1236 RIL_IMS_SMS_Message rism;
1237 int32_t countStrings;
1238 status_t status;
1239 size_t datalen;
1240 char **pStrings;
Mark Salyzyndba25612015-04-09 07:18:35 -07001241 RLOGD("dispatchImsGsmSms: retry=%d, messageRef=%d", retry, messageRef);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001242
1243 status = p.readInt32 (&countStrings);
1244
1245 if (status != NO_ERROR) {
1246 goto invalid;
1247 }
1248
1249 memset(&rism, 0, sizeof(rism));
1250 rism.tech = RADIO_TECH_3GPP;
1251 rism.retry = retry;
1252 rism.messageRef = messageRef;
1253
1254 startRequest;
Etan Cohen5d891b72014-02-27 17:25:17 -08001255 appendPrintBuf("%stech=%d, retry=%d, messageRef=%d, ", printBuf,
1256 (int)rism.tech, (int)rism.retry, rism.messageRef);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001257 if (countStrings == 0) {
1258 // just some non-null pointer
1259 pStrings = (char **)alloca(sizeof(char *));
1260 datalen = 0;
1261 } else if (((int)countStrings) == -1) {
1262 pStrings = NULL;
1263 datalen = 0;
1264 } else {
1265 datalen = sizeof(char *) * countStrings;
1266
1267 pStrings = (char **)alloca(datalen);
1268
1269 for (int i = 0 ; i < countStrings ; i++) {
1270 pStrings[i] = strdupReadString(p);
1271 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
1272 }
1273 }
1274 removeLastChar;
1275 closeRequest;
1276 printRequest(pRI->token, pRI->pCI->requestNumber);
1277
1278 rism.message.gsmMessage = pStrings;
Etan Cohend3652192014-06-20 08:28:44 -07001279 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001280 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Etan Cohend3652192014-06-20 08:28:44 -07001281 +datalen, pRI, pRI->socket_id);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001282
1283 if (pStrings != NULL) {
1284 for (int i = 0 ; i < countStrings ; i++) {
1285#ifdef MEMSET_FREED
1286 memsetString (pStrings[i]);
1287#endif
1288 free(pStrings[i]);
1289 }
1290
1291#ifdef MEMSET_FREED
1292 memset(pStrings, 0, datalen);
1293#endif
1294 }
1295
1296#ifdef MEMSET_FREED
1297 memset(&rism, 0, sizeof(rism));
1298#endif
1299 return;
1300invalid:
1301 ALOGE("dispatchImsGsmSms invalid block");
1302 invalidCommandBlock(pRI);
1303 return;
1304}
1305
1306static void
1307dispatchImsSms(Parcel &p, RequestInfo *pRI) {
1308 int32_t t;
1309 status_t status = p.readInt32(&t);
1310 RIL_RadioTechnologyFamily format;
1311 uint8_t retry;
1312 int32_t messageRef;
1313
Mark Salyzyndba25612015-04-09 07:18:35 -07001314 RLOGD("dispatchImsSms");
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001315 if (status != NO_ERROR) {
1316 goto invalid;
1317 }
1318 format = (RIL_RadioTechnologyFamily) t;
1319
1320 // read retry field
1321 status = p.read(&retry,sizeof(retry));
1322 if (status != NO_ERROR) {
1323 goto invalid;
1324 }
1325 // read messageRef field
1326 status = p.read(&messageRef,sizeof(messageRef));
1327 if (status != NO_ERROR) {
1328 goto invalid;
1329 }
1330
1331 if (RADIO_TECH_3GPP == format) {
1332 dispatchImsGsmSms(p, pRI, retry, messageRef);
1333 } else if (RADIO_TECH_3GPP2 == format) {
1334 dispatchImsCdmaSms(p, pRI, retry, messageRef);
1335 } else {
1336 ALOGE("requestImsSendSMS invalid format value =%d", format);
1337 }
1338
1339 return;
1340
1341invalid:
1342 invalidCommandBlock(pRI);
1343 return;
1344}
1345
1346static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001347dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI) {
1348 RIL_CDMA_SMS_Ack rcsa;
1349 int32_t t;
1350 status_t status;
1351 int32_t digitCount;
1352
Mark Salyzyndba25612015-04-09 07:18:35 -07001353 RLOGD("dispatchCdmaSmsAck");
Wink Savillef4c4d362009-04-02 01:37:03 -07001354 memset(&rcsa, 0, sizeof(rcsa));
1355
1356 status = p.readInt32(&t);
1357 rcsa.uErrorClass = (RIL_CDMA_SMS_ErrorClass) t;
1358
1359 status = p.readInt32(&t);
1360 rcsa.uSMSCauseCode = (int) t;
1361
1362 if (status != NO_ERROR) {
1363 goto invalid;
1364 }
1365
1366 startRequest;
Wink Saville1b5fd232009-04-22 14:50:00 -07001367 appendPrintBuf("%suErrorClass=%d, uTLStatus=%d, ",
1368 printBuf, rcsa.uErrorClass, rcsa.uSMSCauseCode);
Wink Savillef4c4d362009-04-02 01:37:03 -07001369 closeRequest;
1370
1371 printRequest(pRI->token, pRI->pCI->requestNumber);
1372
Etan Cohend3652192014-06-20 08:28:44 -07001373 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsa, sizeof(rcsa),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001374
1375#ifdef MEMSET_FREED
1376 memset(&rcsa, 0, sizeof(rcsa));
1377#endif
1378
1379 return;
1380
1381invalid:
1382 invalidCommandBlock(pRI);
1383 return;
1384}
1385
Wink Savillea592eeb2009-05-22 13:26:36 -07001386static void
1387dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1388 int32_t t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001389 status_t status;
Wink Savillea592eeb2009-05-22 13:26:36 -07001390 int32_t num;
Wink Savillef4c4d362009-04-02 01:37:03 -07001391
Wink Savillea592eeb2009-05-22 13:26:36 -07001392 status = p.readInt32(&num);
Wink Savillef4c4d362009-04-02 01:37:03 -07001393 if (status != NO_ERROR) {
1394 goto invalid;
1395 }
1396
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001397 {
1398 RIL_GSM_BroadcastSmsConfigInfo gsmBci[num];
1399 RIL_GSM_BroadcastSmsConfigInfo *gsmBciPtrs[num];
Wink Savillea592eeb2009-05-22 13:26:36 -07001400
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001401 startRequest;
1402 for (int i = 0 ; i < num ; i++ ) {
1403 gsmBciPtrs[i] = &gsmBci[i];
Wink Savillef4c4d362009-04-02 01:37:03 -07001404
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001405 status = p.readInt32(&t);
1406 gsmBci[i].fromServiceId = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001407
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001408 status = p.readInt32(&t);
1409 gsmBci[i].toServiceId = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001410
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001411 status = p.readInt32(&t);
1412 gsmBci[i].fromCodeScheme = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001413
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001414 status = p.readInt32(&t);
1415 gsmBci[i].toCodeScheme = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001416
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001417 status = p.readInt32(&t);
1418 gsmBci[i].selected = (uint8_t) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001419
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001420 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId =%d, \
1421 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]", printBuf, i,
1422 gsmBci[i].fromServiceId, gsmBci[i].toServiceId,
1423 gsmBci[i].fromCodeScheme, gsmBci[i].toCodeScheme,
1424 gsmBci[i].selected);
1425 }
1426 closeRequest;
Wink Savillef4c4d362009-04-02 01:37:03 -07001427
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001428 if (status != NO_ERROR) {
1429 goto invalid;
1430 }
Wink Savillef4c4d362009-04-02 01:37:03 -07001431
Etan Cohend3652192014-06-20 08:28:44 -07001432 CALL_ONREQUEST(pRI->pCI->requestNumber,
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001433 gsmBciPtrs,
1434 num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *),
Etan Cohend3652192014-06-20 08:28:44 -07001435 pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001436
1437#ifdef MEMSET_FREED
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001438 memset(gsmBci, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo));
1439 memset(gsmBciPtrs, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *));
Wink Savillef4c4d362009-04-02 01:37:03 -07001440#endif
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001441 }
Wink Savillef4c4d362009-04-02 01:37:03 -07001442
1443 return;
1444
1445invalid:
1446 invalidCommandBlock(pRI);
1447 return;
Wink Savillea592eeb2009-05-22 13:26:36 -07001448}
Wink Savillef4c4d362009-04-02 01:37:03 -07001449
Wink Savillea592eeb2009-05-22 13:26:36 -07001450static void
1451dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1452 int32_t t;
1453 status_t status;
1454 int32_t num;
1455
1456 status = p.readInt32(&num);
1457 if (status != NO_ERROR) {
1458 goto invalid;
1459 }
1460
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001461 {
1462 RIL_CDMA_BroadcastSmsConfigInfo cdmaBci[num];
1463 RIL_CDMA_BroadcastSmsConfigInfo *cdmaBciPtrs[num];
Wink Savillea592eeb2009-05-22 13:26:36 -07001464
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001465 startRequest;
1466 for (int i = 0 ; i < num ; i++ ) {
1467 cdmaBciPtrs[i] = &cdmaBci[i];
Wink Savillea592eeb2009-05-22 13:26:36 -07001468
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001469 status = p.readInt32(&t);
1470 cdmaBci[i].service_category = (int) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001471
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001472 status = p.readInt32(&t);
1473 cdmaBci[i].language = (int) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001474
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001475 status = p.readInt32(&t);
1476 cdmaBci[i].selected = (uint8_t) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001477
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001478 appendPrintBuf("%s [%d: service_category=%d, language =%d, \
1479 entries.bSelected =%d]", printBuf, i, cdmaBci[i].service_category,
1480 cdmaBci[i].language, cdmaBci[i].selected);
1481 }
1482 closeRequest;
Wink Savillea592eeb2009-05-22 13:26:36 -07001483
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001484 if (status != NO_ERROR) {
1485 goto invalid;
1486 }
Wink Savillea592eeb2009-05-22 13:26:36 -07001487
Etan Cohend3652192014-06-20 08:28:44 -07001488 CALL_ONREQUEST(pRI->pCI->requestNumber,
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001489 cdmaBciPtrs,
1490 num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *),
Etan Cohend3652192014-06-20 08:28:44 -07001491 pRI, pRI->socket_id);
Wink Savillea592eeb2009-05-22 13:26:36 -07001492
1493#ifdef MEMSET_FREED
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001494 memset(cdmaBci, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo));
1495 memset(cdmaBciPtrs, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *));
Wink Savillea592eeb2009-05-22 13:26:36 -07001496#endif
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001497 }
Wink Savillea592eeb2009-05-22 13:26:36 -07001498
1499 return;
1500
1501invalid:
1502 invalidCommandBlock(pRI);
1503 return;
Wink Savillef4c4d362009-04-02 01:37:03 -07001504}
1505
1506static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI) {
1507 RIL_CDMA_SMS_WriteArgs rcsw;
1508 int32_t t;
1509 uint32_t ut;
1510 uint8_t uct;
1511 status_t status;
1512 int32_t digitCount;
1513
1514 memset(&rcsw, 0, sizeof(rcsw));
1515
1516 status = p.readInt32(&t);
1517 rcsw.status = t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001518
Wink Savillef4c4d362009-04-02 01:37:03 -07001519 status = p.readInt32(&t);
1520 rcsw.message.uTeleserviceID = (int) t;
1521
1522 status = p.read(&uct,sizeof(uct));
1523 rcsw.message.bIsServicePresent = (uint8_t) uct;
1524
1525 status = p.readInt32(&t);
1526 rcsw.message.uServicecategory = (int) t;
1527
1528 status = p.readInt32(&t);
1529 rcsw.message.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1530
1531 status = p.readInt32(&t);
1532 rcsw.message.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1533
1534 status = p.readInt32(&t);
1535 rcsw.message.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1536
1537 status = p.readInt32(&t);
1538 rcsw.message.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1539
1540 status = p.read(&uct,sizeof(uct));
1541 rcsw.message.sAddress.number_of_digits = (uint8_t) uct;
1542
1543 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_ADDRESS_MAX; digitCount ++) {
1544 status = p.read(&uct,sizeof(uct));
1545 rcsw.message.sAddress.digits[digitCount] = (uint8_t) uct;
1546 }
1547
Wink Savillea592eeb2009-05-22 13:26:36 -07001548 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001549 rcsw.message.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1550
Wink Savillea592eeb2009-05-22 13:26:36 -07001551 status = p.read(&uct,sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001552 rcsw.message.sSubAddress.odd = (uint8_t) uct;
1553
1554 status = p.read(&uct,sizeof(uct));
1555 rcsw.message.sSubAddress.number_of_digits = (uint8_t) uct;
1556
1557 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_SUBADDRESS_MAX; digitCount ++) {
Wink Savillea592eeb2009-05-22 13:26:36 -07001558 status = p.read(&uct,sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001559 rcsw.message.sSubAddress.digits[digitCount] = (uint8_t) uct;
1560 }
1561
Wink Savillea592eeb2009-05-22 13:26:36 -07001562 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001563 rcsw.message.uBearerDataLen = (int) t;
1564
1565 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_BEARER_DATA_MAX; digitCount ++) {
Wink Savillea592eeb2009-05-22 13:26:36 -07001566 status = p.read(&uct, sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001567 rcsw.message.aBearerData[digitCount] = (uint8_t) uct;
1568 }
1569
1570 if (status != NO_ERROR) {
1571 goto invalid;
1572 }
1573
1574 startRequest;
Wink Saville1b5fd232009-04-22 14:50:00 -07001575 appendPrintBuf("%sstatus=%d, message.uTeleserviceID=%d, message.bIsServicePresent=%d, \
1576 message.uServicecategory=%d, message.sAddress.digit_mode=%d, \
1577 message.sAddress.number_mode=%d, \
1578 message.sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07001579 printBuf, rcsw.status, rcsw.message.uTeleserviceID, rcsw.message.bIsServicePresent,
Wink Saville1b5fd232009-04-22 14:50:00 -07001580 rcsw.message.uServicecategory, rcsw.message.sAddress.digit_mode,
1581 rcsw.message.sAddress.number_mode,
1582 rcsw.message.sAddress.number_type);
Wink Savillef4c4d362009-04-02 01:37:03 -07001583 closeRequest;
1584
1585 printRequest(pRI->token, pRI->pCI->requestNumber);
1586
Etan Cohend3652192014-06-20 08:28:44 -07001587 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsw, sizeof(rcsw),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001588
1589#ifdef MEMSET_FREED
1590 memset(&rcsw, 0, sizeof(rcsw));
1591#endif
1592
1593 return;
1594
1595invalid:
1596 invalidCommandBlock(pRI);
1597 return;
1598
1599}
1600
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -07001601// For backwards compatibility in RIL_REQUEST_SETUP_DATA_CALL.
1602// Version 4 of the RIL interface adds a new PDP type parameter to support
1603// IPv6 and dual-stack PDP contexts. When dealing with a previous version of
1604// RIL, remove the parameter from the request.
1605static void dispatchDataCall(Parcel& p, RequestInfo *pRI) {
1606 // In RIL v3, REQUEST_SETUP_DATA_CALL takes 6 parameters.
1607 const int numParamsRilV3 = 6;
1608
1609 // The first bytes of the RIL parcel contain the request number and the
1610 // serial number - see processCommandBuffer(). Copy them over too.
1611 int pos = p.dataPosition();
1612
1613 int numParams = p.readInt32();
1614 if (s_callbacks.version < 4 && numParams > numParamsRilV3) {
1615 Parcel p2;
1616 p2.appendFrom(&p, 0, pos);
1617 p2.writeInt32(numParamsRilV3);
1618 for(int i = 0; i < numParamsRilV3; i++) {
1619 p2.writeString16(p.readString16());
1620 }
1621 p2.setDataPosition(pos);
1622 dispatchStrings(p2, pRI);
1623 } else {
Lorenzo Colitti57ce1f22010-09-13 12:23:50 -07001624 p.setDataPosition(pos);
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -07001625 dispatchStrings(p, pRI);
1626 }
1627}
1628
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001629// For backwards compatibility with RILs that dont support RIL_REQUEST_VOICE_RADIO_TECH.
1630// When all RILs handle this request, this function can be removed and
1631// the request can be sent directly to the RIL using dispatchVoid.
1632static void dispatchVoiceRadioTech(Parcel& p, RequestInfo *pRI) {
Etan Cohend3652192014-06-20 08:28:44 -07001633 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001634
1635 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1636 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1637 }
1638
1639 // RILs that support RADIO_STATE_ON should support this request.
1640 if (RADIO_STATE_ON == state) {
1641 dispatchVoid(p, pRI);
1642 return;
1643 }
1644
1645 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1646 // will not support this new request either and decode Voice Radio Technology
1647 // from Radio State
1648 voiceRadioTech = decodeVoiceRadioTechnology(state);
1649
1650 if (voiceRadioTech < 0)
1651 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1652 else
1653 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &voiceRadioTech, sizeof(int));
1654}
1655
1656// For backwards compatibility in RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE:.
1657// When all RILs handle this request, this function can be removed and
1658// the request can be sent directly to the RIL using dispatchVoid.
1659static void dispatchCdmaSubscriptionSource(Parcel& p, RequestInfo *pRI) {
Etan Cohend3652192014-06-20 08:28:44 -07001660 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001661
1662 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1663 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1664 }
1665
1666 // RILs that support RADIO_STATE_ON should support this request.
1667 if (RADIO_STATE_ON == state) {
1668 dispatchVoid(p, pRI);
1669 return;
1670 }
1671
1672 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1673 // will not support this new request either and decode CDMA Subscription Source
1674 // from Radio State
1675 cdmaSubscriptionSource = decodeCdmaSubscriptionSource(state);
1676
1677 if (cdmaSubscriptionSource < 0)
1678 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1679 else
1680 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &cdmaSubscriptionSource, sizeof(int));
1681}
1682
Sungmin Choi75697532013-04-26 15:04:45 -07001683static void dispatchSetInitialAttachApn(Parcel &p, RequestInfo *pRI)
1684{
1685 RIL_InitialAttachApn pf;
1686 int32_t t;
1687 status_t status;
1688
1689 memset(&pf, 0, sizeof(pf));
1690
1691 pf.apn = strdupReadString(p);
1692 pf.protocol = strdupReadString(p);
1693
1694 status = p.readInt32(&t);
1695 pf.authtype = (int) t;
1696
1697 pf.username = strdupReadString(p);
1698 pf.password = strdupReadString(p);
1699
1700 startRequest;
Etan Cohen5d891b72014-02-27 17:25:17 -08001701 appendPrintBuf("%sapn=%s, protocol=%s, authtype=%d, username=%s, password=%s",
1702 printBuf, pf.apn, pf.protocol, pf.authtype, pf.username, pf.password);
Sungmin Choi75697532013-04-26 15:04:45 -07001703 closeRequest;
1704 printRequest(pRI->token, pRI->pCI->requestNumber);
1705
1706 if (status != NO_ERROR) {
1707 goto invalid;
1708 }
Etan Cohend3652192014-06-20 08:28:44 -07001709 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
Sungmin Choi75697532013-04-26 15:04:45 -07001710
1711#ifdef MEMSET_FREED
1712 memsetString(pf.apn);
1713 memsetString(pf.protocol);
1714 memsetString(pf.username);
1715 memsetString(pf.password);
1716#endif
1717
1718 free(pf.apn);
1719 free(pf.protocol);
1720 free(pf.username);
1721 free(pf.password);
1722
1723#ifdef MEMSET_FREED
1724 memset(&pf, 0, sizeof(pf));
1725#endif
1726
1727 return;
1728invalid:
1729 invalidCommandBlock(pRI);
1730 return;
1731}
1732
Jake Hamby8a4a2332014-01-15 13:12:05 -08001733static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI) {
1734 RIL_NV_ReadItem nvri;
1735 int32_t t;
1736 status_t status;
1737
1738 memset(&nvri, 0, sizeof(nvri));
1739
1740 status = p.readInt32(&t);
1741 nvri.itemID = (RIL_NV_Item) t;
1742
1743 if (status != NO_ERROR) {
1744 goto invalid;
1745 }
1746
1747 startRequest;
1748 appendPrintBuf("%snvri.itemID=%d, ", printBuf, nvri.itemID);
1749 closeRequest;
1750
1751 printRequest(pRI->token, pRI->pCI->requestNumber);
1752
Etan Cohend3652192014-06-20 08:28:44 -07001753 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvri, sizeof(nvri), pRI, pRI->socket_id);
Jake Hamby8a4a2332014-01-15 13:12:05 -08001754
1755#ifdef MEMSET_FREED
1756 memset(&nvri, 0, sizeof(nvri));
1757#endif
1758
1759 return;
1760
1761invalid:
1762 invalidCommandBlock(pRI);
1763 return;
1764}
1765
1766static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI) {
1767 RIL_NV_WriteItem nvwi;
1768 int32_t t;
1769 status_t status;
1770
1771 memset(&nvwi, 0, sizeof(nvwi));
1772
1773 status = p.readInt32(&t);
1774 nvwi.itemID = (RIL_NV_Item) t;
1775
1776 nvwi.value = strdupReadString(p);
1777
1778 if (status != NO_ERROR || nvwi.value == NULL) {
1779 goto invalid;
1780 }
1781
1782 startRequest;
1783 appendPrintBuf("%snvwi.itemID=%d, value=%s, ", printBuf, nvwi.itemID,
1784 nvwi.value);
1785 closeRequest;
1786
1787 printRequest(pRI->token, pRI->pCI->requestNumber);
1788
Etan Cohend3652192014-06-20 08:28:44 -07001789 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvwi, sizeof(nvwi), pRI, pRI->socket_id);
Jake Hamby8a4a2332014-01-15 13:12:05 -08001790
1791#ifdef MEMSET_FREED
1792 memsetString(nvwi.value);
1793#endif
1794
1795 free(nvwi.value);
1796
1797#ifdef MEMSET_FREED
1798 memset(&nvwi, 0, sizeof(nvwi));
1799#endif
1800
1801 return;
1802
1803invalid:
1804 invalidCommandBlock(pRI);
1805 return;
1806}
1807
1808
Etan Cohend3652192014-06-20 08:28:44 -07001809static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI) {
1810 RIL_SelectUiccSub uicc_sub;
1811 status_t status;
1812 int32_t t;
1813 memset(&uicc_sub, 0, sizeof(uicc_sub));
1814
1815 status = p.readInt32(&t);
1816 if (status != NO_ERROR) {
1817 goto invalid;
1818 }
1819 uicc_sub.slot = (int) t;
1820
1821 status = p.readInt32(&t);
1822 if (status != NO_ERROR) {
1823 goto invalid;
1824 }
1825 uicc_sub.app_index = (int) t;
1826
1827 status = p.readInt32(&t);
1828 if (status != NO_ERROR) {
1829 goto invalid;
1830 }
1831 uicc_sub.sub_type = (RIL_SubscriptionType) t;
1832
1833 status = p.readInt32(&t);
1834 if (status != NO_ERROR) {
1835 goto invalid;
1836 }
1837 uicc_sub.act_status = (RIL_UiccSubActStatus) t;
1838
1839 startRequest;
1840 appendPrintBuf("slot=%d, app_index=%d, act_status = %d", uicc_sub.slot, uicc_sub.app_index,
1841 uicc_sub.act_status);
1842 RLOGD("dispatchUiccSubscription, slot=%d, app_index=%d, act_status = %d", uicc_sub.slot,
1843 uicc_sub.app_index, uicc_sub.act_status);
1844 closeRequest;
1845 printRequest(pRI->token, pRI->pCI->requestNumber);
1846
1847 CALL_ONREQUEST(pRI->pCI->requestNumber, &uicc_sub, sizeof(uicc_sub), pRI, pRI->socket_id);
1848
1849#ifdef MEMSET_FREED
1850 memset(&uicc_sub, 0, sizeof(uicc_sub));
1851#endif
1852 return;
1853
1854invalid:
1855 invalidCommandBlock(pRI);
1856 return;
1857}
1858
Amit Mahajan90530a62014-07-01 15:54:08 -07001859static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI)
1860{
1861 RIL_SimAuthentication pf;
1862 int32_t t;
1863 status_t status;
1864
1865 memset(&pf, 0, sizeof(pf));
1866
1867 status = p.readInt32(&t);
1868 pf.authContext = (int) t;
1869 pf.authData = strdupReadString(p);
1870 pf.aid = strdupReadString(p);
1871
1872 startRequest;
1873 appendPrintBuf("authContext=%s, authData=%s, aid=%s", pf.authContext, pf.authData, pf.aid);
1874 closeRequest;
1875 printRequest(pRI->token, pRI->pCI->requestNumber);
1876
1877 if (status != NO_ERROR) {
1878 goto invalid;
1879 }
1880 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
1881
1882#ifdef MEMSET_FREED
1883 memsetString(pf.authData);
1884 memsetString(pf.aid);
1885#endif
1886
1887 free(pf.authData);
1888 free(pf.aid);
1889
1890#ifdef MEMSET_FREED
1891 memset(&pf, 0, sizeof(pf));
1892#endif
1893
1894 return;
1895invalid:
1896 invalidCommandBlock(pRI);
1897 return;
1898}
1899
Amit Mahajanc796e222014-08-13 16:54:01 +00001900static void dispatchDataProfile(Parcel &p, RequestInfo *pRI) {
1901 int32_t t;
1902 status_t status;
1903 int32_t num;
1904
1905 status = p.readInt32(&num);
1906 if (status != NO_ERROR) {
1907 goto invalid;
1908 }
1909
1910 {
1911 RIL_DataProfileInfo dataProfiles[num];
1912 RIL_DataProfileInfo *dataProfilePtrs[num];
1913
1914 startRequest;
1915 for (int i = 0 ; i < num ; i++ ) {
1916 dataProfilePtrs[i] = &dataProfiles[i];
1917
1918 status = p.readInt32(&t);
1919 dataProfiles[i].profileId = (int) t;
1920
1921 dataProfiles[i].apn = strdupReadString(p);
1922 dataProfiles[i].protocol = strdupReadString(p);
1923 status = p.readInt32(&t);
1924 dataProfiles[i].authType = (int) t;
1925
1926 dataProfiles[i].user = strdupReadString(p);
1927 dataProfiles[i].password = strdupReadString(p);
1928
1929 status = p.readInt32(&t);
1930 dataProfiles[i].type = (int) t;
1931
1932 status = p.readInt32(&t);
1933 dataProfiles[i].maxConnsTime = (int) t;
1934 status = p.readInt32(&t);
1935 dataProfiles[i].maxConns = (int) t;
1936 status = p.readInt32(&t);
1937 dataProfiles[i].waitTime = (int) t;
1938
1939 status = p.readInt32(&t);
1940 dataProfiles[i].enabled = (int) t;
1941
1942 appendPrintBuf("%s [%d: profileId=%d, apn =%s, protocol =%s, authType =%d, \
1943 user =%s, password =%s, type =%d, maxConnsTime =%d, maxConns =%d, \
1944 waitTime =%d, enabled =%d]", printBuf, i, dataProfiles[i].profileId,
1945 dataProfiles[i].apn, dataProfiles[i].protocol, dataProfiles[i].authType,
1946 dataProfiles[i].user, dataProfiles[i].password, dataProfiles[i].type,
1947 dataProfiles[i].maxConnsTime, dataProfiles[i].maxConns,
1948 dataProfiles[i].waitTime, dataProfiles[i].enabled);
1949 }
1950 closeRequest;
1951 printRequest(pRI->token, pRI->pCI->requestNumber);
1952
1953 if (status != NO_ERROR) {
1954 goto invalid;
1955 }
1956 CALL_ONREQUEST(pRI->pCI->requestNumber,
1957 dataProfilePtrs,
1958 num * sizeof(RIL_DataProfileInfo *),
1959 pRI, pRI->socket_id);
1960
1961#ifdef MEMSET_FREED
1962 memset(dataProfiles, 0, num * sizeof(RIL_DataProfileInfo));
1963 memset(dataProfilePtrs, 0, num * sizeof(RIL_DataProfileInfo *));
1964#endif
1965 }
1966
1967 return;
1968
1969invalid:
1970 invalidCommandBlock(pRI);
1971 return;
1972}
1973
Wink Saville8b4e4f72014-10-17 15:01:45 -07001974static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI){
1975 RIL_RadioCapability rc;
1976 int32_t t;
1977 status_t status;
1978
1979 memset (&rc, 0, sizeof(RIL_RadioCapability));
1980
1981 status = p.readInt32(&t);
1982 rc.version = (int)t;
1983 if (status != NO_ERROR) {
1984 goto invalid;
1985 }
1986
1987 status = p.readInt32(&t);
1988 rc.session= (int)t;
1989 if (status != NO_ERROR) {
1990 goto invalid;
1991 }
1992
1993 status = p.readInt32(&t);
1994 rc.phase= (int)t;
1995 if (status != NO_ERROR) {
1996 goto invalid;
1997 }
1998
1999 status = p.readInt32(&t);
2000 rc.rat = (int)t;
2001 if (status != NO_ERROR) {
2002 goto invalid;
2003 }
2004
2005 status = readStringFromParcelInplace(p, rc.logicalModemUuid, sizeof(rc.logicalModemUuid));
2006 if (status != NO_ERROR) {
2007 goto invalid;
2008 }
2009
2010 status = p.readInt32(&t);
2011 rc.status = (int)t;
2012
2013 if (status != NO_ERROR) {
2014 goto invalid;
2015 }
2016
2017 startRequest;
2018 appendPrintBuf("%s [version:%d, session:%d, phase:%d, rat:%d, \
Legler Wu8caf06f2014-10-29 14:02:14 +08002019 logicalModemUuid:%s, status:%d", printBuf, rc.version, rc.session
2020 rc.phase, rc.rat, rc.logicalModemUuid, rc.session);
Wink Saville8b4e4f72014-10-17 15:01:45 -07002021
2022 closeRequest;
2023 printRequest(pRI->token, pRI->pCI->requestNumber);
2024
2025 CALL_ONREQUEST(pRI->pCI->requestNumber,
2026 &rc,
2027 sizeof(RIL_RadioCapability),
2028 pRI, pRI->socket_id);
2029 return;
2030invalid:
2031 invalidCommandBlock(pRI);
2032 return;
2033}
2034
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002035static int
Wink Savillef4c4d362009-04-02 01:37:03 -07002036blockingWrite(int fd, const void *buffer, size_t len) {
Wink Saville7f856802009-06-09 10:23:37 -07002037 size_t writeOffset = 0;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002038 const uint8_t *toWrite;
2039
2040 toWrite = (const uint8_t *)buffer;
2041
2042 while (writeOffset < len) {
2043 ssize_t written;
2044 do {
2045 written = write (fd, toWrite + writeOffset,
2046 len - writeOffset);
Banavathu, Srinivas Naik38884902011-07-05 20:04:25 +05302047 } while (written < 0 && ((errno == EINTR) || (errno == EAGAIN)));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002048
2049 if (written >= 0) {
2050 writeOffset += written;
2051 } else { // written < 0
Wink Saville8eb2a122012-11-19 16:05:13 -08002052 RLOGE ("RIL Response: unexpected error on write errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002053 close(fd);
2054 return -1;
2055 }
2056 }
Dheeraj Shetty27976c42014-07-02 21:27:57 +02002057 RLOGE("RIL Response bytes written:%d", writeOffset);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002058 return 0;
2059}
2060
2061static int
Etan Cohend3652192014-06-20 08:28:44 -07002062sendResponseRaw (const void *data, size_t dataSize, RIL_SOCKET_ID socket_id) {
2063 int fd = s_ril_param_socket.fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002064 int ret;
2065 uint32_t header;
Etan Cohend3652192014-06-20 08:28:44 -07002066 pthread_mutex_t * writeMutexHook = &s_writeMutex;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002067
Etan Cohend3652192014-06-20 08:28:44 -07002068 RLOGE("Send Response to %s", rilSocketIdToString(socket_id));
2069
2070#if (SIM_COUNT >= 2)
2071 if (socket_id == RIL_SOCKET_2) {
2072 fd = s_ril_param_socket2.fdCommand;
2073 writeMutexHook = &s_writeMutex_socket2;
2074 }
2075#if (SIM_COUNT >= 3)
2076 else if (socket_id == RIL_SOCKET_3) {
2077 fd = s_ril_param_socket3.fdCommand;
2078 writeMutexHook = &s_writeMutex_socket3;
2079 }
2080#endif
2081#if (SIM_COUNT >= 4)
2082 else if (socket_id == RIL_SOCKET_4) {
2083 fd = s_ril_param_socket4.fdCommand;
2084 writeMutexHook = &s_writeMutex_socket4;
2085 }
2086#endif
2087#endif
2088 if (fd < 0) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002089 return -1;
2090 }
2091
2092 if (dataSize > MAX_COMMAND_BYTES) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002093 RLOGE("RIL: packet larger than %u (%u)",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002094 MAX_COMMAND_BYTES, (unsigned int )dataSize);
2095
2096 return -1;
2097 }
Wink Saville7f856802009-06-09 10:23:37 -07002098
Etan Cohend3652192014-06-20 08:28:44 -07002099 pthread_mutex_lock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002100
2101 header = htonl(dataSize);
2102
2103 ret = blockingWrite(fd, (void *)&header, sizeof(header));
2104
2105 if (ret < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002106 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002107 return ret;
2108 }
2109
Kennyee1fadc2009-08-13 00:45:53 +08002110 ret = blockingWrite(fd, data, dataSize);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002111
2112 if (ret < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002113 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002114 return ret;
2115 }
2116
Etan Cohend3652192014-06-20 08:28:44 -07002117 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002118
2119 return 0;
2120}
2121
2122static int
Etan Cohend3652192014-06-20 08:28:44 -07002123sendResponse (Parcel &p, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002124 printResponse;
Etan Cohend3652192014-06-20 08:28:44 -07002125 return sendResponseRaw(p.data(), p.dataSize(), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002126}
2127
Mohamad Ayyash74f7e662014-04-18 11:43:28 -07002128/** response is an int* pointing to an array of ints */
Wink Saville7f856802009-06-09 10:23:37 -07002129
2130static int
Wink Savillef4c4d362009-04-02 01:37:03 -07002131responseInts(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002132 int numInts;
2133
2134 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002135 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002136 return RIL_ERRNO_INVALID_RESPONSE;
2137 }
2138 if (responselen % sizeof(int) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002139 RLOGE("responseInts: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002140 (int)responselen, (int)sizeof(int));
2141 return RIL_ERRNO_INVALID_RESPONSE;
2142 }
2143
2144 int *p_int = (int *) response;
2145
Mohamad Ayyash74f7e662014-04-18 11:43:28 -07002146 numInts = responselen / sizeof(int);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002147 p.writeInt32 (numInts);
2148
2149 /* each int*/
2150 startResponse;
2151 for (int i = 0 ; i < numInts ; i++) {
2152 appendPrintBuf("%s%d,", printBuf, p_int[i]);
2153 p.writeInt32(p_int[i]);
2154 }
2155 removeLastChar;
2156 closeResponse;
2157
2158 return 0;
2159}
2160
Wink Saville43808972011-01-13 17:39:51 -08002161/** response is a char **, pointing to an array of char *'s
2162 The parcel will begin with the version */
2163static int responseStringsWithVersion(int version, Parcel &p, void *response, size_t responselen) {
2164 p.writeInt32(version);
2165 return responseStrings(p, response, responselen);
2166}
2167
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002168/** response is a char **, pointing to an array of char *'s */
Wink Savillef4c4d362009-04-02 01:37:03 -07002169static int responseStrings(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002170 int numStrings;
Wink Saville7f856802009-06-09 10:23:37 -07002171
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002172 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002173 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002174 return RIL_ERRNO_INVALID_RESPONSE;
2175 }
2176 if (responselen % sizeof(char *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002177 RLOGE("responseStrings: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002178 (int)responselen, (int)sizeof(char *));
2179 return RIL_ERRNO_INVALID_RESPONSE;
2180 }
2181
2182 if (response == NULL) {
2183 p.writeInt32 (0);
2184 } else {
2185 char **p_cur = (char **) response;
2186
2187 numStrings = responselen / sizeof(char *);
2188 p.writeInt32 (numStrings);
2189
2190 /* each string*/
2191 startResponse;
2192 for (int i = 0 ; i < numStrings ; i++) {
2193 appendPrintBuf("%s%s,", printBuf, (char*)p_cur[i]);
2194 writeStringToParcel (p, p_cur[i]);
2195 }
2196 removeLastChar;
2197 closeResponse;
2198 }
2199 return 0;
2200}
2201
2202
2203/**
Wink Saville7f856802009-06-09 10:23:37 -07002204 * NULL strings are accepted
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002205 * FIXME currently ignores responselen
2206 */
Wink Savillef4c4d362009-04-02 01:37:03 -07002207static int responseString(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002208 /* one string only */
2209 startResponse;
2210 appendPrintBuf("%s%s", printBuf, (char*)response);
2211 closeResponse;
2212
2213 writeStringToParcel(p, (const char *)response);
2214
2215 return 0;
2216}
2217
Wink Savillef4c4d362009-04-02 01:37:03 -07002218static int responseVoid(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002219 startResponse;
2220 removeLastChar;
2221 return 0;
2222}
2223
Wink Savillef4c4d362009-04-02 01:37:03 -07002224static int responseCallList(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002225 int num;
2226
2227 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002228 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002229 return RIL_ERRNO_INVALID_RESPONSE;
2230 }
2231
2232 if (responselen % sizeof (RIL_Call *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002233 RLOGE("responseCallList: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002234 (int)responselen, (int)sizeof (RIL_Call *));
2235 return RIL_ERRNO_INVALID_RESPONSE;
2236 }
2237
2238 startResponse;
2239 /* number of call info's */
2240 num = responselen / sizeof(RIL_Call *);
2241 p.writeInt32(num);
2242
2243 for (int i = 0 ; i < num ; i++) {
2244 RIL_Call *p_cur = ((RIL_Call **) response)[i];
2245 /* each call info */
2246 p.writeInt32(p_cur->state);
2247 p.writeInt32(p_cur->index);
2248 p.writeInt32(p_cur->toa);
2249 p.writeInt32(p_cur->isMpty);
2250 p.writeInt32(p_cur->isMT);
2251 p.writeInt32(p_cur->als);
2252 p.writeInt32(p_cur->isVoice);
Wink Saville1b5fd232009-04-22 14:50:00 -07002253 p.writeInt32(p_cur->isVoicePrivacy);
2254 writeStringToParcel(p, p_cur->number);
John Wangff368742009-03-24 17:56:29 -07002255 p.writeInt32(p_cur->numberPresentation);
Wink Saville1b5fd232009-04-22 14:50:00 -07002256 writeStringToParcel(p, p_cur->name);
2257 p.writeInt32(p_cur->namePresentation);
Wink Saville3a4840b2010-04-07 13:29:58 -07002258 // Remove when partners upgrade to version 3
Wink Saville74fa3882009-12-22 15:35:41 -08002259 if ((s_callbacks.version < 3) || (p_cur->uusInfo == NULL || p_cur->uusInfo->uusData == NULL)) {
2260 p.writeInt32(0); /* UUS Information is absent */
2261 } else {
2262 RIL_UUS_Info *uusInfo = p_cur->uusInfo;
2263 p.writeInt32(1); /* UUS Information is present */
2264 p.writeInt32(uusInfo->uusType);
2265 p.writeInt32(uusInfo->uusDcs);
2266 p.writeInt32(uusInfo->uusLength);
2267 p.write(uusInfo->uusData, uusInfo->uusLength);
2268 }
Wink Saville3d54e742009-05-18 18:00:44 -07002269 appendPrintBuf("%s[id=%d,%s,toa=%d,",
John Wangff368742009-03-24 17:56:29 -07002270 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002271 p_cur->index,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002272 callStateToString(p_cur->state),
Wink Saville3d54e742009-05-18 18:00:44 -07002273 p_cur->toa);
2274 appendPrintBuf("%s%s,%s,als=%d,%s,%s,",
2275 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002276 (p_cur->isMpty)?"conf":"norm",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002277 (p_cur->isMT)?"mt":"mo",
2278 p_cur->als,
2279 (p_cur->isVoice)?"voc":"nonvoc",
Wink Saville3d54e742009-05-18 18:00:44 -07002280 (p_cur->isVoicePrivacy)?"evp":"noevp");
2281 appendPrintBuf("%s%s,cli=%d,name='%s',%d]",
2282 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002283 p_cur->number,
2284 p_cur->numberPresentation,
2285 p_cur->name,
2286 p_cur->namePresentation);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002287 }
2288 removeLastChar;
2289 closeResponse;
2290
2291 return 0;
2292}
2293
Wink Savillef4c4d362009-04-02 01:37:03 -07002294static int responseSMS(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002295 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002296 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002297 return RIL_ERRNO_INVALID_RESPONSE;
2298 }
2299
2300 if (responselen != sizeof (RIL_SMS_Response) ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002301 RLOGE("invalid response length %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002302 (int)responselen, (int)sizeof (RIL_SMS_Response));
2303 return RIL_ERRNO_INVALID_RESPONSE;
2304 }
2305
2306 RIL_SMS_Response *p_cur = (RIL_SMS_Response *) response;
2307
2308 p.writeInt32(p_cur->messageRef);
2309 writeStringToParcel(p, p_cur->ackPDU);
Jaikumar Ganesh920c78f2009-06-04 10:53:15 -07002310 p.writeInt32(p_cur->errorCode);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002311
2312 startResponse;
Jaikumar Ganesh920c78f2009-06-04 10:53:15 -07002313 appendPrintBuf("%s%d,%s,%d", printBuf, p_cur->messageRef,
2314 (char*)p_cur->ackPDU, p_cur->errorCode);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002315 closeResponse;
2316
2317 return 0;
2318}
2319
Wink Savillec0114b32011-02-18 10:14:07 -08002320static int responseDataCallListV4(Parcel &p, void *response, size_t responselen)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002321{
2322 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002323 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002324 return RIL_ERRNO_INVALID_RESPONSE;
2325 }
2326
Wink Savillec0114b32011-02-18 10:14:07 -08002327 if (responselen % sizeof(RIL_Data_Call_Response_v4) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002328 RLOGE("responseDataCallListV4: invalid response length %d expected multiple of %d",
Wink Savillec0114b32011-02-18 10:14:07 -08002329 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v4));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002330 return RIL_ERRNO_INVALID_RESPONSE;
2331 }
2332
Amit Mahajan52500162014-07-29 17:36:48 -07002333 // Write version
2334 p.writeInt32(4);
2335
Wink Savillec0114b32011-02-18 10:14:07 -08002336 int num = responselen / sizeof(RIL_Data_Call_Response_v4);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002337 p.writeInt32(num);
2338
Wink Savillec0114b32011-02-18 10:14:07 -08002339 RIL_Data_Call_Response_v4 *p_cur = (RIL_Data_Call_Response_v4 *) response;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002340 startResponse;
2341 int i;
2342 for (i = 0; i < num; i++) {
2343 p.writeInt32(p_cur[i].cid);
2344 p.writeInt32(p_cur[i].active);
2345 writeStringToParcel(p, p_cur[i].type);
Wink Savillec0114b32011-02-18 10:14:07 -08002346 // apn is not used, so don't send.
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002347 writeStringToParcel(p, p_cur[i].address);
Wink Savillec0114b32011-02-18 10:14:07 -08002348 appendPrintBuf("%s[cid=%d,%s,%s,%s],", printBuf,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002349 p_cur[i].cid,
2350 (p_cur[i].active==0)?"down":"up",
2351 (char*)p_cur[i].type,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002352 (char*)p_cur[i].address);
2353 }
2354 removeLastChar;
2355 closeResponse;
2356
2357 return 0;
2358}
2359
Etan Cohend3652192014-06-20 08:28:44 -07002360static int responseDataCallListV6(Parcel &p, void *response, size_t responselen)
2361{
Amit Mahajan52500162014-07-29 17:36:48 -07002362 if (response == NULL && responselen != 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002363 RLOGE("invalid response: NULL");
2364 return RIL_ERRNO_INVALID_RESPONSE;
2365 }
2366
2367 if (responselen % sizeof(RIL_Data_Call_Response_v6) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002368 RLOGE("responseDataCallListV6: invalid response length %d expected multiple of %d",
Etan Cohend3652192014-06-20 08:28:44 -07002369 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v6));
2370 return RIL_ERRNO_INVALID_RESPONSE;
2371 }
2372
Amit Mahajan52500162014-07-29 17:36:48 -07002373 // Write version
2374 p.writeInt32(6);
2375
Etan Cohend3652192014-06-20 08:28:44 -07002376 int num = responselen / sizeof(RIL_Data_Call_Response_v6);
2377 p.writeInt32(num);
2378
2379 RIL_Data_Call_Response_v6 *p_cur = (RIL_Data_Call_Response_v6 *) response;
2380 startResponse;
2381 int i;
2382 for (i = 0; i < num; i++) {
2383 p.writeInt32((int)p_cur[i].status);
2384 p.writeInt32(p_cur[i].suggestedRetryTime);
2385 p.writeInt32(p_cur[i].cid);
2386 p.writeInt32(p_cur[i].active);
2387 writeStringToParcel(p, p_cur[i].type);
2388 writeStringToParcel(p, p_cur[i].ifname);
2389 writeStringToParcel(p, p_cur[i].addresses);
2390 writeStringToParcel(p, p_cur[i].dnses);
2391 writeStringToParcel(p, p_cur[i].gateways);
2392 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s],", printBuf,
2393 p_cur[i].status,
2394 p_cur[i].suggestedRetryTime,
2395 p_cur[i].cid,
2396 (p_cur[i].active==0)?"down":"up",
2397 (char*)p_cur[i].type,
2398 (char*)p_cur[i].ifname,
2399 (char*)p_cur[i].addresses,
2400 (char*)p_cur[i].dnses,
2401 (char*)p_cur[i].gateways);
2402 }
2403 removeLastChar;
2404 closeResponse;
2405
2406 return 0;
2407}
2408
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002409static int responseDataCallListV9(Parcel &p, void *response, size_t responselen)
2410{
2411 if (response == NULL && responselen != 0) {
2412 RLOGE("invalid response: NULL");
2413 return RIL_ERRNO_INVALID_RESPONSE;
2414 }
2415
2416 if (responselen % sizeof(RIL_Data_Call_Response_v9) != 0) {
2417 RLOGE("responseDataCallListV9: invalid response length %d expected multiple of %d",
2418 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v9));
2419 return RIL_ERRNO_INVALID_RESPONSE;
2420 }
2421
2422 // Write version
2423 p.writeInt32(10);
2424
2425 int num = responselen / sizeof(RIL_Data_Call_Response_v9);
2426 p.writeInt32(num);
2427
2428 RIL_Data_Call_Response_v9 *p_cur = (RIL_Data_Call_Response_v9 *) response;
2429 startResponse;
2430 int i;
2431 for (i = 0; i < num; i++) {
2432 p.writeInt32((int)p_cur[i].status);
2433 p.writeInt32(p_cur[i].suggestedRetryTime);
2434 p.writeInt32(p_cur[i].cid);
2435 p.writeInt32(p_cur[i].active);
2436 writeStringToParcel(p, p_cur[i].type);
2437 writeStringToParcel(p, p_cur[i].ifname);
2438 writeStringToParcel(p, p_cur[i].addresses);
2439 writeStringToParcel(p, p_cur[i].dnses);
2440 writeStringToParcel(p, p_cur[i].gateways);
2441 writeStringToParcel(p, p_cur[i].pcscf);
2442 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s],", printBuf,
2443 p_cur[i].status,
2444 p_cur[i].suggestedRetryTime,
2445 p_cur[i].cid,
2446 (p_cur[i].active==0)?"down":"up",
2447 (char*)p_cur[i].type,
2448 (char*)p_cur[i].ifname,
2449 (char*)p_cur[i].addresses,
2450 (char*)p_cur[i].dnses,
2451 (char*)p_cur[i].gateways,
2452 (char*)p_cur[i].pcscf);
2453 }
2454 removeLastChar;
2455 closeResponse;
2456
2457 return 0;
2458}
2459
2460
Wink Saville43808972011-01-13 17:39:51 -08002461static int responseDataCallList(Parcel &p, void *response, size_t responselen)
2462{
Wink Saville43808972011-01-13 17:39:51 -08002463 if (s_callbacks.version < 5) {
Amit Mahajan52500162014-07-29 17:36:48 -07002464 RLOGD("responseDataCallList: v4");
Wink Savillec0114b32011-02-18 10:14:07 -08002465 return responseDataCallListV4(p, response, responselen);
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002466 } else if (responselen % sizeof(RIL_Data_Call_Response_v6) == 0) {
2467 return responseDataCallListV6(p, response, responselen);
2468 } else if (responselen % sizeof(RIL_Data_Call_Response_v9) == 0) {
2469 return responseDataCallListV9(p, response, responselen);
Wink Saville43808972011-01-13 17:39:51 -08002470 } else {
2471 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002472 RLOGE("invalid response: NULL");
Wink Saville43808972011-01-13 17:39:51 -08002473 return RIL_ERRNO_INVALID_RESPONSE;
2474 }
2475
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002476 if (responselen % sizeof(RIL_Data_Call_Response_v11) != 0) {
2477 RLOGE("invalid response length %d expected multiple of %d",
2478 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v11));
Wink Saville43808972011-01-13 17:39:51 -08002479 return RIL_ERRNO_INVALID_RESPONSE;
2480 }
2481
Amit Mahajan52500162014-07-29 17:36:48 -07002482 // Write version
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002483 p.writeInt32(11);
Amit Mahajan52500162014-07-29 17:36:48 -07002484
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002485 int num = responselen / sizeof(RIL_Data_Call_Response_v11);
Wink Saville43808972011-01-13 17:39:51 -08002486 p.writeInt32(num);
2487
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002488 RIL_Data_Call_Response_v11 *p_cur = (RIL_Data_Call_Response_v11 *) response;
Wink Saville43808972011-01-13 17:39:51 -08002489 startResponse;
2490 int i;
2491 for (i = 0; i < num; i++) {
2492 p.writeInt32((int)p_cur[i].status);
Kazuhiro Ondobeb25b52011-06-17 16:26:45 -05002493 p.writeInt32(p_cur[i].suggestedRetryTime);
Wink Saville43808972011-01-13 17:39:51 -08002494 p.writeInt32(p_cur[i].cid);
2495 p.writeInt32(p_cur[i].active);
David 'Digit' Turneraf1298d2011-02-04 13:36:47 +01002496 writeStringToParcel(p, p_cur[i].type);
Wink Saville43808972011-01-13 17:39:51 -08002497 writeStringToParcel(p, p_cur[i].ifname);
2498 writeStringToParcel(p, p_cur[i].addresses);
2499 writeStringToParcel(p, p_cur[i].dnses);
Wink Savillec0114b32011-02-18 10:14:07 -08002500 writeStringToParcel(p, p_cur[i].gateways);
Etan Cohend3652192014-06-20 08:28:44 -07002501 writeStringToParcel(p, p_cur[i].pcscf);
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002502 p.writeInt32(p_cur[i].mtu);
2503 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s,mtu=%d],", printBuf,
Wink Saville43808972011-01-13 17:39:51 -08002504 p_cur[i].status,
Kazuhiro Ondobeb25b52011-06-17 16:26:45 -05002505 p_cur[i].suggestedRetryTime,
Wink Saville43808972011-01-13 17:39:51 -08002506 p_cur[i].cid,
2507 (p_cur[i].active==0)?"down":"up",
Naveen Kalla56384152011-11-16 11:12:37 -08002508 (char*)p_cur[i].type,
Wink Saville43808972011-01-13 17:39:51 -08002509 (char*)p_cur[i].ifname,
2510 (char*)p_cur[i].addresses,
Wink Savillec0114b32011-02-18 10:14:07 -08002511 (char*)p_cur[i].dnses,
Etan Cohend3652192014-06-20 08:28:44 -07002512 (char*)p_cur[i].gateways,
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002513 (char*)p_cur[i].pcscf,
2514 p_cur[i].mtu);
Wink Saville43808972011-01-13 17:39:51 -08002515 }
2516 removeLastChar;
2517 closeResponse;
2518 }
2519
2520 return 0;
2521}
2522
2523static int responseSetupDataCall(Parcel &p, void *response, size_t responselen)
2524{
2525 if (s_callbacks.version < 5) {
2526 return responseStringsWithVersion(s_callbacks.version, p, response, responselen);
2527 } else {
2528 return responseDataCallList(p, response, responselen);
2529 }
2530}
2531
Wink Savillef4c4d362009-04-02 01:37:03 -07002532static int responseRaw(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002533 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002534 RLOGE("invalid response: NULL with responselen != 0");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002535 return RIL_ERRNO_INVALID_RESPONSE;
2536 }
2537
2538 // The java code reads -1 size as null byte array
2539 if (response == NULL) {
Wink Saville7f856802009-06-09 10:23:37 -07002540 p.writeInt32(-1);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002541 } else {
2542 p.writeInt32(responselen);
2543 p.write(response, responselen);
2544 }
2545
2546 return 0;
2547}
2548
2549
Wink Savillef4c4d362009-04-02 01:37:03 -07002550static int responseSIM_IO(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002551 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002552 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002553 return RIL_ERRNO_INVALID_RESPONSE;
2554 }
2555
2556 if (responselen != sizeof (RIL_SIM_IO_Response) ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002557 RLOGE("invalid response length was %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002558 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
2559 return RIL_ERRNO_INVALID_RESPONSE;
2560 }
2561
2562 RIL_SIM_IO_Response *p_cur = (RIL_SIM_IO_Response *) response;
2563 p.writeInt32(p_cur->sw1);
2564 p.writeInt32(p_cur->sw2);
2565 writeStringToParcel(p, p_cur->simResponse);
2566
2567 startResponse;
2568 appendPrintBuf("%ssw1=0x%X,sw2=0x%X,%s", printBuf, p_cur->sw1, p_cur->sw2,
2569 (char*)p_cur->simResponse);
2570 closeResponse;
2571
2572
2573 return 0;
2574}
2575
Wink Savillef4c4d362009-04-02 01:37:03 -07002576static int responseCallForwards(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002577 int num;
Wink Saville7f856802009-06-09 10:23:37 -07002578
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002579 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002580 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002581 return RIL_ERRNO_INVALID_RESPONSE;
2582 }
2583
2584 if (responselen % sizeof(RIL_CallForwardInfo *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002585 RLOGE("responseCallForwards: invalid response length %d expected multiple of %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002586 (int)responselen, (int)sizeof(RIL_CallForwardInfo *));
2587 return RIL_ERRNO_INVALID_RESPONSE;
2588 }
2589
2590 /* number of call info's */
2591 num = responselen / sizeof(RIL_CallForwardInfo *);
2592 p.writeInt32(num);
2593
2594 startResponse;
2595 for (int i = 0 ; i < num ; i++) {
2596 RIL_CallForwardInfo *p_cur = ((RIL_CallForwardInfo **) response)[i];
2597
2598 p.writeInt32(p_cur->status);
2599 p.writeInt32(p_cur->reason);
2600 p.writeInt32(p_cur->serviceClass);
2601 p.writeInt32(p_cur->toa);
2602 writeStringToParcel(p, p_cur->number);
2603 p.writeInt32(p_cur->timeSeconds);
2604 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
2605 (p_cur->status==1)?"enable":"disable",
2606 p_cur->reason, p_cur->serviceClass, p_cur->toa,
2607 (char*)p_cur->number,
2608 p_cur->timeSeconds);
2609 }
2610 removeLastChar;
2611 closeResponse;
Wink Saville7f856802009-06-09 10:23:37 -07002612
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002613 return 0;
2614}
2615
Wink Savillef4c4d362009-04-02 01:37:03 -07002616static int responseSsn(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002617 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002618 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002619 return RIL_ERRNO_INVALID_RESPONSE;
2620 }
2621
2622 if (responselen != sizeof(RIL_SuppSvcNotification)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002623 RLOGE("invalid response length was %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002624 (int)responselen, (int)sizeof (RIL_SuppSvcNotification));
2625 return RIL_ERRNO_INVALID_RESPONSE;
2626 }
2627
2628 RIL_SuppSvcNotification *p_cur = (RIL_SuppSvcNotification *) response;
2629 p.writeInt32(p_cur->notificationType);
2630 p.writeInt32(p_cur->code);
2631 p.writeInt32(p_cur->index);
2632 p.writeInt32(p_cur->type);
2633 writeStringToParcel(p, p_cur->number);
2634
2635 startResponse;
2636 appendPrintBuf("%s%s,code=%d,id=%d,type=%d,%s", printBuf,
2637 (p_cur->notificationType==0)?"mo":"mt",
2638 p_cur->code, p_cur->index, p_cur->type,
2639 (char*)p_cur->number);
2640 closeResponse;
2641
2642 return 0;
2643}
2644
Wink Saville3d54e742009-05-18 18:00:44 -07002645static int responseCellList(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002646 int num;
2647
2648 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002649 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002650 return RIL_ERRNO_INVALID_RESPONSE;
2651 }
2652
2653 if (responselen % sizeof (RIL_NeighboringCell *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002654 RLOGE("responseCellList: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002655 (int)responselen, (int)sizeof (RIL_NeighboringCell *));
2656 return RIL_ERRNO_INVALID_RESPONSE;
2657 }
2658
2659 startResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002660 /* number of records */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002661 num = responselen / sizeof(RIL_NeighboringCell *);
2662 p.writeInt32(num);
2663
2664 for (int i = 0 ; i < num ; i++) {
2665 RIL_NeighboringCell *p_cur = ((RIL_NeighboringCell **) response)[i];
2666
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002667 p.writeInt32(p_cur->rssi);
2668 writeStringToParcel (p, p_cur->cid);
2669
2670 appendPrintBuf("%s[cid=%s,rssi=%d],", printBuf,
2671 p_cur->cid, p_cur->rssi);
2672 }
2673 removeLastChar;
2674 closeResponse;
2675
2676 return 0;
2677}
2678
Wink Saville3d54e742009-05-18 18:00:44 -07002679/**
2680 * Marshall the signalInfoRecord into the parcel if it exists.
2681 */
Wink Savillea592eeb2009-05-22 13:26:36 -07002682static void marshallSignalInfoRecord(Parcel &p,
2683 RIL_CDMA_SignalInfoRecord &p_signalInfoRecord) {
Wink Saville3d54e742009-05-18 18:00:44 -07002684 p.writeInt32(p_signalInfoRecord.isPresent);
2685 p.writeInt32(p_signalInfoRecord.signalType);
2686 p.writeInt32(p_signalInfoRecord.alertPitch);
2687 p.writeInt32(p_signalInfoRecord.signal);
2688}
2689
Wink Savillea592eeb2009-05-22 13:26:36 -07002690static int responseCdmaInformationRecords(Parcel &p,
2691 void *response, size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07002692 int num;
Wink Savillea592eeb2009-05-22 13:26:36 -07002693 char* string8 = NULL;
2694 int buffer_lenght;
2695 RIL_CDMA_InformationRecord *infoRec;
Wink Saville3d54e742009-05-18 18:00:44 -07002696
2697 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002698 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002699 return RIL_ERRNO_INVALID_RESPONSE;
2700 }
2701
Wink Savillea592eeb2009-05-22 13:26:36 -07002702 if (responselen != sizeof (RIL_CDMA_InformationRecords)) {
Amit Mahajan52500162014-07-29 17:36:48 -07002703 RLOGE("responseCdmaInformationRecords: invalid response length %d expected multiple of %d\n",
Wink Savillea592eeb2009-05-22 13:26:36 -07002704 (int)responselen, (int)sizeof (RIL_CDMA_InformationRecords *));
Wink Saville3d54e742009-05-18 18:00:44 -07002705 return RIL_ERRNO_INVALID_RESPONSE;
2706 }
2707
Wink Savillea592eeb2009-05-22 13:26:36 -07002708 RIL_CDMA_InformationRecords *p_cur =
2709 (RIL_CDMA_InformationRecords *) response;
2710 num = MIN(p_cur->numberOfInfoRecs, RIL_CDMA_MAX_NUMBER_OF_INFO_RECS);
Wink Saville3d54e742009-05-18 18:00:44 -07002711
2712 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07002713 p.writeInt32(num);
Wink Saville3d54e742009-05-18 18:00:44 -07002714
Wink Savillea592eeb2009-05-22 13:26:36 -07002715 for (int i = 0 ; i < num ; i++) {
2716 infoRec = &p_cur->infoRec[i];
2717 p.writeInt32(infoRec->name);
2718 switch (infoRec->name) {
Wink Saville3d54e742009-05-18 18:00:44 -07002719 case RIL_CDMA_DISPLAY_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002720 case RIL_CDMA_EXTENDED_DISPLAY_INFO_REC:
2721 if (infoRec->rec.display.alpha_len >
2722 CDMA_ALPHA_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002723 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002724 expected not more than %d\n",
2725 (int)infoRec->rec.display.alpha_len,
2726 CDMA_ALPHA_INFO_BUFFER_LENGTH);
2727 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002728 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002729 string8 = (char*) malloc((infoRec->rec.display.alpha_len + 1)
2730 * sizeof(char) );
2731 for (int i = 0 ; i < infoRec->rec.display.alpha_len ; i++) {
2732 string8[i] = infoRec->rec.display.alpha_buf[i];
2733 }
Wink Saville43808972011-01-13 17:39:51 -08002734 string8[(int)infoRec->rec.display.alpha_len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002735 writeStringToParcel(p, (const char*)string8);
2736 free(string8);
2737 string8 = NULL;
Wink Saville3d54e742009-05-18 18:00:44 -07002738 break;
2739 case RIL_CDMA_CALLED_PARTY_NUMBER_INFO_REC:
Wink Saville3d54e742009-05-18 18:00:44 -07002740 case RIL_CDMA_CALLING_PARTY_NUMBER_INFO_REC:
Wink Saville3d54e742009-05-18 18:00:44 -07002741 case RIL_CDMA_CONNECTED_NUMBER_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002742 if (infoRec->rec.number.len > CDMA_NUMBER_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002743 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002744 expected not more than %d\n",
2745 (int)infoRec->rec.number.len,
2746 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2747 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002748 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002749 string8 = (char*) malloc((infoRec->rec.number.len + 1)
2750 * sizeof(char) );
2751 for (int i = 0 ; i < infoRec->rec.number.len; i++) {
2752 string8[i] = infoRec->rec.number.buf[i];
2753 }
Wink Saville43808972011-01-13 17:39:51 -08002754 string8[(int)infoRec->rec.number.len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002755 writeStringToParcel(p, (const char*)string8);
2756 free(string8);
2757 string8 = NULL;
2758 p.writeInt32(infoRec->rec.number.number_type);
2759 p.writeInt32(infoRec->rec.number.number_plan);
2760 p.writeInt32(infoRec->rec.number.pi);
2761 p.writeInt32(infoRec->rec.number.si);
Wink Saville3d54e742009-05-18 18:00:44 -07002762 break;
2763 case RIL_CDMA_SIGNAL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002764 p.writeInt32(infoRec->rec.signal.isPresent);
2765 p.writeInt32(infoRec->rec.signal.signalType);
2766 p.writeInt32(infoRec->rec.signal.alertPitch);
2767 p.writeInt32(infoRec->rec.signal.signal);
2768
2769 appendPrintBuf("%sisPresent=%X, signalType=%X, \
2770 alertPitch=%X, signal=%X, ",
2771 printBuf, (int)infoRec->rec.signal.isPresent,
2772 (int)infoRec->rec.signal.signalType,
2773 (int)infoRec->rec.signal.alertPitch,
2774 (int)infoRec->rec.signal.signal);
2775 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002776 break;
2777 case RIL_CDMA_REDIRECTING_NUMBER_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002778 if (infoRec->rec.redir.redirectingNumber.len >
2779 CDMA_NUMBER_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002780 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002781 expected not more than %d\n",
2782 (int)infoRec->rec.redir.redirectingNumber.len,
2783 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2784 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002785 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002786 string8 = (char*) malloc((infoRec->rec.redir.redirectingNumber
2787 .len + 1) * sizeof(char) );
2788 for (int i = 0;
2789 i < infoRec->rec.redir.redirectingNumber.len;
2790 i++) {
2791 string8[i] = infoRec->rec.redir.redirectingNumber.buf[i];
2792 }
Wink Saville43808972011-01-13 17:39:51 -08002793 string8[(int)infoRec->rec.redir.redirectingNumber.len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002794 writeStringToParcel(p, (const char*)string8);
2795 free(string8);
2796 string8 = NULL;
2797 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_type);
2798 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_plan);
2799 p.writeInt32(infoRec->rec.redir.redirectingNumber.pi);
2800 p.writeInt32(infoRec->rec.redir.redirectingNumber.si);
2801 p.writeInt32(infoRec->rec.redir.redirectingReason);
Wink Saville3d54e742009-05-18 18:00:44 -07002802 break;
2803 case RIL_CDMA_LINE_CONTROL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002804 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPolarityIncluded);
2805 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlToggle);
2806 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlReverse);
2807 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2808
2809 appendPrintBuf("%slineCtrlPolarityIncluded=%d, \
2810 lineCtrlToggle=%d, lineCtrlReverse=%d, \
2811 lineCtrlPowerDenial=%d, ", printBuf,
2812 (int)infoRec->rec.lineCtrl.lineCtrlPolarityIncluded,
2813 (int)infoRec->rec.lineCtrl.lineCtrlToggle,
2814 (int)infoRec->rec.lineCtrl.lineCtrlReverse,
2815 (int)infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2816 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002817 break;
2818 case RIL_CDMA_T53_CLIR_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002819 p.writeInt32((int)(infoRec->rec.clir.cause));
Wink Saville3d54e742009-05-18 18:00:44 -07002820
Wink Savillea592eeb2009-05-22 13:26:36 -07002821 appendPrintBuf("%scause%d", printBuf, infoRec->rec.clir.cause);
2822 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002823 break;
2824 case RIL_CDMA_T53_AUDIO_CONTROL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002825 p.writeInt32(infoRec->rec.audioCtrl.upLink);
2826 p.writeInt32(infoRec->rec.audioCtrl.downLink);
2827
2828 appendPrintBuf("%supLink=%d, downLink=%d, ", printBuf,
2829 infoRec->rec.audioCtrl.upLink,
2830 infoRec->rec.audioCtrl.downLink);
2831 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002832 break;
Wink Savillea592eeb2009-05-22 13:26:36 -07002833 case RIL_CDMA_T53_RELEASE_INFO_REC:
2834 // TODO(Moto): See David Krause, he has the answer:)
Wink Saville8eb2a122012-11-19 16:05:13 -08002835 RLOGE("RIL_CDMA_T53_RELEASE_INFO_REC: return INVALID_RESPONSE");
Wink Savillea592eeb2009-05-22 13:26:36 -07002836 return RIL_ERRNO_INVALID_RESPONSE;
2837 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08002838 RLOGE("Incorrect name value");
Wink Savillea592eeb2009-05-22 13:26:36 -07002839 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002840 }
2841 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002842 closeResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002843
Wink Savillea592eeb2009-05-22 13:26:36 -07002844 return 0;
Wink Saville3d54e742009-05-18 18:00:44 -07002845}
2846
Wink Savillea592eeb2009-05-22 13:26:36 -07002847static int responseRilSignalStrength(Parcel &p,
2848 void *response, size_t responselen) {
2849 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002850 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002851 return RIL_ERRNO_INVALID_RESPONSE;
2852 }
2853
Wink Savillec0114b32011-02-18 10:14:07 -08002854 if (responselen >= sizeof (RIL_SignalStrength_v5)) {
Etan Cohend3652192014-06-20 08:28:44 -07002855 RIL_SignalStrength_v10 *p_cur = ((RIL_SignalStrength_v10 *) response);
Wink Saville3d54e742009-05-18 18:00:44 -07002856
Wink Saville3d54e742009-05-18 18:00:44 -07002857 p.writeInt32(p_cur->GW_SignalStrength.signalStrength);
2858 p.writeInt32(p_cur->GW_SignalStrength.bitErrorRate);
2859 p.writeInt32(p_cur->CDMA_SignalStrength.dbm);
2860 p.writeInt32(p_cur->CDMA_SignalStrength.ecio);
2861 p.writeInt32(p_cur->EVDO_SignalStrength.dbm);
2862 p.writeInt32(p_cur->EVDO_SignalStrength.ecio);
2863 p.writeInt32(p_cur->EVDO_SignalStrength.signalNoiseRatio);
Wink Savillec0114b32011-02-18 10:14:07 -08002864 if (responselen >= sizeof (RIL_SignalStrength_v6)) {
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002865 /*
Wink Saville18e4ab12013-04-07 17:31:04 -07002866 * Fixup LTE for backwards compatibility
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002867 */
Wink Saville18e4ab12013-04-07 17:31:04 -07002868 if (s_callbacks.version <= 6) {
2869 // signalStrength: -1 -> 99
2870 if (p_cur->LTE_SignalStrength.signalStrength == -1) {
2871 p_cur->LTE_SignalStrength.signalStrength = 99;
2872 }
2873 // rsrp: -1 -> INT_MAX all other negative value to positive.
2874 // So remap here
2875 if (p_cur->LTE_SignalStrength.rsrp == -1) {
2876 p_cur->LTE_SignalStrength.rsrp = INT_MAX;
2877 } else if (p_cur->LTE_SignalStrength.rsrp < -1) {
2878 p_cur->LTE_SignalStrength.rsrp = -p_cur->LTE_SignalStrength.rsrp;
2879 }
2880 // rsrq: -1 -> INT_MAX
2881 if (p_cur->LTE_SignalStrength.rsrq == -1) {
2882 p_cur->LTE_SignalStrength.rsrq = INT_MAX;
2883 }
2884 // Not remapping rssnr is already using INT_MAX
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002885
Wink Saville18e4ab12013-04-07 17:31:04 -07002886 // cqi: -1 -> INT_MAX
2887 if (p_cur->LTE_SignalStrength.cqi == -1) {
2888 p_cur->LTE_SignalStrength.cqi = INT_MAX;
2889 }
2890 }
2891 p.writeInt32(p_cur->LTE_SignalStrength.signalStrength);
Wink Savillec0114b32011-02-18 10:14:07 -08002892 p.writeInt32(p_cur->LTE_SignalStrength.rsrp);
2893 p.writeInt32(p_cur->LTE_SignalStrength.rsrq);
2894 p.writeInt32(p_cur->LTE_SignalStrength.rssnr);
2895 p.writeInt32(p_cur->LTE_SignalStrength.cqi);
Etan Cohend3652192014-06-20 08:28:44 -07002896 if (responselen >= sizeof (RIL_SignalStrength_v10)) {
2897 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
2898 } else {
2899 p.writeInt32(INT_MAX);
2900 }
Wink Savillec0114b32011-02-18 10:14:07 -08002901 } else {
Wink Saville18e4ab12013-04-07 17:31:04 -07002902 p.writeInt32(99);
2903 p.writeInt32(INT_MAX);
2904 p.writeInt32(INT_MAX);
2905 p.writeInt32(INT_MAX);
2906 p.writeInt32(INT_MAX);
Etan Cohend3652192014-06-20 08:28:44 -07002907 p.writeInt32(INT_MAX);
Wink Savillec0114b32011-02-18 10:14:07 -08002908 }
johnwangfdf825f2009-05-22 15:50:34 -07002909
2910 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07002911 appendPrintBuf("%s[signalStrength=%d,bitErrorRate=%d,\
Wink Savillec0114b32011-02-18 10:14:07 -08002912 CDMA_SS.dbm=%d,CDMA_SSecio=%d,\
2913 EVDO_SS.dbm=%d,EVDO_SS.ecio=%d,\
2914 EVDO_SS.signalNoiseRatio=%d,\
2915 LTE_SS.signalStrength=%d,LTE_SS.rsrp=%d,LTE_SS.rsrq=%d,\
Etan Cohend3652192014-06-20 08:28:44 -07002916 LTE_SS.rssnr=%d,LTE_SS.cqi=%d,TDSCDMA_SS.rscp=%d]",
Wink Savillea592eeb2009-05-22 13:26:36 -07002917 printBuf,
2918 p_cur->GW_SignalStrength.signalStrength,
2919 p_cur->GW_SignalStrength.bitErrorRate,
2920 p_cur->CDMA_SignalStrength.dbm,
2921 p_cur->CDMA_SignalStrength.ecio,
2922 p_cur->EVDO_SignalStrength.dbm,
2923 p_cur->EVDO_SignalStrength.ecio,
Wink Savillec0114b32011-02-18 10:14:07 -08002924 p_cur->EVDO_SignalStrength.signalNoiseRatio,
2925 p_cur->LTE_SignalStrength.signalStrength,
2926 p_cur->LTE_SignalStrength.rsrp,
2927 p_cur->LTE_SignalStrength.rsrq,
2928 p_cur->LTE_SignalStrength.rssnr,
Etan Cohend3652192014-06-20 08:28:44 -07002929 p_cur->LTE_SignalStrength.cqi,
2930 p_cur->TD_SCDMA_SignalStrength.rscp);
Wink Savillea592eeb2009-05-22 13:26:36 -07002931 closeResponse;
2932
Wink Saville3d54e742009-05-18 18:00:44 -07002933 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08002934 RLOGE("invalid response length");
Wink Saville3d54e742009-05-18 18:00:44 -07002935 return RIL_ERRNO_INVALID_RESPONSE;
2936 }
2937
Wink Saville3d54e742009-05-18 18:00:44 -07002938 return 0;
2939}
2940
2941static int responseCallRing(Parcel &p, void *response, size_t responselen) {
2942 if ((response == NULL) || (responselen == 0)) {
2943 return responseVoid(p, response, responselen);
2944 } else {
2945 return responseCdmaSignalInfoRecord(p, response, responselen);
2946 }
2947}
2948
2949static int responseCdmaSignalInfoRecord(Parcel &p, void *response, size_t responselen) {
2950 if (response == NULL || responselen == 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002951 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002952 return RIL_ERRNO_INVALID_RESPONSE;
2953 }
2954
2955 if (responselen != sizeof (RIL_CDMA_SignalInfoRecord)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002956 RLOGE("invalid response length %d expected sizeof (RIL_CDMA_SignalInfoRecord) of %d\n",
Wink Saville3d54e742009-05-18 18:00:44 -07002957 (int)responselen, (int)sizeof (RIL_CDMA_SignalInfoRecord));
2958 return RIL_ERRNO_INVALID_RESPONSE;
2959 }
2960
2961 startResponse;
2962
2963 RIL_CDMA_SignalInfoRecord *p_cur = ((RIL_CDMA_SignalInfoRecord *) response);
2964 marshallSignalInfoRecord(p, *p_cur);
2965
2966 appendPrintBuf("%s[isPresent=%d,signalType=%d,alertPitch=%d\
2967 signal=%d]",
2968 printBuf,
2969 p_cur->isPresent,
2970 p_cur->signalType,
2971 p_cur->alertPitch,
2972 p_cur->signal);
2973
2974 closeResponse;
2975 return 0;
2976}
2977
Wink Savillea592eeb2009-05-22 13:26:36 -07002978static int responseCdmaCallWaiting(Parcel &p, void *response,
2979 size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07002980 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002981 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002982 return RIL_ERRNO_INVALID_RESPONSE;
2983 }
2984
Wink Savillec0114b32011-02-18 10:14:07 -08002985 if (responselen < sizeof(RIL_CDMA_CallWaiting_v6)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002986 RLOGW("Upgrade to ril version %d\n", RIL_VERSION);
Wink Savillec0114b32011-02-18 10:14:07 -08002987 }
2988
2989 RIL_CDMA_CallWaiting_v6 *p_cur = ((RIL_CDMA_CallWaiting_v6 *) response);
2990
2991 writeStringToParcel(p, p_cur->number);
2992 p.writeInt32(p_cur->numberPresentation);
2993 writeStringToParcel(p, p_cur->name);
2994 marshallSignalInfoRecord(p, p_cur->signalInfoRecord);
2995
2996 if (responselen >= sizeof(RIL_CDMA_CallWaiting_v6)) {
2997 p.writeInt32(p_cur->number_type);
2998 p.writeInt32(p_cur->number_plan);
2999 } else {
3000 p.writeInt32(0);
3001 p.writeInt32(0);
Wink Saville3d54e742009-05-18 18:00:44 -07003002 }
3003
3004 startResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07003005 appendPrintBuf("%snumber=%s,numberPresentation=%d, name=%s,\
3006 signalInfoRecord[isPresent=%d,signalType=%d,alertPitch=%d\
Wink Savillec0114b32011-02-18 10:14:07 -08003007 signal=%d,number_type=%d,number_plan=%d]",
Wink Saville3d54e742009-05-18 18:00:44 -07003008 printBuf,
3009 p_cur->number,
3010 p_cur->numberPresentation,
3011 p_cur->name,
3012 p_cur->signalInfoRecord.isPresent,
3013 p_cur->signalInfoRecord.signalType,
3014 p_cur->signalInfoRecord.alertPitch,
Wink Savillec0114b32011-02-18 10:14:07 -08003015 p_cur->signalInfoRecord.signal,
3016 p_cur->number_type,
3017 p_cur->number_plan);
Wink Saville3d54e742009-05-18 18:00:44 -07003018 closeResponse;
3019
3020 return 0;
3021}
3022
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003023static int responseSimRefresh(Parcel &p, void *response, size_t responselen) {
3024 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003025 RLOGE("responseSimRefresh: invalid response: NULL");
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003026 return RIL_ERRNO_INVALID_RESPONSE;
3027 }
3028
3029 startResponse;
3030 if (s_callbacks.version == 7) {
3031 RIL_SimRefreshResponse_v7 *p_cur = ((RIL_SimRefreshResponse_v7 *) response);
3032 p.writeInt32(p_cur->result);
3033 p.writeInt32(p_cur->ef_id);
3034 writeStringToParcel(p, p_cur->aid);
3035
3036 appendPrintBuf("%sresult=%d, ef_id=%d, aid=%s",
3037 printBuf,
3038 p_cur->result,
3039 p_cur->ef_id,
3040 p_cur->aid);
3041 } else {
3042 int *p_cur = ((int *) response);
3043 p.writeInt32(p_cur[0]);
3044 p.writeInt32(p_cur[1]);
3045 writeStringToParcel(p, NULL);
3046
3047 appendPrintBuf("%sresult=%d, ef_id=%d",
3048 printBuf,
3049 p_cur[0],
3050 p_cur[1]);
3051 }
3052 closeResponse;
3053
3054 return 0;
3055}
3056
Wink Saville8a9e0212013-04-09 12:11:38 -07003057static int responseCellInfoList(Parcel &p, void *response, size_t responselen)
3058{
3059 if (response == NULL && responselen != 0) {
3060 RLOGE("invalid response: NULL");
3061 return RIL_ERRNO_INVALID_RESPONSE;
3062 }
3063
3064 if (responselen % sizeof(RIL_CellInfo) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07003065 RLOGE("responseCellInfoList: invalid response length %d expected multiple of %d",
Wink Saville8a9e0212013-04-09 12:11:38 -07003066 (int)responselen, (int)sizeof(RIL_CellInfo));
3067 return RIL_ERRNO_INVALID_RESPONSE;
3068 }
3069
3070 int num = responselen / sizeof(RIL_CellInfo);
3071 p.writeInt32(num);
3072
3073 RIL_CellInfo *p_cur = (RIL_CellInfo *) response;
3074 startResponse;
3075 int i;
3076 for (i = 0; i < num; i++) {
3077 appendPrintBuf("%s[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", printBuf, i,
3078 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
3079 p.writeInt32((int)p_cur->cellInfoType);
3080 p.writeInt32(p_cur->registered);
3081 p.writeInt32(p_cur->timeStampType);
3082 p.writeInt64(p_cur->timeStamp);
3083 switch(p_cur->cellInfoType) {
3084 case RIL_CELL_INFO_TYPE_GSM: {
Wink Savillec57b3eb2013-04-17 12:51:41 -07003085 appendPrintBuf("%s GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,", printBuf,
Wink Saville8a9e0212013-04-09 12:11:38 -07003086 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
3087 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
3088 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
Wink Savillec57b3eb2013-04-17 12:51:41 -07003089 p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3090 appendPrintBuf("%s gsmSS: ss=%d,ber=%d],", printBuf,
Wink Saville8a9e0212013-04-09 12:11:38 -07003091 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
3092 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3093
3094 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
3095 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
3096 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
3097 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
Wink Saville8a9e0212013-04-09 12:11:38 -07003098 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
3099 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3100 break;
3101 }
Wink Savillec57b3eb2013-04-17 12:51:41 -07003102 case RIL_CELL_INFO_TYPE_WCDMA: {
3103 appendPrintBuf("%s WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,", printBuf,
3104 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
3105 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
3106 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
3107 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
3108 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3109 appendPrintBuf("%s wcdmaSS: ss=%d,ber=%d],", printBuf,
3110 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
3111 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3112
3113 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
3114 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
3115 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
3116 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
3117 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3118 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
3119 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3120 break;
3121 }
Wink Saville8a9e0212013-04-09 12:11:38 -07003122 case RIL_CELL_INFO_TYPE_CDMA: {
3123 appendPrintBuf("%s CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d", printBuf,
3124 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
3125 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
3126 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
3127 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
3128 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3129
3130 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
3131 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
3132 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
3133 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
3134 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3135
3136 appendPrintBuf("%s cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d", printBuf,
3137 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
3138 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
3139 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
3140 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
3141 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3142
3143 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
3144 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
3145 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
3146 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
3147 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3148 break;
3149 }
3150 case RIL_CELL_INFO_TYPE_LTE: {
3151 appendPrintBuf("%s LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d", printBuf,
3152 p_cur->CellInfo.lte.cellIdentityLte.mcc,
3153 p_cur->CellInfo.lte.cellIdentityLte.mnc,
3154 p_cur->CellInfo.lte.cellIdentityLte.ci,
3155 p_cur->CellInfo.lte.cellIdentityLte.pci,
3156 p_cur->CellInfo.lte.cellIdentityLte.tac);
3157
3158 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
3159 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
3160 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
3161 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
3162 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
3163
3164 appendPrintBuf("%s lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d", printBuf,
3165 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
3166 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
3167 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
3168 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
3169 p_cur->CellInfo.lte.signalStrengthLte.cqi,
3170 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3171 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
3172 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
3173 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
3174 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
3175 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
3176 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3177 break;
3178 }
Etan Cohend3652192014-06-20 08:28:44 -07003179 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
3180 appendPrintBuf("%s TDSCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,cpid=%d,", printBuf,
3181 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc,
3182 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc,
3183 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac,
3184 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid,
3185 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3186 appendPrintBuf("%s tdscdmaSS: rscp=%d],", printBuf,
3187 p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3188
3189 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
3190 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
3191 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
3192 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
3193 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3194 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3195 break;
3196 }
Wink Saville8a9e0212013-04-09 12:11:38 -07003197 }
3198 p_cur += 1;
3199 }
3200 removeLastChar;
3201 closeResponse;
3202
3203 return 0;
3204}
3205
Etan Cohend3652192014-06-20 08:28:44 -07003206static int responseHardwareConfig(Parcel &p, void *response, size_t responselen)
3207{
3208 if (response == NULL && responselen != 0) {
3209 RLOGE("invalid response: NULL");
3210 return RIL_ERRNO_INVALID_RESPONSE;
3211 }
3212
3213 if (responselen % sizeof(RIL_HardwareConfig) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07003214 RLOGE("responseHardwareConfig: invalid response length %d expected multiple of %d",
Etan Cohend3652192014-06-20 08:28:44 -07003215 (int)responselen, (int)sizeof(RIL_HardwareConfig));
3216 return RIL_ERRNO_INVALID_RESPONSE;
3217 }
3218
3219 int num = responselen / sizeof(RIL_HardwareConfig);
3220 int i;
3221 RIL_HardwareConfig *p_cur = (RIL_HardwareConfig *) response;
3222
3223 p.writeInt32(num);
3224
3225 startResponse;
3226 for (i = 0; i < num; i++) {
3227 switch (p_cur[i].type) {
3228 case RIL_HARDWARE_CONFIG_MODEM: {
3229 writeStringToParcel(p, p_cur[i].uuid);
3230 p.writeInt32((int)p_cur[i].state);
3231 p.writeInt32(p_cur[i].cfg.modem.rat);
3232 p.writeInt32(p_cur[i].cfg.modem.maxVoice);
3233 p.writeInt32(p_cur[i].cfg.modem.maxData);
3234 p.writeInt32(p_cur[i].cfg.modem.maxStandby);
3235
3236 appendPrintBuf("%s modem: uuid=%s,state=%d,rat=%08x,maxV=%d,maxD=%d,maxS=%d", printBuf,
3237 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.modem.rat,
3238 p_cur[i].cfg.modem.maxVoice, p_cur[i].cfg.modem.maxData, p_cur[i].cfg.modem.maxStandby);
3239 break;
3240 }
3241 case RIL_HARDWARE_CONFIG_SIM: {
3242 writeStringToParcel(p, p_cur[i].uuid);
3243 p.writeInt32((int)p_cur[i].state);
3244 writeStringToParcel(p, p_cur[i].cfg.sim.modemUuid);
3245
3246 appendPrintBuf("%s sim: uuid=%s,state=%d,modem-uuid=%s", printBuf,
3247 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.sim.modemUuid);
3248 break;
3249 }
3250 }
3251 }
3252 removeLastChar;
3253 closeResponse;
3254 return 0;
3255}
3256
Wink Saville8b4e4f72014-10-17 15:01:45 -07003257static int responseRadioCapability(Parcel &p, void *response, size_t responselen) {
3258 if (response == NULL) {
3259 RLOGE("invalid response: NULL");
3260 return RIL_ERRNO_INVALID_RESPONSE;
3261 }
3262
3263 if (responselen != sizeof (RIL_RadioCapability) ) {
3264 RLOGE("invalid response length was %d expected %d",
3265 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3266 return RIL_ERRNO_INVALID_RESPONSE;
3267 }
3268
3269 RIL_RadioCapability *p_cur = (RIL_RadioCapability *) response;
3270 p.writeInt32(p_cur->version);
3271 p.writeInt32(p_cur->session);
3272 p.writeInt32(p_cur->phase);
3273 p.writeInt32(p_cur->rat);
3274 writeStringToParcel(p, p_cur->logicalModemUuid);
3275 p.writeInt32(p_cur->status);
3276
3277 startResponse;
3278 appendPrintBuf("%s[version=%d,session=%d,phase=%d,\
Legler Wu8caf06f2014-10-29 14:02:14 +08003279 rat=%s,logicalModemUuid=%s,status=%d]",
Wink Saville8b4e4f72014-10-17 15:01:45 -07003280 printBuf,
3281 p_cur->version,
3282 p_cur->session,
3283 p_cur->phase,
3284 p_cur->rat,
Legler Wu8caf06f2014-10-29 14:02:14 +08003285 p_cur->logicalModemUuid,
Wink Saville8b4e4f72014-10-17 15:01:45 -07003286 p_cur->status);
3287 closeResponse;
3288 return 0;
3289}
3290
Amit Mahajan54563d32014-11-22 00:54:49 +00003291static int responseSSData(Parcel &p, void *response, size_t responselen) {
3292 RLOGD("In responseSSData");
3293 int num;
3294
3295 if (response == NULL && responselen != 0) {
3296 RLOGE("invalid response length was %d expected %d",
3297 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3298 return RIL_ERRNO_INVALID_RESPONSE;
3299 }
3300
3301 if (responselen != sizeof(RIL_StkCcUnsolSsResponse)) {
3302 RLOGE("invalid response length %d, expected %d",
3303 (int)responselen, (int)sizeof(RIL_StkCcUnsolSsResponse));
3304 return RIL_ERRNO_INVALID_RESPONSE;
3305 }
3306
3307 startResponse;
3308 RIL_StkCcUnsolSsResponse *p_cur = (RIL_StkCcUnsolSsResponse *) response;
3309 p.writeInt32(p_cur->serviceType);
3310 p.writeInt32(p_cur->requestType);
3311 p.writeInt32(p_cur->teleserviceType);
3312 p.writeInt32(p_cur->serviceClass);
3313 p.writeInt32(p_cur->result);
3314
3315 if (isServiceTypeCfQuery(p_cur->serviceType, p_cur->requestType)) {
3316 RLOGD("responseSSData CF type, num of Cf elements %d", p_cur->cfData.numValidIndexes);
3317 if (p_cur->cfData.numValidIndexes > NUM_SERVICE_CLASSES) {
3318 RLOGE("numValidIndexes is greater than max value %d, "
3319 "truncating it to max value", NUM_SERVICE_CLASSES);
3320 p_cur->cfData.numValidIndexes = NUM_SERVICE_CLASSES;
3321 }
3322 /* number of call info's */
3323 p.writeInt32(p_cur->cfData.numValidIndexes);
3324
3325 for (int i = 0; i < p_cur->cfData.numValidIndexes; i++) {
3326 RIL_CallForwardInfo cf = p_cur->cfData.cfInfo[i];
3327
3328 p.writeInt32(cf.status);
3329 p.writeInt32(cf.reason);
3330 p.writeInt32(cf.serviceClass);
3331 p.writeInt32(cf.toa);
3332 writeStringToParcel(p, cf.number);
3333 p.writeInt32(cf.timeSeconds);
3334 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
3335 (cf.status==1)?"enable":"disable", cf.reason, cf.serviceClass, cf.toa,
3336 (char*)cf.number, cf.timeSeconds);
3337 RLOGD("Data: %d,reason=%d,cls=%d,toa=%d,num=%s,tout=%d],", cf.status,
3338 cf.reason, cf.serviceClass, cf.toa, (char*)cf.number, cf.timeSeconds);
3339 }
3340 } else {
3341 p.writeInt32 (SS_INFO_MAX);
3342
3343 /* each int*/
3344 for (int i = 0; i < SS_INFO_MAX; i++) {
3345 appendPrintBuf("%s%d,", printBuf, p_cur->ssInfo[i]);
3346 RLOGD("Data: %d",p_cur->ssInfo[i]);
3347 p.writeInt32(p_cur->ssInfo[i]);
3348 }
3349 }
3350 removeLastChar;
3351 closeResponse;
3352
3353 return 0;
3354}
3355
3356static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType) {
3357 if ((reqType == SS_INTERROGATION) &&
3358 (serType == SS_CFU ||
3359 serType == SS_CF_BUSY ||
3360 serType == SS_CF_NO_REPLY ||
3361 serType == SS_CF_NOT_REACHABLE ||
3362 serType == SS_CF_ALL ||
3363 serType == SS_CF_ALL_CONDITIONAL)) {
3364 return true;
3365 }
3366 return false;
3367}
3368
Wink Saville3d54e742009-05-18 18:00:44 -07003369static void triggerEvLoop() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003370 int ret;
3371 if (!pthread_equal(pthread_self(), s_tid_dispatch)) {
3372 /* trigger event loop to wakeup. No reason to do this,
3373 * if we're in the event loop thread */
3374 do {
3375 ret = write (s_fdWakeupWrite, " ", 1);
3376 } while (ret < 0 && errno == EINTR);
3377 }
3378}
3379
Wink Saville3d54e742009-05-18 18:00:44 -07003380static void rilEventAddWakeup(struct ril_event *ev) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003381 ril_event_add(ev);
3382 triggerEvLoop();
3383}
3384
Wink Savillefd729372011-02-22 16:19:39 -08003385static void sendSimStatusAppInfo(Parcel &p, int num_apps, RIL_AppStatus appStatus[]) {
3386 p.writeInt32(num_apps);
3387 startResponse;
3388 for (int i = 0; i < num_apps; i++) {
3389 p.writeInt32(appStatus[i].app_type);
3390 p.writeInt32(appStatus[i].app_state);
3391 p.writeInt32(appStatus[i].perso_substate);
3392 writeStringToParcel(p, (const char*)(appStatus[i].aid_ptr));
3393 writeStringToParcel(p, (const char*)
3394 (appStatus[i].app_label_ptr));
3395 p.writeInt32(appStatus[i].pin1_replaced);
3396 p.writeInt32(appStatus[i].pin1);
3397 p.writeInt32(appStatus[i].pin2);
3398 appendPrintBuf("%s[app_type=%d,app_state=%d,perso_substate=%d,\
3399 aid_ptr=%s,app_label_ptr=%s,pin1_replaced=%d,pin1=%d,pin2=%d],",
3400 printBuf,
3401 appStatus[i].app_type,
3402 appStatus[i].app_state,
3403 appStatus[i].perso_substate,
3404 appStatus[i].aid_ptr,
3405 appStatus[i].app_label_ptr,
3406 appStatus[i].pin1_replaced,
3407 appStatus[i].pin1,
3408 appStatus[i].pin2);
3409 }
3410 closeResponse;
3411}
3412
Wink Savillef4c4d362009-04-02 01:37:03 -07003413static int responseSimStatus(Parcel &p, void *response, size_t responselen) {
3414 int i;
3415
3416 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003417 RLOGE("invalid response: NULL");
Wink Savillef4c4d362009-04-02 01:37:03 -07003418 return RIL_ERRNO_INVALID_RESPONSE;
3419 }
3420
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003421 if (responselen == sizeof (RIL_CardStatus_v6)) {
Wink Savillefd729372011-02-22 16:19:39 -08003422 RIL_CardStatus_v6 *p_cur = ((RIL_CardStatus_v6 *) response);
Wink Savillef4c4d362009-04-02 01:37:03 -07003423
Wink Savillefd729372011-02-22 16:19:39 -08003424 p.writeInt32(p_cur->card_state);
3425 p.writeInt32(p_cur->universal_pin_state);
3426 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3427 p.writeInt32(p_cur->cdma_subscription_app_index);
3428 p.writeInt32(p_cur->ims_subscription_app_index);
3429
3430 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003431 } else if (responselen == sizeof (RIL_CardStatus_v5)) {
Wink Savillefd729372011-02-22 16:19:39 -08003432 RIL_CardStatus_v5 *p_cur = ((RIL_CardStatus_v5 *) response);
3433
3434 p.writeInt32(p_cur->card_state);
3435 p.writeInt32(p_cur->universal_pin_state);
3436 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3437 p.writeInt32(p_cur->cdma_subscription_app_index);
3438 p.writeInt32(-1);
3439
3440 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003441 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003442 RLOGE("responseSimStatus: A RilCardStatus_v6 or _v5 expected\n");
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003443 return RIL_ERRNO_INVALID_RESPONSE;
Wink Savillef4c4d362009-04-02 01:37:03 -07003444 }
Wink Savillef4c4d362009-04-02 01:37:03 -07003445
3446 return 0;
Wink Saville3d54e742009-05-18 18:00:44 -07003447}
Wink Savillef4c4d362009-04-02 01:37:03 -07003448
Wink Savillea592eeb2009-05-22 13:26:36 -07003449static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3450 int num = responselen / sizeof(RIL_GSM_BroadcastSmsConfigInfo *);
Wink Savillef4c4d362009-04-02 01:37:03 -07003451 p.writeInt32(num);
3452
Wink Savillef4c4d362009-04-02 01:37:03 -07003453 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07003454 RIL_GSM_BroadcastSmsConfigInfo **p_cur =
3455 (RIL_GSM_BroadcastSmsConfigInfo **) response;
3456 for (int i = 0; i < num; i++) {
3457 p.writeInt32(p_cur[i]->fromServiceId);
3458 p.writeInt32(p_cur[i]->toServiceId);
3459 p.writeInt32(p_cur[i]->fromCodeScheme);
3460 p.writeInt32(p_cur[i]->toCodeScheme);
3461 p.writeInt32(p_cur[i]->selected);
3462
3463 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId=%d, \
3464 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]",
3465 printBuf, i, p_cur[i]->fromServiceId, p_cur[i]->toServiceId,
3466 p_cur[i]->fromCodeScheme, p_cur[i]->toCodeScheme,
3467 p_cur[i]->selected);
3468 }
Wink Savillef4c4d362009-04-02 01:37:03 -07003469 closeResponse;
3470
3471 return 0;
3472}
3473
Wink Savillea592eeb2009-05-22 13:26:36 -07003474static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3475 RIL_CDMA_BroadcastSmsConfigInfo **p_cur =
3476 (RIL_CDMA_BroadcastSmsConfigInfo **) response;
Wink Savillef4c4d362009-04-02 01:37:03 -07003477
Wink Savillea592eeb2009-05-22 13:26:36 -07003478 int num = responselen / sizeof (RIL_CDMA_BroadcastSmsConfigInfo *);
3479 p.writeInt32(num);
Wink Savillef4c4d362009-04-02 01:37:03 -07003480
3481 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07003482 for (int i = 0 ; i < num ; i++ ) {
3483 p.writeInt32(p_cur[i]->service_category);
3484 p.writeInt32(p_cur[i]->language);
3485 p.writeInt32(p_cur[i]->selected);
Wink Savillef4c4d362009-04-02 01:37:03 -07003486
Wink Savillea592eeb2009-05-22 13:26:36 -07003487 appendPrintBuf("%s [%d: srvice_category=%d, language =%d, \
3488 selected =%d], ",
3489 printBuf, i, p_cur[i]->service_category, p_cur[i]->language,
3490 p_cur[i]->selected);
Wink Savillef5903df2009-04-24 11:54:14 -07003491 }
Wink Savillea592eeb2009-05-22 13:26:36 -07003492 closeResponse;
Wink Savillef5903df2009-04-24 11:54:14 -07003493
Wink Savillef4c4d362009-04-02 01:37:03 -07003494 return 0;
3495}
3496
3497static int responseCdmaSms(Parcel &p, void *response, size_t responselen) {
3498 int num;
3499 int digitCount;
3500 int digitLimit;
3501 uint8_t uct;
3502 void* dest;
3503
Wink Saville8eb2a122012-11-19 16:05:13 -08003504 RLOGD("Inside responseCdmaSms");
Wink Savillef5903df2009-04-24 11:54:14 -07003505
Wink Savillef4c4d362009-04-02 01:37:03 -07003506 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003507 RLOGE("invalid response: NULL");
Wink Savillef4c4d362009-04-02 01:37:03 -07003508 return RIL_ERRNO_INVALID_RESPONSE;
3509 }
3510
Wink Savillef5903df2009-04-24 11:54:14 -07003511 if (responselen != sizeof(RIL_CDMA_SMS_Message)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003512 RLOGE("invalid response length was %d expected %d",
Wink Savillef5903df2009-04-24 11:54:14 -07003513 (int)responselen, (int)sizeof(RIL_CDMA_SMS_Message));
Wink Savillef4c4d362009-04-02 01:37:03 -07003514 return RIL_ERRNO_INVALID_RESPONSE;
3515 }
3516
3517 RIL_CDMA_SMS_Message *p_cur = (RIL_CDMA_SMS_Message *) response;
3518 p.writeInt32(p_cur->uTeleserviceID);
3519 p.write(&(p_cur->bIsServicePresent),sizeof(uct));
3520 p.writeInt32(p_cur->uServicecategory);
3521 p.writeInt32(p_cur->sAddress.digit_mode);
3522 p.writeInt32(p_cur->sAddress.number_mode);
3523 p.writeInt32(p_cur->sAddress.number_type);
3524 p.writeInt32(p_cur->sAddress.number_plan);
3525 p.write(&(p_cur->sAddress.number_of_digits), sizeof(uct));
3526 digitLimit= MIN((p_cur->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
3527 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3528 p.write(&(p_cur->sAddress.digits[digitCount]),sizeof(uct));
3529 }
3530
3531 p.writeInt32(p_cur->sSubAddress.subaddressType);
3532 p.write(&(p_cur->sSubAddress.odd),sizeof(uct));
3533 p.write(&(p_cur->sSubAddress.number_of_digits),sizeof(uct));
3534 digitLimit= MIN((p_cur->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
3535 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3536 p.write(&(p_cur->sSubAddress.digits[digitCount]),sizeof(uct));
3537 }
3538
3539 digitLimit= MIN((p_cur->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
3540 p.writeInt32(p_cur->uBearerDataLen);
3541 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3542 p.write(&(p_cur->aBearerData[digitCount]), sizeof(uct));
3543 }
3544
3545 startResponse;
3546 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
Wink Saville1b5fd232009-04-22 14:50:00 -07003547 sAddress.digit_mode=%d, sAddress.number_mode=%d, sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07003548 printBuf, p_cur->uTeleserviceID,p_cur->bIsServicePresent,p_cur->uServicecategory,
3549 p_cur->sAddress.digit_mode, p_cur->sAddress.number_mode,p_cur->sAddress.number_type);
3550 closeResponse;
3551
3552 return 0;
3553}
3554
Wink Savillec29360a2014-07-13 05:17:28 -07003555static int responseDcRtInfo(Parcel &p, void *response, size_t responselen)
3556{
3557 int num = responselen / sizeof(RIL_DcRtInfo);
3558 if ((responselen % sizeof(RIL_DcRtInfo) != 0) || (num != 1)) {
Amit Mahajan52500162014-07-29 17:36:48 -07003559 RLOGE("responseDcRtInfo: invalid response length %d expected multiple of %d",
Wink Savillec29360a2014-07-13 05:17:28 -07003560 (int)responselen, (int)sizeof(RIL_DcRtInfo));
3561 return RIL_ERRNO_INVALID_RESPONSE;
3562 }
3563
3564 startResponse;
3565 RIL_DcRtInfo *pDcRtInfo = (RIL_DcRtInfo *)response;
3566 p.writeInt64(pDcRtInfo->time);
3567 p.writeInt32(pDcRtInfo->powerState);
3568 appendPrintBuf("%s[time=%d,powerState=%d]", printBuf,
3569 pDcRtInfo->time,
3570 pDcRtInfo->powerState);
3571 closeResponse;
3572
3573 return 0;
3574}
3575
fengluf7408292015-04-14 14:53:55 -07003576static int responseLceStatus(Parcel &p, void *response, size_t responselen) {
3577 if (response == NULL || responselen != sizeof(RIL_LceStatusInfo)) {
3578 if (response == NULL) {
3579 RLOGE("invalid response: NULL");
3580 }
3581 else {
3582 RLOGE("responseLceStatus: invalid response length %d expecting len: d%",
3583 sizeof(RIL_LceStatusInfo), responselen);
3584 }
3585 return RIL_ERRNO_INVALID_RESPONSE;
3586 }
3587
3588 RIL_LceStatusInfo *p_cur = (RIL_LceStatusInfo *)response;
3589 p.write((void *)p_cur, 1); // p_cur->lce_status takes one byte.
3590 p.writeInt32(p_cur->actual_interval_ms);
3591
3592 startResponse;
3593 appendPrintBuf("LCE Status: %d, actual_interval_ms: %d",
3594 p_cur->lce_status, p_cur->actual_interval_ms);
3595 closeResponse;
3596
3597 return 0;
3598}
3599
3600static int responseLceData(Parcel &p, void *response, size_t responselen) {
3601 if (response == NULL || responselen != sizeof(RIL_LceDataInfo)) {
3602 if (response == NULL) {
3603 RLOGE("invalid response: NULL");
3604 }
3605 else {
3606 RLOGE("responseLceData: invalid response length %d expecting len: d%",
3607 sizeof(RIL_LceDataInfo), responselen);
3608 }
3609 return RIL_ERRNO_INVALID_RESPONSE;
3610 }
3611
3612 RIL_LceDataInfo *p_cur = (RIL_LceDataInfo *)response;
3613 p.writeInt32(p_cur->last_hop_capacity_kbps);
3614
3615 /* p_cur->confidence_level and p_cur->lce_suspended take 1 byte each.*/
3616 p.write((void *)&(p_cur->confidence_level), 1);
3617 p.write((void *)&(p_cur->lce_suspended), 1);
3618
3619 startResponse;
3620 appendPrintBuf("LCE info received: capacity %d confidence level %d
3621 and suspended %d",
3622 p_cur->last_hop_capacity_kbps, p_cur->confidence_level,
3623 p_cur->lce_suspended);
3624 closeResponse;
3625
3626 return 0;
3627}
3628
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003629/**
3630 * A write on the wakeup fd is done just to pop us out of select()
3631 * We empty the buffer here and then ril_event will reset the timers on the
3632 * way back down
3633 */
Wink Savillef4c4d362009-04-02 01:37:03 -07003634static void processWakeupCallback(int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003635 char buff[16];
3636 int ret;
3637
Wink Saville8eb2a122012-11-19 16:05:13 -08003638 RLOGV("processWakeupCallback");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003639
3640 /* empty our wakeup socket out */
3641 do {
3642 ret = read(s_fdWakeupRead, &buff, sizeof(buff));
Wink Saville7f856802009-06-09 10:23:37 -07003643 } while (ret > 0 || (ret < 0 && errno == EINTR));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003644}
3645
Etan Cohend3652192014-06-20 08:28:44 -07003646static void onCommandsSocketClosed(RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003647 int ret;
3648 RequestInfo *p_cur;
Etan Cohend3652192014-06-20 08:28:44 -07003649 /* Hook for current context
3650 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
3651 pthread_mutex_t * pendingRequestsMutexHook = &s_pendingRequestsMutex;
3652 /* pendingRequestsHook refer to &s_pendingRequests */
3653 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003654
Etan Cohend3652192014-06-20 08:28:44 -07003655#if (SIM_COUNT >= 2)
3656 if (socket_id == RIL_SOCKET_2) {
3657 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
3658 pendingRequestsHook = &s_pendingRequests_socket2;
3659 }
3660#if (SIM_COUNT >= 3)
3661 else if (socket_id == RIL_SOCKET_3) {
3662 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
3663 pendingRequestsHook = &s_pendingRequests_socket3;
3664 }
3665#endif
3666#if (SIM_COUNT >= 4)
3667 else if (socket_id == RIL_SOCKET_4) {
3668 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
3669 pendingRequestsHook = &s_pendingRequests_socket4;
3670 }
3671#endif
3672#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003673 /* mark pending requests as "cancelled" so we dont report responses */
Etan Cohend3652192014-06-20 08:28:44 -07003674 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003675 assert (ret == 0);
3676
Etan Cohend3652192014-06-20 08:28:44 -07003677 p_cur = *pendingRequestsHook;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003678
Etan Cohend3652192014-06-20 08:28:44 -07003679 for (p_cur = *pendingRequestsHook
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003680 ; p_cur != NULL
3681 ; p_cur = p_cur->p_next
3682 ) {
3683 p_cur->cancelled = 1;
3684 }
3685
Etan Cohend3652192014-06-20 08:28:44 -07003686 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003687 assert (ret == 0);
3688}
3689
Wink Savillef4c4d362009-04-02 01:37:03 -07003690static void processCommandsCallback(int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003691 RecordStream *p_rs;
3692 void *p_record;
3693 size_t recordlen;
3694 int ret;
Etan Cohend3652192014-06-20 08:28:44 -07003695 SocketListenParam *p_info = (SocketListenParam *)param;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003696
Etan Cohend3652192014-06-20 08:28:44 -07003697 assert(fd == p_info->fdCommand);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003698
Etan Cohend3652192014-06-20 08:28:44 -07003699 p_rs = p_info->p_rs;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003700
3701 for (;;) {
3702 /* loop until EAGAIN/EINTR, end of stream, or other error */
3703 ret = record_stream_get_next(p_rs, &p_record, &recordlen);
3704
3705 if (ret == 0 && p_record == NULL) {
3706 /* end-of-stream */
3707 break;
3708 } else if (ret < 0) {
3709 break;
3710 } else if (ret == 0) { /* && p_record != NULL */
Etan Cohend3652192014-06-20 08:28:44 -07003711 processCommandBuffer(p_record, recordlen, p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003712 }
3713 }
3714
3715 if (ret == 0 || !(errno == EAGAIN || errno == EINTR)) {
3716 /* fatal error or end-of-stream */
3717 if (ret != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003718 RLOGE("error on reading command socket errno:%d\n", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003719 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003720 RLOGW("EOS. Closing command socket.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003721 }
Wink Saville7f856802009-06-09 10:23:37 -07003722
Etan Cohend3652192014-06-20 08:28:44 -07003723 close(fd);
3724 p_info->fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003725
Etan Cohend3652192014-06-20 08:28:44 -07003726 ril_event_del(p_info->commands_event);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003727
3728 record_stream_free(p_rs);
3729
3730 /* start listening for new connections again */
3731 rilEventAddWakeup(&s_listen_event);
3732
Etan Cohend3652192014-06-20 08:28:44 -07003733 onCommandsSocketClosed(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003734 }
3735}
3736
3737
Etan Cohend3652192014-06-20 08:28:44 -07003738static void onNewCommandConnect(RIL_SOCKET_ID socket_id) {
Wink Saville5b9df332011-04-06 16:24:21 -07003739 // Inform we are connected and the ril version
Jake Hambya9c18d12011-04-12 23:32:08 -07003740 int rilVer = s_callbacks.version;
Etan Cohend3652192014-06-20 08:28:44 -07003741 RIL_UNSOL_RESPONSE(RIL_UNSOL_RIL_CONNECTED,
3742 &rilVer, sizeof(rilVer), socket_id);
Wink Saville5b9df332011-04-06 16:24:21 -07003743
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003744 // implicit radio state changed
Etan Cohend3652192014-06-20 08:28:44 -07003745 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
3746 NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003747
3748 // Send last NITZ time data, in case it was missed
3749 if (s_lastNITZTimeData != NULL) {
Etan Cohend3652192014-06-20 08:28:44 -07003750 sendResponseRaw(s_lastNITZTimeData, s_lastNITZTimeDataSize, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003751
3752 free(s_lastNITZTimeData);
3753 s_lastNITZTimeData = NULL;
3754 }
3755
3756 // Get version string
3757 if (s_callbacks.getVersion != NULL) {
3758 const char *version;
3759 version = s_callbacks.getVersion();
Wink Saville8eb2a122012-11-19 16:05:13 -08003760 RLOGI("RIL Daemon version: %s\n", version);
Wink Saville7f856802009-06-09 10:23:37 -07003761
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003762 property_set(PROPERTY_RIL_IMPL, version);
3763 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003764 RLOGI("RIL Daemon version: unavailable\n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003765 property_set(PROPERTY_RIL_IMPL, "unavailable");
3766 }
3767
3768}
3769
Wink Savillef4c4d362009-04-02 01:37:03 -07003770static void listenCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003771 int ret;
3772 int err;
3773 int is_phone_socket;
Etan Cohend3652192014-06-20 08:28:44 -07003774 int fdCommand = -1;
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003775 char* processName;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003776 RecordStream *p_rs;
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003777 MySocketListenParam* listenParam;
3778 RilSocket *sapSocket = NULL;
3779 socketClient *sClient = NULL;
3780
Etan Cohend3652192014-06-20 08:28:44 -07003781 SocketListenParam *p_info = (SocketListenParam *)param;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003782
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003783 if(RIL_SAP_SOCKET == p_info->type) {
3784 listenParam = (MySocketListenParam *)param;
3785 sapSocket = listenParam->socket;
3786 }
3787
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003788 struct sockaddr_un peeraddr;
3789 socklen_t socklen = sizeof (peeraddr);
3790
3791 struct ucred creds;
3792 socklen_t szCreds = sizeof(creds);
3793
3794 struct passwd *pwd = NULL;
3795
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003796 if(NULL == sapSocket) {
3797 assert (*p_info->fdCommand < 0);
3798 assert (fd == *p_info->fdListen);
3799 processName = PHONE_PROCESS;
3800 } else {
3801 assert (sapSocket->commandFd < 0);
3802 assert (fd == sapSocket->listenFd);
3803 processName = BLUETOOTH_PROCESS;
3804 }
3805
Wink Saville7f856802009-06-09 10:23:37 -07003806
Etan Cohend3652192014-06-20 08:28:44 -07003807 fdCommand = accept(fd, (sockaddr *) &peeraddr, &socklen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003808
Etan Cohend3652192014-06-20 08:28:44 -07003809 if (fdCommand < 0 ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003810 RLOGE("Error on accept() errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003811 /* start listening for new connections again */
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003812 if(NULL == sapSocket) {
3813 rilEventAddWakeup(p_info->listen_event);
3814 } else {
3815 rilEventAddWakeup(sapSocket->getListenEvent());
3816 }
Etan Cohend3652192014-06-20 08:28:44 -07003817 return;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003818 }
3819
3820 /* check the credential of the other side and only accept socket from
3821 * phone process
Wink Saville7f856802009-06-09 10:23:37 -07003822 */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003823 errno = 0;
3824 is_phone_socket = 0;
Wink Savillef4c4d362009-04-02 01:37:03 -07003825
Etan Cohend3652192014-06-20 08:28:44 -07003826 err = getsockopt(fdCommand, SOL_SOCKET, SO_PEERCRED, &creds, &szCreds);
Wink Savillef4c4d362009-04-02 01:37:03 -07003827
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003828 if (err == 0 && szCreds > 0) {
Wink Savillef4c4d362009-04-02 01:37:03 -07003829 errno = 0;
3830 pwd = getpwuid(creds.uid);
3831 if (pwd != NULL) {
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003832 if (strcmp(pwd->pw_name, processName) == 0) {
Wink Savillef4c4d362009-04-02 01:37:03 -07003833 is_phone_socket = 1;
3834 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003835 RLOGE("RILD can't accept socket from process %s", pwd->pw_name);
Wink Savillef4c4d362009-04-02 01:37:03 -07003836 }
3837 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003838 RLOGE("Error on getpwuid() errno: %d", errno);
Wink Savillef4c4d362009-04-02 01:37:03 -07003839 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003840 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003841 RLOGD("Error on getsockopt() errno: %d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003842 }
3843
Etan Cohend3652192014-06-20 08:28:44 -07003844 if (!is_phone_socket) {
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003845 RLOGE("RILD must accept socket from %s", processName);
Wink Saville7f856802009-06-09 10:23:37 -07003846
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003847 close(fdCommand);
3848 fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003849
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003850 if(NULL == sapSocket) {
3851 onCommandsSocketClosed(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003852
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003853 /* start listening for new connections again */
3854 rilEventAddWakeup(p_info->listen_event);
3855 } else {
3856 sapSocket->onCommandsSocketClosed();
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003857
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003858 /* start listening for new connections again */
3859 rilEventAddWakeup(sapSocket->getListenEvent());
3860 }
3861
3862 return;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003863 }
3864
Etan Cohend3652192014-06-20 08:28:44 -07003865 ret = fcntl(fdCommand, F_SETFL, O_NONBLOCK);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003866
3867 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003868 RLOGE ("Error setting O_NONBLOCK errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003869 }
3870
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003871 if(NULL == sapSocket) {
3872 RLOGI("libril: new connection to %s", rilSocketIdToString(p_info->socket_id));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003873
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003874 p_info->fdCommand = fdCommand;
3875 p_rs = record_stream_new(p_info->fdCommand, MAX_COMMAND_BYTES);
3876 p_info->p_rs = p_rs;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003877
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003878 ril_event_set (p_info->commands_event, p_info->fdCommand, 1,
Etan Cohend3652192014-06-20 08:28:44 -07003879 p_info->processCommandsCallback, p_info);
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003880 rilEventAddWakeup (p_info->commands_event);
Etan Cohend3652192014-06-20 08:28:44 -07003881
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003882 onNewCommandConnect(p_info->socket_id);
3883 } else {
3884 RLOGI("libril: new connection");
Etan Cohend3652192014-06-20 08:28:44 -07003885
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003886 sapSocket->setCommandFd(fdCommand);
3887 p_rs = record_stream_new(sapSocket->getCommandFd(), MAX_COMMAND_BYTES);
3888 sClient = new socketClient(sapSocket,p_rs);
3889 ril_event_set (sapSocket->getCallbackEvent(), sapSocket->getCommandFd(), 1,
3890 sapSocket->getCommandCb(), sClient);
3891
3892 rilEventAddWakeup(sapSocket->getCallbackEvent());
3893 sapSocket->onNewCommandConnect();
3894 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003895}
3896
3897static void freeDebugCallbackArgs(int number, char **args) {
3898 for (int i = 0; i < number; i++) {
3899 if (args[i] != NULL) {
3900 free(args[i]);
3901 }
3902 }
3903 free(args);
3904}
3905
Wink Savillef4c4d362009-04-02 01:37:03 -07003906static void debugCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003907 int acceptFD, option;
3908 struct sockaddr_un peeraddr;
3909 socklen_t socklen = sizeof (peeraddr);
3910 int data;
3911 unsigned int qxdm_data[6];
3912 const char *deactData[1] = {"1"};
3913 char *actData[1];
3914 RIL_Dial dialData;
3915 int hangupData[1] = {1};
3916 int number;
3917 char **args;
Etan Cohend3652192014-06-20 08:28:44 -07003918 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
3919 int sim_id = 0;
3920
3921 RLOGI("debugCallback for socket %s", rilSocketIdToString(socket_id));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003922
3923 acceptFD = accept (fd, (sockaddr *) &peeraddr, &socklen);
3924
3925 if (acceptFD < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003926 RLOGE ("error accepting on debug port: %d\n", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003927 return;
3928 }
3929
3930 if (recv(acceptFD, &number, sizeof(int), 0) != sizeof(int)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003931 RLOGE ("error reading on socket: number of Args: \n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003932 return;
3933 }
3934 args = (char **) malloc(sizeof(char*) * number);
3935
3936 for (int i = 0; i < number; i++) {
3937 int len;
3938 if (recv(acceptFD, &len, sizeof(int), 0) != sizeof(int)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003939 RLOGE ("error reading on socket: Len of Args: \n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003940 freeDebugCallbackArgs(i, args);
3941 return;
3942 }
3943 // +1 for null-term
3944 args[i] = (char *) malloc((sizeof(char) * len) + 1);
Wink Saville7f856802009-06-09 10:23:37 -07003945 if (recv(acceptFD, args[i], sizeof(char) * len, 0)
Wink Saville1b5fd232009-04-22 14:50:00 -07003946 != (int)sizeof(char) * len) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003947 RLOGE ("error reading on socket: Args[%d] \n", i);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003948 freeDebugCallbackArgs(i, args);
3949 return;
3950 }
3951 char * buf = args[i];
3952 buf[len] = 0;
Etan Cohend3652192014-06-20 08:28:44 -07003953 if ((i+1) == number) {
3954 /* The last argument should be sim id 0(SIM1)~3(SIM4) */
3955 sim_id = atoi(args[i]);
3956 switch (sim_id) {
3957 case 0:
3958 socket_id = RIL_SOCKET_1;
3959 break;
3960 #if (SIM_COUNT >= 2)
3961 case 1:
3962 socket_id = RIL_SOCKET_2;
3963 break;
3964 #endif
3965 #if (SIM_COUNT >= 3)
3966 case 2:
3967 socket_id = RIL_SOCKET_3;
3968 break;
3969 #endif
3970 #if (SIM_COUNT >= 4)
3971 case 3:
3972 socket_id = RIL_SOCKET_4;
3973 break;
3974 #endif
3975 default:
3976 socket_id = RIL_SOCKET_1;
3977 break;
3978 }
3979 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003980 }
3981
3982 switch (atoi(args[0])) {
3983 case 0:
Wink Saville8eb2a122012-11-19 16:05:13 -08003984 RLOGI ("Connection on debug port: issuing reset.");
Etan Cohend3652192014-06-20 08:28:44 -07003985 issueLocalRequest(RIL_REQUEST_RESET_RADIO, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003986 break;
3987 case 1:
Wink Saville8eb2a122012-11-19 16:05:13 -08003988 RLOGI ("Connection on debug port: issuing radio power off.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003989 data = 0;
Etan Cohend3652192014-06-20 08:28:44 -07003990 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003991 // Close the socket
Etan Cohend3652192014-06-20 08:28:44 -07003992 if (socket_id == RIL_SOCKET_1 && s_ril_param_socket.fdCommand > 0) {
3993 close(s_ril_param_socket.fdCommand);
3994 s_ril_param_socket.fdCommand = -1;
3995 }
3996 #if (SIM_COUNT == 2)
3997 else if (socket_id == RIL_SOCKET_2 && s_ril_param_socket2.fdCommand > 0) {
3998 close(s_ril_param_socket2.fdCommand);
3999 s_ril_param_socket2.fdCommand = -1;
4000 }
4001 #endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004002 break;
4003 case 2:
Wink Saville8eb2a122012-11-19 16:05:13 -08004004 RLOGI ("Debug port: issuing unsolicited voice network change.");
Etan Cohend3652192014-06-20 08:28:44 -07004005 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004006 break;
4007 case 3:
Wink Saville8eb2a122012-11-19 16:05:13 -08004008 RLOGI ("Debug port: QXDM log enable.");
Xia Wangd855ef42010-07-27 17:26:55 -07004009 qxdm_data[0] = 65536; // head.func_tag
4010 qxdm_data[1] = 16; // head.len
4011 qxdm_data[2] = 1; // mode: 1 for 'start logging'
4012 qxdm_data[3] = 32; // log_file_size: 32megabytes
4013 qxdm_data[4] = 0; // log_mask
4014 qxdm_data[5] = 8; // log_max_fileindex
Wink Saville7f856802009-06-09 10:23:37 -07004015 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Etan Cohend3652192014-06-20 08:28:44 -07004016 6 * sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004017 break;
4018 case 4:
Wink Saville8eb2a122012-11-19 16:05:13 -08004019 RLOGI ("Debug port: QXDM log disable.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004020 qxdm_data[0] = 65536;
4021 qxdm_data[1] = 16;
Xia Wangd855ef42010-07-27 17:26:55 -07004022 qxdm_data[2] = 0; // mode: 0 for 'stop logging'
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004023 qxdm_data[3] = 32;
4024 qxdm_data[4] = 0;
Xia Wangd855ef42010-07-27 17:26:55 -07004025 qxdm_data[5] = 8;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004026 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Etan Cohend3652192014-06-20 08:28:44 -07004027 6 * sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004028 break;
4029 case 5:
Wink Saville8eb2a122012-11-19 16:05:13 -08004030 RLOGI("Debug port: Radio On");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004031 data = 1;
Etan Cohend3652192014-06-20 08:28:44 -07004032 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004033 sleep(2);
4034 // Set network selection automatic.
Etan Cohend3652192014-06-20 08:28:44 -07004035 issueLocalRequest(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004036 break;
4037 case 6:
Wink Saville8eb2a122012-11-19 16:05:13 -08004038 RLOGI("Debug port: Setup Data Call, Apn :%s\n", args[1]);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004039 actData[0] = args[1];
Wink Saville7f856802009-06-09 10:23:37 -07004040 issueLocalRequest(RIL_REQUEST_SETUP_DATA_CALL, &actData,
Etan Cohend3652192014-06-20 08:28:44 -07004041 sizeof(actData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004042 break;
4043 case 7:
Wink Saville8eb2a122012-11-19 16:05:13 -08004044 RLOGI("Debug port: Deactivate Data Call");
Wink Saville7f856802009-06-09 10:23:37 -07004045 issueLocalRequest(RIL_REQUEST_DEACTIVATE_DATA_CALL, &deactData,
Etan Cohend3652192014-06-20 08:28:44 -07004046 sizeof(deactData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004047 break;
4048 case 8:
Wink Saville8eb2a122012-11-19 16:05:13 -08004049 RLOGI("Debug port: Dial Call");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004050 dialData.clir = 0;
4051 dialData.address = args[1];
Etan Cohend3652192014-06-20 08:28:44 -07004052 issueLocalRequest(RIL_REQUEST_DIAL, &dialData, sizeof(dialData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004053 break;
4054 case 9:
Wink Saville8eb2a122012-11-19 16:05:13 -08004055 RLOGI("Debug port: Answer Call");
Etan Cohend3652192014-06-20 08:28:44 -07004056 issueLocalRequest(RIL_REQUEST_ANSWER, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004057 break;
4058 case 10:
Wink Saville8eb2a122012-11-19 16:05:13 -08004059 RLOGI("Debug port: End Call");
Wink Saville7f856802009-06-09 10:23:37 -07004060 issueLocalRequest(RIL_REQUEST_HANGUP, &hangupData,
Etan Cohend3652192014-06-20 08:28:44 -07004061 sizeof(hangupData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004062 break;
4063 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004064 RLOGE ("Invalid request");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004065 break;
4066 }
4067 freeDebugCallbackArgs(number, args);
4068 close(acceptFD);
4069}
4070
4071
Wink Savillef4c4d362009-04-02 01:37:03 -07004072static void userTimerCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004073 UserCallbackInfo *p_info;
4074
4075 p_info = (UserCallbackInfo *)param;
4076
4077 p_info->p_callback(p_info->userParam);
4078
4079
4080 // FIXME generalize this...there should be a cancel mechanism
4081 if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) {
4082 s_last_wake_timeout_info = NULL;
4083 }
4084
4085 free(p_info);
4086}
4087
4088
4089static void *
Wink Savillef4c4d362009-04-02 01:37:03 -07004090eventLoop(void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004091 int ret;
4092 int filedes[2];
4093
4094 ril_event_init();
4095
4096 pthread_mutex_lock(&s_startupMutex);
4097
4098 s_started = 1;
4099 pthread_cond_broadcast(&s_startupCond);
4100
4101 pthread_mutex_unlock(&s_startupMutex);
4102
4103 ret = pipe(filedes);
4104
4105 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004106 RLOGE("Error in pipe() errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004107 return NULL;
4108 }
4109
4110 s_fdWakeupRead = filedes[0];
4111 s_fdWakeupWrite = filedes[1];
4112
4113 fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK);
4114
4115 ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,
4116 processWakeupCallback, NULL);
4117
4118 rilEventAddWakeup (&s_wakeupfd_event);
4119
4120 // Only returns on error
4121 ril_event_loop();
Wink Saville8eb2a122012-11-19 16:05:13 -08004122 RLOGE ("error in event_loop_base errno:%d", errno);
Kazuhiro Ondo5cdc1352011-10-14 17:50:58 -05004123 // kill self to restart on error
4124 kill(0, SIGKILL);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004125
4126 return NULL;
4127}
4128
Wink Saville7f856802009-06-09 10:23:37 -07004129extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07004130RIL_startEventLoop(void) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004131 /* spin up eventLoop thread and wait for it to get started */
4132 s_started = 0;
4133 pthread_mutex_lock(&s_startupMutex);
4134
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004135 pthread_attr_t attr;
4136 pthread_attr_init(&attr);
Wink Saville7f856802009-06-09 10:23:37 -07004137 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004138
Elliott Hughesfd81e712014-01-06 12:46:02 -08004139 int result = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
4140 if (result != 0) {
4141 RLOGE("Failed to create dispatch thread: %s", strerror(result));
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004142 goto done;
4143 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004144
4145 while (s_started == 0) {
4146 pthread_cond_wait(&s_startupCond, &s_startupMutex);
4147 }
4148
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004149done:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004150 pthread_mutex_unlock(&s_startupMutex);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004151}
4152
4153// Used for testing purpose only.
4154extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) {
4155 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4156}
4157
Etan Cohend3652192014-06-20 08:28:44 -07004158static void startListen(RIL_SOCKET_ID socket_id, SocketListenParam* socket_listen_p) {
4159 int fdListen = -1;
4160 int ret;
4161 char socket_name[10];
4162
4163 memset(socket_name, 0, sizeof(char)*10);
4164
4165 switch(socket_id) {
4166 case RIL_SOCKET_1:
4167 strncpy(socket_name, RIL_getRilSocketName(), 9);
4168 break;
4169 #if (SIM_COUNT >= 2)
4170 case RIL_SOCKET_2:
4171 strncpy(socket_name, SOCKET2_NAME_RIL, 9);
4172 break;
4173 #endif
4174 #if (SIM_COUNT >= 3)
4175 case RIL_SOCKET_3:
4176 strncpy(socket_name, SOCKET3_NAME_RIL, 9);
4177 break;
4178 #endif
4179 #if (SIM_COUNT >= 4)
4180 case RIL_SOCKET_4:
4181 strncpy(socket_name, SOCKET4_NAME_RIL, 9);
4182 break;
4183 #endif
4184 default:
4185 RLOGE("Socket id is wrong!!");
4186 return;
4187 }
4188
4189 RLOGI("Start to listen %s", rilSocketIdToString(socket_id));
4190
4191 fdListen = android_get_control_socket(socket_name);
4192 if (fdListen < 0) {
4193 RLOGE("Failed to get socket %s", socket_name);
4194 exit(-1);
4195 }
4196
4197 ret = listen(fdListen, 4);
4198
4199 if (ret < 0) {
4200 RLOGE("Failed to listen on control socket '%d': %s",
4201 fdListen, strerror(errno));
4202 exit(-1);
4203 }
4204 socket_listen_p->fdListen = fdListen;
4205
4206 /* note: non-persistent so we can accept only one connection at a time */
4207 ril_event_set (socket_listen_p->listen_event, fdListen, false,
4208 listenCallback, socket_listen_p);
4209
4210 rilEventAddWakeup (socket_listen_p->listen_event);
4211}
4212
Wink Saville7f856802009-06-09 10:23:37 -07004213extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07004214RIL_register (const RIL_RadioFunctions *callbacks) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004215 int ret;
4216 int flags;
4217
Etan Cohend3652192014-06-20 08:28:44 -07004218 RLOGI("SIM_COUNT: %d", SIM_COUNT);
4219
Wink Saville43808972011-01-13 17:39:51 -08004220 if (callbacks == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004221 RLOGE("RIL_register: RIL_RadioFunctions * null");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004222 return;
4223 }
Wink Saville43808972011-01-13 17:39:51 -08004224 if (callbacks->version < RIL_VERSION_MIN) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004225 RLOGE("RIL_register: version %d is to old, min version is %d",
Wink Saville43808972011-01-13 17:39:51 -08004226 callbacks->version, RIL_VERSION_MIN);
4227 return;
Wink Saville3a4840b2010-04-07 13:29:58 -07004228 }
Wink Saville43808972011-01-13 17:39:51 -08004229 if (callbacks->version > RIL_VERSION) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004230 RLOGE("RIL_register: version %d is too new, max version is %d",
Wink Saville43808972011-01-13 17:39:51 -08004231 callbacks->version, RIL_VERSION);
4232 return;
4233 }
Wink Saville8eb2a122012-11-19 16:05:13 -08004234 RLOGE("RIL_register: RIL version %d", callbacks->version);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004235
4236 if (s_registerCalled > 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004237 RLOGE("RIL_register has been called more than once. "
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004238 "Subsequent call ignored");
4239 return;
4240 }
4241
4242 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4243
Etan Cohend3652192014-06-20 08:28:44 -07004244 /* Initialize socket1 parameters */
4245 s_ril_param_socket = {
4246 RIL_SOCKET_1, /* socket_id */
4247 -1, /* fdListen */
4248 -1, /* fdCommand */
4249 PHONE_PROCESS, /* processName */
4250 &s_commands_event, /* commands_event */
4251 &s_listen_event, /* listen_event */
4252 processCommandsCallback, /* processCommandsCallback */
4253 NULL /* p_rs */
4254 };
4255
4256#if (SIM_COUNT >= 2)
4257 s_ril_param_socket2 = {
4258 RIL_SOCKET_2, /* socket_id */
4259 -1, /* fdListen */
4260 -1, /* fdCommand */
4261 PHONE_PROCESS, /* processName */
4262 &s_commands_event_socket2, /* commands_event */
4263 &s_listen_event_socket2, /* listen_event */
4264 processCommandsCallback, /* processCommandsCallback */
4265 NULL /* p_rs */
4266 };
4267#endif
4268
4269#if (SIM_COUNT >= 3)
4270 s_ril_param_socket3 = {
4271 RIL_SOCKET_3, /* socket_id */
4272 -1, /* fdListen */
4273 -1, /* fdCommand */
4274 PHONE_PROCESS, /* processName */
4275 &s_commands_event_socket3, /* commands_event */
4276 &s_listen_event_socket3, /* listen_event */
4277 processCommandsCallback, /* processCommandsCallback */
4278 NULL /* p_rs */
4279 };
4280#endif
4281
4282#if (SIM_COUNT >= 4)
4283 s_ril_param_socket4 = {
4284 RIL_SOCKET_4, /* socket_id */
4285 -1, /* fdListen */
4286 -1, /* fdCommand */
4287 PHONE_PROCESS, /* processName */
4288 &s_commands_event_socket4, /* commands_event */
4289 &s_listen_event_socket4, /* listen_event */
4290 processCommandsCallback, /* processCommandsCallback */
4291 NULL /* p_rs */
4292 };
4293#endif
4294
4295
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004296 s_registerCalled = 1;
4297
Etan Cohend3652192014-06-20 08:28:44 -07004298 RLOGI("s_registerCalled flag set, %d", s_started);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004299 // Little self-check
4300
Wink Savillef4c4d362009-04-02 01:37:03 -07004301 for (int i = 0; i < (int)NUM_ELEMS(s_commands); i++) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004302 assert(i == s_commands[i].requestNumber);
4303 }
4304
Wink Savillef4c4d362009-04-02 01:37:03 -07004305 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses); i++) {
Wink Saville7f856802009-06-09 10:23:37 -07004306 assert(i + RIL_UNSOL_RESPONSE_BASE
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004307 == s_unsolResponses[i].requestNumber);
4308 }
4309
4310 // New rild impl calls RIL_startEventLoop() first
4311 // old standalone impl wants it here.
4312
4313 if (s_started == 0) {
4314 RIL_startEventLoop();
4315 }
4316
Etan Cohend3652192014-06-20 08:28:44 -07004317 // start listen socket1
4318 startListen(RIL_SOCKET_1, &s_ril_param_socket);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004319
Etan Cohend3652192014-06-20 08:28:44 -07004320#if (SIM_COUNT >= 2)
4321 // start listen socket2
4322 startListen(RIL_SOCKET_2, &s_ril_param_socket2);
4323#endif /* (SIM_COUNT == 2) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004324
Etan Cohend3652192014-06-20 08:28:44 -07004325#if (SIM_COUNT >= 3)
4326 // start listen socket3
4327 startListen(RIL_SOCKET_3, &s_ril_param_socket3);
4328#endif /* (SIM_COUNT == 3) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004329
Etan Cohend3652192014-06-20 08:28:44 -07004330#if (SIM_COUNT >= 4)
4331 // start listen socket4
4332 startListen(RIL_SOCKET_4, &s_ril_param_socket4);
4333#endif /* (SIM_COUNT == 4) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004334
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004335
4336#if 1
4337 // start debug interface socket
4338
Etan Cohend3652192014-06-20 08:28:44 -07004339 char *inst = NULL;
4340 if (strlen(RIL_getRilSocketName()) >= strlen(SOCKET_NAME_RIL)) {
4341 inst = RIL_getRilSocketName() + strlen(SOCKET_NAME_RIL);
4342 }
4343
4344 char rildebug[MAX_DEBUG_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL_DEBUG;
4345 if (inst != NULL) {
Nick Kralevichc52e45e2015-02-08 07:54:16 -08004346 strlcat(rildebug, inst, MAX_DEBUG_SOCKET_NAME_LENGTH);
Etan Cohend3652192014-06-20 08:28:44 -07004347 }
4348
4349 s_fdDebug = android_get_control_socket(rildebug);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004350 if (s_fdDebug < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07004351 RLOGE("Failed to get socket : %s errno:%d", rildebug, errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004352 exit(-1);
4353 }
4354
4355 ret = listen(s_fdDebug, 4);
4356
4357 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004358 RLOGE("Failed to listen on ril debug socket '%d': %s",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004359 s_fdDebug, strerror(errno));
4360 exit(-1);
4361 }
4362
4363 ril_event_set (&s_debug_event, s_fdDebug, true,
4364 debugCallback, NULL);
4365
4366 rilEventAddWakeup (&s_debug_event);
4367#endif
4368
4369}
4370
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004371extern "C" void
4372RIL_register_socket (RIL_RadioFunctions *(*Init)(const struct RIL_Env *, int, char **),RIL_SOCKET_TYPE socketType, int argc, char **argv) {
4373
4374 RIL_RadioFunctions* UimFuncs = NULL;
4375
4376 if(Init) {
4377 UimFuncs = Init(&RilSapSocket::uimRilEnv, argc, argv);
4378
4379 switch(socketType) {
4380 case RIL_SAP_SOCKET:
4381 RilSapSocket::initSapSocket("sap_uim_socket1", UimFuncs);
4382
4383#if (SIM_COUNT >= 2)
4384 RilSapSocket::initSapSocket("sap_uim_socket2", UimFuncs);
4385#endif
4386
4387#if (SIM_COUNT >= 3)
4388 RilSapSocket::initSapSocket("sap_uim_socket3", UimFuncs);
4389#endif
4390
4391#if (SIM_COUNT >= 4)
4392 RilSapSocket::initSapSocket("sap_uim_socket4", UimFuncs);
4393#endif
4394 }
4395 }
4396}
4397
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004398static int
Wink Savillef4c4d362009-04-02 01:37:03 -07004399checkAndDequeueRequestInfo(struct RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004400 int ret = 0;
Etan Cohend3652192014-06-20 08:28:44 -07004401 /* Hook for current context
4402 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
4403 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
4404 /* pendingRequestsHook refer to &s_pendingRequests */
4405 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
Wink Saville7f856802009-06-09 10:23:37 -07004406
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004407 if (pRI == NULL) {
4408 return 0;
4409 }
4410
Etan Cohend3652192014-06-20 08:28:44 -07004411#if (SIM_COUNT >= 2)
4412 if (pRI->socket_id == RIL_SOCKET_2) {
4413 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
4414 pendingRequestsHook = &s_pendingRequests_socket2;
4415 }
4416#if (SIM_COUNT >= 3)
4417 if (pRI->socket_id == RIL_SOCKET_3) {
4418 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
4419 pendingRequestsHook = &s_pendingRequests_socket3;
4420 }
4421#endif
4422#if (SIM_COUNT >= 4)
4423 if (pRI->socket_id == RIL_SOCKET_4) {
4424 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
4425 pendingRequestsHook = &s_pendingRequests_socket4;
4426 }
4427#endif
4428#endif
4429 pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004430
Etan Cohend3652192014-06-20 08:28:44 -07004431 for(RequestInfo **ppCur = pendingRequestsHook
Wink Saville7f856802009-06-09 10:23:37 -07004432 ; *ppCur != NULL
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004433 ; ppCur = &((*ppCur)->p_next)
4434 ) {
4435 if (pRI == *ppCur) {
4436 ret = 1;
4437
4438 *ppCur = (*ppCur)->p_next;
4439 break;
4440 }
4441 }
4442
Etan Cohend3652192014-06-20 08:28:44 -07004443 pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004444
4445 return ret;
4446}
4447
4448
4449extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07004450RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004451 RequestInfo *pRI;
4452 int ret;
Etan Cohend3652192014-06-20 08:28:44 -07004453 int fd = s_ril_param_socket.fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004454 size_t errorOffset;
Etan Cohend3652192014-06-20 08:28:44 -07004455 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004456
4457 pRI = (RequestInfo *)t;
4458
Jayachandran C6c607592014-08-04 15:48:01 -07004459 if (!checkAndDequeueRequestInfo(pRI)) {
4460 RLOGE ("RIL_onRequestComplete: invalid RIL_Token");
4461 return;
4462 }
4463
Etan Cohend3652192014-06-20 08:28:44 -07004464 socket_id = pRI->socket_id;
4465#if (SIM_COUNT >= 2)
4466 if (socket_id == RIL_SOCKET_2) {
4467 fd = s_ril_param_socket2.fdCommand;
4468 }
4469#if (SIM_COUNT >= 3)
4470 if (socket_id == RIL_SOCKET_3) {
4471 fd = s_ril_param_socket3.fdCommand;
4472 }
4473#endif
4474#if (SIM_COUNT >= 4)
4475 if (socket_id == RIL_SOCKET_4) {
4476 fd = s_ril_param_socket4.fdCommand;
4477 }
4478#endif
4479#endif
4480 RLOGD("RequestComplete, %s", rilSocketIdToString(socket_id));
4481
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004482 if (pRI->local > 0) {
4483 // Locally issued command...void only!
4484 // response does not go back up the command socket
Wink Saville8eb2a122012-11-19 16:05:13 -08004485 RLOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004486
4487 goto done;
4488 }
4489
4490 appendPrintBuf("[%04d]< %s",
4491 pRI->token, requestToString(pRI->pCI->requestNumber));
4492
4493 if (pRI->cancelled == 0) {
4494 Parcel p;
4495
4496 p.writeInt32 (RESPONSE_SOLICITED);
4497 p.writeInt32 (pRI->token);
4498 errorOffset = p.dataPosition();
4499
4500 p.writeInt32 (e);
4501
johnwangb2a61842009-06-02 14:55:45 -07004502 if (response != NULL) {
4503 // there is a response payload, no matter success or not.
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004504 ret = pRI->pCI->responseFunction(p, response, responselen);
4505
4506 /* if an error occurred, rewind and mark it */
4507 if (ret != 0) {
Etan Cohend3652192014-06-20 08:28:44 -07004508 RLOGE ("responseFunction error, ret %d", ret);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004509 p.setDataPosition(errorOffset);
4510 p.writeInt32 (ret);
4511 }
johnwangb2a61842009-06-02 14:55:45 -07004512 }
4513
4514 if (e != RIL_E_SUCCESS) {
4515 appendPrintBuf("%s fails by %s", printBuf, failCauseToString(e));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004516 }
4517
Etan Cohend3652192014-06-20 08:28:44 -07004518 if (fd < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004519 RLOGD ("RIL onRequestComplete: Command channel closed");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004520 }
Etan Cohend3652192014-06-20 08:28:44 -07004521 sendResponse(p, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004522 }
4523
4524done:
4525 free(pRI);
4526}
4527
4528
4529static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004530grabPartialWakeLock() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004531 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
4532}
4533
4534static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004535releaseWakeLock() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004536 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
4537}
4538
4539/**
4540 * Timer callback to put us back to sleep before the default timeout
4541 */
4542static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004543wakeTimeoutCallback (void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004544 // We're using "param != NULL" as a cancellation mechanism
4545 if (param == NULL) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004546 releaseWakeLock();
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004547 }
4548}
4549
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004550static int
4551decodeVoiceRadioTechnology (RIL_RadioState radioState) {
4552 switch (radioState) {
4553 case RADIO_STATE_SIM_NOT_READY:
4554 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4555 case RADIO_STATE_SIM_READY:
4556 return RADIO_TECH_UMTS;
4557
4558 case RADIO_STATE_RUIM_NOT_READY:
4559 case RADIO_STATE_RUIM_READY:
4560 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4561 case RADIO_STATE_NV_NOT_READY:
4562 case RADIO_STATE_NV_READY:
4563 return RADIO_TECH_1xRTT;
4564
4565 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004566 RLOGD("decodeVoiceRadioTechnology: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004567 return -1;
4568 }
4569}
4570
4571static int
4572decodeCdmaSubscriptionSource (RIL_RadioState radioState) {
4573 switch (radioState) {
4574 case RADIO_STATE_SIM_NOT_READY:
4575 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4576 case RADIO_STATE_SIM_READY:
4577 case RADIO_STATE_RUIM_NOT_READY:
4578 case RADIO_STATE_RUIM_READY:
4579 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4580 return CDMA_SUBSCRIPTION_SOURCE_RUIM_SIM;
4581
4582 case RADIO_STATE_NV_NOT_READY:
4583 case RADIO_STATE_NV_READY:
4584 return CDMA_SUBSCRIPTION_SOURCE_NV;
4585
4586 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004587 RLOGD("decodeCdmaSubscriptionSource: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004588 return -1;
4589 }
4590}
4591
4592static int
4593decodeSimStatus (RIL_RadioState radioState) {
4594 switch (radioState) {
4595 case RADIO_STATE_SIM_NOT_READY:
4596 case RADIO_STATE_RUIM_NOT_READY:
4597 case RADIO_STATE_NV_NOT_READY:
4598 case RADIO_STATE_NV_READY:
4599 return -1;
4600 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4601 case RADIO_STATE_SIM_READY:
4602 case RADIO_STATE_RUIM_READY:
4603 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4604 return radioState;
4605 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004606 RLOGD("decodeSimStatus: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004607 return -1;
4608 }
4609}
4610
4611static bool is3gpp2(int radioTech) {
4612 switch (radioTech) {
4613 case RADIO_TECH_IS95A:
4614 case RADIO_TECH_IS95B:
4615 case RADIO_TECH_1xRTT:
4616 case RADIO_TECH_EVDO_0:
4617 case RADIO_TECH_EVDO_A:
4618 case RADIO_TECH_EVDO_B:
4619 case RADIO_TECH_EHRPD:
4620 return true;
4621 default:
4622 return false;
4623 }
4624}
4625
4626/* If RIL sends SIM states or RUIM states, store the voice radio
4627 * technology and subscription source information so that they can be
4628 * returned when telephony framework requests them
4629 */
4630static RIL_RadioState
Etan Cohend3652192014-06-20 08:28:44 -07004631processRadioState(RIL_RadioState newRadioState, RIL_SOCKET_ID socket_id) {
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004632
4633 if((newRadioState > RADIO_STATE_UNAVAILABLE) && (newRadioState < RADIO_STATE_ON)) {
4634 int newVoiceRadioTech;
4635 int newCdmaSubscriptionSource;
4636 int newSimStatus;
4637
4638 /* This is old RIL. Decode Subscription source and Voice Radio Technology
4639 from Radio State and send change notifications if there has been a change */
4640 newVoiceRadioTech = decodeVoiceRadioTechnology(newRadioState);
4641 if(newVoiceRadioTech != voiceRadioTech) {
4642 voiceRadioTech = newVoiceRadioTech;
Etan Cohend3652192014-06-20 08:28:44 -07004643 RIL_UNSOL_RESPONSE(RIL_UNSOL_VOICE_RADIO_TECH_CHANGED,
4644 &voiceRadioTech, sizeof(voiceRadioTech), socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004645 }
4646 if(is3gpp2(newVoiceRadioTech)) {
4647 newCdmaSubscriptionSource = decodeCdmaSubscriptionSource(newRadioState);
4648 if(newCdmaSubscriptionSource != cdmaSubscriptionSource) {
4649 cdmaSubscriptionSource = newCdmaSubscriptionSource;
Etan Cohend3652192014-06-20 08:28:44 -07004650 RIL_UNSOL_RESPONSE(RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED,
4651 &cdmaSubscriptionSource, sizeof(cdmaSubscriptionSource), socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004652 }
4653 }
4654 newSimStatus = decodeSimStatus(newRadioState);
4655 if(newSimStatus != simRuimStatus) {
4656 simRuimStatus = newSimStatus;
Etan Cohend3652192014-06-20 08:28:44 -07004657 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0, socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004658 }
4659
4660 /* Send RADIO_ON to telephony */
4661 newRadioState = RADIO_STATE_ON;
4662 }
4663
4664 return newRadioState;
4665}
4666
Etan Cohend3652192014-06-20 08:28:44 -07004667
4668#if defined(ANDROID_MULTI_SIM)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004669extern "C"
Bernhard Rosenkränzerd613b962014-11-17 20:52:09 +01004670void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Etan Cohend3652192014-06-20 08:28:44 -07004671 size_t datalen, RIL_SOCKET_ID socket_id)
4672#else
4673extern "C"
Bernhard Rosenkränzerd613b962014-11-17 20:52:09 +01004674void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004675 size_t datalen)
Etan Cohend3652192014-06-20 08:28:44 -07004676#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004677{
4678 int unsolResponseIndex;
4679 int ret;
4680 int64_t timeReceived = 0;
4681 bool shouldScheduleTimeout = false;
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004682 RIL_RadioState newState;
Etan Cohend3652192014-06-20 08:28:44 -07004683 RIL_SOCKET_ID soc_id = RIL_SOCKET_1;
4684
4685#if defined(ANDROID_MULTI_SIM)
4686 soc_id = socket_id;
4687#endif
4688
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004689
4690 if (s_registerCalled == 0) {
4691 // Ignore RIL_onUnsolicitedResponse before RIL_register
Wink Saville8eb2a122012-11-19 16:05:13 -08004692 RLOGW("RIL_onUnsolicitedResponse called before RIL_register");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004693 return;
4694 }
Wink Saville7f856802009-06-09 10:23:37 -07004695
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004696 unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
4697
4698 if ((unsolResponseIndex < 0)
4699 || (unsolResponseIndex >= (int32_t)NUM_ELEMS(s_unsolResponses))) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004700 RLOGE("unsupported unsolicited response code %d", unsolResponse);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004701 return;
4702 }
4703
4704 // Grab a wake lock if needed for this reponse,
4705 // as we exit we'll either release it immediately
4706 // or set a timer to release it later.
4707 switch (s_unsolResponses[unsolResponseIndex].wakeType) {
4708 case WAKE_PARTIAL:
4709 grabPartialWakeLock();
4710 shouldScheduleTimeout = true;
4711 break;
4712
4713 case DONT_WAKE:
4714 default:
4715 // No wake lock is grabed so don't set timeout
4716 shouldScheduleTimeout = false;
4717 break;
4718 }
4719
4720 // Mark the time this was received, doing this
4721 // after grabing the wakelock incase getting
4722 // the elapsedRealTime might cause us to goto
4723 // sleep.
4724 if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4725 timeReceived = elapsedRealtime();
4726 }
4727
4728 appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
4729
4730 Parcel p;
4731
4732 p.writeInt32 (RESPONSE_UNSOLICITED);
4733 p.writeInt32 (unsolResponse);
4734
4735 ret = s_unsolResponses[unsolResponseIndex]
Bernhard Rosenkränzer6e7c1962013-12-12 10:01:10 +01004736 .responseFunction(p, const_cast<void*>(data), datalen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004737 if (ret != 0) {
4738 // Problem with the response. Don't continue;
4739 goto error_exit;
4740 }
4741
4742 // some things get more payload
4743 switch(unsolResponse) {
4744 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
Etan Cohend3652192014-06-20 08:28:44 -07004745 newState = processRadioState(CALL_ONSTATEREQUEST(soc_id), soc_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004746 p.writeInt32(newState);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004747 appendPrintBuf("%s {%s}", printBuf,
Etan Cohend3652192014-06-20 08:28:44 -07004748 radioStateToString(CALL_ONSTATEREQUEST(soc_id)));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004749 break;
4750
4751
4752 case RIL_UNSOL_NITZ_TIME_RECEIVED:
4753 // Store the time that this was received so the
4754 // handler of this message can account for
4755 // the time it takes to arrive and process. In
4756 // particular the system has been known to sleep
4757 // before this message can be processed.
4758 p.writeInt64(timeReceived);
4759 break;
4760 }
4761
Etan Cohend3652192014-06-20 08:28:44 -07004762 RLOGI("%s UNSOLICITED: %s length:%d", rilSocketIdToString(soc_id), requestToString(unsolResponse), p.dataSize());
4763 ret = sendResponse(p, soc_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004764 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4765
4766 // Unfortunately, NITZ time is not poll/update like everything
4767 // else in the system. So, if the upstream client isn't connected,
4768 // keep a copy of the last NITZ response (with receive time noted
4769 // above) around so we can deliver it when it is connected
4770
4771 if (s_lastNITZTimeData != NULL) {
4772 free (s_lastNITZTimeData);
4773 s_lastNITZTimeData = NULL;
4774 }
4775
4776 s_lastNITZTimeData = malloc(p.dataSize());
4777 s_lastNITZTimeDataSize = p.dataSize();
4778 memcpy(s_lastNITZTimeData, p.data(), p.dataSize());
4779 }
4780
4781 // For now, we automatically go back to sleep after TIMEVAL_WAKE_TIMEOUT
4782 // FIXME The java code should handshake here to release wake lock
4783
4784 if (shouldScheduleTimeout) {
4785 // Cancel the previous request
4786 if (s_last_wake_timeout_info != NULL) {
4787 s_last_wake_timeout_info->userParam = (void *)1;
4788 }
4789
4790 s_last_wake_timeout_info
4791 = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
4792 &TIMEVAL_WAKE_TIMEOUT);
4793 }
4794
4795 // Normal exit
4796 return;
4797
4798error_exit:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004799 if (shouldScheduleTimeout) {
4800 releaseWakeLock();
4801 }
4802}
4803
Wink Saville7f856802009-06-09 10:23:37 -07004804/** FIXME generalize this if you track UserCAllbackInfo, clear it
4805 when the callback occurs
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004806*/
4807static UserCallbackInfo *
Wink Saville7f856802009-06-09 10:23:37 -07004808internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004809 const struct timeval *relativeTime)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004810{
4811 struct timeval myRelativeTime;
4812 UserCallbackInfo *p_info;
4813
4814 p_info = (UserCallbackInfo *) malloc (sizeof(UserCallbackInfo));
4815
Wink Saville7f856802009-06-09 10:23:37 -07004816 p_info->p_callback = callback;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004817 p_info->userParam = param;
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004818
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004819 if (relativeTime == NULL) {
4820 /* treat null parameter as a 0 relative time */
4821 memset (&myRelativeTime, 0, sizeof(myRelativeTime));
4822 } else {
4823 /* FIXME I think event_add's tv param is really const anyway */
4824 memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
4825 }
4826
4827 ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
4828
4829 ril_timer_add(&(p_info->event), &myRelativeTime);
4830
4831 triggerEvLoop();
4832 return p_info;
4833}
4834
Naveen Kalla7edd07c2010-06-21 18:54:47 -07004835
4836extern "C" void
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004837RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
4838 const struct timeval *relativeTime) {
4839 internalRequestTimedCallback (callback, param, relativeTime);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004840}
4841
4842const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004843failCauseToString(RIL_Errno e) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004844 switch(e) {
4845 case RIL_E_SUCCESS: return "E_SUCCESS";
Robert Greenwalt2126ab22013-04-09 12:20:45 -07004846 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RADIO_NOT_AVAILABLE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004847 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
4848 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
4849 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
4850 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
4851 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
4852 case RIL_E_CANCELLED: return "E_CANCELLED";
4853 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
4854 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
4855 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
Wink Savillef4c4d362009-04-02 01:37:03 -07004856 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
John Wang75534472010-04-20 15:11:42 -07004857 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
Wink Saville7f856802009-06-09 10:23:37 -07004858#ifdef FEATURE_MULTIMODE_ANDROID
Wink Savillef4c4d362009-04-02 01:37:03 -07004859 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
4860 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
4861#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004862 default: return "<unknown error>";
4863 }
4864}
4865
4866const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004867radioStateToString(RIL_RadioState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004868 switch(s) {
4869 case RADIO_STATE_OFF: return "RADIO_OFF";
4870 case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
4871 case RADIO_STATE_SIM_NOT_READY: return "RADIO_SIM_NOT_READY";
4872 case RADIO_STATE_SIM_LOCKED_OR_ABSENT: return "RADIO_SIM_LOCKED_OR_ABSENT";
4873 case RADIO_STATE_SIM_READY: return "RADIO_SIM_READY";
Wink Savillef4c4d362009-04-02 01:37:03 -07004874 case RADIO_STATE_RUIM_NOT_READY:return"RADIO_RUIM_NOT_READY";
4875 case RADIO_STATE_RUIM_READY:return"RADIO_RUIM_READY";
4876 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:return"RADIO_RUIM_LOCKED_OR_ABSENT";
4877 case RADIO_STATE_NV_NOT_READY:return"RADIO_NV_NOT_READY";
4878 case RADIO_STATE_NV_READY:return"RADIO_NV_READY";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004879 case RADIO_STATE_ON:return"RADIO_ON";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004880 default: return "<unknown state>";
4881 }
4882}
4883
4884const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004885callStateToString(RIL_CallState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004886 switch(s) {
4887 case RIL_CALL_ACTIVE : return "ACTIVE";
4888 case RIL_CALL_HOLDING: return "HOLDING";
4889 case RIL_CALL_DIALING: return "DIALING";
4890 case RIL_CALL_ALERTING: return "ALERTING";
4891 case RIL_CALL_INCOMING: return "INCOMING";
4892 case RIL_CALL_WAITING: return "WAITING";
4893 default: return "<unknown state>";
4894 }
4895}
4896
4897const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004898requestToString(int request) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004899/*
4900 cat libs/telephony/ril_commands.h \
4901 | egrep "^ *{RIL_" \
4902 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
4903
4904
4905 cat libs/telephony/ril_unsol_commands.h \
4906 | egrep "^ *{RIL_" \
4907 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
4908
4909*/
4910 switch(request) {
4911 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
4912 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
4913 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
4914 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
4915 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
4916 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
4917 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
4918 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
4919 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
4920 case RIL_REQUEST_DIAL: return "DIAL";
4921 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
4922 case RIL_REQUEST_HANGUP: return "HANGUP";
4923 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
4924 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
4925 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
4926 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
4927 case RIL_REQUEST_UDUB: return "UDUB";
4928 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
4929 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
Wink Savillec0114b32011-02-18 10:14:07 -08004930 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
4931 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004932 case RIL_REQUEST_OPERATOR: return "OPERATOR";
4933 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
4934 case RIL_REQUEST_DTMF: return "DTMF";
4935 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
4936 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
Wink Savillef4c4d362009-04-02 01:37:03 -07004937 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004938 case RIL_REQUEST_SIM_IO: return "SIM_IO";
4939 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
4940 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
4941 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
4942 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
4943 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
4944 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
4945 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
4946 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
4947 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
4948 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
4949 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
4950 case RIL_REQUEST_ANSWER: return "ANSWER";
Wink Savillef4c4d362009-04-02 01:37:03 -07004951 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004952 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
4953 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
4954 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
4955 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
4956 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
4957 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
4958 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";
4959 case RIL_REQUEST_DTMF_START: return "DTMF_START";
4960 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
4961 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
4962 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
4963 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
4964 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
4965 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
4966 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
4967 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
4968 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
Wink Savillef4c4d362009-04-02 01:37:03 -07004969 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
4970 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004971 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
4972 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
4973 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
Wink Savillef4c4d362009-04-02 01:37:03 -07004974 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
4975 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004976 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
4977 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
4978 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
4979 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
4980 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
4981 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
4982 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
4983 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
Wink Savillec0114b32011-02-18 10:14:07 -08004984 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE:return"CDMA_SET_SUBSCRIPTION_SOURCE";
Wink Savillef4c4d362009-04-02 01:37:03 -07004985 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"CDMA_SET_ROAMING_PREFERENCE";
4986 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"CDMA_QUERY_ROAMING_PREFERENCE";
4987 case RIL_REQUEST_SET_TTY_MODE:return"SET_TTY_MODE";
4988 case RIL_REQUEST_QUERY_TTY_MODE:return"QUERY_TTY_MODE";
4989 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
4990 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
4991 case RIL_REQUEST_CDMA_FLASH:return"CDMA_FLASH";
4992 case RIL_REQUEST_CDMA_BURST_DTMF:return"CDMA_BURST_DTMF";
4993 case RIL_REQUEST_CDMA_SEND_SMS:return"CDMA_SEND_SMS";
4994 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:return"CDMA_SMS_ACKNOWLEDGE";
Wink Savillea592eeb2009-05-22 13:26:36 -07004995 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG:return"GSM_GET_BROADCAST_SMS_CONFIG";
4996 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG:return"GSM_SET_BROADCAST_SMS_CONFIG";
4997 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG:return "CDMA_GET_BROADCAST_SMS_CONFIG";
4998 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG:return "CDMA_SET_BROADCAST_SMS_CONFIG";
4999 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION:return "CDMA_SMS_BROADCAST_ACTIVATION";
Naveen Kalla03c1edf2009-09-23 11:18:35 -07005000 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return"CDMA_VALIDATE_AND_WRITE_AKEY";
Wink Savillef4c4d362009-04-02 01:37:03 -07005001 case RIL_REQUEST_CDMA_SUBSCRIPTION: return"CDMA_SUBSCRIPTION";
5002 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
5003 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
5004 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
jsh000a9fe2009-05-11 14:52:35 -07005005 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
5006 case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
5007 case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
jsh09a68ba2009-06-10 11:56:38 -07005008 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
jsh563fd722010-06-08 16:52:24 -07005009 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
Wink Savillec0114b32011-02-18 10:14:07 -08005010 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
Jake Hambyfa8d5842011-08-19 16:22:18 -07005011 case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
Jake Hamby300105d2011-09-26 01:01:44 -07005012 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
5013 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005014 case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
Wink Saville8a9e0212013-04-09 12:11:38 -07005015 case RIL_REQUEST_GET_CELL_INFO_LIST: return"GET_CELL_INFO_LIST";
5016 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return"SET_UNSOL_CELL_INFO_LIST_RATE";
Sungmin Choi75697532013-04-26 15:04:45 -07005017 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "RIL_REQUEST_SET_INITIAL_ATTACH_APN";
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07005018 case RIL_REQUEST_IMS_REGISTRATION_STATE: return "IMS_REGISTRATION_STATE";
5019 case RIL_REQUEST_IMS_SEND_SMS: return "IMS_SEND_SMS";
Shishir Agrawal2458d8d2013-11-27 14:53:05 -08005020 case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "SIM_TRANSMIT_APDU_BASIC";
5021 case RIL_REQUEST_SIM_OPEN_CHANNEL: return "SIM_OPEN_CHANNEL";
5022 case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "SIM_CLOSE_CHANNEL";
5023 case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "SIM_TRANSMIT_APDU_CHANNEL";
Wink Saville8b4e4f72014-10-17 15:01:45 -07005024 case RIL_REQUEST_GET_RADIO_CAPABILITY: return "RIL_REQUEST_GET_RADIO_CAPABILITY";
5025 case RIL_REQUEST_SET_RADIO_CAPABILITY: return "RIL_REQUEST_SET_RADIO_CAPABILITY";
Etan Cohend3652192014-06-20 08:28:44 -07005026 case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "SET_UICC_SUBSCRIPTION";
5027 case RIL_REQUEST_ALLOW_DATA: return "ALLOW_DATA";
Amit Mahajan2b772032014-06-26 14:20:11 -07005028 case RIL_REQUEST_GET_HARDWARE_CONFIG: return "GET_HARDWARE_CONFIG";
5029 case RIL_REQUEST_SIM_AUTHENTICATION: return "SIM_AUTHENTICATION";
Wink Savillec29360a2014-07-13 05:17:28 -07005030 case RIL_REQUEST_GET_DC_RT_INFO: return "GET_DC_RT_INFO";
5031 case RIL_REQUEST_SET_DC_RT_INFO_RATE: return "SET_DC_RT_INFO_RATE";
Amit Mahajanc796e222014-08-13 16:54:01 +00005032 case RIL_REQUEST_SET_DATA_PROFILE: return "SET_DATA_PROFILE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005033 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
5034 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08005035 case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005036 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
5037 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
5038 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
5039 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
5040 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)";
5041 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
5042 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
5043 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
5044 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
5045 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
5046 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
5047 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL";
5048 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
Wink Savillef4c4d362009-04-02 01:37:03 -07005049 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005050 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
Wink Savillef4c4d362009-04-02 01:37:03 -07005051 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
5052 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_NEW_CDMA_SMS";
5053 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_NEW_BROADCAST_SMS";
5054 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
Wink Saville3d54e742009-05-18 18:00:44 -07005055 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
5056 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
5057 case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
5058 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
5059 case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
Jaikumar Ganeshaf6ecbf2009-04-29 13:27:51 -07005060 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
John Wang5d621da2009-09-18 17:17:48 -07005061 case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
John Wang5909cf82010-01-29 00:18:54 -08005062 case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
Wink Savilleee274582011-04-16 15:05:49 -07005063 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08005064 case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
5065 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
Wink Saville5b9df332011-04-06 16:24:21 -07005066 case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005067 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
Wink Saville8a9e0212013-04-09 12:11:38 -07005068 case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07005069 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "RESPONSE_IMS_NETWORK_STATE_CHANGED";
Etan Cohend3652192014-06-20 08:28:44 -07005070 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return "UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED";
5071 case RIL_UNSOL_SRVCC_STATE_NOTIFY: return "UNSOL_SRVCC_STATE_NOTIFY";
5072 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return "HARDWARE_CONFIG_CHANGED";
Wink Savillec29360a2014-07-13 05:17:28 -07005073 case RIL_UNSOL_DC_RT_INFO_CHANGED: return "UNSOL_DC_RT_INFO_CHANGED";
Naveen Kallaa65a16a2014-07-31 16:48:31 -07005074 case RIL_REQUEST_SHUTDOWN: return "SHUTDOWN";
Wink Saville8b4e4f72014-10-17 15:01:45 -07005075 case RIL_UNSOL_RADIO_CAPABILITY: return "RIL_UNSOL_RADIO_CAPABILITY";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005076 default: return "<unknown request>";
5077 }
5078}
5079
Etan Cohend3652192014-06-20 08:28:44 -07005080const char *
5081rilSocketIdToString(RIL_SOCKET_ID socket_id)
5082{
5083 switch(socket_id) {
5084 case RIL_SOCKET_1:
5085 return "RIL_SOCKET_1";
5086#if (SIM_COUNT >= 2)
5087 case RIL_SOCKET_2:
5088 return "RIL_SOCKET_2";
5089#endif
5090#if (SIM_COUNT >= 3)
5091 case RIL_SOCKET_3:
5092 return "RIL_SOCKET_3";
5093#endif
5094#if (SIM_COUNT >= 4)
5095 case RIL_SOCKET_4:
5096 return "RIL_SOCKET_4";
5097#endif
5098 default:
5099 return "not a valid RIL";
5100 }
5101}
5102
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005103} /* namespace android */
Dheeraj Shetty27976c42014-07-02 21:27:57 +02005104
5105void rilEventAddWakeup_helper(struct ril_event *ev) {
5106 android::rilEventAddWakeup(ev);
5107}
5108
5109void listenCallback_helper(int fd, short flags, void *param) {
5110 android::listenCallback(fd, flags, param);
5111}
5112
5113int blockingWrite_helper(int fd, void *buffer, size_t len) {
5114 return android::blockingWrite(fd, buffer, len);
5115}