blob: 30e51c6bda5aef69e479a2680ffd43678aed7670 [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)
306extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
307 size_t datalen, RIL_SOCKET_ID socket_id);
308#else
Wink Saville7f856802009-06-09 10:23:37 -0700309extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, 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
701 memset (&args, 0, sizeof(args));
702
703 status = p.readInt32(&t);
704 args.status = (int)t;
705
706 args.pdu = strdupReadString(p);
707
708 if (status != NO_ERROR || args.pdu == NULL) {
709 goto invalid;
710 }
711
712 args.smsc = strdupReadString(p);
713
714 startRequest;
715 appendPrintBuf("%s%d,%s,smsc=%s", printBuf, args.status,
716 (char*)args.pdu, (char*)args.smsc);
717 closeRequest;
718 printRequest(pRI->token, pRI->pCI->requestNumber);
Wink Saville7f856802009-06-09 10:23:37 -0700719
Etan Cohend3652192014-06-20 08:28:44 -0700720 CALL_ONREQUEST(pRI->pCI->requestNumber, &args, sizeof(args), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800721
722#ifdef MEMSET_FREED
723 memsetString (args.pdu);
724#endif
725
726 free (args.pdu);
Wink Saville7f856802009-06-09 10:23:37 -0700727
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800728#ifdef MEMSET_FREED
729 memset(&args, 0, sizeof(args));
730#endif
731
732 return;
733invalid:
734 invalidCommandBlock(pRI);
735 return;
736}
737
Wink Saville7f856802009-06-09 10:23:37 -0700738/**
739 * Callee expects const RIL_Dial *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800740 * Payload is:
741 * String address
742 * int32_t clir
743 */
744static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700745dispatchDial (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800746 RIL_Dial dial;
Wink Saville74fa3882009-12-22 15:35:41 -0800747 RIL_UUS_Info uusInfo;
Wink Saville7bce0822010-01-08 15:20:12 -0800748 int32_t sizeOfDial;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800749 int32_t t;
Wink Saville74fa3882009-12-22 15:35:41 -0800750 int32_t uusPresent;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800751 status_t status;
752
753 memset (&dial, 0, sizeof(dial));
754
755 dial.address = strdupReadString(p);
756
757 status = p.readInt32(&t);
758 dial.clir = (int)t;
759
760 if (status != NO_ERROR || dial.address == NULL) {
761 goto invalid;
762 }
763
Wink Saville3a4840b2010-04-07 13:29:58 -0700764 if (s_callbacks.version < 3) { // Remove when partners upgrade to version 3
Wink Saville74fa3882009-12-22 15:35:41 -0800765 uusPresent = 0;
Wink Saville7bce0822010-01-08 15:20:12 -0800766 sizeOfDial = sizeof(dial) - sizeof(RIL_UUS_Info *);
Wink Saville74fa3882009-12-22 15:35:41 -0800767 } else {
768 status = p.readInt32(&uusPresent);
769
770 if (status != NO_ERROR) {
771 goto invalid;
772 }
773
774 if (uusPresent == 0) {
775 dial.uusInfo = NULL;
776 } else {
777 int32_t len;
778
779 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
780
781 status = p.readInt32(&t);
782 uusInfo.uusType = (RIL_UUS_Type) t;
783
784 status = p.readInt32(&t);
785 uusInfo.uusDcs = (RIL_UUS_DCS) t;
786
787 status = p.readInt32(&len);
788 if (status != NO_ERROR) {
789 goto invalid;
790 }
791
792 // The java code writes -1 for null arrays
793 if (((int) len) == -1) {
794 uusInfo.uusData = NULL;
795 len = 0;
796 } else {
797 uusInfo.uusData = (char*) p.readInplace(len);
798 }
799
800 uusInfo.uusLength = len;
801 dial.uusInfo = &uusInfo;
802 }
Wink Saville7bce0822010-01-08 15:20:12 -0800803 sizeOfDial = sizeof(dial);
Wink Saville74fa3882009-12-22 15:35:41 -0800804 }
805
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800806 startRequest;
807 appendPrintBuf("%snum=%s,clir=%d", printBuf, dial.address, dial.clir);
Wink Saville74fa3882009-12-22 15:35:41 -0800808 if (uusPresent) {
809 appendPrintBuf("%s,uusType=%d,uusDcs=%d,uusLen=%d", printBuf,
810 dial.uusInfo->uusType, dial.uusInfo->uusDcs,
811 dial.uusInfo->uusLength);
812 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800813 closeRequest;
814 printRequest(pRI->token, pRI->pCI->requestNumber);
815
Etan Cohend3652192014-06-20 08:28:44 -0700816 CALL_ONREQUEST(pRI->pCI->requestNumber, &dial, sizeOfDial, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800817
818#ifdef MEMSET_FREED
819 memsetString (dial.address);
820#endif
821
822 free (dial.address);
Wink Saville7f856802009-06-09 10:23:37 -0700823
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800824#ifdef MEMSET_FREED
Wink Saville74fa3882009-12-22 15:35:41 -0800825 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800826 memset(&dial, 0, sizeof(dial));
827#endif
828
829 return;
830invalid:
831 invalidCommandBlock(pRI);
832 return;
833}
834
Wink Saville7f856802009-06-09 10:23:37 -0700835/**
836 * Callee expects const RIL_SIM_IO *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800837 * Payload is:
838 * int32_t command
839 * int32_t fileid
840 * String path
841 * int32_t p1, p2, p3
Wink Saville7f856802009-06-09 10:23:37 -0700842 * String data
843 * String pin2
Wink Savillec0114b32011-02-18 10:14:07 -0800844 * String aidPtr
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800845 */
846static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700847dispatchSIM_IO (Parcel &p, RequestInfo *pRI) {
Wink Savillec0114b32011-02-18 10:14:07 -0800848 union RIL_SIM_IO {
849 RIL_SIM_IO_v6 v6;
850 RIL_SIM_IO_v5 v5;
851 } simIO;
852
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800853 int32_t t;
Wink Savillec0114b32011-02-18 10:14:07 -0800854 int size;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800855 status_t status;
856
857 memset (&simIO, 0, sizeof(simIO));
858
Wink Saville7f856802009-06-09 10:23:37 -0700859 // note we only check status at the end
860
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800861 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800862 simIO.v6.command = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800863
864 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800865 simIO.v6.fileid = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800866
Wink Savillec0114b32011-02-18 10:14:07 -0800867 simIO.v6.path = strdupReadString(p);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800868
869 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800870 simIO.v6.p1 = (int)t;
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.p2 = (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.p3 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800877
Wink Savillec0114b32011-02-18 10:14:07 -0800878 simIO.v6.data = strdupReadString(p);
879 simIO.v6.pin2 = strdupReadString(p);
880 simIO.v6.aidPtr = strdupReadString(p);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800881
882 startRequest;
Wink Savillec0114b32011-02-18 10:14:07 -0800883 appendPrintBuf("%scmd=0x%X,efid=0x%X,path=%s,%d,%d,%d,%s,pin2=%s,aid=%s", printBuf,
884 simIO.v6.command, simIO.v6.fileid, (char*)simIO.v6.path,
885 simIO.v6.p1, simIO.v6.p2, simIO.v6.p3,
886 (char*)simIO.v6.data, (char*)simIO.v6.pin2, simIO.v6.aidPtr);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800887 closeRequest;
888 printRequest(pRI->token, pRI->pCI->requestNumber);
Wink Saville7f856802009-06-09 10:23:37 -0700889
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800890 if (status != NO_ERROR) {
891 goto invalid;
892 }
893
Wink Savillec0114b32011-02-18 10:14:07 -0800894 size = (s_callbacks.version < 6) ? sizeof(simIO.v5) : sizeof(simIO.v6);
Etan Cohend3652192014-06-20 08:28:44 -0700895 CALL_ONREQUEST(pRI->pCI->requestNumber, &simIO, size, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800896
897#ifdef MEMSET_FREED
Wink Savillec0114b32011-02-18 10:14:07 -0800898 memsetString (simIO.v6.path);
899 memsetString (simIO.v6.data);
900 memsetString (simIO.v6.pin2);
901 memsetString (simIO.v6.aidPtr);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800902#endif
903
Wink Savillec0114b32011-02-18 10:14:07 -0800904 free (simIO.v6.path);
905 free (simIO.v6.data);
906 free (simIO.v6.pin2);
907 free (simIO.v6.aidPtr);
Wink Saville7f856802009-06-09 10:23:37 -0700908
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800909#ifdef MEMSET_FREED
910 memset(&simIO, 0, sizeof(simIO));
911#endif
912
913 return;
914invalid:
915 invalidCommandBlock(pRI);
916 return;
917}
918
919/**
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800920 * Callee expects const RIL_SIM_APDU *
921 * Payload is:
922 * int32_t sessionid
923 * int32_t cla
924 * int32_t instruction
925 * int32_t p1, p2, p3
926 * String data
927 */
928static void
929dispatchSIM_APDU (Parcel &p, RequestInfo *pRI) {
930 int32_t t;
931 status_t status;
932 RIL_SIM_APDU apdu;
933
934 memset (&apdu, 0, sizeof(RIL_SIM_APDU));
935
936 // Note we only check status at the end. Any single failure leads to
937 // subsequent reads filing.
938 status = p.readInt32(&t);
939 apdu.sessionid = (int)t;
940
941 status = p.readInt32(&t);
942 apdu.cla = (int)t;
943
944 status = p.readInt32(&t);
945 apdu.instruction = (int)t;
946
947 status = p.readInt32(&t);
948 apdu.p1 = (int)t;
949
950 status = p.readInt32(&t);
951 apdu.p2 = (int)t;
952
953 status = p.readInt32(&t);
954 apdu.p3 = (int)t;
955
956 apdu.data = strdupReadString(p);
957
958 startRequest;
959 appendPrintBuf("%ssessionid=%d,cla=%d,ins=%d,p1=%d,p2=%d,p3=%d,data=%s",
960 printBuf, apdu.sessionid, apdu.cla, apdu.instruction, apdu.p1, apdu.p2,
961 apdu.p3, (char*)apdu.data);
962 closeRequest;
963 printRequest(pRI->token, pRI->pCI->requestNumber);
964
965 if (status != NO_ERROR) {
966 goto invalid;
967 }
968
Etan Cohend3652192014-06-20 08:28:44 -0700969 CALL_ONREQUEST(pRI->pCI->requestNumber, &apdu, sizeof(RIL_SIM_APDU), pRI, pRI->socket_id);
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800970
971#ifdef MEMSET_FREED
972 memsetString(apdu.data);
973#endif
974 free(apdu.data);
975
976#ifdef MEMSET_FREED
977 memset(&apdu, 0, sizeof(RIL_SIM_APDU));
978#endif
979
980 return;
981invalid:
982 invalidCommandBlock(pRI);
983 return;
984}
985
986
987/**
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800988 * Callee expects const RIL_CallForwardInfo *
989 * Payload is:
990 * int32_t status/action
991 * int32_t reason
992 * int32_t serviceCode
993 * int32_t toa
994 * String number (0 length -> null)
995 * int32_t timeSeconds
996 */
Wink Saville7f856802009-06-09 10:23:37 -0700997static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700998dispatchCallForward(Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800999 RIL_CallForwardInfo cff;
1000 int32_t t;
1001 status_t status;
1002
1003 memset (&cff, 0, sizeof(cff));
1004
Wink Saville7f856802009-06-09 10:23:37 -07001005 // note we only check status at the end
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001006
1007 status = p.readInt32(&t);
1008 cff.status = (int)t;
Wink Saville7f856802009-06-09 10:23:37 -07001009
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001010 status = p.readInt32(&t);
1011 cff.reason = (int)t;
1012
1013 status = p.readInt32(&t);
1014 cff.serviceClass = (int)t;
1015
1016 status = p.readInt32(&t);
1017 cff.toa = (int)t;
1018
1019 cff.number = strdupReadString(p);
1020
1021 status = p.readInt32(&t);
1022 cff.timeSeconds = (int)t;
1023
1024 if (status != NO_ERROR) {
1025 goto invalid;
1026 }
1027
1028 // special case: number 0-length fields is null
1029
1030 if (cff.number != NULL && strlen (cff.number) == 0) {
1031 cff.number = NULL;
1032 }
1033
1034 startRequest;
1035 appendPrintBuf("%sstat=%d,reason=%d,serv=%d,toa=%d,%s,tout=%d", printBuf,
1036 cff.status, cff.reason, cff.serviceClass, cff.toa,
1037 (char*)cff.number, cff.timeSeconds);
1038 closeRequest;
1039 printRequest(pRI->token, pRI->pCI->requestNumber);
1040
Etan Cohend3652192014-06-20 08:28:44 -07001041 CALL_ONREQUEST(pRI->pCI->requestNumber, &cff, sizeof(cff), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001042
1043#ifdef MEMSET_FREED
1044 memsetString(cff.number);
1045#endif
1046
1047 free (cff.number);
1048
1049#ifdef MEMSET_FREED
1050 memset(&cff, 0, sizeof(cff));
1051#endif
1052
1053 return;
1054invalid:
1055 invalidCommandBlock(pRI);
1056 return;
1057}
1058
1059
Wink Saville7f856802009-06-09 10:23:37 -07001060static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001061dispatchRaw(Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001062 int32_t len;
1063 status_t status;
1064 const void *data;
1065
1066 status = p.readInt32(&len);
1067
1068 if (status != NO_ERROR) {
1069 goto invalid;
1070 }
1071
1072 // The java code writes -1 for null arrays
1073 if (((int)len) == -1) {
1074 data = NULL;
1075 len = 0;
Wink Saville7f856802009-06-09 10:23:37 -07001076 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001077
1078 data = p.readInplace(len);
1079
1080 startRequest;
1081 appendPrintBuf("%sraw_size=%d", printBuf, len);
1082 closeRequest;
1083 printRequest(pRI->token, pRI->pCI->requestNumber);
1084
Etan Cohend3652192014-06-20 08:28:44 -07001085 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<void *>(data), len, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001086
1087 return;
1088invalid:
1089 invalidCommandBlock(pRI);
1090 return;
1091}
1092
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001093static status_t
1094constructCdmaSms(Parcel &p, RequestInfo *pRI, RIL_CDMA_SMS_Message& rcsm) {
Wink Savillef4c4d362009-04-02 01:37:03 -07001095 int32_t t;
1096 uint8_t ut;
1097 status_t status;
1098 int32_t digitCount;
1099 int digitLimit;
Wink Saville7f856802009-06-09 10:23:37 -07001100
Wink Savillef4c4d362009-04-02 01:37:03 -07001101 memset(&rcsm, 0, sizeof(rcsm));
1102
1103 status = p.readInt32(&t);
1104 rcsm.uTeleserviceID = (int) t;
1105
1106 status = p.read(&ut,sizeof(ut));
1107 rcsm.bIsServicePresent = (uint8_t) ut;
1108
1109 status = p.readInt32(&t);
1110 rcsm.uServicecategory = (int) t;
1111
1112 status = p.readInt32(&t);
1113 rcsm.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1114
1115 status = p.readInt32(&t);
1116 rcsm.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1117
1118 status = p.readInt32(&t);
1119 rcsm.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1120
1121 status = p.readInt32(&t);
1122 rcsm.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1123
1124 status = p.read(&ut,sizeof(ut));
1125 rcsm.sAddress.number_of_digits= (uint8_t) ut;
1126
1127 digitLimit= MIN((rcsm.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
1128 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1129 status = p.read(&ut,sizeof(ut));
1130 rcsm.sAddress.digits[digitCount] = (uint8_t) ut;
1131 }
1132
Wink Saville7f856802009-06-09 10:23:37 -07001133 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001134 rcsm.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1135
Wink Saville7f856802009-06-09 10:23:37 -07001136 status = p.read(&ut,sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001137 rcsm.sSubAddress.odd = (uint8_t) ut;
1138
1139 status = p.read(&ut,sizeof(ut));
1140 rcsm.sSubAddress.number_of_digits = (uint8_t) ut;
1141
1142 digitLimit= MIN((rcsm.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
Wink Saville7f856802009-06-09 10:23:37 -07001143 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1144 status = p.read(&ut,sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001145 rcsm.sSubAddress.digits[digitCount] = (uint8_t) ut;
1146 }
1147
Wink Saville7f856802009-06-09 10:23:37 -07001148 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001149 rcsm.uBearerDataLen = (int) t;
1150
1151 digitLimit= MIN((rcsm.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
Wink Saville7f856802009-06-09 10:23:37 -07001152 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1153 status = p.read(&ut, sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001154 rcsm.aBearerData[digitCount] = (uint8_t) ut;
1155 }
1156
1157 if (status != NO_ERROR) {
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001158 return status;
Wink Savillef4c4d362009-04-02 01:37:03 -07001159 }
1160
1161 startRequest;
1162 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
Wink Saville1b5fd232009-04-22 14:50:00 -07001163 sAddress.digit_mode=%d, sAddress.Number_mode=%d, sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07001164 printBuf, rcsm.uTeleserviceID,rcsm.bIsServicePresent,rcsm.uServicecategory,
Wink Saville1b5fd232009-04-22 14:50:00 -07001165 rcsm.sAddress.digit_mode, rcsm.sAddress.number_mode,rcsm.sAddress.number_type);
Wink Savillef4c4d362009-04-02 01:37:03 -07001166 closeRequest;
Wink Saville7f856802009-06-09 10:23:37 -07001167
Wink Savillef4c4d362009-04-02 01:37:03 -07001168 printRequest(pRI->token, pRI->pCI->requestNumber);
1169
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001170 return status;
1171}
1172
1173static void
1174dispatchCdmaSms(Parcel &p, RequestInfo *pRI) {
1175 RIL_CDMA_SMS_Message rcsm;
1176
1177 ALOGD("dispatchCdmaSms");
1178 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1179 goto invalid;
1180 }
1181
Etan Cohend3652192014-06-20 08:28:44 -07001182 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001183
1184#ifdef MEMSET_FREED
1185 memset(&rcsm, 0, sizeof(rcsm));
1186#endif
1187
1188 return;
1189
1190invalid:
1191 invalidCommandBlock(pRI);
1192 return;
1193}
1194
Wink Saville7f856802009-06-09 10:23:37 -07001195static void
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001196dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1197 RIL_IMS_SMS_Message rism;
1198 RIL_CDMA_SMS_Message rcsm;
1199
1200 ALOGD("dispatchImsCdmaSms: retry=%d, messageRef=%d", retry, messageRef);
1201
1202 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1203 goto invalid;
1204 }
1205 memset(&rism, 0, sizeof(rism));
1206 rism.tech = RADIO_TECH_3GPP2;
1207 rism.retry = retry;
1208 rism.messageRef = messageRef;
1209 rism.message.cdmaMessage = &rcsm;
1210
Etan Cohend3652192014-06-20 08:28:44 -07001211 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001212 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Etan Cohend3652192014-06-20 08:28:44 -07001213 +sizeof(rcsm),pRI, pRI->socket_id);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001214
1215#ifdef MEMSET_FREED
1216 memset(&rcsm, 0, sizeof(rcsm));
1217 memset(&rism, 0, sizeof(rism));
1218#endif
1219
1220 return;
1221
1222invalid:
1223 invalidCommandBlock(pRI);
1224 return;
1225}
1226
1227static void
1228dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1229 RIL_IMS_SMS_Message rism;
1230 int32_t countStrings;
1231 status_t status;
1232 size_t datalen;
1233 char **pStrings;
1234 ALOGD("dispatchImsGsmSms: retry=%d, messageRef=%d", retry, messageRef);
1235
1236 status = p.readInt32 (&countStrings);
1237
1238 if (status != NO_ERROR) {
1239 goto invalid;
1240 }
1241
1242 memset(&rism, 0, sizeof(rism));
1243 rism.tech = RADIO_TECH_3GPP;
1244 rism.retry = retry;
1245 rism.messageRef = messageRef;
1246
1247 startRequest;
Etan Cohen5d891b72014-02-27 17:25:17 -08001248 appendPrintBuf("%stech=%d, retry=%d, messageRef=%d, ", printBuf,
1249 (int)rism.tech, (int)rism.retry, rism.messageRef);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001250 if (countStrings == 0) {
1251 // just some non-null pointer
1252 pStrings = (char **)alloca(sizeof(char *));
1253 datalen = 0;
1254 } else if (((int)countStrings) == -1) {
1255 pStrings = NULL;
1256 datalen = 0;
1257 } else {
1258 datalen = sizeof(char *) * countStrings;
1259
1260 pStrings = (char **)alloca(datalen);
1261
1262 for (int i = 0 ; i < countStrings ; i++) {
1263 pStrings[i] = strdupReadString(p);
1264 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
1265 }
1266 }
1267 removeLastChar;
1268 closeRequest;
1269 printRequest(pRI->token, pRI->pCI->requestNumber);
1270
1271 rism.message.gsmMessage = pStrings;
Etan Cohend3652192014-06-20 08:28:44 -07001272 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001273 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Etan Cohend3652192014-06-20 08:28:44 -07001274 +datalen, pRI, pRI->socket_id);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001275
1276 if (pStrings != NULL) {
1277 for (int i = 0 ; i < countStrings ; i++) {
1278#ifdef MEMSET_FREED
1279 memsetString (pStrings[i]);
1280#endif
1281 free(pStrings[i]);
1282 }
1283
1284#ifdef MEMSET_FREED
1285 memset(pStrings, 0, datalen);
1286#endif
1287 }
1288
1289#ifdef MEMSET_FREED
1290 memset(&rism, 0, sizeof(rism));
1291#endif
1292 return;
1293invalid:
1294 ALOGE("dispatchImsGsmSms invalid block");
1295 invalidCommandBlock(pRI);
1296 return;
1297}
1298
1299static void
1300dispatchImsSms(Parcel &p, RequestInfo *pRI) {
1301 int32_t t;
1302 status_t status = p.readInt32(&t);
1303 RIL_RadioTechnologyFamily format;
1304 uint8_t retry;
1305 int32_t messageRef;
1306
1307 ALOGD("dispatchImsSms");
1308 if (status != NO_ERROR) {
1309 goto invalid;
1310 }
1311 format = (RIL_RadioTechnologyFamily) t;
1312
1313 // read retry field
1314 status = p.read(&retry,sizeof(retry));
1315 if (status != NO_ERROR) {
1316 goto invalid;
1317 }
1318 // read messageRef field
1319 status = p.read(&messageRef,sizeof(messageRef));
1320 if (status != NO_ERROR) {
1321 goto invalid;
1322 }
1323
1324 if (RADIO_TECH_3GPP == format) {
1325 dispatchImsGsmSms(p, pRI, retry, messageRef);
1326 } else if (RADIO_TECH_3GPP2 == format) {
1327 dispatchImsCdmaSms(p, pRI, retry, messageRef);
1328 } else {
1329 ALOGE("requestImsSendSMS invalid format value =%d", format);
1330 }
1331
1332 return;
1333
1334invalid:
1335 invalidCommandBlock(pRI);
1336 return;
1337}
1338
1339static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001340dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI) {
1341 RIL_CDMA_SMS_Ack rcsa;
1342 int32_t t;
1343 status_t status;
1344 int32_t digitCount;
1345
1346 memset(&rcsa, 0, sizeof(rcsa));
1347
1348 status = p.readInt32(&t);
1349 rcsa.uErrorClass = (RIL_CDMA_SMS_ErrorClass) t;
1350
1351 status = p.readInt32(&t);
1352 rcsa.uSMSCauseCode = (int) t;
1353
1354 if (status != NO_ERROR) {
1355 goto invalid;
1356 }
1357
1358 startRequest;
Wink Saville1b5fd232009-04-22 14:50:00 -07001359 appendPrintBuf("%suErrorClass=%d, uTLStatus=%d, ",
1360 printBuf, rcsa.uErrorClass, rcsa.uSMSCauseCode);
Wink Savillef4c4d362009-04-02 01:37:03 -07001361 closeRequest;
1362
1363 printRequest(pRI->token, pRI->pCI->requestNumber);
1364
Etan Cohend3652192014-06-20 08:28:44 -07001365 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsa, sizeof(rcsa),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001366
1367#ifdef MEMSET_FREED
1368 memset(&rcsa, 0, sizeof(rcsa));
1369#endif
1370
1371 return;
1372
1373invalid:
1374 invalidCommandBlock(pRI);
1375 return;
1376}
1377
Wink Savillea592eeb2009-05-22 13:26:36 -07001378static void
1379dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1380 int32_t t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001381 status_t status;
Wink Savillea592eeb2009-05-22 13:26:36 -07001382 int32_t num;
Wink Savillef4c4d362009-04-02 01:37:03 -07001383
Wink Savillea592eeb2009-05-22 13:26:36 -07001384 status = p.readInt32(&num);
Wink Savillef4c4d362009-04-02 01:37:03 -07001385 if (status != NO_ERROR) {
1386 goto invalid;
1387 }
1388
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001389 {
1390 RIL_GSM_BroadcastSmsConfigInfo gsmBci[num];
1391 RIL_GSM_BroadcastSmsConfigInfo *gsmBciPtrs[num];
Wink Savillea592eeb2009-05-22 13:26:36 -07001392
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001393 startRequest;
1394 for (int i = 0 ; i < num ; i++ ) {
1395 gsmBciPtrs[i] = &gsmBci[i];
Wink Savillef4c4d362009-04-02 01:37:03 -07001396
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001397 status = p.readInt32(&t);
1398 gsmBci[i].fromServiceId = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001399
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001400 status = p.readInt32(&t);
1401 gsmBci[i].toServiceId = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001402
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001403 status = p.readInt32(&t);
1404 gsmBci[i].fromCodeScheme = (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].toCodeScheme = (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].selected = (uint8_t) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001411
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001412 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId =%d, \
1413 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]", printBuf, i,
1414 gsmBci[i].fromServiceId, gsmBci[i].toServiceId,
1415 gsmBci[i].fromCodeScheme, gsmBci[i].toCodeScheme,
1416 gsmBci[i].selected);
1417 }
1418 closeRequest;
Wink Savillef4c4d362009-04-02 01:37:03 -07001419
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001420 if (status != NO_ERROR) {
1421 goto invalid;
1422 }
Wink Savillef4c4d362009-04-02 01:37:03 -07001423
Etan Cohend3652192014-06-20 08:28:44 -07001424 CALL_ONREQUEST(pRI->pCI->requestNumber,
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001425 gsmBciPtrs,
1426 num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *),
Etan Cohend3652192014-06-20 08:28:44 -07001427 pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001428
1429#ifdef MEMSET_FREED
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001430 memset(gsmBci, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo));
1431 memset(gsmBciPtrs, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *));
Wink Savillef4c4d362009-04-02 01:37:03 -07001432#endif
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001433 }
Wink Savillef4c4d362009-04-02 01:37:03 -07001434
1435 return;
1436
1437invalid:
1438 invalidCommandBlock(pRI);
1439 return;
Wink Savillea592eeb2009-05-22 13:26:36 -07001440}
Wink Savillef4c4d362009-04-02 01:37:03 -07001441
Wink Savillea592eeb2009-05-22 13:26:36 -07001442static void
1443dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1444 int32_t t;
1445 status_t status;
1446 int32_t num;
1447
1448 status = p.readInt32(&num);
1449 if (status != NO_ERROR) {
1450 goto invalid;
1451 }
1452
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001453 {
1454 RIL_CDMA_BroadcastSmsConfigInfo cdmaBci[num];
1455 RIL_CDMA_BroadcastSmsConfigInfo *cdmaBciPtrs[num];
Wink Savillea592eeb2009-05-22 13:26:36 -07001456
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001457 startRequest;
1458 for (int i = 0 ; i < num ; i++ ) {
1459 cdmaBciPtrs[i] = &cdmaBci[i];
Wink Savillea592eeb2009-05-22 13:26:36 -07001460
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001461 status = p.readInt32(&t);
1462 cdmaBci[i].service_category = (int) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001463
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001464 status = p.readInt32(&t);
1465 cdmaBci[i].language = (int) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001466
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001467 status = p.readInt32(&t);
1468 cdmaBci[i].selected = (uint8_t) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001469
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001470 appendPrintBuf("%s [%d: service_category=%d, language =%d, \
1471 entries.bSelected =%d]", printBuf, i, cdmaBci[i].service_category,
1472 cdmaBci[i].language, cdmaBci[i].selected);
1473 }
1474 closeRequest;
Wink Savillea592eeb2009-05-22 13:26:36 -07001475
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001476 if (status != NO_ERROR) {
1477 goto invalid;
1478 }
Wink Savillea592eeb2009-05-22 13:26:36 -07001479
Etan Cohend3652192014-06-20 08:28:44 -07001480 CALL_ONREQUEST(pRI->pCI->requestNumber,
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001481 cdmaBciPtrs,
1482 num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *),
Etan Cohend3652192014-06-20 08:28:44 -07001483 pRI, pRI->socket_id);
Wink Savillea592eeb2009-05-22 13:26:36 -07001484
1485#ifdef MEMSET_FREED
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001486 memset(cdmaBci, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo));
1487 memset(cdmaBciPtrs, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *));
Wink Savillea592eeb2009-05-22 13:26:36 -07001488#endif
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001489 }
Wink Savillea592eeb2009-05-22 13:26:36 -07001490
1491 return;
1492
1493invalid:
1494 invalidCommandBlock(pRI);
1495 return;
Wink Savillef4c4d362009-04-02 01:37:03 -07001496}
1497
1498static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI) {
1499 RIL_CDMA_SMS_WriteArgs rcsw;
1500 int32_t t;
1501 uint32_t ut;
1502 uint8_t uct;
1503 status_t status;
1504 int32_t digitCount;
1505
1506 memset(&rcsw, 0, sizeof(rcsw));
1507
1508 status = p.readInt32(&t);
1509 rcsw.status = t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001510
Wink Savillef4c4d362009-04-02 01:37:03 -07001511 status = p.readInt32(&t);
1512 rcsw.message.uTeleserviceID = (int) t;
1513
1514 status = p.read(&uct,sizeof(uct));
1515 rcsw.message.bIsServicePresent = (uint8_t) uct;
1516
1517 status = p.readInt32(&t);
1518 rcsw.message.uServicecategory = (int) t;
1519
1520 status = p.readInt32(&t);
1521 rcsw.message.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1522
1523 status = p.readInt32(&t);
1524 rcsw.message.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1525
1526 status = p.readInt32(&t);
1527 rcsw.message.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1528
1529 status = p.readInt32(&t);
1530 rcsw.message.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1531
1532 status = p.read(&uct,sizeof(uct));
1533 rcsw.message.sAddress.number_of_digits = (uint8_t) uct;
1534
1535 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_ADDRESS_MAX; digitCount ++) {
1536 status = p.read(&uct,sizeof(uct));
1537 rcsw.message.sAddress.digits[digitCount] = (uint8_t) uct;
1538 }
1539
Wink Savillea592eeb2009-05-22 13:26:36 -07001540 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001541 rcsw.message.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1542
Wink Savillea592eeb2009-05-22 13:26:36 -07001543 status = p.read(&uct,sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001544 rcsw.message.sSubAddress.odd = (uint8_t) uct;
1545
1546 status = p.read(&uct,sizeof(uct));
1547 rcsw.message.sSubAddress.number_of_digits = (uint8_t) uct;
1548
1549 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_SUBADDRESS_MAX; digitCount ++) {
Wink Savillea592eeb2009-05-22 13:26:36 -07001550 status = p.read(&uct,sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001551 rcsw.message.sSubAddress.digits[digitCount] = (uint8_t) uct;
1552 }
1553
Wink Savillea592eeb2009-05-22 13:26:36 -07001554 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001555 rcsw.message.uBearerDataLen = (int) t;
1556
1557 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_BEARER_DATA_MAX; digitCount ++) {
Wink Savillea592eeb2009-05-22 13:26:36 -07001558 status = p.read(&uct, sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001559 rcsw.message.aBearerData[digitCount] = (uint8_t) uct;
1560 }
1561
1562 if (status != NO_ERROR) {
1563 goto invalid;
1564 }
1565
1566 startRequest;
Wink Saville1b5fd232009-04-22 14:50:00 -07001567 appendPrintBuf("%sstatus=%d, message.uTeleserviceID=%d, message.bIsServicePresent=%d, \
1568 message.uServicecategory=%d, message.sAddress.digit_mode=%d, \
1569 message.sAddress.number_mode=%d, \
1570 message.sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07001571 printBuf, rcsw.status, rcsw.message.uTeleserviceID, rcsw.message.bIsServicePresent,
Wink Saville1b5fd232009-04-22 14:50:00 -07001572 rcsw.message.uServicecategory, rcsw.message.sAddress.digit_mode,
1573 rcsw.message.sAddress.number_mode,
1574 rcsw.message.sAddress.number_type);
Wink Savillef4c4d362009-04-02 01:37:03 -07001575 closeRequest;
1576
1577 printRequest(pRI->token, pRI->pCI->requestNumber);
1578
Etan Cohend3652192014-06-20 08:28:44 -07001579 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsw, sizeof(rcsw),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001580
1581#ifdef MEMSET_FREED
1582 memset(&rcsw, 0, sizeof(rcsw));
1583#endif
1584
1585 return;
1586
1587invalid:
1588 invalidCommandBlock(pRI);
1589 return;
1590
1591}
1592
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -07001593// For backwards compatibility in RIL_REQUEST_SETUP_DATA_CALL.
1594// Version 4 of the RIL interface adds a new PDP type parameter to support
1595// IPv6 and dual-stack PDP contexts. When dealing with a previous version of
1596// RIL, remove the parameter from the request.
1597static void dispatchDataCall(Parcel& p, RequestInfo *pRI) {
1598 // In RIL v3, REQUEST_SETUP_DATA_CALL takes 6 parameters.
1599 const int numParamsRilV3 = 6;
1600
1601 // The first bytes of the RIL parcel contain the request number and the
1602 // serial number - see processCommandBuffer(). Copy them over too.
1603 int pos = p.dataPosition();
1604
1605 int numParams = p.readInt32();
1606 if (s_callbacks.version < 4 && numParams > numParamsRilV3) {
1607 Parcel p2;
1608 p2.appendFrom(&p, 0, pos);
1609 p2.writeInt32(numParamsRilV3);
1610 for(int i = 0; i < numParamsRilV3; i++) {
1611 p2.writeString16(p.readString16());
1612 }
1613 p2.setDataPosition(pos);
1614 dispatchStrings(p2, pRI);
1615 } else {
Lorenzo Colitti57ce1f22010-09-13 12:23:50 -07001616 p.setDataPosition(pos);
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -07001617 dispatchStrings(p, pRI);
1618 }
1619}
1620
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001621// For backwards compatibility with RILs that dont support RIL_REQUEST_VOICE_RADIO_TECH.
1622// When all RILs handle this request, this function can be removed and
1623// the request can be sent directly to the RIL using dispatchVoid.
1624static void dispatchVoiceRadioTech(Parcel& p, RequestInfo *pRI) {
Etan Cohend3652192014-06-20 08:28:44 -07001625 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001626
1627 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1628 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1629 }
1630
1631 // RILs that support RADIO_STATE_ON should support this request.
1632 if (RADIO_STATE_ON == state) {
1633 dispatchVoid(p, pRI);
1634 return;
1635 }
1636
1637 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1638 // will not support this new request either and decode Voice Radio Technology
1639 // from Radio State
1640 voiceRadioTech = decodeVoiceRadioTechnology(state);
1641
1642 if (voiceRadioTech < 0)
1643 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1644 else
1645 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &voiceRadioTech, sizeof(int));
1646}
1647
1648// For backwards compatibility in RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE:.
1649// When all RILs handle this request, this function can be removed and
1650// the request can be sent directly to the RIL using dispatchVoid.
1651static void dispatchCdmaSubscriptionSource(Parcel& p, RequestInfo *pRI) {
Etan Cohend3652192014-06-20 08:28:44 -07001652 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001653
1654 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1655 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1656 }
1657
1658 // RILs that support RADIO_STATE_ON should support this request.
1659 if (RADIO_STATE_ON == state) {
1660 dispatchVoid(p, pRI);
1661 return;
1662 }
1663
1664 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1665 // will not support this new request either and decode CDMA Subscription Source
1666 // from Radio State
1667 cdmaSubscriptionSource = decodeCdmaSubscriptionSource(state);
1668
1669 if (cdmaSubscriptionSource < 0)
1670 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1671 else
1672 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &cdmaSubscriptionSource, sizeof(int));
1673}
1674
Sungmin Choi75697532013-04-26 15:04:45 -07001675static void dispatchSetInitialAttachApn(Parcel &p, RequestInfo *pRI)
1676{
1677 RIL_InitialAttachApn pf;
1678 int32_t t;
1679 status_t status;
1680
1681 memset(&pf, 0, sizeof(pf));
1682
1683 pf.apn = strdupReadString(p);
1684 pf.protocol = strdupReadString(p);
1685
1686 status = p.readInt32(&t);
1687 pf.authtype = (int) t;
1688
1689 pf.username = strdupReadString(p);
1690 pf.password = strdupReadString(p);
1691
1692 startRequest;
Etan Cohen5d891b72014-02-27 17:25:17 -08001693 appendPrintBuf("%sapn=%s, protocol=%s, authtype=%d, username=%s, password=%s",
1694 printBuf, pf.apn, pf.protocol, pf.authtype, pf.username, pf.password);
Sungmin Choi75697532013-04-26 15:04:45 -07001695 closeRequest;
1696 printRequest(pRI->token, pRI->pCI->requestNumber);
1697
1698 if (status != NO_ERROR) {
1699 goto invalid;
1700 }
Etan Cohend3652192014-06-20 08:28:44 -07001701 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
Sungmin Choi75697532013-04-26 15:04:45 -07001702
1703#ifdef MEMSET_FREED
1704 memsetString(pf.apn);
1705 memsetString(pf.protocol);
1706 memsetString(pf.username);
1707 memsetString(pf.password);
1708#endif
1709
1710 free(pf.apn);
1711 free(pf.protocol);
1712 free(pf.username);
1713 free(pf.password);
1714
1715#ifdef MEMSET_FREED
1716 memset(&pf, 0, sizeof(pf));
1717#endif
1718
1719 return;
1720invalid:
1721 invalidCommandBlock(pRI);
1722 return;
1723}
1724
Jake Hamby8a4a2332014-01-15 13:12:05 -08001725static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI) {
1726 RIL_NV_ReadItem nvri;
1727 int32_t t;
1728 status_t status;
1729
1730 memset(&nvri, 0, sizeof(nvri));
1731
1732 status = p.readInt32(&t);
1733 nvri.itemID = (RIL_NV_Item) t;
1734
1735 if (status != NO_ERROR) {
1736 goto invalid;
1737 }
1738
1739 startRequest;
1740 appendPrintBuf("%snvri.itemID=%d, ", printBuf, nvri.itemID);
1741 closeRequest;
1742
1743 printRequest(pRI->token, pRI->pCI->requestNumber);
1744
Etan Cohend3652192014-06-20 08:28:44 -07001745 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvri, sizeof(nvri), pRI, pRI->socket_id);
Jake Hamby8a4a2332014-01-15 13:12:05 -08001746
1747#ifdef MEMSET_FREED
1748 memset(&nvri, 0, sizeof(nvri));
1749#endif
1750
1751 return;
1752
1753invalid:
1754 invalidCommandBlock(pRI);
1755 return;
1756}
1757
1758static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI) {
1759 RIL_NV_WriteItem nvwi;
1760 int32_t t;
1761 status_t status;
1762
1763 memset(&nvwi, 0, sizeof(nvwi));
1764
1765 status = p.readInt32(&t);
1766 nvwi.itemID = (RIL_NV_Item) t;
1767
1768 nvwi.value = strdupReadString(p);
1769
1770 if (status != NO_ERROR || nvwi.value == NULL) {
1771 goto invalid;
1772 }
1773
1774 startRequest;
1775 appendPrintBuf("%snvwi.itemID=%d, value=%s, ", printBuf, nvwi.itemID,
1776 nvwi.value);
1777 closeRequest;
1778
1779 printRequest(pRI->token, pRI->pCI->requestNumber);
1780
Etan Cohend3652192014-06-20 08:28:44 -07001781 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvwi, sizeof(nvwi), pRI, pRI->socket_id);
Jake Hamby8a4a2332014-01-15 13:12:05 -08001782
1783#ifdef MEMSET_FREED
1784 memsetString(nvwi.value);
1785#endif
1786
1787 free(nvwi.value);
1788
1789#ifdef MEMSET_FREED
1790 memset(&nvwi, 0, sizeof(nvwi));
1791#endif
1792
1793 return;
1794
1795invalid:
1796 invalidCommandBlock(pRI);
1797 return;
1798}
1799
1800
Etan Cohend3652192014-06-20 08:28:44 -07001801static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI) {
1802 RIL_SelectUiccSub uicc_sub;
1803 status_t status;
1804 int32_t t;
1805 memset(&uicc_sub, 0, sizeof(uicc_sub));
1806
1807 status = p.readInt32(&t);
1808 if (status != NO_ERROR) {
1809 goto invalid;
1810 }
1811 uicc_sub.slot = (int) t;
1812
1813 status = p.readInt32(&t);
1814 if (status != NO_ERROR) {
1815 goto invalid;
1816 }
1817 uicc_sub.app_index = (int) t;
1818
1819 status = p.readInt32(&t);
1820 if (status != NO_ERROR) {
1821 goto invalid;
1822 }
1823 uicc_sub.sub_type = (RIL_SubscriptionType) t;
1824
1825 status = p.readInt32(&t);
1826 if (status != NO_ERROR) {
1827 goto invalid;
1828 }
1829 uicc_sub.act_status = (RIL_UiccSubActStatus) t;
1830
1831 startRequest;
1832 appendPrintBuf("slot=%d, app_index=%d, act_status = %d", uicc_sub.slot, uicc_sub.app_index,
1833 uicc_sub.act_status);
1834 RLOGD("dispatchUiccSubscription, slot=%d, app_index=%d, act_status = %d", uicc_sub.slot,
1835 uicc_sub.app_index, uicc_sub.act_status);
1836 closeRequest;
1837 printRequest(pRI->token, pRI->pCI->requestNumber);
1838
1839 CALL_ONREQUEST(pRI->pCI->requestNumber, &uicc_sub, sizeof(uicc_sub), pRI, pRI->socket_id);
1840
1841#ifdef MEMSET_FREED
1842 memset(&uicc_sub, 0, sizeof(uicc_sub));
1843#endif
1844 return;
1845
1846invalid:
1847 invalidCommandBlock(pRI);
1848 return;
1849}
1850
Amit Mahajan90530a62014-07-01 15:54:08 -07001851static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI)
1852{
1853 RIL_SimAuthentication pf;
1854 int32_t t;
1855 status_t status;
1856
1857 memset(&pf, 0, sizeof(pf));
1858
1859 status = p.readInt32(&t);
1860 pf.authContext = (int) t;
1861 pf.authData = strdupReadString(p);
1862 pf.aid = strdupReadString(p);
1863
1864 startRequest;
1865 appendPrintBuf("authContext=%s, authData=%s, aid=%s", pf.authContext, pf.authData, pf.aid);
1866 closeRequest;
1867 printRequest(pRI->token, pRI->pCI->requestNumber);
1868
1869 if (status != NO_ERROR) {
1870 goto invalid;
1871 }
1872 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
1873
1874#ifdef MEMSET_FREED
1875 memsetString(pf.authData);
1876 memsetString(pf.aid);
1877#endif
1878
1879 free(pf.authData);
1880 free(pf.aid);
1881
1882#ifdef MEMSET_FREED
1883 memset(&pf, 0, sizeof(pf));
1884#endif
1885
1886 return;
1887invalid:
1888 invalidCommandBlock(pRI);
1889 return;
1890}
1891
Amit Mahajanc796e222014-08-13 16:54:01 +00001892static void dispatchDataProfile(Parcel &p, RequestInfo *pRI) {
1893 int32_t t;
1894 status_t status;
1895 int32_t num;
1896
1897 status = p.readInt32(&num);
1898 if (status != NO_ERROR) {
1899 goto invalid;
1900 }
1901
1902 {
1903 RIL_DataProfileInfo dataProfiles[num];
1904 RIL_DataProfileInfo *dataProfilePtrs[num];
1905
1906 startRequest;
1907 for (int i = 0 ; i < num ; i++ ) {
1908 dataProfilePtrs[i] = &dataProfiles[i];
1909
1910 status = p.readInt32(&t);
1911 dataProfiles[i].profileId = (int) t;
1912
1913 dataProfiles[i].apn = strdupReadString(p);
1914 dataProfiles[i].protocol = strdupReadString(p);
1915 status = p.readInt32(&t);
1916 dataProfiles[i].authType = (int) t;
1917
1918 dataProfiles[i].user = strdupReadString(p);
1919 dataProfiles[i].password = strdupReadString(p);
1920
1921 status = p.readInt32(&t);
1922 dataProfiles[i].type = (int) t;
1923
1924 status = p.readInt32(&t);
1925 dataProfiles[i].maxConnsTime = (int) t;
1926 status = p.readInt32(&t);
1927 dataProfiles[i].maxConns = (int) t;
1928 status = p.readInt32(&t);
1929 dataProfiles[i].waitTime = (int) t;
1930
1931 status = p.readInt32(&t);
1932 dataProfiles[i].enabled = (int) t;
1933
1934 appendPrintBuf("%s [%d: profileId=%d, apn =%s, protocol =%s, authType =%d, \
1935 user =%s, password =%s, type =%d, maxConnsTime =%d, maxConns =%d, \
1936 waitTime =%d, enabled =%d]", printBuf, i, dataProfiles[i].profileId,
1937 dataProfiles[i].apn, dataProfiles[i].protocol, dataProfiles[i].authType,
1938 dataProfiles[i].user, dataProfiles[i].password, dataProfiles[i].type,
1939 dataProfiles[i].maxConnsTime, dataProfiles[i].maxConns,
1940 dataProfiles[i].waitTime, dataProfiles[i].enabled);
1941 }
1942 closeRequest;
1943 printRequest(pRI->token, pRI->pCI->requestNumber);
1944
1945 if (status != NO_ERROR) {
1946 goto invalid;
1947 }
1948 CALL_ONREQUEST(pRI->pCI->requestNumber,
1949 dataProfilePtrs,
1950 num * sizeof(RIL_DataProfileInfo *),
1951 pRI, pRI->socket_id);
1952
1953#ifdef MEMSET_FREED
1954 memset(dataProfiles, 0, num * sizeof(RIL_DataProfileInfo));
1955 memset(dataProfilePtrs, 0, num * sizeof(RIL_DataProfileInfo *));
1956#endif
1957 }
1958
1959 return;
1960
1961invalid:
1962 invalidCommandBlock(pRI);
1963 return;
1964}
1965
Wink Saville8b4e4f72014-10-17 15:01:45 -07001966static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI){
1967 RIL_RadioCapability rc;
1968 int32_t t;
1969 status_t status;
1970
1971 memset (&rc, 0, sizeof(RIL_RadioCapability));
1972
1973 status = p.readInt32(&t);
1974 rc.version = (int)t;
1975 if (status != NO_ERROR) {
1976 goto invalid;
1977 }
1978
1979 status = p.readInt32(&t);
1980 rc.session= (int)t;
1981 if (status != NO_ERROR) {
1982 goto invalid;
1983 }
1984
1985 status = p.readInt32(&t);
1986 rc.phase= (int)t;
1987 if (status != NO_ERROR) {
1988 goto invalid;
1989 }
1990
1991 status = p.readInt32(&t);
1992 rc.rat = (int)t;
1993 if (status != NO_ERROR) {
1994 goto invalid;
1995 }
1996
1997 status = readStringFromParcelInplace(p, rc.logicalModemUuid, sizeof(rc.logicalModemUuid));
1998 if (status != NO_ERROR) {
1999 goto invalid;
2000 }
2001
2002 status = p.readInt32(&t);
2003 rc.status = (int)t;
2004
2005 if (status != NO_ERROR) {
2006 goto invalid;
2007 }
2008
2009 startRequest;
2010 appendPrintBuf("%s [version:%d, session:%d, phase:%d, rat:%d, \
Legler Wu8caf06f2014-10-29 14:02:14 +08002011 logicalModemUuid:%s, status:%d", printBuf, rc.version, rc.session
2012 rc.phase, rc.rat, rc.logicalModemUuid, rc.session);
Wink Saville8b4e4f72014-10-17 15:01:45 -07002013
2014 closeRequest;
2015 printRequest(pRI->token, pRI->pCI->requestNumber);
2016
2017 CALL_ONREQUEST(pRI->pCI->requestNumber,
2018 &rc,
2019 sizeof(RIL_RadioCapability),
2020 pRI, pRI->socket_id);
2021 return;
2022invalid:
2023 invalidCommandBlock(pRI);
2024 return;
2025}
2026
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002027static int
Wink Savillef4c4d362009-04-02 01:37:03 -07002028blockingWrite(int fd, const void *buffer, size_t len) {
Wink Saville7f856802009-06-09 10:23:37 -07002029 size_t writeOffset = 0;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002030 const uint8_t *toWrite;
2031
2032 toWrite = (const uint8_t *)buffer;
2033
2034 while (writeOffset < len) {
2035 ssize_t written;
2036 do {
2037 written = write (fd, toWrite + writeOffset,
2038 len - writeOffset);
Banavathu, Srinivas Naik38884902011-07-05 20:04:25 +05302039 } while (written < 0 && ((errno == EINTR) || (errno == EAGAIN)));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002040
2041 if (written >= 0) {
2042 writeOffset += written;
2043 } else { // written < 0
Wink Saville8eb2a122012-11-19 16:05:13 -08002044 RLOGE ("RIL Response: unexpected error on write errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002045 close(fd);
2046 return -1;
2047 }
2048 }
Dheeraj Shetty27976c42014-07-02 21:27:57 +02002049 RLOGE("RIL Response bytes written:%d", writeOffset);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002050 return 0;
2051}
2052
2053static int
Etan Cohend3652192014-06-20 08:28:44 -07002054sendResponseRaw (const void *data, size_t dataSize, RIL_SOCKET_ID socket_id) {
2055 int fd = s_ril_param_socket.fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002056 int ret;
2057 uint32_t header;
Etan Cohend3652192014-06-20 08:28:44 -07002058 pthread_mutex_t * writeMutexHook = &s_writeMutex;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002059
Etan Cohend3652192014-06-20 08:28:44 -07002060 RLOGE("Send Response to %s", rilSocketIdToString(socket_id));
2061
2062#if (SIM_COUNT >= 2)
2063 if (socket_id == RIL_SOCKET_2) {
2064 fd = s_ril_param_socket2.fdCommand;
2065 writeMutexHook = &s_writeMutex_socket2;
2066 }
2067#if (SIM_COUNT >= 3)
2068 else if (socket_id == RIL_SOCKET_3) {
2069 fd = s_ril_param_socket3.fdCommand;
2070 writeMutexHook = &s_writeMutex_socket3;
2071 }
2072#endif
2073#if (SIM_COUNT >= 4)
2074 else if (socket_id == RIL_SOCKET_4) {
2075 fd = s_ril_param_socket4.fdCommand;
2076 writeMutexHook = &s_writeMutex_socket4;
2077 }
2078#endif
2079#endif
2080 if (fd < 0) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002081 return -1;
2082 }
2083
2084 if (dataSize > MAX_COMMAND_BYTES) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002085 RLOGE("RIL: packet larger than %u (%u)",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002086 MAX_COMMAND_BYTES, (unsigned int )dataSize);
2087
2088 return -1;
2089 }
Wink Saville7f856802009-06-09 10:23:37 -07002090
Etan Cohend3652192014-06-20 08:28:44 -07002091 pthread_mutex_lock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002092
2093 header = htonl(dataSize);
2094
2095 ret = blockingWrite(fd, (void *)&header, sizeof(header));
2096
2097 if (ret < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002098 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002099 return ret;
2100 }
2101
Kennyee1fadc2009-08-13 00:45:53 +08002102 ret = blockingWrite(fd, data, dataSize);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002103
2104 if (ret < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002105 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002106 return ret;
2107 }
2108
Etan Cohend3652192014-06-20 08:28:44 -07002109 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002110
2111 return 0;
2112}
2113
2114static int
Etan Cohend3652192014-06-20 08:28:44 -07002115sendResponse (Parcel &p, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002116 printResponse;
Etan Cohend3652192014-06-20 08:28:44 -07002117 return sendResponseRaw(p.data(), p.dataSize(), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002118}
2119
Mohamad Ayyash74f7e662014-04-18 11:43:28 -07002120/** response is an int* pointing to an array of ints */
Wink Saville7f856802009-06-09 10:23:37 -07002121
2122static int
Wink Savillef4c4d362009-04-02 01:37:03 -07002123responseInts(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002124 int numInts;
2125
2126 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002127 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002128 return RIL_ERRNO_INVALID_RESPONSE;
2129 }
2130 if (responselen % sizeof(int) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002131 RLOGE("responseInts: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002132 (int)responselen, (int)sizeof(int));
2133 return RIL_ERRNO_INVALID_RESPONSE;
2134 }
2135
2136 int *p_int = (int *) response;
2137
Mohamad Ayyash74f7e662014-04-18 11:43:28 -07002138 numInts = responselen / sizeof(int);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002139 p.writeInt32 (numInts);
2140
2141 /* each int*/
2142 startResponse;
2143 for (int i = 0 ; i < numInts ; i++) {
2144 appendPrintBuf("%s%d,", printBuf, p_int[i]);
2145 p.writeInt32(p_int[i]);
2146 }
2147 removeLastChar;
2148 closeResponse;
2149
2150 return 0;
2151}
2152
Wink Saville43808972011-01-13 17:39:51 -08002153/** response is a char **, pointing to an array of char *'s
2154 The parcel will begin with the version */
2155static int responseStringsWithVersion(int version, Parcel &p, void *response, size_t responselen) {
2156 p.writeInt32(version);
2157 return responseStrings(p, response, responselen);
2158}
2159
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002160/** response is a char **, pointing to an array of char *'s */
Wink Savillef4c4d362009-04-02 01:37:03 -07002161static int responseStrings(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002162 int numStrings;
Wink Saville7f856802009-06-09 10:23:37 -07002163
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002164 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002165 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002166 return RIL_ERRNO_INVALID_RESPONSE;
2167 }
2168 if (responselen % sizeof(char *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002169 RLOGE("responseStrings: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002170 (int)responselen, (int)sizeof(char *));
2171 return RIL_ERRNO_INVALID_RESPONSE;
2172 }
2173
2174 if (response == NULL) {
2175 p.writeInt32 (0);
2176 } else {
2177 char **p_cur = (char **) response;
2178
2179 numStrings = responselen / sizeof(char *);
2180 p.writeInt32 (numStrings);
2181
2182 /* each string*/
2183 startResponse;
2184 for (int i = 0 ; i < numStrings ; i++) {
2185 appendPrintBuf("%s%s,", printBuf, (char*)p_cur[i]);
2186 writeStringToParcel (p, p_cur[i]);
2187 }
2188 removeLastChar;
2189 closeResponse;
2190 }
2191 return 0;
2192}
2193
2194
2195/**
Wink Saville7f856802009-06-09 10:23:37 -07002196 * NULL strings are accepted
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002197 * FIXME currently ignores responselen
2198 */
Wink Savillef4c4d362009-04-02 01:37:03 -07002199static int responseString(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002200 /* one string only */
2201 startResponse;
2202 appendPrintBuf("%s%s", printBuf, (char*)response);
2203 closeResponse;
2204
2205 writeStringToParcel(p, (const char *)response);
2206
2207 return 0;
2208}
2209
Wink Savillef4c4d362009-04-02 01:37:03 -07002210static int responseVoid(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002211 startResponse;
2212 removeLastChar;
2213 return 0;
2214}
2215
Wink Savillef4c4d362009-04-02 01:37:03 -07002216static int responseCallList(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002217 int num;
2218
2219 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002220 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002221 return RIL_ERRNO_INVALID_RESPONSE;
2222 }
2223
2224 if (responselen % sizeof (RIL_Call *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002225 RLOGE("responseCallList: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002226 (int)responselen, (int)sizeof (RIL_Call *));
2227 return RIL_ERRNO_INVALID_RESPONSE;
2228 }
2229
2230 startResponse;
2231 /* number of call info's */
2232 num = responselen / sizeof(RIL_Call *);
2233 p.writeInt32(num);
2234
2235 for (int i = 0 ; i < num ; i++) {
2236 RIL_Call *p_cur = ((RIL_Call **) response)[i];
2237 /* each call info */
2238 p.writeInt32(p_cur->state);
2239 p.writeInt32(p_cur->index);
2240 p.writeInt32(p_cur->toa);
2241 p.writeInt32(p_cur->isMpty);
2242 p.writeInt32(p_cur->isMT);
2243 p.writeInt32(p_cur->als);
2244 p.writeInt32(p_cur->isVoice);
Wink Saville1b5fd232009-04-22 14:50:00 -07002245 p.writeInt32(p_cur->isVoicePrivacy);
2246 writeStringToParcel(p, p_cur->number);
John Wangff368742009-03-24 17:56:29 -07002247 p.writeInt32(p_cur->numberPresentation);
Wink Saville1b5fd232009-04-22 14:50:00 -07002248 writeStringToParcel(p, p_cur->name);
2249 p.writeInt32(p_cur->namePresentation);
Wink Saville3a4840b2010-04-07 13:29:58 -07002250 // Remove when partners upgrade to version 3
Wink Saville74fa3882009-12-22 15:35:41 -08002251 if ((s_callbacks.version < 3) || (p_cur->uusInfo == NULL || p_cur->uusInfo->uusData == NULL)) {
2252 p.writeInt32(0); /* UUS Information is absent */
2253 } else {
2254 RIL_UUS_Info *uusInfo = p_cur->uusInfo;
2255 p.writeInt32(1); /* UUS Information is present */
2256 p.writeInt32(uusInfo->uusType);
2257 p.writeInt32(uusInfo->uusDcs);
2258 p.writeInt32(uusInfo->uusLength);
2259 p.write(uusInfo->uusData, uusInfo->uusLength);
2260 }
Wink Saville3d54e742009-05-18 18:00:44 -07002261 appendPrintBuf("%s[id=%d,%s,toa=%d,",
John Wangff368742009-03-24 17:56:29 -07002262 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002263 p_cur->index,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002264 callStateToString(p_cur->state),
Wink Saville3d54e742009-05-18 18:00:44 -07002265 p_cur->toa);
2266 appendPrintBuf("%s%s,%s,als=%d,%s,%s,",
2267 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002268 (p_cur->isMpty)?"conf":"norm",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002269 (p_cur->isMT)?"mt":"mo",
2270 p_cur->als,
2271 (p_cur->isVoice)?"voc":"nonvoc",
Wink Saville3d54e742009-05-18 18:00:44 -07002272 (p_cur->isVoicePrivacy)?"evp":"noevp");
2273 appendPrintBuf("%s%s,cli=%d,name='%s',%d]",
2274 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002275 p_cur->number,
2276 p_cur->numberPresentation,
2277 p_cur->name,
2278 p_cur->namePresentation);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002279 }
2280 removeLastChar;
2281 closeResponse;
2282
2283 return 0;
2284}
2285
Wink Savillef4c4d362009-04-02 01:37:03 -07002286static int responseSMS(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002287 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002288 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002289 return RIL_ERRNO_INVALID_RESPONSE;
2290 }
2291
2292 if (responselen != sizeof (RIL_SMS_Response) ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002293 RLOGE("invalid response length %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002294 (int)responselen, (int)sizeof (RIL_SMS_Response));
2295 return RIL_ERRNO_INVALID_RESPONSE;
2296 }
2297
2298 RIL_SMS_Response *p_cur = (RIL_SMS_Response *) response;
2299
2300 p.writeInt32(p_cur->messageRef);
2301 writeStringToParcel(p, p_cur->ackPDU);
Jaikumar Ganesh920c78f2009-06-04 10:53:15 -07002302 p.writeInt32(p_cur->errorCode);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002303
2304 startResponse;
Jaikumar Ganesh920c78f2009-06-04 10:53:15 -07002305 appendPrintBuf("%s%d,%s,%d", printBuf, p_cur->messageRef,
2306 (char*)p_cur->ackPDU, p_cur->errorCode);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002307 closeResponse;
2308
2309 return 0;
2310}
2311
Wink Savillec0114b32011-02-18 10:14:07 -08002312static int responseDataCallListV4(Parcel &p, void *response, size_t responselen)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002313{
2314 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002315 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002316 return RIL_ERRNO_INVALID_RESPONSE;
2317 }
2318
Wink Savillec0114b32011-02-18 10:14:07 -08002319 if (responselen % sizeof(RIL_Data_Call_Response_v4) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002320 RLOGE("responseDataCallListV4: invalid response length %d expected multiple of %d",
Wink Savillec0114b32011-02-18 10:14:07 -08002321 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v4));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002322 return RIL_ERRNO_INVALID_RESPONSE;
2323 }
2324
Amit Mahajan52500162014-07-29 17:36:48 -07002325 // Write version
2326 p.writeInt32(4);
2327
Wink Savillec0114b32011-02-18 10:14:07 -08002328 int num = responselen / sizeof(RIL_Data_Call_Response_v4);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002329 p.writeInt32(num);
2330
Wink Savillec0114b32011-02-18 10:14:07 -08002331 RIL_Data_Call_Response_v4 *p_cur = (RIL_Data_Call_Response_v4 *) response;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002332 startResponse;
2333 int i;
2334 for (i = 0; i < num; i++) {
2335 p.writeInt32(p_cur[i].cid);
2336 p.writeInt32(p_cur[i].active);
2337 writeStringToParcel(p, p_cur[i].type);
Wink Savillec0114b32011-02-18 10:14:07 -08002338 // apn is not used, so don't send.
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002339 writeStringToParcel(p, p_cur[i].address);
Wink Savillec0114b32011-02-18 10:14:07 -08002340 appendPrintBuf("%s[cid=%d,%s,%s,%s],", printBuf,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002341 p_cur[i].cid,
2342 (p_cur[i].active==0)?"down":"up",
2343 (char*)p_cur[i].type,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002344 (char*)p_cur[i].address);
2345 }
2346 removeLastChar;
2347 closeResponse;
2348
2349 return 0;
2350}
2351
Etan Cohend3652192014-06-20 08:28:44 -07002352static int responseDataCallListV6(Parcel &p, void *response, size_t responselen)
2353{
Amit Mahajan52500162014-07-29 17:36:48 -07002354 if (response == NULL && responselen != 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002355 RLOGE("invalid response: NULL");
2356 return RIL_ERRNO_INVALID_RESPONSE;
2357 }
2358
2359 if (responselen % sizeof(RIL_Data_Call_Response_v6) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002360 RLOGE("responseDataCallListV6: invalid response length %d expected multiple of %d",
Etan Cohend3652192014-06-20 08:28:44 -07002361 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v6));
2362 return RIL_ERRNO_INVALID_RESPONSE;
2363 }
2364
Amit Mahajan52500162014-07-29 17:36:48 -07002365 // Write version
2366 p.writeInt32(6);
2367
Etan Cohend3652192014-06-20 08:28:44 -07002368 int num = responselen / sizeof(RIL_Data_Call_Response_v6);
2369 p.writeInt32(num);
2370
2371 RIL_Data_Call_Response_v6 *p_cur = (RIL_Data_Call_Response_v6 *) response;
2372 startResponse;
2373 int i;
2374 for (i = 0; i < num; i++) {
2375 p.writeInt32((int)p_cur[i].status);
2376 p.writeInt32(p_cur[i].suggestedRetryTime);
2377 p.writeInt32(p_cur[i].cid);
2378 p.writeInt32(p_cur[i].active);
2379 writeStringToParcel(p, p_cur[i].type);
2380 writeStringToParcel(p, p_cur[i].ifname);
2381 writeStringToParcel(p, p_cur[i].addresses);
2382 writeStringToParcel(p, p_cur[i].dnses);
2383 writeStringToParcel(p, p_cur[i].gateways);
2384 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s],", printBuf,
2385 p_cur[i].status,
2386 p_cur[i].suggestedRetryTime,
2387 p_cur[i].cid,
2388 (p_cur[i].active==0)?"down":"up",
2389 (char*)p_cur[i].type,
2390 (char*)p_cur[i].ifname,
2391 (char*)p_cur[i].addresses,
2392 (char*)p_cur[i].dnses,
2393 (char*)p_cur[i].gateways);
2394 }
2395 removeLastChar;
2396 closeResponse;
2397
2398 return 0;
2399}
2400
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002401static int responseDataCallListV9(Parcel &p, void *response, size_t responselen)
2402{
2403 if (response == NULL && responselen != 0) {
2404 RLOGE("invalid response: NULL");
2405 return RIL_ERRNO_INVALID_RESPONSE;
2406 }
2407
2408 if (responselen % sizeof(RIL_Data_Call_Response_v9) != 0) {
2409 RLOGE("responseDataCallListV9: invalid response length %d expected multiple of %d",
2410 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v9));
2411 return RIL_ERRNO_INVALID_RESPONSE;
2412 }
2413
2414 // Write version
2415 p.writeInt32(10);
2416
2417 int num = responselen / sizeof(RIL_Data_Call_Response_v9);
2418 p.writeInt32(num);
2419
2420 RIL_Data_Call_Response_v9 *p_cur = (RIL_Data_Call_Response_v9 *) response;
2421 startResponse;
2422 int i;
2423 for (i = 0; i < num; i++) {
2424 p.writeInt32((int)p_cur[i].status);
2425 p.writeInt32(p_cur[i].suggestedRetryTime);
2426 p.writeInt32(p_cur[i].cid);
2427 p.writeInt32(p_cur[i].active);
2428 writeStringToParcel(p, p_cur[i].type);
2429 writeStringToParcel(p, p_cur[i].ifname);
2430 writeStringToParcel(p, p_cur[i].addresses);
2431 writeStringToParcel(p, p_cur[i].dnses);
2432 writeStringToParcel(p, p_cur[i].gateways);
2433 writeStringToParcel(p, p_cur[i].pcscf);
2434 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s],", printBuf,
2435 p_cur[i].status,
2436 p_cur[i].suggestedRetryTime,
2437 p_cur[i].cid,
2438 (p_cur[i].active==0)?"down":"up",
2439 (char*)p_cur[i].type,
2440 (char*)p_cur[i].ifname,
2441 (char*)p_cur[i].addresses,
2442 (char*)p_cur[i].dnses,
2443 (char*)p_cur[i].gateways,
2444 (char*)p_cur[i].pcscf);
2445 }
2446 removeLastChar;
2447 closeResponse;
2448
2449 return 0;
2450}
2451
2452
Wink Saville43808972011-01-13 17:39:51 -08002453static int responseDataCallList(Parcel &p, void *response, size_t responselen)
2454{
Wink Saville43808972011-01-13 17:39:51 -08002455 if (s_callbacks.version < 5) {
Amit Mahajan52500162014-07-29 17:36:48 -07002456 RLOGD("responseDataCallList: v4");
Wink Savillec0114b32011-02-18 10:14:07 -08002457 return responseDataCallListV4(p, response, responselen);
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002458 } else if (responselen % sizeof(RIL_Data_Call_Response_v6) == 0) {
2459 return responseDataCallListV6(p, response, responselen);
2460 } else if (responselen % sizeof(RIL_Data_Call_Response_v9) == 0) {
2461 return responseDataCallListV9(p, response, responselen);
Wink Saville43808972011-01-13 17:39:51 -08002462 } else {
2463 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002464 RLOGE("invalid response: NULL");
Wink Saville43808972011-01-13 17:39:51 -08002465 return RIL_ERRNO_INVALID_RESPONSE;
2466 }
2467
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002468 if (responselen % sizeof(RIL_Data_Call_Response_v11) != 0) {
2469 RLOGE("invalid response length %d expected multiple of %d",
2470 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v11));
Wink Saville43808972011-01-13 17:39:51 -08002471 return RIL_ERRNO_INVALID_RESPONSE;
2472 }
2473
Amit Mahajan52500162014-07-29 17:36:48 -07002474 // Write version
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002475 p.writeInt32(11);
Amit Mahajan52500162014-07-29 17:36:48 -07002476
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002477 int num = responselen / sizeof(RIL_Data_Call_Response_v11);
Wink Saville43808972011-01-13 17:39:51 -08002478 p.writeInt32(num);
2479
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002480 RIL_Data_Call_Response_v11 *p_cur = (RIL_Data_Call_Response_v11 *) response;
Wink Saville43808972011-01-13 17:39:51 -08002481 startResponse;
2482 int i;
2483 for (i = 0; i < num; i++) {
2484 p.writeInt32((int)p_cur[i].status);
Kazuhiro Ondobeb25b52011-06-17 16:26:45 -05002485 p.writeInt32(p_cur[i].suggestedRetryTime);
Wink Saville43808972011-01-13 17:39:51 -08002486 p.writeInt32(p_cur[i].cid);
2487 p.writeInt32(p_cur[i].active);
David 'Digit' Turneraf1298d2011-02-04 13:36:47 +01002488 writeStringToParcel(p, p_cur[i].type);
Wink Saville43808972011-01-13 17:39:51 -08002489 writeStringToParcel(p, p_cur[i].ifname);
2490 writeStringToParcel(p, p_cur[i].addresses);
2491 writeStringToParcel(p, p_cur[i].dnses);
Wink Savillec0114b32011-02-18 10:14:07 -08002492 writeStringToParcel(p, p_cur[i].gateways);
Etan Cohend3652192014-06-20 08:28:44 -07002493 writeStringToParcel(p, p_cur[i].pcscf);
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002494 p.writeInt32(p_cur[i].mtu);
2495 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 -08002496 p_cur[i].status,
Kazuhiro Ondobeb25b52011-06-17 16:26:45 -05002497 p_cur[i].suggestedRetryTime,
Wink Saville43808972011-01-13 17:39:51 -08002498 p_cur[i].cid,
2499 (p_cur[i].active==0)?"down":"up",
Naveen Kalla56384152011-11-16 11:12:37 -08002500 (char*)p_cur[i].type,
Wink Saville43808972011-01-13 17:39:51 -08002501 (char*)p_cur[i].ifname,
2502 (char*)p_cur[i].addresses,
Wink Savillec0114b32011-02-18 10:14:07 -08002503 (char*)p_cur[i].dnses,
Etan Cohend3652192014-06-20 08:28:44 -07002504 (char*)p_cur[i].gateways,
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002505 (char*)p_cur[i].pcscf,
2506 p_cur[i].mtu);
Wink Saville43808972011-01-13 17:39:51 -08002507 }
2508 removeLastChar;
2509 closeResponse;
2510 }
2511
2512 return 0;
2513}
2514
2515static int responseSetupDataCall(Parcel &p, void *response, size_t responselen)
2516{
2517 if (s_callbacks.version < 5) {
2518 return responseStringsWithVersion(s_callbacks.version, p, response, responselen);
2519 } else {
2520 return responseDataCallList(p, response, responselen);
2521 }
2522}
2523
Wink Savillef4c4d362009-04-02 01:37:03 -07002524static int responseRaw(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002525 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002526 RLOGE("invalid response: NULL with responselen != 0");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002527 return RIL_ERRNO_INVALID_RESPONSE;
2528 }
2529
2530 // The java code reads -1 size as null byte array
2531 if (response == NULL) {
Wink Saville7f856802009-06-09 10:23:37 -07002532 p.writeInt32(-1);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002533 } else {
2534 p.writeInt32(responselen);
2535 p.write(response, responselen);
2536 }
2537
2538 return 0;
2539}
2540
2541
Wink Savillef4c4d362009-04-02 01:37:03 -07002542static int responseSIM_IO(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002543 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002544 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002545 return RIL_ERRNO_INVALID_RESPONSE;
2546 }
2547
2548 if (responselen != sizeof (RIL_SIM_IO_Response) ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002549 RLOGE("invalid response length was %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002550 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
2551 return RIL_ERRNO_INVALID_RESPONSE;
2552 }
2553
2554 RIL_SIM_IO_Response *p_cur = (RIL_SIM_IO_Response *) response;
2555 p.writeInt32(p_cur->sw1);
2556 p.writeInt32(p_cur->sw2);
2557 writeStringToParcel(p, p_cur->simResponse);
2558
2559 startResponse;
2560 appendPrintBuf("%ssw1=0x%X,sw2=0x%X,%s", printBuf, p_cur->sw1, p_cur->sw2,
2561 (char*)p_cur->simResponse);
2562 closeResponse;
2563
2564
2565 return 0;
2566}
2567
Wink Savillef4c4d362009-04-02 01:37:03 -07002568static int responseCallForwards(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002569 int num;
Wink Saville7f856802009-06-09 10:23:37 -07002570
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002571 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002572 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002573 return RIL_ERRNO_INVALID_RESPONSE;
2574 }
2575
2576 if (responselen % sizeof(RIL_CallForwardInfo *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002577 RLOGE("responseCallForwards: invalid response length %d expected multiple of %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002578 (int)responselen, (int)sizeof(RIL_CallForwardInfo *));
2579 return RIL_ERRNO_INVALID_RESPONSE;
2580 }
2581
2582 /* number of call info's */
2583 num = responselen / sizeof(RIL_CallForwardInfo *);
2584 p.writeInt32(num);
2585
2586 startResponse;
2587 for (int i = 0 ; i < num ; i++) {
2588 RIL_CallForwardInfo *p_cur = ((RIL_CallForwardInfo **) response)[i];
2589
2590 p.writeInt32(p_cur->status);
2591 p.writeInt32(p_cur->reason);
2592 p.writeInt32(p_cur->serviceClass);
2593 p.writeInt32(p_cur->toa);
2594 writeStringToParcel(p, p_cur->number);
2595 p.writeInt32(p_cur->timeSeconds);
2596 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
2597 (p_cur->status==1)?"enable":"disable",
2598 p_cur->reason, p_cur->serviceClass, p_cur->toa,
2599 (char*)p_cur->number,
2600 p_cur->timeSeconds);
2601 }
2602 removeLastChar;
2603 closeResponse;
Wink Saville7f856802009-06-09 10:23:37 -07002604
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002605 return 0;
2606}
2607
Wink Savillef4c4d362009-04-02 01:37:03 -07002608static int responseSsn(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002609 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002610 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002611 return RIL_ERRNO_INVALID_RESPONSE;
2612 }
2613
2614 if (responselen != sizeof(RIL_SuppSvcNotification)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002615 RLOGE("invalid response length was %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002616 (int)responselen, (int)sizeof (RIL_SuppSvcNotification));
2617 return RIL_ERRNO_INVALID_RESPONSE;
2618 }
2619
2620 RIL_SuppSvcNotification *p_cur = (RIL_SuppSvcNotification *) response;
2621 p.writeInt32(p_cur->notificationType);
2622 p.writeInt32(p_cur->code);
2623 p.writeInt32(p_cur->index);
2624 p.writeInt32(p_cur->type);
2625 writeStringToParcel(p, p_cur->number);
2626
2627 startResponse;
2628 appendPrintBuf("%s%s,code=%d,id=%d,type=%d,%s", printBuf,
2629 (p_cur->notificationType==0)?"mo":"mt",
2630 p_cur->code, p_cur->index, p_cur->type,
2631 (char*)p_cur->number);
2632 closeResponse;
2633
2634 return 0;
2635}
2636
Wink Saville3d54e742009-05-18 18:00:44 -07002637static int responseCellList(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002638 int num;
2639
2640 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002641 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002642 return RIL_ERRNO_INVALID_RESPONSE;
2643 }
2644
2645 if (responselen % sizeof (RIL_NeighboringCell *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002646 RLOGE("responseCellList: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002647 (int)responselen, (int)sizeof (RIL_NeighboringCell *));
2648 return RIL_ERRNO_INVALID_RESPONSE;
2649 }
2650
2651 startResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002652 /* number of records */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002653 num = responselen / sizeof(RIL_NeighboringCell *);
2654 p.writeInt32(num);
2655
2656 for (int i = 0 ; i < num ; i++) {
2657 RIL_NeighboringCell *p_cur = ((RIL_NeighboringCell **) response)[i];
2658
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002659 p.writeInt32(p_cur->rssi);
2660 writeStringToParcel (p, p_cur->cid);
2661
2662 appendPrintBuf("%s[cid=%s,rssi=%d],", printBuf,
2663 p_cur->cid, p_cur->rssi);
2664 }
2665 removeLastChar;
2666 closeResponse;
2667
2668 return 0;
2669}
2670
Wink Saville3d54e742009-05-18 18:00:44 -07002671/**
2672 * Marshall the signalInfoRecord into the parcel if it exists.
2673 */
Wink Savillea592eeb2009-05-22 13:26:36 -07002674static void marshallSignalInfoRecord(Parcel &p,
2675 RIL_CDMA_SignalInfoRecord &p_signalInfoRecord) {
Wink Saville3d54e742009-05-18 18:00:44 -07002676 p.writeInt32(p_signalInfoRecord.isPresent);
2677 p.writeInt32(p_signalInfoRecord.signalType);
2678 p.writeInt32(p_signalInfoRecord.alertPitch);
2679 p.writeInt32(p_signalInfoRecord.signal);
2680}
2681
Wink Savillea592eeb2009-05-22 13:26:36 -07002682static int responseCdmaInformationRecords(Parcel &p,
2683 void *response, size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07002684 int num;
Wink Savillea592eeb2009-05-22 13:26:36 -07002685 char* string8 = NULL;
2686 int buffer_lenght;
2687 RIL_CDMA_InformationRecord *infoRec;
Wink Saville3d54e742009-05-18 18:00:44 -07002688
2689 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002690 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002691 return RIL_ERRNO_INVALID_RESPONSE;
2692 }
2693
Wink Savillea592eeb2009-05-22 13:26:36 -07002694 if (responselen != sizeof (RIL_CDMA_InformationRecords)) {
Amit Mahajan52500162014-07-29 17:36:48 -07002695 RLOGE("responseCdmaInformationRecords: invalid response length %d expected multiple of %d\n",
Wink Savillea592eeb2009-05-22 13:26:36 -07002696 (int)responselen, (int)sizeof (RIL_CDMA_InformationRecords *));
Wink Saville3d54e742009-05-18 18:00:44 -07002697 return RIL_ERRNO_INVALID_RESPONSE;
2698 }
2699
Wink Savillea592eeb2009-05-22 13:26:36 -07002700 RIL_CDMA_InformationRecords *p_cur =
2701 (RIL_CDMA_InformationRecords *) response;
2702 num = MIN(p_cur->numberOfInfoRecs, RIL_CDMA_MAX_NUMBER_OF_INFO_RECS);
Wink Saville3d54e742009-05-18 18:00:44 -07002703
2704 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07002705 p.writeInt32(num);
Wink Saville3d54e742009-05-18 18:00:44 -07002706
Wink Savillea592eeb2009-05-22 13:26:36 -07002707 for (int i = 0 ; i < num ; i++) {
2708 infoRec = &p_cur->infoRec[i];
2709 p.writeInt32(infoRec->name);
2710 switch (infoRec->name) {
Wink Saville3d54e742009-05-18 18:00:44 -07002711 case RIL_CDMA_DISPLAY_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002712 case RIL_CDMA_EXTENDED_DISPLAY_INFO_REC:
2713 if (infoRec->rec.display.alpha_len >
2714 CDMA_ALPHA_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002715 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002716 expected not more than %d\n",
2717 (int)infoRec->rec.display.alpha_len,
2718 CDMA_ALPHA_INFO_BUFFER_LENGTH);
2719 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002720 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002721 string8 = (char*) malloc((infoRec->rec.display.alpha_len + 1)
2722 * sizeof(char) );
2723 for (int i = 0 ; i < infoRec->rec.display.alpha_len ; i++) {
2724 string8[i] = infoRec->rec.display.alpha_buf[i];
2725 }
Wink Saville43808972011-01-13 17:39:51 -08002726 string8[(int)infoRec->rec.display.alpha_len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002727 writeStringToParcel(p, (const char*)string8);
2728 free(string8);
2729 string8 = NULL;
Wink Saville3d54e742009-05-18 18:00:44 -07002730 break;
2731 case RIL_CDMA_CALLED_PARTY_NUMBER_INFO_REC:
Wink Saville3d54e742009-05-18 18:00:44 -07002732 case RIL_CDMA_CALLING_PARTY_NUMBER_INFO_REC:
Wink Saville3d54e742009-05-18 18:00:44 -07002733 case RIL_CDMA_CONNECTED_NUMBER_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002734 if (infoRec->rec.number.len > CDMA_NUMBER_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002735 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002736 expected not more than %d\n",
2737 (int)infoRec->rec.number.len,
2738 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2739 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002740 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002741 string8 = (char*) malloc((infoRec->rec.number.len + 1)
2742 * sizeof(char) );
2743 for (int i = 0 ; i < infoRec->rec.number.len; i++) {
2744 string8[i] = infoRec->rec.number.buf[i];
2745 }
Wink Saville43808972011-01-13 17:39:51 -08002746 string8[(int)infoRec->rec.number.len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002747 writeStringToParcel(p, (const char*)string8);
2748 free(string8);
2749 string8 = NULL;
2750 p.writeInt32(infoRec->rec.number.number_type);
2751 p.writeInt32(infoRec->rec.number.number_plan);
2752 p.writeInt32(infoRec->rec.number.pi);
2753 p.writeInt32(infoRec->rec.number.si);
Wink Saville3d54e742009-05-18 18:00:44 -07002754 break;
2755 case RIL_CDMA_SIGNAL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002756 p.writeInt32(infoRec->rec.signal.isPresent);
2757 p.writeInt32(infoRec->rec.signal.signalType);
2758 p.writeInt32(infoRec->rec.signal.alertPitch);
2759 p.writeInt32(infoRec->rec.signal.signal);
2760
2761 appendPrintBuf("%sisPresent=%X, signalType=%X, \
2762 alertPitch=%X, signal=%X, ",
2763 printBuf, (int)infoRec->rec.signal.isPresent,
2764 (int)infoRec->rec.signal.signalType,
2765 (int)infoRec->rec.signal.alertPitch,
2766 (int)infoRec->rec.signal.signal);
2767 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002768 break;
2769 case RIL_CDMA_REDIRECTING_NUMBER_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002770 if (infoRec->rec.redir.redirectingNumber.len >
2771 CDMA_NUMBER_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002772 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002773 expected not more than %d\n",
2774 (int)infoRec->rec.redir.redirectingNumber.len,
2775 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2776 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002777 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002778 string8 = (char*) malloc((infoRec->rec.redir.redirectingNumber
2779 .len + 1) * sizeof(char) );
2780 for (int i = 0;
2781 i < infoRec->rec.redir.redirectingNumber.len;
2782 i++) {
2783 string8[i] = infoRec->rec.redir.redirectingNumber.buf[i];
2784 }
Wink Saville43808972011-01-13 17:39:51 -08002785 string8[(int)infoRec->rec.redir.redirectingNumber.len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002786 writeStringToParcel(p, (const char*)string8);
2787 free(string8);
2788 string8 = NULL;
2789 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_type);
2790 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_plan);
2791 p.writeInt32(infoRec->rec.redir.redirectingNumber.pi);
2792 p.writeInt32(infoRec->rec.redir.redirectingNumber.si);
2793 p.writeInt32(infoRec->rec.redir.redirectingReason);
Wink Saville3d54e742009-05-18 18:00:44 -07002794 break;
2795 case RIL_CDMA_LINE_CONTROL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002796 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPolarityIncluded);
2797 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlToggle);
2798 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlReverse);
2799 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2800
2801 appendPrintBuf("%slineCtrlPolarityIncluded=%d, \
2802 lineCtrlToggle=%d, lineCtrlReverse=%d, \
2803 lineCtrlPowerDenial=%d, ", printBuf,
2804 (int)infoRec->rec.lineCtrl.lineCtrlPolarityIncluded,
2805 (int)infoRec->rec.lineCtrl.lineCtrlToggle,
2806 (int)infoRec->rec.lineCtrl.lineCtrlReverse,
2807 (int)infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2808 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002809 break;
2810 case RIL_CDMA_T53_CLIR_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002811 p.writeInt32((int)(infoRec->rec.clir.cause));
Wink Saville3d54e742009-05-18 18:00:44 -07002812
Wink Savillea592eeb2009-05-22 13:26:36 -07002813 appendPrintBuf("%scause%d", printBuf, infoRec->rec.clir.cause);
2814 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002815 break;
2816 case RIL_CDMA_T53_AUDIO_CONTROL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002817 p.writeInt32(infoRec->rec.audioCtrl.upLink);
2818 p.writeInt32(infoRec->rec.audioCtrl.downLink);
2819
2820 appendPrintBuf("%supLink=%d, downLink=%d, ", printBuf,
2821 infoRec->rec.audioCtrl.upLink,
2822 infoRec->rec.audioCtrl.downLink);
2823 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002824 break;
Wink Savillea592eeb2009-05-22 13:26:36 -07002825 case RIL_CDMA_T53_RELEASE_INFO_REC:
2826 // TODO(Moto): See David Krause, he has the answer:)
Wink Saville8eb2a122012-11-19 16:05:13 -08002827 RLOGE("RIL_CDMA_T53_RELEASE_INFO_REC: return INVALID_RESPONSE");
Wink Savillea592eeb2009-05-22 13:26:36 -07002828 return RIL_ERRNO_INVALID_RESPONSE;
2829 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08002830 RLOGE("Incorrect name value");
Wink Savillea592eeb2009-05-22 13:26:36 -07002831 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002832 }
2833 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002834 closeResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002835
Wink Savillea592eeb2009-05-22 13:26:36 -07002836 return 0;
Wink Saville3d54e742009-05-18 18:00:44 -07002837}
2838
Wink Savillea592eeb2009-05-22 13:26:36 -07002839static int responseRilSignalStrength(Parcel &p,
2840 void *response, size_t responselen) {
2841 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002842 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002843 return RIL_ERRNO_INVALID_RESPONSE;
2844 }
2845
Wink Savillec0114b32011-02-18 10:14:07 -08002846 if (responselen >= sizeof (RIL_SignalStrength_v5)) {
Etan Cohend3652192014-06-20 08:28:44 -07002847 RIL_SignalStrength_v10 *p_cur = ((RIL_SignalStrength_v10 *) response);
Wink Saville3d54e742009-05-18 18:00:44 -07002848
Wink Saville3d54e742009-05-18 18:00:44 -07002849 p.writeInt32(p_cur->GW_SignalStrength.signalStrength);
2850 p.writeInt32(p_cur->GW_SignalStrength.bitErrorRate);
2851 p.writeInt32(p_cur->CDMA_SignalStrength.dbm);
2852 p.writeInt32(p_cur->CDMA_SignalStrength.ecio);
2853 p.writeInt32(p_cur->EVDO_SignalStrength.dbm);
2854 p.writeInt32(p_cur->EVDO_SignalStrength.ecio);
2855 p.writeInt32(p_cur->EVDO_SignalStrength.signalNoiseRatio);
Wink Savillec0114b32011-02-18 10:14:07 -08002856 if (responselen >= sizeof (RIL_SignalStrength_v6)) {
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002857 /*
Wink Saville18e4ab12013-04-07 17:31:04 -07002858 * Fixup LTE for backwards compatibility
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002859 */
Wink Saville18e4ab12013-04-07 17:31:04 -07002860 if (s_callbacks.version <= 6) {
2861 // signalStrength: -1 -> 99
2862 if (p_cur->LTE_SignalStrength.signalStrength == -1) {
2863 p_cur->LTE_SignalStrength.signalStrength = 99;
2864 }
2865 // rsrp: -1 -> INT_MAX all other negative value to positive.
2866 // So remap here
2867 if (p_cur->LTE_SignalStrength.rsrp == -1) {
2868 p_cur->LTE_SignalStrength.rsrp = INT_MAX;
2869 } else if (p_cur->LTE_SignalStrength.rsrp < -1) {
2870 p_cur->LTE_SignalStrength.rsrp = -p_cur->LTE_SignalStrength.rsrp;
2871 }
2872 // rsrq: -1 -> INT_MAX
2873 if (p_cur->LTE_SignalStrength.rsrq == -1) {
2874 p_cur->LTE_SignalStrength.rsrq = INT_MAX;
2875 }
2876 // Not remapping rssnr is already using INT_MAX
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002877
Wink Saville18e4ab12013-04-07 17:31:04 -07002878 // cqi: -1 -> INT_MAX
2879 if (p_cur->LTE_SignalStrength.cqi == -1) {
2880 p_cur->LTE_SignalStrength.cqi = INT_MAX;
2881 }
2882 }
2883 p.writeInt32(p_cur->LTE_SignalStrength.signalStrength);
Wink Savillec0114b32011-02-18 10:14:07 -08002884 p.writeInt32(p_cur->LTE_SignalStrength.rsrp);
2885 p.writeInt32(p_cur->LTE_SignalStrength.rsrq);
2886 p.writeInt32(p_cur->LTE_SignalStrength.rssnr);
2887 p.writeInt32(p_cur->LTE_SignalStrength.cqi);
Etan Cohend3652192014-06-20 08:28:44 -07002888 if (responselen >= sizeof (RIL_SignalStrength_v10)) {
2889 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
2890 } else {
2891 p.writeInt32(INT_MAX);
2892 }
Wink Savillec0114b32011-02-18 10:14:07 -08002893 } else {
Wink Saville18e4ab12013-04-07 17:31:04 -07002894 p.writeInt32(99);
2895 p.writeInt32(INT_MAX);
2896 p.writeInt32(INT_MAX);
2897 p.writeInt32(INT_MAX);
2898 p.writeInt32(INT_MAX);
Etan Cohend3652192014-06-20 08:28:44 -07002899 p.writeInt32(INT_MAX);
Wink Savillec0114b32011-02-18 10:14:07 -08002900 }
johnwangfdf825f2009-05-22 15:50:34 -07002901
2902 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07002903 appendPrintBuf("%s[signalStrength=%d,bitErrorRate=%d,\
Wink Savillec0114b32011-02-18 10:14:07 -08002904 CDMA_SS.dbm=%d,CDMA_SSecio=%d,\
2905 EVDO_SS.dbm=%d,EVDO_SS.ecio=%d,\
2906 EVDO_SS.signalNoiseRatio=%d,\
2907 LTE_SS.signalStrength=%d,LTE_SS.rsrp=%d,LTE_SS.rsrq=%d,\
Etan Cohend3652192014-06-20 08:28:44 -07002908 LTE_SS.rssnr=%d,LTE_SS.cqi=%d,TDSCDMA_SS.rscp=%d]",
Wink Savillea592eeb2009-05-22 13:26:36 -07002909 printBuf,
2910 p_cur->GW_SignalStrength.signalStrength,
2911 p_cur->GW_SignalStrength.bitErrorRate,
2912 p_cur->CDMA_SignalStrength.dbm,
2913 p_cur->CDMA_SignalStrength.ecio,
2914 p_cur->EVDO_SignalStrength.dbm,
2915 p_cur->EVDO_SignalStrength.ecio,
Wink Savillec0114b32011-02-18 10:14:07 -08002916 p_cur->EVDO_SignalStrength.signalNoiseRatio,
2917 p_cur->LTE_SignalStrength.signalStrength,
2918 p_cur->LTE_SignalStrength.rsrp,
2919 p_cur->LTE_SignalStrength.rsrq,
2920 p_cur->LTE_SignalStrength.rssnr,
Etan Cohend3652192014-06-20 08:28:44 -07002921 p_cur->LTE_SignalStrength.cqi,
2922 p_cur->TD_SCDMA_SignalStrength.rscp);
Wink Savillea592eeb2009-05-22 13:26:36 -07002923 closeResponse;
2924
Wink Saville3d54e742009-05-18 18:00:44 -07002925 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08002926 RLOGE("invalid response length");
Wink Saville3d54e742009-05-18 18:00:44 -07002927 return RIL_ERRNO_INVALID_RESPONSE;
2928 }
2929
Wink Saville3d54e742009-05-18 18:00:44 -07002930 return 0;
2931}
2932
2933static int responseCallRing(Parcel &p, void *response, size_t responselen) {
2934 if ((response == NULL) || (responselen == 0)) {
2935 return responseVoid(p, response, responselen);
2936 } else {
2937 return responseCdmaSignalInfoRecord(p, response, responselen);
2938 }
2939}
2940
2941static int responseCdmaSignalInfoRecord(Parcel &p, void *response, size_t responselen) {
2942 if (response == NULL || responselen == 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002943 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002944 return RIL_ERRNO_INVALID_RESPONSE;
2945 }
2946
2947 if (responselen != sizeof (RIL_CDMA_SignalInfoRecord)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002948 RLOGE("invalid response length %d expected sizeof (RIL_CDMA_SignalInfoRecord) of %d\n",
Wink Saville3d54e742009-05-18 18:00:44 -07002949 (int)responselen, (int)sizeof (RIL_CDMA_SignalInfoRecord));
2950 return RIL_ERRNO_INVALID_RESPONSE;
2951 }
2952
2953 startResponse;
2954
2955 RIL_CDMA_SignalInfoRecord *p_cur = ((RIL_CDMA_SignalInfoRecord *) response);
2956 marshallSignalInfoRecord(p, *p_cur);
2957
2958 appendPrintBuf("%s[isPresent=%d,signalType=%d,alertPitch=%d\
2959 signal=%d]",
2960 printBuf,
2961 p_cur->isPresent,
2962 p_cur->signalType,
2963 p_cur->alertPitch,
2964 p_cur->signal);
2965
2966 closeResponse;
2967 return 0;
2968}
2969
Wink Savillea592eeb2009-05-22 13:26:36 -07002970static int responseCdmaCallWaiting(Parcel &p, void *response,
2971 size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07002972 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002973 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002974 return RIL_ERRNO_INVALID_RESPONSE;
2975 }
2976
Wink Savillec0114b32011-02-18 10:14:07 -08002977 if (responselen < sizeof(RIL_CDMA_CallWaiting_v6)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002978 RLOGW("Upgrade to ril version %d\n", RIL_VERSION);
Wink Savillec0114b32011-02-18 10:14:07 -08002979 }
2980
2981 RIL_CDMA_CallWaiting_v6 *p_cur = ((RIL_CDMA_CallWaiting_v6 *) response);
2982
2983 writeStringToParcel(p, p_cur->number);
2984 p.writeInt32(p_cur->numberPresentation);
2985 writeStringToParcel(p, p_cur->name);
2986 marshallSignalInfoRecord(p, p_cur->signalInfoRecord);
2987
2988 if (responselen >= sizeof(RIL_CDMA_CallWaiting_v6)) {
2989 p.writeInt32(p_cur->number_type);
2990 p.writeInt32(p_cur->number_plan);
2991 } else {
2992 p.writeInt32(0);
2993 p.writeInt32(0);
Wink Saville3d54e742009-05-18 18:00:44 -07002994 }
2995
2996 startResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002997 appendPrintBuf("%snumber=%s,numberPresentation=%d, name=%s,\
2998 signalInfoRecord[isPresent=%d,signalType=%d,alertPitch=%d\
Wink Savillec0114b32011-02-18 10:14:07 -08002999 signal=%d,number_type=%d,number_plan=%d]",
Wink Saville3d54e742009-05-18 18:00:44 -07003000 printBuf,
3001 p_cur->number,
3002 p_cur->numberPresentation,
3003 p_cur->name,
3004 p_cur->signalInfoRecord.isPresent,
3005 p_cur->signalInfoRecord.signalType,
3006 p_cur->signalInfoRecord.alertPitch,
Wink Savillec0114b32011-02-18 10:14:07 -08003007 p_cur->signalInfoRecord.signal,
3008 p_cur->number_type,
3009 p_cur->number_plan);
Wink Saville3d54e742009-05-18 18:00:44 -07003010 closeResponse;
3011
3012 return 0;
3013}
3014
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003015static int responseSimRefresh(Parcel &p, void *response, size_t responselen) {
3016 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003017 RLOGE("responseSimRefresh: invalid response: NULL");
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003018 return RIL_ERRNO_INVALID_RESPONSE;
3019 }
3020
3021 startResponse;
3022 if (s_callbacks.version == 7) {
3023 RIL_SimRefreshResponse_v7 *p_cur = ((RIL_SimRefreshResponse_v7 *) response);
3024 p.writeInt32(p_cur->result);
3025 p.writeInt32(p_cur->ef_id);
3026 writeStringToParcel(p, p_cur->aid);
3027
3028 appendPrintBuf("%sresult=%d, ef_id=%d, aid=%s",
3029 printBuf,
3030 p_cur->result,
3031 p_cur->ef_id,
3032 p_cur->aid);
3033 } else {
3034 int *p_cur = ((int *) response);
3035 p.writeInt32(p_cur[0]);
3036 p.writeInt32(p_cur[1]);
3037 writeStringToParcel(p, NULL);
3038
3039 appendPrintBuf("%sresult=%d, ef_id=%d",
3040 printBuf,
3041 p_cur[0],
3042 p_cur[1]);
3043 }
3044 closeResponse;
3045
3046 return 0;
3047}
3048
Wink Saville8a9e0212013-04-09 12:11:38 -07003049static int responseCellInfoList(Parcel &p, void *response, size_t responselen)
3050{
3051 if (response == NULL && responselen != 0) {
3052 RLOGE("invalid response: NULL");
3053 return RIL_ERRNO_INVALID_RESPONSE;
3054 }
3055
3056 if (responselen % sizeof(RIL_CellInfo) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07003057 RLOGE("responseCellInfoList: invalid response length %d expected multiple of %d",
Wink Saville8a9e0212013-04-09 12:11:38 -07003058 (int)responselen, (int)sizeof(RIL_CellInfo));
3059 return RIL_ERRNO_INVALID_RESPONSE;
3060 }
3061
3062 int num = responselen / sizeof(RIL_CellInfo);
3063 p.writeInt32(num);
3064
3065 RIL_CellInfo *p_cur = (RIL_CellInfo *) response;
3066 startResponse;
3067 int i;
3068 for (i = 0; i < num; i++) {
3069 appendPrintBuf("%s[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", printBuf, i,
3070 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
3071 p.writeInt32((int)p_cur->cellInfoType);
3072 p.writeInt32(p_cur->registered);
3073 p.writeInt32(p_cur->timeStampType);
3074 p.writeInt64(p_cur->timeStamp);
3075 switch(p_cur->cellInfoType) {
3076 case RIL_CELL_INFO_TYPE_GSM: {
Wink Savillec57b3eb2013-04-17 12:51:41 -07003077 appendPrintBuf("%s GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,", printBuf,
Wink Saville8a9e0212013-04-09 12:11:38 -07003078 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
3079 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
3080 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
Wink Savillec57b3eb2013-04-17 12:51:41 -07003081 p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3082 appendPrintBuf("%s gsmSS: ss=%d,ber=%d],", printBuf,
Wink Saville8a9e0212013-04-09 12:11:38 -07003083 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
3084 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3085
3086 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
3087 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
3088 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
3089 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
Wink Saville8a9e0212013-04-09 12:11:38 -07003090 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
3091 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3092 break;
3093 }
Wink Savillec57b3eb2013-04-17 12:51:41 -07003094 case RIL_CELL_INFO_TYPE_WCDMA: {
3095 appendPrintBuf("%s WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,", printBuf,
3096 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
3097 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
3098 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
3099 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
3100 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3101 appendPrintBuf("%s wcdmaSS: ss=%d,ber=%d],", printBuf,
3102 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
3103 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3104
3105 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
3106 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
3107 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
3108 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
3109 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3110 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
3111 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3112 break;
3113 }
Wink Saville8a9e0212013-04-09 12:11:38 -07003114 case RIL_CELL_INFO_TYPE_CDMA: {
3115 appendPrintBuf("%s CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d", printBuf,
3116 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
3117 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
3118 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
3119 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
3120 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3121
3122 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
3123 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
3124 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
3125 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
3126 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3127
3128 appendPrintBuf("%s cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d", printBuf,
3129 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
3130 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
3131 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
3132 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
3133 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3134
3135 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
3136 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
3137 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
3138 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
3139 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3140 break;
3141 }
3142 case RIL_CELL_INFO_TYPE_LTE: {
3143 appendPrintBuf("%s LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d", printBuf,
3144 p_cur->CellInfo.lte.cellIdentityLte.mcc,
3145 p_cur->CellInfo.lte.cellIdentityLte.mnc,
3146 p_cur->CellInfo.lte.cellIdentityLte.ci,
3147 p_cur->CellInfo.lte.cellIdentityLte.pci,
3148 p_cur->CellInfo.lte.cellIdentityLte.tac);
3149
3150 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
3151 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
3152 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
3153 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
3154 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
3155
3156 appendPrintBuf("%s lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d", printBuf,
3157 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
3158 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
3159 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
3160 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
3161 p_cur->CellInfo.lte.signalStrengthLte.cqi,
3162 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3163 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
3164 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
3165 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
3166 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
3167 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
3168 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3169 break;
3170 }
Etan Cohend3652192014-06-20 08:28:44 -07003171 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
3172 appendPrintBuf("%s TDSCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,cpid=%d,", printBuf,
3173 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc,
3174 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc,
3175 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac,
3176 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid,
3177 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3178 appendPrintBuf("%s tdscdmaSS: rscp=%d],", printBuf,
3179 p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3180
3181 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
3182 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
3183 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
3184 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
3185 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3186 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3187 break;
3188 }
Wink Saville8a9e0212013-04-09 12:11:38 -07003189 }
3190 p_cur += 1;
3191 }
3192 removeLastChar;
3193 closeResponse;
3194
3195 return 0;
3196}
3197
Etan Cohend3652192014-06-20 08:28:44 -07003198static int responseHardwareConfig(Parcel &p, void *response, size_t responselen)
3199{
3200 if (response == NULL && responselen != 0) {
3201 RLOGE("invalid response: NULL");
3202 return RIL_ERRNO_INVALID_RESPONSE;
3203 }
3204
3205 if (responselen % sizeof(RIL_HardwareConfig) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07003206 RLOGE("responseHardwareConfig: invalid response length %d expected multiple of %d",
Etan Cohend3652192014-06-20 08:28:44 -07003207 (int)responselen, (int)sizeof(RIL_HardwareConfig));
3208 return RIL_ERRNO_INVALID_RESPONSE;
3209 }
3210
3211 int num = responselen / sizeof(RIL_HardwareConfig);
3212 int i;
3213 RIL_HardwareConfig *p_cur = (RIL_HardwareConfig *) response;
3214
3215 p.writeInt32(num);
3216
3217 startResponse;
3218 for (i = 0; i < num; i++) {
3219 switch (p_cur[i].type) {
3220 case RIL_HARDWARE_CONFIG_MODEM: {
3221 writeStringToParcel(p, p_cur[i].uuid);
3222 p.writeInt32((int)p_cur[i].state);
3223 p.writeInt32(p_cur[i].cfg.modem.rat);
3224 p.writeInt32(p_cur[i].cfg.modem.maxVoice);
3225 p.writeInt32(p_cur[i].cfg.modem.maxData);
3226 p.writeInt32(p_cur[i].cfg.modem.maxStandby);
3227
3228 appendPrintBuf("%s modem: uuid=%s,state=%d,rat=%08x,maxV=%d,maxD=%d,maxS=%d", printBuf,
3229 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.modem.rat,
3230 p_cur[i].cfg.modem.maxVoice, p_cur[i].cfg.modem.maxData, p_cur[i].cfg.modem.maxStandby);
3231 break;
3232 }
3233 case RIL_HARDWARE_CONFIG_SIM: {
3234 writeStringToParcel(p, p_cur[i].uuid);
3235 p.writeInt32((int)p_cur[i].state);
3236 writeStringToParcel(p, p_cur[i].cfg.sim.modemUuid);
3237
3238 appendPrintBuf("%s sim: uuid=%s,state=%d,modem-uuid=%s", printBuf,
3239 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.sim.modemUuid);
3240 break;
3241 }
3242 }
3243 }
3244 removeLastChar;
3245 closeResponse;
3246 return 0;
3247}
3248
Wink Saville8b4e4f72014-10-17 15:01:45 -07003249static int responseRadioCapability(Parcel &p, void *response, size_t responselen) {
3250 if (response == NULL) {
3251 RLOGE("invalid response: NULL");
3252 return RIL_ERRNO_INVALID_RESPONSE;
3253 }
3254
3255 if (responselen != sizeof (RIL_RadioCapability) ) {
3256 RLOGE("invalid response length was %d expected %d",
3257 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3258 return RIL_ERRNO_INVALID_RESPONSE;
3259 }
3260
3261 RIL_RadioCapability *p_cur = (RIL_RadioCapability *) response;
3262 p.writeInt32(p_cur->version);
3263 p.writeInt32(p_cur->session);
3264 p.writeInt32(p_cur->phase);
3265 p.writeInt32(p_cur->rat);
3266 writeStringToParcel(p, p_cur->logicalModemUuid);
3267 p.writeInt32(p_cur->status);
3268
3269 startResponse;
3270 appendPrintBuf("%s[version=%d,session=%d,phase=%d,\
Legler Wu8caf06f2014-10-29 14:02:14 +08003271 rat=%s,logicalModemUuid=%s,status=%d]",
Wink Saville8b4e4f72014-10-17 15:01:45 -07003272 printBuf,
3273 p_cur->version,
3274 p_cur->session,
3275 p_cur->phase,
3276 p_cur->rat,
Legler Wu8caf06f2014-10-29 14:02:14 +08003277 p_cur->logicalModemUuid,
Wink Saville8b4e4f72014-10-17 15:01:45 -07003278 p_cur->status);
3279 closeResponse;
3280 return 0;
3281}
3282
Amit Mahajan54563d32014-11-22 00:54:49 +00003283static int responseSSData(Parcel &p, void *response, size_t responselen) {
3284 RLOGD("In responseSSData");
3285 int num;
3286
3287 if (response == NULL && responselen != 0) {
3288 RLOGE("invalid response length was %d expected %d",
3289 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3290 return RIL_ERRNO_INVALID_RESPONSE;
3291 }
3292
3293 if (responselen != sizeof(RIL_StkCcUnsolSsResponse)) {
3294 RLOGE("invalid response length %d, expected %d",
3295 (int)responselen, (int)sizeof(RIL_StkCcUnsolSsResponse));
3296 return RIL_ERRNO_INVALID_RESPONSE;
3297 }
3298
3299 startResponse;
3300 RIL_StkCcUnsolSsResponse *p_cur = (RIL_StkCcUnsolSsResponse *) response;
3301 p.writeInt32(p_cur->serviceType);
3302 p.writeInt32(p_cur->requestType);
3303 p.writeInt32(p_cur->teleserviceType);
3304 p.writeInt32(p_cur->serviceClass);
3305 p.writeInt32(p_cur->result);
3306
3307 if (isServiceTypeCfQuery(p_cur->serviceType, p_cur->requestType)) {
3308 RLOGD("responseSSData CF type, num of Cf elements %d", p_cur->cfData.numValidIndexes);
3309 if (p_cur->cfData.numValidIndexes > NUM_SERVICE_CLASSES) {
3310 RLOGE("numValidIndexes is greater than max value %d, "
3311 "truncating it to max value", NUM_SERVICE_CLASSES);
3312 p_cur->cfData.numValidIndexes = NUM_SERVICE_CLASSES;
3313 }
3314 /* number of call info's */
3315 p.writeInt32(p_cur->cfData.numValidIndexes);
3316
3317 for (int i = 0; i < p_cur->cfData.numValidIndexes; i++) {
3318 RIL_CallForwardInfo cf = p_cur->cfData.cfInfo[i];
3319
3320 p.writeInt32(cf.status);
3321 p.writeInt32(cf.reason);
3322 p.writeInt32(cf.serviceClass);
3323 p.writeInt32(cf.toa);
3324 writeStringToParcel(p, cf.number);
3325 p.writeInt32(cf.timeSeconds);
3326 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
3327 (cf.status==1)?"enable":"disable", cf.reason, cf.serviceClass, cf.toa,
3328 (char*)cf.number, cf.timeSeconds);
3329 RLOGD("Data: %d,reason=%d,cls=%d,toa=%d,num=%s,tout=%d],", cf.status,
3330 cf.reason, cf.serviceClass, cf.toa, (char*)cf.number, cf.timeSeconds);
3331 }
3332 } else {
3333 p.writeInt32 (SS_INFO_MAX);
3334
3335 /* each int*/
3336 for (int i = 0; i < SS_INFO_MAX; i++) {
3337 appendPrintBuf("%s%d,", printBuf, p_cur->ssInfo[i]);
3338 RLOGD("Data: %d",p_cur->ssInfo[i]);
3339 p.writeInt32(p_cur->ssInfo[i]);
3340 }
3341 }
3342 removeLastChar;
3343 closeResponse;
3344
3345 return 0;
3346}
3347
3348static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType) {
3349 if ((reqType == SS_INTERROGATION) &&
3350 (serType == SS_CFU ||
3351 serType == SS_CF_BUSY ||
3352 serType == SS_CF_NO_REPLY ||
3353 serType == SS_CF_NOT_REACHABLE ||
3354 serType == SS_CF_ALL ||
3355 serType == SS_CF_ALL_CONDITIONAL)) {
3356 return true;
3357 }
3358 return false;
3359}
3360
Wink Saville3d54e742009-05-18 18:00:44 -07003361static void triggerEvLoop() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003362 int ret;
3363 if (!pthread_equal(pthread_self(), s_tid_dispatch)) {
3364 /* trigger event loop to wakeup. No reason to do this,
3365 * if we're in the event loop thread */
3366 do {
3367 ret = write (s_fdWakeupWrite, " ", 1);
3368 } while (ret < 0 && errno == EINTR);
3369 }
3370}
3371
Wink Saville3d54e742009-05-18 18:00:44 -07003372static void rilEventAddWakeup(struct ril_event *ev) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003373 ril_event_add(ev);
3374 triggerEvLoop();
3375}
3376
Wink Savillefd729372011-02-22 16:19:39 -08003377static void sendSimStatusAppInfo(Parcel &p, int num_apps, RIL_AppStatus appStatus[]) {
3378 p.writeInt32(num_apps);
3379 startResponse;
3380 for (int i = 0; i < num_apps; i++) {
3381 p.writeInt32(appStatus[i].app_type);
3382 p.writeInt32(appStatus[i].app_state);
3383 p.writeInt32(appStatus[i].perso_substate);
3384 writeStringToParcel(p, (const char*)(appStatus[i].aid_ptr));
3385 writeStringToParcel(p, (const char*)
3386 (appStatus[i].app_label_ptr));
3387 p.writeInt32(appStatus[i].pin1_replaced);
3388 p.writeInt32(appStatus[i].pin1);
3389 p.writeInt32(appStatus[i].pin2);
3390 appendPrintBuf("%s[app_type=%d,app_state=%d,perso_substate=%d,\
3391 aid_ptr=%s,app_label_ptr=%s,pin1_replaced=%d,pin1=%d,pin2=%d],",
3392 printBuf,
3393 appStatus[i].app_type,
3394 appStatus[i].app_state,
3395 appStatus[i].perso_substate,
3396 appStatus[i].aid_ptr,
3397 appStatus[i].app_label_ptr,
3398 appStatus[i].pin1_replaced,
3399 appStatus[i].pin1,
3400 appStatus[i].pin2);
3401 }
3402 closeResponse;
3403}
3404
Wink Savillef4c4d362009-04-02 01:37:03 -07003405static int responseSimStatus(Parcel &p, void *response, size_t responselen) {
3406 int i;
3407
3408 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003409 RLOGE("invalid response: NULL");
Wink Savillef4c4d362009-04-02 01:37:03 -07003410 return RIL_ERRNO_INVALID_RESPONSE;
3411 }
3412
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003413 if (responselen == sizeof (RIL_CardStatus_v6)) {
Wink Savillefd729372011-02-22 16:19:39 -08003414 RIL_CardStatus_v6 *p_cur = ((RIL_CardStatus_v6 *) response);
Wink Savillef4c4d362009-04-02 01:37:03 -07003415
Wink Savillefd729372011-02-22 16:19:39 -08003416 p.writeInt32(p_cur->card_state);
3417 p.writeInt32(p_cur->universal_pin_state);
3418 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3419 p.writeInt32(p_cur->cdma_subscription_app_index);
3420 p.writeInt32(p_cur->ims_subscription_app_index);
3421
3422 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003423 } else if (responselen == sizeof (RIL_CardStatus_v5)) {
Wink Savillefd729372011-02-22 16:19:39 -08003424 RIL_CardStatus_v5 *p_cur = ((RIL_CardStatus_v5 *) response);
3425
3426 p.writeInt32(p_cur->card_state);
3427 p.writeInt32(p_cur->universal_pin_state);
3428 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3429 p.writeInt32(p_cur->cdma_subscription_app_index);
3430 p.writeInt32(-1);
3431
3432 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003433 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003434 RLOGE("responseSimStatus: A RilCardStatus_v6 or _v5 expected\n");
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003435 return RIL_ERRNO_INVALID_RESPONSE;
Wink Savillef4c4d362009-04-02 01:37:03 -07003436 }
Wink Savillef4c4d362009-04-02 01:37:03 -07003437
3438 return 0;
Wink Saville3d54e742009-05-18 18:00:44 -07003439}
Wink Savillef4c4d362009-04-02 01:37:03 -07003440
Wink Savillea592eeb2009-05-22 13:26:36 -07003441static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3442 int num = responselen / sizeof(RIL_GSM_BroadcastSmsConfigInfo *);
Wink Savillef4c4d362009-04-02 01:37:03 -07003443 p.writeInt32(num);
3444
Wink Savillef4c4d362009-04-02 01:37:03 -07003445 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07003446 RIL_GSM_BroadcastSmsConfigInfo **p_cur =
3447 (RIL_GSM_BroadcastSmsConfigInfo **) response;
3448 for (int i = 0; i < num; i++) {
3449 p.writeInt32(p_cur[i]->fromServiceId);
3450 p.writeInt32(p_cur[i]->toServiceId);
3451 p.writeInt32(p_cur[i]->fromCodeScheme);
3452 p.writeInt32(p_cur[i]->toCodeScheme);
3453 p.writeInt32(p_cur[i]->selected);
3454
3455 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId=%d, \
3456 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]",
3457 printBuf, i, p_cur[i]->fromServiceId, p_cur[i]->toServiceId,
3458 p_cur[i]->fromCodeScheme, p_cur[i]->toCodeScheme,
3459 p_cur[i]->selected);
3460 }
Wink Savillef4c4d362009-04-02 01:37:03 -07003461 closeResponse;
3462
3463 return 0;
3464}
3465
Wink Savillea592eeb2009-05-22 13:26:36 -07003466static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3467 RIL_CDMA_BroadcastSmsConfigInfo **p_cur =
3468 (RIL_CDMA_BroadcastSmsConfigInfo **) response;
Wink Savillef4c4d362009-04-02 01:37:03 -07003469
Wink Savillea592eeb2009-05-22 13:26:36 -07003470 int num = responselen / sizeof (RIL_CDMA_BroadcastSmsConfigInfo *);
3471 p.writeInt32(num);
Wink Savillef4c4d362009-04-02 01:37:03 -07003472
3473 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07003474 for (int i = 0 ; i < num ; i++ ) {
3475 p.writeInt32(p_cur[i]->service_category);
3476 p.writeInt32(p_cur[i]->language);
3477 p.writeInt32(p_cur[i]->selected);
Wink Savillef4c4d362009-04-02 01:37:03 -07003478
Wink Savillea592eeb2009-05-22 13:26:36 -07003479 appendPrintBuf("%s [%d: srvice_category=%d, language =%d, \
3480 selected =%d], ",
3481 printBuf, i, p_cur[i]->service_category, p_cur[i]->language,
3482 p_cur[i]->selected);
Wink Savillef5903df2009-04-24 11:54:14 -07003483 }
Wink Savillea592eeb2009-05-22 13:26:36 -07003484 closeResponse;
Wink Savillef5903df2009-04-24 11:54:14 -07003485
Wink Savillef4c4d362009-04-02 01:37:03 -07003486 return 0;
3487}
3488
3489static int responseCdmaSms(Parcel &p, void *response, size_t responselen) {
3490 int num;
3491 int digitCount;
3492 int digitLimit;
3493 uint8_t uct;
3494 void* dest;
3495
Wink Saville8eb2a122012-11-19 16:05:13 -08003496 RLOGD("Inside responseCdmaSms");
Wink Savillef5903df2009-04-24 11:54:14 -07003497
Wink Savillef4c4d362009-04-02 01:37:03 -07003498 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003499 RLOGE("invalid response: NULL");
Wink Savillef4c4d362009-04-02 01:37:03 -07003500 return RIL_ERRNO_INVALID_RESPONSE;
3501 }
3502
Wink Savillef5903df2009-04-24 11:54:14 -07003503 if (responselen != sizeof(RIL_CDMA_SMS_Message)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003504 RLOGE("invalid response length was %d expected %d",
Wink Savillef5903df2009-04-24 11:54:14 -07003505 (int)responselen, (int)sizeof(RIL_CDMA_SMS_Message));
Wink Savillef4c4d362009-04-02 01:37:03 -07003506 return RIL_ERRNO_INVALID_RESPONSE;
3507 }
3508
3509 RIL_CDMA_SMS_Message *p_cur = (RIL_CDMA_SMS_Message *) response;
3510 p.writeInt32(p_cur->uTeleserviceID);
3511 p.write(&(p_cur->bIsServicePresent),sizeof(uct));
3512 p.writeInt32(p_cur->uServicecategory);
3513 p.writeInt32(p_cur->sAddress.digit_mode);
3514 p.writeInt32(p_cur->sAddress.number_mode);
3515 p.writeInt32(p_cur->sAddress.number_type);
3516 p.writeInt32(p_cur->sAddress.number_plan);
3517 p.write(&(p_cur->sAddress.number_of_digits), sizeof(uct));
3518 digitLimit= MIN((p_cur->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
3519 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3520 p.write(&(p_cur->sAddress.digits[digitCount]),sizeof(uct));
3521 }
3522
3523 p.writeInt32(p_cur->sSubAddress.subaddressType);
3524 p.write(&(p_cur->sSubAddress.odd),sizeof(uct));
3525 p.write(&(p_cur->sSubAddress.number_of_digits),sizeof(uct));
3526 digitLimit= MIN((p_cur->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
3527 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3528 p.write(&(p_cur->sSubAddress.digits[digitCount]),sizeof(uct));
3529 }
3530
3531 digitLimit= MIN((p_cur->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
3532 p.writeInt32(p_cur->uBearerDataLen);
3533 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3534 p.write(&(p_cur->aBearerData[digitCount]), sizeof(uct));
3535 }
3536
3537 startResponse;
3538 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
Wink Saville1b5fd232009-04-22 14:50:00 -07003539 sAddress.digit_mode=%d, sAddress.number_mode=%d, sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07003540 printBuf, p_cur->uTeleserviceID,p_cur->bIsServicePresent,p_cur->uServicecategory,
3541 p_cur->sAddress.digit_mode, p_cur->sAddress.number_mode,p_cur->sAddress.number_type);
3542 closeResponse;
3543
3544 return 0;
3545}
3546
Wink Savillec29360a2014-07-13 05:17:28 -07003547static int responseDcRtInfo(Parcel &p, void *response, size_t responselen)
3548{
3549 int num = responselen / sizeof(RIL_DcRtInfo);
3550 if ((responselen % sizeof(RIL_DcRtInfo) != 0) || (num != 1)) {
Amit Mahajan52500162014-07-29 17:36:48 -07003551 RLOGE("responseDcRtInfo: invalid response length %d expected multiple of %d",
Wink Savillec29360a2014-07-13 05:17:28 -07003552 (int)responselen, (int)sizeof(RIL_DcRtInfo));
3553 return RIL_ERRNO_INVALID_RESPONSE;
3554 }
3555
3556 startResponse;
3557 RIL_DcRtInfo *pDcRtInfo = (RIL_DcRtInfo *)response;
3558 p.writeInt64(pDcRtInfo->time);
3559 p.writeInt32(pDcRtInfo->powerState);
3560 appendPrintBuf("%s[time=%d,powerState=%d]", printBuf,
3561 pDcRtInfo->time,
3562 pDcRtInfo->powerState);
3563 closeResponse;
3564
3565 return 0;
3566}
3567
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003568/**
3569 * A write on the wakeup fd is done just to pop us out of select()
3570 * We empty the buffer here and then ril_event will reset the timers on the
3571 * way back down
3572 */
Wink Savillef4c4d362009-04-02 01:37:03 -07003573static void processWakeupCallback(int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003574 char buff[16];
3575 int ret;
3576
Wink Saville8eb2a122012-11-19 16:05:13 -08003577 RLOGV("processWakeupCallback");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003578
3579 /* empty our wakeup socket out */
3580 do {
3581 ret = read(s_fdWakeupRead, &buff, sizeof(buff));
Wink Saville7f856802009-06-09 10:23:37 -07003582 } while (ret > 0 || (ret < 0 && errno == EINTR));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003583}
3584
Etan Cohend3652192014-06-20 08:28:44 -07003585static void onCommandsSocketClosed(RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003586 int ret;
3587 RequestInfo *p_cur;
Etan Cohend3652192014-06-20 08:28:44 -07003588 /* Hook for current context
3589 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
3590 pthread_mutex_t * pendingRequestsMutexHook = &s_pendingRequestsMutex;
3591 /* pendingRequestsHook refer to &s_pendingRequests */
3592 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003593
Etan Cohend3652192014-06-20 08:28:44 -07003594#if (SIM_COUNT >= 2)
3595 if (socket_id == RIL_SOCKET_2) {
3596 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
3597 pendingRequestsHook = &s_pendingRequests_socket2;
3598 }
3599#if (SIM_COUNT >= 3)
3600 else if (socket_id == RIL_SOCKET_3) {
3601 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
3602 pendingRequestsHook = &s_pendingRequests_socket3;
3603 }
3604#endif
3605#if (SIM_COUNT >= 4)
3606 else if (socket_id == RIL_SOCKET_4) {
3607 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
3608 pendingRequestsHook = &s_pendingRequests_socket4;
3609 }
3610#endif
3611#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003612 /* mark pending requests as "cancelled" so we dont report responses */
Etan Cohend3652192014-06-20 08:28:44 -07003613 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003614 assert (ret == 0);
3615
Etan Cohend3652192014-06-20 08:28:44 -07003616 p_cur = *pendingRequestsHook;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003617
Etan Cohend3652192014-06-20 08:28:44 -07003618 for (p_cur = *pendingRequestsHook
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003619 ; p_cur != NULL
3620 ; p_cur = p_cur->p_next
3621 ) {
3622 p_cur->cancelled = 1;
3623 }
3624
Etan Cohend3652192014-06-20 08:28:44 -07003625 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003626 assert (ret == 0);
3627}
3628
Wink Savillef4c4d362009-04-02 01:37:03 -07003629static void processCommandsCallback(int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003630 RecordStream *p_rs;
3631 void *p_record;
3632 size_t recordlen;
3633 int ret;
Etan Cohend3652192014-06-20 08:28:44 -07003634 SocketListenParam *p_info = (SocketListenParam *)param;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003635
Etan Cohend3652192014-06-20 08:28:44 -07003636 assert(fd == p_info->fdCommand);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003637
Etan Cohend3652192014-06-20 08:28:44 -07003638 p_rs = p_info->p_rs;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003639
3640 for (;;) {
3641 /* loop until EAGAIN/EINTR, end of stream, or other error */
3642 ret = record_stream_get_next(p_rs, &p_record, &recordlen);
3643
3644 if (ret == 0 && p_record == NULL) {
3645 /* end-of-stream */
3646 break;
3647 } else if (ret < 0) {
3648 break;
3649 } else if (ret == 0) { /* && p_record != NULL */
Etan Cohend3652192014-06-20 08:28:44 -07003650 processCommandBuffer(p_record, recordlen, p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003651 }
3652 }
3653
3654 if (ret == 0 || !(errno == EAGAIN || errno == EINTR)) {
3655 /* fatal error or end-of-stream */
3656 if (ret != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003657 RLOGE("error on reading command socket errno:%d\n", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003658 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003659 RLOGW("EOS. Closing command socket.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003660 }
Wink Saville7f856802009-06-09 10:23:37 -07003661
Etan Cohend3652192014-06-20 08:28:44 -07003662 close(fd);
3663 p_info->fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003664
Etan Cohend3652192014-06-20 08:28:44 -07003665 ril_event_del(p_info->commands_event);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003666
3667 record_stream_free(p_rs);
3668
3669 /* start listening for new connections again */
3670 rilEventAddWakeup(&s_listen_event);
3671
Etan Cohend3652192014-06-20 08:28:44 -07003672 onCommandsSocketClosed(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003673 }
3674}
3675
3676
Etan Cohend3652192014-06-20 08:28:44 -07003677static void onNewCommandConnect(RIL_SOCKET_ID socket_id) {
Wink Saville5b9df332011-04-06 16:24:21 -07003678 // Inform we are connected and the ril version
Jake Hambya9c18d12011-04-12 23:32:08 -07003679 int rilVer = s_callbacks.version;
Etan Cohend3652192014-06-20 08:28:44 -07003680 RIL_UNSOL_RESPONSE(RIL_UNSOL_RIL_CONNECTED,
3681 &rilVer, sizeof(rilVer), socket_id);
Wink Saville5b9df332011-04-06 16:24:21 -07003682
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003683 // implicit radio state changed
Etan Cohend3652192014-06-20 08:28:44 -07003684 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
3685 NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003686
3687 // Send last NITZ time data, in case it was missed
3688 if (s_lastNITZTimeData != NULL) {
Etan Cohend3652192014-06-20 08:28:44 -07003689 sendResponseRaw(s_lastNITZTimeData, s_lastNITZTimeDataSize, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003690
3691 free(s_lastNITZTimeData);
3692 s_lastNITZTimeData = NULL;
3693 }
3694
3695 // Get version string
3696 if (s_callbacks.getVersion != NULL) {
3697 const char *version;
3698 version = s_callbacks.getVersion();
Wink Saville8eb2a122012-11-19 16:05:13 -08003699 RLOGI("RIL Daemon version: %s\n", version);
Wink Saville7f856802009-06-09 10:23:37 -07003700
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003701 property_set(PROPERTY_RIL_IMPL, version);
3702 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003703 RLOGI("RIL Daemon version: unavailable\n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003704 property_set(PROPERTY_RIL_IMPL, "unavailable");
3705 }
3706
3707}
3708
Wink Savillef4c4d362009-04-02 01:37:03 -07003709static void listenCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003710 int ret;
3711 int err;
3712 int is_phone_socket;
Etan Cohend3652192014-06-20 08:28:44 -07003713 int fdCommand = -1;
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003714 char* processName;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003715 RecordStream *p_rs;
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003716 MySocketListenParam* listenParam;
3717 RilSocket *sapSocket = NULL;
3718 socketClient *sClient = NULL;
3719
Etan Cohend3652192014-06-20 08:28:44 -07003720 SocketListenParam *p_info = (SocketListenParam *)param;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003721
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003722 if(RIL_SAP_SOCKET == p_info->type) {
3723 listenParam = (MySocketListenParam *)param;
3724 sapSocket = listenParam->socket;
3725 }
3726
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003727 struct sockaddr_un peeraddr;
3728 socklen_t socklen = sizeof (peeraddr);
3729
3730 struct ucred creds;
3731 socklen_t szCreds = sizeof(creds);
3732
3733 struct passwd *pwd = NULL;
3734
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003735 if(NULL == sapSocket) {
3736 assert (*p_info->fdCommand < 0);
3737 assert (fd == *p_info->fdListen);
3738 processName = PHONE_PROCESS;
3739 } else {
3740 assert (sapSocket->commandFd < 0);
3741 assert (fd == sapSocket->listenFd);
3742 processName = BLUETOOTH_PROCESS;
3743 }
3744
Wink Saville7f856802009-06-09 10:23:37 -07003745
Etan Cohend3652192014-06-20 08:28:44 -07003746 fdCommand = accept(fd, (sockaddr *) &peeraddr, &socklen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003747
Etan Cohend3652192014-06-20 08:28:44 -07003748 if (fdCommand < 0 ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003749 RLOGE("Error on accept() errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003750 /* start listening for new connections again */
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003751 if(NULL == sapSocket) {
3752 rilEventAddWakeup(p_info->listen_event);
3753 } else {
3754 rilEventAddWakeup(sapSocket->getListenEvent());
3755 }
Etan Cohend3652192014-06-20 08:28:44 -07003756 return;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003757 }
3758
3759 /* check the credential of the other side and only accept socket from
3760 * phone process
Wink Saville7f856802009-06-09 10:23:37 -07003761 */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003762 errno = 0;
3763 is_phone_socket = 0;
Wink Savillef4c4d362009-04-02 01:37:03 -07003764
Etan Cohend3652192014-06-20 08:28:44 -07003765 err = getsockopt(fdCommand, SOL_SOCKET, SO_PEERCRED, &creds, &szCreds);
Wink Savillef4c4d362009-04-02 01:37:03 -07003766
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003767 if (err == 0 && szCreds > 0) {
Wink Savillef4c4d362009-04-02 01:37:03 -07003768 errno = 0;
3769 pwd = getpwuid(creds.uid);
3770 if (pwd != NULL) {
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003771 if (strcmp(pwd->pw_name, processName) == 0) {
Wink Savillef4c4d362009-04-02 01:37:03 -07003772 is_phone_socket = 1;
3773 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003774 RLOGE("RILD can't accept socket from process %s", pwd->pw_name);
Wink Savillef4c4d362009-04-02 01:37:03 -07003775 }
3776 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003777 RLOGE("Error on getpwuid() errno: %d", errno);
Wink Savillef4c4d362009-04-02 01:37:03 -07003778 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003779 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003780 RLOGD("Error on getsockopt() errno: %d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003781 }
3782
Etan Cohend3652192014-06-20 08:28:44 -07003783 if (!is_phone_socket) {
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003784 RLOGE("RILD must accept socket from %s", processName);
Wink Saville7f856802009-06-09 10:23:37 -07003785
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003786 close(fdCommand);
3787 fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003788
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003789 if(NULL == sapSocket) {
3790 onCommandsSocketClosed(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003791
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003792 /* start listening for new connections again */
3793 rilEventAddWakeup(p_info->listen_event);
3794 } else {
3795 sapSocket->onCommandsSocketClosed();
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003796
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003797 /* start listening for new connections again */
3798 rilEventAddWakeup(sapSocket->getListenEvent());
3799 }
3800
3801 return;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003802 }
3803
Etan Cohend3652192014-06-20 08:28:44 -07003804 ret = fcntl(fdCommand, F_SETFL, O_NONBLOCK);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003805
3806 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003807 RLOGE ("Error setting O_NONBLOCK errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003808 }
3809
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003810 if(NULL == sapSocket) {
3811 RLOGI("libril: new connection to %s", rilSocketIdToString(p_info->socket_id));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003812
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003813 p_info->fdCommand = fdCommand;
3814 p_rs = record_stream_new(p_info->fdCommand, MAX_COMMAND_BYTES);
3815 p_info->p_rs = p_rs;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003816
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003817 ril_event_set (p_info->commands_event, p_info->fdCommand, 1,
Etan Cohend3652192014-06-20 08:28:44 -07003818 p_info->processCommandsCallback, p_info);
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003819 rilEventAddWakeup (p_info->commands_event);
Etan Cohend3652192014-06-20 08:28:44 -07003820
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003821 onNewCommandConnect(p_info->socket_id);
3822 } else {
3823 RLOGI("libril: new connection");
Etan Cohend3652192014-06-20 08:28:44 -07003824
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003825 sapSocket->setCommandFd(fdCommand);
3826 p_rs = record_stream_new(sapSocket->getCommandFd(), MAX_COMMAND_BYTES);
3827 sClient = new socketClient(sapSocket,p_rs);
3828 ril_event_set (sapSocket->getCallbackEvent(), sapSocket->getCommandFd(), 1,
3829 sapSocket->getCommandCb(), sClient);
3830
3831 rilEventAddWakeup(sapSocket->getCallbackEvent());
3832 sapSocket->onNewCommandConnect();
3833 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003834}
3835
3836static void freeDebugCallbackArgs(int number, char **args) {
3837 for (int i = 0; i < number; i++) {
3838 if (args[i] != NULL) {
3839 free(args[i]);
3840 }
3841 }
3842 free(args);
3843}
3844
Wink Savillef4c4d362009-04-02 01:37:03 -07003845static void debugCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003846 int acceptFD, option;
3847 struct sockaddr_un peeraddr;
3848 socklen_t socklen = sizeof (peeraddr);
3849 int data;
3850 unsigned int qxdm_data[6];
3851 const char *deactData[1] = {"1"};
3852 char *actData[1];
3853 RIL_Dial dialData;
3854 int hangupData[1] = {1};
3855 int number;
3856 char **args;
Etan Cohend3652192014-06-20 08:28:44 -07003857 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
3858 int sim_id = 0;
3859
3860 RLOGI("debugCallback for socket %s", rilSocketIdToString(socket_id));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003861
3862 acceptFD = accept (fd, (sockaddr *) &peeraddr, &socklen);
3863
3864 if (acceptFD < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003865 RLOGE ("error accepting on debug port: %d\n", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003866 return;
3867 }
3868
3869 if (recv(acceptFD, &number, sizeof(int), 0) != sizeof(int)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003870 RLOGE ("error reading on socket: number of Args: \n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003871 return;
3872 }
3873 args = (char **) malloc(sizeof(char*) * number);
3874
3875 for (int i = 0; i < number; i++) {
3876 int len;
3877 if (recv(acceptFD, &len, sizeof(int), 0) != sizeof(int)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003878 RLOGE ("error reading on socket: Len of Args: \n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003879 freeDebugCallbackArgs(i, args);
3880 return;
3881 }
3882 // +1 for null-term
3883 args[i] = (char *) malloc((sizeof(char) * len) + 1);
Wink Saville7f856802009-06-09 10:23:37 -07003884 if (recv(acceptFD, args[i], sizeof(char) * len, 0)
Wink Saville1b5fd232009-04-22 14:50:00 -07003885 != (int)sizeof(char) * len) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003886 RLOGE ("error reading on socket: Args[%d] \n", i);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003887 freeDebugCallbackArgs(i, args);
3888 return;
3889 }
3890 char * buf = args[i];
3891 buf[len] = 0;
Etan Cohend3652192014-06-20 08:28:44 -07003892 if ((i+1) == number) {
3893 /* The last argument should be sim id 0(SIM1)~3(SIM4) */
3894 sim_id = atoi(args[i]);
3895 switch (sim_id) {
3896 case 0:
3897 socket_id = RIL_SOCKET_1;
3898 break;
3899 #if (SIM_COUNT >= 2)
3900 case 1:
3901 socket_id = RIL_SOCKET_2;
3902 break;
3903 #endif
3904 #if (SIM_COUNT >= 3)
3905 case 2:
3906 socket_id = RIL_SOCKET_3;
3907 break;
3908 #endif
3909 #if (SIM_COUNT >= 4)
3910 case 3:
3911 socket_id = RIL_SOCKET_4;
3912 break;
3913 #endif
3914 default:
3915 socket_id = RIL_SOCKET_1;
3916 break;
3917 }
3918 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003919 }
3920
3921 switch (atoi(args[0])) {
3922 case 0:
Wink Saville8eb2a122012-11-19 16:05:13 -08003923 RLOGI ("Connection on debug port: issuing reset.");
Etan Cohend3652192014-06-20 08:28:44 -07003924 issueLocalRequest(RIL_REQUEST_RESET_RADIO, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003925 break;
3926 case 1:
Wink Saville8eb2a122012-11-19 16:05:13 -08003927 RLOGI ("Connection on debug port: issuing radio power off.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003928 data = 0;
Etan Cohend3652192014-06-20 08:28:44 -07003929 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003930 // Close the socket
Etan Cohend3652192014-06-20 08:28:44 -07003931 if (socket_id == RIL_SOCKET_1 && s_ril_param_socket.fdCommand > 0) {
3932 close(s_ril_param_socket.fdCommand);
3933 s_ril_param_socket.fdCommand = -1;
3934 }
3935 #if (SIM_COUNT == 2)
3936 else if (socket_id == RIL_SOCKET_2 && s_ril_param_socket2.fdCommand > 0) {
3937 close(s_ril_param_socket2.fdCommand);
3938 s_ril_param_socket2.fdCommand = -1;
3939 }
3940 #endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003941 break;
3942 case 2:
Wink Saville8eb2a122012-11-19 16:05:13 -08003943 RLOGI ("Debug port: issuing unsolicited voice network change.");
Etan Cohend3652192014-06-20 08:28:44 -07003944 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003945 break;
3946 case 3:
Wink Saville8eb2a122012-11-19 16:05:13 -08003947 RLOGI ("Debug port: QXDM log enable.");
Xia Wangd855ef42010-07-27 17:26:55 -07003948 qxdm_data[0] = 65536; // head.func_tag
3949 qxdm_data[1] = 16; // head.len
3950 qxdm_data[2] = 1; // mode: 1 for 'start logging'
3951 qxdm_data[3] = 32; // log_file_size: 32megabytes
3952 qxdm_data[4] = 0; // log_mask
3953 qxdm_data[5] = 8; // log_max_fileindex
Wink Saville7f856802009-06-09 10:23:37 -07003954 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Etan Cohend3652192014-06-20 08:28:44 -07003955 6 * sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003956 break;
3957 case 4:
Wink Saville8eb2a122012-11-19 16:05:13 -08003958 RLOGI ("Debug port: QXDM log disable.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003959 qxdm_data[0] = 65536;
3960 qxdm_data[1] = 16;
Xia Wangd855ef42010-07-27 17:26:55 -07003961 qxdm_data[2] = 0; // mode: 0 for 'stop logging'
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003962 qxdm_data[3] = 32;
3963 qxdm_data[4] = 0;
Xia Wangd855ef42010-07-27 17:26:55 -07003964 qxdm_data[5] = 8;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003965 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Etan Cohend3652192014-06-20 08:28:44 -07003966 6 * sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003967 break;
3968 case 5:
Wink Saville8eb2a122012-11-19 16:05:13 -08003969 RLOGI("Debug port: Radio On");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003970 data = 1;
Etan Cohend3652192014-06-20 08:28:44 -07003971 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003972 sleep(2);
3973 // Set network selection automatic.
Etan Cohend3652192014-06-20 08:28:44 -07003974 issueLocalRequest(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003975 break;
3976 case 6:
Wink Saville8eb2a122012-11-19 16:05:13 -08003977 RLOGI("Debug port: Setup Data Call, Apn :%s\n", args[1]);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003978 actData[0] = args[1];
Wink Saville7f856802009-06-09 10:23:37 -07003979 issueLocalRequest(RIL_REQUEST_SETUP_DATA_CALL, &actData,
Etan Cohend3652192014-06-20 08:28:44 -07003980 sizeof(actData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003981 break;
3982 case 7:
Wink Saville8eb2a122012-11-19 16:05:13 -08003983 RLOGI("Debug port: Deactivate Data Call");
Wink Saville7f856802009-06-09 10:23:37 -07003984 issueLocalRequest(RIL_REQUEST_DEACTIVATE_DATA_CALL, &deactData,
Etan Cohend3652192014-06-20 08:28:44 -07003985 sizeof(deactData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003986 break;
3987 case 8:
Wink Saville8eb2a122012-11-19 16:05:13 -08003988 RLOGI("Debug port: Dial Call");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003989 dialData.clir = 0;
3990 dialData.address = args[1];
Etan Cohend3652192014-06-20 08:28:44 -07003991 issueLocalRequest(RIL_REQUEST_DIAL, &dialData, sizeof(dialData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003992 break;
3993 case 9:
Wink Saville8eb2a122012-11-19 16:05:13 -08003994 RLOGI("Debug port: Answer Call");
Etan Cohend3652192014-06-20 08:28:44 -07003995 issueLocalRequest(RIL_REQUEST_ANSWER, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003996 break;
3997 case 10:
Wink Saville8eb2a122012-11-19 16:05:13 -08003998 RLOGI("Debug port: End Call");
Wink Saville7f856802009-06-09 10:23:37 -07003999 issueLocalRequest(RIL_REQUEST_HANGUP, &hangupData,
Etan Cohend3652192014-06-20 08:28:44 -07004000 sizeof(hangupData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004001 break;
4002 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004003 RLOGE ("Invalid request");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004004 break;
4005 }
4006 freeDebugCallbackArgs(number, args);
4007 close(acceptFD);
4008}
4009
4010
Wink Savillef4c4d362009-04-02 01:37:03 -07004011static void userTimerCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004012 UserCallbackInfo *p_info;
4013
4014 p_info = (UserCallbackInfo *)param;
4015
4016 p_info->p_callback(p_info->userParam);
4017
4018
4019 // FIXME generalize this...there should be a cancel mechanism
4020 if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) {
4021 s_last_wake_timeout_info = NULL;
4022 }
4023
4024 free(p_info);
4025}
4026
4027
4028static void *
Wink Savillef4c4d362009-04-02 01:37:03 -07004029eventLoop(void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004030 int ret;
4031 int filedes[2];
4032
4033 ril_event_init();
4034
4035 pthread_mutex_lock(&s_startupMutex);
4036
4037 s_started = 1;
4038 pthread_cond_broadcast(&s_startupCond);
4039
4040 pthread_mutex_unlock(&s_startupMutex);
4041
4042 ret = pipe(filedes);
4043
4044 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004045 RLOGE("Error in pipe() errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004046 return NULL;
4047 }
4048
4049 s_fdWakeupRead = filedes[0];
4050 s_fdWakeupWrite = filedes[1];
4051
4052 fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK);
4053
4054 ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,
4055 processWakeupCallback, NULL);
4056
4057 rilEventAddWakeup (&s_wakeupfd_event);
4058
4059 // Only returns on error
4060 ril_event_loop();
Wink Saville8eb2a122012-11-19 16:05:13 -08004061 RLOGE ("error in event_loop_base errno:%d", errno);
Kazuhiro Ondo5cdc1352011-10-14 17:50:58 -05004062 // kill self to restart on error
4063 kill(0, SIGKILL);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004064
4065 return NULL;
4066}
4067
Wink Saville7f856802009-06-09 10:23:37 -07004068extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07004069RIL_startEventLoop(void) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004070 /* spin up eventLoop thread and wait for it to get started */
4071 s_started = 0;
4072 pthread_mutex_lock(&s_startupMutex);
4073
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004074 pthread_attr_t attr;
4075 pthread_attr_init(&attr);
Wink Saville7f856802009-06-09 10:23:37 -07004076 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004077
Elliott Hughesfd81e712014-01-06 12:46:02 -08004078 int result = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
4079 if (result != 0) {
4080 RLOGE("Failed to create dispatch thread: %s", strerror(result));
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004081 goto done;
4082 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004083
4084 while (s_started == 0) {
4085 pthread_cond_wait(&s_startupCond, &s_startupMutex);
4086 }
4087
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004088done:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004089 pthread_mutex_unlock(&s_startupMutex);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004090}
4091
4092// Used for testing purpose only.
4093extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) {
4094 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4095}
4096
Etan Cohend3652192014-06-20 08:28:44 -07004097static void startListen(RIL_SOCKET_ID socket_id, SocketListenParam* socket_listen_p) {
4098 int fdListen = -1;
4099 int ret;
4100 char socket_name[10];
4101
4102 memset(socket_name, 0, sizeof(char)*10);
4103
4104 switch(socket_id) {
4105 case RIL_SOCKET_1:
4106 strncpy(socket_name, RIL_getRilSocketName(), 9);
4107 break;
4108 #if (SIM_COUNT >= 2)
4109 case RIL_SOCKET_2:
4110 strncpy(socket_name, SOCKET2_NAME_RIL, 9);
4111 break;
4112 #endif
4113 #if (SIM_COUNT >= 3)
4114 case RIL_SOCKET_3:
4115 strncpy(socket_name, SOCKET3_NAME_RIL, 9);
4116 break;
4117 #endif
4118 #if (SIM_COUNT >= 4)
4119 case RIL_SOCKET_4:
4120 strncpy(socket_name, SOCKET4_NAME_RIL, 9);
4121 break;
4122 #endif
4123 default:
4124 RLOGE("Socket id is wrong!!");
4125 return;
4126 }
4127
4128 RLOGI("Start to listen %s", rilSocketIdToString(socket_id));
4129
4130 fdListen = android_get_control_socket(socket_name);
4131 if (fdListen < 0) {
4132 RLOGE("Failed to get socket %s", socket_name);
4133 exit(-1);
4134 }
4135
4136 ret = listen(fdListen, 4);
4137
4138 if (ret < 0) {
4139 RLOGE("Failed to listen on control socket '%d': %s",
4140 fdListen, strerror(errno));
4141 exit(-1);
4142 }
4143 socket_listen_p->fdListen = fdListen;
4144
4145 /* note: non-persistent so we can accept only one connection at a time */
4146 ril_event_set (socket_listen_p->listen_event, fdListen, false,
4147 listenCallback, socket_listen_p);
4148
4149 rilEventAddWakeup (socket_listen_p->listen_event);
4150}
4151
Wink Saville7f856802009-06-09 10:23:37 -07004152extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07004153RIL_register (const RIL_RadioFunctions *callbacks) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004154 int ret;
4155 int flags;
4156
Etan Cohend3652192014-06-20 08:28:44 -07004157 RLOGI("SIM_COUNT: %d", SIM_COUNT);
4158
Wink Saville43808972011-01-13 17:39:51 -08004159 if (callbacks == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004160 RLOGE("RIL_register: RIL_RadioFunctions * null");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004161 return;
4162 }
Wink Saville43808972011-01-13 17:39:51 -08004163 if (callbacks->version < RIL_VERSION_MIN) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004164 RLOGE("RIL_register: version %d is to old, min version is %d",
Wink Saville43808972011-01-13 17:39:51 -08004165 callbacks->version, RIL_VERSION_MIN);
4166 return;
Wink Saville3a4840b2010-04-07 13:29:58 -07004167 }
Wink Saville43808972011-01-13 17:39:51 -08004168 if (callbacks->version > RIL_VERSION) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004169 RLOGE("RIL_register: version %d is too new, max version is %d",
Wink Saville43808972011-01-13 17:39:51 -08004170 callbacks->version, RIL_VERSION);
4171 return;
4172 }
Wink Saville8eb2a122012-11-19 16:05:13 -08004173 RLOGE("RIL_register: RIL version %d", callbacks->version);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004174
4175 if (s_registerCalled > 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004176 RLOGE("RIL_register has been called more than once. "
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004177 "Subsequent call ignored");
4178 return;
4179 }
4180
4181 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4182
Etan Cohend3652192014-06-20 08:28:44 -07004183 /* Initialize socket1 parameters */
4184 s_ril_param_socket = {
4185 RIL_SOCKET_1, /* socket_id */
4186 -1, /* fdListen */
4187 -1, /* fdCommand */
4188 PHONE_PROCESS, /* processName */
4189 &s_commands_event, /* commands_event */
4190 &s_listen_event, /* listen_event */
4191 processCommandsCallback, /* processCommandsCallback */
4192 NULL /* p_rs */
4193 };
4194
4195#if (SIM_COUNT >= 2)
4196 s_ril_param_socket2 = {
4197 RIL_SOCKET_2, /* socket_id */
4198 -1, /* fdListen */
4199 -1, /* fdCommand */
4200 PHONE_PROCESS, /* processName */
4201 &s_commands_event_socket2, /* commands_event */
4202 &s_listen_event_socket2, /* listen_event */
4203 processCommandsCallback, /* processCommandsCallback */
4204 NULL /* p_rs */
4205 };
4206#endif
4207
4208#if (SIM_COUNT >= 3)
4209 s_ril_param_socket3 = {
4210 RIL_SOCKET_3, /* socket_id */
4211 -1, /* fdListen */
4212 -1, /* fdCommand */
4213 PHONE_PROCESS, /* processName */
4214 &s_commands_event_socket3, /* commands_event */
4215 &s_listen_event_socket3, /* listen_event */
4216 processCommandsCallback, /* processCommandsCallback */
4217 NULL /* p_rs */
4218 };
4219#endif
4220
4221#if (SIM_COUNT >= 4)
4222 s_ril_param_socket4 = {
4223 RIL_SOCKET_4, /* socket_id */
4224 -1, /* fdListen */
4225 -1, /* fdCommand */
4226 PHONE_PROCESS, /* processName */
4227 &s_commands_event_socket4, /* commands_event */
4228 &s_listen_event_socket4, /* listen_event */
4229 processCommandsCallback, /* processCommandsCallback */
4230 NULL /* p_rs */
4231 };
4232#endif
4233
4234
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004235 s_registerCalled = 1;
4236
Etan Cohend3652192014-06-20 08:28:44 -07004237 RLOGI("s_registerCalled flag set, %d", s_started);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004238 // Little self-check
4239
Wink Savillef4c4d362009-04-02 01:37:03 -07004240 for (int i = 0; i < (int)NUM_ELEMS(s_commands); i++) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004241 assert(i == s_commands[i].requestNumber);
4242 }
4243
Wink Savillef4c4d362009-04-02 01:37:03 -07004244 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses); i++) {
Wink Saville7f856802009-06-09 10:23:37 -07004245 assert(i + RIL_UNSOL_RESPONSE_BASE
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004246 == s_unsolResponses[i].requestNumber);
4247 }
4248
4249 // New rild impl calls RIL_startEventLoop() first
4250 // old standalone impl wants it here.
4251
4252 if (s_started == 0) {
4253 RIL_startEventLoop();
4254 }
4255
Etan Cohend3652192014-06-20 08:28:44 -07004256 // start listen socket1
4257 startListen(RIL_SOCKET_1, &s_ril_param_socket);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004258
Etan Cohend3652192014-06-20 08:28:44 -07004259#if (SIM_COUNT >= 2)
4260 // start listen socket2
4261 startListen(RIL_SOCKET_2, &s_ril_param_socket2);
4262#endif /* (SIM_COUNT == 2) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004263
Etan Cohend3652192014-06-20 08:28:44 -07004264#if (SIM_COUNT >= 3)
4265 // start listen socket3
4266 startListen(RIL_SOCKET_3, &s_ril_param_socket3);
4267#endif /* (SIM_COUNT == 3) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004268
Etan Cohend3652192014-06-20 08:28:44 -07004269#if (SIM_COUNT >= 4)
4270 // start listen socket4
4271 startListen(RIL_SOCKET_4, &s_ril_param_socket4);
4272#endif /* (SIM_COUNT == 4) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004273
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004274
4275#if 1
4276 // start debug interface socket
4277
Etan Cohend3652192014-06-20 08:28:44 -07004278 char *inst = NULL;
4279 if (strlen(RIL_getRilSocketName()) >= strlen(SOCKET_NAME_RIL)) {
4280 inst = RIL_getRilSocketName() + strlen(SOCKET_NAME_RIL);
4281 }
4282
4283 char rildebug[MAX_DEBUG_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL_DEBUG;
4284 if (inst != NULL) {
4285 strncat(rildebug, inst, MAX_DEBUG_SOCKET_NAME_LENGTH);
4286 }
4287
4288 s_fdDebug = android_get_control_socket(rildebug);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004289 if (s_fdDebug < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07004290 RLOGE("Failed to get socket : %s errno:%d", rildebug, errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004291 exit(-1);
4292 }
4293
4294 ret = listen(s_fdDebug, 4);
4295
4296 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004297 RLOGE("Failed to listen on ril debug socket '%d': %s",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004298 s_fdDebug, strerror(errno));
4299 exit(-1);
4300 }
4301
4302 ril_event_set (&s_debug_event, s_fdDebug, true,
4303 debugCallback, NULL);
4304
4305 rilEventAddWakeup (&s_debug_event);
4306#endif
4307
4308}
4309
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004310extern "C" void
4311RIL_register_socket (RIL_RadioFunctions *(*Init)(const struct RIL_Env *, int, char **),RIL_SOCKET_TYPE socketType, int argc, char **argv) {
4312
4313 RIL_RadioFunctions* UimFuncs = NULL;
4314
4315 if(Init) {
4316 UimFuncs = Init(&RilSapSocket::uimRilEnv, argc, argv);
4317
4318 switch(socketType) {
4319 case RIL_SAP_SOCKET:
4320 RilSapSocket::initSapSocket("sap_uim_socket1", UimFuncs);
4321
4322#if (SIM_COUNT >= 2)
4323 RilSapSocket::initSapSocket("sap_uim_socket2", UimFuncs);
4324#endif
4325
4326#if (SIM_COUNT >= 3)
4327 RilSapSocket::initSapSocket("sap_uim_socket3", UimFuncs);
4328#endif
4329
4330#if (SIM_COUNT >= 4)
4331 RilSapSocket::initSapSocket("sap_uim_socket4", UimFuncs);
4332#endif
4333 }
4334 }
4335}
4336
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004337static int
Wink Savillef4c4d362009-04-02 01:37:03 -07004338checkAndDequeueRequestInfo(struct RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004339 int ret = 0;
Etan Cohend3652192014-06-20 08:28:44 -07004340 /* Hook for current context
4341 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
4342 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
4343 /* pendingRequestsHook refer to &s_pendingRequests */
4344 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
Wink Saville7f856802009-06-09 10:23:37 -07004345
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004346 if (pRI == NULL) {
4347 return 0;
4348 }
4349
Etan Cohend3652192014-06-20 08:28:44 -07004350#if (SIM_COUNT >= 2)
4351 if (pRI->socket_id == RIL_SOCKET_2) {
4352 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
4353 pendingRequestsHook = &s_pendingRequests_socket2;
4354 }
4355#if (SIM_COUNT >= 3)
4356 if (pRI->socket_id == RIL_SOCKET_3) {
4357 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
4358 pendingRequestsHook = &s_pendingRequests_socket3;
4359 }
4360#endif
4361#if (SIM_COUNT >= 4)
4362 if (pRI->socket_id == RIL_SOCKET_4) {
4363 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
4364 pendingRequestsHook = &s_pendingRequests_socket4;
4365 }
4366#endif
4367#endif
4368 pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004369
Etan Cohend3652192014-06-20 08:28:44 -07004370 for(RequestInfo **ppCur = pendingRequestsHook
Wink Saville7f856802009-06-09 10:23:37 -07004371 ; *ppCur != NULL
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004372 ; ppCur = &((*ppCur)->p_next)
4373 ) {
4374 if (pRI == *ppCur) {
4375 ret = 1;
4376
4377 *ppCur = (*ppCur)->p_next;
4378 break;
4379 }
4380 }
4381
Etan Cohend3652192014-06-20 08:28:44 -07004382 pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004383
4384 return ret;
4385}
4386
4387
4388extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07004389RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004390 RequestInfo *pRI;
4391 int ret;
Etan Cohend3652192014-06-20 08:28:44 -07004392 int fd = s_ril_param_socket.fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004393 size_t errorOffset;
Etan Cohend3652192014-06-20 08:28:44 -07004394 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004395
4396 pRI = (RequestInfo *)t;
4397
Jayachandran C6c607592014-08-04 15:48:01 -07004398 if (!checkAndDequeueRequestInfo(pRI)) {
4399 RLOGE ("RIL_onRequestComplete: invalid RIL_Token");
4400 return;
4401 }
4402
Etan Cohend3652192014-06-20 08:28:44 -07004403 socket_id = pRI->socket_id;
4404#if (SIM_COUNT >= 2)
4405 if (socket_id == RIL_SOCKET_2) {
4406 fd = s_ril_param_socket2.fdCommand;
4407 }
4408#if (SIM_COUNT >= 3)
4409 if (socket_id == RIL_SOCKET_3) {
4410 fd = s_ril_param_socket3.fdCommand;
4411 }
4412#endif
4413#if (SIM_COUNT >= 4)
4414 if (socket_id == RIL_SOCKET_4) {
4415 fd = s_ril_param_socket4.fdCommand;
4416 }
4417#endif
4418#endif
4419 RLOGD("RequestComplete, %s", rilSocketIdToString(socket_id));
4420
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004421 if (pRI->local > 0) {
4422 // Locally issued command...void only!
4423 // response does not go back up the command socket
Wink Saville8eb2a122012-11-19 16:05:13 -08004424 RLOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004425
4426 goto done;
4427 }
4428
4429 appendPrintBuf("[%04d]< %s",
4430 pRI->token, requestToString(pRI->pCI->requestNumber));
4431
4432 if (pRI->cancelled == 0) {
4433 Parcel p;
4434
4435 p.writeInt32 (RESPONSE_SOLICITED);
4436 p.writeInt32 (pRI->token);
4437 errorOffset = p.dataPosition();
4438
4439 p.writeInt32 (e);
4440
johnwangb2a61842009-06-02 14:55:45 -07004441 if (response != NULL) {
4442 // there is a response payload, no matter success or not.
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004443 ret = pRI->pCI->responseFunction(p, response, responselen);
4444
4445 /* if an error occurred, rewind and mark it */
4446 if (ret != 0) {
Etan Cohend3652192014-06-20 08:28:44 -07004447 RLOGE ("responseFunction error, ret %d", ret);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004448 p.setDataPosition(errorOffset);
4449 p.writeInt32 (ret);
4450 }
johnwangb2a61842009-06-02 14:55:45 -07004451 }
4452
4453 if (e != RIL_E_SUCCESS) {
4454 appendPrintBuf("%s fails by %s", printBuf, failCauseToString(e));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004455 }
4456
Etan Cohend3652192014-06-20 08:28:44 -07004457 if (fd < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004458 RLOGD ("RIL onRequestComplete: Command channel closed");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004459 }
Etan Cohend3652192014-06-20 08:28:44 -07004460 sendResponse(p, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004461 }
4462
4463done:
4464 free(pRI);
4465}
4466
4467
4468static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004469grabPartialWakeLock() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004470 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
4471}
4472
4473static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004474releaseWakeLock() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004475 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
4476}
4477
4478/**
4479 * Timer callback to put us back to sleep before the default timeout
4480 */
4481static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004482wakeTimeoutCallback (void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004483 // We're using "param != NULL" as a cancellation mechanism
4484 if (param == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004485 //RLOGD("wakeTimeout: releasing wake lock");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004486
4487 releaseWakeLock();
4488 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08004489 //RLOGD("wakeTimeout: releasing wake lock CANCELLED");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004490 }
4491}
4492
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004493static int
4494decodeVoiceRadioTechnology (RIL_RadioState radioState) {
4495 switch (radioState) {
4496 case RADIO_STATE_SIM_NOT_READY:
4497 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4498 case RADIO_STATE_SIM_READY:
4499 return RADIO_TECH_UMTS;
4500
4501 case RADIO_STATE_RUIM_NOT_READY:
4502 case RADIO_STATE_RUIM_READY:
4503 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4504 case RADIO_STATE_NV_NOT_READY:
4505 case RADIO_STATE_NV_READY:
4506 return RADIO_TECH_1xRTT;
4507
4508 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004509 RLOGD("decodeVoiceRadioTechnology: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004510 return -1;
4511 }
4512}
4513
4514static int
4515decodeCdmaSubscriptionSource (RIL_RadioState radioState) {
4516 switch (radioState) {
4517 case RADIO_STATE_SIM_NOT_READY:
4518 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4519 case RADIO_STATE_SIM_READY:
4520 case RADIO_STATE_RUIM_NOT_READY:
4521 case RADIO_STATE_RUIM_READY:
4522 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4523 return CDMA_SUBSCRIPTION_SOURCE_RUIM_SIM;
4524
4525 case RADIO_STATE_NV_NOT_READY:
4526 case RADIO_STATE_NV_READY:
4527 return CDMA_SUBSCRIPTION_SOURCE_NV;
4528
4529 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004530 RLOGD("decodeCdmaSubscriptionSource: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004531 return -1;
4532 }
4533}
4534
4535static int
4536decodeSimStatus (RIL_RadioState radioState) {
4537 switch (radioState) {
4538 case RADIO_STATE_SIM_NOT_READY:
4539 case RADIO_STATE_RUIM_NOT_READY:
4540 case RADIO_STATE_NV_NOT_READY:
4541 case RADIO_STATE_NV_READY:
4542 return -1;
4543 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4544 case RADIO_STATE_SIM_READY:
4545 case RADIO_STATE_RUIM_READY:
4546 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4547 return radioState;
4548 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004549 RLOGD("decodeSimStatus: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004550 return -1;
4551 }
4552}
4553
4554static bool is3gpp2(int radioTech) {
4555 switch (radioTech) {
4556 case RADIO_TECH_IS95A:
4557 case RADIO_TECH_IS95B:
4558 case RADIO_TECH_1xRTT:
4559 case RADIO_TECH_EVDO_0:
4560 case RADIO_TECH_EVDO_A:
4561 case RADIO_TECH_EVDO_B:
4562 case RADIO_TECH_EHRPD:
4563 return true;
4564 default:
4565 return false;
4566 }
4567}
4568
4569/* If RIL sends SIM states or RUIM states, store the voice radio
4570 * technology and subscription source information so that they can be
4571 * returned when telephony framework requests them
4572 */
4573static RIL_RadioState
Etan Cohend3652192014-06-20 08:28:44 -07004574processRadioState(RIL_RadioState newRadioState, RIL_SOCKET_ID socket_id) {
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004575
4576 if((newRadioState > RADIO_STATE_UNAVAILABLE) && (newRadioState < RADIO_STATE_ON)) {
4577 int newVoiceRadioTech;
4578 int newCdmaSubscriptionSource;
4579 int newSimStatus;
4580
4581 /* This is old RIL. Decode Subscription source and Voice Radio Technology
4582 from Radio State and send change notifications if there has been a change */
4583 newVoiceRadioTech = decodeVoiceRadioTechnology(newRadioState);
4584 if(newVoiceRadioTech != voiceRadioTech) {
4585 voiceRadioTech = newVoiceRadioTech;
Etan Cohend3652192014-06-20 08:28:44 -07004586 RIL_UNSOL_RESPONSE(RIL_UNSOL_VOICE_RADIO_TECH_CHANGED,
4587 &voiceRadioTech, sizeof(voiceRadioTech), socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004588 }
4589 if(is3gpp2(newVoiceRadioTech)) {
4590 newCdmaSubscriptionSource = decodeCdmaSubscriptionSource(newRadioState);
4591 if(newCdmaSubscriptionSource != cdmaSubscriptionSource) {
4592 cdmaSubscriptionSource = newCdmaSubscriptionSource;
Etan Cohend3652192014-06-20 08:28:44 -07004593 RIL_UNSOL_RESPONSE(RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED,
4594 &cdmaSubscriptionSource, sizeof(cdmaSubscriptionSource), socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004595 }
4596 }
4597 newSimStatus = decodeSimStatus(newRadioState);
4598 if(newSimStatus != simRuimStatus) {
4599 simRuimStatus = newSimStatus;
Etan Cohend3652192014-06-20 08:28:44 -07004600 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0, socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004601 }
4602
4603 /* Send RADIO_ON to telephony */
4604 newRadioState = RADIO_STATE_ON;
4605 }
4606
4607 return newRadioState;
4608}
4609
Etan Cohend3652192014-06-20 08:28:44 -07004610
4611#if defined(ANDROID_MULTI_SIM)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004612extern "C"
Etan Cohend3652192014-06-20 08:28:44 -07004613void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
4614 size_t datalen, RIL_SOCKET_ID socket_id)
4615#else
4616extern "C"
4617void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004618 size_t datalen)
Etan Cohend3652192014-06-20 08:28:44 -07004619#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004620{
4621 int unsolResponseIndex;
4622 int ret;
4623 int64_t timeReceived = 0;
4624 bool shouldScheduleTimeout = false;
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004625 RIL_RadioState newState;
Etan Cohend3652192014-06-20 08:28:44 -07004626 RIL_SOCKET_ID soc_id = RIL_SOCKET_1;
4627
4628#if defined(ANDROID_MULTI_SIM)
4629 soc_id = socket_id;
4630#endif
4631
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004632
4633 if (s_registerCalled == 0) {
4634 // Ignore RIL_onUnsolicitedResponse before RIL_register
Wink Saville8eb2a122012-11-19 16:05:13 -08004635 RLOGW("RIL_onUnsolicitedResponse called before RIL_register");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004636 return;
4637 }
Wink Saville7f856802009-06-09 10:23:37 -07004638
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004639 unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
4640
4641 if ((unsolResponseIndex < 0)
4642 || (unsolResponseIndex >= (int32_t)NUM_ELEMS(s_unsolResponses))) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004643 RLOGE("unsupported unsolicited response code %d", unsolResponse);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004644 return;
4645 }
4646
4647 // Grab a wake lock if needed for this reponse,
4648 // as we exit we'll either release it immediately
4649 // or set a timer to release it later.
4650 switch (s_unsolResponses[unsolResponseIndex].wakeType) {
4651 case WAKE_PARTIAL:
4652 grabPartialWakeLock();
4653 shouldScheduleTimeout = true;
4654 break;
4655
4656 case DONT_WAKE:
4657 default:
4658 // No wake lock is grabed so don't set timeout
4659 shouldScheduleTimeout = false;
4660 break;
4661 }
4662
4663 // Mark the time this was received, doing this
4664 // after grabing the wakelock incase getting
4665 // the elapsedRealTime might cause us to goto
4666 // sleep.
4667 if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4668 timeReceived = elapsedRealtime();
4669 }
4670
4671 appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
4672
4673 Parcel p;
4674
4675 p.writeInt32 (RESPONSE_UNSOLICITED);
4676 p.writeInt32 (unsolResponse);
4677
4678 ret = s_unsolResponses[unsolResponseIndex]
Bernhard Rosenkränzer6e7c1962013-12-12 10:01:10 +01004679 .responseFunction(p, const_cast<void*>(data), datalen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004680 if (ret != 0) {
4681 // Problem with the response. Don't continue;
4682 goto error_exit;
4683 }
4684
4685 // some things get more payload
4686 switch(unsolResponse) {
4687 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
Etan Cohend3652192014-06-20 08:28:44 -07004688 newState = processRadioState(CALL_ONSTATEREQUEST(soc_id), soc_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004689 p.writeInt32(newState);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004690 appendPrintBuf("%s {%s}", printBuf,
Etan Cohend3652192014-06-20 08:28:44 -07004691 radioStateToString(CALL_ONSTATEREQUEST(soc_id)));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004692 break;
4693
4694
4695 case RIL_UNSOL_NITZ_TIME_RECEIVED:
4696 // Store the time that this was received so the
4697 // handler of this message can account for
4698 // the time it takes to arrive and process. In
4699 // particular the system has been known to sleep
4700 // before this message can be processed.
4701 p.writeInt64(timeReceived);
4702 break;
4703 }
4704
Etan Cohend3652192014-06-20 08:28:44 -07004705 RLOGI("%s UNSOLICITED: %s length:%d", rilSocketIdToString(soc_id), requestToString(unsolResponse), p.dataSize());
4706 ret = sendResponse(p, soc_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004707 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4708
4709 // Unfortunately, NITZ time is not poll/update like everything
4710 // else in the system. So, if the upstream client isn't connected,
4711 // keep a copy of the last NITZ response (with receive time noted
4712 // above) around so we can deliver it when it is connected
4713
4714 if (s_lastNITZTimeData != NULL) {
4715 free (s_lastNITZTimeData);
4716 s_lastNITZTimeData = NULL;
4717 }
4718
4719 s_lastNITZTimeData = malloc(p.dataSize());
4720 s_lastNITZTimeDataSize = p.dataSize();
4721 memcpy(s_lastNITZTimeData, p.data(), p.dataSize());
4722 }
4723
4724 // For now, we automatically go back to sleep after TIMEVAL_WAKE_TIMEOUT
4725 // FIXME The java code should handshake here to release wake lock
4726
4727 if (shouldScheduleTimeout) {
4728 // Cancel the previous request
4729 if (s_last_wake_timeout_info != NULL) {
4730 s_last_wake_timeout_info->userParam = (void *)1;
4731 }
4732
4733 s_last_wake_timeout_info
4734 = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
4735 &TIMEVAL_WAKE_TIMEOUT);
4736 }
4737
4738 // Normal exit
4739 return;
4740
4741error_exit:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004742 if (shouldScheduleTimeout) {
4743 releaseWakeLock();
4744 }
4745}
4746
Wink Saville7f856802009-06-09 10:23:37 -07004747/** FIXME generalize this if you track UserCAllbackInfo, clear it
4748 when the callback occurs
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004749*/
4750static UserCallbackInfo *
Wink Saville7f856802009-06-09 10:23:37 -07004751internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004752 const struct timeval *relativeTime)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004753{
4754 struct timeval myRelativeTime;
4755 UserCallbackInfo *p_info;
4756
4757 p_info = (UserCallbackInfo *) malloc (sizeof(UserCallbackInfo));
4758
Wink Saville7f856802009-06-09 10:23:37 -07004759 p_info->p_callback = callback;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004760 p_info->userParam = param;
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004761
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004762 if (relativeTime == NULL) {
4763 /* treat null parameter as a 0 relative time */
4764 memset (&myRelativeTime, 0, sizeof(myRelativeTime));
4765 } else {
4766 /* FIXME I think event_add's tv param is really const anyway */
4767 memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
4768 }
4769
4770 ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
4771
4772 ril_timer_add(&(p_info->event), &myRelativeTime);
4773
4774 triggerEvLoop();
4775 return p_info;
4776}
4777
Naveen Kalla7edd07c2010-06-21 18:54:47 -07004778
4779extern "C" void
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004780RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
4781 const struct timeval *relativeTime) {
4782 internalRequestTimedCallback (callback, param, relativeTime);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004783}
4784
4785const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004786failCauseToString(RIL_Errno e) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004787 switch(e) {
4788 case RIL_E_SUCCESS: return "E_SUCCESS";
Robert Greenwalt2126ab22013-04-09 12:20:45 -07004789 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RADIO_NOT_AVAILABLE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004790 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
4791 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
4792 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
4793 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
4794 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
4795 case RIL_E_CANCELLED: return "E_CANCELLED";
4796 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
4797 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
4798 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
Wink Savillef4c4d362009-04-02 01:37:03 -07004799 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
John Wang75534472010-04-20 15:11:42 -07004800 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
Wink Saville7f856802009-06-09 10:23:37 -07004801#ifdef FEATURE_MULTIMODE_ANDROID
Wink Savillef4c4d362009-04-02 01:37:03 -07004802 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
4803 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
4804#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004805 default: return "<unknown error>";
4806 }
4807}
4808
4809const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004810radioStateToString(RIL_RadioState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004811 switch(s) {
4812 case RADIO_STATE_OFF: return "RADIO_OFF";
4813 case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
4814 case RADIO_STATE_SIM_NOT_READY: return "RADIO_SIM_NOT_READY";
4815 case RADIO_STATE_SIM_LOCKED_OR_ABSENT: return "RADIO_SIM_LOCKED_OR_ABSENT";
4816 case RADIO_STATE_SIM_READY: return "RADIO_SIM_READY";
Wink Savillef4c4d362009-04-02 01:37:03 -07004817 case RADIO_STATE_RUIM_NOT_READY:return"RADIO_RUIM_NOT_READY";
4818 case RADIO_STATE_RUIM_READY:return"RADIO_RUIM_READY";
4819 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:return"RADIO_RUIM_LOCKED_OR_ABSENT";
4820 case RADIO_STATE_NV_NOT_READY:return"RADIO_NV_NOT_READY";
4821 case RADIO_STATE_NV_READY:return"RADIO_NV_READY";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004822 case RADIO_STATE_ON:return"RADIO_ON";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004823 default: return "<unknown state>";
4824 }
4825}
4826
4827const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004828callStateToString(RIL_CallState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004829 switch(s) {
4830 case RIL_CALL_ACTIVE : return "ACTIVE";
4831 case RIL_CALL_HOLDING: return "HOLDING";
4832 case RIL_CALL_DIALING: return "DIALING";
4833 case RIL_CALL_ALERTING: return "ALERTING";
4834 case RIL_CALL_INCOMING: return "INCOMING";
4835 case RIL_CALL_WAITING: return "WAITING";
4836 default: return "<unknown state>";
4837 }
4838}
4839
4840const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004841requestToString(int request) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004842/*
4843 cat libs/telephony/ril_commands.h \
4844 | egrep "^ *{RIL_" \
4845 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
4846
4847
4848 cat libs/telephony/ril_unsol_commands.h \
4849 | egrep "^ *{RIL_" \
4850 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
4851
4852*/
4853 switch(request) {
4854 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
4855 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
4856 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
4857 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
4858 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
4859 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
4860 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
4861 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
4862 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
4863 case RIL_REQUEST_DIAL: return "DIAL";
4864 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
4865 case RIL_REQUEST_HANGUP: return "HANGUP";
4866 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
4867 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
4868 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
4869 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
4870 case RIL_REQUEST_UDUB: return "UDUB";
4871 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
4872 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
Wink Savillec0114b32011-02-18 10:14:07 -08004873 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
4874 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004875 case RIL_REQUEST_OPERATOR: return "OPERATOR";
4876 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
4877 case RIL_REQUEST_DTMF: return "DTMF";
4878 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
4879 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
Wink Savillef4c4d362009-04-02 01:37:03 -07004880 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004881 case RIL_REQUEST_SIM_IO: return "SIM_IO";
4882 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
4883 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
4884 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
4885 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
4886 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
4887 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
4888 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
4889 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
4890 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
4891 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
4892 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
4893 case RIL_REQUEST_ANSWER: return "ANSWER";
Wink Savillef4c4d362009-04-02 01:37:03 -07004894 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004895 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
4896 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
4897 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
4898 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
4899 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
4900 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
4901 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";
4902 case RIL_REQUEST_DTMF_START: return "DTMF_START";
4903 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
4904 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
4905 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
4906 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
4907 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
4908 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
4909 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
4910 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
4911 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
Wink Savillef4c4d362009-04-02 01:37:03 -07004912 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
4913 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004914 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
4915 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
4916 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
Wink Savillef4c4d362009-04-02 01:37:03 -07004917 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
4918 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004919 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
4920 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
4921 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
4922 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
4923 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
4924 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
4925 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
4926 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
Wink Savillec0114b32011-02-18 10:14:07 -08004927 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE:return"CDMA_SET_SUBSCRIPTION_SOURCE";
Wink Savillef4c4d362009-04-02 01:37:03 -07004928 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"CDMA_SET_ROAMING_PREFERENCE";
4929 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"CDMA_QUERY_ROAMING_PREFERENCE";
4930 case RIL_REQUEST_SET_TTY_MODE:return"SET_TTY_MODE";
4931 case RIL_REQUEST_QUERY_TTY_MODE:return"QUERY_TTY_MODE";
4932 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
4933 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
4934 case RIL_REQUEST_CDMA_FLASH:return"CDMA_FLASH";
4935 case RIL_REQUEST_CDMA_BURST_DTMF:return"CDMA_BURST_DTMF";
4936 case RIL_REQUEST_CDMA_SEND_SMS:return"CDMA_SEND_SMS";
4937 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:return"CDMA_SMS_ACKNOWLEDGE";
Wink Savillea592eeb2009-05-22 13:26:36 -07004938 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG:return"GSM_GET_BROADCAST_SMS_CONFIG";
4939 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG:return"GSM_SET_BROADCAST_SMS_CONFIG";
4940 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG:return "CDMA_GET_BROADCAST_SMS_CONFIG";
4941 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG:return "CDMA_SET_BROADCAST_SMS_CONFIG";
4942 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION:return "CDMA_SMS_BROADCAST_ACTIVATION";
Naveen Kalla03c1edf2009-09-23 11:18:35 -07004943 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return"CDMA_VALIDATE_AND_WRITE_AKEY";
Wink Savillef4c4d362009-04-02 01:37:03 -07004944 case RIL_REQUEST_CDMA_SUBSCRIPTION: return"CDMA_SUBSCRIPTION";
4945 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
4946 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
4947 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
jsh000a9fe2009-05-11 14:52:35 -07004948 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
4949 case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
4950 case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
jsh09a68ba2009-06-10 11:56:38 -07004951 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
jsh563fd722010-06-08 16:52:24 -07004952 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
Wink Savillec0114b32011-02-18 10:14:07 -08004953 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
Jake Hambyfa8d5842011-08-19 16:22:18 -07004954 case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
Jake Hamby300105d2011-09-26 01:01:44 -07004955 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
4956 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004957 case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
Wink Saville8a9e0212013-04-09 12:11:38 -07004958 case RIL_REQUEST_GET_CELL_INFO_LIST: return"GET_CELL_INFO_LIST";
4959 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return"SET_UNSOL_CELL_INFO_LIST_RATE";
Sungmin Choi75697532013-04-26 15:04:45 -07004960 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "RIL_REQUEST_SET_INITIAL_ATTACH_APN";
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07004961 case RIL_REQUEST_IMS_REGISTRATION_STATE: return "IMS_REGISTRATION_STATE";
4962 case RIL_REQUEST_IMS_SEND_SMS: return "IMS_SEND_SMS";
Shishir Agrawal2458d8d2013-11-27 14:53:05 -08004963 case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "SIM_TRANSMIT_APDU_BASIC";
4964 case RIL_REQUEST_SIM_OPEN_CHANNEL: return "SIM_OPEN_CHANNEL";
4965 case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "SIM_CLOSE_CHANNEL";
4966 case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "SIM_TRANSMIT_APDU_CHANNEL";
Wink Saville8b4e4f72014-10-17 15:01:45 -07004967 case RIL_REQUEST_GET_RADIO_CAPABILITY: return "RIL_REQUEST_GET_RADIO_CAPABILITY";
4968 case RIL_REQUEST_SET_RADIO_CAPABILITY: return "RIL_REQUEST_SET_RADIO_CAPABILITY";
Etan Cohend3652192014-06-20 08:28:44 -07004969 case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "SET_UICC_SUBSCRIPTION";
4970 case RIL_REQUEST_ALLOW_DATA: return "ALLOW_DATA";
Amit Mahajan2b772032014-06-26 14:20:11 -07004971 case RIL_REQUEST_GET_HARDWARE_CONFIG: return "GET_HARDWARE_CONFIG";
4972 case RIL_REQUEST_SIM_AUTHENTICATION: return "SIM_AUTHENTICATION";
Wink Savillec29360a2014-07-13 05:17:28 -07004973 case RIL_REQUEST_GET_DC_RT_INFO: return "GET_DC_RT_INFO";
4974 case RIL_REQUEST_SET_DC_RT_INFO_RATE: return "SET_DC_RT_INFO_RATE";
Amit Mahajanc796e222014-08-13 16:54:01 +00004975 case RIL_REQUEST_SET_DATA_PROFILE: return "SET_DATA_PROFILE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004976 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
4977 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08004978 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 -08004979 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
4980 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
4981 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
4982 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
4983 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)";
4984 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
4985 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
4986 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
4987 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
4988 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
4989 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
4990 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL";
4991 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
Wink Savillef4c4d362009-04-02 01:37:03 -07004992 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004993 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
Wink Savillef4c4d362009-04-02 01:37:03 -07004994 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
4995 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_NEW_CDMA_SMS";
4996 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_NEW_BROADCAST_SMS";
4997 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
Wink Saville3d54e742009-05-18 18:00:44 -07004998 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
4999 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
5000 case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
5001 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
5002 case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
Jaikumar Ganeshaf6ecbf2009-04-29 13:27:51 -07005003 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
John Wang5d621da2009-09-18 17:17:48 -07005004 case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
John Wang5909cf82010-01-29 00:18:54 -08005005 case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
Wink Savilleee274582011-04-16 15:05:49 -07005006 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08005007 case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
5008 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
Wink Saville5b9df332011-04-06 16:24:21 -07005009 case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005010 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
Wink Saville8a9e0212013-04-09 12:11:38 -07005011 case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07005012 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "RESPONSE_IMS_NETWORK_STATE_CHANGED";
Etan Cohend3652192014-06-20 08:28:44 -07005013 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return "UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED";
5014 case RIL_UNSOL_SRVCC_STATE_NOTIFY: return "UNSOL_SRVCC_STATE_NOTIFY";
5015 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return "HARDWARE_CONFIG_CHANGED";
Wink Savillec29360a2014-07-13 05:17:28 -07005016 case RIL_UNSOL_DC_RT_INFO_CHANGED: return "UNSOL_DC_RT_INFO_CHANGED";
Naveen Kallaa65a16a2014-07-31 16:48:31 -07005017 case RIL_REQUEST_SHUTDOWN: return "SHUTDOWN";
Wink Saville8b4e4f72014-10-17 15:01:45 -07005018 case RIL_UNSOL_RADIO_CAPABILITY: return "RIL_UNSOL_RADIO_CAPABILITY";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005019 default: return "<unknown request>";
5020 }
5021}
5022
Etan Cohend3652192014-06-20 08:28:44 -07005023const char *
5024rilSocketIdToString(RIL_SOCKET_ID socket_id)
5025{
5026 switch(socket_id) {
5027 case RIL_SOCKET_1:
5028 return "RIL_SOCKET_1";
5029#if (SIM_COUNT >= 2)
5030 case RIL_SOCKET_2:
5031 return "RIL_SOCKET_2";
5032#endif
5033#if (SIM_COUNT >= 3)
5034 case RIL_SOCKET_3:
5035 return "RIL_SOCKET_3";
5036#endif
5037#if (SIM_COUNT >= 4)
5038 case RIL_SOCKET_4:
5039 return "RIL_SOCKET_4";
5040#endif
5041 default:
5042 return "not a valid RIL";
5043 }
5044}
5045
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005046} /* namespace android */
Dheeraj Shetty27976c42014-07-02 21:27:57 +02005047
5048void rilEventAddWakeup_helper(struct ril_event *ev) {
5049 android::rilEventAddWakeup(ev);
5050}
5051
5052void listenCallback_helper(int fd, short flags, void *param) {
5053 android::listenCallback(fd, flags, param);
5054}
5055
5056int blockingWrite_helper(int fd, void *buffer, size_t len) {
5057 return android::blockingWrite(fd, buffer, len);
5058}