blob: 052399eaef82fff326be213bcdd22efaaedfdf5a [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);
297
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800298static int decodeVoiceRadioTechnology (RIL_RadioState radioState);
299static int decodeCdmaSubscriptionSource (RIL_RadioState radioState);
300static RIL_RadioState processRadioState(RIL_RadioState newRadioState);
301
Amit Mahajan54563d32014-11-22 00:54:49 +0000302static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType);
303
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800304#ifdef RIL_SHLIB
Etan Cohend3652192014-06-20 08:28:44 -0700305#if defined(ANDROID_MULTI_SIM)
Vinit Deshpande1b1ec2d2015-04-15 13:31:05 -0700306extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Etan Cohend3652192014-06-20 08:28:44 -0700307 size_t datalen, RIL_SOCKET_ID socket_id);
308#else
Vinit Deshpande1b1ec2d2015-04-15 13:31:05 -0700309extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800310 size_t datalen);
311#endif
Etan Cohend3652192014-06-20 08:28:44 -0700312#endif
313
314#if defined(ANDROID_MULTI_SIM)
315#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c), (d))
316#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d), (e))
317#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest(a)
318#else
319#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c))
320#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d))
321#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest()
322#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800323
Wink Saville7f856802009-06-09 10:23:37 -0700324static UserCallbackInfo * internalRequestTimedCallback
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -0700325 (RIL_TimedCallback callback, void *param,
326 const struct timeval *relativeTime);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800327
328/** Index == requestNumber */
329static CommandInfo s_commands[] = {
330#include "ril_commands.h"
331};
332
333static UnsolResponseInfo s_unsolResponses[] = {
334#include "ril_unsol_commands.h"
335};
336
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800337/* For older RILs that do not support new commands RIL_REQUEST_VOICE_RADIO_TECH and
338 RIL_UNSOL_VOICE_RADIO_TECH_CHANGED messages, decode the voice radio tech from
339 radio state message and store it. Every time there is a change in Radio State
340 check to see if voice radio tech changes and notify telephony
341 */
342int voiceRadioTech = -1;
343
344/* For older RILs that do not support new commands RIL_REQUEST_GET_CDMA_SUBSCRIPTION_SOURCE
345 and RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED messages, decode the subscription
346 source from radio state and store it. Every time there is a change in Radio State
347 check to see if subscription source changed and notify telephony
348 */
349int cdmaSubscriptionSource = -1;
350
351/* For older RILs that do not send RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, decode the
352 SIM/RUIM state from radio state and store it. Every time there is a change in Radio State,
353 check to see if SIM/RUIM status changed and notify telephony
354 */
355int simRuimStatus = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800356
Etan Cohend3652192014-06-20 08:28:44 -0700357static char * RIL_getRilSocketName() {
358 return rild;
359}
360
361extern "C"
Dheeraj Shetty27976c42014-07-02 21:27:57 +0200362void RIL_setRilSocketName(const char * s) {
Etan Cohend3652192014-06-20 08:28:44 -0700363 strncpy(rild, s, MAX_SOCKET_NAME_LENGTH);
364}
365
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800366static char *
Wink Savillef4c4d362009-04-02 01:37:03 -0700367strdupReadString(Parcel &p) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800368 size_t stringlen;
369 const char16_t *s16;
Wink Saville7f856802009-06-09 10:23:37 -0700370
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800371 s16 = p.readString16Inplace(&stringlen);
Wink Saville7f856802009-06-09 10:23:37 -0700372
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800373 return strndup16to8(s16, stringlen);
374}
375
Wink Saville8b4e4f72014-10-17 15:01:45 -0700376static status_t
377readStringFromParcelInplace(Parcel &p, char *str, size_t maxLen) {
378 size_t s16Len;
379 const char16_t *s16;
380
381 s16 = p.readString16Inplace(&s16Len);
382 if (s16 == NULL) {
383 return NO_MEMORY;
384 }
385 size_t strLen = strnlen16to8(s16, s16Len);
386 if ((strLen + 1) > maxLen) {
387 return NO_MEMORY;
388 }
389 if (strncpy16to8(str, s16, strLen) == NULL) {
390 return NO_MEMORY;
391 } else {
392 return NO_ERROR;
393 }
394}
395
Wink Savillef4c4d362009-04-02 01:37:03 -0700396static void writeStringToParcel(Parcel &p, const char *s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800397 char16_t *s16;
398 size_t s16_len;
399 s16 = strdup8to16(s, &s16_len);
400 p.writeString16(s16, s16_len);
401 free(s16);
402}
403
404
405static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700406memsetString (char *s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800407 if (s != NULL) {
408 memset (s, 0, strlen(s));
409 }
410}
411
412void nullParcelReleaseFunction (const uint8_t* data, size_t dataSize,
413 const size_t* objects, size_t objectsSize,
Wink Savillef4c4d362009-04-02 01:37:03 -0700414 void* cookie) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800415 // do nothing -- the data reference lives longer than the Parcel object
416}
417
Wink Saville7f856802009-06-09 10:23:37 -0700418/**
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800419 * To be called from dispatch thread
420 * Issue a single local request, ensuring that the response
Wink Saville7f856802009-06-09 10:23:37 -0700421 * is not sent back up to the command process
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800422 */
423static void
Etan Cohend3652192014-06-20 08:28:44 -0700424issueLocalRequest(int request, void *data, int len, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800425 RequestInfo *pRI;
426 int ret;
Etan Cohend3652192014-06-20 08:28:44 -0700427 /* Hook for current context */
428 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
429 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
430 /* pendingRequestsHook refer to &s_pendingRequests */
431 RequestInfo** pendingRequestsHook = &s_pendingRequests;
432
433#if (SIM_COUNT == 2)
434 if (socket_id == RIL_SOCKET_2) {
435 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
436 pendingRequestsHook = &s_pendingRequests_socket2;
437 }
438#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800439
440 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
441
442 pRI->local = 1;
443 pRI->token = 0xffffffff; // token is not used in this context
444 pRI->pCI = &(s_commands[request]);
Etan Cohend3652192014-06-20 08:28:44 -0700445 pRI->socket_id = socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800446
Etan Cohend3652192014-06-20 08:28:44 -0700447 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800448 assert (ret == 0);
449
Etan Cohend3652192014-06-20 08:28:44 -0700450 pRI->p_next = *pendingRequestsHook;
451 *pendingRequestsHook = pRI;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800452
Etan Cohend3652192014-06-20 08:28:44 -0700453 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800454 assert (ret == 0);
455
Wink Saville8eb2a122012-11-19 16:05:13 -0800456 RLOGD("C[locl]> %s", requestToString(request));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800457
Etan Cohend3652192014-06-20 08:28:44 -0700458 CALL_ONREQUEST(request, data, len, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800459}
460
461
462
463static int
Etan Cohend3652192014-06-20 08:28:44 -0700464processCommandBuffer(void *buffer, size_t buflen, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800465 Parcel p;
466 status_t status;
467 int32_t request;
468 int32_t token;
469 RequestInfo *pRI;
470 int ret;
Etan Cohend3652192014-06-20 08:28:44 -0700471 /* Hook for current context */
472 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
473 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
474 /* pendingRequestsHook refer to &s_pendingRequests */
475 RequestInfo** pendingRequestsHook = &s_pendingRequests;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800476
477 p.setData((uint8_t *) buffer, buflen);
478
479 // status checked at end
480 status = p.readInt32(&request);
481 status = p.readInt32 (&token);
482
Etan Cohend3652192014-06-20 08:28:44 -0700483#if (SIM_COUNT >= 2)
484 if (socket_id == RIL_SOCKET_2) {
485 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
486 pendingRequestsHook = &s_pendingRequests_socket2;
487 }
488#if (SIM_COUNT >= 3)
489 else if (socket_id == RIL_SOCKET_3) {
490 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
491 pendingRequestsHook = &s_pendingRequests_socket3;
492 }
493#endif
494#if (SIM_COUNT >= 4)
495 else if (socket_id == RIL_SOCKET_4) {
496 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
497 pendingRequestsHook = &s_pendingRequests_socket4;
498 }
499#endif
500#endif
501
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800502 if (status != NO_ERROR) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800503 RLOGE("invalid request block");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800504 return 0;
505 }
506
507 if (request < 1 || request >= (int32_t)NUM_ELEMS(s_commands)) {
Etan Cohend3652192014-06-20 08:28:44 -0700508 Parcel pErr;
Wink Saville8eb2a122012-11-19 16:05:13 -0800509 RLOGE("unsupported request code %d token %d", request, token);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800510 // FIXME this should perhaps return a response
Etan Cohend3652192014-06-20 08:28:44 -0700511 pErr.writeInt32 (RESPONSE_SOLICITED);
512 pErr.writeInt32 (token);
513 pErr.writeInt32 (RIL_E_GENERIC_FAILURE);
514
515 sendResponse(pErr, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800516 return 0;
517 }
518
519
520 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
521
522 pRI->token = token;
523 pRI->pCI = &(s_commands[request]);
Etan Cohend3652192014-06-20 08:28:44 -0700524 pRI->socket_id = socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800525
Etan Cohend3652192014-06-20 08:28:44 -0700526 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800527 assert (ret == 0);
528
Etan Cohend3652192014-06-20 08:28:44 -0700529 pRI->p_next = *pendingRequestsHook;
530 *pendingRequestsHook = pRI;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800531
Etan Cohend3652192014-06-20 08:28:44 -0700532 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800533 assert (ret == 0);
534
535/* sLastDispatchedToken = token; */
536
Wink Saville7f856802009-06-09 10:23:37 -0700537 pRI->pCI->dispatchFunction(p, pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800538
539 return 0;
540}
541
542static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700543invalidCommandBlock (RequestInfo *pRI) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800544 RLOGE("invalid command block for token %d request %s",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800545 pRI->token, requestToString(pRI->pCI->requestNumber));
546}
547
548/** Callee expects NULL */
Wink Saville7f856802009-06-09 10:23:37 -0700549static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700550dispatchVoid (Parcel& p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800551 clearPrintBuf;
552 printRequest(pRI->token, pRI->pCI->requestNumber);
Etan Cohend3652192014-06-20 08:28:44 -0700553 CALL_ONREQUEST(pRI->pCI->requestNumber, NULL, 0, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800554}
555
556/** Callee expects const char * */
557static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700558dispatchString (Parcel& p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800559 status_t status;
560 size_t datalen;
561 size_t stringlen;
562 char *string8 = NULL;
563
564 string8 = strdupReadString(p);
565
566 startRequest;
567 appendPrintBuf("%s%s", printBuf, string8);
568 closeRequest;
569 printRequest(pRI->token, pRI->pCI->requestNumber);
570
Etan Cohend3652192014-06-20 08:28:44 -0700571 CALL_ONREQUEST(pRI->pCI->requestNumber, string8,
572 sizeof(char *), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800573
574#ifdef MEMSET_FREED
575 memsetString(string8);
576#endif
577
578 free(string8);
579 return;
580invalid:
581 invalidCommandBlock(pRI);
582 return;
583}
584
585/** Callee expects const char ** */
586static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700587dispatchStrings (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800588 int32_t countStrings;
589 status_t status;
590 size_t datalen;
591 char **pStrings;
592
593 status = p.readInt32 (&countStrings);
594
595 if (status != NO_ERROR) {
596 goto invalid;
597 }
598
599 startRequest;
600 if (countStrings == 0) {
601 // just some non-null pointer
602 pStrings = (char **)alloca(sizeof(char *));
603 datalen = 0;
604 } else if (((int)countStrings) == -1) {
605 pStrings = NULL;
606 datalen = 0;
607 } else {
608 datalen = sizeof(char *) * countStrings;
Wink Saville7f856802009-06-09 10:23:37 -0700609
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800610 pStrings = (char **)alloca(datalen);
611
612 for (int i = 0 ; i < countStrings ; i++) {
613 pStrings[i] = strdupReadString(p);
614 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
615 }
616 }
617 removeLastChar;
618 closeRequest;
619 printRequest(pRI->token, pRI->pCI->requestNumber);
620
Etan Cohend3652192014-06-20 08:28:44 -0700621 CALL_ONREQUEST(pRI->pCI->requestNumber, pStrings, datalen, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800622
623 if (pStrings != NULL) {
624 for (int i = 0 ; i < countStrings ; i++) {
625#ifdef MEMSET_FREED
626 memsetString (pStrings[i]);
627#endif
628 free(pStrings[i]);
629 }
630
631#ifdef MEMSET_FREED
632 memset(pStrings, 0, datalen);
633#endif
634 }
Wink Saville7f856802009-06-09 10:23:37 -0700635
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800636 return;
637invalid:
638 invalidCommandBlock(pRI);
639 return;
640}
641
642/** Callee expects const int * */
643static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700644dispatchInts (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800645 int32_t count;
646 status_t status;
647 size_t datalen;
648 int *pInts;
649
650 status = p.readInt32 (&count);
651
652 if (status != NO_ERROR || count == 0) {
653 goto invalid;
654 }
655
656 datalen = sizeof(int) * count;
657 pInts = (int *)alloca(datalen);
658
659 startRequest;
660 for (int i = 0 ; i < count ; i++) {
661 int32_t t;
662
663 status = p.readInt32(&t);
664 pInts[i] = (int)t;
665 appendPrintBuf("%s%d,", printBuf, t);
666
667 if (status != NO_ERROR) {
668 goto invalid;
669 }
670 }
671 removeLastChar;
672 closeRequest;
673 printRequest(pRI->token, pRI->pCI->requestNumber);
674
Etan Cohend3652192014-06-20 08:28:44 -0700675 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<int *>(pInts),
676 datalen, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800677
678#ifdef MEMSET_FREED
679 memset(pInts, 0, datalen);
680#endif
681
682 return;
683invalid:
684 invalidCommandBlock(pRI);
685 return;
686}
687
688
Wink Saville7f856802009-06-09 10:23:37 -0700689/**
690 * Callee expects const RIL_SMS_WriteArgs *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800691 * Payload is:
692 * int32_t status
693 * String pdu
694 */
695static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700696dispatchSmsWrite (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800697 RIL_SMS_WriteArgs args;
698 int32_t t;
699 status_t status;
700
Mark Salyzyndba25612015-04-09 07:18:35 -0700701 RLOGD("dispatchSmsWrite");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800702 memset (&args, 0, sizeof(args));
703
704 status = p.readInt32(&t);
705 args.status = (int)t;
706
707 args.pdu = strdupReadString(p);
708
709 if (status != NO_ERROR || args.pdu == NULL) {
710 goto invalid;
711 }
712
713 args.smsc = strdupReadString(p);
714
715 startRequest;
716 appendPrintBuf("%s%d,%s,smsc=%s", printBuf, args.status,
717 (char*)args.pdu, (char*)args.smsc);
718 closeRequest;
719 printRequest(pRI->token, pRI->pCI->requestNumber);
Wink Saville7f856802009-06-09 10:23:37 -0700720
Etan Cohend3652192014-06-20 08:28:44 -0700721 CALL_ONREQUEST(pRI->pCI->requestNumber, &args, sizeof(args), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800722
723#ifdef MEMSET_FREED
724 memsetString (args.pdu);
725#endif
726
727 free (args.pdu);
Wink Saville7f856802009-06-09 10:23:37 -0700728
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800729#ifdef MEMSET_FREED
730 memset(&args, 0, sizeof(args));
731#endif
732
733 return;
734invalid:
735 invalidCommandBlock(pRI);
736 return;
737}
738
Wink Saville7f856802009-06-09 10:23:37 -0700739/**
740 * Callee expects const RIL_Dial *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800741 * Payload is:
742 * String address
743 * int32_t clir
744 */
745static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700746dispatchDial (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800747 RIL_Dial dial;
Wink Saville74fa3882009-12-22 15:35:41 -0800748 RIL_UUS_Info uusInfo;
Wink Saville7bce0822010-01-08 15:20:12 -0800749 int32_t sizeOfDial;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800750 int32_t t;
Wink Saville74fa3882009-12-22 15:35:41 -0800751 int32_t uusPresent;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800752 status_t status;
753
Mark Salyzyndba25612015-04-09 07:18:35 -0700754 RLOGD("dispatchDial");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800755 memset (&dial, 0, sizeof(dial));
756
757 dial.address = strdupReadString(p);
758
759 status = p.readInt32(&t);
760 dial.clir = (int)t;
761
762 if (status != NO_ERROR || dial.address == NULL) {
763 goto invalid;
764 }
765
Wink Saville3a4840b2010-04-07 13:29:58 -0700766 if (s_callbacks.version < 3) { // Remove when partners upgrade to version 3
Wink Saville74fa3882009-12-22 15:35:41 -0800767 uusPresent = 0;
Wink Saville7bce0822010-01-08 15:20:12 -0800768 sizeOfDial = sizeof(dial) - sizeof(RIL_UUS_Info *);
Wink Saville74fa3882009-12-22 15:35:41 -0800769 } else {
770 status = p.readInt32(&uusPresent);
771
772 if (status != NO_ERROR) {
773 goto invalid;
774 }
775
776 if (uusPresent == 0) {
777 dial.uusInfo = NULL;
778 } else {
779 int32_t len;
780
781 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
782
783 status = p.readInt32(&t);
784 uusInfo.uusType = (RIL_UUS_Type) t;
785
786 status = p.readInt32(&t);
787 uusInfo.uusDcs = (RIL_UUS_DCS) t;
788
789 status = p.readInt32(&len);
790 if (status != NO_ERROR) {
791 goto invalid;
792 }
793
794 // The java code writes -1 for null arrays
795 if (((int) len) == -1) {
796 uusInfo.uusData = NULL;
797 len = 0;
798 } else {
799 uusInfo.uusData = (char*) p.readInplace(len);
800 }
801
802 uusInfo.uusLength = len;
803 dial.uusInfo = &uusInfo;
804 }
Wink Saville7bce0822010-01-08 15:20:12 -0800805 sizeOfDial = sizeof(dial);
Wink Saville74fa3882009-12-22 15:35:41 -0800806 }
807
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800808 startRequest;
809 appendPrintBuf("%snum=%s,clir=%d", printBuf, dial.address, dial.clir);
Wink Saville74fa3882009-12-22 15:35:41 -0800810 if (uusPresent) {
811 appendPrintBuf("%s,uusType=%d,uusDcs=%d,uusLen=%d", printBuf,
812 dial.uusInfo->uusType, dial.uusInfo->uusDcs,
813 dial.uusInfo->uusLength);
814 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800815 closeRequest;
816 printRequest(pRI->token, pRI->pCI->requestNumber);
817
Etan Cohend3652192014-06-20 08:28:44 -0700818 CALL_ONREQUEST(pRI->pCI->requestNumber, &dial, sizeOfDial, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800819
820#ifdef MEMSET_FREED
821 memsetString (dial.address);
822#endif
823
824 free (dial.address);
Wink Saville7f856802009-06-09 10:23:37 -0700825
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800826#ifdef MEMSET_FREED
Wink Saville74fa3882009-12-22 15:35:41 -0800827 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800828 memset(&dial, 0, sizeof(dial));
829#endif
830
831 return;
832invalid:
833 invalidCommandBlock(pRI);
834 return;
835}
836
Wink Saville7f856802009-06-09 10:23:37 -0700837/**
838 * Callee expects const RIL_SIM_IO *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800839 * Payload is:
840 * int32_t command
841 * int32_t fileid
842 * String path
843 * int32_t p1, p2, p3
Wink Saville7f856802009-06-09 10:23:37 -0700844 * String data
845 * String pin2
Wink Savillec0114b32011-02-18 10:14:07 -0800846 * String aidPtr
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800847 */
848static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700849dispatchSIM_IO (Parcel &p, RequestInfo *pRI) {
Wink Savillec0114b32011-02-18 10:14:07 -0800850 union RIL_SIM_IO {
851 RIL_SIM_IO_v6 v6;
852 RIL_SIM_IO_v5 v5;
853 } simIO;
854
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800855 int32_t t;
Wink Savillec0114b32011-02-18 10:14:07 -0800856 int size;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800857 status_t status;
858
Mark Salyzyndba25612015-04-09 07:18:35 -0700859 RLOGD("dispatchSIM_IO");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800860 memset (&simIO, 0, sizeof(simIO));
861
Wink Saville7f856802009-06-09 10:23:37 -0700862 // note we only check status at the end
863
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800864 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800865 simIO.v6.command = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800866
867 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800868 simIO.v6.fileid = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800869
Wink Savillec0114b32011-02-18 10:14:07 -0800870 simIO.v6.path = strdupReadString(p);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800871
872 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800873 simIO.v6.p1 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800874
875 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800876 simIO.v6.p2 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800877
878 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800879 simIO.v6.p3 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800880
Wink Savillec0114b32011-02-18 10:14:07 -0800881 simIO.v6.data = strdupReadString(p);
882 simIO.v6.pin2 = strdupReadString(p);
883 simIO.v6.aidPtr = strdupReadString(p);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800884
885 startRequest;
Wink Savillec0114b32011-02-18 10:14:07 -0800886 appendPrintBuf("%scmd=0x%X,efid=0x%X,path=%s,%d,%d,%d,%s,pin2=%s,aid=%s", printBuf,
887 simIO.v6.command, simIO.v6.fileid, (char*)simIO.v6.path,
888 simIO.v6.p1, simIO.v6.p2, simIO.v6.p3,
889 (char*)simIO.v6.data, (char*)simIO.v6.pin2, simIO.v6.aidPtr);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800890 closeRequest;
891 printRequest(pRI->token, pRI->pCI->requestNumber);
Wink Saville7f856802009-06-09 10:23:37 -0700892
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800893 if (status != NO_ERROR) {
894 goto invalid;
895 }
896
Wink Savillec0114b32011-02-18 10:14:07 -0800897 size = (s_callbacks.version < 6) ? sizeof(simIO.v5) : sizeof(simIO.v6);
Etan Cohend3652192014-06-20 08:28:44 -0700898 CALL_ONREQUEST(pRI->pCI->requestNumber, &simIO, size, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800899
900#ifdef MEMSET_FREED
Wink Savillec0114b32011-02-18 10:14:07 -0800901 memsetString (simIO.v6.path);
902 memsetString (simIO.v6.data);
903 memsetString (simIO.v6.pin2);
904 memsetString (simIO.v6.aidPtr);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800905#endif
906
Wink Savillec0114b32011-02-18 10:14:07 -0800907 free (simIO.v6.path);
908 free (simIO.v6.data);
909 free (simIO.v6.pin2);
910 free (simIO.v6.aidPtr);
Wink Saville7f856802009-06-09 10:23:37 -0700911
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800912#ifdef MEMSET_FREED
913 memset(&simIO, 0, sizeof(simIO));
914#endif
915
916 return;
917invalid:
918 invalidCommandBlock(pRI);
919 return;
920}
921
922/**
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800923 * Callee expects const RIL_SIM_APDU *
924 * Payload is:
925 * int32_t sessionid
926 * int32_t cla
927 * int32_t instruction
928 * int32_t p1, p2, p3
929 * String data
930 */
931static void
932dispatchSIM_APDU (Parcel &p, RequestInfo *pRI) {
933 int32_t t;
934 status_t status;
935 RIL_SIM_APDU apdu;
936
Mark Salyzyndba25612015-04-09 07:18:35 -0700937 RLOGD("dispatchSIM_APDU");
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800938 memset (&apdu, 0, sizeof(RIL_SIM_APDU));
939
940 // Note we only check status at the end. Any single failure leads to
941 // subsequent reads filing.
942 status = p.readInt32(&t);
943 apdu.sessionid = (int)t;
944
945 status = p.readInt32(&t);
946 apdu.cla = (int)t;
947
948 status = p.readInt32(&t);
949 apdu.instruction = (int)t;
950
951 status = p.readInt32(&t);
952 apdu.p1 = (int)t;
953
954 status = p.readInt32(&t);
955 apdu.p2 = (int)t;
956
957 status = p.readInt32(&t);
958 apdu.p3 = (int)t;
959
960 apdu.data = strdupReadString(p);
961
962 startRequest;
963 appendPrintBuf("%ssessionid=%d,cla=%d,ins=%d,p1=%d,p2=%d,p3=%d,data=%s",
964 printBuf, apdu.sessionid, apdu.cla, apdu.instruction, apdu.p1, apdu.p2,
965 apdu.p3, (char*)apdu.data);
966 closeRequest;
967 printRequest(pRI->token, pRI->pCI->requestNumber);
968
969 if (status != NO_ERROR) {
970 goto invalid;
971 }
972
Etan Cohend3652192014-06-20 08:28:44 -0700973 CALL_ONREQUEST(pRI->pCI->requestNumber, &apdu, sizeof(RIL_SIM_APDU), pRI, pRI->socket_id);
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800974
975#ifdef MEMSET_FREED
976 memsetString(apdu.data);
977#endif
978 free(apdu.data);
979
980#ifdef MEMSET_FREED
981 memset(&apdu, 0, sizeof(RIL_SIM_APDU));
982#endif
983
984 return;
985invalid:
986 invalidCommandBlock(pRI);
987 return;
988}
989
990
991/**
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800992 * Callee expects const RIL_CallForwardInfo *
993 * Payload is:
994 * int32_t status/action
995 * int32_t reason
996 * int32_t serviceCode
997 * int32_t toa
998 * String number (0 length -> null)
999 * int32_t timeSeconds
1000 */
Wink Saville7f856802009-06-09 10:23:37 -07001001static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001002dispatchCallForward(Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001003 RIL_CallForwardInfo cff;
1004 int32_t t;
1005 status_t status;
1006
Mark Salyzyndba25612015-04-09 07:18:35 -07001007 RLOGD("dispatchCallForward");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001008 memset (&cff, 0, sizeof(cff));
1009
Wink Saville7f856802009-06-09 10:23:37 -07001010 // note we only check status at the end
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001011
1012 status = p.readInt32(&t);
1013 cff.status = (int)t;
Wink Saville7f856802009-06-09 10:23:37 -07001014
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001015 status = p.readInt32(&t);
1016 cff.reason = (int)t;
1017
1018 status = p.readInt32(&t);
1019 cff.serviceClass = (int)t;
1020
1021 status = p.readInt32(&t);
1022 cff.toa = (int)t;
1023
1024 cff.number = strdupReadString(p);
1025
1026 status = p.readInt32(&t);
1027 cff.timeSeconds = (int)t;
1028
1029 if (status != NO_ERROR) {
1030 goto invalid;
1031 }
1032
1033 // special case: number 0-length fields is null
1034
1035 if (cff.number != NULL && strlen (cff.number) == 0) {
1036 cff.number = NULL;
1037 }
1038
1039 startRequest;
1040 appendPrintBuf("%sstat=%d,reason=%d,serv=%d,toa=%d,%s,tout=%d", printBuf,
1041 cff.status, cff.reason, cff.serviceClass, cff.toa,
1042 (char*)cff.number, cff.timeSeconds);
1043 closeRequest;
1044 printRequest(pRI->token, pRI->pCI->requestNumber);
1045
Etan Cohend3652192014-06-20 08:28:44 -07001046 CALL_ONREQUEST(pRI->pCI->requestNumber, &cff, sizeof(cff), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001047
1048#ifdef MEMSET_FREED
1049 memsetString(cff.number);
1050#endif
1051
1052 free (cff.number);
1053
1054#ifdef MEMSET_FREED
1055 memset(&cff, 0, sizeof(cff));
1056#endif
1057
1058 return;
1059invalid:
1060 invalidCommandBlock(pRI);
1061 return;
1062}
1063
1064
Wink Saville7f856802009-06-09 10:23:37 -07001065static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001066dispatchRaw(Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001067 int32_t len;
1068 status_t status;
1069 const void *data;
1070
1071 status = p.readInt32(&len);
1072
1073 if (status != NO_ERROR) {
1074 goto invalid;
1075 }
1076
1077 // The java code writes -1 for null arrays
1078 if (((int)len) == -1) {
1079 data = NULL;
1080 len = 0;
Wink Saville7f856802009-06-09 10:23:37 -07001081 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001082
1083 data = p.readInplace(len);
1084
1085 startRequest;
1086 appendPrintBuf("%sraw_size=%d", printBuf, len);
1087 closeRequest;
1088 printRequest(pRI->token, pRI->pCI->requestNumber);
1089
Etan Cohend3652192014-06-20 08:28:44 -07001090 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<void *>(data), len, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001091
1092 return;
1093invalid:
1094 invalidCommandBlock(pRI);
1095 return;
1096}
1097
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001098static status_t
1099constructCdmaSms(Parcel &p, RequestInfo *pRI, RIL_CDMA_SMS_Message& rcsm) {
Wink Savillef4c4d362009-04-02 01:37:03 -07001100 int32_t t;
1101 uint8_t ut;
1102 status_t status;
1103 int32_t digitCount;
1104 int digitLimit;
Wink Saville7f856802009-06-09 10:23:37 -07001105
Wink Savillef4c4d362009-04-02 01:37:03 -07001106 memset(&rcsm, 0, sizeof(rcsm));
1107
1108 status = p.readInt32(&t);
1109 rcsm.uTeleserviceID = (int) t;
1110
1111 status = p.read(&ut,sizeof(ut));
1112 rcsm.bIsServicePresent = (uint8_t) ut;
1113
1114 status = p.readInt32(&t);
1115 rcsm.uServicecategory = (int) t;
1116
1117 status = p.readInt32(&t);
1118 rcsm.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1119
1120 status = p.readInt32(&t);
1121 rcsm.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1122
1123 status = p.readInt32(&t);
1124 rcsm.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1125
1126 status = p.readInt32(&t);
1127 rcsm.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1128
1129 status = p.read(&ut,sizeof(ut));
1130 rcsm.sAddress.number_of_digits= (uint8_t) ut;
1131
1132 digitLimit= MIN((rcsm.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
1133 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1134 status = p.read(&ut,sizeof(ut));
1135 rcsm.sAddress.digits[digitCount] = (uint8_t) ut;
1136 }
1137
Wink Saville7f856802009-06-09 10:23:37 -07001138 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001139 rcsm.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1140
Wink Saville7f856802009-06-09 10:23:37 -07001141 status = p.read(&ut,sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001142 rcsm.sSubAddress.odd = (uint8_t) ut;
1143
1144 status = p.read(&ut,sizeof(ut));
1145 rcsm.sSubAddress.number_of_digits = (uint8_t) ut;
1146
1147 digitLimit= MIN((rcsm.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
Wink Saville7f856802009-06-09 10:23:37 -07001148 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1149 status = p.read(&ut,sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001150 rcsm.sSubAddress.digits[digitCount] = (uint8_t) ut;
1151 }
1152
Wink Saville7f856802009-06-09 10:23:37 -07001153 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001154 rcsm.uBearerDataLen = (int) t;
1155
1156 digitLimit= MIN((rcsm.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
Wink Saville7f856802009-06-09 10:23:37 -07001157 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1158 status = p.read(&ut, sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001159 rcsm.aBearerData[digitCount] = (uint8_t) ut;
1160 }
1161
1162 if (status != NO_ERROR) {
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001163 return status;
Wink Savillef4c4d362009-04-02 01:37:03 -07001164 }
1165
1166 startRequest;
1167 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
Wink Saville1b5fd232009-04-22 14:50:00 -07001168 sAddress.digit_mode=%d, sAddress.Number_mode=%d, sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07001169 printBuf, rcsm.uTeleserviceID,rcsm.bIsServicePresent,rcsm.uServicecategory,
Wink Saville1b5fd232009-04-22 14:50:00 -07001170 rcsm.sAddress.digit_mode, rcsm.sAddress.number_mode,rcsm.sAddress.number_type);
Wink Savillef4c4d362009-04-02 01:37:03 -07001171 closeRequest;
Wink Saville7f856802009-06-09 10:23:37 -07001172
Wink Savillef4c4d362009-04-02 01:37:03 -07001173 printRequest(pRI->token, pRI->pCI->requestNumber);
1174
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001175 return status;
1176}
1177
1178static void
1179dispatchCdmaSms(Parcel &p, RequestInfo *pRI) {
1180 RIL_CDMA_SMS_Message rcsm;
1181
Mark Salyzyndba25612015-04-09 07:18:35 -07001182 RLOGD("dispatchCdmaSms");
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001183 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1184 goto invalid;
1185 }
1186
Etan Cohend3652192014-06-20 08:28:44 -07001187 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001188
1189#ifdef MEMSET_FREED
1190 memset(&rcsm, 0, sizeof(rcsm));
1191#endif
1192
1193 return;
1194
1195invalid:
1196 invalidCommandBlock(pRI);
1197 return;
1198}
1199
Wink Saville7f856802009-06-09 10:23:37 -07001200static void
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001201dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1202 RIL_IMS_SMS_Message rism;
1203 RIL_CDMA_SMS_Message rcsm;
1204
Mark Salyzyndba25612015-04-09 07:18:35 -07001205 RLOGD("dispatchImsCdmaSms: retry=%d, messageRef=%d", retry, messageRef);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001206
1207 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1208 goto invalid;
1209 }
1210 memset(&rism, 0, sizeof(rism));
1211 rism.tech = RADIO_TECH_3GPP2;
1212 rism.retry = retry;
1213 rism.messageRef = messageRef;
1214 rism.message.cdmaMessage = &rcsm;
1215
Etan Cohend3652192014-06-20 08:28:44 -07001216 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001217 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Etan Cohend3652192014-06-20 08:28:44 -07001218 +sizeof(rcsm),pRI, pRI->socket_id);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001219
1220#ifdef MEMSET_FREED
1221 memset(&rcsm, 0, sizeof(rcsm));
1222 memset(&rism, 0, sizeof(rism));
1223#endif
1224
1225 return;
1226
1227invalid:
1228 invalidCommandBlock(pRI);
1229 return;
1230}
1231
1232static void
1233dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1234 RIL_IMS_SMS_Message rism;
1235 int32_t countStrings;
1236 status_t status;
1237 size_t datalen;
1238 char **pStrings;
Mark Salyzyndba25612015-04-09 07:18:35 -07001239 RLOGD("dispatchImsGsmSms: retry=%d, messageRef=%d", retry, messageRef);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001240
1241 status = p.readInt32 (&countStrings);
1242
1243 if (status != NO_ERROR) {
1244 goto invalid;
1245 }
1246
1247 memset(&rism, 0, sizeof(rism));
1248 rism.tech = RADIO_TECH_3GPP;
1249 rism.retry = retry;
1250 rism.messageRef = messageRef;
1251
1252 startRequest;
Etan Cohen5d891b72014-02-27 17:25:17 -08001253 appendPrintBuf("%stech=%d, retry=%d, messageRef=%d, ", printBuf,
1254 (int)rism.tech, (int)rism.retry, rism.messageRef);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001255 if (countStrings == 0) {
1256 // just some non-null pointer
1257 pStrings = (char **)alloca(sizeof(char *));
1258 datalen = 0;
1259 } else if (((int)countStrings) == -1) {
1260 pStrings = NULL;
1261 datalen = 0;
1262 } else {
1263 datalen = sizeof(char *) * countStrings;
1264
1265 pStrings = (char **)alloca(datalen);
1266
1267 for (int i = 0 ; i < countStrings ; i++) {
1268 pStrings[i] = strdupReadString(p);
1269 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
1270 }
1271 }
1272 removeLastChar;
1273 closeRequest;
1274 printRequest(pRI->token, pRI->pCI->requestNumber);
1275
1276 rism.message.gsmMessage = pStrings;
Etan Cohend3652192014-06-20 08:28:44 -07001277 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001278 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Etan Cohend3652192014-06-20 08:28:44 -07001279 +datalen, pRI, pRI->socket_id);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001280
1281 if (pStrings != NULL) {
1282 for (int i = 0 ; i < countStrings ; i++) {
1283#ifdef MEMSET_FREED
1284 memsetString (pStrings[i]);
1285#endif
1286 free(pStrings[i]);
1287 }
1288
1289#ifdef MEMSET_FREED
1290 memset(pStrings, 0, datalen);
1291#endif
1292 }
1293
1294#ifdef MEMSET_FREED
1295 memset(&rism, 0, sizeof(rism));
1296#endif
1297 return;
1298invalid:
1299 ALOGE("dispatchImsGsmSms invalid block");
1300 invalidCommandBlock(pRI);
1301 return;
1302}
1303
1304static void
1305dispatchImsSms(Parcel &p, RequestInfo *pRI) {
1306 int32_t t;
1307 status_t status = p.readInt32(&t);
1308 RIL_RadioTechnologyFamily format;
1309 uint8_t retry;
1310 int32_t messageRef;
1311
Mark Salyzyndba25612015-04-09 07:18:35 -07001312 RLOGD("dispatchImsSms");
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001313 if (status != NO_ERROR) {
1314 goto invalid;
1315 }
1316 format = (RIL_RadioTechnologyFamily) t;
1317
1318 // read retry field
1319 status = p.read(&retry,sizeof(retry));
1320 if (status != NO_ERROR) {
1321 goto invalid;
1322 }
1323 // read messageRef field
1324 status = p.read(&messageRef,sizeof(messageRef));
1325 if (status != NO_ERROR) {
1326 goto invalid;
1327 }
1328
1329 if (RADIO_TECH_3GPP == format) {
1330 dispatchImsGsmSms(p, pRI, retry, messageRef);
1331 } else if (RADIO_TECH_3GPP2 == format) {
1332 dispatchImsCdmaSms(p, pRI, retry, messageRef);
1333 } else {
1334 ALOGE("requestImsSendSMS invalid format value =%d", format);
1335 }
1336
1337 return;
1338
1339invalid:
1340 invalidCommandBlock(pRI);
1341 return;
1342}
1343
1344static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001345dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI) {
1346 RIL_CDMA_SMS_Ack rcsa;
1347 int32_t t;
1348 status_t status;
1349 int32_t digitCount;
1350
Mark Salyzyndba25612015-04-09 07:18:35 -07001351 RLOGD("dispatchCdmaSmsAck");
Wink Savillef4c4d362009-04-02 01:37:03 -07001352 memset(&rcsa, 0, sizeof(rcsa));
1353
1354 status = p.readInt32(&t);
1355 rcsa.uErrorClass = (RIL_CDMA_SMS_ErrorClass) t;
1356
1357 status = p.readInt32(&t);
1358 rcsa.uSMSCauseCode = (int) t;
1359
1360 if (status != NO_ERROR) {
1361 goto invalid;
1362 }
1363
1364 startRequest;
Wink Saville1b5fd232009-04-22 14:50:00 -07001365 appendPrintBuf("%suErrorClass=%d, uTLStatus=%d, ",
1366 printBuf, rcsa.uErrorClass, rcsa.uSMSCauseCode);
Wink Savillef4c4d362009-04-02 01:37:03 -07001367 closeRequest;
1368
1369 printRequest(pRI->token, pRI->pCI->requestNumber);
1370
Etan Cohend3652192014-06-20 08:28:44 -07001371 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsa, sizeof(rcsa),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001372
1373#ifdef MEMSET_FREED
1374 memset(&rcsa, 0, sizeof(rcsa));
1375#endif
1376
1377 return;
1378
1379invalid:
1380 invalidCommandBlock(pRI);
1381 return;
1382}
1383
Wink Savillea592eeb2009-05-22 13:26:36 -07001384static void
1385dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1386 int32_t t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001387 status_t status;
Wink Savillea592eeb2009-05-22 13:26:36 -07001388 int32_t num;
Wink Savillef4c4d362009-04-02 01:37:03 -07001389
Wink Savillea592eeb2009-05-22 13:26:36 -07001390 status = p.readInt32(&num);
Wink Savillef4c4d362009-04-02 01:37:03 -07001391 if (status != NO_ERROR) {
1392 goto invalid;
1393 }
1394
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001395 {
1396 RIL_GSM_BroadcastSmsConfigInfo gsmBci[num];
1397 RIL_GSM_BroadcastSmsConfigInfo *gsmBciPtrs[num];
Wink Savillea592eeb2009-05-22 13:26:36 -07001398
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001399 startRequest;
1400 for (int i = 0 ; i < num ; i++ ) {
1401 gsmBciPtrs[i] = &gsmBci[i];
Wink Savillef4c4d362009-04-02 01:37:03 -07001402
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001403 status = p.readInt32(&t);
1404 gsmBci[i].fromServiceId = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001405
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001406 status = p.readInt32(&t);
1407 gsmBci[i].toServiceId = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001408
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001409 status = p.readInt32(&t);
1410 gsmBci[i].fromCodeScheme = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001411
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001412 status = p.readInt32(&t);
1413 gsmBci[i].toCodeScheme = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001414
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001415 status = p.readInt32(&t);
1416 gsmBci[i].selected = (uint8_t) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001417
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001418 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId =%d, \
1419 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]", printBuf, i,
1420 gsmBci[i].fromServiceId, gsmBci[i].toServiceId,
1421 gsmBci[i].fromCodeScheme, gsmBci[i].toCodeScheme,
1422 gsmBci[i].selected);
1423 }
1424 closeRequest;
Wink Savillef4c4d362009-04-02 01:37:03 -07001425
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001426 if (status != NO_ERROR) {
1427 goto invalid;
1428 }
Wink Savillef4c4d362009-04-02 01:37:03 -07001429
Etan Cohend3652192014-06-20 08:28:44 -07001430 CALL_ONREQUEST(pRI->pCI->requestNumber,
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001431 gsmBciPtrs,
1432 num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *),
Etan Cohend3652192014-06-20 08:28:44 -07001433 pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001434
1435#ifdef MEMSET_FREED
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001436 memset(gsmBci, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo));
1437 memset(gsmBciPtrs, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *));
Wink Savillef4c4d362009-04-02 01:37:03 -07001438#endif
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001439 }
Wink Savillef4c4d362009-04-02 01:37:03 -07001440
1441 return;
1442
1443invalid:
1444 invalidCommandBlock(pRI);
1445 return;
Wink Savillea592eeb2009-05-22 13:26:36 -07001446}
Wink Savillef4c4d362009-04-02 01:37:03 -07001447
Wink Savillea592eeb2009-05-22 13:26:36 -07001448static void
1449dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1450 int32_t t;
1451 status_t status;
1452 int32_t num;
1453
1454 status = p.readInt32(&num);
1455 if (status != NO_ERROR) {
1456 goto invalid;
1457 }
1458
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001459 {
1460 RIL_CDMA_BroadcastSmsConfigInfo cdmaBci[num];
1461 RIL_CDMA_BroadcastSmsConfigInfo *cdmaBciPtrs[num];
Wink Savillea592eeb2009-05-22 13:26:36 -07001462
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001463 startRequest;
1464 for (int i = 0 ; i < num ; i++ ) {
1465 cdmaBciPtrs[i] = &cdmaBci[i];
Wink Savillea592eeb2009-05-22 13:26:36 -07001466
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001467 status = p.readInt32(&t);
1468 cdmaBci[i].service_category = (int) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001469
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001470 status = p.readInt32(&t);
1471 cdmaBci[i].language = (int) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001472
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001473 status = p.readInt32(&t);
1474 cdmaBci[i].selected = (uint8_t) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001475
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001476 appendPrintBuf("%s [%d: service_category=%d, language =%d, \
1477 entries.bSelected =%d]", printBuf, i, cdmaBci[i].service_category,
1478 cdmaBci[i].language, cdmaBci[i].selected);
1479 }
1480 closeRequest;
Wink Savillea592eeb2009-05-22 13:26:36 -07001481
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001482 if (status != NO_ERROR) {
1483 goto invalid;
1484 }
Wink Savillea592eeb2009-05-22 13:26:36 -07001485
Etan Cohend3652192014-06-20 08:28:44 -07001486 CALL_ONREQUEST(pRI->pCI->requestNumber,
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001487 cdmaBciPtrs,
1488 num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *),
Etan Cohend3652192014-06-20 08:28:44 -07001489 pRI, pRI->socket_id);
Wink Savillea592eeb2009-05-22 13:26:36 -07001490
1491#ifdef MEMSET_FREED
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001492 memset(cdmaBci, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo));
1493 memset(cdmaBciPtrs, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *));
Wink Savillea592eeb2009-05-22 13:26:36 -07001494#endif
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001495 }
Wink Savillea592eeb2009-05-22 13:26:36 -07001496
1497 return;
1498
1499invalid:
1500 invalidCommandBlock(pRI);
1501 return;
Wink Savillef4c4d362009-04-02 01:37:03 -07001502}
1503
1504static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI) {
1505 RIL_CDMA_SMS_WriteArgs rcsw;
1506 int32_t t;
1507 uint32_t ut;
1508 uint8_t uct;
1509 status_t status;
1510 int32_t digitCount;
1511
1512 memset(&rcsw, 0, sizeof(rcsw));
1513
1514 status = p.readInt32(&t);
1515 rcsw.status = t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001516
Wink Savillef4c4d362009-04-02 01:37:03 -07001517 status = p.readInt32(&t);
1518 rcsw.message.uTeleserviceID = (int) t;
1519
1520 status = p.read(&uct,sizeof(uct));
1521 rcsw.message.bIsServicePresent = (uint8_t) uct;
1522
1523 status = p.readInt32(&t);
1524 rcsw.message.uServicecategory = (int) t;
1525
1526 status = p.readInt32(&t);
1527 rcsw.message.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1528
1529 status = p.readInt32(&t);
1530 rcsw.message.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1531
1532 status = p.readInt32(&t);
1533 rcsw.message.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1534
1535 status = p.readInt32(&t);
1536 rcsw.message.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1537
1538 status = p.read(&uct,sizeof(uct));
1539 rcsw.message.sAddress.number_of_digits = (uint8_t) uct;
1540
1541 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_ADDRESS_MAX; digitCount ++) {
1542 status = p.read(&uct,sizeof(uct));
1543 rcsw.message.sAddress.digits[digitCount] = (uint8_t) uct;
1544 }
1545
Wink Savillea592eeb2009-05-22 13:26:36 -07001546 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001547 rcsw.message.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1548
Wink Savillea592eeb2009-05-22 13:26:36 -07001549 status = p.read(&uct,sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001550 rcsw.message.sSubAddress.odd = (uint8_t) uct;
1551
1552 status = p.read(&uct,sizeof(uct));
1553 rcsw.message.sSubAddress.number_of_digits = (uint8_t) uct;
1554
1555 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_SUBADDRESS_MAX; digitCount ++) {
Wink Savillea592eeb2009-05-22 13:26:36 -07001556 status = p.read(&uct,sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001557 rcsw.message.sSubAddress.digits[digitCount] = (uint8_t) uct;
1558 }
1559
Wink Savillea592eeb2009-05-22 13:26:36 -07001560 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001561 rcsw.message.uBearerDataLen = (int) t;
1562
1563 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_BEARER_DATA_MAX; digitCount ++) {
Wink Savillea592eeb2009-05-22 13:26:36 -07001564 status = p.read(&uct, sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001565 rcsw.message.aBearerData[digitCount] = (uint8_t) uct;
1566 }
1567
1568 if (status != NO_ERROR) {
1569 goto invalid;
1570 }
1571
1572 startRequest;
Wink Saville1b5fd232009-04-22 14:50:00 -07001573 appendPrintBuf("%sstatus=%d, message.uTeleserviceID=%d, message.bIsServicePresent=%d, \
1574 message.uServicecategory=%d, message.sAddress.digit_mode=%d, \
1575 message.sAddress.number_mode=%d, \
1576 message.sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07001577 printBuf, rcsw.status, rcsw.message.uTeleserviceID, rcsw.message.bIsServicePresent,
Wink Saville1b5fd232009-04-22 14:50:00 -07001578 rcsw.message.uServicecategory, rcsw.message.sAddress.digit_mode,
1579 rcsw.message.sAddress.number_mode,
1580 rcsw.message.sAddress.number_type);
Wink Savillef4c4d362009-04-02 01:37:03 -07001581 closeRequest;
1582
1583 printRequest(pRI->token, pRI->pCI->requestNumber);
1584
Etan Cohend3652192014-06-20 08:28:44 -07001585 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsw, sizeof(rcsw),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001586
1587#ifdef MEMSET_FREED
1588 memset(&rcsw, 0, sizeof(rcsw));
1589#endif
1590
1591 return;
1592
1593invalid:
1594 invalidCommandBlock(pRI);
1595 return;
1596
1597}
1598
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -07001599// For backwards compatibility in RIL_REQUEST_SETUP_DATA_CALL.
1600// Version 4 of the RIL interface adds a new PDP type parameter to support
1601// IPv6 and dual-stack PDP contexts. When dealing with a previous version of
1602// RIL, remove the parameter from the request.
1603static void dispatchDataCall(Parcel& p, RequestInfo *pRI) {
1604 // In RIL v3, REQUEST_SETUP_DATA_CALL takes 6 parameters.
1605 const int numParamsRilV3 = 6;
1606
1607 // The first bytes of the RIL parcel contain the request number and the
1608 // serial number - see processCommandBuffer(). Copy them over too.
1609 int pos = p.dataPosition();
1610
1611 int numParams = p.readInt32();
1612 if (s_callbacks.version < 4 && numParams > numParamsRilV3) {
1613 Parcel p2;
1614 p2.appendFrom(&p, 0, pos);
1615 p2.writeInt32(numParamsRilV3);
1616 for(int i = 0; i < numParamsRilV3; i++) {
1617 p2.writeString16(p.readString16());
1618 }
1619 p2.setDataPosition(pos);
1620 dispatchStrings(p2, pRI);
1621 } else {
Lorenzo Colitti57ce1f22010-09-13 12:23:50 -07001622 p.setDataPosition(pos);
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -07001623 dispatchStrings(p, pRI);
1624 }
1625}
1626
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001627// For backwards compatibility with RILs that dont support RIL_REQUEST_VOICE_RADIO_TECH.
1628// When all RILs handle this request, this function can be removed and
1629// the request can be sent directly to the RIL using dispatchVoid.
1630static void dispatchVoiceRadioTech(Parcel& p, RequestInfo *pRI) {
Etan Cohend3652192014-06-20 08:28:44 -07001631 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001632
1633 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1634 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1635 }
1636
1637 // RILs that support RADIO_STATE_ON should support this request.
1638 if (RADIO_STATE_ON == state) {
1639 dispatchVoid(p, pRI);
1640 return;
1641 }
1642
1643 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1644 // will not support this new request either and decode Voice Radio Technology
1645 // from Radio State
1646 voiceRadioTech = decodeVoiceRadioTechnology(state);
1647
1648 if (voiceRadioTech < 0)
1649 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1650 else
1651 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &voiceRadioTech, sizeof(int));
1652}
1653
1654// For backwards compatibility in RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE:.
1655// When all RILs handle this request, this function can be removed and
1656// the request can be sent directly to the RIL using dispatchVoid.
1657static void dispatchCdmaSubscriptionSource(Parcel& p, RequestInfo *pRI) {
Etan Cohend3652192014-06-20 08:28:44 -07001658 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001659
1660 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1661 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1662 }
1663
1664 // RILs that support RADIO_STATE_ON should support this request.
1665 if (RADIO_STATE_ON == state) {
1666 dispatchVoid(p, pRI);
1667 return;
1668 }
1669
1670 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1671 // will not support this new request either and decode CDMA Subscription Source
1672 // from Radio State
1673 cdmaSubscriptionSource = decodeCdmaSubscriptionSource(state);
1674
1675 if (cdmaSubscriptionSource < 0)
1676 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1677 else
1678 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &cdmaSubscriptionSource, sizeof(int));
1679}
1680
Sungmin Choi75697532013-04-26 15:04:45 -07001681static void dispatchSetInitialAttachApn(Parcel &p, RequestInfo *pRI)
1682{
1683 RIL_InitialAttachApn pf;
1684 int32_t t;
1685 status_t status;
1686
1687 memset(&pf, 0, sizeof(pf));
1688
1689 pf.apn = strdupReadString(p);
1690 pf.protocol = strdupReadString(p);
1691
1692 status = p.readInt32(&t);
1693 pf.authtype = (int) t;
1694
1695 pf.username = strdupReadString(p);
1696 pf.password = strdupReadString(p);
1697
1698 startRequest;
Etan Cohen5d891b72014-02-27 17:25:17 -08001699 appendPrintBuf("%sapn=%s, protocol=%s, authtype=%d, username=%s, password=%s",
1700 printBuf, pf.apn, pf.protocol, pf.authtype, pf.username, pf.password);
Sungmin Choi75697532013-04-26 15:04:45 -07001701 closeRequest;
1702 printRequest(pRI->token, pRI->pCI->requestNumber);
1703
1704 if (status != NO_ERROR) {
1705 goto invalid;
1706 }
Etan Cohend3652192014-06-20 08:28:44 -07001707 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
Sungmin Choi75697532013-04-26 15:04:45 -07001708
1709#ifdef MEMSET_FREED
1710 memsetString(pf.apn);
1711 memsetString(pf.protocol);
1712 memsetString(pf.username);
1713 memsetString(pf.password);
1714#endif
1715
1716 free(pf.apn);
1717 free(pf.protocol);
1718 free(pf.username);
1719 free(pf.password);
1720
1721#ifdef MEMSET_FREED
1722 memset(&pf, 0, sizeof(pf));
1723#endif
1724
1725 return;
1726invalid:
1727 invalidCommandBlock(pRI);
1728 return;
1729}
1730
Jake Hamby8a4a2332014-01-15 13:12:05 -08001731static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI) {
1732 RIL_NV_ReadItem nvri;
1733 int32_t t;
1734 status_t status;
1735
1736 memset(&nvri, 0, sizeof(nvri));
1737
1738 status = p.readInt32(&t);
1739 nvri.itemID = (RIL_NV_Item) t;
1740
1741 if (status != NO_ERROR) {
1742 goto invalid;
1743 }
1744
1745 startRequest;
1746 appendPrintBuf("%snvri.itemID=%d, ", printBuf, nvri.itemID);
1747 closeRequest;
1748
1749 printRequest(pRI->token, pRI->pCI->requestNumber);
1750
Etan Cohend3652192014-06-20 08:28:44 -07001751 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvri, sizeof(nvri), pRI, pRI->socket_id);
Jake Hamby8a4a2332014-01-15 13:12:05 -08001752
1753#ifdef MEMSET_FREED
1754 memset(&nvri, 0, sizeof(nvri));
1755#endif
1756
1757 return;
1758
1759invalid:
1760 invalidCommandBlock(pRI);
1761 return;
1762}
1763
1764static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI) {
1765 RIL_NV_WriteItem nvwi;
1766 int32_t t;
1767 status_t status;
1768
1769 memset(&nvwi, 0, sizeof(nvwi));
1770
1771 status = p.readInt32(&t);
1772 nvwi.itemID = (RIL_NV_Item) t;
1773
1774 nvwi.value = strdupReadString(p);
1775
1776 if (status != NO_ERROR || nvwi.value == NULL) {
1777 goto invalid;
1778 }
1779
1780 startRequest;
1781 appendPrintBuf("%snvwi.itemID=%d, value=%s, ", printBuf, nvwi.itemID,
1782 nvwi.value);
1783 closeRequest;
1784
1785 printRequest(pRI->token, pRI->pCI->requestNumber);
1786
Etan Cohend3652192014-06-20 08:28:44 -07001787 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvwi, sizeof(nvwi), pRI, pRI->socket_id);
Jake Hamby8a4a2332014-01-15 13:12:05 -08001788
1789#ifdef MEMSET_FREED
1790 memsetString(nvwi.value);
1791#endif
1792
1793 free(nvwi.value);
1794
1795#ifdef MEMSET_FREED
1796 memset(&nvwi, 0, sizeof(nvwi));
1797#endif
1798
1799 return;
1800
1801invalid:
1802 invalidCommandBlock(pRI);
1803 return;
1804}
1805
1806
Etan Cohend3652192014-06-20 08:28:44 -07001807static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI) {
1808 RIL_SelectUiccSub uicc_sub;
1809 status_t status;
1810 int32_t t;
1811 memset(&uicc_sub, 0, sizeof(uicc_sub));
1812
1813 status = p.readInt32(&t);
1814 if (status != NO_ERROR) {
1815 goto invalid;
1816 }
1817 uicc_sub.slot = (int) t;
1818
1819 status = p.readInt32(&t);
1820 if (status != NO_ERROR) {
1821 goto invalid;
1822 }
1823 uicc_sub.app_index = (int) t;
1824
1825 status = p.readInt32(&t);
1826 if (status != NO_ERROR) {
1827 goto invalid;
1828 }
1829 uicc_sub.sub_type = (RIL_SubscriptionType) t;
1830
1831 status = p.readInt32(&t);
1832 if (status != NO_ERROR) {
1833 goto invalid;
1834 }
1835 uicc_sub.act_status = (RIL_UiccSubActStatus) t;
1836
1837 startRequest;
1838 appendPrintBuf("slot=%d, app_index=%d, act_status = %d", uicc_sub.slot, uicc_sub.app_index,
1839 uicc_sub.act_status);
1840 RLOGD("dispatchUiccSubscription, slot=%d, app_index=%d, act_status = %d", uicc_sub.slot,
1841 uicc_sub.app_index, uicc_sub.act_status);
1842 closeRequest;
1843 printRequest(pRI->token, pRI->pCI->requestNumber);
1844
1845 CALL_ONREQUEST(pRI->pCI->requestNumber, &uicc_sub, sizeof(uicc_sub), pRI, pRI->socket_id);
1846
1847#ifdef MEMSET_FREED
1848 memset(&uicc_sub, 0, sizeof(uicc_sub));
1849#endif
1850 return;
1851
1852invalid:
1853 invalidCommandBlock(pRI);
1854 return;
1855}
1856
Amit Mahajan90530a62014-07-01 15:54:08 -07001857static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI)
1858{
1859 RIL_SimAuthentication pf;
1860 int32_t t;
1861 status_t status;
1862
1863 memset(&pf, 0, sizeof(pf));
1864
1865 status = p.readInt32(&t);
1866 pf.authContext = (int) t;
1867 pf.authData = strdupReadString(p);
1868 pf.aid = strdupReadString(p);
1869
1870 startRequest;
1871 appendPrintBuf("authContext=%s, authData=%s, aid=%s", pf.authContext, pf.authData, pf.aid);
1872 closeRequest;
1873 printRequest(pRI->token, pRI->pCI->requestNumber);
1874
1875 if (status != NO_ERROR) {
1876 goto invalid;
1877 }
1878 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
1879
1880#ifdef MEMSET_FREED
1881 memsetString(pf.authData);
1882 memsetString(pf.aid);
1883#endif
1884
1885 free(pf.authData);
1886 free(pf.aid);
1887
1888#ifdef MEMSET_FREED
1889 memset(&pf, 0, sizeof(pf));
1890#endif
1891
1892 return;
1893invalid:
1894 invalidCommandBlock(pRI);
1895 return;
1896}
1897
Amit Mahajanc796e222014-08-13 16:54:01 +00001898static void dispatchDataProfile(Parcel &p, RequestInfo *pRI) {
1899 int32_t t;
1900 status_t status;
1901 int32_t num;
1902
1903 status = p.readInt32(&num);
1904 if (status != NO_ERROR) {
1905 goto invalid;
1906 }
1907
1908 {
1909 RIL_DataProfileInfo dataProfiles[num];
1910 RIL_DataProfileInfo *dataProfilePtrs[num];
1911
1912 startRequest;
1913 for (int i = 0 ; i < num ; i++ ) {
1914 dataProfilePtrs[i] = &dataProfiles[i];
1915
1916 status = p.readInt32(&t);
1917 dataProfiles[i].profileId = (int) t;
1918
1919 dataProfiles[i].apn = strdupReadString(p);
1920 dataProfiles[i].protocol = strdupReadString(p);
1921 status = p.readInt32(&t);
1922 dataProfiles[i].authType = (int) t;
1923
1924 dataProfiles[i].user = strdupReadString(p);
1925 dataProfiles[i].password = strdupReadString(p);
1926
1927 status = p.readInt32(&t);
1928 dataProfiles[i].type = (int) t;
1929
1930 status = p.readInt32(&t);
1931 dataProfiles[i].maxConnsTime = (int) t;
1932 status = p.readInt32(&t);
1933 dataProfiles[i].maxConns = (int) t;
1934 status = p.readInt32(&t);
1935 dataProfiles[i].waitTime = (int) t;
1936
1937 status = p.readInt32(&t);
1938 dataProfiles[i].enabled = (int) t;
1939
1940 appendPrintBuf("%s [%d: profileId=%d, apn =%s, protocol =%s, authType =%d, \
1941 user =%s, password =%s, type =%d, maxConnsTime =%d, maxConns =%d, \
1942 waitTime =%d, enabled =%d]", printBuf, i, dataProfiles[i].profileId,
1943 dataProfiles[i].apn, dataProfiles[i].protocol, dataProfiles[i].authType,
1944 dataProfiles[i].user, dataProfiles[i].password, dataProfiles[i].type,
1945 dataProfiles[i].maxConnsTime, dataProfiles[i].maxConns,
1946 dataProfiles[i].waitTime, dataProfiles[i].enabled);
1947 }
1948 closeRequest;
1949 printRequest(pRI->token, pRI->pCI->requestNumber);
1950
1951 if (status != NO_ERROR) {
1952 goto invalid;
1953 }
1954 CALL_ONREQUEST(pRI->pCI->requestNumber,
1955 dataProfilePtrs,
1956 num * sizeof(RIL_DataProfileInfo *),
1957 pRI, pRI->socket_id);
1958
1959#ifdef MEMSET_FREED
1960 memset(dataProfiles, 0, num * sizeof(RIL_DataProfileInfo));
1961 memset(dataProfilePtrs, 0, num * sizeof(RIL_DataProfileInfo *));
1962#endif
1963 }
1964
1965 return;
1966
1967invalid:
1968 invalidCommandBlock(pRI);
1969 return;
1970}
1971
Wink Saville8b4e4f72014-10-17 15:01:45 -07001972static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI){
1973 RIL_RadioCapability rc;
1974 int32_t t;
1975 status_t status;
1976
1977 memset (&rc, 0, sizeof(RIL_RadioCapability));
1978
1979 status = p.readInt32(&t);
1980 rc.version = (int)t;
1981 if (status != NO_ERROR) {
1982 goto invalid;
1983 }
1984
1985 status = p.readInt32(&t);
1986 rc.session= (int)t;
1987 if (status != NO_ERROR) {
1988 goto invalid;
1989 }
1990
1991 status = p.readInt32(&t);
1992 rc.phase= (int)t;
1993 if (status != NO_ERROR) {
1994 goto invalid;
1995 }
1996
1997 status = p.readInt32(&t);
1998 rc.rat = (int)t;
1999 if (status != NO_ERROR) {
2000 goto invalid;
2001 }
2002
2003 status = readStringFromParcelInplace(p, rc.logicalModemUuid, sizeof(rc.logicalModemUuid));
2004 if (status != NO_ERROR) {
2005 goto invalid;
2006 }
2007
2008 status = p.readInt32(&t);
2009 rc.status = (int)t;
2010
2011 if (status != NO_ERROR) {
2012 goto invalid;
2013 }
2014
2015 startRequest;
2016 appendPrintBuf("%s [version:%d, session:%d, phase:%d, rat:%d, \
Legler Wu8caf06f2014-10-29 14:02:14 +08002017 logicalModemUuid:%s, status:%d", printBuf, rc.version, rc.session
2018 rc.phase, rc.rat, rc.logicalModemUuid, rc.session);
Wink Saville8b4e4f72014-10-17 15:01:45 -07002019
2020 closeRequest;
2021 printRequest(pRI->token, pRI->pCI->requestNumber);
2022
2023 CALL_ONREQUEST(pRI->pCI->requestNumber,
2024 &rc,
2025 sizeof(RIL_RadioCapability),
2026 pRI, pRI->socket_id);
2027 return;
2028invalid:
2029 invalidCommandBlock(pRI);
2030 return;
2031}
2032
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002033static int
Wink Savillef4c4d362009-04-02 01:37:03 -07002034blockingWrite(int fd, const void *buffer, size_t len) {
Wink Saville7f856802009-06-09 10:23:37 -07002035 size_t writeOffset = 0;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002036 const uint8_t *toWrite;
2037
2038 toWrite = (const uint8_t *)buffer;
2039
2040 while (writeOffset < len) {
2041 ssize_t written;
2042 do {
2043 written = write (fd, toWrite + writeOffset,
2044 len - writeOffset);
Banavathu, Srinivas Naik38884902011-07-05 20:04:25 +05302045 } while (written < 0 && ((errno == EINTR) || (errno == EAGAIN)));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002046
2047 if (written >= 0) {
2048 writeOffset += written;
2049 } else { // written < 0
Wink Saville8eb2a122012-11-19 16:05:13 -08002050 RLOGE ("RIL Response: unexpected error on write errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002051 close(fd);
2052 return -1;
2053 }
2054 }
Dheeraj Shetty27976c42014-07-02 21:27:57 +02002055 RLOGE("RIL Response bytes written:%d", writeOffset);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002056 return 0;
2057}
2058
2059static int
Etan Cohend3652192014-06-20 08:28:44 -07002060sendResponseRaw (const void *data, size_t dataSize, RIL_SOCKET_ID socket_id) {
2061 int fd = s_ril_param_socket.fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002062 int ret;
2063 uint32_t header;
Etan Cohend3652192014-06-20 08:28:44 -07002064 pthread_mutex_t * writeMutexHook = &s_writeMutex;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002065
Etan Cohend3652192014-06-20 08:28:44 -07002066 RLOGE("Send Response to %s", rilSocketIdToString(socket_id));
2067
2068#if (SIM_COUNT >= 2)
2069 if (socket_id == RIL_SOCKET_2) {
2070 fd = s_ril_param_socket2.fdCommand;
2071 writeMutexHook = &s_writeMutex_socket2;
2072 }
2073#if (SIM_COUNT >= 3)
2074 else if (socket_id == RIL_SOCKET_3) {
2075 fd = s_ril_param_socket3.fdCommand;
2076 writeMutexHook = &s_writeMutex_socket3;
2077 }
2078#endif
2079#if (SIM_COUNT >= 4)
2080 else if (socket_id == RIL_SOCKET_4) {
2081 fd = s_ril_param_socket4.fdCommand;
2082 writeMutexHook = &s_writeMutex_socket4;
2083 }
2084#endif
2085#endif
2086 if (fd < 0) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002087 return -1;
2088 }
2089
2090 if (dataSize > MAX_COMMAND_BYTES) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002091 RLOGE("RIL: packet larger than %u (%u)",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002092 MAX_COMMAND_BYTES, (unsigned int )dataSize);
2093
2094 return -1;
2095 }
Wink Saville7f856802009-06-09 10:23:37 -07002096
Etan Cohend3652192014-06-20 08:28:44 -07002097 pthread_mutex_lock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002098
2099 header = htonl(dataSize);
2100
2101 ret = blockingWrite(fd, (void *)&header, sizeof(header));
2102
2103 if (ret < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002104 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002105 return ret;
2106 }
2107
Kennyee1fadc2009-08-13 00:45:53 +08002108 ret = blockingWrite(fd, data, dataSize);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002109
2110 if (ret < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002111 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002112 return ret;
2113 }
2114
Etan Cohend3652192014-06-20 08:28:44 -07002115 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002116
2117 return 0;
2118}
2119
2120static int
Etan Cohend3652192014-06-20 08:28:44 -07002121sendResponse (Parcel &p, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002122 printResponse;
Etan Cohend3652192014-06-20 08:28:44 -07002123 return sendResponseRaw(p.data(), p.dataSize(), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002124}
2125
Mohamad Ayyash74f7e662014-04-18 11:43:28 -07002126/** response is an int* pointing to an array of ints */
Wink Saville7f856802009-06-09 10:23:37 -07002127
2128static int
Wink Savillef4c4d362009-04-02 01:37:03 -07002129responseInts(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002130 int numInts;
2131
2132 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002133 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002134 return RIL_ERRNO_INVALID_RESPONSE;
2135 }
2136 if (responselen % sizeof(int) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002137 RLOGE("responseInts: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002138 (int)responselen, (int)sizeof(int));
2139 return RIL_ERRNO_INVALID_RESPONSE;
2140 }
2141
2142 int *p_int = (int *) response;
2143
Mohamad Ayyash74f7e662014-04-18 11:43:28 -07002144 numInts = responselen / sizeof(int);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002145 p.writeInt32 (numInts);
2146
2147 /* each int*/
2148 startResponse;
2149 for (int i = 0 ; i < numInts ; i++) {
2150 appendPrintBuf("%s%d,", printBuf, p_int[i]);
2151 p.writeInt32(p_int[i]);
2152 }
2153 removeLastChar;
2154 closeResponse;
2155
2156 return 0;
2157}
2158
Wink Saville43808972011-01-13 17:39:51 -08002159/** response is a char **, pointing to an array of char *'s
2160 The parcel will begin with the version */
2161static int responseStringsWithVersion(int version, Parcel &p, void *response, size_t responselen) {
2162 p.writeInt32(version);
2163 return responseStrings(p, response, responselen);
2164}
2165
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002166/** response is a char **, pointing to an array of char *'s */
Wink Savillef4c4d362009-04-02 01:37:03 -07002167static int responseStrings(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002168 int numStrings;
Wink Saville7f856802009-06-09 10:23:37 -07002169
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002170 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002171 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002172 return RIL_ERRNO_INVALID_RESPONSE;
2173 }
2174 if (responselen % sizeof(char *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002175 RLOGE("responseStrings: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002176 (int)responselen, (int)sizeof(char *));
2177 return RIL_ERRNO_INVALID_RESPONSE;
2178 }
2179
2180 if (response == NULL) {
2181 p.writeInt32 (0);
2182 } else {
2183 char **p_cur = (char **) response;
2184
2185 numStrings = responselen / sizeof(char *);
2186 p.writeInt32 (numStrings);
2187
2188 /* each string*/
2189 startResponse;
2190 for (int i = 0 ; i < numStrings ; i++) {
2191 appendPrintBuf("%s%s,", printBuf, (char*)p_cur[i]);
2192 writeStringToParcel (p, p_cur[i]);
2193 }
2194 removeLastChar;
2195 closeResponse;
2196 }
2197 return 0;
2198}
2199
2200
2201/**
Wink Saville7f856802009-06-09 10:23:37 -07002202 * NULL strings are accepted
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002203 * FIXME currently ignores responselen
2204 */
Wink Savillef4c4d362009-04-02 01:37:03 -07002205static int responseString(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002206 /* one string only */
2207 startResponse;
2208 appendPrintBuf("%s%s", printBuf, (char*)response);
2209 closeResponse;
2210
2211 writeStringToParcel(p, (const char *)response);
2212
2213 return 0;
2214}
2215
Wink Savillef4c4d362009-04-02 01:37:03 -07002216static int responseVoid(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002217 startResponse;
2218 removeLastChar;
2219 return 0;
2220}
2221
Wink Savillef4c4d362009-04-02 01:37:03 -07002222static int responseCallList(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002223 int num;
2224
2225 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002226 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002227 return RIL_ERRNO_INVALID_RESPONSE;
2228 }
2229
2230 if (responselen % sizeof (RIL_Call *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002231 RLOGE("responseCallList: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002232 (int)responselen, (int)sizeof (RIL_Call *));
2233 return RIL_ERRNO_INVALID_RESPONSE;
2234 }
2235
2236 startResponse;
2237 /* number of call info's */
2238 num = responselen / sizeof(RIL_Call *);
2239 p.writeInt32(num);
2240
2241 for (int i = 0 ; i < num ; i++) {
2242 RIL_Call *p_cur = ((RIL_Call **) response)[i];
2243 /* each call info */
2244 p.writeInt32(p_cur->state);
2245 p.writeInt32(p_cur->index);
2246 p.writeInt32(p_cur->toa);
2247 p.writeInt32(p_cur->isMpty);
2248 p.writeInt32(p_cur->isMT);
2249 p.writeInt32(p_cur->als);
2250 p.writeInt32(p_cur->isVoice);
Wink Saville1b5fd232009-04-22 14:50:00 -07002251 p.writeInt32(p_cur->isVoicePrivacy);
2252 writeStringToParcel(p, p_cur->number);
John Wangff368742009-03-24 17:56:29 -07002253 p.writeInt32(p_cur->numberPresentation);
Wink Saville1b5fd232009-04-22 14:50:00 -07002254 writeStringToParcel(p, p_cur->name);
2255 p.writeInt32(p_cur->namePresentation);
Wink Saville3a4840b2010-04-07 13:29:58 -07002256 // Remove when partners upgrade to version 3
Wink Saville74fa3882009-12-22 15:35:41 -08002257 if ((s_callbacks.version < 3) || (p_cur->uusInfo == NULL || p_cur->uusInfo->uusData == NULL)) {
2258 p.writeInt32(0); /* UUS Information is absent */
2259 } else {
2260 RIL_UUS_Info *uusInfo = p_cur->uusInfo;
2261 p.writeInt32(1); /* UUS Information is present */
2262 p.writeInt32(uusInfo->uusType);
2263 p.writeInt32(uusInfo->uusDcs);
2264 p.writeInt32(uusInfo->uusLength);
2265 p.write(uusInfo->uusData, uusInfo->uusLength);
2266 }
Wink Saville3d54e742009-05-18 18:00:44 -07002267 appendPrintBuf("%s[id=%d,%s,toa=%d,",
John Wangff368742009-03-24 17:56:29 -07002268 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002269 p_cur->index,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002270 callStateToString(p_cur->state),
Wink Saville3d54e742009-05-18 18:00:44 -07002271 p_cur->toa);
2272 appendPrintBuf("%s%s,%s,als=%d,%s,%s,",
2273 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002274 (p_cur->isMpty)?"conf":"norm",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002275 (p_cur->isMT)?"mt":"mo",
2276 p_cur->als,
2277 (p_cur->isVoice)?"voc":"nonvoc",
Wink Saville3d54e742009-05-18 18:00:44 -07002278 (p_cur->isVoicePrivacy)?"evp":"noevp");
2279 appendPrintBuf("%s%s,cli=%d,name='%s',%d]",
2280 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002281 p_cur->number,
2282 p_cur->numberPresentation,
2283 p_cur->name,
2284 p_cur->namePresentation);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002285 }
2286 removeLastChar;
2287 closeResponse;
2288
2289 return 0;
2290}
2291
Wink Savillef4c4d362009-04-02 01:37:03 -07002292static int responseSMS(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002293 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002294 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002295 return RIL_ERRNO_INVALID_RESPONSE;
2296 }
2297
2298 if (responselen != sizeof (RIL_SMS_Response) ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002299 RLOGE("invalid response length %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002300 (int)responselen, (int)sizeof (RIL_SMS_Response));
2301 return RIL_ERRNO_INVALID_RESPONSE;
2302 }
2303
2304 RIL_SMS_Response *p_cur = (RIL_SMS_Response *) response;
2305
2306 p.writeInt32(p_cur->messageRef);
2307 writeStringToParcel(p, p_cur->ackPDU);
Jaikumar Ganesh920c78f2009-06-04 10:53:15 -07002308 p.writeInt32(p_cur->errorCode);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002309
2310 startResponse;
Jaikumar Ganesh920c78f2009-06-04 10:53:15 -07002311 appendPrintBuf("%s%d,%s,%d", printBuf, p_cur->messageRef,
2312 (char*)p_cur->ackPDU, p_cur->errorCode);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002313 closeResponse;
2314
2315 return 0;
2316}
2317
Wink Savillec0114b32011-02-18 10:14:07 -08002318static int responseDataCallListV4(Parcel &p, void *response, size_t responselen)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002319{
2320 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002321 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002322 return RIL_ERRNO_INVALID_RESPONSE;
2323 }
2324
Wink Savillec0114b32011-02-18 10:14:07 -08002325 if (responselen % sizeof(RIL_Data_Call_Response_v4) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002326 RLOGE("responseDataCallListV4: invalid response length %d expected multiple of %d",
Wink Savillec0114b32011-02-18 10:14:07 -08002327 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v4));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002328 return RIL_ERRNO_INVALID_RESPONSE;
2329 }
2330
Amit Mahajan52500162014-07-29 17:36:48 -07002331 // Write version
2332 p.writeInt32(4);
2333
Wink Savillec0114b32011-02-18 10:14:07 -08002334 int num = responselen / sizeof(RIL_Data_Call_Response_v4);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002335 p.writeInt32(num);
2336
Wink Savillec0114b32011-02-18 10:14:07 -08002337 RIL_Data_Call_Response_v4 *p_cur = (RIL_Data_Call_Response_v4 *) response;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002338 startResponse;
2339 int i;
2340 for (i = 0; i < num; i++) {
2341 p.writeInt32(p_cur[i].cid);
2342 p.writeInt32(p_cur[i].active);
2343 writeStringToParcel(p, p_cur[i].type);
Wink Savillec0114b32011-02-18 10:14:07 -08002344 // apn is not used, so don't send.
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002345 writeStringToParcel(p, p_cur[i].address);
Wink Savillec0114b32011-02-18 10:14:07 -08002346 appendPrintBuf("%s[cid=%d,%s,%s,%s],", printBuf,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002347 p_cur[i].cid,
2348 (p_cur[i].active==0)?"down":"up",
2349 (char*)p_cur[i].type,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002350 (char*)p_cur[i].address);
2351 }
2352 removeLastChar;
2353 closeResponse;
2354
2355 return 0;
2356}
2357
Etan Cohend3652192014-06-20 08:28:44 -07002358static int responseDataCallListV6(Parcel &p, void *response, size_t responselen)
2359{
Amit Mahajan52500162014-07-29 17:36:48 -07002360 if (response == NULL && responselen != 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002361 RLOGE("invalid response: NULL");
2362 return RIL_ERRNO_INVALID_RESPONSE;
2363 }
2364
2365 if (responselen % sizeof(RIL_Data_Call_Response_v6) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002366 RLOGE("responseDataCallListV6: invalid response length %d expected multiple of %d",
Etan Cohend3652192014-06-20 08:28:44 -07002367 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v6));
2368 return RIL_ERRNO_INVALID_RESPONSE;
2369 }
2370
Amit Mahajan52500162014-07-29 17:36:48 -07002371 // Write version
2372 p.writeInt32(6);
2373
Etan Cohend3652192014-06-20 08:28:44 -07002374 int num = responselen / sizeof(RIL_Data_Call_Response_v6);
2375 p.writeInt32(num);
2376
2377 RIL_Data_Call_Response_v6 *p_cur = (RIL_Data_Call_Response_v6 *) response;
2378 startResponse;
2379 int i;
2380 for (i = 0; i < num; i++) {
2381 p.writeInt32((int)p_cur[i].status);
2382 p.writeInt32(p_cur[i].suggestedRetryTime);
2383 p.writeInt32(p_cur[i].cid);
2384 p.writeInt32(p_cur[i].active);
2385 writeStringToParcel(p, p_cur[i].type);
2386 writeStringToParcel(p, p_cur[i].ifname);
2387 writeStringToParcel(p, p_cur[i].addresses);
2388 writeStringToParcel(p, p_cur[i].dnses);
2389 writeStringToParcel(p, p_cur[i].gateways);
2390 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s],", printBuf,
2391 p_cur[i].status,
2392 p_cur[i].suggestedRetryTime,
2393 p_cur[i].cid,
2394 (p_cur[i].active==0)?"down":"up",
2395 (char*)p_cur[i].type,
2396 (char*)p_cur[i].ifname,
2397 (char*)p_cur[i].addresses,
2398 (char*)p_cur[i].dnses,
2399 (char*)p_cur[i].gateways);
2400 }
2401 removeLastChar;
2402 closeResponse;
2403
2404 return 0;
2405}
2406
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002407static int responseDataCallListV9(Parcel &p, void *response, size_t responselen)
2408{
2409 if (response == NULL && responselen != 0) {
2410 RLOGE("invalid response: NULL");
2411 return RIL_ERRNO_INVALID_RESPONSE;
2412 }
2413
2414 if (responselen % sizeof(RIL_Data_Call_Response_v9) != 0) {
2415 RLOGE("responseDataCallListV9: invalid response length %d expected multiple of %d",
2416 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v9));
2417 return RIL_ERRNO_INVALID_RESPONSE;
2418 }
2419
2420 // Write version
2421 p.writeInt32(10);
2422
2423 int num = responselen / sizeof(RIL_Data_Call_Response_v9);
2424 p.writeInt32(num);
2425
2426 RIL_Data_Call_Response_v9 *p_cur = (RIL_Data_Call_Response_v9 *) response;
2427 startResponse;
2428 int i;
2429 for (i = 0; i < num; i++) {
2430 p.writeInt32((int)p_cur[i].status);
2431 p.writeInt32(p_cur[i].suggestedRetryTime);
2432 p.writeInt32(p_cur[i].cid);
2433 p.writeInt32(p_cur[i].active);
2434 writeStringToParcel(p, p_cur[i].type);
2435 writeStringToParcel(p, p_cur[i].ifname);
2436 writeStringToParcel(p, p_cur[i].addresses);
2437 writeStringToParcel(p, p_cur[i].dnses);
2438 writeStringToParcel(p, p_cur[i].gateways);
2439 writeStringToParcel(p, p_cur[i].pcscf);
2440 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s],", printBuf,
2441 p_cur[i].status,
2442 p_cur[i].suggestedRetryTime,
2443 p_cur[i].cid,
2444 (p_cur[i].active==0)?"down":"up",
2445 (char*)p_cur[i].type,
2446 (char*)p_cur[i].ifname,
2447 (char*)p_cur[i].addresses,
2448 (char*)p_cur[i].dnses,
2449 (char*)p_cur[i].gateways,
2450 (char*)p_cur[i].pcscf);
2451 }
2452 removeLastChar;
2453 closeResponse;
2454
2455 return 0;
2456}
2457
2458
Wink Saville43808972011-01-13 17:39:51 -08002459static int responseDataCallList(Parcel &p, void *response, size_t responselen)
2460{
Wink Saville43808972011-01-13 17:39:51 -08002461 if (s_callbacks.version < 5) {
Amit Mahajan52500162014-07-29 17:36:48 -07002462 RLOGD("responseDataCallList: v4");
Wink Savillec0114b32011-02-18 10:14:07 -08002463 return responseDataCallListV4(p, response, responselen);
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002464 } else if (responselen % sizeof(RIL_Data_Call_Response_v6) == 0) {
2465 return responseDataCallListV6(p, response, responselen);
2466 } else if (responselen % sizeof(RIL_Data_Call_Response_v9) == 0) {
2467 return responseDataCallListV9(p, response, responselen);
Wink Saville43808972011-01-13 17:39:51 -08002468 } else {
2469 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002470 RLOGE("invalid response: NULL");
Wink Saville43808972011-01-13 17:39:51 -08002471 return RIL_ERRNO_INVALID_RESPONSE;
2472 }
2473
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002474 if (responselen % sizeof(RIL_Data_Call_Response_v11) != 0) {
2475 RLOGE("invalid response length %d expected multiple of %d",
2476 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v11));
Wink Saville43808972011-01-13 17:39:51 -08002477 return RIL_ERRNO_INVALID_RESPONSE;
2478 }
2479
Amit Mahajan52500162014-07-29 17:36:48 -07002480 // Write version
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002481 p.writeInt32(11);
Amit Mahajan52500162014-07-29 17:36:48 -07002482
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002483 int num = responselen / sizeof(RIL_Data_Call_Response_v11);
Wink Saville43808972011-01-13 17:39:51 -08002484 p.writeInt32(num);
2485
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002486 RIL_Data_Call_Response_v11 *p_cur = (RIL_Data_Call_Response_v11 *) response;
Wink Saville43808972011-01-13 17:39:51 -08002487 startResponse;
2488 int i;
2489 for (i = 0; i < num; i++) {
2490 p.writeInt32((int)p_cur[i].status);
Kazuhiro Ondobeb25b52011-06-17 16:26:45 -05002491 p.writeInt32(p_cur[i].suggestedRetryTime);
Wink Saville43808972011-01-13 17:39:51 -08002492 p.writeInt32(p_cur[i].cid);
2493 p.writeInt32(p_cur[i].active);
David 'Digit' Turneraf1298d2011-02-04 13:36:47 +01002494 writeStringToParcel(p, p_cur[i].type);
Wink Saville43808972011-01-13 17:39:51 -08002495 writeStringToParcel(p, p_cur[i].ifname);
2496 writeStringToParcel(p, p_cur[i].addresses);
2497 writeStringToParcel(p, p_cur[i].dnses);
Wink Savillec0114b32011-02-18 10:14:07 -08002498 writeStringToParcel(p, p_cur[i].gateways);
Etan Cohend3652192014-06-20 08:28:44 -07002499 writeStringToParcel(p, p_cur[i].pcscf);
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002500 p.writeInt32(p_cur[i].mtu);
2501 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 -08002502 p_cur[i].status,
Kazuhiro Ondobeb25b52011-06-17 16:26:45 -05002503 p_cur[i].suggestedRetryTime,
Wink Saville43808972011-01-13 17:39:51 -08002504 p_cur[i].cid,
2505 (p_cur[i].active==0)?"down":"up",
Naveen Kalla56384152011-11-16 11:12:37 -08002506 (char*)p_cur[i].type,
Wink Saville43808972011-01-13 17:39:51 -08002507 (char*)p_cur[i].ifname,
2508 (char*)p_cur[i].addresses,
Wink Savillec0114b32011-02-18 10:14:07 -08002509 (char*)p_cur[i].dnses,
Etan Cohend3652192014-06-20 08:28:44 -07002510 (char*)p_cur[i].gateways,
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002511 (char*)p_cur[i].pcscf,
2512 p_cur[i].mtu);
Wink Saville43808972011-01-13 17:39:51 -08002513 }
2514 removeLastChar;
2515 closeResponse;
2516 }
2517
2518 return 0;
2519}
2520
2521static int responseSetupDataCall(Parcel &p, void *response, size_t responselen)
2522{
2523 if (s_callbacks.version < 5) {
2524 return responseStringsWithVersion(s_callbacks.version, p, response, responselen);
2525 } else {
2526 return responseDataCallList(p, response, responselen);
2527 }
2528}
2529
Wink Savillef4c4d362009-04-02 01:37:03 -07002530static int responseRaw(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002531 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002532 RLOGE("invalid response: NULL with responselen != 0");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002533 return RIL_ERRNO_INVALID_RESPONSE;
2534 }
2535
2536 // The java code reads -1 size as null byte array
2537 if (response == NULL) {
Wink Saville7f856802009-06-09 10:23:37 -07002538 p.writeInt32(-1);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002539 } else {
2540 p.writeInt32(responselen);
2541 p.write(response, responselen);
2542 }
2543
2544 return 0;
2545}
2546
2547
Wink Savillef4c4d362009-04-02 01:37:03 -07002548static int responseSIM_IO(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002549 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002550 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002551 return RIL_ERRNO_INVALID_RESPONSE;
2552 }
2553
2554 if (responselen != sizeof (RIL_SIM_IO_Response) ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002555 RLOGE("invalid response length was %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002556 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
2557 return RIL_ERRNO_INVALID_RESPONSE;
2558 }
2559
2560 RIL_SIM_IO_Response *p_cur = (RIL_SIM_IO_Response *) response;
2561 p.writeInt32(p_cur->sw1);
2562 p.writeInt32(p_cur->sw2);
2563 writeStringToParcel(p, p_cur->simResponse);
2564
2565 startResponse;
2566 appendPrintBuf("%ssw1=0x%X,sw2=0x%X,%s", printBuf, p_cur->sw1, p_cur->sw2,
2567 (char*)p_cur->simResponse);
2568 closeResponse;
2569
2570
2571 return 0;
2572}
2573
Wink Savillef4c4d362009-04-02 01:37:03 -07002574static int responseCallForwards(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002575 int num;
Wink Saville7f856802009-06-09 10:23:37 -07002576
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002577 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002578 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002579 return RIL_ERRNO_INVALID_RESPONSE;
2580 }
2581
2582 if (responselen % sizeof(RIL_CallForwardInfo *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002583 RLOGE("responseCallForwards: invalid response length %d expected multiple of %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002584 (int)responselen, (int)sizeof(RIL_CallForwardInfo *));
2585 return RIL_ERRNO_INVALID_RESPONSE;
2586 }
2587
2588 /* number of call info's */
2589 num = responselen / sizeof(RIL_CallForwardInfo *);
2590 p.writeInt32(num);
2591
2592 startResponse;
2593 for (int i = 0 ; i < num ; i++) {
2594 RIL_CallForwardInfo *p_cur = ((RIL_CallForwardInfo **) response)[i];
2595
2596 p.writeInt32(p_cur->status);
2597 p.writeInt32(p_cur->reason);
2598 p.writeInt32(p_cur->serviceClass);
2599 p.writeInt32(p_cur->toa);
2600 writeStringToParcel(p, p_cur->number);
2601 p.writeInt32(p_cur->timeSeconds);
2602 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
2603 (p_cur->status==1)?"enable":"disable",
2604 p_cur->reason, p_cur->serviceClass, p_cur->toa,
2605 (char*)p_cur->number,
2606 p_cur->timeSeconds);
2607 }
2608 removeLastChar;
2609 closeResponse;
Wink Saville7f856802009-06-09 10:23:37 -07002610
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002611 return 0;
2612}
2613
Wink Savillef4c4d362009-04-02 01:37:03 -07002614static int responseSsn(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002615 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002616 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002617 return RIL_ERRNO_INVALID_RESPONSE;
2618 }
2619
2620 if (responselen != sizeof(RIL_SuppSvcNotification)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002621 RLOGE("invalid response length was %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002622 (int)responselen, (int)sizeof (RIL_SuppSvcNotification));
2623 return RIL_ERRNO_INVALID_RESPONSE;
2624 }
2625
2626 RIL_SuppSvcNotification *p_cur = (RIL_SuppSvcNotification *) response;
2627 p.writeInt32(p_cur->notificationType);
2628 p.writeInt32(p_cur->code);
2629 p.writeInt32(p_cur->index);
2630 p.writeInt32(p_cur->type);
2631 writeStringToParcel(p, p_cur->number);
2632
2633 startResponse;
2634 appendPrintBuf("%s%s,code=%d,id=%d,type=%d,%s", printBuf,
2635 (p_cur->notificationType==0)?"mo":"mt",
2636 p_cur->code, p_cur->index, p_cur->type,
2637 (char*)p_cur->number);
2638 closeResponse;
2639
2640 return 0;
2641}
2642
Wink Saville3d54e742009-05-18 18:00:44 -07002643static int responseCellList(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002644 int num;
2645
2646 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002647 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002648 return RIL_ERRNO_INVALID_RESPONSE;
2649 }
2650
2651 if (responselen % sizeof (RIL_NeighboringCell *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002652 RLOGE("responseCellList: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002653 (int)responselen, (int)sizeof (RIL_NeighboringCell *));
2654 return RIL_ERRNO_INVALID_RESPONSE;
2655 }
2656
2657 startResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002658 /* number of records */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002659 num = responselen / sizeof(RIL_NeighboringCell *);
2660 p.writeInt32(num);
2661
2662 for (int i = 0 ; i < num ; i++) {
2663 RIL_NeighboringCell *p_cur = ((RIL_NeighboringCell **) response)[i];
2664
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002665 p.writeInt32(p_cur->rssi);
2666 writeStringToParcel (p, p_cur->cid);
2667
2668 appendPrintBuf("%s[cid=%s,rssi=%d],", printBuf,
2669 p_cur->cid, p_cur->rssi);
2670 }
2671 removeLastChar;
2672 closeResponse;
2673
2674 return 0;
2675}
2676
Wink Saville3d54e742009-05-18 18:00:44 -07002677/**
2678 * Marshall the signalInfoRecord into the parcel if it exists.
2679 */
Wink Savillea592eeb2009-05-22 13:26:36 -07002680static void marshallSignalInfoRecord(Parcel &p,
2681 RIL_CDMA_SignalInfoRecord &p_signalInfoRecord) {
Wink Saville3d54e742009-05-18 18:00:44 -07002682 p.writeInt32(p_signalInfoRecord.isPresent);
2683 p.writeInt32(p_signalInfoRecord.signalType);
2684 p.writeInt32(p_signalInfoRecord.alertPitch);
2685 p.writeInt32(p_signalInfoRecord.signal);
2686}
2687
Wink Savillea592eeb2009-05-22 13:26:36 -07002688static int responseCdmaInformationRecords(Parcel &p,
2689 void *response, size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07002690 int num;
Wink Savillea592eeb2009-05-22 13:26:36 -07002691 char* string8 = NULL;
2692 int buffer_lenght;
2693 RIL_CDMA_InformationRecord *infoRec;
Wink Saville3d54e742009-05-18 18:00:44 -07002694
2695 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002696 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002697 return RIL_ERRNO_INVALID_RESPONSE;
2698 }
2699
Wink Savillea592eeb2009-05-22 13:26:36 -07002700 if (responselen != sizeof (RIL_CDMA_InformationRecords)) {
Amit Mahajan52500162014-07-29 17:36:48 -07002701 RLOGE("responseCdmaInformationRecords: invalid response length %d expected multiple of %d\n",
Wink Savillea592eeb2009-05-22 13:26:36 -07002702 (int)responselen, (int)sizeof (RIL_CDMA_InformationRecords *));
Wink Saville3d54e742009-05-18 18:00:44 -07002703 return RIL_ERRNO_INVALID_RESPONSE;
2704 }
2705
Wink Savillea592eeb2009-05-22 13:26:36 -07002706 RIL_CDMA_InformationRecords *p_cur =
2707 (RIL_CDMA_InformationRecords *) response;
2708 num = MIN(p_cur->numberOfInfoRecs, RIL_CDMA_MAX_NUMBER_OF_INFO_RECS);
Wink Saville3d54e742009-05-18 18:00:44 -07002709
2710 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07002711 p.writeInt32(num);
Wink Saville3d54e742009-05-18 18:00:44 -07002712
Wink Savillea592eeb2009-05-22 13:26:36 -07002713 for (int i = 0 ; i < num ; i++) {
2714 infoRec = &p_cur->infoRec[i];
2715 p.writeInt32(infoRec->name);
2716 switch (infoRec->name) {
Wink Saville3d54e742009-05-18 18:00:44 -07002717 case RIL_CDMA_DISPLAY_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002718 case RIL_CDMA_EXTENDED_DISPLAY_INFO_REC:
2719 if (infoRec->rec.display.alpha_len >
2720 CDMA_ALPHA_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002721 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002722 expected not more than %d\n",
2723 (int)infoRec->rec.display.alpha_len,
2724 CDMA_ALPHA_INFO_BUFFER_LENGTH);
2725 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002726 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002727 string8 = (char*) malloc((infoRec->rec.display.alpha_len + 1)
2728 * sizeof(char) );
2729 for (int i = 0 ; i < infoRec->rec.display.alpha_len ; i++) {
2730 string8[i] = infoRec->rec.display.alpha_buf[i];
2731 }
Wink Saville43808972011-01-13 17:39:51 -08002732 string8[(int)infoRec->rec.display.alpha_len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002733 writeStringToParcel(p, (const char*)string8);
2734 free(string8);
2735 string8 = NULL;
Wink Saville3d54e742009-05-18 18:00:44 -07002736 break;
2737 case RIL_CDMA_CALLED_PARTY_NUMBER_INFO_REC:
Wink Saville3d54e742009-05-18 18:00:44 -07002738 case RIL_CDMA_CALLING_PARTY_NUMBER_INFO_REC:
Wink Saville3d54e742009-05-18 18:00:44 -07002739 case RIL_CDMA_CONNECTED_NUMBER_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002740 if (infoRec->rec.number.len > CDMA_NUMBER_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002741 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002742 expected not more than %d\n",
2743 (int)infoRec->rec.number.len,
2744 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2745 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002746 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002747 string8 = (char*) malloc((infoRec->rec.number.len + 1)
2748 * sizeof(char) );
2749 for (int i = 0 ; i < infoRec->rec.number.len; i++) {
2750 string8[i] = infoRec->rec.number.buf[i];
2751 }
Wink Saville43808972011-01-13 17:39:51 -08002752 string8[(int)infoRec->rec.number.len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002753 writeStringToParcel(p, (const char*)string8);
2754 free(string8);
2755 string8 = NULL;
2756 p.writeInt32(infoRec->rec.number.number_type);
2757 p.writeInt32(infoRec->rec.number.number_plan);
2758 p.writeInt32(infoRec->rec.number.pi);
2759 p.writeInt32(infoRec->rec.number.si);
Wink Saville3d54e742009-05-18 18:00:44 -07002760 break;
2761 case RIL_CDMA_SIGNAL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002762 p.writeInt32(infoRec->rec.signal.isPresent);
2763 p.writeInt32(infoRec->rec.signal.signalType);
2764 p.writeInt32(infoRec->rec.signal.alertPitch);
2765 p.writeInt32(infoRec->rec.signal.signal);
2766
2767 appendPrintBuf("%sisPresent=%X, signalType=%X, \
2768 alertPitch=%X, signal=%X, ",
2769 printBuf, (int)infoRec->rec.signal.isPresent,
2770 (int)infoRec->rec.signal.signalType,
2771 (int)infoRec->rec.signal.alertPitch,
2772 (int)infoRec->rec.signal.signal);
2773 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002774 break;
2775 case RIL_CDMA_REDIRECTING_NUMBER_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002776 if (infoRec->rec.redir.redirectingNumber.len >
2777 CDMA_NUMBER_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002778 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002779 expected not more than %d\n",
2780 (int)infoRec->rec.redir.redirectingNumber.len,
2781 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2782 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002783 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002784 string8 = (char*) malloc((infoRec->rec.redir.redirectingNumber
2785 .len + 1) * sizeof(char) );
2786 for (int i = 0;
2787 i < infoRec->rec.redir.redirectingNumber.len;
2788 i++) {
2789 string8[i] = infoRec->rec.redir.redirectingNumber.buf[i];
2790 }
Wink Saville43808972011-01-13 17:39:51 -08002791 string8[(int)infoRec->rec.redir.redirectingNumber.len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002792 writeStringToParcel(p, (const char*)string8);
2793 free(string8);
2794 string8 = NULL;
2795 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_type);
2796 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_plan);
2797 p.writeInt32(infoRec->rec.redir.redirectingNumber.pi);
2798 p.writeInt32(infoRec->rec.redir.redirectingNumber.si);
2799 p.writeInt32(infoRec->rec.redir.redirectingReason);
Wink Saville3d54e742009-05-18 18:00:44 -07002800 break;
2801 case RIL_CDMA_LINE_CONTROL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002802 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPolarityIncluded);
2803 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlToggle);
2804 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlReverse);
2805 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2806
2807 appendPrintBuf("%slineCtrlPolarityIncluded=%d, \
2808 lineCtrlToggle=%d, lineCtrlReverse=%d, \
2809 lineCtrlPowerDenial=%d, ", printBuf,
2810 (int)infoRec->rec.lineCtrl.lineCtrlPolarityIncluded,
2811 (int)infoRec->rec.lineCtrl.lineCtrlToggle,
2812 (int)infoRec->rec.lineCtrl.lineCtrlReverse,
2813 (int)infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2814 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002815 break;
2816 case RIL_CDMA_T53_CLIR_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002817 p.writeInt32((int)(infoRec->rec.clir.cause));
Wink Saville3d54e742009-05-18 18:00:44 -07002818
Wink Savillea592eeb2009-05-22 13:26:36 -07002819 appendPrintBuf("%scause%d", printBuf, infoRec->rec.clir.cause);
2820 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002821 break;
2822 case RIL_CDMA_T53_AUDIO_CONTROL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002823 p.writeInt32(infoRec->rec.audioCtrl.upLink);
2824 p.writeInt32(infoRec->rec.audioCtrl.downLink);
2825
2826 appendPrintBuf("%supLink=%d, downLink=%d, ", printBuf,
2827 infoRec->rec.audioCtrl.upLink,
2828 infoRec->rec.audioCtrl.downLink);
2829 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002830 break;
Wink Savillea592eeb2009-05-22 13:26:36 -07002831 case RIL_CDMA_T53_RELEASE_INFO_REC:
2832 // TODO(Moto): See David Krause, he has the answer:)
Wink Saville8eb2a122012-11-19 16:05:13 -08002833 RLOGE("RIL_CDMA_T53_RELEASE_INFO_REC: return INVALID_RESPONSE");
Wink Savillea592eeb2009-05-22 13:26:36 -07002834 return RIL_ERRNO_INVALID_RESPONSE;
2835 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08002836 RLOGE("Incorrect name value");
Wink Savillea592eeb2009-05-22 13:26:36 -07002837 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002838 }
2839 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002840 closeResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002841
Wink Savillea592eeb2009-05-22 13:26:36 -07002842 return 0;
Wink Saville3d54e742009-05-18 18:00:44 -07002843}
2844
Wink Savillea592eeb2009-05-22 13:26:36 -07002845static int responseRilSignalStrength(Parcel &p,
2846 void *response, size_t responselen) {
2847 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002848 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002849 return RIL_ERRNO_INVALID_RESPONSE;
2850 }
2851
Wink Savillec0114b32011-02-18 10:14:07 -08002852 if (responselen >= sizeof (RIL_SignalStrength_v5)) {
Etan Cohend3652192014-06-20 08:28:44 -07002853 RIL_SignalStrength_v10 *p_cur = ((RIL_SignalStrength_v10 *) response);
Wink Saville3d54e742009-05-18 18:00:44 -07002854
Wink Saville3d54e742009-05-18 18:00:44 -07002855 p.writeInt32(p_cur->GW_SignalStrength.signalStrength);
2856 p.writeInt32(p_cur->GW_SignalStrength.bitErrorRate);
2857 p.writeInt32(p_cur->CDMA_SignalStrength.dbm);
2858 p.writeInt32(p_cur->CDMA_SignalStrength.ecio);
2859 p.writeInt32(p_cur->EVDO_SignalStrength.dbm);
2860 p.writeInt32(p_cur->EVDO_SignalStrength.ecio);
2861 p.writeInt32(p_cur->EVDO_SignalStrength.signalNoiseRatio);
Wink Savillec0114b32011-02-18 10:14:07 -08002862 if (responselen >= sizeof (RIL_SignalStrength_v6)) {
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002863 /*
Wink Saville18e4ab12013-04-07 17:31:04 -07002864 * Fixup LTE for backwards compatibility
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002865 */
Wink Saville18e4ab12013-04-07 17:31:04 -07002866 if (s_callbacks.version <= 6) {
2867 // signalStrength: -1 -> 99
2868 if (p_cur->LTE_SignalStrength.signalStrength == -1) {
2869 p_cur->LTE_SignalStrength.signalStrength = 99;
2870 }
2871 // rsrp: -1 -> INT_MAX all other negative value to positive.
2872 // So remap here
2873 if (p_cur->LTE_SignalStrength.rsrp == -1) {
2874 p_cur->LTE_SignalStrength.rsrp = INT_MAX;
2875 } else if (p_cur->LTE_SignalStrength.rsrp < -1) {
2876 p_cur->LTE_SignalStrength.rsrp = -p_cur->LTE_SignalStrength.rsrp;
2877 }
2878 // rsrq: -1 -> INT_MAX
2879 if (p_cur->LTE_SignalStrength.rsrq == -1) {
2880 p_cur->LTE_SignalStrength.rsrq = INT_MAX;
2881 }
2882 // Not remapping rssnr is already using INT_MAX
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002883
Wink Saville18e4ab12013-04-07 17:31:04 -07002884 // cqi: -1 -> INT_MAX
2885 if (p_cur->LTE_SignalStrength.cqi == -1) {
2886 p_cur->LTE_SignalStrength.cqi = INT_MAX;
2887 }
2888 }
2889 p.writeInt32(p_cur->LTE_SignalStrength.signalStrength);
Wink Savillec0114b32011-02-18 10:14:07 -08002890 p.writeInt32(p_cur->LTE_SignalStrength.rsrp);
2891 p.writeInt32(p_cur->LTE_SignalStrength.rsrq);
2892 p.writeInt32(p_cur->LTE_SignalStrength.rssnr);
2893 p.writeInt32(p_cur->LTE_SignalStrength.cqi);
Etan Cohend3652192014-06-20 08:28:44 -07002894 if (responselen >= sizeof (RIL_SignalStrength_v10)) {
2895 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
2896 } else {
2897 p.writeInt32(INT_MAX);
2898 }
Wink Savillec0114b32011-02-18 10:14:07 -08002899 } else {
Wink Saville18e4ab12013-04-07 17:31:04 -07002900 p.writeInt32(99);
2901 p.writeInt32(INT_MAX);
2902 p.writeInt32(INT_MAX);
2903 p.writeInt32(INT_MAX);
2904 p.writeInt32(INT_MAX);
Etan Cohend3652192014-06-20 08:28:44 -07002905 p.writeInt32(INT_MAX);
Wink Savillec0114b32011-02-18 10:14:07 -08002906 }
johnwangfdf825f2009-05-22 15:50:34 -07002907
2908 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07002909 appendPrintBuf("%s[signalStrength=%d,bitErrorRate=%d,\
Wink Savillec0114b32011-02-18 10:14:07 -08002910 CDMA_SS.dbm=%d,CDMA_SSecio=%d,\
2911 EVDO_SS.dbm=%d,EVDO_SS.ecio=%d,\
2912 EVDO_SS.signalNoiseRatio=%d,\
2913 LTE_SS.signalStrength=%d,LTE_SS.rsrp=%d,LTE_SS.rsrq=%d,\
Etan Cohend3652192014-06-20 08:28:44 -07002914 LTE_SS.rssnr=%d,LTE_SS.cqi=%d,TDSCDMA_SS.rscp=%d]",
Wink Savillea592eeb2009-05-22 13:26:36 -07002915 printBuf,
2916 p_cur->GW_SignalStrength.signalStrength,
2917 p_cur->GW_SignalStrength.bitErrorRate,
2918 p_cur->CDMA_SignalStrength.dbm,
2919 p_cur->CDMA_SignalStrength.ecio,
2920 p_cur->EVDO_SignalStrength.dbm,
2921 p_cur->EVDO_SignalStrength.ecio,
Wink Savillec0114b32011-02-18 10:14:07 -08002922 p_cur->EVDO_SignalStrength.signalNoiseRatio,
2923 p_cur->LTE_SignalStrength.signalStrength,
2924 p_cur->LTE_SignalStrength.rsrp,
2925 p_cur->LTE_SignalStrength.rsrq,
2926 p_cur->LTE_SignalStrength.rssnr,
Etan Cohend3652192014-06-20 08:28:44 -07002927 p_cur->LTE_SignalStrength.cqi,
2928 p_cur->TD_SCDMA_SignalStrength.rscp);
Wink Savillea592eeb2009-05-22 13:26:36 -07002929 closeResponse;
2930
Wink Saville3d54e742009-05-18 18:00:44 -07002931 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08002932 RLOGE("invalid response length");
Wink Saville3d54e742009-05-18 18:00:44 -07002933 return RIL_ERRNO_INVALID_RESPONSE;
2934 }
2935
Wink Saville3d54e742009-05-18 18:00:44 -07002936 return 0;
2937}
2938
2939static int responseCallRing(Parcel &p, void *response, size_t responselen) {
2940 if ((response == NULL) || (responselen == 0)) {
2941 return responseVoid(p, response, responselen);
2942 } else {
2943 return responseCdmaSignalInfoRecord(p, response, responselen);
2944 }
2945}
2946
2947static int responseCdmaSignalInfoRecord(Parcel &p, void *response, size_t responselen) {
2948 if (response == NULL || responselen == 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002949 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002950 return RIL_ERRNO_INVALID_RESPONSE;
2951 }
2952
2953 if (responselen != sizeof (RIL_CDMA_SignalInfoRecord)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002954 RLOGE("invalid response length %d expected sizeof (RIL_CDMA_SignalInfoRecord) of %d\n",
Wink Saville3d54e742009-05-18 18:00:44 -07002955 (int)responselen, (int)sizeof (RIL_CDMA_SignalInfoRecord));
2956 return RIL_ERRNO_INVALID_RESPONSE;
2957 }
2958
2959 startResponse;
2960
2961 RIL_CDMA_SignalInfoRecord *p_cur = ((RIL_CDMA_SignalInfoRecord *) response);
2962 marshallSignalInfoRecord(p, *p_cur);
2963
2964 appendPrintBuf("%s[isPresent=%d,signalType=%d,alertPitch=%d\
2965 signal=%d]",
2966 printBuf,
2967 p_cur->isPresent,
2968 p_cur->signalType,
2969 p_cur->alertPitch,
2970 p_cur->signal);
2971
2972 closeResponse;
2973 return 0;
2974}
2975
Wink Savillea592eeb2009-05-22 13:26:36 -07002976static int responseCdmaCallWaiting(Parcel &p, void *response,
2977 size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07002978 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002979 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002980 return RIL_ERRNO_INVALID_RESPONSE;
2981 }
2982
Wink Savillec0114b32011-02-18 10:14:07 -08002983 if (responselen < sizeof(RIL_CDMA_CallWaiting_v6)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002984 RLOGW("Upgrade to ril version %d\n", RIL_VERSION);
Wink Savillec0114b32011-02-18 10:14:07 -08002985 }
2986
2987 RIL_CDMA_CallWaiting_v6 *p_cur = ((RIL_CDMA_CallWaiting_v6 *) response);
2988
2989 writeStringToParcel(p, p_cur->number);
2990 p.writeInt32(p_cur->numberPresentation);
2991 writeStringToParcel(p, p_cur->name);
2992 marshallSignalInfoRecord(p, p_cur->signalInfoRecord);
2993
2994 if (responselen >= sizeof(RIL_CDMA_CallWaiting_v6)) {
2995 p.writeInt32(p_cur->number_type);
2996 p.writeInt32(p_cur->number_plan);
2997 } else {
2998 p.writeInt32(0);
2999 p.writeInt32(0);
Wink Saville3d54e742009-05-18 18:00:44 -07003000 }
3001
3002 startResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07003003 appendPrintBuf("%snumber=%s,numberPresentation=%d, name=%s,\
3004 signalInfoRecord[isPresent=%d,signalType=%d,alertPitch=%d\
Wink Savillec0114b32011-02-18 10:14:07 -08003005 signal=%d,number_type=%d,number_plan=%d]",
Wink Saville3d54e742009-05-18 18:00:44 -07003006 printBuf,
3007 p_cur->number,
3008 p_cur->numberPresentation,
3009 p_cur->name,
3010 p_cur->signalInfoRecord.isPresent,
3011 p_cur->signalInfoRecord.signalType,
3012 p_cur->signalInfoRecord.alertPitch,
Wink Savillec0114b32011-02-18 10:14:07 -08003013 p_cur->signalInfoRecord.signal,
3014 p_cur->number_type,
3015 p_cur->number_plan);
Wink Saville3d54e742009-05-18 18:00:44 -07003016 closeResponse;
3017
3018 return 0;
3019}
3020
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003021static int responseSimRefresh(Parcel &p, void *response, size_t responselen) {
3022 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003023 RLOGE("responseSimRefresh: invalid response: NULL");
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003024 return RIL_ERRNO_INVALID_RESPONSE;
3025 }
3026
3027 startResponse;
3028 if (s_callbacks.version == 7) {
3029 RIL_SimRefreshResponse_v7 *p_cur = ((RIL_SimRefreshResponse_v7 *) response);
3030 p.writeInt32(p_cur->result);
3031 p.writeInt32(p_cur->ef_id);
3032 writeStringToParcel(p, p_cur->aid);
3033
3034 appendPrintBuf("%sresult=%d, ef_id=%d, aid=%s",
3035 printBuf,
3036 p_cur->result,
3037 p_cur->ef_id,
3038 p_cur->aid);
3039 } else {
3040 int *p_cur = ((int *) response);
3041 p.writeInt32(p_cur[0]);
3042 p.writeInt32(p_cur[1]);
3043 writeStringToParcel(p, NULL);
3044
3045 appendPrintBuf("%sresult=%d, ef_id=%d",
3046 printBuf,
3047 p_cur[0],
3048 p_cur[1]);
3049 }
3050 closeResponse;
3051
3052 return 0;
3053}
3054
Wink Saville8a9e0212013-04-09 12:11:38 -07003055static int responseCellInfoList(Parcel &p, void *response, size_t responselen)
3056{
3057 if (response == NULL && responselen != 0) {
3058 RLOGE("invalid response: NULL");
3059 return RIL_ERRNO_INVALID_RESPONSE;
3060 }
3061
3062 if (responselen % sizeof(RIL_CellInfo) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07003063 RLOGE("responseCellInfoList: invalid response length %d expected multiple of %d",
Wink Saville8a9e0212013-04-09 12:11:38 -07003064 (int)responselen, (int)sizeof(RIL_CellInfo));
3065 return RIL_ERRNO_INVALID_RESPONSE;
3066 }
3067
3068 int num = responselen / sizeof(RIL_CellInfo);
3069 p.writeInt32(num);
3070
3071 RIL_CellInfo *p_cur = (RIL_CellInfo *) response;
3072 startResponse;
3073 int i;
3074 for (i = 0; i < num; i++) {
3075 appendPrintBuf("%s[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", printBuf, i,
3076 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
3077 p.writeInt32((int)p_cur->cellInfoType);
3078 p.writeInt32(p_cur->registered);
3079 p.writeInt32(p_cur->timeStampType);
3080 p.writeInt64(p_cur->timeStamp);
3081 switch(p_cur->cellInfoType) {
3082 case RIL_CELL_INFO_TYPE_GSM: {
Wink Savillec57b3eb2013-04-17 12:51:41 -07003083 appendPrintBuf("%s GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,", printBuf,
Wink Saville8a9e0212013-04-09 12:11:38 -07003084 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
3085 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
3086 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
Wink Savillec57b3eb2013-04-17 12:51:41 -07003087 p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3088 appendPrintBuf("%s gsmSS: ss=%d,ber=%d],", printBuf,
Wink Saville8a9e0212013-04-09 12:11:38 -07003089 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
3090 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3091
3092 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
3093 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
3094 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
3095 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
Wink Saville8a9e0212013-04-09 12:11:38 -07003096 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
3097 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3098 break;
3099 }
Wink Savillec57b3eb2013-04-17 12:51:41 -07003100 case RIL_CELL_INFO_TYPE_WCDMA: {
3101 appendPrintBuf("%s WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,", printBuf,
3102 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
3103 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
3104 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
3105 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
3106 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3107 appendPrintBuf("%s wcdmaSS: ss=%d,ber=%d],", printBuf,
3108 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
3109 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3110
3111 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
3112 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
3113 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
3114 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
3115 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3116 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
3117 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3118 break;
3119 }
Wink Saville8a9e0212013-04-09 12:11:38 -07003120 case RIL_CELL_INFO_TYPE_CDMA: {
3121 appendPrintBuf("%s CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d", printBuf,
3122 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
3123 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
3124 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
3125 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
3126 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3127
3128 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
3129 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
3130 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
3131 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
3132 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3133
3134 appendPrintBuf("%s cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d", printBuf,
3135 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
3136 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
3137 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
3138 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
3139 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3140
3141 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
3142 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
3143 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
3144 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
3145 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3146 break;
3147 }
3148 case RIL_CELL_INFO_TYPE_LTE: {
3149 appendPrintBuf("%s LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d", printBuf,
3150 p_cur->CellInfo.lte.cellIdentityLte.mcc,
3151 p_cur->CellInfo.lte.cellIdentityLte.mnc,
3152 p_cur->CellInfo.lte.cellIdentityLte.ci,
3153 p_cur->CellInfo.lte.cellIdentityLte.pci,
3154 p_cur->CellInfo.lte.cellIdentityLte.tac);
3155
3156 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
3157 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
3158 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
3159 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
3160 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
3161
3162 appendPrintBuf("%s lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d", printBuf,
3163 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
3164 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
3165 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
3166 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
3167 p_cur->CellInfo.lte.signalStrengthLte.cqi,
3168 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3169 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
3170 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
3171 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
3172 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
3173 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
3174 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3175 break;
3176 }
Etan Cohend3652192014-06-20 08:28:44 -07003177 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
3178 appendPrintBuf("%s TDSCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,cpid=%d,", printBuf,
3179 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc,
3180 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc,
3181 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac,
3182 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid,
3183 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3184 appendPrintBuf("%s tdscdmaSS: rscp=%d],", printBuf,
3185 p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3186
3187 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
3188 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
3189 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
3190 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
3191 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3192 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3193 break;
3194 }
Wink Saville8a9e0212013-04-09 12:11:38 -07003195 }
3196 p_cur += 1;
3197 }
3198 removeLastChar;
3199 closeResponse;
3200
3201 return 0;
3202}
3203
Etan Cohend3652192014-06-20 08:28:44 -07003204static int responseHardwareConfig(Parcel &p, void *response, size_t responselen)
3205{
3206 if (response == NULL && responselen != 0) {
3207 RLOGE("invalid response: NULL");
3208 return RIL_ERRNO_INVALID_RESPONSE;
3209 }
3210
3211 if (responselen % sizeof(RIL_HardwareConfig) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07003212 RLOGE("responseHardwareConfig: invalid response length %d expected multiple of %d",
Etan Cohend3652192014-06-20 08:28:44 -07003213 (int)responselen, (int)sizeof(RIL_HardwareConfig));
3214 return RIL_ERRNO_INVALID_RESPONSE;
3215 }
3216
3217 int num = responselen / sizeof(RIL_HardwareConfig);
3218 int i;
3219 RIL_HardwareConfig *p_cur = (RIL_HardwareConfig *) response;
3220
3221 p.writeInt32(num);
3222
3223 startResponse;
3224 for (i = 0; i < num; i++) {
3225 switch (p_cur[i].type) {
3226 case RIL_HARDWARE_CONFIG_MODEM: {
3227 writeStringToParcel(p, p_cur[i].uuid);
3228 p.writeInt32((int)p_cur[i].state);
3229 p.writeInt32(p_cur[i].cfg.modem.rat);
3230 p.writeInt32(p_cur[i].cfg.modem.maxVoice);
3231 p.writeInt32(p_cur[i].cfg.modem.maxData);
3232 p.writeInt32(p_cur[i].cfg.modem.maxStandby);
3233
3234 appendPrintBuf("%s modem: uuid=%s,state=%d,rat=%08x,maxV=%d,maxD=%d,maxS=%d", printBuf,
3235 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.modem.rat,
3236 p_cur[i].cfg.modem.maxVoice, p_cur[i].cfg.modem.maxData, p_cur[i].cfg.modem.maxStandby);
3237 break;
3238 }
3239 case RIL_HARDWARE_CONFIG_SIM: {
3240 writeStringToParcel(p, p_cur[i].uuid);
3241 p.writeInt32((int)p_cur[i].state);
3242 writeStringToParcel(p, p_cur[i].cfg.sim.modemUuid);
3243
3244 appendPrintBuf("%s sim: uuid=%s,state=%d,modem-uuid=%s", printBuf,
3245 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.sim.modemUuid);
3246 break;
3247 }
3248 }
3249 }
3250 removeLastChar;
3251 closeResponse;
3252 return 0;
3253}
3254
Wink Saville8b4e4f72014-10-17 15:01:45 -07003255static int responseRadioCapability(Parcel &p, void *response, size_t responselen) {
3256 if (response == NULL) {
3257 RLOGE("invalid response: NULL");
3258 return RIL_ERRNO_INVALID_RESPONSE;
3259 }
3260
3261 if (responselen != sizeof (RIL_RadioCapability) ) {
3262 RLOGE("invalid response length was %d expected %d",
3263 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3264 return RIL_ERRNO_INVALID_RESPONSE;
3265 }
3266
3267 RIL_RadioCapability *p_cur = (RIL_RadioCapability *) response;
3268 p.writeInt32(p_cur->version);
3269 p.writeInt32(p_cur->session);
3270 p.writeInt32(p_cur->phase);
3271 p.writeInt32(p_cur->rat);
3272 writeStringToParcel(p, p_cur->logicalModemUuid);
3273 p.writeInt32(p_cur->status);
3274
3275 startResponse;
3276 appendPrintBuf("%s[version=%d,session=%d,phase=%d,\
Legler Wu8caf06f2014-10-29 14:02:14 +08003277 rat=%s,logicalModemUuid=%s,status=%d]",
Wink Saville8b4e4f72014-10-17 15:01:45 -07003278 printBuf,
3279 p_cur->version,
3280 p_cur->session,
3281 p_cur->phase,
3282 p_cur->rat,
Legler Wu8caf06f2014-10-29 14:02:14 +08003283 p_cur->logicalModemUuid,
Wink Saville8b4e4f72014-10-17 15:01:45 -07003284 p_cur->status);
3285 closeResponse;
3286 return 0;
3287}
3288
Amit Mahajan54563d32014-11-22 00:54:49 +00003289static int responseSSData(Parcel &p, void *response, size_t responselen) {
3290 RLOGD("In responseSSData");
3291 int num;
3292
3293 if (response == NULL && responselen != 0) {
3294 RLOGE("invalid response length was %d expected %d",
3295 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3296 return RIL_ERRNO_INVALID_RESPONSE;
3297 }
3298
3299 if (responselen != sizeof(RIL_StkCcUnsolSsResponse)) {
3300 RLOGE("invalid response length %d, expected %d",
3301 (int)responselen, (int)sizeof(RIL_StkCcUnsolSsResponse));
3302 return RIL_ERRNO_INVALID_RESPONSE;
3303 }
3304
3305 startResponse;
3306 RIL_StkCcUnsolSsResponse *p_cur = (RIL_StkCcUnsolSsResponse *) response;
3307 p.writeInt32(p_cur->serviceType);
3308 p.writeInt32(p_cur->requestType);
3309 p.writeInt32(p_cur->teleserviceType);
3310 p.writeInt32(p_cur->serviceClass);
3311 p.writeInt32(p_cur->result);
3312
3313 if (isServiceTypeCfQuery(p_cur->serviceType, p_cur->requestType)) {
3314 RLOGD("responseSSData CF type, num of Cf elements %d", p_cur->cfData.numValidIndexes);
3315 if (p_cur->cfData.numValidIndexes > NUM_SERVICE_CLASSES) {
3316 RLOGE("numValidIndexes is greater than max value %d, "
3317 "truncating it to max value", NUM_SERVICE_CLASSES);
3318 p_cur->cfData.numValidIndexes = NUM_SERVICE_CLASSES;
3319 }
3320 /* number of call info's */
3321 p.writeInt32(p_cur->cfData.numValidIndexes);
3322
3323 for (int i = 0; i < p_cur->cfData.numValidIndexes; i++) {
3324 RIL_CallForwardInfo cf = p_cur->cfData.cfInfo[i];
3325
3326 p.writeInt32(cf.status);
3327 p.writeInt32(cf.reason);
3328 p.writeInt32(cf.serviceClass);
3329 p.writeInt32(cf.toa);
3330 writeStringToParcel(p, cf.number);
3331 p.writeInt32(cf.timeSeconds);
3332 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
3333 (cf.status==1)?"enable":"disable", cf.reason, cf.serviceClass, cf.toa,
3334 (char*)cf.number, cf.timeSeconds);
3335 RLOGD("Data: %d,reason=%d,cls=%d,toa=%d,num=%s,tout=%d],", cf.status,
3336 cf.reason, cf.serviceClass, cf.toa, (char*)cf.number, cf.timeSeconds);
3337 }
3338 } else {
3339 p.writeInt32 (SS_INFO_MAX);
3340
3341 /* each int*/
3342 for (int i = 0; i < SS_INFO_MAX; i++) {
3343 appendPrintBuf("%s%d,", printBuf, p_cur->ssInfo[i]);
3344 RLOGD("Data: %d",p_cur->ssInfo[i]);
3345 p.writeInt32(p_cur->ssInfo[i]);
3346 }
3347 }
3348 removeLastChar;
3349 closeResponse;
3350
3351 return 0;
3352}
3353
3354static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType) {
3355 if ((reqType == SS_INTERROGATION) &&
3356 (serType == SS_CFU ||
3357 serType == SS_CF_BUSY ||
3358 serType == SS_CF_NO_REPLY ||
3359 serType == SS_CF_NOT_REACHABLE ||
3360 serType == SS_CF_ALL ||
3361 serType == SS_CF_ALL_CONDITIONAL)) {
3362 return true;
3363 }
3364 return false;
3365}
3366
Wink Saville3d54e742009-05-18 18:00:44 -07003367static void triggerEvLoop() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003368 int ret;
3369 if (!pthread_equal(pthread_self(), s_tid_dispatch)) {
3370 /* trigger event loop to wakeup. No reason to do this,
3371 * if we're in the event loop thread */
3372 do {
3373 ret = write (s_fdWakeupWrite, " ", 1);
3374 } while (ret < 0 && errno == EINTR);
3375 }
3376}
3377
Wink Saville3d54e742009-05-18 18:00:44 -07003378static void rilEventAddWakeup(struct ril_event *ev) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003379 ril_event_add(ev);
3380 triggerEvLoop();
3381}
3382
Wink Savillefd729372011-02-22 16:19:39 -08003383static void sendSimStatusAppInfo(Parcel &p, int num_apps, RIL_AppStatus appStatus[]) {
3384 p.writeInt32(num_apps);
3385 startResponse;
3386 for (int i = 0; i < num_apps; i++) {
3387 p.writeInt32(appStatus[i].app_type);
3388 p.writeInt32(appStatus[i].app_state);
3389 p.writeInt32(appStatus[i].perso_substate);
3390 writeStringToParcel(p, (const char*)(appStatus[i].aid_ptr));
3391 writeStringToParcel(p, (const char*)
3392 (appStatus[i].app_label_ptr));
3393 p.writeInt32(appStatus[i].pin1_replaced);
3394 p.writeInt32(appStatus[i].pin1);
3395 p.writeInt32(appStatus[i].pin2);
3396 appendPrintBuf("%s[app_type=%d,app_state=%d,perso_substate=%d,\
3397 aid_ptr=%s,app_label_ptr=%s,pin1_replaced=%d,pin1=%d,pin2=%d],",
3398 printBuf,
3399 appStatus[i].app_type,
3400 appStatus[i].app_state,
3401 appStatus[i].perso_substate,
3402 appStatus[i].aid_ptr,
3403 appStatus[i].app_label_ptr,
3404 appStatus[i].pin1_replaced,
3405 appStatus[i].pin1,
3406 appStatus[i].pin2);
3407 }
3408 closeResponse;
3409}
3410
Wink Savillef4c4d362009-04-02 01:37:03 -07003411static int responseSimStatus(Parcel &p, void *response, size_t responselen) {
3412 int i;
3413
3414 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003415 RLOGE("invalid response: NULL");
Wink Savillef4c4d362009-04-02 01:37:03 -07003416 return RIL_ERRNO_INVALID_RESPONSE;
3417 }
3418
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003419 if (responselen == sizeof (RIL_CardStatus_v6)) {
Wink Savillefd729372011-02-22 16:19:39 -08003420 RIL_CardStatus_v6 *p_cur = ((RIL_CardStatus_v6 *) response);
Wink Savillef4c4d362009-04-02 01:37:03 -07003421
Wink Savillefd729372011-02-22 16:19:39 -08003422 p.writeInt32(p_cur->card_state);
3423 p.writeInt32(p_cur->universal_pin_state);
3424 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3425 p.writeInt32(p_cur->cdma_subscription_app_index);
3426 p.writeInt32(p_cur->ims_subscription_app_index);
3427
3428 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003429 } else if (responselen == sizeof (RIL_CardStatus_v5)) {
Wink Savillefd729372011-02-22 16:19:39 -08003430 RIL_CardStatus_v5 *p_cur = ((RIL_CardStatus_v5 *) response);
3431
3432 p.writeInt32(p_cur->card_state);
3433 p.writeInt32(p_cur->universal_pin_state);
3434 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3435 p.writeInt32(p_cur->cdma_subscription_app_index);
3436 p.writeInt32(-1);
3437
3438 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003439 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003440 RLOGE("responseSimStatus: A RilCardStatus_v6 or _v5 expected\n");
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003441 return RIL_ERRNO_INVALID_RESPONSE;
Wink Savillef4c4d362009-04-02 01:37:03 -07003442 }
Wink Savillef4c4d362009-04-02 01:37:03 -07003443
3444 return 0;
Wink Saville3d54e742009-05-18 18:00:44 -07003445}
Wink Savillef4c4d362009-04-02 01:37:03 -07003446
Wink Savillea592eeb2009-05-22 13:26:36 -07003447static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3448 int num = responselen / sizeof(RIL_GSM_BroadcastSmsConfigInfo *);
Wink Savillef4c4d362009-04-02 01:37:03 -07003449 p.writeInt32(num);
3450
Wink Savillef4c4d362009-04-02 01:37:03 -07003451 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07003452 RIL_GSM_BroadcastSmsConfigInfo **p_cur =
3453 (RIL_GSM_BroadcastSmsConfigInfo **) response;
3454 for (int i = 0; i < num; i++) {
3455 p.writeInt32(p_cur[i]->fromServiceId);
3456 p.writeInt32(p_cur[i]->toServiceId);
3457 p.writeInt32(p_cur[i]->fromCodeScheme);
3458 p.writeInt32(p_cur[i]->toCodeScheme);
3459 p.writeInt32(p_cur[i]->selected);
3460
3461 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId=%d, \
3462 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]",
3463 printBuf, i, p_cur[i]->fromServiceId, p_cur[i]->toServiceId,
3464 p_cur[i]->fromCodeScheme, p_cur[i]->toCodeScheme,
3465 p_cur[i]->selected);
3466 }
Wink Savillef4c4d362009-04-02 01:37:03 -07003467 closeResponse;
3468
3469 return 0;
3470}
3471
Wink Savillea592eeb2009-05-22 13:26:36 -07003472static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3473 RIL_CDMA_BroadcastSmsConfigInfo **p_cur =
3474 (RIL_CDMA_BroadcastSmsConfigInfo **) response;
Wink Savillef4c4d362009-04-02 01:37:03 -07003475
Wink Savillea592eeb2009-05-22 13:26:36 -07003476 int num = responselen / sizeof (RIL_CDMA_BroadcastSmsConfigInfo *);
3477 p.writeInt32(num);
Wink Savillef4c4d362009-04-02 01:37:03 -07003478
3479 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07003480 for (int i = 0 ; i < num ; i++ ) {
3481 p.writeInt32(p_cur[i]->service_category);
3482 p.writeInt32(p_cur[i]->language);
3483 p.writeInt32(p_cur[i]->selected);
Wink Savillef4c4d362009-04-02 01:37:03 -07003484
Wink Savillea592eeb2009-05-22 13:26:36 -07003485 appendPrintBuf("%s [%d: srvice_category=%d, language =%d, \
3486 selected =%d], ",
3487 printBuf, i, p_cur[i]->service_category, p_cur[i]->language,
3488 p_cur[i]->selected);
Wink Savillef5903df2009-04-24 11:54:14 -07003489 }
Wink Savillea592eeb2009-05-22 13:26:36 -07003490 closeResponse;
Wink Savillef5903df2009-04-24 11:54:14 -07003491
Wink Savillef4c4d362009-04-02 01:37:03 -07003492 return 0;
3493}
3494
3495static int responseCdmaSms(Parcel &p, void *response, size_t responselen) {
3496 int num;
3497 int digitCount;
3498 int digitLimit;
3499 uint8_t uct;
3500 void* dest;
3501
Wink Saville8eb2a122012-11-19 16:05:13 -08003502 RLOGD("Inside responseCdmaSms");
Wink Savillef5903df2009-04-24 11:54:14 -07003503
Wink Savillef4c4d362009-04-02 01:37:03 -07003504 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003505 RLOGE("invalid response: NULL");
Wink Savillef4c4d362009-04-02 01:37:03 -07003506 return RIL_ERRNO_INVALID_RESPONSE;
3507 }
3508
Wink Savillef5903df2009-04-24 11:54:14 -07003509 if (responselen != sizeof(RIL_CDMA_SMS_Message)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003510 RLOGE("invalid response length was %d expected %d",
Wink Savillef5903df2009-04-24 11:54:14 -07003511 (int)responselen, (int)sizeof(RIL_CDMA_SMS_Message));
Wink Savillef4c4d362009-04-02 01:37:03 -07003512 return RIL_ERRNO_INVALID_RESPONSE;
3513 }
3514
3515 RIL_CDMA_SMS_Message *p_cur = (RIL_CDMA_SMS_Message *) response;
3516 p.writeInt32(p_cur->uTeleserviceID);
3517 p.write(&(p_cur->bIsServicePresent),sizeof(uct));
3518 p.writeInt32(p_cur->uServicecategory);
3519 p.writeInt32(p_cur->sAddress.digit_mode);
3520 p.writeInt32(p_cur->sAddress.number_mode);
3521 p.writeInt32(p_cur->sAddress.number_type);
3522 p.writeInt32(p_cur->sAddress.number_plan);
3523 p.write(&(p_cur->sAddress.number_of_digits), sizeof(uct));
3524 digitLimit= MIN((p_cur->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
3525 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3526 p.write(&(p_cur->sAddress.digits[digitCount]),sizeof(uct));
3527 }
3528
3529 p.writeInt32(p_cur->sSubAddress.subaddressType);
3530 p.write(&(p_cur->sSubAddress.odd),sizeof(uct));
3531 p.write(&(p_cur->sSubAddress.number_of_digits),sizeof(uct));
3532 digitLimit= MIN((p_cur->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
3533 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3534 p.write(&(p_cur->sSubAddress.digits[digitCount]),sizeof(uct));
3535 }
3536
3537 digitLimit= MIN((p_cur->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
3538 p.writeInt32(p_cur->uBearerDataLen);
3539 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3540 p.write(&(p_cur->aBearerData[digitCount]), sizeof(uct));
3541 }
3542
3543 startResponse;
3544 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
Wink Saville1b5fd232009-04-22 14:50:00 -07003545 sAddress.digit_mode=%d, sAddress.number_mode=%d, sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07003546 printBuf, p_cur->uTeleserviceID,p_cur->bIsServicePresent,p_cur->uServicecategory,
3547 p_cur->sAddress.digit_mode, p_cur->sAddress.number_mode,p_cur->sAddress.number_type);
3548 closeResponse;
3549
3550 return 0;
3551}
3552
Wink Savillec29360a2014-07-13 05:17:28 -07003553static int responseDcRtInfo(Parcel &p, void *response, size_t responselen)
3554{
3555 int num = responselen / sizeof(RIL_DcRtInfo);
3556 if ((responselen % sizeof(RIL_DcRtInfo) != 0) || (num != 1)) {
Amit Mahajan52500162014-07-29 17:36:48 -07003557 RLOGE("responseDcRtInfo: invalid response length %d expected multiple of %d",
Wink Savillec29360a2014-07-13 05:17:28 -07003558 (int)responselen, (int)sizeof(RIL_DcRtInfo));
3559 return RIL_ERRNO_INVALID_RESPONSE;
3560 }
3561
3562 startResponse;
3563 RIL_DcRtInfo *pDcRtInfo = (RIL_DcRtInfo *)response;
3564 p.writeInt64(pDcRtInfo->time);
3565 p.writeInt32(pDcRtInfo->powerState);
3566 appendPrintBuf("%s[time=%d,powerState=%d]", printBuf,
3567 pDcRtInfo->time,
3568 pDcRtInfo->powerState);
3569 closeResponse;
3570
3571 return 0;
3572}
3573
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003574/**
3575 * A write on the wakeup fd is done just to pop us out of select()
3576 * We empty the buffer here and then ril_event will reset the timers on the
3577 * way back down
3578 */
Wink Savillef4c4d362009-04-02 01:37:03 -07003579static void processWakeupCallback(int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003580 char buff[16];
3581 int ret;
3582
Wink Saville8eb2a122012-11-19 16:05:13 -08003583 RLOGV("processWakeupCallback");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003584
3585 /* empty our wakeup socket out */
3586 do {
3587 ret = read(s_fdWakeupRead, &buff, sizeof(buff));
Wink Saville7f856802009-06-09 10:23:37 -07003588 } while (ret > 0 || (ret < 0 && errno == EINTR));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003589}
3590
Etan Cohend3652192014-06-20 08:28:44 -07003591static void onCommandsSocketClosed(RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003592 int ret;
3593 RequestInfo *p_cur;
Etan Cohend3652192014-06-20 08:28:44 -07003594 /* Hook for current context
3595 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
3596 pthread_mutex_t * pendingRequestsMutexHook = &s_pendingRequestsMutex;
3597 /* pendingRequestsHook refer to &s_pendingRequests */
3598 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003599
Etan Cohend3652192014-06-20 08:28:44 -07003600#if (SIM_COUNT >= 2)
3601 if (socket_id == RIL_SOCKET_2) {
3602 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
3603 pendingRequestsHook = &s_pendingRequests_socket2;
3604 }
3605#if (SIM_COUNT >= 3)
3606 else if (socket_id == RIL_SOCKET_3) {
3607 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
3608 pendingRequestsHook = &s_pendingRequests_socket3;
3609 }
3610#endif
3611#if (SIM_COUNT >= 4)
3612 else if (socket_id == RIL_SOCKET_4) {
3613 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
3614 pendingRequestsHook = &s_pendingRequests_socket4;
3615 }
3616#endif
3617#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003618 /* mark pending requests as "cancelled" so we dont report responses */
Etan Cohend3652192014-06-20 08:28:44 -07003619 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003620 assert (ret == 0);
3621
Etan Cohend3652192014-06-20 08:28:44 -07003622 p_cur = *pendingRequestsHook;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003623
Etan Cohend3652192014-06-20 08:28:44 -07003624 for (p_cur = *pendingRequestsHook
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003625 ; p_cur != NULL
3626 ; p_cur = p_cur->p_next
3627 ) {
3628 p_cur->cancelled = 1;
3629 }
3630
Etan Cohend3652192014-06-20 08:28:44 -07003631 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003632 assert (ret == 0);
3633}
3634
Wink Savillef4c4d362009-04-02 01:37:03 -07003635static void processCommandsCallback(int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003636 RecordStream *p_rs;
3637 void *p_record;
3638 size_t recordlen;
3639 int ret;
Etan Cohend3652192014-06-20 08:28:44 -07003640 SocketListenParam *p_info = (SocketListenParam *)param;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003641
Etan Cohend3652192014-06-20 08:28:44 -07003642 assert(fd == p_info->fdCommand);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003643
Etan Cohend3652192014-06-20 08:28:44 -07003644 p_rs = p_info->p_rs;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003645
3646 for (;;) {
3647 /* loop until EAGAIN/EINTR, end of stream, or other error */
3648 ret = record_stream_get_next(p_rs, &p_record, &recordlen);
3649
3650 if (ret == 0 && p_record == NULL) {
3651 /* end-of-stream */
3652 break;
3653 } else if (ret < 0) {
3654 break;
3655 } else if (ret == 0) { /* && p_record != NULL */
Etan Cohend3652192014-06-20 08:28:44 -07003656 processCommandBuffer(p_record, recordlen, p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003657 }
3658 }
3659
3660 if (ret == 0 || !(errno == EAGAIN || errno == EINTR)) {
3661 /* fatal error or end-of-stream */
3662 if (ret != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003663 RLOGE("error on reading command socket errno:%d\n", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003664 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003665 RLOGW("EOS. Closing command socket.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003666 }
Wink Saville7f856802009-06-09 10:23:37 -07003667
Etan Cohend3652192014-06-20 08:28:44 -07003668 close(fd);
3669 p_info->fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003670
Etan Cohend3652192014-06-20 08:28:44 -07003671 ril_event_del(p_info->commands_event);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003672
3673 record_stream_free(p_rs);
3674
3675 /* start listening for new connections again */
3676 rilEventAddWakeup(&s_listen_event);
3677
Etan Cohend3652192014-06-20 08:28:44 -07003678 onCommandsSocketClosed(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003679 }
3680}
3681
3682
Etan Cohend3652192014-06-20 08:28:44 -07003683static void onNewCommandConnect(RIL_SOCKET_ID socket_id) {
Wink Saville5b9df332011-04-06 16:24:21 -07003684 // Inform we are connected and the ril version
Jake Hambya9c18d12011-04-12 23:32:08 -07003685 int rilVer = s_callbacks.version;
Etan Cohend3652192014-06-20 08:28:44 -07003686 RIL_UNSOL_RESPONSE(RIL_UNSOL_RIL_CONNECTED,
3687 &rilVer, sizeof(rilVer), socket_id);
Wink Saville5b9df332011-04-06 16:24:21 -07003688
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003689 // implicit radio state changed
Etan Cohend3652192014-06-20 08:28:44 -07003690 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
3691 NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003692
3693 // Send last NITZ time data, in case it was missed
3694 if (s_lastNITZTimeData != NULL) {
Etan Cohend3652192014-06-20 08:28:44 -07003695 sendResponseRaw(s_lastNITZTimeData, s_lastNITZTimeDataSize, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003696
3697 free(s_lastNITZTimeData);
3698 s_lastNITZTimeData = NULL;
3699 }
3700
3701 // Get version string
3702 if (s_callbacks.getVersion != NULL) {
3703 const char *version;
3704 version = s_callbacks.getVersion();
Wink Saville8eb2a122012-11-19 16:05:13 -08003705 RLOGI("RIL Daemon version: %s\n", version);
Wink Saville7f856802009-06-09 10:23:37 -07003706
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003707 property_set(PROPERTY_RIL_IMPL, version);
3708 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003709 RLOGI("RIL Daemon version: unavailable\n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003710 property_set(PROPERTY_RIL_IMPL, "unavailable");
3711 }
3712
3713}
3714
Wink Savillef4c4d362009-04-02 01:37:03 -07003715static void listenCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003716 int ret;
3717 int err;
3718 int is_phone_socket;
Etan Cohend3652192014-06-20 08:28:44 -07003719 int fdCommand = -1;
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003720 char* processName;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003721 RecordStream *p_rs;
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003722 MySocketListenParam* listenParam;
3723 RilSocket *sapSocket = NULL;
3724 socketClient *sClient = NULL;
3725
Etan Cohend3652192014-06-20 08:28:44 -07003726 SocketListenParam *p_info = (SocketListenParam *)param;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003727
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003728 if(RIL_SAP_SOCKET == p_info->type) {
3729 listenParam = (MySocketListenParam *)param;
3730 sapSocket = listenParam->socket;
3731 }
3732
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003733 struct sockaddr_un peeraddr;
3734 socklen_t socklen = sizeof (peeraddr);
3735
3736 struct ucred creds;
3737 socklen_t szCreds = sizeof(creds);
3738
3739 struct passwd *pwd = NULL;
3740
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003741 if(NULL == sapSocket) {
3742 assert (*p_info->fdCommand < 0);
3743 assert (fd == *p_info->fdListen);
3744 processName = PHONE_PROCESS;
3745 } else {
3746 assert (sapSocket->commandFd < 0);
3747 assert (fd == sapSocket->listenFd);
3748 processName = BLUETOOTH_PROCESS;
3749 }
3750
Wink Saville7f856802009-06-09 10:23:37 -07003751
Etan Cohend3652192014-06-20 08:28:44 -07003752 fdCommand = accept(fd, (sockaddr *) &peeraddr, &socklen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003753
Etan Cohend3652192014-06-20 08:28:44 -07003754 if (fdCommand < 0 ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003755 RLOGE("Error on accept() errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003756 /* start listening for new connections again */
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003757 if(NULL == sapSocket) {
3758 rilEventAddWakeup(p_info->listen_event);
3759 } else {
3760 rilEventAddWakeup(sapSocket->getListenEvent());
3761 }
Etan Cohend3652192014-06-20 08:28:44 -07003762 return;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003763 }
3764
3765 /* check the credential of the other side and only accept socket from
3766 * phone process
Wink Saville7f856802009-06-09 10:23:37 -07003767 */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003768 errno = 0;
3769 is_phone_socket = 0;
Wink Savillef4c4d362009-04-02 01:37:03 -07003770
Etan Cohend3652192014-06-20 08:28:44 -07003771 err = getsockopt(fdCommand, SOL_SOCKET, SO_PEERCRED, &creds, &szCreds);
Wink Savillef4c4d362009-04-02 01:37:03 -07003772
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003773 if (err == 0 && szCreds > 0) {
Wink Savillef4c4d362009-04-02 01:37:03 -07003774 errno = 0;
3775 pwd = getpwuid(creds.uid);
3776 if (pwd != NULL) {
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003777 if (strcmp(pwd->pw_name, processName) == 0) {
Wink Savillef4c4d362009-04-02 01:37:03 -07003778 is_phone_socket = 1;
3779 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003780 RLOGE("RILD can't accept socket from process %s", pwd->pw_name);
Wink Savillef4c4d362009-04-02 01:37:03 -07003781 }
3782 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003783 RLOGE("Error on getpwuid() errno: %d", errno);
Wink Savillef4c4d362009-04-02 01:37:03 -07003784 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003785 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003786 RLOGD("Error on getsockopt() errno: %d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003787 }
3788
Etan Cohend3652192014-06-20 08:28:44 -07003789 if (!is_phone_socket) {
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003790 RLOGE("RILD must accept socket from %s", processName);
Wink Saville7f856802009-06-09 10:23:37 -07003791
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003792 close(fdCommand);
3793 fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003794
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003795 if(NULL == sapSocket) {
3796 onCommandsSocketClosed(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003797
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003798 /* start listening for new connections again */
3799 rilEventAddWakeup(p_info->listen_event);
3800 } else {
3801 sapSocket->onCommandsSocketClosed();
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003802
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003803 /* start listening for new connections again */
3804 rilEventAddWakeup(sapSocket->getListenEvent());
3805 }
3806
3807 return;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003808 }
3809
Etan Cohend3652192014-06-20 08:28:44 -07003810 ret = fcntl(fdCommand, F_SETFL, O_NONBLOCK);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003811
3812 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003813 RLOGE ("Error setting O_NONBLOCK errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003814 }
3815
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003816 if(NULL == sapSocket) {
3817 RLOGI("libril: new connection to %s", rilSocketIdToString(p_info->socket_id));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003818
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003819 p_info->fdCommand = fdCommand;
3820 p_rs = record_stream_new(p_info->fdCommand, MAX_COMMAND_BYTES);
3821 p_info->p_rs = p_rs;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003822
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003823 ril_event_set (p_info->commands_event, p_info->fdCommand, 1,
Etan Cohend3652192014-06-20 08:28:44 -07003824 p_info->processCommandsCallback, p_info);
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003825 rilEventAddWakeup (p_info->commands_event);
Etan Cohend3652192014-06-20 08:28:44 -07003826
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003827 onNewCommandConnect(p_info->socket_id);
3828 } else {
3829 RLOGI("libril: new connection");
Etan Cohend3652192014-06-20 08:28:44 -07003830
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003831 sapSocket->setCommandFd(fdCommand);
3832 p_rs = record_stream_new(sapSocket->getCommandFd(), MAX_COMMAND_BYTES);
3833 sClient = new socketClient(sapSocket,p_rs);
3834 ril_event_set (sapSocket->getCallbackEvent(), sapSocket->getCommandFd(), 1,
3835 sapSocket->getCommandCb(), sClient);
3836
3837 rilEventAddWakeup(sapSocket->getCallbackEvent());
3838 sapSocket->onNewCommandConnect();
3839 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003840}
3841
3842static void freeDebugCallbackArgs(int number, char **args) {
3843 for (int i = 0; i < number; i++) {
3844 if (args[i] != NULL) {
3845 free(args[i]);
3846 }
3847 }
3848 free(args);
3849}
3850
Wink Savillef4c4d362009-04-02 01:37:03 -07003851static void debugCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003852 int acceptFD, option;
3853 struct sockaddr_un peeraddr;
3854 socklen_t socklen = sizeof (peeraddr);
3855 int data;
3856 unsigned int qxdm_data[6];
3857 const char *deactData[1] = {"1"};
3858 char *actData[1];
3859 RIL_Dial dialData;
3860 int hangupData[1] = {1};
3861 int number;
3862 char **args;
Etan Cohend3652192014-06-20 08:28:44 -07003863 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
3864 int sim_id = 0;
3865
3866 RLOGI("debugCallback for socket %s", rilSocketIdToString(socket_id));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003867
3868 acceptFD = accept (fd, (sockaddr *) &peeraddr, &socklen);
3869
3870 if (acceptFD < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003871 RLOGE ("error accepting on debug port: %d\n", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003872 return;
3873 }
3874
3875 if (recv(acceptFD, &number, sizeof(int), 0) != sizeof(int)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003876 RLOGE ("error reading on socket: number of Args: \n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003877 return;
3878 }
3879 args = (char **) malloc(sizeof(char*) * number);
3880
3881 for (int i = 0; i < number; i++) {
3882 int len;
3883 if (recv(acceptFD, &len, sizeof(int), 0) != sizeof(int)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003884 RLOGE ("error reading on socket: Len of Args: \n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003885 freeDebugCallbackArgs(i, args);
3886 return;
3887 }
3888 // +1 for null-term
3889 args[i] = (char *) malloc((sizeof(char) * len) + 1);
Wink Saville7f856802009-06-09 10:23:37 -07003890 if (recv(acceptFD, args[i], sizeof(char) * len, 0)
Wink Saville1b5fd232009-04-22 14:50:00 -07003891 != (int)sizeof(char) * len) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003892 RLOGE ("error reading on socket: Args[%d] \n", i);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003893 freeDebugCallbackArgs(i, args);
3894 return;
3895 }
3896 char * buf = args[i];
3897 buf[len] = 0;
Etan Cohend3652192014-06-20 08:28:44 -07003898 if ((i+1) == number) {
3899 /* The last argument should be sim id 0(SIM1)~3(SIM4) */
3900 sim_id = atoi(args[i]);
3901 switch (sim_id) {
3902 case 0:
3903 socket_id = RIL_SOCKET_1;
3904 break;
3905 #if (SIM_COUNT >= 2)
3906 case 1:
3907 socket_id = RIL_SOCKET_2;
3908 break;
3909 #endif
3910 #if (SIM_COUNT >= 3)
3911 case 2:
3912 socket_id = RIL_SOCKET_3;
3913 break;
3914 #endif
3915 #if (SIM_COUNT >= 4)
3916 case 3:
3917 socket_id = RIL_SOCKET_4;
3918 break;
3919 #endif
3920 default:
3921 socket_id = RIL_SOCKET_1;
3922 break;
3923 }
3924 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003925 }
3926
3927 switch (atoi(args[0])) {
3928 case 0:
Wink Saville8eb2a122012-11-19 16:05:13 -08003929 RLOGI ("Connection on debug port: issuing reset.");
Etan Cohend3652192014-06-20 08:28:44 -07003930 issueLocalRequest(RIL_REQUEST_RESET_RADIO, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003931 break;
3932 case 1:
Wink Saville8eb2a122012-11-19 16:05:13 -08003933 RLOGI ("Connection on debug port: issuing radio power off.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003934 data = 0;
Etan Cohend3652192014-06-20 08:28:44 -07003935 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003936 // Close the socket
Etan Cohend3652192014-06-20 08:28:44 -07003937 if (socket_id == RIL_SOCKET_1 && s_ril_param_socket.fdCommand > 0) {
3938 close(s_ril_param_socket.fdCommand);
3939 s_ril_param_socket.fdCommand = -1;
3940 }
3941 #if (SIM_COUNT == 2)
3942 else if (socket_id == RIL_SOCKET_2 && s_ril_param_socket2.fdCommand > 0) {
3943 close(s_ril_param_socket2.fdCommand);
3944 s_ril_param_socket2.fdCommand = -1;
3945 }
3946 #endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003947 break;
3948 case 2:
Wink Saville8eb2a122012-11-19 16:05:13 -08003949 RLOGI ("Debug port: issuing unsolicited voice network change.");
Etan Cohend3652192014-06-20 08:28:44 -07003950 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003951 break;
3952 case 3:
Wink Saville8eb2a122012-11-19 16:05:13 -08003953 RLOGI ("Debug port: QXDM log enable.");
Xia Wangd855ef42010-07-27 17:26:55 -07003954 qxdm_data[0] = 65536; // head.func_tag
3955 qxdm_data[1] = 16; // head.len
3956 qxdm_data[2] = 1; // mode: 1 for 'start logging'
3957 qxdm_data[3] = 32; // log_file_size: 32megabytes
3958 qxdm_data[4] = 0; // log_mask
3959 qxdm_data[5] = 8; // log_max_fileindex
Wink Saville7f856802009-06-09 10:23:37 -07003960 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Etan Cohend3652192014-06-20 08:28:44 -07003961 6 * sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003962 break;
3963 case 4:
Wink Saville8eb2a122012-11-19 16:05:13 -08003964 RLOGI ("Debug port: QXDM log disable.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003965 qxdm_data[0] = 65536;
3966 qxdm_data[1] = 16;
Xia Wangd855ef42010-07-27 17:26:55 -07003967 qxdm_data[2] = 0; // mode: 0 for 'stop logging'
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003968 qxdm_data[3] = 32;
3969 qxdm_data[4] = 0;
Xia Wangd855ef42010-07-27 17:26:55 -07003970 qxdm_data[5] = 8;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003971 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Etan Cohend3652192014-06-20 08:28:44 -07003972 6 * sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003973 break;
3974 case 5:
Wink Saville8eb2a122012-11-19 16:05:13 -08003975 RLOGI("Debug port: Radio On");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003976 data = 1;
Etan Cohend3652192014-06-20 08:28:44 -07003977 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003978 sleep(2);
3979 // Set network selection automatic.
Etan Cohend3652192014-06-20 08:28:44 -07003980 issueLocalRequest(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003981 break;
3982 case 6:
Wink Saville8eb2a122012-11-19 16:05:13 -08003983 RLOGI("Debug port: Setup Data Call, Apn :%s\n", args[1]);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003984 actData[0] = args[1];
Wink Saville7f856802009-06-09 10:23:37 -07003985 issueLocalRequest(RIL_REQUEST_SETUP_DATA_CALL, &actData,
Etan Cohend3652192014-06-20 08:28:44 -07003986 sizeof(actData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003987 break;
3988 case 7:
Wink Saville8eb2a122012-11-19 16:05:13 -08003989 RLOGI("Debug port: Deactivate Data Call");
Wink Saville7f856802009-06-09 10:23:37 -07003990 issueLocalRequest(RIL_REQUEST_DEACTIVATE_DATA_CALL, &deactData,
Etan Cohend3652192014-06-20 08:28:44 -07003991 sizeof(deactData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003992 break;
3993 case 8:
Wink Saville8eb2a122012-11-19 16:05:13 -08003994 RLOGI("Debug port: Dial Call");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003995 dialData.clir = 0;
3996 dialData.address = args[1];
Etan Cohend3652192014-06-20 08:28:44 -07003997 issueLocalRequest(RIL_REQUEST_DIAL, &dialData, sizeof(dialData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003998 break;
3999 case 9:
Wink Saville8eb2a122012-11-19 16:05:13 -08004000 RLOGI("Debug port: Answer Call");
Etan Cohend3652192014-06-20 08:28:44 -07004001 issueLocalRequest(RIL_REQUEST_ANSWER, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004002 break;
4003 case 10:
Wink Saville8eb2a122012-11-19 16:05:13 -08004004 RLOGI("Debug port: End Call");
Wink Saville7f856802009-06-09 10:23:37 -07004005 issueLocalRequest(RIL_REQUEST_HANGUP, &hangupData,
Etan Cohend3652192014-06-20 08:28:44 -07004006 sizeof(hangupData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004007 break;
4008 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004009 RLOGE ("Invalid request");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004010 break;
4011 }
4012 freeDebugCallbackArgs(number, args);
4013 close(acceptFD);
4014}
4015
4016
Wink Savillef4c4d362009-04-02 01:37:03 -07004017static void userTimerCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004018 UserCallbackInfo *p_info;
4019
4020 p_info = (UserCallbackInfo *)param;
4021
4022 p_info->p_callback(p_info->userParam);
4023
4024
4025 // FIXME generalize this...there should be a cancel mechanism
4026 if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) {
4027 s_last_wake_timeout_info = NULL;
4028 }
4029
4030 free(p_info);
4031}
4032
4033
4034static void *
Wink Savillef4c4d362009-04-02 01:37:03 -07004035eventLoop(void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004036 int ret;
4037 int filedes[2];
4038
4039 ril_event_init();
4040
4041 pthread_mutex_lock(&s_startupMutex);
4042
4043 s_started = 1;
4044 pthread_cond_broadcast(&s_startupCond);
4045
4046 pthread_mutex_unlock(&s_startupMutex);
4047
4048 ret = pipe(filedes);
4049
4050 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004051 RLOGE("Error in pipe() errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004052 return NULL;
4053 }
4054
4055 s_fdWakeupRead = filedes[0];
4056 s_fdWakeupWrite = filedes[1];
4057
4058 fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK);
4059
4060 ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,
4061 processWakeupCallback, NULL);
4062
4063 rilEventAddWakeup (&s_wakeupfd_event);
4064
4065 // Only returns on error
4066 ril_event_loop();
Wink Saville8eb2a122012-11-19 16:05:13 -08004067 RLOGE ("error in event_loop_base errno:%d", errno);
Kazuhiro Ondo5cdc1352011-10-14 17:50:58 -05004068 // kill self to restart on error
4069 kill(0, SIGKILL);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004070
4071 return NULL;
4072}
4073
Wink Saville7f856802009-06-09 10:23:37 -07004074extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07004075RIL_startEventLoop(void) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004076 /* spin up eventLoop thread and wait for it to get started */
4077 s_started = 0;
4078 pthread_mutex_lock(&s_startupMutex);
4079
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004080 pthread_attr_t attr;
4081 pthread_attr_init(&attr);
Wink Saville7f856802009-06-09 10:23:37 -07004082 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004083
Elliott Hughesfd81e712014-01-06 12:46:02 -08004084 int result = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
4085 if (result != 0) {
4086 RLOGE("Failed to create dispatch thread: %s", strerror(result));
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004087 goto done;
4088 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004089
4090 while (s_started == 0) {
4091 pthread_cond_wait(&s_startupCond, &s_startupMutex);
4092 }
4093
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004094done:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004095 pthread_mutex_unlock(&s_startupMutex);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004096}
4097
4098// Used for testing purpose only.
4099extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) {
4100 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4101}
4102
Etan Cohend3652192014-06-20 08:28:44 -07004103static void startListen(RIL_SOCKET_ID socket_id, SocketListenParam* socket_listen_p) {
4104 int fdListen = -1;
4105 int ret;
4106 char socket_name[10];
4107
4108 memset(socket_name, 0, sizeof(char)*10);
4109
4110 switch(socket_id) {
4111 case RIL_SOCKET_1:
4112 strncpy(socket_name, RIL_getRilSocketName(), 9);
4113 break;
4114 #if (SIM_COUNT >= 2)
4115 case RIL_SOCKET_2:
4116 strncpy(socket_name, SOCKET2_NAME_RIL, 9);
4117 break;
4118 #endif
4119 #if (SIM_COUNT >= 3)
4120 case RIL_SOCKET_3:
4121 strncpy(socket_name, SOCKET3_NAME_RIL, 9);
4122 break;
4123 #endif
4124 #if (SIM_COUNT >= 4)
4125 case RIL_SOCKET_4:
4126 strncpy(socket_name, SOCKET4_NAME_RIL, 9);
4127 break;
4128 #endif
4129 default:
4130 RLOGE("Socket id is wrong!!");
4131 return;
4132 }
4133
4134 RLOGI("Start to listen %s", rilSocketIdToString(socket_id));
4135
4136 fdListen = android_get_control_socket(socket_name);
4137 if (fdListen < 0) {
4138 RLOGE("Failed to get socket %s", socket_name);
4139 exit(-1);
4140 }
4141
4142 ret = listen(fdListen, 4);
4143
4144 if (ret < 0) {
4145 RLOGE("Failed to listen on control socket '%d': %s",
4146 fdListen, strerror(errno));
4147 exit(-1);
4148 }
4149 socket_listen_p->fdListen = fdListen;
4150
4151 /* note: non-persistent so we can accept only one connection at a time */
4152 ril_event_set (socket_listen_p->listen_event, fdListen, false,
4153 listenCallback, socket_listen_p);
4154
4155 rilEventAddWakeup (socket_listen_p->listen_event);
4156}
4157
Wink Saville7f856802009-06-09 10:23:37 -07004158extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07004159RIL_register (const RIL_RadioFunctions *callbacks) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004160 int ret;
4161 int flags;
4162
Etan Cohend3652192014-06-20 08:28:44 -07004163 RLOGI("SIM_COUNT: %d", SIM_COUNT);
4164
Wink Saville43808972011-01-13 17:39:51 -08004165 if (callbacks == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004166 RLOGE("RIL_register: RIL_RadioFunctions * null");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004167 return;
4168 }
Wink Saville43808972011-01-13 17:39:51 -08004169 if (callbacks->version < RIL_VERSION_MIN) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004170 RLOGE("RIL_register: version %d is to old, min version is %d",
Wink Saville43808972011-01-13 17:39:51 -08004171 callbacks->version, RIL_VERSION_MIN);
4172 return;
Wink Saville3a4840b2010-04-07 13:29:58 -07004173 }
Wink Saville43808972011-01-13 17:39:51 -08004174 if (callbacks->version > RIL_VERSION) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004175 RLOGE("RIL_register: version %d is too new, max version is %d",
Wink Saville43808972011-01-13 17:39:51 -08004176 callbacks->version, RIL_VERSION);
4177 return;
4178 }
Wink Saville8eb2a122012-11-19 16:05:13 -08004179 RLOGE("RIL_register: RIL version %d", callbacks->version);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004180
4181 if (s_registerCalled > 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004182 RLOGE("RIL_register has been called more than once. "
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004183 "Subsequent call ignored");
4184 return;
4185 }
4186
4187 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4188
Etan Cohend3652192014-06-20 08:28:44 -07004189 /* Initialize socket1 parameters */
4190 s_ril_param_socket = {
4191 RIL_SOCKET_1, /* socket_id */
4192 -1, /* fdListen */
4193 -1, /* fdCommand */
4194 PHONE_PROCESS, /* processName */
4195 &s_commands_event, /* commands_event */
4196 &s_listen_event, /* listen_event */
4197 processCommandsCallback, /* processCommandsCallback */
4198 NULL /* p_rs */
4199 };
4200
4201#if (SIM_COUNT >= 2)
4202 s_ril_param_socket2 = {
4203 RIL_SOCKET_2, /* socket_id */
4204 -1, /* fdListen */
4205 -1, /* fdCommand */
4206 PHONE_PROCESS, /* processName */
4207 &s_commands_event_socket2, /* commands_event */
4208 &s_listen_event_socket2, /* listen_event */
4209 processCommandsCallback, /* processCommandsCallback */
4210 NULL /* p_rs */
4211 };
4212#endif
4213
4214#if (SIM_COUNT >= 3)
4215 s_ril_param_socket3 = {
4216 RIL_SOCKET_3, /* socket_id */
4217 -1, /* fdListen */
4218 -1, /* fdCommand */
4219 PHONE_PROCESS, /* processName */
4220 &s_commands_event_socket3, /* commands_event */
4221 &s_listen_event_socket3, /* listen_event */
4222 processCommandsCallback, /* processCommandsCallback */
4223 NULL /* p_rs */
4224 };
4225#endif
4226
4227#if (SIM_COUNT >= 4)
4228 s_ril_param_socket4 = {
4229 RIL_SOCKET_4, /* socket_id */
4230 -1, /* fdListen */
4231 -1, /* fdCommand */
4232 PHONE_PROCESS, /* processName */
4233 &s_commands_event_socket4, /* commands_event */
4234 &s_listen_event_socket4, /* listen_event */
4235 processCommandsCallback, /* processCommandsCallback */
4236 NULL /* p_rs */
4237 };
4238#endif
4239
4240
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004241 s_registerCalled = 1;
4242
Etan Cohend3652192014-06-20 08:28:44 -07004243 RLOGI("s_registerCalled flag set, %d", s_started);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004244 // Little self-check
4245
Wink Savillef4c4d362009-04-02 01:37:03 -07004246 for (int i = 0; i < (int)NUM_ELEMS(s_commands); i++) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004247 assert(i == s_commands[i].requestNumber);
4248 }
4249
Wink Savillef4c4d362009-04-02 01:37:03 -07004250 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses); i++) {
Wink Saville7f856802009-06-09 10:23:37 -07004251 assert(i + RIL_UNSOL_RESPONSE_BASE
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004252 == s_unsolResponses[i].requestNumber);
4253 }
4254
4255 // New rild impl calls RIL_startEventLoop() first
4256 // old standalone impl wants it here.
4257
4258 if (s_started == 0) {
4259 RIL_startEventLoop();
4260 }
4261
Etan Cohend3652192014-06-20 08:28:44 -07004262 // start listen socket1
4263 startListen(RIL_SOCKET_1, &s_ril_param_socket);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004264
Etan Cohend3652192014-06-20 08:28:44 -07004265#if (SIM_COUNT >= 2)
4266 // start listen socket2
4267 startListen(RIL_SOCKET_2, &s_ril_param_socket2);
4268#endif /* (SIM_COUNT == 2) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004269
Etan Cohend3652192014-06-20 08:28:44 -07004270#if (SIM_COUNT >= 3)
4271 // start listen socket3
4272 startListen(RIL_SOCKET_3, &s_ril_param_socket3);
4273#endif /* (SIM_COUNT == 3) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004274
Etan Cohend3652192014-06-20 08:28:44 -07004275#if (SIM_COUNT >= 4)
4276 // start listen socket4
4277 startListen(RIL_SOCKET_4, &s_ril_param_socket4);
4278#endif /* (SIM_COUNT == 4) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004279
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004280
4281#if 1
4282 // start debug interface socket
4283
Etan Cohend3652192014-06-20 08:28:44 -07004284 char *inst = NULL;
4285 if (strlen(RIL_getRilSocketName()) >= strlen(SOCKET_NAME_RIL)) {
4286 inst = RIL_getRilSocketName() + strlen(SOCKET_NAME_RIL);
4287 }
4288
4289 char rildebug[MAX_DEBUG_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL_DEBUG;
4290 if (inst != NULL) {
Nick Kralevichc52e45e2015-02-08 07:54:16 -08004291 strlcat(rildebug, inst, MAX_DEBUG_SOCKET_NAME_LENGTH);
Etan Cohend3652192014-06-20 08:28:44 -07004292 }
4293
4294 s_fdDebug = android_get_control_socket(rildebug);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004295 if (s_fdDebug < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07004296 RLOGE("Failed to get socket : %s errno:%d", rildebug, errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004297 exit(-1);
4298 }
4299
4300 ret = listen(s_fdDebug, 4);
4301
4302 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004303 RLOGE("Failed to listen on ril debug socket '%d': %s",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004304 s_fdDebug, strerror(errno));
4305 exit(-1);
4306 }
4307
4308 ril_event_set (&s_debug_event, s_fdDebug, true,
4309 debugCallback, NULL);
4310
4311 rilEventAddWakeup (&s_debug_event);
4312#endif
4313
4314}
4315
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004316extern "C" void
4317RIL_register_socket (RIL_RadioFunctions *(*Init)(const struct RIL_Env *, int, char **),RIL_SOCKET_TYPE socketType, int argc, char **argv) {
4318
4319 RIL_RadioFunctions* UimFuncs = NULL;
4320
4321 if(Init) {
4322 UimFuncs = Init(&RilSapSocket::uimRilEnv, argc, argv);
4323
4324 switch(socketType) {
4325 case RIL_SAP_SOCKET:
4326 RilSapSocket::initSapSocket("sap_uim_socket1", UimFuncs);
4327
4328#if (SIM_COUNT >= 2)
4329 RilSapSocket::initSapSocket("sap_uim_socket2", UimFuncs);
4330#endif
4331
4332#if (SIM_COUNT >= 3)
4333 RilSapSocket::initSapSocket("sap_uim_socket3", UimFuncs);
4334#endif
4335
4336#if (SIM_COUNT >= 4)
4337 RilSapSocket::initSapSocket("sap_uim_socket4", UimFuncs);
4338#endif
4339 }
4340 }
4341}
4342
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004343static int
Wink Savillef4c4d362009-04-02 01:37:03 -07004344checkAndDequeueRequestInfo(struct RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004345 int ret = 0;
Etan Cohend3652192014-06-20 08:28:44 -07004346 /* Hook for current context
4347 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
4348 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
4349 /* pendingRequestsHook refer to &s_pendingRequests */
4350 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
Wink Saville7f856802009-06-09 10:23:37 -07004351
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004352 if (pRI == NULL) {
4353 return 0;
4354 }
4355
Etan Cohend3652192014-06-20 08:28:44 -07004356#if (SIM_COUNT >= 2)
4357 if (pRI->socket_id == RIL_SOCKET_2) {
4358 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
4359 pendingRequestsHook = &s_pendingRequests_socket2;
4360 }
4361#if (SIM_COUNT >= 3)
4362 if (pRI->socket_id == RIL_SOCKET_3) {
4363 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
4364 pendingRequestsHook = &s_pendingRequests_socket3;
4365 }
4366#endif
4367#if (SIM_COUNT >= 4)
4368 if (pRI->socket_id == RIL_SOCKET_4) {
4369 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
4370 pendingRequestsHook = &s_pendingRequests_socket4;
4371 }
4372#endif
4373#endif
4374 pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004375
Etan Cohend3652192014-06-20 08:28:44 -07004376 for(RequestInfo **ppCur = pendingRequestsHook
Wink Saville7f856802009-06-09 10:23:37 -07004377 ; *ppCur != NULL
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004378 ; ppCur = &((*ppCur)->p_next)
4379 ) {
4380 if (pRI == *ppCur) {
4381 ret = 1;
4382
4383 *ppCur = (*ppCur)->p_next;
4384 break;
4385 }
4386 }
4387
Etan Cohend3652192014-06-20 08:28:44 -07004388 pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004389
4390 return ret;
4391}
4392
4393
4394extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07004395RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004396 RequestInfo *pRI;
4397 int ret;
Etan Cohend3652192014-06-20 08:28:44 -07004398 int fd = s_ril_param_socket.fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004399 size_t errorOffset;
Etan Cohend3652192014-06-20 08:28:44 -07004400 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004401
4402 pRI = (RequestInfo *)t;
4403
Jayachandran C6c607592014-08-04 15:48:01 -07004404 if (!checkAndDequeueRequestInfo(pRI)) {
4405 RLOGE ("RIL_onRequestComplete: invalid RIL_Token");
4406 return;
4407 }
4408
Etan Cohend3652192014-06-20 08:28:44 -07004409 socket_id = pRI->socket_id;
4410#if (SIM_COUNT >= 2)
4411 if (socket_id == RIL_SOCKET_2) {
4412 fd = s_ril_param_socket2.fdCommand;
4413 }
4414#if (SIM_COUNT >= 3)
4415 if (socket_id == RIL_SOCKET_3) {
4416 fd = s_ril_param_socket3.fdCommand;
4417 }
4418#endif
4419#if (SIM_COUNT >= 4)
4420 if (socket_id == RIL_SOCKET_4) {
4421 fd = s_ril_param_socket4.fdCommand;
4422 }
4423#endif
4424#endif
4425 RLOGD("RequestComplete, %s", rilSocketIdToString(socket_id));
4426
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004427 if (pRI->local > 0) {
4428 // Locally issued command...void only!
4429 // response does not go back up the command socket
Wink Saville8eb2a122012-11-19 16:05:13 -08004430 RLOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004431
4432 goto done;
4433 }
4434
4435 appendPrintBuf("[%04d]< %s",
4436 pRI->token, requestToString(pRI->pCI->requestNumber));
4437
4438 if (pRI->cancelled == 0) {
4439 Parcel p;
4440
4441 p.writeInt32 (RESPONSE_SOLICITED);
4442 p.writeInt32 (pRI->token);
4443 errorOffset = p.dataPosition();
4444
4445 p.writeInt32 (e);
4446
johnwangb2a61842009-06-02 14:55:45 -07004447 if (response != NULL) {
4448 // there is a response payload, no matter success or not.
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004449 ret = pRI->pCI->responseFunction(p, response, responselen);
4450
4451 /* if an error occurred, rewind and mark it */
4452 if (ret != 0) {
Etan Cohend3652192014-06-20 08:28:44 -07004453 RLOGE ("responseFunction error, ret %d", ret);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004454 p.setDataPosition(errorOffset);
4455 p.writeInt32 (ret);
4456 }
johnwangb2a61842009-06-02 14:55:45 -07004457 }
4458
4459 if (e != RIL_E_SUCCESS) {
4460 appendPrintBuf("%s fails by %s", printBuf, failCauseToString(e));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004461 }
4462
Etan Cohend3652192014-06-20 08:28:44 -07004463 if (fd < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004464 RLOGD ("RIL onRequestComplete: Command channel closed");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004465 }
Etan Cohend3652192014-06-20 08:28:44 -07004466 sendResponse(p, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004467 }
4468
4469done:
4470 free(pRI);
4471}
4472
4473
4474static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004475grabPartialWakeLock() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004476 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
4477}
4478
4479static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004480releaseWakeLock() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004481 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
4482}
4483
4484/**
4485 * Timer callback to put us back to sleep before the default timeout
4486 */
4487static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004488wakeTimeoutCallback (void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004489 // We're using "param != NULL" as a cancellation mechanism
4490 if (param == NULL) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004491 releaseWakeLock();
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004492 }
4493}
4494
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004495static int
4496decodeVoiceRadioTechnology (RIL_RadioState radioState) {
4497 switch (radioState) {
4498 case RADIO_STATE_SIM_NOT_READY:
4499 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4500 case RADIO_STATE_SIM_READY:
4501 return RADIO_TECH_UMTS;
4502
4503 case RADIO_STATE_RUIM_NOT_READY:
4504 case RADIO_STATE_RUIM_READY:
4505 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4506 case RADIO_STATE_NV_NOT_READY:
4507 case RADIO_STATE_NV_READY:
4508 return RADIO_TECH_1xRTT;
4509
4510 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004511 RLOGD("decodeVoiceRadioTechnology: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004512 return -1;
4513 }
4514}
4515
4516static int
4517decodeCdmaSubscriptionSource (RIL_RadioState radioState) {
4518 switch (radioState) {
4519 case RADIO_STATE_SIM_NOT_READY:
4520 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4521 case RADIO_STATE_SIM_READY:
4522 case RADIO_STATE_RUIM_NOT_READY:
4523 case RADIO_STATE_RUIM_READY:
4524 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4525 return CDMA_SUBSCRIPTION_SOURCE_RUIM_SIM;
4526
4527 case RADIO_STATE_NV_NOT_READY:
4528 case RADIO_STATE_NV_READY:
4529 return CDMA_SUBSCRIPTION_SOURCE_NV;
4530
4531 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004532 RLOGD("decodeCdmaSubscriptionSource: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004533 return -1;
4534 }
4535}
4536
4537static int
4538decodeSimStatus (RIL_RadioState radioState) {
4539 switch (radioState) {
4540 case RADIO_STATE_SIM_NOT_READY:
4541 case RADIO_STATE_RUIM_NOT_READY:
4542 case RADIO_STATE_NV_NOT_READY:
4543 case RADIO_STATE_NV_READY:
4544 return -1;
4545 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4546 case RADIO_STATE_SIM_READY:
4547 case RADIO_STATE_RUIM_READY:
4548 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4549 return radioState;
4550 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004551 RLOGD("decodeSimStatus: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004552 return -1;
4553 }
4554}
4555
4556static bool is3gpp2(int radioTech) {
4557 switch (radioTech) {
4558 case RADIO_TECH_IS95A:
4559 case RADIO_TECH_IS95B:
4560 case RADIO_TECH_1xRTT:
4561 case RADIO_TECH_EVDO_0:
4562 case RADIO_TECH_EVDO_A:
4563 case RADIO_TECH_EVDO_B:
4564 case RADIO_TECH_EHRPD:
4565 return true;
4566 default:
4567 return false;
4568 }
4569}
4570
4571/* If RIL sends SIM states or RUIM states, store the voice radio
4572 * technology and subscription source information so that they can be
4573 * returned when telephony framework requests them
4574 */
4575static RIL_RadioState
Etan Cohend3652192014-06-20 08:28:44 -07004576processRadioState(RIL_RadioState newRadioState, RIL_SOCKET_ID socket_id) {
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004577
4578 if((newRadioState > RADIO_STATE_UNAVAILABLE) && (newRadioState < RADIO_STATE_ON)) {
4579 int newVoiceRadioTech;
4580 int newCdmaSubscriptionSource;
4581 int newSimStatus;
4582
4583 /* This is old RIL. Decode Subscription source and Voice Radio Technology
4584 from Radio State and send change notifications if there has been a change */
4585 newVoiceRadioTech = decodeVoiceRadioTechnology(newRadioState);
4586 if(newVoiceRadioTech != voiceRadioTech) {
4587 voiceRadioTech = newVoiceRadioTech;
Etan Cohend3652192014-06-20 08:28:44 -07004588 RIL_UNSOL_RESPONSE(RIL_UNSOL_VOICE_RADIO_TECH_CHANGED,
4589 &voiceRadioTech, sizeof(voiceRadioTech), socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004590 }
4591 if(is3gpp2(newVoiceRadioTech)) {
4592 newCdmaSubscriptionSource = decodeCdmaSubscriptionSource(newRadioState);
4593 if(newCdmaSubscriptionSource != cdmaSubscriptionSource) {
4594 cdmaSubscriptionSource = newCdmaSubscriptionSource;
Etan Cohend3652192014-06-20 08:28:44 -07004595 RIL_UNSOL_RESPONSE(RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED,
4596 &cdmaSubscriptionSource, sizeof(cdmaSubscriptionSource), socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004597 }
4598 }
4599 newSimStatus = decodeSimStatus(newRadioState);
4600 if(newSimStatus != simRuimStatus) {
4601 simRuimStatus = newSimStatus;
Etan Cohend3652192014-06-20 08:28:44 -07004602 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0, socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004603 }
4604
4605 /* Send RADIO_ON to telephony */
4606 newRadioState = RADIO_STATE_ON;
4607 }
4608
4609 return newRadioState;
4610}
4611
Etan Cohend3652192014-06-20 08:28:44 -07004612
4613#if defined(ANDROID_MULTI_SIM)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004614extern "C"
Bernhard Rosenkränzerd613b962014-11-17 20:52:09 +01004615void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Etan Cohend3652192014-06-20 08:28:44 -07004616 size_t datalen, RIL_SOCKET_ID socket_id)
4617#else
4618extern "C"
Bernhard Rosenkränzerd613b962014-11-17 20:52:09 +01004619void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004620 size_t datalen)
Etan Cohend3652192014-06-20 08:28:44 -07004621#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004622{
4623 int unsolResponseIndex;
4624 int ret;
4625 int64_t timeReceived = 0;
4626 bool shouldScheduleTimeout = false;
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004627 RIL_RadioState newState;
Etan Cohend3652192014-06-20 08:28:44 -07004628 RIL_SOCKET_ID soc_id = RIL_SOCKET_1;
4629
4630#if defined(ANDROID_MULTI_SIM)
4631 soc_id = socket_id;
4632#endif
4633
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004634
4635 if (s_registerCalled == 0) {
4636 // Ignore RIL_onUnsolicitedResponse before RIL_register
Wink Saville8eb2a122012-11-19 16:05:13 -08004637 RLOGW("RIL_onUnsolicitedResponse called before RIL_register");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004638 return;
4639 }
Wink Saville7f856802009-06-09 10:23:37 -07004640
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004641 unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
4642
4643 if ((unsolResponseIndex < 0)
4644 || (unsolResponseIndex >= (int32_t)NUM_ELEMS(s_unsolResponses))) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004645 RLOGE("unsupported unsolicited response code %d", unsolResponse);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004646 return;
4647 }
4648
4649 // Grab a wake lock if needed for this reponse,
4650 // as we exit we'll either release it immediately
4651 // or set a timer to release it later.
4652 switch (s_unsolResponses[unsolResponseIndex].wakeType) {
4653 case WAKE_PARTIAL:
4654 grabPartialWakeLock();
4655 shouldScheduleTimeout = true;
4656 break;
4657
4658 case DONT_WAKE:
4659 default:
4660 // No wake lock is grabed so don't set timeout
4661 shouldScheduleTimeout = false;
4662 break;
4663 }
4664
4665 // Mark the time this was received, doing this
4666 // after grabing the wakelock incase getting
4667 // the elapsedRealTime might cause us to goto
4668 // sleep.
4669 if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4670 timeReceived = elapsedRealtime();
4671 }
4672
4673 appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
4674
4675 Parcel p;
4676
4677 p.writeInt32 (RESPONSE_UNSOLICITED);
4678 p.writeInt32 (unsolResponse);
4679
4680 ret = s_unsolResponses[unsolResponseIndex]
Bernhard Rosenkränzer6e7c1962013-12-12 10:01:10 +01004681 .responseFunction(p, const_cast<void*>(data), datalen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004682 if (ret != 0) {
4683 // Problem with the response. Don't continue;
4684 goto error_exit;
4685 }
4686
4687 // some things get more payload
4688 switch(unsolResponse) {
4689 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
Etan Cohend3652192014-06-20 08:28:44 -07004690 newState = processRadioState(CALL_ONSTATEREQUEST(soc_id), soc_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004691 p.writeInt32(newState);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004692 appendPrintBuf("%s {%s}", printBuf,
Etan Cohend3652192014-06-20 08:28:44 -07004693 radioStateToString(CALL_ONSTATEREQUEST(soc_id)));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004694 break;
4695
4696
4697 case RIL_UNSOL_NITZ_TIME_RECEIVED:
4698 // Store the time that this was received so the
4699 // handler of this message can account for
4700 // the time it takes to arrive and process. In
4701 // particular the system has been known to sleep
4702 // before this message can be processed.
4703 p.writeInt64(timeReceived);
4704 break;
4705 }
4706
Etan Cohend3652192014-06-20 08:28:44 -07004707 RLOGI("%s UNSOLICITED: %s length:%d", rilSocketIdToString(soc_id), requestToString(unsolResponse), p.dataSize());
4708 ret = sendResponse(p, soc_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004709 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4710
4711 // Unfortunately, NITZ time is not poll/update like everything
4712 // else in the system. So, if the upstream client isn't connected,
4713 // keep a copy of the last NITZ response (with receive time noted
4714 // above) around so we can deliver it when it is connected
4715
4716 if (s_lastNITZTimeData != NULL) {
4717 free (s_lastNITZTimeData);
4718 s_lastNITZTimeData = NULL;
4719 }
4720
4721 s_lastNITZTimeData = malloc(p.dataSize());
4722 s_lastNITZTimeDataSize = p.dataSize();
4723 memcpy(s_lastNITZTimeData, p.data(), p.dataSize());
4724 }
4725
4726 // For now, we automatically go back to sleep after TIMEVAL_WAKE_TIMEOUT
4727 // FIXME The java code should handshake here to release wake lock
4728
4729 if (shouldScheduleTimeout) {
4730 // Cancel the previous request
4731 if (s_last_wake_timeout_info != NULL) {
4732 s_last_wake_timeout_info->userParam = (void *)1;
4733 }
4734
4735 s_last_wake_timeout_info
4736 = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
4737 &TIMEVAL_WAKE_TIMEOUT);
4738 }
4739
4740 // Normal exit
4741 return;
4742
4743error_exit:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004744 if (shouldScheduleTimeout) {
4745 releaseWakeLock();
4746 }
4747}
4748
Wink Saville7f856802009-06-09 10:23:37 -07004749/** FIXME generalize this if you track UserCAllbackInfo, clear it
4750 when the callback occurs
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004751*/
4752static UserCallbackInfo *
Wink Saville7f856802009-06-09 10:23:37 -07004753internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004754 const struct timeval *relativeTime)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004755{
4756 struct timeval myRelativeTime;
4757 UserCallbackInfo *p_info;
4758
4759 p_info = (UserCallbackInfo *) malloc (sizeof(UserCallbackInfo));
4760
Wink Saville7f856802009-06-09 10:23:37 -07004761 p_info->p_callback = callback;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004762 p_info->userParam = param;
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004763
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004764 if (relativeTime == NULL) {
4765 /* treat null parameter as a 0 relative time */
4766 memset (&myRelativeTime, 0, sizeof(myRelativeTime));
4767 } else {
4768 /* FIXME I think event_add's tv param is really const anyway */
4769 memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
4770 }
4771
4772 ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
4773
4774 ril_timer_add(&(p_info->event), &myRelativeTime);
4775
4776 triggerEvLoop();
4777 return p_info;
4778}
4779
Naveen Kalla7edd07c2010-06-21 18:54:47 -07004780
4781extern "C" void
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004782RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
4783 const struct timeval *relativeTime) {
4784 internalRequestTimedCallback (callback, param, relativeTime);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004785}
4786
4787const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004788failCauseToString(RIL_Errno e) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004789 switch(e) {
4790 case RIL_E_SUCCESS: return "E_SUCCESS";
Robert Greenwalt2126ab22013-04-09 12:20:45 -07004791 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RADIO_NOT_AVAILABLE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004792 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
4793 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
4794 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
4795 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
4796 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
4797 case RIL_E_CANCELLED: return "E_CANCELLED";
4798 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
4799 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
4800 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
Wink Savillef4c4d362009-04-02 01:37:03 -07004801 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
John Wang75534472010-04-20 15:11:42 -07004802 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
Wink Saville7f856802009-06-09 10:23:37 -07004803#ifdef FEATURE_MULTIMODE_ANDROID
Wink Savillef4c4d362009-04-02 01:37:03 -07004804 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
4805 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
4806#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004807 default: return "<unknown error>";
4808 }
4809}
4810
4811const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004812radioStateToString(RIL_RadioState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004813 switch(s) {
4814 case RADIO_STATE_OFF: return "RADIO_OFF";
4815 case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
4816 case RADIO_STATE_SIM_NOT_READY: return "RADIO_SIM_NOT_READY";
4817 case RADIO_STATE_SIM_LOCKED_OR_ABSENT: return "RADIO_SIM_LOCKED_OR_ABSENT";
4818 case RADIO_STATE_SIM_READY: return "RADIO_SIM_READY";
Wink Savillef4c4d362009-04-02 01:37:03 -07004819 case RADIO_STATE_RUIM_NOT_READY:return"RADIO_RUIM_NOT_READY";
4820 case RADIO_STATE_RUIM_READY:return"RADIO_RUIM_READY";
4821 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:return"RADIO_RUIM_LOCKED_OR_ABSENT";
4822 case RADIO_STATE_NV_NOT_READY:return"RADIO_NV_NOT_READY";
4823 case RADIO_STATE_NV_READY:return"RADIO_NV_READY";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004824 case RADIO_STATE_ON:return"RADIO_ON";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004825 default: return "<unknown state>";
4826 }
4827}
4828
4829const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004830callStateToString(RIL_CallState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004831 switch(s) {
4832 case RIL_CALL_ACTIVE : return "ACTIVE";
4833 case RIL_CALL_HOLDING: return "HOLDING";
4834 case RIL_CALL_DIALING: return "DIALING";
4835 case RIL_CALL_ALERTING: return "ALERTING";
4836 case RIL_CALL_INCOMING: return "INCOMING";
4837 case RIL_CALL_WAITING: return "WAITING";
4838 default: return "<unknown state>";
4839 }
4840}
4841
4842const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004843requestToString(int request) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004844/*
4845 cat libs/telephony/ril_commands.h \
4846 | egrep "^ *{RIL_" \
4847 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
4848
4849
4850 cat libs/telephony/ril_unsol_commands.h \
4851 | egrep "^ *{RIL_" \
4852 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
4853
4854*/
4855 switch(request) {
4856 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
4857 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
4858 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
4859 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
4860 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
4861 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
4862 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
4863 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
4864 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
4865 case RIL_REQUEST_DIAL: return "DIAL";
4866 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
4867 case RIL_REQUEST_HANGUP: return "HANGUP";
4868 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
4869 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
4870 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
4871 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
4872 case RIL_REQUEST_UDUB: return "UDUB";
4873 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
4874 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
Wink Savillec0114b32011-02-18 10:14:07 -08004875 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
4876 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004877 case RIL_REQUEST_OPERATOR: return "OPERATOR";
4878 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
4879 case RIL_REQUEST_DTMF: return "DTMF";
4880 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
4881 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
Wink Savillef4c4d362009-04-02 01:37:03 -07004882 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004883 case RIL_REQUEST_SIM_IO: return "SIM_IO";
4884 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
4885 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
4886 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
4887 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
4888 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
4889 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
4890 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
4891 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
4892 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
4893 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
4894 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
4895 case RIL_REQUEST_ANSWER: return "ANSWER";
Wink Savillef4c4d362009-04-02 01:37:03 -07004896 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004897 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
4898 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
4899 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
4900 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
4901 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
4902 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
4903 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";
4904 case RIL_REQUEST_DTMF_START: return "DTMF_START";
4905 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
4906 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
4907 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
4908 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
4909 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
4910 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
4911 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
4912 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
4913 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
Wink Savillef4c4d362009-04-02 01:37:03 -07004914 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
4915 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004916 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
4917 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
4918 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
Wink Savillef4c4d362009-04-02 01:37:03 -07004919 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
4920 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004921 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
4922 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
4923 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
4924 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
4925 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
4926 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
4927 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
4928 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
Wink Savillec0114b32011-02-18 10:14:07 -08004929 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE:return"CDMA_SET_SUBSCRIPTION_SOURCE";
Wink Savillef4c4d362009-04-02 01:37:03 -07004930 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"CDMA_SET_ROAMING_PREFERENCE";
4931 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"CDMA_QUERY_ROAMING_PREFERENCE";
4932 case RIL_REQUEST_SET_TTY_MODE:return"SET_TTY_MODE";
4933 case RIL_REQUEST_QUERY_TTY_MODE:return"QUERY_TTY_MODE";
4934 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
4935 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
4936 case RIL_REQUEST_CDMA_FLASH:return"CDMA_FLASH";
4937 case RIL_REQUEST_CDMA_BURST_DTMF:return"CDMA_BURST_DTMF";
4938 case RIL_REQUEST_CDMA_SEND_SMS:return"CDMA_SEND_SMS";
4939 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:return"CDMA_SMS_ACKNOWLEDGE";
Wink Savillea592eeb2009-05-22 13:26:36 -07004940 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG:return"GSM_GET_BROADCAST_SMS_CONFIG";
4941 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG:return"GSM_SET_BROADCAST_SMS_CONFIG";
4942 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG:return "CDMA_GET_BROADCAST_SMS_CONFIG";
4943 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG:return "CDMA_SET_BROADCAST_SMS_CONFIG";
4944 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION:return "CDMA_SMS_BROADCAST_ACTIVATION";
Naveen Kalla03c1edf2009-09-23 11:18:35 -07004945 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return"CDMA_VALIDATE_AND_WRITE_AKEY";
Wink Savillef4c4d362009-04-02 01:37:03 -07004946 case RIL_REQUEST_CDMA_SUBSCRIPTION: return"CDMA_SUBSCRIPTION";
4947 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
4948 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
4949 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
jsh000a9fe2009-05-11 14:52:35 -07004950 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
4951 case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
4952 case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
jsh09a68ba2009-06-10 11:56:38 -07004953 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
jsh563fd722010-06-08 16:52:24 -07004954 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
Wink Savillec0114b32011-02-18 10:14:07 -08004955 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
Jake Hambyfa8d5842011-08-19 16:22:18 -07004956 case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
Jake Hamby300105d2011-09-26 01:01:44 -07004957 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
4958 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004959 case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
Wink Saville8a9e0212013-04-09 12:11:38 -07004960 case RIL_REQUEST_GET_CELL_INFO_LIST: return"GET_CELL_INFO_LIST";
4961 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return"SET_UNSOL_CELL_INFO_LIST_RATE";
Sungmin Choi75697532013-04-26 15:04:45 -07004962 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "RIL_REQUEST_SET_INITIAL_ATTACH_APN";
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07004963 case RIL_REQUEST_IMS_REGISTRATION_STATE: return "IMS_REGISTRATION_STATE";
4964 case RIL_REQUEST_IMS_SEND_SMS: return "IMS_SEND_SMS";
Shishir Agrawal2458d8d2013-11-27 14:53:05 -08004965 case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "SIM_TRANSMIT_APDU_BASIC";
4966 case RIL_REQUEST_SIM_OPEN_CHANNEL: return "SIM_OPEN_CHANNEL";
4967 case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "SIM_CLOSE_CHANNEL";
4968 case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "SIM_TRANSMIT_APDU_CHANNEL";
Wink Saville8b4e4f72014-10-17 15:01:45 -07004969 case RIL_REQUEST_GET_RADIO_CAPABILITY: return "RIL_REQUEST_GET_RADIO_CAPABILITY";
4970 case RIL_REQUEST_SET_RADIO_CAPABILITY: return "RIL_REQUEST_SET_RADIO_CAPABILITY";
Etan Cohend3652192014-06-20 08:28:44 -07004971 case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "SET_UICC_SUBSCRIPTION";
4972 case RIL_REQUEST_ALLOW_DATA: return "ALLOW_DATA";
Amit Mahajan2b772032014-06-26 14:20:11 -07004973 case RIL_REQUEST_GET_HARDWARE_CONFIG: return "GET_HARDWARE_CONFIG";
4974 case RIL_REQUEST_SIM_AUTHENTICATION: return "SIM_AUTHENTICATION";
Wink Savillec29360a2014-07-13 05:17:28 -07004975 case RIL_REQUEST_GET_DC_RT_INFO: return "GET_DC_RT_INFO";
4976 case RIL_REQUEST_SET_DC_RT_INFO_RATE: return "SET_DC_RT_INFO_RATE";
Amit Mahajanc796e222014-08-13 16:54:01 +00004977 case RIL_REQUEST_SET_DATA_PROFILE: return "SET_DATA_PROFILE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004978 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
4979 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08004980 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 -08004981 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
4982 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
4983 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
4984 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
4985 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)";
4986 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
4987 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
4988 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
4989 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
4990 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
4991 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
4992 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL";
4993 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
Wink Savillef4c4d362009-04-02 01:37:03 -07004994 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004995 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
Wink Savillef4c4d362009-04-02 01:37:03 -07004996 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
4997 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_NEW_CDMA_SMS";
4998 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_NEW_BROADCAST_SMS";
4999 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
Wink Saville3d54e742009-05-18 18:00:44 -07005000 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
5001 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
5002 case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
5003 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
5004 case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
Jaikumar Ganeshaf6ecbf2009-04-29 13:27:51 -07005005 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
John Wang5d621da2009-09-18 17:17:48 -07005006 case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
John Wang5909cf82010-01-29 00:18:54 -08005007 case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
Wink Savilleee274582011-04-16 15:05:49 -07005008 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08005009 case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
5010 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
Wink Saville5b9df332011-04-06 16:24:21 -07005011 case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005012 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
Wink Saville8a9e0212013-04-09 12:11:38 -07005013 case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07005014 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "RESPONSE_IMS_NETWORK_STATE_CHANGED";
Etan Cohend3652192014-06-20 08:28:44 -07005015 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return "UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED";
5016 case RIL_UNSOL_SRVCC_STATE_NOTIFY: return "UNSOL_SRVCC_STATE_NOTIFY";
5017 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return "HARDWARE_CONFIG_CHANGED";
Wink Savillec29360a2014-07-13 05:17:28 -07005018 case RIL_UNSOL_DC_RT_INFO_CHANGED: return "UNSOL_DC_RT_INFO_CHANGED";
Naveen Kallaa65a16a2014-07-31 16:48:31 -07005019 case RIL_REQUEST_SHUTDOWN: return "SHUTDOWN";
Wink Saville8b4e4f72014-10-17 15:01:45 -07005020 case RIL_UNSOL_RADIO_CAPABILITY: return "RIL_UNSOL_RADIO_CAPABILITY";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005021 default: return "<unknown request>";
5022 }
5023}
5024
Etan Cohend3652192014-06-20 08:28:44 -07005025const char *
5026rilSocketIdToString(RIL_SOCKET_ID socket_id)
5027{
5028 switch(socket_id) {
5029 case RIL_SOCKET_1:
5030 return "RIL_SOCKET_1";
5031#if (SIM_COUNT >= 2)
5032 case RIL_SOCKET_2:
5033 return "RIL_SOCKET_2";
5034#endif
5035#if (SIM_COUNT >= 3)
5036 case RIL_SOCKET_3:
5037 return "RIL_SOCKET_3";
5038#endif
5039#if (SIM_COUNT >= 4)
5040 case RIL_SOCKET_4:
5041 return "RIL_SOCKET_4";
5042#endif
5043 default:
5044 return "not a valid RIL";
5045 }
5046}
5047
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005048} /* namespace android */
Dheeraj Shetty27976c42014-07-02 21:27:57 +02005049
5050void rilEventAddWakeup_helper(struct ril_event *ev) {
5051 android::rilEventAddWakeup(ev);
5052}
5053
5054void listenCallback_helper(int fd, short flags, void *param) {
5055 android::listenCallback(fd, flags, param);
5056}
5057
5058int blockingWrite_helper(int fd, void *buffer, size_t len) {
5059 return android::blockingWrite(fd, buffer, len);
5060}