blob: aa82e7f321183740bc4e0effc26a991c8aa66608 [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
Robert Greenwalt191e4dc2015-04-29 16:57:39 -070092// Enable verbose logging
93#define VDBG 0
94
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080095// Enable RILC log
96#define RILC_LOG 0
97
98#if RILC_LOG
99 #define startRequest sprintf(printBuf, "(")
100 #define closeRequest sprintf(printBuf, "%s)", printBuf)
101 #define printRequest(token, req) \
Wink Saville8eb2a122012-11-19 16:05:13 -0800102 RLOGD("[%04d]> %s %s", token, requestToString(req), printBuf)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800103
104 #define startResponse sprintf(printBuf, "%s {", printBuf)
105 #define closeResponse sprintf(printBuf, "%s}", printBuf)
Wink Saville8eb2a122012-11-19 16:05:13 -0800106 #define printResponse RLOGD("%s", printBuf)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800107
108 #define clearPrintBuf printBuf[0] = 0
109 #define removeLastChar printBuf[strlen(printBuf)-1] = 0
110 #define appendPrintBuf(x...) sprintf(printBuf, x)
111#else
112 #define startRequest
113 #define closeRequest
114 #define printRequest(token, req)
115 #define startResponse
116 #define closeResponse
117 #define printResponse
118 #define clearPrintBuf
119 #define removeLastChar
120 #define appendPrintBuf(x...)
121#endif
122
123enum WakeType {DONT_WAKE, WAKE_PARTIAL};
124
125typedef struct {
126 int requestNumber;
127 void (*dispatchFunction) (Parcel &p, struct RequestInfo *pRI);
128 int(*responseFunction) (Parcel &p, void *response, size_t responselen);
129} CommandInfo;
130
131typedef struct {
132 int requestNumber;
133 int (*responseFunction) (Parcel &p, void *response, size_t responselen);
134 WakeType wakeType;
135} UnsolResponseInfo;
136
137typedef struct RequestInfo {
Wink Saville7f856802009-06-09 10:23:37 -0700138 int32_t token; //this is not RIL_Token
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800139 CommandInfo *pCI;
140 struct RequestInfo *p_next;
141 char cancelled;
142 char local; // responses to local commands do not go back to command process
Etan Cohend3652192014-06-20 08:28:44 -0700143 RIL_SOCKET_ID socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800144} RequestInfo;
145
Wink Saville3d54e742009-05-18 18:00:44 -0700146typedef struct UserCallbackInfo {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800147 RIL_TimedCallback p_callback;
148 void *userParam;
149 struct ril_event event;
150 struct UserCallbackInfo *p_next;
151} UserCallbackInfo;
152
Etan Cohend3652192014-06-20 08:28:44 -0700153extern "C" const char * requestToString(int request);
154extern "C" const char * failCauseToString(RIL_Errno);
155extern "C" const char * callStateToString(RIL_CallState);
156extern "C" const char * radioStateToString(RIL_RadioState);
157extern "C" const char * rilSocketIdToString(RIL_SOCKET_ID socket_id);
158
159extern "C"
160char rild[MAX_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800161/*******************************************************************/
162
163RIL_RadioFunctions s_callbacks = {0, NULL, NULL, NULL, NULL, NULL};
164static int s_registerCalled = 0;
165
166static pthread_t s_tid_dispatch;
167static pthread_t s_tid_reader;
168static int s_started = 0;
169
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800170static int s_fdDebug = -1;
Etan Cohend3652192014-06-20 08:28:44 -0700171static int s_fdDebug_socket2 = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800172
173static int s_fdWakeupRead;
174static int s_fdWakeupWrite;
175
176static struct ril_event s_commands_event;
177static struct ril_event s_wakeupfd_event;
178static struct ril_event s_listen_event;
Etan Cohend3652192014-06-20 08:28:44 -0700179static SocketListenParam s_ril_param_socket;
180
181static pthread_mutex_t s_pendingRequestsMutex = PTHREAD_MUTEX_INITIALIZER;
182static pthread_mutex_t s_writeMutex = PTHREAD_MUTEX_INITIALIZER;
183static RequestInfo *s_pendingRequests = NULL;
184
185#if (SIM_COUNT >= 2)
186static struct ril_event s_commands_event_socket2;
187static struct ril_event s_listen_event_socket2;
188static SocketListenParam s_ril_param_socket2;
189
190static pthread_mutex_t s_pendingRequestsMutex_socket2 = PTHREAD_MUTEX_INITIALIZER;
191static pthread_mutex_t s_writeMutex_socket2 = PTHREAD_MUTEX_INITIALIZER;
192static RequestInfo *s_pendingRequests_socket2 = NULL;
193#endif
194
195#if (SIM_COUNT >= 3)
196static struct ril_event s_commands_event_socket3;
197static struct ril_event s_listen_event_socket3;
198static SocketListenParam s_ril_param_socket3;
199
200static pthread_mutex_t s_pendingRequestsMutex_socket3 = PTHREAD_MUTEX_INITIALIZER;
201static pthread_mutex_t s_writeMutex_socket3 = PTHREAD_MUTEX_INITIALIZER;
202static RequestInfo *s_pendingRequests_socket3 = NULL;
203#endif
204
205#if (SIM_COUNT >= 4)
206static struct ril_event s_commands_event_socket4;
207static struct ril_event s_listen_event_socket4;
208static SocketListenParam s_ril_param_socket4;
209
210static pthread_mutex_t s_pendingRequestsMutex_socket4 = PTHREAD_MUTEX_INITIALIZER;
211static pthread_mutex_t s_writeMutex_socket4 = PTHREAD_MUTEX_INITIALIZER;
212static RequestInfo *s_pendingRequests_socket4 = NULL;
213#endif
214
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800215static struct ril_event s_wake_timeout_event;
216static struct ril_event s_debug_event;
217
218
219static const struct timeval TIMEVAL_WAKE_TIMEOUT = {1,0};
220
Etan Cohend3652192014-06-20 08:28:44 -0700221
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800222static pthread_mutex_t s_startupMutex = PTHREAD_MUTEX_INITIALIZER;
223static pthread_cond_t s_startupCond = PTHREAD_COND_INITIALIZER;
224
225static pthread_mutex_t s_dispatchMutex = PTHREAD_MUTEX_INITIALIZER;
226static pthread_cond_t s_dispatchCond = PTHREAD_COND_INITIALIZER;
227
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800228static RequestInfo *s_toDispatchHead = NULL;
229static RequestInfo *s_toDispatchTail = NULL;
230
231static UserCallbackInfo *s_last_wake_timeout_info = NULL;
232
233static void *s_lastNITZTimeData = NULL;
234static size_t s_lastNITZTimeDataSize;
235
236#if RILC_LOG
237 static char printBuf[PRINTBUF_SIZE];
238#endif
239
240/*******************************************************************/
Etan Cohend3652192014-06-20 08:28:44 -0700241static int sendResponse (Parcel &p, RIL_SOCKET_ID socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800242
243static void dispatchVoid (Parcel& p, RequestInfo *pRI);
244static void dispatchString (Parcel& p, RequestInfo *pRI);
245static void dispatchStrings (Parcel& p, RequestInfo *pRI);
246static void dispatchInts (Parcel& p, RequestInfo *pRI);
247static void dispatchDial (Parcel& p, RequestInfo *pRI);
248static void dispatchSIM_IO (Parcel& p, RequestInfo *pRI);
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800249static void dispatchSIM_APDU (Parcel& p, RequestInfo *pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800250static void dispatchCallForward(Parcel& p, RequestInfo *pRI);
251static void dispatchRaw(Parcel& p, RequestInfo *pRI);
252static void dispatchSmsWrite (Parcel &p, RequestInfo *pRI);
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -0700253static void dispatchDataCall (Parcel& p, RequestInfo *pRI);
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800254static void dispatchVoiceRadioTech (Parcel& p, RequestInfo *pRI);
Sungmin Choi75697532013-04-26 15:04:45 -0700255static void dispatchSetInitialAttachApn (Parcel& p, RequestInfo *pRI);
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800256static void dispatchCdmaSubscriptionSource (Parcel& p, RequestInfo *pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800257
Wink Savillef4c4d362009-04-02 01:37:03 -0700258static void dispatchCdmaSms(Parcel &p, RequestInfo *pRI);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -0700259static void dispatchImsSms(Parcel &p, RequestInfo *pRI);
260static void dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
261static void dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
Wink Savillef4c4d362009-04-02 01:37:03 -0700262static void dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI);
Wink Savillea592eeb2009-05-22 13:26:36 -0700263static void dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI);
Wink Savillef4c4d362009-04-02 01:37:03 -0700264static void dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI);
265static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI);
Jake Hamby8a4a2332014-01-15 13:12:05 -0800266static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI);
267static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI);
Etan Cohend3652192014-06-20 08:28:44 -0700268static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI);
Amit Mahajan90530a62014-07-01 15:54:08 -0700269static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI);
Amit Mahajanc796e222014-08-13 16:54:01 +0000270static void dispatchDataProfile(Parcel &p, RequestInfo *pRI);
Wink Saville8b4e4f72014-10-17 15:01:45 -0700271static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800272static int responseInts(Parcel &p, void *response, size_t responselen);
273static int responseStrings(Parcel &p, void *response, size_t responselen);
274static int responseString(Parcel &p, void *response, size_t responselen);
275static int responseVoid(Parcel &p, void *response, size_t responselen);
276static int responseCallList(Parcel &p, void *response, size_t responselen);
277static int responseSMS(Parcel &p, void *response, size_t responselen);
278static int responseSIM_IO(Parcel &p, void *response, size_t responselen);
279static int responseCallForwards(Parcel &p, void *response, size_t responselen);
Wink Savillef4c4d362009-04-02 01:37:03 -0700280static int responseDataCallList(Parcel &p, void *response, size_t responselen);
Wink Saville43808972011-01-13 17:39:51 -0800281static int responseSetupDataCall(Parcel &p, void *response, size_t responselen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800282static int responseRaw(Parcel &p, void *response, size_t responselen);
283static int responseSsn(Parcel &p, void *response, size_t responselen);
Wink Savillef4c4d362009-04-02 01:37:03 -0700284static int responseSimStatus(Parcel &p, void *response, size_t responselen);
Wink Savillea592eeb2009-05-22 13:26:36 -0700285static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen);
286static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen);
Wink Savillef4c4d362009-04-02 01:37:03 -0700287static int responseCdmaSms(Parcel &p, void *response, size_t responselen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800288static int responseCellList(Parcel &p, void *response, size_t responselen);
Wink Saville3d54e742009-05-18 18:00:44 -0700289static int responseCdmaInformationRecords(Parcel &p,void *response, size_t responselen);
290static int responseRilSignalStrength(Parcel &p,void *response, size_t responselen);
291static int responseCallRing(Parcel &p, void *response, size_t responselen);
292static int responseCdmaSignalInfoRecord(Parcel &p,void *response, size_t responselen);
293static int responseCdmaCallWaiting(Parcel &p,void *response, size_t responselen);
Alex Yakavenka45e740e2012-01-31 11:48:27 -0800294static int responseSimRefresh(Parcel &p, void *response, size_t responselen);
Wink Saville8a9e0212013-04-09 12:11:38 -0700295static int responseCellInfoList(Parcel &p, void *response, size_t responselen);
Etan Cohend3652192014-06-20 08:28:44 -0700296static int responseHardwareConfig(Parcel &p, void *response, size_t responselen);
Wink Savillec29360a2014-07-13 05:17:28 -0700297static int responseDcRtInfo(Parcel &p, void *response, size_t responselen);
Wink Saville8b4e4f72014-10-17 15:01:45 -0700298static int responseRadioCapability(Parcel &p, void *response, size_t responselen);
Amit Mahajan54563d32014-11-22 00:54:49 +0000299static int responseSSData(Parcel &p, void *response, size_t responselen);
fengluf7408292015-04-14 14:53:55 -0700300static int responseLceStatus(Parcel &p, void *response, size_t responselen);
301static int responseLceData(Parcel &p, void *response, size_t responselen);
Amit Mahajan54563d32014-11-22 00:54:49 +0000302
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800303static int decodeVoiceRadioTechnology (RIL_RadioState radioState);
304static int decodeCdmaSubscriptionSource (RIL_RadioState radioState);
305static RIL_RadioState processRadioState(RIL_RadioState newRadioState);
306
Amit Mahajan54563d32014-11-22 00:54:49 +0000307static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType);
308
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800309#ifdef RIL_SHLIB
Etan Cohend3652192014-06-20 08:28:44 -0700310#if defined(ANDROID_MULTI_SIM)
Vinit Deshpande1b1ec2d2015-04-15 13:31:05 -0700311extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Etan Cohend3652192014-06-20 08:28:44 -0700312 size_t datalen, RIL_SOCKET_ID socket_id);
313#else
Vinit Deshpande1b1ec2d2015-04-15 13:31:05 -0700314extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800315 size_t datalen);
316#endif
Etan Cohend3652192014-06-20 08:28:44 -0700317#endif
318
319#if defined(ANDROID_MULTI_SIM)
320#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c), (d))
321#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d), (e))
322#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest(a)
323#else
324#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c))
325#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d))
326#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest()
327#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800328
Wink Saville7f856802009-06-09 10:23:37 -0700329static UserCallbackInfo * internalRequestTimedCallback
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -0700330 (RIL_TimedCallback callback, void *param,
331 const struct timeval *relativeTime);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800332
333/** Index == requestNumber */
334static CommandInfo s_commands[] = {
335#include "ril_commands.h"
336};
337
338static UnsolResponseInfo s_unsolResponses[] = {
339#include "ril_unsol_commands.h"
340};
341
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800342/* For older RILs that do not support new commands RIL_REQUEST_VOICE_RADIO_TECH and
343 RIL_UNSOL_VOICE_RADIO_TECH_CHANGED messages, decode the voice radio tech from
344 radio state message and store it. Every time there is a change in Radio State
345 check to see if voice radio tech changes and notify telephony
346 */
347int voiceRadioTech = -1;
348
349/* For older RILs that do not support new commands RIL_REQUEST_GET_CDMA_SUBSCRIPTION_SOURCE
350 and RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED messages, decode the subscription
351 source from radio state and store it. Every time there is a change in Radio State
352 check to see if subscription source changed and notify telephony
353 */
354int cdmaSubscriptionSource = -1;
355
356/* For older RILs that do not send RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, decode the
357 SIM/RUIM state from radio state and store it. Every time there is a change in Radio State,
358 check to see if SIM/RUIM status changed and notify telephony
359 */
360int simRuimStatus = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800361
Etan Cohend3652192014-06-20 08:28:44 -0700362static char * RIL_getRilSocketName() {
363 return rild;
364}
365
366extern "C"
Dheeraj Shetty27976c42014-07-02 21:27:57 +0200367void RIL_setRilSocketName(const char * s) {
Etan Cohend3652192014-06-20 08:28:44 -0700368 strncpy(rild, s, MAX_SOCKET_NAME_LENGTH);
369}
370
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800371static char *
Wink Savillef4c4d362009-04-02 01:37:03 -0700372strdupReadString(Parcel &p) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800373 size_t stringlen;
374 const char16_t *s16;
Wink Saville7f856802009-06-09 10:23:37 -0700375
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800376 s16 = p.readString16Inplace(&stringlen);
Wink Saville7f856802009-06-09 10:23:37 -0700377
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800378 return strndup16to8(s16, stringlen);
379}
380
Wink Saville8b4e4f72014-10-17 15:01:45 -0700381static status_t
382readStringFromParcelInplace(Parcel &p, char *str, size_t maxLen) {
383 size_t s16Len;
384 const char16_t *s16;
385
386 s16 = p.readString16Inplace(&s16Len);
387 if (s16 == NULL) {
388 return NO_MEMORY;
389 }
390 size_t strLen = strnlen16to8(s16, s16Len);
391 if ((strLen + 1) > maxLen) {
392 return NO_MEMORY;
393 }
394 if (strncpy16to8(str, s16, strLen) == NULL) {
395 return NO_MEMORY;
396 } else {
397 return NO_ERROR;
398 }
399}
400
Wink Savillef4c4d362009-04-02 01:37:03 -0700401static void writeStringToParcel(Parcel &p, const char *s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800402 char16_t *s16;
403 size_t s16_len;
404 s16 = strdup8to16(s, &s16_len);
405 p.writeString16(s16, s16_len);
406 free(s16);
407}
408
409
410static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700411memsetString (char *s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800412 if (s != NULL) {
413 memset (s, 0, strlen(s));
414 }
415}
416
417void nullParcelReleaseFunction (const uint8_t* data, size_t dataSize,
418 const size_t* objects, size_t objectsSize,
Wink Savillef4c4d362009-04-02 01:37:03 -0700419 void* cookie) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800420 // do nothing -- the data reference lives longer than the Parcel object
421}
422
Wink Saville7f856802009-06-09 10:23:37 -0700423/**
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800424 * To be called from dispatch thread
425 * Issue a single local request, ensuring that the response
Wink Saville7f856802009-06-09 10:23:37 -0700426 * is not sent back up to the command process
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800427 */
428static void
Etan Cohend3652192014-06-20 08:28:44 -0700429issueLocalRequest(int request, void *data, int len, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800430 RequestInfo *pRI;
431 int ret;
Etan Cohend3652192014-06-20 08:28:44 -0700432 /* Hook for current context */
433 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
434 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
435 /* pendingRequestsHook refer to &s_pendingRequests */
436 RequestInfo** pendingRequestsHook = &s_pendingRequests;
437
438#if (SIM_COUNT == 2)
439 if (socket_id == RIL_SOCKET_2) {
440 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
441 pendingRequestsHook = &s_pendingRequests_socket2;
442 }
443#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800444
445 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
446
447 pRI->local = 1;
448 pRI->token = 0xffffffff; // token is not used in this context
449 pRI->pCI = &(s_commands[request]);
Etan Cohend3652192014-06-20 08:28:44 -0700450 pRI->socket_id = socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800451
Etan Cohend3652192014-06-20 08:28:44 -0700452 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800453 assert (ret == 0);
454
Etan Cohend3652192014-06-20 08:28:44 -0700455 pRI->p_next = *pendingRequestsHook;
456 *pendingRequestsHook = pRI;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800457
Etan Cohend3652192014-06-20 08:28:44 -0700458 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800459 assert (ret == 0);
460
Wink Saville8eb2a122012-11-19 16:05:13 -0800461 RLOGD("C[locl]> %s", requestToString(request));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800462
Etan Cohend3652192014-06-20 08:28:44 -0700463 CALL_ONREQUEST(request, data, len, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800464}
465
466
467
468static int
Etan Cohend3652192014-06-20 08:28:44 -0700469processCommandBuffer(void *buffer, size_t buflen, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800470 Parcel p;
471 status_t status;
472 int32_t request;
473 int32_t token;
474 RequestInfo *pRI;
475 int ret;
Etan Cohend3652192014-06-20 08:28:44 -0700476 /* Hook for current context */
477 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
478 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
479 /* pendingRequestsHook refer to &s_pendingRequests */
480 RequestInfo** pendingRequestsHook = &s_pendingRequests;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800481
482 p.setData((uint8_t *) buffer, buflen);
483
484 // status checked at end
485 status = p.readInt32(&request);
486 status = p.readInt32 (&token);
487
Etan Cohend3652192014-06-20 08:28:44 -0700488#if (SIM_COUNT >= 2)
489 if (socket_id == RIL_SOCKET_2) {
490 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
491 pendingRequestsHook = &s_pendingRequests_socket2;
492 }
493#if (SIM_COUNT >= 3)
494 else if (socket_id == RIL_SOCKET_3) {
495 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
496 pendingRequestsHook = &s_pendingRequests_socket3;
497 }
498#endif
499#if (SIM_COUNT >= 4)
500 else if (socket_id == RIL_SOCKET_4) {
501 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
502 pendingRequestsHook = &s_pendingRequests_socket4;
503 }
504#endif
505#endif
506
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800507 if (status != NO_ERROR) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800508 RLOGE("invalid request block");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800509 return 0;
510 }
511
512 if (request < 1 || request >= (int32_t)NUM_ELEMS(s_commands)) {
Etan Cohend3652192014-06-20 08:28:44 -0700513 Parcel pErr;
Wink Saville8eb2a122012-11-19 16:05:13 -0800514 RLOGE("unsupported request code %d token %d", request, token);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800515 // FIXME this should perhaps return a response
Etan Cohend3652192014-06-20 08:28:44 -0700516 pErr.writeInt32 (RESPONSE_SOLICITED);
517 pErr.writeInt32 (token);
518 pErr.writeInt32 (RIL_E_GENERIC_FAILURE);
519
520 sendResponse(pErr, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800521 return 0;
522 }
523
524
525 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
526
527 pRI->token = token;
528 pRI->pCI = &(s_commands[request]);
Etan Cohend3652192014-06-20 08:28:44 -0700529 pRI->socket_id = socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800530
Etan Cohend3652192014-06-20 08:28:44 -0700531 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800532 assert (ret == 0);
533
Etan Cohend3652192014-06-20 08:28:44 -0700534 pRI->p_next = *pendingRequestsHook;
535 *pendingRequestsHook = pRI;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800536
Etan Cohend3652192014-06-20 08:28:44 -0700537 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800538 assert (ret == 0);
539
540/* sLastDispatchedToken = token; */
541
Wink Saville7f856802009-06-09 10:23:37 -0700542 pRI->pCI->dispatchFunction(p, pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800543
544 return 0;
545}
546
547static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700548invalidCommandBlock (RequestInfo *pRI) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800549 RLOGE("invalid command block for token %d request %s",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800550 pRI->token, requestToString(pRI->pCI->requestNumber));
551}
552
553/** Callee expects NULL */
Wink Saville7f856802009-06-09 10:23:37 -0700554static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700555dispatchVoid (Parcel& p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800556 clearPrintBuf;
557 printRequest(pRI->token, pRI->pCI->requestNumber);
Etan Cohend3652192014-06-20 08:28:44 -0700558 CALL_ONREQUEST(pRI->pCI->requestNumber, NULL, 0, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800559}
560
561/** Callee expects const char * */
562static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700563dispatchString (Parcel& p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800564 status_t status;
565 size_t datalen;
566 size_t stringlen;
567 char *string8 = NULL;
568
569 string8 = strdupReadString(p);
570
571 startRequest;
572 appendPrintBuf("%s%s", printBuf, string8);
573 closeRequest;
574 printRequest(pRI->token, pRI->pCI->requestNumber);
575
Etan Cohend3652192014-06-20 08:28:44 -0700576 CALL_ONREQUEST(pRI->pCI->requestNumber, string8,
577 sizeof(char *), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800578
579#ifdef MEMSET_FREED
580 memsetString(string8);
581#endif
582
583 free(string8);
584 return;
585invalid:
586 invalidCommandBlock(pRI);
587 return;
588}
589
590/** Callee expects const char ** */
591static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700592dispatchStrings (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800593 int32_t countStrings;
594 status_t status;
595 size_t datalen;
596 char **pStrings;
597
598 status = p.readInt32 (&countStrings);
599
600 if (status != NO_ERROR) {
601 goto invalid;
602 }
603
604 startRequest;
605 if (countStrings == 0) {
606 // just some non-null pointer
607 pStrings = (char **)alloca(sizeof(char *));
608 datalen = 0;
609 } else if (((int)countStrings) == -1) {
610 pStrings = NULL;
611 datalen = 0;
612 } else {
613 datalen = sizeof(char *) * countStrings;
Wink Saville7f856802009-06-09 10:23:37 -0700614
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800615 pStrings = (char **)alloca(datalen);
616
617 for (int i = 0 ; i < countStrings ; i++) {
618 pStrings[i] = strdupReadString(p);
619 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
620 }
621 }
622 removeLastChar;
623 closeRequest;
624 printRequest(pRI->token, pRI->pCI->requestNumber);
625
Etan Cohend3652192014-06-20 08:28:44 -0700626 CALL_ONREQUEST(pRI->pCI->requestNumber, pStrings, datalen, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800627
628 if (pStrings != NULL) {
629 for (int i = 0 ; i < countStrings ; i++) {
630#ifdef MEMSET_FREED
631 memsetString (pStrings[i]);
632#endif
633 free(pStrings[i]);
634 }
635
636#ifdef MEMSET_FREED
637 memset(pStrings, 0, datalen);
638#endif
639 }
Wink Saville7f856802009-06-09 10:23:37 -0700640
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800641 return;
642invalid:
643 invalidCommandBlock(pRI);
644 return;
645}
646
647/** Callee expects const int * */
648static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700649dispatchInts (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800650 int32_t count;
651 status_t status;
652 size_t datalen;
653 int *pInts;
654
655 status = p.readInt32 (&count);
656
657 if (status != NO_ERROR || count == 0) {
658 goto invalid;
659 }
660
661 datalen = sizeof(int) * count;
662 pInts = (int *)alloca(datalen);
663
664 startRequest;
665 for (int i = 0 ; i < count ; i++) {
666 int32_t t;
667
668 status = p.readInt32(&t);
669 pInts[i] = (int)t;
670 appendPrintBuf("%s%d,", printBuf, t);
671
672 if (status != NO_ERROR) {
673 goto invalid;
674 }
675 }
676 removeLastChar;
677 closeRequest;
678 printRequest(pRI->token, pRI->pCI->requestNumber);
679
Etan Cohend3652192014-06-20 08:28:44 -0700680 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<int *>(pInts),
681 datalen, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800682
683#ifdef MEMSET_FREED
684 memset(pInts, 0, datalen);
685#endif
686
687 return;
688invalid:
689 invalidCommandBlock(pRI);
690 return;
691}
692
693
Wink Saville7f856802009-06-09 10:23:37 -0700694/**
695 * Callee expects const RIL_SMS_WriteArgs *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800696 * Payload is:
697 * int32_t status
698 * String pdu
699 */
700static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700701dispatchSmsWrite (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800702 RIL_SMS_WriteArgs args;
703 int32_t t;
704 status_t status;
705
Mark Salyzyndba25612015-04-09 07:18:35 -0700706 RLOGD("dispatchSmsWrite");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800707 memset (&args, 0, sizeof(args));
708
709 status = p.readInt32(&t);
710 args.status = (int)t;
711
712 args.pdu = strdupReadString(p);
713
714 if (status != NO_ERROR || args.pdu == NULL) {
715 goto invalid;
716 }
717
718 args.smsc = strdupReadString(p);
719
720 startRequest;
721 appendPrintBuf("%s%d,%s,smsc=%s", printBuf, args.status,
722 (char*)args.pdu, (char*)args.smsc);
723 closeRequest;
724 printRequest(pRI->token, pRI->pCI->requestNumber);
Wink Saville7f856802009-06-09 10:23:37 -0700725
Etan Cohend3652192014-06-20 08:28:44 -0700726 CALL_ONREQUEST(pRI->pCI->requestNumber, &args, sizeof(args), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800727
728#ifdef MEMSET_FREED
729 memsetString (args.pdu);
730#endif
731
732 free (args.pdu);
Wink Saville7f856802009-06-09 10:23:37 -0700733
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800734#ifdef MEMSET_FREED
735 memset(&args, 0, sizeof(args));
736#endif
737
738 return;
739invalid:
740 invalidCommandBlock(pRI);
741 return;
742}
743
Wink Saville7f856802009-06-09 10:23:37 -0700744/**
745 * Callee expects const RIL_Dial *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800746 * Payload is:
747 * String address
748 * int32_t clir
749 */
750static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700751dispatchDial (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800752 RIL_Dial dial;
Wink Saville74fa3882009-12-22 15:35:41 -0800753 RIL_UUS_Info uusInfo;
Wink Saville7bce0822010-01-08 15:20:12 -0800754 int32_t sizeOfDial;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800755 int32_t t;
Wink Saville74fa3882009-12-22 15:35:41 -0800756 int32_t uusPresent;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800757 status_t status;
758
Mark Salyzyndba25612015-04-09 07:18:35 -0700759 RLOGD("dispatchDial");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800760 memset (&dial, 0, sizeof(dial));
761
762 dial.address = strdupReadString(p);
763
764 status = p.readInt32(&t);
765 dial.clir = (int)t;
766
767 if (status != NO_ERROR || dial.address == NULL) {
768 goto invalid;
769 }
770
Wink Saville3a4840b2010-04-07 13:29:58 -0700771 if (s_callbacks.version < 3) { // Remove when partners upgrade to version 3
Wink Saville74fa3882009-12-22 15:35:41 -0800772 uusPresent = 0;
Wink Saville7bce0822010-01-08 15:20:12 -0800773 sizeOfDial = sizeof(dial) - sizeof(RIL_UUS_Info *);
Wink Saville74fa3882009-12-22 15:35:41 -0800774 } else {
775 status = p.readInt32(&uusPresent);
776
777 if (status != NO_ERROR) {
778 goto invalid;
779 }
780
781 if (uusPresent == 0) {
782 dial.uusInfo = NULL;
783 } else {
784 int32_t len;
785
786 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
787
788 status = p.readInt32(&t);
789 uusInfo.uusType = (RIL_UUS_Type) t;
790
791 status = p.readInt32(&t);
792 uusInfo.uusDcs = (RIL_UUS_DCS) t;
793
794 status = p.readInt32(&len);
795 if (status != NO_ERROR) {
796 goto invalid;
797 }
798
799 // The java code writes -1 for null arrays
800 if (((int) len) == -1) {
801 uusInfo.uusData = NULL;
802 len = 0;
803 } else {
804 uusInfo.uusData = (char*) p.readInplace(len);
805 }
806
807 uusInfo.uusLength = len;
808 dial.uusInfo = &uusInfo;
809 }
Wink Saville7bce0822010-01-08 15:20:12 -0800810 sizeOfDial = sizeof(dial);
Wink Saville74fa3882009-12-22 15:35:41 -0800811 }
812
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800813 startRequest;
814 appendPrintBuf("%snum=%s,clir=%d", printBuf, dial.address, dial.clir);
Wink Saville74fa3882009-12-22 15:35:41 -0800815 if (uusPresent) {
816 appendPrintBuf("%s,uusType=%d,uusDcs=%d,uusLen=%d", printBuf,
817 dial.uusInfo->uusType, dial.uusInfo->uusDcs,
818 dial.uusInfo->uusLength);
819 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800820 closeRequest;
821 printRequest(pRI->token, pRI->pCI->requestNumber);
822
Etan Cohend3652192014-06-20 08:28:44 -0700823 CALL_ONREQUEST(pRI->pCI->requestNumber, &dial, sizeOfDial, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800824
825#ifdef MEMSET_FREED
826 memsetString (dial.address);
827#endif
828
829 free (dial.address);
Wink Saville7f856802009-06-09 10:23:37 -0700830
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800831#ifdef MEMSET_FREED
Wink Saville74fa3882009-12-22 15:35:41 -0800832 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800833 memset(&dial, 0, sizeof(dial));
834#endif
835
836 return;
837invalid:
838 invalidCommandBlock(pRI);
839 return;
840}
841
Wink Saville7f856802009-06-09 10:23:37 -0700842/**
843 * Callee expects const RIL_SIM_IO *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800844 * Payload is:
845 * int32_t command
846 * int32_t fileid
847 * String path
848 * int32_t p1, p2, p3
Wink Saville7f856802009-06-09 10:23:37 -0700849 * String data
850 * String pin2
Wink Savillec0114b32011-02-18 10:14:07 -0800851 * String aidPtr
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800852 */
853static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700854dispatchSIM_IO (Parcel &p, RequestInfo *pRI) {
Wink Savillec0114b32011-02-18 10:14:07 -0800855 union RIL_SIM_IO {
856 RIL_SIM_IO_v6 v6;
857 RIL_SIM_IO_v5 v5;
858 } simIO;
859
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800860 int32_t t;
Wink Savillec0114b32011-02-18 10:14:07 -0800861 int size;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800862 status_t status;
863
Robert Greenwalt191e4dc2015-04-29 16:57:39 -0700864#if VDBG
Mark Salyzyndba25612015-04-09 07:18:35 -0700865 RLOGD("dispatchSIM_IO");
Robert Greenwalt191e4dc2015-04-29 16:57:39 -0700866#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800867 memset (&simIO, 0, sizeof(simIO));
868
Wink Saville7f856802009-06-09 10:23:37 -0700869 // note we only check status at the end
870
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800871 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800872 simIO.v6.command = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800873
874 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800875 simIO.v6.fileid = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800876
Wink Savillec0114b32011-02-18 10:14:07 -0800877 simIO.v6.path = strdupReadString(p);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800878
879 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800880 simIO.v6.p1 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800881
882 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800883 simIO.v6.p2 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800884
885 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800886 simIO.v6.p3 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800887
Wink Savillec0114b32011-02-18 10:14:07 -0800888 simIO.v6.data = strdupReadString(p);
889 simIO.v6.pin2 = strdupReadString(p);
890 simIO.v6.aidPtr = strdupReadString(p);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800891
892 startRequest;
Wink Savillec0114b32011-02-18 10:14:07 -0800893 appendPrintBuf("%scmd=0x%X,efid=0x%X,path=%s,%d,%d,%d,%s,pin2=%s,aid=%s", printBuf,
894 simIO.v6.command, simIO.v6.fileid, (char*)simIO.v6.path,
895 simIO.v6.p1, simIO.v6.p2, simIO.v6.p3,
896 (char*)simIO.v6.data, (char*)simIO.v6.pin2, simIO.v6.aidPtr);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800897 closeRequest;
898 printRequest(pRI->token, pRI->pCI->requestNumber);
Wink Saville7f856802009-06-09 10:23:37 -0700899
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800900 if (status != NO_ERROR) {
901 goto invalid;
902 }
903
Wink Savillec0114b32011-02-18 10:14:07 -0800904 size = (s_callbacks.version < 6) ? sizeof(simIO.v5) : sizeof(simIO.v6);
Etan Cohend3652192014-06-20 08:28:44 -0700905 CALL_ONREQUEST(pRI->pCI->requestNumber, &simIO, size, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800906
907#ifdef MEMSET_FREED
Wink Savillec0114b32011-02-18 10:14:07 -0800908 memsetString (simIO.v6.path);
909 memsetString (simIO.v6.data);
910 memsetString (simIO.v6.pin2);
911 memsetString (simIO.v6.aidPtr);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800912#endif
913
Wink Savillec0114b32011-02-18 10:14:07 -0800914 free (simIO.v6.path);
915 free (simIO.v6.data);
916 free (simIO.v6.pin2);
917 free (simIO.v6.aidPtr);
Wink Saville7f856802009-06-09 10:23:37 -0700918
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800919#ifdef MEMSET_FREED
920 memset(&simIO, 0, sizeof(simIO));
921#endif
922
923 return;
924invalid:
925 invalidCommandBlock(pRI);
926 return;
927}
928
929/**
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800930 * Callee expects const RIL_SIM_APDU *
931 * Payload is:
932 * int32_t sessionid
933 * int32_t cla
934 * int32_t instruction
935 * int32_t p1, p2, p3
936 * String data
937 */
938static void
939dispatchSIM_APDU (Parcel &p, RequestInfo *pRI) {
940 int32_t t;
941 status_t status;
942 RIL_SIM_APDU apdu;
943
Robert Greenwalt191e4dc2015-04-29 16:57:39 -0700944#if VDBG
Mark Salyzyndba25612015-04-09 07:18:35 -0700945 RLOGD("dispatchSIM_APDU");
Robert Greenwalt191e4dc2015-04-29 16:57:39 -0700946#endif
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800947 memset (&apdu, 0, sizeof(RIL_SIM_APDU));
948
949 // Note we only check status at the end. Any single failure leads to
950 // subsequent reads filing.
951 status = p.readInt32(&t);
952 apdu.sessionid = (int)t;
953
954 status = p.readInt32(&t);
955 apdu.cla = (int)t;
956
957 status = p.readInt32(&t);
958 apdu.instruction = (int)t;
959
960 status = p.readInt32(&t);
961 apdu.p1 = (int)t;
962
963 status = p.readInt32(&t);
964 apdu.p2 = (int)t;
965
966 status = p.readInt32(&t);
967 apdu.p3 = (int)t;
968
969 apdu.data = strdupReadString(p);
970
971 startRequest;
972 appendPrintBuf("%ssessionid=%d,cla=%d,ins=%d,p1=%d,p2=%d,p3=%d,data=%s",
973 printBuf, apdu.sessionid, apdu.cla, apdu.instruction, apdu.p1, apdu.p2,
974 apdu.p3, (char*)apdu.data);
975 closeRequest;
976 printRequest(pRI->token, pRI->pCI->requestNumber);
977
978 if (status != NO_ERROR) {
979 goto invalid;
980 }
981
Etan Cohend3652192014-06-20 08:28:44 -0700982 CALL_ONREQUEST(pRI->pCI->requestNumber, &apdu, sizeof(RIL_SIM_APDU), pRI, pRI->socket_id);
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800983
984#ifdef MEMSET_FREED
985 memsetString(apdu.data);
986#endif
987 free(apdu.data);
988
989#ifdef MEMSET_FREED
990 memset(&apdu, 0, sizeof(RIL_SIM_APDU));
991#endif
992
993 return;
994invalid:
995 invalidCommandBlock(pRI);
996 return;
997}
998
999
1000/**
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001001 * Callee expects const RIL_CallForwardInfo *
1002 * Payload is:
1003 * int32_t status/action
1004 * int32_t reason
1005 * int32_t serviceCode
1006 * int32_t toa
1007 * String number (0 length -> null)
1008 * int32_t timeSeconds
1009 */
Wink Saville7f856802009-06-09 10:23:37 -07001010static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001011dispatchCallForward(Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001012 RIL_CallForwardInfo cff;
1013 int32_t t;
1014 status_t status;
1015
Mark Salyzyndba25612015-04-09 07:18:35 -07001016 RLOGD("dispatchCallForward");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001017 memset (&cff, 0, sizeof(cff));
1018
Wink Saville7f856802009-06-09 10:23:37 -07001019 // note we only check status at the end
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001020
1021 status = p.readInt32(&t);
1022 cff.status = (int)t;
Wink Saville7f856802009-06-09 10:23:37 -07001023
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001024 status = p.readInt32(&t);
1025 cff.reason = (int)t;
1026
1027 status = p.readInt32(&t);
1028 cff.serviceClass = (int)t;
1029
1030 status = p.readInt32(&t);
1031 cff.toa = (int)t;
1032
1033 cff.number = strdupReadString(p);
1034
1035 status = p.readInt32(&t);
1036 cff.timeSeconds = (int)t;
1037
1038 if (status != NO_ERROR) {
1039 goto invalid;
1040 }
1041
1042 // special case: number 0-length fields is null
1043
1044 if (cff.number != NULL && strlen (cff.number) == 0) {
1045 cff.number = NULL;
1046 }
1047
1048 startRequest;
1049 appendPrintBuf("%sstat=%d,reason=%d,serv=%d,toa=%d,%s,tout=%d", printBuf,
1050 cff.status, cff.reason, cff.serviceClass, cff.toa,
1051 (char*)cff.number, cff.timeSeconds);
1052 closeRequest;
1053 printRequest(pRI->token, pRI->pCI->requestNumber);
1054
Etan Cohend3652192014-06-20 08:28:44 -07001055 CALL_ONREQUEST(pRI->pCI->requestNumber, &cff, sizeof(cff), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001056
1057#ifdef MEMSET_FREED
1058 memsetString(cff.number);
1059#endif
1060
1061 free (cff.number);
1062
1063#ifdef MEMSET_FREED
1064 memset(&cff, 0, sizeof(cff));
1065#endif
1066
1067 return;
1068invalid:
1069 invalidCommandBlock(pRI);
1070 return;
1071}
1072
1073
Wink Saville7f856802009-06-09 10:23:37 -07001074static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001075dispatchRaw(Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001076 int32_t len;
1077 status_t status;
1078 const void *data;
1079
1080 status = p.readInt32(&len);
1081
1082 if (status != NO_ERROR) {
1083 goto invalid;
1084 }
1085
1086 // The java code writes -1 for null arrays
1087 if (((int)len) == -1) {
1088 data = NULL;
1089 len = 0;
Wink Saville7f856802009-06-09 10:23:37 -07001090 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001091
1092 data = p.readInplace(len);
1093
1094 startRequest;
1095 appendPrintBuf("%sraw_size=%d", printBuf, len);
1096 closeRequest;
1097 printRequest(pRI->token, pRI->pCI->requestNumber);
1098
Etan Cohend3652192014-06-20 08:28:44 -07001099 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<void *>(data), len, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001100
1101 return;
1102invalid:
1103 invalidCommandBlock(pRI);
1104 return;
1105}
1106
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001107static status_t
1108constructCdmaSms(Parcel &p, RequestInfo *pRI, RIL_CDMA_SMS_Message& rcsm) {
Wink Savillef4c4d362009-04-02 01:37:03 -07001109 int32_t t;
1110 uint8_t ut;
1111 status_t status;
1112 int32_t digitCount;
1113 int digitLimit;
Wink Saville7f856802009-06-09 10:23:37 -07001114
Wink Savillef4c4d362009-04-02 01:37:03 -07001115 memset(&rcsm, 0, sizeof(rcsm));
1116
1117 status = p.readInt32(&t);
1118 rcsm.uTeleserviceID = (int) t;
1119
1120 status = p.read(&ut,sizeof(ut));
1121 rcsm.bIsServicePresent = (uint8_t) ut;
1122
1123 status = p.readInt32(&t);
1124 rcsm.uServicecategory = (int) t;
1125
1126 status = p.readInt32(&t);
1127 rcsm.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1128
1129 status = p.readInt32(&t);
1130 rcsm.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1131
1132 status = p.readInt32(&t);
1133 rcsm.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1134
1135 status = p.readInt32(&t);
1136 rcsm.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1137
1138 status = p.read(&ut,sizeof(ut));
1139 rcsm.sAddress.number_of_digits= (uint8_t) ut;
1140
1141 digitLimit= MIN((rcsm.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
1142 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1143 status = p.read(&ut,sizeof(ut));
1144 rcsm.sAddress.digits[digitCount] = (uint8_t) ut;
1145 }
1146
Wink Saville7f856802009-06-09 10:23:37 -07001147 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001148 rcsm.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1149
Wink Saville7f856802009-06-09 10:23:37 -07001150 status = p.read(&ut,sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001151 rcsm.sSubAddress.odd = (uint8_t) ut;
1152
1153 status = p.read(&ut,sizeof(ut));
1154 rcsm.sSubAddress.number_of_digits = (uint8_t) ut;
1155
1156 digitLimit= MIN((rcsm.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
Wink Saville7f856802009-06-09 10:23:37 -07001157 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1158 status = p.read(&ut,sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001159 rcsm.sSubAddress.digits[digitCount] = (uint8_t) ut;
1160 }
1161
Wink Saville7f856802009-06-09 10:23:37 -07001162 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001163 rcsm.uBearerDataLen = (int) t;
1164
1165 digitLimit= MIN((rcsm.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
Wink Saville7f856802009-06-09 10:23:37 -07001166 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1167 status = p.read(&ut, sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001168 rcsm.aBearerData[digitCount] = (uint8_t) ut;
1169 }
1170
1171 if (status != NO_ERROR) {
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001172 return status;
Wink Savillef4c4d362009-04-02 01:37:03 -07001173 }
1174
1175 startRequest;
1176 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
Wink Saville1b5fd232009-04-22 14:50:00 -07001177 sAddress.digit_mode=%d, sAddress.Number_mode=%d, sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07001178 printBuf, rcsm.uTeleserviceID,rcsm.bIsServicePresent,rcsm.uServicecategory,
Wink Saville1b5fd232009-04-22 14:50:00 -07001179 rcsm.sAddress.digit_mode, rcsm.sAddress.number_mode,rcsm.sAddress.number_type);
Wink Savillef4c4d362009-04-02 01:37:03 -07001180 closeRequest;
Wink Saville7f856802009-06-09 10:23:37 -07001181
Wink Savillef4c4d362009-04-02 01:37:03 -07001182 printRequest(pRI->token, pRI->pCI->requestNumber);
1183
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001184 return status;
1185}
1186
1187static void
1188dispatchCdmaSms(Parcel &p, RequestInfo *pRI) {
1189 RIL_CDMA_SMS_Message rcsm;
1190
Mark Salyzyndba25612015-04-09 07:18:35 -07001191 RLOGD("dispatchCdmaSms");
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001192 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1193 goto invalid;
1194 }
1195
Etan Cohend3652192014-06-20 08:28:44 -07001196 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001197
1198#ifdef MEMSET_FREED
1199 memset(&rcsm, 0, sizeof(rcsm));
1200#endif
1201
1202 return;
1203
1204invalid:
1205 invalidCommandBlock(pRI);
1206 return;
1207}
1208
Wink Saville7f856802009-06-09 10:23:37 -07001209static void
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001210dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1211 RIL_IMS_SMS_Message rism;
1212 RIL_CDMA_SMS_Message rcsm;
1213
Mark Salyzyndba25612015-04-09 07:18:35 -07001214 RLOGD("dispatchImsCdmaSms: retry=%d, messageRef=%d", retry, messageRef);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001215
1216 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1217 goto invalid;
1218 }
1219 memset(&rism, 0, sizeof(rism));
1220 rism.tech = RADIO_TECH_3GPP2;
1221 rism.retry = retry;
1222 rism.messageRef = messageRef;
1223 rism.message.cdmaMessage = &rcsm;
1224
Etan Cohend3652192014-06-20 08:28:44 -07001225 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001226 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Etan Cohend3652192014-06-20 08:28:44 -07001227 +sizeof(rcsm),pRI, pRI->socket_id);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001228
1229#ifdef MEMSET_FREED
1230 memset(&rcsm, 0, sizeof(rcsm));
1231 memset(&rism, 0, sizeof(rism));
1232#endif
1233
1234 return;
1235
1236invalid:
1237 invalidCommandBlock(pRI);
1238 return;
1239}
1240
1241static void
1242dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1243 RIL_IMS_SMS_Message rism;
1244 int32_t countStrings;
1245 status_t status;
1246 size_t datalen;
1247 char **pStrings;
Mark Salyzyndba25612015-04-09 07:18:35 -07001248 RLOGD("dispatchImsGsmSms: retry=%d, messageRef=%d", retry, messageRef);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001249
1250 status = p.readInt32 (&countStrings);
1251
1252 if (status != NO_ERROR) {
1253 goto invalid;
1254 }
1255
1256 memset(&rism, 0, sizeof(rism));
1257 rism.tech = RADIO_TECH_3GPP;
1258 rism.retry = retry;
1259 rism.messageRef = messageRef;
1260
1261 startRequest;
Etan Cohen5d891b72014-02-27 17:25:17 -08001262 appendPrintBuf("%stech=%d, retry=%d, messageRef=%d, ", printBuf,
1263 (int)rism.tech, (int)rism.retry, rism.messageRef);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001264 if (countStrings == 0) {
1265 // just some non-null pointer
1266 pStrings = (char **)alloca(sizeof(char *));
1267 datalen = 0;
1268 } else if (((int)countStrings) == -1) {
1269 pStrings = NULL;
1270 datalen = 0;
1271 } else {
1272 datalen = sizeof(char *) * countStrings;
1273
1274 pStrings = (char **)alloca(datalen);
1275
1276 for (int i = 0 ; i < countStrings ; i++) {
1277 pStrings[i] = strdupReadString(p);
1278 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
1279 }
1280 }
1281 removeLastChar;
1282 closeRequest;
1283 printRequest(pRI->token, pRI->pCI->requestNumber);
1284
1285 rism.message.gsmMessage = pStrings;
Etan Cohend3652192014-06-20 08:28:44 -07001286 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001287 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Etan Cohend3652192014-06-20 08:28:44 -07001288 +datalen, pRI, pRI->socket_id);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001289
1290 if (pStrings != NULL) {
1291 for (int i = 0 ; i < countStrings ; i++) {
1292#ifdef MEMSET_FREED
1293 memsetString (pStrings[i]);
1294#endif
1295 free(pStrings[i]);
1296 }
1297
1298#ifdef MEMSET_FREED
1299 memset(pStrings, 0, datalen);
1300#endif
1301 }
1302
1303#ifdef MEMSET_FREED
1304 memset(&rism, 0, sizeof(rism));
1305#endif
1306 return;
1307invalid:
1308 ALOGE("dispatchImsGsmSms invalid block");
1309 invalidCommandBlock(pRI);
1310 return;
1311}
1312
1313static void
1314dispatchImsSms(Parcel &p, RequestInfo *pRI) {
1315 int32_t t;
1316 status_t status = p.readInt32(&t);
1317 RIL_RadioTechnologyFamily format;
1318 uint8_t retry;
1319 int32_t messageRef;
1320
Mark Salyzyndba25612015-04-09 07:18:35 -07001321 RLOGD("dispatchImsSms");
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001322 if (status != NO_ERROR) {
1323 goto invalid;
1324 }
1325 format = (RIL_RadioTechnologyFamily) t;
1326
1327 // read retry field
1328 status = p.read(&retry,sizeof(retry));
1329 if (status != NO_ERROR) {
1330 goto invalid;
1331 }
1332 // read messageRef field
1333 status = p.read(&messageRef,sizeof(messageRef));
1334 if (status != NO_ERROR) {
1335 goto invalid;
1336 }
1337
1338 if (RADIO_TECH_3GPP == format) {
1339 dispatchImsGsmSms(p, pRI, retry, messageRef);
1340 } else if (RADIO_TECH_3GPP2 == format) {
1341 dispatchImsCdmaSms(p, pRI, retry, messageRef);
1342 } else {
1343 ALOGE("requestImsSendSMS invalid format value =%d", format);
1344 }
1345
1346 return;
1347
1348invalid:
1349 invalidCommandBlock(pRI);
1350 return;
1351}
1352
1353static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001354dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI) {
1355 RIL_CDMA_SMS_Ack rcsa;
1356 int32_t t;
1357 status_t status;
1358 int32_t digitCount;
1359
Mark Salyzyndba25612015-04-09 07:18:35 -07001360 RLOGD("dispatchCdmaSmsAck");
Wink Savillef4c4d362009-04-02 01:37:03 -07001361 memset(&rcsa, 0, sizeof(rcsa));
1362
1363 status = p.readInt32(&t);
1364 rcsa.uErrorClass = (RIL_CDMA_SMS_ErrorClass) t;
1365
1366 status = p.readInt32(&t);
1367 rcsa.uSMSCauseCode = (int) t;
1368
1369 if (status != NO_ERROR) {
1370 goto invalid;
1371 }
1372
1373 startRequest;
Wink Saville1b5fd232009-04-22 14:50:00 -07001374 appendPrintBuf("%suErrorClass=%d, uTLStatus=%d, ",
1375 printBuf, rcsa.uErrorClass, rcsa.uSMSCauseCode);
Wink Savillef4c4d362009-04-02 01:37:03 -07001376 closeRequest;
1377
1378 printRequest(pRI->token, pRI->pCI->requestNumber);
1379
Etan Cohend3652192014-06-20 08:28:44 -07001380 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsa, sizeof(rcsa),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001381
1382#ifdef MEMSET_FREED
1383 memset(&rcsa, 0, sizeof(rcsa));
1384#endif
1385
1386 return;
1387
1388invalid:
1389 invalidCommandBlock(pRI);
1390 return;
1391}
1392
Wink Savillea592eeb2009-05-22 13:26:36 -07001393static void
1394dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1395 int32_t t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001396 status_t status;
Wink Savillea592eeb2009-05-22 13:26:36 -07001397 int32_t num;
Wink Savillef4c4d362009-04-02 01:37:03 -07001398
Wink Savillea592eeb2009-05-22 13:26:36 -07001399 status = p.readInt32(&num);
Wink Savillef4c4d362009-04-02 01:37:03 -07001400 if (status != NO_ERROR) {
1401 goto invalid;
1402 }
1403
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001404 {
1405 RIL_GSM_BroadcastSmsConfigInfo gsmBci[num];
1406 RIL_GSM_BroadcastSmsConfigInfo *gsmBciPtrs[num];
Wink Savillea592eeb2009-05-22 13:26:36 -07001407
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001408 startRequest;
1409 for (int i = 0 ; i < num ; i++ ) {
1410 gsmBciPtrs[i] = &gsmBci[i];
Wink Savillef4c4d362009-04-02 01:37:03 -07001411
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001412 status = p.readInt32(&t);
1413 gsmBci[i].fromServiceId = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001414
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001415 status = p.readInt32(&t);
1416 gsmBci[i].toServiceId = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001417
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001418 status = p.readInt32(&t);
1419 gsmBci[i].fromCodeScheme = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001420
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001421 status = p.readInt32(&t);
1422 gsmBci[i].toCodeScheme = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001423
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001424 status = p.readInt32(&t);
1425 gsmBci[i].selected = (uint8_t) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001426
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001427 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId =%d, \
1428 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]", printBuf, i,
1429 gsmBci[i].fromServiceId, gsmBci[i].toServiceId,
1430 gsmBci[i].fromCodeScheme, gsmBci[i].toCodeScheme,
1431 gsmBci[i].selected);
1432 }
1433 closeRequest;
Wink Savillef4c4d362009-04-02 01:37:03 -07001434
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001435 if (status != NO_ERROR) {
1436 goto invalid;
1437 }
Wink Savillef4c4d362009-04-02 01:37:03 -07001438
Etan Cohend3652192014-06-20 08:28:44 -07001439 CALL_ONREQUEST(pRI->pCI->requestNumber,
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001440 gsmBciPtrs,
1441 num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *),
Etan Cohend3652192014-06-20 08:28:44 -07001442 pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001443
1444#ifdef MEMSET_FREED
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001445 memset(gsmBci, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo));
1446 memset(gsmBciPtrs, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *));
Wink Savillef4c4d362009-04-02 01:37:03 -07001447#endif
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001448 }
Wink Savillef4c4d362009-04-02 01:37:03 -07001449
1450 return;
1451
1452invalid:
1453 invalidCommandBlock(pRI);
1454 return;
Wink Savillea592eeb2009-05-22 13:26:36 -07001455}
Wink Savillef4c4d362009-04-02 01:37:03 -07001456
Wink Savillea592eeb2009-05-22 13:26:36 -07001457static void
1458dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1459 int32_t t;
1460 status_t status;
1461 int32_t num;
1462
1463 status = p.readInt32(&num);
1464 if (status != NO_ERROR) {
1465 goto invalid;
1466 }
1467
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001468 {
1469 RIL_CDMA_BroadcastSmsConfigInfo cdmaBci[num];
1470 RIL_CDMA_BroadcastSmsConfigInfo *cdmaBciPtrs[num];
Wink Savillea592eeb2009-05-22 13:26:36 -07001471
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001472 startRequest;
1473 for (int i = 0 ; i < num ; i++ ) {
1474 cdmaBciPtrs[i] = &cdmaBci[i];
Wink Savillea592eeb2009-05-22 13:26:36 -07001475
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001476 status = p.readInt32(&t);
1477 cdmaBci[i].service_category = (int) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001478
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001479 status = p.readInt32(&t);
1480 cdmaBci[i].language = (int) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001481
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001482 status = p.readInt32(&t);
1483 cdmaBci[i].selected = (uint8_t) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001484
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001485 appendPrintBuf("%s [%d: service_category=%d, language =%d, \
1486 entries.bSelected =%d]", printBuf, i, cdmaBci[i].service_category,
1487 cdmaBci[i].language, cdmaBci[i].selected);
1488 }
1489 closeRequest;
Wink Savillea592eeb2009-05-22 13:26:36 -07001490
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001491 if (status != NO_ERROR) {
1492 goto invalid;
1493 }
Wink Savillea592eeb2009-05-22 13:26:36 -07001494
Etan Cohend3652192014-06-20 08:28:44 -07001495 CALL_ONREQUEST(pRI->pCI->requestNumber,
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001496 cdmaBciPtrs,
1497 num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *),
Etan Cohend3652192014-06-20 08:28:44 -07001498 pRI, pRI->socket_id);
Wink Savillea592eeb2009-05-22 13:26:36 -07001499
1500#ifdef MEMSET_FREED
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001501 memset(cdmaBci, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo));
1502 memset(cdmaBciPtrs, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *));
Wink Savillea592eeb2009-05-22 13:26:36 -07001503#endif
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001504 }
Wink Savillea592eeb2009-05-22 13:26:36 -07001505
1506 return;
1507
1508invalid:
1509 invalidCommandBlock(pRI);
1510 return;
Wink Savillef4c4d362009-04-02 01:37:03 -07001511}
1512
1513static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI) {
1514 RIL_CDMA_SMS_WriteArgs rcsw;
1515 int32_t t;
1516 uint32_t ut;
1517 uint8_t uct;
1518 status_t status;
1519 int32_t digitCount;
1520
1521 memset(&rcsw, 0, sizeof(rcsw));
1522
1523 status = p.readInt32(&t);
1524 rcsw.status = t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001525
Wink Savillef4c4d362009-04-02 01:37:03 -07001526 status = p.readInt32(&t);
1527 rcsw.message.uTeleserviceID = (int) t;
1528
1529 status = p.read(&uct,sizeof(uct));
1530 rcsw.message.bIsServicePresent = (uint8_t) uct;
1531
1532 status = p.readInt32(&t);
1533 rcsw.message.uServicecategory = (int) t;
1534
1535 status = p.readInt32(&t);
1536 rcsw.message.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1537
1538 status = p.readInt32(&t);
1539 rcsw.message.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1540
1541 status = p.readInt32(&t);
1542 rcsw.message.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1543
1544 status = p.readInt32(&t);
1545 rcsw.message.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1546
1547 status = p.read(&uct,sizeof(uct));
1548 rcsw.message.sAddress.number_of_digits = (uint8_t) uct;
1549
1550 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_ADDRESS_MAX; digitCount ++) {
1551 status = p.read(&uct,sizeof(uct));
1552 rcsw.message.sAddress.digits[digitCount] = (uint8_t) uct;
1553 }
1554
Wink Savillea592eeb2009-05-22 13:26:36 -07001555 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001556 rcsw.message.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1557
Wink Savillea592eeb2009-05-22 13:26:36 -07001558 status = p.read(&uct,sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001559 rcsw.message.sSubAddress.odd = (uint8_t) uct;
1560
1561 status = p.read(&uct,sizeof(uct));
1562 rcsw.message.sSubAddress.number_of_digits = (uint8_t) uct;
1563
1564 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_SUBADDRESS_MAX; digitCount ++) {
Wink Savillea592eeb2009-05-22 13:26:36 -07001565 status = p.read(&uct,sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001566 rcsw.message.sSubAddress.digits[digitCount] = (uint8_t) uct;
1567 }
1568
Wink Savillea592eeb2009-05-22 13:26:36 -07001569 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001570 rcsw.message.uBearerDataLen = (int) t;
1571
1572 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_BEARER_DATA_MAX; digitCount ++) {
Wink Savillea592eeb2009-05-22 13:26:36 -07001573 status = p.read(&uct, sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001574 rcsw.message.aBearerData[digitCount] = (uint8_t) uct;
1575 }
1576
1577 if (status != NO_ERROR) {
1578 goto invalid;
1579 }
1580
1581 startRequest;
Wink Saville1b5fd232009-04-22 14:50:00 -07001582 appendPrintBuf("%sstatus=%d, message.uTeleserviceID=%d, message.bIsServicePresent=%d, \
1583 message.uServicecategory=%d, message.sAddress.digit_mode=%d, \
1584 message.sAddress.number_mode=%d, \
1585 message.sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07001586 printBuf, rcsw.status, rcsw.message.uTeleserviceID, rcsw.message.bIsServicePresent,
Wink Saville1b5fd232009-04-22 14:50:00 -07001587 rcsw.message.uServicecategory, rcsw.message.sAddress.digit_mode,
1588 rcsw.message.sAddress.number_mode,
1589 rcsw.message.sAddress.number_type);
Wink Savillef4c4d362009-04-02 01:37:03 -07001590 closeRequest;
1591
1592 printRequest(pRI->token, pRI->pCI->requestNumber);
1593
Etan Cohend3652192014-06-20 08:28:44 -07001594 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsw, sizeof(rcsw),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001595
1596#ifdef MEMSET_FREED
1597 memset(&rcsw, 0, sizeof(rcsw));
1598#endif
1599
1600 return;
1601
1602invalid:
1603 invalidCommandBlock(pRI);
1604 return;
1605
1606}
1607
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -07001608// For backwards compatibility in RIL_REQUEST_SETUP_DATA_CALL.
1609// Version 4 of the RIL interface adds a new PDP type parameter to support
1610// IPv6 and dual-stack PDP contexts. When dealing with a previous version of
1611// RIL, remove the parameter from the request.
1612static void dispatchDataCall(Parcel& p, RequestInfo *pRI) {
1613 // In RIL v3, REQUEST_SETUP_DATA_CALL takes 6 parameters.
1614 const int numParamsRilV3 = 6;
1615
1616 // The first bytes of the RIL parcel contain the request number and the
1617 // serial number - see processCommandBuffer(). Copy them over too.
1618 int pos = p.dataPosition();
1619
1620 int numParams = p.readInt32();
1621 if (s_callbacks.version < 4 && numParams > numParamsRilV3) {
1622 Parcel p2;
1623 p2.appendFrom(&p, 0, pos);
1624 p2.writeInt32(numParamsRilV3);
1625 for(int i = 0; i < numParamsRilV3; i++) {
1626 p2.writeString16(p.readString16());
1627 }
1628 p2.setDataPosition(pos);
1629 dispatchStrings(p2, pRI);
1630 } else {
Lorenzo Colitti57ce1f22010-09-13 12:23:50 -07001631 p.setDataPosition(pos);
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -07001632 dispatchStrings(p, pRI);
1633 }
1634}
1635
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001636// For backwards compatibility with RILs that dont support RIL_REQUEST_VOICE_RADIO_TECH.
1637// When all RILs handle this request, this function can be removed and
1638// the request can be sent directly to the RIL using dispatchVoid.
1639static void dispatchVoiceRadioTech(Parcel& p, RequestInfo *pRI) {
Etan Cohend3652192014-06-20 08:28:44 -07001640 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001641
1642 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1643 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1644 }
1645
1646 // RILs that support RADIO_STATE_ON should support this request.
1647 if (RADIO_STATE_ON == state) {
1648 dispatchVoid(p, pRI);
1649 return;
1650 }
1651
1652 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1653 // will not support this new request either and decode Voice Radio Technology
1654 // from Radio State
1655 voiceRadioTech = decodeVoiceRadioTechnology(state);
1656
1657 if (voiceRadioTech < 0)
1658 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1659 else
1660 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &voiceRadioTech, sizeof(int));
1661}
1662
1663// For backwards compatibility in RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE:.
1664// When all RILs handle this request, this function can be removed and
1665// the request can be sent directly to the RIL using dispatchVoid.
1666static void dispatchCdmaSubscriptionSource(Parcel& p, RequestInfo *pRI) {
Etan Cohend3652192014-06-20 08:28:44 -07001667 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001668
1669 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1670 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1671 }
1672
1673 // RILs that support RADIO_STATE_ON should support this request.
1674 if (RADIO_STATE_ON == state) {
1675 dispatchVoid(p, pRI);
1676 return;
1677 }
1678
1679 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1680 // will not support this new request either and decode CDMA Subscription Source
1681 // from Radio State
1682 cdmaSubscriptionSource = decodeCdmaSubscriptionSource(state);
1683
1684 if (cdmaSubscriptionSource < 0)
1685 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1686 else
1687 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &cdmaSubscriptionSource, sizeof(int));
1688}
1689
Sungmin Choi75697532013-04-26 15:04:45 -07001690static void dispatchSetInitialAttachApn(Parcel &p, RequestInfo *pRI)
1691{
1692 RIL_InitialAttachApn pf;
1693 int32_t t;
1694 status_t status;
1695
1696 memset(&pf, 0, sizeof(pf));
1697
1698 pf.apn = strdupReadString(p);
1699 pf.protocol = strdupReadString(p);
1700
1701 status = p.readInt32(&t);
1702 pf.authtype = (int) t;
1703
1704 pf.username = strdupReadString(p);
1705 pf.password = strdupReadString(p);
1706
1707 startRequest;
Etan Cohen5d891b72014-02-27 17:25:17 -08001708 appendPrintBuf("%sapn=%s, protocol=%s, authtype=%d, username=%s, password=%s",
1709 printBuf, pf.apn, pf.protocol, pf.authtype, pf.username, pf.password);
Sungmin Choi75697532013-04-26 15:04:45 -07001710 closeRequest;
1711 printRequest(pRI->token, pRI->pCI->requestNumber);
1712
1713 if (status != NO_ERROR) {
1714 goto invalid;
1715 }
Etan Cohend3652192014-06-20 08:28:44 -07001716 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
Sungmin Choi75697532013-04-26 15:04:45 -07001717
1718#ifdef MEMSET_FREED
1719 memsetString(pf.apn);
1720 memsetString(pf.protocol);
1721 memsetString(pf.username);
1722 memsetString(pf.password);
1723#endif
1724
1725 free(pf.apn);
1726 free(pf.protocol);
1727 free(pf.username);
1728 free(pf.password);
1729
1730#ifdef MEMSET_FREED
1731 memset(&pf, 0, sizeof(pf));
1732#endif
1733
1734 return;
1735invalid:
1736 invalidCommandBlock(pRI);
1737 return;
1738}
1739
Jake Hamby8a4a2332014-01-15 13:12:05 -08001740static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI) {
1741 RIL_NV_ReadItem nvri;
1742 int32_t t;
1743 status_t status;
1744
1745 memset(&nvri, 0, sizeof(nvri));
1746
1747 status = p.readInt32(&t);
1748 nvri.itemID = (RIL_NV_Item) t;
1749
1750 if (status != NO_ERROR) {
1751 goto invalid;
1752 }
1753
1754 startRequest;
1755 appendPrintBuf("%snvri.itemID=%d, ", printBuf, nvri.itemID);
1756 closeRequest;
1757
1758 printRequest(pRI->token, pRI->pCI->requestNumber);
1759
Etan Cohend3652192014-06-20 08:28:44 -07001760 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvri, sizeof(nvri), pRI, pRI->socket_id);
Jake Hamby8a4a2332014-01-15 13:12:05 -08001761
1762#ifdef MEMSET_FREED
1763 memset(&nvri, 0, sizeof(nvri));
1764#endif
1765
1766 return;
1767
1768invalid:
1769 invalidCommandBlock(pRI);
1770 return;
1771}
1772
1773static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI) {
1774 RIL_NV_WriteItem nvwi;
1775 int32_t t;
1776 status_t status;
1777
1778 memset(&nvwi, 0, sizeof(nvwi));
1779
1780 status = p.readInt32(&t);
1781 nvwi.itemID = (RIL_NV_Item) t;
1782
1783 nvwi.value = strdupReadString(p);
1784
1785 if (status != NO_ERROR || nvwi.value == NULL) {
1786 goto invalid;
1787 }
1788
1789 startRequest;
1790 appendPrintBuf("%snvwi.itemID=%d, value=%s, ", printBuf, nvwi.itemID,
1791 nvwi.value);
1792 closeRequest;
1793
1794 printRequest(pRI->token, pRI->pCI->requestNumber);
1795
Etan Cohend3652192014-06-20 08:28:44 -07001796 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvwi, sizeof(nvwi), pRI, pRI->socket_id);
Jake Hamby8a4a2332014-01-15 13:12:05 -08001797
1798#ifdef MEMSET_FREED
1799 memsetString(nvwi.value);
1800#endif
1801
1802 free(nvwi.value);
1803
1804#ifdef MEMSET_FREED
1805 memset(&nvwi, 0, sizeof(nvwi));
1806#endif
1807
1808 return;
1809
1810invalid:
1811 invalidCommandBlock(pRI);
1812 return;
1813}
1814
1815
Etan Cohend3652192014-06-20 08:28:44 -07001816static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI) {
1817 RIL_SelectUiccSub uicc_sub;
1818 status_t status;
1819 int32_t t;
1820 memset(&uicc_sub, 0, sizeof(uicc_sub));
1821
1822 status = p.readInt32(&t);
1823 if (status != NO_ERROR) {
1824 goto invalid;
1825 }
1826 uicc_sub.slot = (int) t;
1827
1828 status = p.readInt32(&t);
1829 if (status != NO_ERROR) {
1830 goto invalid;
1831 }
1832 uicc_sub.app_index = (int) t;
1833
1834 status = p.readInt32(&t);
1835 if (status != NO_ERROR) {
1836 goto invalid;
1837 }
1838 uicc_sub.sub_type = (RIL_SubscriptionType) t;
1839
1840 status = p.readInt32(&t);
1841 if (status != NO_ERROR) {
1842 goto invalid;
1843 }
1844 uicc_sub.act_status = (RIL_UiccSubActStatus) t;
1845
1846 startRequest;
1847 appendPrintBuf("slot=%d, app_index=%d, act_status = %d", uicc_sub.slot, uicc_sub.app_index,
1848 uicc_sub.act_status);
1849 RLOGD("dispatchUiccSubscription, slot=%d, app_index=%d, act_status = %d", uicc_sub.slot,
1850 uicc_sub.app_index, uicc_sub.act_status);
1851 closeRequest;
1852 printRequest(pRI->token, pRI->pCI->requestNumber);
1853
1854 CALL_ONREQUEST(pRI->pCI->requestNumber, &uicc_sub, sizeof(uicc_sub), pRI, pRI->socket_id);
1855
1856#ifdef MEMSET_FREED
1857 memset(&uicc_sub, 0, sizeof(uicc_sub));
1858#endif
1859 return;
1860
1861invalid:
1862 invalidCommandBlock(pRI);
1863 return;
1864}
1865
Amit Mahajan90530a62014-07-01 15:54:08 -07001866static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI)
1867{
1868 RIL_SimAuthentication pf;
1869 int32_t t;
1870 status_t status;
1871
1872 memset(&pf, 0, sizeof(pf));
1873
1874 status = p.readInt32(&t);
1875 pf.authContext = (int) t;
1876 pf.authData = strdupReadString(p);
1877 pf.aid = strdupReadString(p);
1878
1879 startRequest;
1880 appendPrintBuf("authContext=%s, authData=%s, aid=%s", pf.authContext, pf.authData, pf.aid);
1881 closeRequest;
1882 printRequest(pRI->token, pRI->pCI->requestNumber);
1883
1884 if (status != NO_ERROR) {
1885 goto invalid;
1886 }
1887 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
1888
1889#ifdef MEMSET_FREED
1890 memsetString(pf.authData);
1891 memsetString(pf.aid);
1892#endif
1893
1894 free(pf.authData);
1895 free(pf.aid);
1896
1897#ifdef MEMSET_FREED
1898 memset(&pf, 0, sizeof(pf));
1899#endif
1900
1901 return;
1902invalid:
1903 invalidCommandBlock(pRI);
1904 return;
1905}
1906
Amit Mahajanc796e222014-08-13 16:54:01 +00001907static void dispatchDataProfile(Parcel &p, RequestInfo *pRI) {
1908 int32_t t;
1909 status_t status;
1910 int32_t num;
1911
1912 status = p.readInt32(&num);
1913 if (status != NO_ERROR) {
1914 goto invalid;
1915 }
1916
1917 {
1918 RIL_DataProfileInfo dataProfiles[num];
1919 RIL_DataProfileInfo *dataProfilePtrs[num];
1920
1921 startRequest;
1922 for (int i = 0 ; i < num ; i++ ) {
1923 dataProfilePtrs[i] = &dataProfiles[i];
1924
1925 status = p.readInt32(&t);
1926 dataProfiles[i].profileId = (int) t;
1927
1928 dataProfiles[i].apn = strdupReadString(p);
1929 dataProfiles[i].protocol = strdupReadString(p);
1930 status = p.readInt32(&t);
1931 dataProfiles[i].authType = (int) t;
1932
1933 dataProfiles[i].user = strdupReadString(p);
1934 dataProfiles[i].password = strdupReadString(p);
1935
1936 status = p.readInt32(&t);
1937 dataProfiles[i].type = (int) t;
1938
1939 status = p.readInt32(&t);
1940 dataProfiles[i].maxConnsTime = (int) t;
1941 status = p.readInt32(&t);
1942 dataProfiles[i].maxConns = (int) t;
1943 status = p.readInt32(&t);
1944 dataProfiles[i].waitTime = (int) t;
1945
1946 status = p.readInt32(&t);
1947 dataProfiles[i].enabled = (int) t;
1948
1949 appendPrintBuf("%s [%d: profileId=%d, apn =%s, protocol =%s, authType =%d, \
1950 user =%s, password =%s, type =%d, maxConnsTime =%d, maxConns =%d, \
1951 waitTime =%d, enabled =%d]", printBuf, i, dataProfiles[i].profileId,
1952 dataProfiles[i].apn, dataProfiles[i].protocol, dataProfiles[i].authType,
1953 dataProfiles[i].user, dataProfiles[i].password, dataProfiles[i].type,
1954 dataProfiles[i].maxConnsTime, dataProfiles[i].maxConns,
1955 dataProfiles[i].waitTime, dataProfiles[i].enabled);
1956 }
1957 closeRequest;
1958 printRequest(pRI->token, pRI->pCI->requestNumber);
1959
1960 if (status != NO_ERROR) {
1961 goto invalid;
1962 }
1963 CALL_ONREQUEST(pRI->pCI->requestNumber,
1964 dataProfilePtrs,
1965 num * sizeof(RIL_DataProfileInfo *),
1966 pRI, pRI->socket_id);
1967
1968#ifdef MEMSET_FREED
1969 memset(dataProfiles, 0, num * sizeof(RIL_DataProfileInfo));
1970 memset(dataProfilePtrs, 0, num * sizeof(RIL_DataProfileInfo *));
1971#endif
1972 }
1973
1974 return;
1975
1976invalid:
1977 invalidCommandBlock(pRI);
1978 return;
1979}
1980
Wink Saville8b4e4f72014-10-17 15:01:45 -07001981static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI){
1982 RIL_RadioCapability rc;
1983 int32_t t;
1984 status_t status;
1985
1986 memset (&rc, 0, sizeof(RIL_RadioCapability));
1987
1988 status = p.readInt32(&t);
1989 rc.version = (int)t;
1990 if (status != NO_ERROR) {
1991 goto invalid;
1992 }
1993
1994 status = p.readInt32(&t);
1995 rc.session= (int)t;
1996 if (status != NO_ERROR) {
1997 goto invalid;
1998 }
1999
2000 status = p.readInt32(&t);
2001 rc.phase= (int)t;
2002 if (status != NO_ERROR) {
2003 goto invalid;
2004 }
2005
2006 status = p.readInt32(&t);
2007 rc.rat = (int)t;
2008 if (status != NO_ERROR) {
2009 goto invalid;
2010 }
2011
2012 status = readStringFromParcelInplace(p, rc.logicalModemUuid, sizeof(rc.logicalModemUuid));
2013 if (status != NO_ERROR) {
2014 goto invalid;
2015 }
2016
2017 status = p.readInt32(&t);
2018 rc.status = (int)t;
2019
2020 if (status != NO_ERROR) {
2021 goto invalid;
2022 }
2023
2024 startRequest;
2025 appendPrintBuf("%s [version:%d, session:%d, phase:%d, rat:%d, \
Legler Wu8caf06f2014-10-29 14:02:14 +08002026 logicalModemUuid:%s, status:%d", printBuf, rc.version, rc.session
2027 rc.phase, rc.rat, rc.logicalModemUuid, rc.session);
Wink Saville8b4e4f72014-10-17 15:01:45 -07002028
2029 closeRequest;
2030 printRequest(pRI->token, pRI->pCI->requestNumber);
2031
2032 CALL_ONREQUEST(pRI->pCI->requestNumber,
2033 &rc,
2034 sizeof(RIL_RadioCapability),
2035 pRI, pRI->socket_id);
2036 return;
2037invalid:
2038 invalidCommandBlock(pRI);
2039 return;
2040}
2041
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002042static int
Wink Savillef4c4d362009-04-02 01:37:03 -07002043blockingWrite(int fd, const void *buffer, size_t len) {
Wink Saville7f856802009-06-09 10:23:37 -07002044 size_t writeOffset = 0;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002045 const uint8_t *toWrite;
2046
2047 toWrite = (const uint8_t *)buffer;
2048
2049 while (writeOffset < len) {
2050 ssize_t written;
2051 do {
2052 written = write (fd, toWrite + writeOffset,
2053 len - writeOffset);
Banavathu, Srinivas Naik38884902011-07-05 20:04:25 +05302054 } while (written < 0 && ((errno == EINTR) || (errno == EAGAIN)));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002055
2056 if (written >= 0) {
2057 writeOffset += written;
2058 } else { // written < 0
Wink Saville8eb2a122012-11-19 16:05:13 -08002059 RLOGE ("RIL Response: unexpected error on write errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002060 close(fd);
2061 return -1;
2062 }
2063 }
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07002064#if VDBG
Dheeraj Shetty27976c42014-07-02 21:27:57 +02002065 RLOGE("RIL Response bytes written:%d", writeOffset);
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07002066#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002067 return 0;
2068}
2069
2070static int
Etan Cohend3652192014-06-20 08:28:44 -07002071sendResponseRaw (const void *data, size_t dataSize, RIL_SOCKET_ID socket_id) {
2072 int fd = s_ril_param_socket.fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002073 int ret;
2074 uint32_t header;
Etan Cohend3652192014-06-20 08:28:44 -07002075 pthread_mutex_t * writeMutexHook = &s_writeMutex;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002076
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07002077#if VDBG
Etan Cohend3652192014-06-20 08:28:44 -07002078 RLOGE("Send Response to %s", rilSocketIdToString(socket_id));
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07002079#endif
Etan Cohend3652192014-06-20 08:28:44 -07002080
2081#if (SIM_COUNT >= 2)
2082 if (socket_id == RIL_SOCKET_2) {
2083 fd = s_ril_param_socket2.fdCommand;
2084 writeMutexHook = &s_writeMutex_socket2;
2085 }
2086#if (SIM_COUNT >= 3)
2087 else if (socket_id == RIL_SOCKET_3) {
2088 fd = s_ril_param_socket3.fdCommand;
2089 writeMutexHook = &s_writeMutex_socket3;
2090 }
2091#endif
2092#if (SIM_COUNT >= 4)
2093 else if (socket_id == RIL_SOCKET_4) {
2094 fd = s_ril_param_socket4.fdCommand;
2095 writeMutexHook = &s_writeMutex_socket4;
2096 }
2097#endif
2098#endif
2099 if (fd < 0) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002100 return -1;
2101 }
2102
2103 if (dataSize > MAX_COMMAND_BYTES) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002104 RLOGE("RIL: packet larger than %u (%u)",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002105 MAX_COMMAND_BYTES, (unsigned int )dataSize);
2106
2107 return -1;
2108 }
Wink Saville7f856802009-06-09 10:23:37 -07002109
Etan Cohend3652192014-06-20 08:28:44 -07002110 pthread_mutex_lock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002111
2112 header = htonl(dataSize);
2113
2114 ret = blockingWrite(fd, (void *)&header, sizeof(header));
2115
2116 if (ret < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002117 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002118 return ret;
2119 }
2120
Kennyee1fadc2009-08-13 00:45:53 +08002121 ret = blockingWrite(fd, data, dataSize);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002122
2123 if (ret < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002124 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002125 return ret;
2126 }
2127
Etan Cohend3652192014-06-20 08:28:44 -07002128 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002129
2130 return 0;
2131}
2132
2133static int
Etan Cohend3652192014-06-20 08:28:44 -07002134sendResponse (Parcel &p, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002135 printResponse;
Etan Cohend3652192014-06-20 08:28:44 -07002136 return sendResponseRaw(p.data(), p.dataSize(), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002137}
2138
Mohamad Ayyash74f7e662014-04-18 11:43:28 -07002139/** response is an int* pointing to an array of ints */
Wink Saville7f856802009-06-09 10:23:37 -07002140
2141static int
Wink Savillef4c4d362009-04-02 01:37:03 -07002142responseInts(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002143 int numInts;
2144
2145 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002146 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002147 return RIL_ERRNO_INVALID_RESPONSE;
2148 }
2149 if (responselen % sizeof(int) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002150 RLOGE("responseInts: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002151 (int)responselen, (int)sizeof(int));
2152 return RIL_ERRNO_INVALID_RESPONSE;
2153 }
2154
2155 int *p_int = (int *) response;
2156
Mohamad Ayyash74f7e662014-04-18 11:43:28 -07002157 numInts = responselen / sizeof(int);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002158 p.writeInt32 (numInts);
2159
2160 /* each int*/
2161 startResponse;
2162 for (int i = 0 ; i < numInts ; i++) {
2163 appendPrintBuf("%s%d,", printBuf, p_int[i]);
2164 p.writeInt32(p_int[i]);
2165 }
2166 removeLastChar;
2167 closeResponse;
2168
2169 return 0;
2170}
2171
Wink Saville43808972011-01-13 17:39:51 -08002172/** response is a char **, pointing to an array of char *'s
2173 The parcel will begin with the version */
2174static int responseStringsWithVersion(int version, Parcel &p, void *response, size_t responselen) {
2175 p.writeInt32(version);
2176 return responseStrings(p, response, responselen);
2177}
2178
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002179/** response is a char **, pointing to an array of char *'s */
Wink Savillef4c4d362009-04-02 01:37:03 -07002180static int responseStrings(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002181 int numStrings;
Wink Saville7f856802009-06-09 10:23:37 -07002182
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002183 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002184 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002185 return RIL_ERRNO_INVALID_RESPONSE;
2186 }
2187 if (responselen % sizeof(char *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002188 RLOGE("responseStrings: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002189 (int)responselen, (int)sizeof(char *));
2190 return RIL_ERRNO_INVALID_RESPONSE;
2191 }
2192
2193 if (response == NULL) {
2194 p.writeInt32 (0);
2195 } else {
2196 char **p_cur = (char **) response;
2197
2198 numStrings = responselen / sizeof(char *);
2199 p.writeInt32 (numStrings);
2200
2201 /* each string*/
2202 startResponse;
2203 for (int i = 0 ; i < numStrings ; i++) {
2204 appendPrintBuf("%s%s,", printBuf, (char*)p_cur[i]);
2205 writeStringToParcel (p, p_cur[i]);
2206 }
2207 removeLastChar;
2208 closeResponse;
2209 }
2210 return 0;
2211}
2212
2213
2214/**
Wink Saville7f856802009-06-09 10:23:37 -07002215 * NULL strings are accepted
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002216 * FIXME currently ignores responselen
2217 */
Wink Savillef4c4d362009-04-02 01:37:03 -07002218static int responseString(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002219 /* one string only */
2220 startResponse;
2221 appendPrintBuf("%s%s", printBuf, (char*)response);
2222 closeResponse;
2223
2224 writeStringToParcel(p, (const char *)response);
2225
2226 return 0;
2227}
2228
Wink Savillef4c4d362009-04-02 01:37:03 -07002229static int responseVoid(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002230 startResponse;
2231 removeLastChar;
2232 return 0;
2233}
2234
Wink Savillef4c4d362009-04-02 01:37:03 -07002235static int responseCallList(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002236 int num;
2237
2238 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002239 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002240 return RIL_ERRNO_INVALID_RESPONSE;
2241 }
2242
2243 if (responselen % sizeof (RIL_Call *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002244 RLOGE("responseCallList: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002245 (int)responselen, (int)sizeof (RIL_Call *));
2246 return RIL_ERRNO_INVALID_RESPONSE;
2247 }
2248
2249 startResponse;
2250 /* number of call info's */
2251 num = responselen / sizeof(RIL_Call *);
2252 p.writeInt32(num);
2253
2254 for (int i = 0 ; i < num ; i++) {
2255 RIL_Call *p_cur = ((RIL_Call **) response)[i];
2256 /* each call info */
2257 p.writeInt32(p_cur->state);
2258 p.writeInt32(p_cur->index);
2259 p.writeInt32(p_cur->toa);
2260 p.writeInt32(p_cur->isMpty);
2261 p.writeInt32(p_cur->isMT);
2262 p.writeInt32(p_cur->als);
2263 p.writeInt32(p_cur->isVoice);
Wink Saville1b5fd232009-04-22 14:50:00 -07002264 p.writeInt32(p_cur->isVoicePrivacy);
2265 writeStringToParcel(p, p_cur->number);
John Wangff368742009-03-24 17:56:29 -07002266 p.writeInt32(p_cur->numberPresentation);
Wink Saville1b5fd232009-04-22 14:50:00 -07002267 writeStringToParcel(p, p_cur->name);
2268 p.writeInt32(p_cur->namePresentation);
Wink Saville3a4840b2010-04-07 13:29:58 -07002269 // Remove when partners upgrade to version 3
Wink Saville74fa3882009-12-22 15:35:41 -08002270 if ((s_callbacks.version < 3) || (p_cur->uusInfo == NULL || p_cur->uusInfo->uusData == NULL)) {
2271 p.writeInt32(0); /* UUS Information is absent */
2272 } else {
2273 RIL_UUS_Info *uusInfo = p_cur->uusInfo;
2274 p.writeInt32(1); /* UUS Information is present */
2275 p.writeInt32(uusInfo->uusType);
2276 p.writeInt32(uusInfo->uusDcs);
2277 p.writeInt32(uusInfo->uusLength);
2278 p.write(uusInfo->uusData, uusInfo->uusLength);
2279 }
Wink Saville3d54e742009-05-18 18:00:44 -07002280 appendPrintBuf("%s[id=%d,%s,toa=%d,",
John Wangff368742009-03-24 17:56:29 -07002281 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002282 p_cur->index,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002283 callStateToString(p_cur->state),
Wink Saville3d54e742009-05-18 18:00:44 -07002284 p_cur->toa);
2285 appendPrintBuf("%s%s,%s,als=%d,%s,%s,",
2286 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002287 (p_cur->isMpty)?"conf":"norm",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002288 (p_cur->isMT)?"mt":"mo",
2289 p_cur->als,
2290 (p_cur->isVoice)?"voc":"nonvoc",
Wink Saville3d54e742009-05-18 18:00:44 -07002291 (p_cur->isVoicePrivacy)?"evp":"noevp");
2292 appendPrintBuf("%s%s,cli=%d,name='%s',%d]",
2293 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002294 p_cur->number,
2295 p_cur->numberPresentation,
2296 p_cur->name,
2297 p_cur->namePresentation);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002298 }
2299 removeLastChar;
2300 closeResponse;
2301
2302 return 0;
2303}
2304
Wink Savillef4c4d362009-04-02 01:37:03 -07002305static int responseSMS(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002306 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002307 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002308 return RIL_ERRNO_INVALID_RESPONSE;
2309 }
2310
2311 if (responselen != sizeof (RIL_SMS_Response) ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002312 RLOGE("invalid response length %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002313 (int)responselen, (int)sizeof (RIL_SMS_Response));
2314 return RIL_ERRNO_INVALID_RESPONSE;
2315 }
2316
2317 RIL_SMS_Response *p_cur = (RIL_SMS_Response *) response;
2318
2319 p.writeInt32(p_cur->messageRef);
2320 writeStringToParcel(p, p_cur->ackPDU);
Jaikumar Ganesh920c78f2009-06-04 10:53:15 -07002321 p.writeInt32(p_cur->errorCode);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002322
2323 startResponse;
Jaikumar Ganesh920c78f2009-06-04 10:53:15 -07002324 appendPrintBuf("%s%d,%s,%d", printBuf, p_cur->messageRef,
2325 (char*)p_cur->ackPDU, p_cur->errorCode);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002326 closeResponse;
2327
2328 return 0;
2329}
2330
Wink Savillec0114b32011-02-18 10:14:07 -08002331static int responseDataCallListV4(Parcel &p, void *response, size_t responselen)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002332{
2333 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002334 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002335 return RIL_ERRNO_INVALID_RESPONSE;
2336 }
2337
Wink Savillec0114b32011-02-18 10:14:07 -08002338 if (responselen % sizeof(RIL_Data_Call_Response_v4) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002339 RLOGE("responseDataCallListV4: invalid response length %d expected multiple of %d",
Wink Savillec0114b32011-02-18 10:14:07 -08002340 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v4));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002341 return RIL_ERRNO_INVALID_RESPONSE;
2342 }
2343
Amit Mahajan52500162014-07-29 17:36:48 -07002344 // Write version
2345 p.writeInt32(4);
2346
Wink Savillec0114b32011-02-18 10:14:07 -08002347 int num = responselen / sizeof(RIL_Data_Call_Response_v4);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002348 p.writeInt32(num);
2349
Wink Savillec0114b32011-02-18 10:14:07 -08002350 RIL_Data_Call_Response_v4 *p_cur = (RIL_Data_Call_Response_v4 *) response;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002351 startResponse;
2352 int i;
2353 for (i = 0; i < num; i++) {
2354 p.writeInt32(p_cur[i].cid);
2355 p.writeInt32(p_cur[i].active);
2356 writeStringToParcel(p, p_cur[i].type);
Wink Savillec0114b32011-02-18 10:14:07 -08002357 // apn is not used, so don't send.
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002358 writeStringToParcel(p, p_cur[i].address);
Wink Savillec0114b32011-02-18 10:14:07 -08002359 appendPrintBuf("%s[cid=%d,%s,%s,%s],", printBuf,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002360 p_cur[i].cid,
2361 (p_cur[i].active==0)?"down":"up",
2362 (char*)p_cur[i].type,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002363 (char*)p_cur[i].address);
2364 }
2365 removeLastChar;
2366 closeResponse;
2367
2368 return 0;
2369}
2370
Etan Cohend3652192014-06-20 08:28:44 -07002371static int responseDataCallListV6(Parcel &p, void *response, size_t responselen)
2372{
Amit Mahajan52500162014-07-29 17:36:48 -07002373 if (response == NULL && responselen != 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002374 RLOGE("invalid response: NULL");
2375 return RIL_ERRNO_INVALID_RESPONSE;
2376 }
2377
2378 if (responselen % sizeof(RIL_Data_Call_Response_v6) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002379 RLOGE("responseDataCallListV6: invalid response length %d expected multiple of %d",
Etan Cohend3652192014-06-20 08:28:44 -07002380 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v6));
2381 return RIL_ERRNO_INVALID_RESPONSE;
2382 }
2383
Amit Mahajan52500162014-07-29 17:36:48 -07002384 // Write version
2385 p.writeInt32(6);
2386
Etan Cohend3652192014-06-20 08:28:44 -07002387 int num = responselen / sizeof(RIL_Data_Call_Response_v6);
2388 p.writeInt32(num);
2389
2390 RIL_Data_Call_Response_v6 *p_cur = (RIL_Data_Call_Response_v6 *) response;
2391 startResponse;
2392 int i;
2393 for (i = 0; i < num; i++) {
2394 p.writeInt32((int)p_cur[i].status);
2395 p.writeInt32(p_cur[i].suggestedRetryTime);
2396 p.writeInt32(p_cur[i].cid);
2397 p.writeInt32(p_cur[i].active);
2398 writeStringToParcel(p, p_cur[i].type);
2399 writeStringToParcel(p, p_cur[i].ifname);
2400 writeStringToParcel(p, p_cur[i].addresses);
2401 writeStringToParcel(p, p_cur[i].dnses);
2402 writeStringToParcel(p, p_cur[i].gateways);
2403 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s],", printBuf,
2404 p_cur[i].status,
2405 p_cur[i].suggestedRetryTime,
2406 p_cur[i].cid,
2407 (p_cur[i].active==0)?"down":"up",
2408 (char*)p_cur[i].type,
2409 (char*)p_cur[i].ifname,
2410 (char*)p_cur[i].addresses,
2411 (char*)p_cur[i].dnses,
2412 (char*)p_cur[i].gateways);
2413 }
2414 removeLastChar;
2415 closeResponse;
2416
2417 return 0;
2418}
2419
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002420static int responseDataCallListV9(Parcel &p, void *response, size_t responselen)
2421{
2422 if (response == NULL && responselen != 0) {
2423 RLOGE("invalid response: NULL");
2424 return RIL_ERRNO_INVALID_RESPONSE;
2425 }
2426
2427 if (responselen % sizeof(RIL_Data_Call_Response_v9) != 0) {
2428 RLOGE("responseDataCallListV9: invalid response length %d expected multiple of %d",
2429 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v9));
2430 return RIL_ERRNO_INVALID_RESPONSE;
2431 }
2432
2433 // Write version
2434 p.writeInt32(10);
2435
2436 int num = responselen / sizeof(RIL_Data_Call_Response_v9);
2437 p.writeInt32(num);
2438
2439 RIL_Data_Call_Response_v9 *p_cur = (RIL_Data_Call_Response_v9 *) response;
2440 startResponse;
2441 int i;
2442 for (i = 0; i < num; i++) {
2443 p.writeInt32((int)p_cur[i].status);
2444 p.writeInt32(p_cur[i].suggestedRetryTime);
2445 p.writeInt32(p_cur[i].cid);
2446 p.writeInt32(p_cur[i].active);
2447 writeStringToParcel(p, p_cur[i].type);
2448 writeStringToParcel(p, p_cur[i].ifname);
2449 writeStringToParcel(p, p_cur[i].addresses);
2450 writeStringToParcel(p, p_cur[i].dnses);
2451 writeStringToParcel(p, p_cur[i].gateways);
2452 writeStringToParcel(p, p_cur[i].pcscf);
2453 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s],", printBuf,
2454 p_cur[i].status,
2455 p_cur[i].suggestedRetryTime,
2456 p_cur[i].cid,
2457 (p_cur[i].active==0)?"down":"up",
2458 (char*)p_cur[i].type,
2459 (char*)p_cur[i].ifname,
2460 (char*)p_cur[i].addresses,
2461 (char*)p_cur[i].dnses,
2462 (char*)p_cur[i].gateways,
2463 (char*)p_cur[i].pcscf);
2464 }
2465 removeLastChar;
2466 closeResponse;
2467
2468 return 0;
2469}
2470
2471
Wink Saville43808972011-01-13 17:39:51 -08002472static int responseDataCallList(Parcel &p, void *response, size_t responselen)
2473{
Wink Saville43808972011-01-13 17:39:51 -08002474 if (s_callbacks.version < 5) {
Amit Mahajan52500162014-07-29 17:36:48 -07002475 RLOGD("responseDataCallList: v4");
Wink Savillec0114b32011-02-18 10:14:07 -08002476 return responseDataCallListV4(p, response, responselen);
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002477 } else if (responselen % sizeof(RIL_Data_Call_Response_v6) == 0) {
2478 return responseDataCallListV6(p, response, responselen);
2479 } else if (responselen % sizeof(RIL_Data_Call_Response_v9) == 0) {
2480 return responseDataCallListV9(p, response, responselen);
Wink Saville43808972011-01-13 17:39:51 -08002481 } else {
2482 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002483 RLOGE("invalid response: NULL");
Wink Saville43808972011-01-13 17:39:51 -08002484 return RIL_ERRNO_INVALID_RESPONSE;
2485 }
2486
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002487 if (responselen % sizeof(RIL_Data_Call_Response_v11) != 0) {
2488 RLOGE("invalid response length %d expected multiple of %d",
2489 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v11));
Wink Saville43808972011-01-13 17:39:51 -08002490 return RIL_ERRNO_INVALID_RESPONSE;
2491 }
2492
Amit Mahajan52500162014-07-29 17:36:48 -07002493 // Write version
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002494 p.writeInt32(11);
Amit Mahajan52500162014-07-29 17:36:48 -07002495
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002496 int num = responselen / sizeof(RIL_Data_Call_Response_v11);
Wink Saville43808972011-01-13 17:39:51 -08002497 p.writeInt32(num);
2498
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002499 RIL_Data_Call_Response_v11 *p_cur = (RIL_Data_Call_Response_v11 *) response;
Wink Saville43808972011-01-13 17:39:51 -08002500 startResponse;
2501 int i;
2502 for (i = 0; i < num; i++) {
2503 p.writeInt32((int)p_cur[i].status);
Kazuhiro Ondobeb25b52011-06-17 16:26:45 -05002504 p.writeInt32(p_cur[i].suggestedRetryTime);
Wink Saville43808972011-01-13 17:39:51 -08002505 p.writeInt32(p_cur[i].cid);
2506 p.writeInt32(p_cur[i].active);
David 'Digit' Turneraf1298d2011-02-04 13:36:47 +01002507 writeStringToParcel(p, p_cur[i].type);
Wink Saville43808972011-01-13 17:39:51 -08002508 writeStringToParcel(p, p_cur[i].ifname);
2509 writeStringToParcel(p, p_cur[i].addresses);
2510 writeStringToParcel(p, p_cur[i].dnses);
Wink Savillec0114b32011-02-18 10:14:07 -08002511 writeStringToParcel(p, p_cur[i].gateways);
Etan Cohend3652192014-06-20 08:28:44 -07002512 writeStringToParcel(p, p_cur[i].pcscf);
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002513 p.writeInt32(p_cur[i].mtu);
2514 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 -08002515 p_cur[i].status,
Kazuhiro Ondobeb25b52011-06-17 16:26:45 -05002516 p_cur[i].suggestedRetryTime,
Wink Saville43808972011-01-13 17:39:51 -08002517 p_cur[i].cid,
2518 (p_cur[i].active==0)?"down":"up",
Naveen Kalla56384152011-11-16 11:12:37 -08002519 (char*)p_cur[i].type,
Wink Saville43808972011-01-13 17:39:51 -08002520 (char*)p_cur[i].ifname,
2521 (char*)p_cur[i].addresses,
Wink Savillec0114b32011-02-18 10:14:07 -08002522 (char*)p_cur[i].dnses,
Etan Cohend3652192014-06-20 08:28:44 -07002523 (char*)p_cur[i].gateways,
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002524 (char*)p_cur[i].pcscf,
2525 p_cur[i].mtu);
Wink Saville43808972011-01-13 17:39:51 -08002526 }
2527 removeLastChar;
2528 closeResponse;
2529 }
2530
2531 return 0;
2532}
2533
2534static int responseSetupDataCall(Parcel &p, void *response, size_t responselen)
2535{
2536 if (s_callbacks.version < 5) {
2537 return responseStringsWithVersion(s_callbacks.version, p, response, responselen);
2538 } else {
2539 return responseDataCallList(p, response, responselen);
2540 }
2541}
2542
Wink Savillef4c4d362009-04-02 01:37:03 -07002543static int responseRaw(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002544 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002545 RLOGE("invalid response: NULL with responselen != 0");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002546 return RIL_ERRNO_INVALID_RESPONSE;
2547 }
2548
2549 // The java code reads -1 size as null byte array
2550 if (response == NULL) {
Wink Saville7f856802009-06-09 10:23:37 -07002551 p.writeInt32(-1);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002552 } else {
2553 p.writeInt32(responselen);
2554 p.write(response, responselen);
2555 }
2556
2557 return 0;
2558}
2559
2560
Wink Savillef4c4d362009-04-02 01:37:03 -07002561static int responseSIM_IO(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002562 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002563 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002564 return RIL_ERRNO_INVALID_RESPONSE;
2565 }
2566
2567 if (responselen != sizeof (RIL_SIM_IO_Response) ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002568 RLOGE("invalid response length was %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002569 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
2570 return RIL_ERRNO_INVALID_RESPONSE;
2571 }
2572
2573 RIL_SIM_IO_Response *p_cur = (RIL_SIM_IO_Response *) response;
2574 p.writeInt32(p_cur->sw1);
2575 p.writeInt32(p_cur->sw2);
2576 writeStringToParcel(p, p_cur->simResponse);
2577
2578 startResponse;
2579 appendPrintBuf("%ssw1=0x%X,sw2=0x%X,%s", printBuf, p_cur->sw1, p_cur->sw2,
2580 (char*)p_cur->simResponse);
2581 closeResponse;
2582
2583
2584 return 0;
2585}
2586
Wink Savillef4c4d362009-04-02 01:37:03 -07002587static int responseCallForwards(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002588 int num;
Wink Saville7f856802009-06-09 10:23:37 -07002589
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002590 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002591 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002592 return RIL_ERRNO_INVALID_RESPONSE;
2593 }
2594
2595 if (responselen % sizeof(RIL_CallForwardInfo *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002596 RLOGE("responseCallForwards: invalid response length %d expected multiple of %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002597 (int)responselen, (int)sizeof(RIL_CallForwardInfo *));
2598 return RIL_ERRNO_INVALID_RESPONSE;
2599 }
2600
2601 /* number of call info's */
2602 num = responselen / sizeof(RIL_CallForwardInfo *);
2603 p.writeInt32(num);
2604
2605 startResponse;
2606 for (int i = 0 ; i < num ; i++) {
2607 RIL_CallForwardInfo *p_cur = ((RIL_CallForwardInfo **) response)[i];
2608
2609 p.writeInt32(p_cur->status);
2610 p.writeInt32(p_cur->reason);
2611 p.writeInt32(p_cur->serviceClass);
2612 p.writeInt32(p_cur->toa);
2613 writeStringToParcel(p, p_cur->number);
2614 p.writeInt32(p_cur->timeSeconds);
2615 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
2616 (p_cur->status==1)?"enable":"disable",
2617 p_cur->reason, p_cur->serviceClass, p_cur->toa,
2618 (char*)p_cur->number,
2619 p_cur->timeSeconds);
2620 }
2621 removeLastChar;
2622 closeResponse;
Wink Saville7f856802009-06-09 10:23:37 -07002623
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002624 return 0;
2625}
2626
Wink Savillef4c4d362009-04-02 01:37:03 -07002627static int responseSsn(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002628 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002629 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002630 return RIL_ERRNO_INVALID_RESPONSE;
2631 }
2632
2633 if (responselen != sizeof(RIL_SuppSvcNotification)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002634 RLOGE("invalid response length was %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002635 (int)responselen, (int)sizeof (RIL_SuppSvcNotification));
2636 return RIL_ERRNO_INVALID_RESPONSE;
2637 }
2638
2639 RIL_SuppSvcNotification *p_cur = (RIL_SuppSvcNotification *) response;
2640 p.writeInt32(p_cur->notificationType);
2641 p.writeInt32(p_cur->code);
2642 p.writeInt32(p_cur->index);
2643 p.writeInt32(p_cur->type);
2644 writeStringToParcel(p, p_cur->number);
2645
2646 startResponse;
2647 appendPrintBuf("%s%s,code=%d,id=%d,type=%d,%s", printBuf,
2648 (p_cur->notificationType==0)?"mo":"mt",
2649 p_cur->code, p_cur->index, p_cur->type,
2650 (char*)p_cur->number);
2651 closeResponse;
2652
2653 return 0;
2654}
2655
Wink Saville3d54e742009-05-18 18:00:44 -07002656static int responseCellList(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002657 int num;
2658
2659 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002660 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002661 return RIL_ERRNO_INVALID_RESPONSE;
2662 }
2663
2664 if (responselen % sizeof (RIL_NeighboringCell *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002665 RLOGE("responseCellList: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002666 (int)responselen, (int)sizeof (RIL_NeighboringCell *));
2667 return RIL_ERRNO_INVALID_RESPONSE;
2668 }
2669
2670 startResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002671 /* number of records */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002672 num = responselen / sizeof(RIL_NeighboringCell *);
2673 p.writeInt32(num);
2674
2675 for (int i = 0 ; i < num ; i++) {
2676 RIL_NeighboringCell *p_cur = ((RIL_NeighboringCell **) response)[i];
2677
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002678 p.writeInt32(p_cur->rssi);
2679 writeStringToParcel (p, p_cur->cid);
2680
2681 appendPrintBuf("%s[cid=%s,rssi=%d],", printBuf,
2682 p_cur->cid, p_cur->rssi);
2683 }
2684 removeLastChar;
2685 closeResponse;
2686
2687 return 0;
2688}
2689
Wink Saville3d54e742009-05-18 18:00:44 -07002690/**
2691 * Marshall the signalInfoRecord into the parcel if it exists.
2692 */
Wink Savillea592eeb2009-05-22 13:26:36 -07002693static void marshallSignalInfoRecord(Parcel &p,
2694 RIL_CDMA_SignalInfoRecord &p_signalInfoRecord) {
Wink Saville3d54e742009-05-18 18:00:44 -07002695 p.writeInt32(p_signalInfoRecord.isPresent);
2696 p.writeInt32(p_signalInfoRecord.signalType);
2697 p.writeInt32(p_signalInfoRecord.alertPitch);
2698 p.writeInt32(p_signalInfoRecord.signal);
2699}
2700
Wink Savillea592eeb2009-05-22 13:26:36 -07002701static int responseCdmaInformationRecords(Parcel &p,
2702 void *response, size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07002703 int num;
Wink Savillea592eeb2009-05-22 13:26:36 -07002704 char* string8 = NULL;
2705 int buffer_lenght;
2706 RIL_CDMA_InformationRecord *infoRec;
Wink Saville3d54e742009-05-18 18:00:44 -07002707
2708 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002709 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002710 return RIL_ERRNO_INVALID_RESPONSE;
2711 }
2712
Wink Savillea592eeb2009-05-22 13:26:36 -07002713 if (responselen != sizeof (RIL_CDMA_InformationRecords)) {
Amit Mahajan52500162014-07-29 17:36:48 -07002714 RLOGE("responseCdmaInformationRecords: invalid response length %d expected multiple of %d\n",
Wink Savillea592eeb2009-05-22 13:26:36 -07002715 (int)responselen, (int)sizeof (RIL_CDMA_InformationRecords *));
Wink Saville3d54e742009-05-18 18:00:44 -07002716 return RIL_ERRNO_INVALID_RESPONSE;
2717 }
2718
Wink Savillea592eeb2009-05-22 13:26:36 -07002719 RIL_CDMA_InformationRecords *p_cur =
2720 (RIL_CDMA_InformationRecords *) response;
2721 num = MIN(p_cur->numberOfInfoRecs, RIL_CDMA_MAX_NUMBER_OF_INFO_RECS);
Wink Saville3d54e742009-05-18 18:00:44 -07002722
2723 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07002724 p.writeInt32(num);
Wink Saville3d54e742009-05-18 18:00:44 -07002725
Wink Savillea592eeb2009-05-22 13:26:36 -07002726 for (int i = 0 ; i < num ; i++) {
2727 infoRec = &p_cur->infoRec[i];
2728 p.writeInt32(infoRec->name);
2729 switch (infoRec->name) {
Wink Saville3d54e742009-05-18 18:00:44 -07002730 case RIL_CDMA_DISPLAY_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002731 case RIL_CDMA_EXTENDED_DISPLAY_INFO_REC:
2732 if (infoRec->rec.display.alpha_len >
2733 CDMA_ALPHA_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002734 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002735 expected not more than %d\n",
2736 (int)infoRec->rec.display.alpha_len,
2737 CDMA_ALPHA_INFO_BUFFER_LENGTH);
2738 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002739 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002740 string8 = (char*) malloc((infoRec->rec.display.alpha_len + 1)
2741 * sizeof(char) );
2742 for (int i = 0 ; i < infoRec->rec.display.alpha_len ; i++) {
2743 string8[i] = infoRec->rec.display.alpha_buf[i];
2744 }
Wink Saville43808972011-01-13 17:39:51 -08002745 string8[(int)infoRec->rec.display.alpha_len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002746 writeStringToParcel(p, (const char*)string8);
2747 free(string8);
2748 string8 = NULL;
Wink Saville3d54e742009-05-18 18:00:44 -07002749 break;
2750 case RIL_CDMA_CALLED_PARTY_NUMBER_INFO_REC:
Wink Saville3d54e742009-05-18 18:00:44 -07002751 case RIL_CDMA_CALLING_PARTY_NUMBER_INFO_REC:
Wink Saville3d54e742009-05-18 18:00:44 -07002752 case RIL_CDMA_CONNECTED_NUMBER_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002753 if (infoRec->rec.number.len > CDMA_NUMBER_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002754 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002755 expected not more than %d\n",
2756 (int)infoRec->rec.number.len,
2757 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2758 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002759 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002760 string8 = (char*) malloc((infoRec->rec.number.len + 1)
2761 * sizeof(char) );
2762 for (int i = 0 ; i < infoRec->rec.number.len; i++) {
2763 string8[i] = infoRec->rec.number.buf[i];
2764 }
Wink Saville43808972011-01-13 17:39:51 -08002765 string8[(int)infoRec->rec.number.len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002766 writeStringToParcel(p, (const char*)string8);
2767 free(string8);
2768 string8 = NULL;
2769 p.writeInt32(infoRec->rec.number.number_type);
2770 p.writeInt32(infoRec->rec.number.number_plan);
2771 p.writeInt32(infoRec->rec.number.pi);
2772 p.writeInt32(infoRec->rec.number.si);
Wink Saville3d54e742009-05-18 18:00:44 -07002773 break;
2774 case RIL_CDMA_SIGNAL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002775 p.writeInt32(infoRec->rec.signal.isPresent);
2776 p.writeInt32(infoRec->rec.signal.signalType);
2777 p.writeInt32(infoRec->rec.signal.alertPitch);
2778 p.writeInt32(infoRec->rec.signal.signal);
2779
2780 appendPrintBuf("%sisPresent=%X, signalType=%X, \
2781 alertPitch=%X, signal=%X, ",
2782 printBuf, (int)infoRec->rec.signal.isPresent,
2783 (int)infoRec->rec.signal.signalType,
2784 (int)infoRec->rec.signal.alertPitch,
2785 (int)infoRec->rec.signal.signal);
2786 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002787 break;
2788 case RIL_CDMA_REDIRECTING_NUMBER_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002789 if (infoRec->rec.redir.redirectingNumber.len >
2790 CDMA_NUMBER_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002791 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002792 expected not more than %d\n",
2793 (int)infoRec->rec.redir.redirectingNumber.len,
2794 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2795 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002796 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002797 string8 = (char*) malloc((infoRec->rec.redir.redirectingNumber
2798 .len + 1) * sizeof(char) );
2799 for (int i = 0;
2800 i < infoRec->rec.redir.redirectingNumber.len;
2801 i++) {
2802 string8[i] = infoRec->rec.redir.redirectingNumber.buf[i];
2803 }
Wink Saville43808972011-01-13 17:39:51 -08002804 string8[(int)infoRec->rec.redir.redirectingNumber.len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002805 writeStringToParcel(p, (const char*)string8);
2806 free(string8);
2807 string8 = NULL;
2808 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_type);
2809 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_plan);
2810 p.writeInt32(infoRec->rec.redir.redirectingNumber.pi);
2811 p.writeInt32(infoRec->rec.redir.redirectingNumber.si);
2812 p.writeInt32(infoRec->rec.redir.redirectingReason);
Wink Saville3d54e742009-05-18 18:00:44 -07002813 break;
2814 case RIL_CDMA_LINE_CONTROL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002815 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPolarityIncluded);
2816 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlToggle);
2817 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlReverse);
2818 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2819
2820 appendPrintBuf("%slineCtrlPolarityIncluded=%d, \
2821 lineCtrlToggle=%d, lineCtrlReverse=%d, \
2822 lineCtrlPowerDenial=%d, ", printBuf,
2823 (int)infoRec->rec.lineCtrl.lineCtrlPolarityIncluded,
2824 (int)infoRec->rec.lineCtrl.lineCtrlToggle,
2825 (int)infoRec->rec.lineCtrl.lineCtrlReverse,
2826 (int)infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2827 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002828 break;
2829 case RIL_CDMA_T53_CLIR_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002830 p.writeInt32((int)(infoRec->rec.clir.cause));
Wink Saville3d54e742009-05-18 18:00:44 -07002831
Wink Savillea592eeb2009-05-22 13:26:36 -07002832 appendPrintBuf("%scause%d", printBuf, infoRec->rec.clir.cause);
2833 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002834 break;
2835 case RIL_CDMA_T53_AUDIO_CONTROL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002836 p.writeInt32(infoRec->rec.audioCtrl.upLink);
2837 p.writeInt32(infoRec->rec.audioCtrl.downLink);
2838
2839 appendPrintBuf("%supLink=%d, downLink=%d, ", printBuf,
2840 infoRec->rec.audioCtrl.upLink,
2841 infoRec->rec.audioCtrl.downLink);
2842 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002843 break;
Wink Savillea592eeb2009-05-22 13:26:36 -07002844 case RIL_CDMA_T53_RELEASE_INFO_REC:
2845 // TODO(Moto): See David Krause, he has the answer:)
Wink Saville8eb2a122012-11-19 16:05:13 -08002846 RLOGE("RIL_CDMA_T53_RELEASE_INFO_REC: return INVALID_RESPONSE");
Wink Savillea592eeb2009-05-22 13:26:36 -07002847 return RIL_ERRNO_INVALID_RESPONSE;
2848 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08002849 RLOGE("Incorrect name value");
Wink Savillea592eeb2009-05-22 13:26:36 -07002850 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002851 }
2852 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002853 closeResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002854
Wink Savillea592eeb2009-05-22 13:26:36 -07002855 return 0;
Wink Saville3d54e742009-05-18 18:00:44 -07002856}
2857
Wink Savillea592eeb2009-05-22 13:26:36 -07002858static int responseRilSignalStrength(Parcel &p,
2859 void *response, size_t responselen) {
2860 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002861 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002862 return RIL_ERRNO_INVALID_RESPONSE;
2863 }
2864
Wink Savillec0114b32011-02-18 10:14:07 -08002865 if (responselen >= sizeof (RIL_SignalStrength_v5)) {
Etan Cohend3652192014-06-20 08:28:44 -07002866 RIL_SignalStrength_v10 *p_cur = ((RIL_SignalStrength_v10 *) response);
Wink Saville3d54e742009-05-18 18:00:44 -07002867
Wink Saville3d54e742009-05-18 18:00:44 -07002868 p.writeInt32(p_cur->GW_SignalStrength.signalStrength);
2869 p.writeInt32(p_cur->GW_SignalStrength.bitErrorRate);
2870 p.writeInt32(p_cur->CDMA_SignalStrength.dbm);
2871 p.writeInt32(p_cur->CDMA_SignalStrength.ecio);
2872 p.writeInt32(p_cur->EVDO_SignalStrength.dbm);
2873 p.writeInt32(p_cur->EVDO_SignalStrength.ecio);
2874 p.writeInt32(p_cur->EVDO_SignalStrength.signalNoiseRatio);
Wink Savillec0114b32011-02-18 10:14:07 -08002875 if (responselen >= sizeof (RIL_SignalStrength_v6)) {
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002876 /*
Wink Saville18e4ab12013-04-07 17:31:04 -07002877 * Fixup LTE for backwards compatibility
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002878 */
Wink Saville18e4ab12013-04-07 17:31:04 -07002879 if (s_callbacks.version <= 6) {
2880 // signalStrength: -1 -> 99
2881 if (p_cur->LTE_SignalStrength.signalStrength == -1) {
2882 p_cur->LTE_SignalStrength.signalStrength = 99;
2883 }
2884 // rsrp: -1 -> INT_MAX all other negative value to positive.
2885 // So remap here
2886 if (p_cur->LTE_SignalStrength.rsrp == -1) {
2887 p_cur->LTE_SignalStrength.rsrp = INT_MAX;
2888 } else if (p_cur->LTE_SignalStrength.rsrp < -1) {
2889 p_cur->LTE_SignalStrength.rsrp = -p_cur->LTE_SignalStrength.rsrp;
2890 }
2891 // rsrq: -1 -> INT_MAX
2892 if (p_cur->LTE_SignalStrength.rsrq == -1) {
2893 p_cur->LTE_SignalStrength.rsrq = INT_MAX;
2894 }
2895 // Not remapping rssnr is already using INT_MAX
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002896
Wink Saville18e4ab12013-04-07 17:31:04 -07002897 // cqi: -1 -> INT_MAX
2898 if (p_cur->LTE_SignalStrength.cqi == -1) {
2899 p_cur->LTE_SignalStrength.cqi = INT_MAX;
2900 }
2901 }
2902 p.writeInt32(p_cur->LTE_SignalStrength.signalStrength);
Wink Savillec0114b32011-02-18 10:14:07 -08002903 p.writeInt32(p_cur->LTE_SignalStrength.rsrp);
2904 p.writeInt32(p_cur->LTE_SignalStrength.rsrq);
2905 p.writeInt32(p_cur->LTE_SignalStrength.rssnr);
2906 p.writeInt32(p_cur->LTE_SignalStrength.cqi);
Etan Cohend3652192014-06-20 08:28:44 -07002907 if (responselen >= sizeof (RIL_SignalStrength_v10)) {
2908 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
2909 } else {
2910 p.writeInt32(INT_MAX);
2911 }
Wink Savillec0114b32011-02-18 10:14:07 -08002912 } else {
Wink Saville18e4ab12013-04-07 17:31:04 -07002913 p.writeInt32(99);
2914 p.writeInt32(INT_MAX);
2915 p.writeInt32(INT_MAX);
2916 p.writeInt32(INT_MAX);
2917 p.writeInt32(INT_MAX);
Etan Cohend3652192014-06-20 08:28:44 -07002918 p.writeInt32(INT_MAX);
Wink Savillec0114b32011-02-18 10:14:07 -08002919 }
johnwangfdf825f2009-05-22 15:50:34 -07002920
2921 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07002922 appendPrintBuf("%s[signalStrength=%d,bitErrorRate=%d,\
Wink Savillec0114b32011-02-18 10:14:07 -08002923 CDMA_SS.dbm=%d,CDMA_SSecio=%d,\
2924 EVDO_SS.dbm=%d,EVDO_SS.ecio=%d,\
2925 EVDO_SS.signalNoiseRatio=%d,\
2926 LTE_SS.signalStrength=%d,LTE_SS.rsrp=%d,LTE_SS.rsrq=%d,\
Etan Cohend3652192014-06-20 08:28:44 -07002927 LTE_SS.rssnr=%d,LTE_SS.cqi=%d,TDSCDMA_SS.rscp=%d]",
Wink Savillea592eeb2009-05-22 13:26:36 -07002928 printBuf,
2929 p_cur->GW_SignalStrength.signalStrength,
2930 p_cur->GW_SignalStrength.bitErrorRate,
2931 p_cur->CDMA_SignalStrength.dbm,
2932 p_cur->CDMA_SignalStrength.ecio,
2933 p_cur->EVDO_SignalStrength.dbm,
2934 p_cur->EVDO_SignalStrength.ecio,
Wink Savillec0114b32011-02-18 10:14:07 -08002935 p_cur->EVDO_SignalStrength.signalNoiseRatio,
2936 p_cur->LTE_SignalStrength.signalStrength,
2937 p_cur->LTE_SignalStrength.rsrp,
2938 p_cur->LTE_SignalStrength.rsrq,
2939 p_cur->LTE_SignalStrength.rssnr,
Etan Cohend3652192014-06-20 08:28:44 -07002940 p_cur->LTE_SignalStrength.cqi,
2941 p_cur->TD_SCDMA_SignalStrength.rscp);
Wink Savillea592eeb2009-05-22 13:26:36 -07002942 closeResponse;
2943
Wink Saville3d54e742009-05-18 18:00:44 -07002944 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08002945 RLOGE("invalid response length");
Wink Saville3d54e742009-05-18 18:00:44 -07002946 return RIL_ERRNO_INVALID_RESPONSE;
2947 }
2948
Wink Saville3d54e742009-05-18 18:00:44 -07002949 return 0;
2950}
2951
2952static int responseCallRing(Parcel &p, void *response, size_t responselen) {
2953 if ((response == NULL) || (responselen == 0)) {
2954 return responseVoid(p, response, responselen);
2955 } else {
2956 return responseCdmaSignalInfoRecord(p, response, responselen);
2957 }
2958}
2959
2960static int responseCdmaSignalInfoRecord(Parcel &p, void *response, size_t responselen) {
2961 if (response == NULL || responselen == 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002962 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002963 return RIL_ERRNO_INVALID_RESPONSE;
2964 }
2965
2966 if (responselen != sizeof (RIL_CDMA_SignalInfoRecord)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002967 RLOGE("invalid response length %d expected sizeof (RIL_CDMA_SignalInfoRecord) of %d\n",
Wink Saville3d54e742009-05-18 18:00:44 -07002968 (int)responselen, (int)sizeof (RIL_CDMA_SignalInfoRecord));
2969 return RIL_ERRNO_INVALID_RESPONSE;
2970 }
2971
2972 startResponse;
2973
2974 RIL_CDMA_SignalInfoRecord *p_cur = ((RIL_CDMA_SignalInfoRecord *) response);
2975 marshallSignalInfoRecord(p, *p_cur);
2976
2977 appendPrintBuf("%s[isPresent=%d,signalType=%d,alertPitch=%d\
2978 signal=%d]",
2979 printBuf,
2980 p_cur->isPresent,
2981 p_cur->signalType,
2982 p_cur->alertPitch,
2983 p_cur->signal);
2984
2985 closeResponse;
2986 return 0;
2987}
2988
Wink Savillea592eeb2009-05-22 13:26:36 -07002989static int responseCdmaCallWaiting(Parcel &p, void *response,
2990 size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07002991 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002992 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002993 return RIL_ERRNO_INVALID_RESPONSE;
2994 }
2995
Wink Savillec0114b32011-02-18 10:14:07 -08002996 if (responselen < sizeof(RIL_CDMA_CallWaiting_v6)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002997 RLOGW("Upgrade to ril version %d\n", RIL_VERSION);
Wink Savillec0114b32011-02-18 10:14:07 -08002998 }
2999
3000 RIL_CDMA_CallWaiting_v6 *p_cur = ((RIL_CDMA_CallWaiting_v6 *) response);
3001
3002 writeStringToParcel(p, p_cur->number);
3003 p.writeInt32(p_cur->numberPresentation);
3004 writeStringToParcel(p, p_cur->name);
3005 marshallSignalInfoRecord(p, p_cur->signalInfoRecord);
3006
3007 if (responselen >= sizeof(RIL_CDMA_CallWaiting_v6)) {
3008 p.writeInt32(p_cur->number_type);
3009 p.writeInt32(p_cur->number_plan);
3010 } else {
3011 p.writeInt32(0);
3012 p.writeInt32(0);
Wink Saville3d54e742009-05-18 18:00:44 -07003013 }
3014
3015 startResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07003016 appendPrintBuf("%snumber=%s,numberPresentation=%d, name=%s,\
3017 signalInfoRecord[isPresent=%d,signalType=%d,alertPitch=%d\
Wink Savillec0114b32011-02-18 10:14:07 -08003018 signal=%d,number_type=%d,number_plan=%d]",
Wink Saville3d54e742009-05-18 18:00:44 -07003019 printBuf,
3020 p_cur->number,
3021 p_cur->numberPresentation,
3022 p_cur->name,
3023 p_cur->signalInfoRecord.isPresent,
3024 p_cur->signalInfoRecord.signalType,
3025 p_cur->signalInfoRecord.alertPitch,
Wink Savillec0114b32011-02-18 10:14:07 -08003026 p_cur->signalInfoRecord.signal,
3027 p_cur->number_type,
3028 p_cur->number_plan);
Wink Saville3d54e742009-05-18 18:00:44 -07003029 closeResponse;
3030
3031 return 0;
3032}
3033
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003034static int responseSimRefresh(Parcel &p, void *response, size_t responselen) {
3035 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003036 RLOGE("responseSimRefresh: invalid response: NULL");
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003037 return RIL_ERRNO_INVALID_RESPONSE;
3038 }
3039
3040 startResponse;
3041 if (s_callbacks.version == 7) {
3042 RIL_SimRefreshResponse_v7 *p_cur = ((RIL_SimRefreshResponse_v7 *) response);
3043 p.writeInt32(p_cur->result);
3044 p.writeInt32(p_cur->ef_id);
3045 writeStringToParcel(p, p_cur->aid);
3046
3047 appendPrintBuf("%sresult=%d, ef_id=%d, aid=%s",
3048 printBuf,
3049 p_cur->result,
3050 p_cur->ef_id,
3051 p_cur->aid);
3052 } else {
3053 int *p_cur = ((int *) response);
3054 p.writeInt32(p_cur[0]);
3055 p.writeInt32(p_cur[1]);
3056 writeStringToParcel(p, NULL);
3057
3058 appendPrintBuf("%sresult=%d, ef_id=%d",
3059 printBuf,
3060 p_cur[0],
3061 p_cur[1]);
3062 }
3063 closeResponse;
3064
3065 return 0;
3066}
3067
Wink Saville8a9e0212013-04-09 12:11:38 -07003068static int responseCellInfoList(Parcel &p, void *response, size_t responselen)
3069{
3070 if (response == NULL && responselen != 0) {
3071 RLOGE("invalid response: NULL");
3072 return RIL_ERRNO_INVALID_RESPONSE;
3073 }
3074
3075 if (responselen % sizeof(RIL_CellInfo) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07003076 RLOGE("responseCellInfoList: invalid response length %d expected multiple of %d",
Wink Saville8a9e0212013-04-09 12:11:38 -07003077 (int)responselen, (int)sizeof(RIL_CellInfo));
3078 return RIL_ERRNO_INVALID_RESPONSE;
3079 }
3080
3081 int num = responselen / sizeof(RIL_CellInfo);
3082 p.writeInt32(num);
3083
3084 RIL_CellInfo *p_cur = (RIL_CellInfo *) response;
3085 startResponse;
3086 int i;
3087 for (i = 0; i < num; i++) {
3088 appendPrintBuf("%s[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", printBuf, i,
3089 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
3090 p.writeInt32((int)p_cur->cellInfoType);
3091 p.writeInt32(p_cur->registered);
3092 p.writeInt32(p_cur->timeStampType);
3093 p.writeInt64(p_cur->timeStamp);
3094 switch(p_cur->cellInfoType) {
3095 case RIL_CELL_INFO_TYPE_GSM: {
Wink Savillec57b3eb2013-04-17 12:51:41 -07003096 appendPrintBuf("%s GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,", printBuf,
Wink Saville8a9e0212013-04-09 12:11:38 -07003097 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
3098 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
3099 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
Wink Savillec57b3eb2013-04-17 12:51:41 -07003100 p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3101 appendPrintBuf("%s gsmSS: ss=%d,ber=%d],", printBuf,
Wink Saville8a9e0212013-04-09 12:11:38 -07003102 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
3103 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3104
3105 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
3106 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
3107 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
3108 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
Wink Saville8a9e0212013-04-09 12:11:38 -07003109 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
3110 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3111 break;
3112 }
Wink Savillec57b3eb2013-04-17 12:51:41 -07003113 case RIL_CELL_INFO_TYPE_WCDMA: {
3114 appendPrintBuf("%s WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,", printBuf,
3115 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
3116 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
3117 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
3118 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
3119 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3120 appendPrintBuf("%s wcdmaSS: ss=%d,ber=%d],", printBuf,
3121 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
3122 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3123
3124 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
3125 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
3126 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
3127 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
3128 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3129 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
3130 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3131 break;
3132 }
Wink Saville8a9e0212013-04-09 12:11:38 -07003133 case RIL_CELL_INFO_TYPE_CDMA: {
3134 appendPrintBuf("%s CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d", printBuf,
3135 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
3136 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
3137 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
3138 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
3139 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3140
3141 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
3142 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
3143 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
3144 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
3145 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3146
3147 appendPrintBuf("%s cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d", printBuf,
3148 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
3149 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
3150 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
3151 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
3152 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3153
3154 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
3155 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
3156 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
3157 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
3158 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3159 break;
3160 }
3161 case RIL_CELL_INFO_TYPE_LTE: {
3162 appendPrintBuf("%s LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d", printBuf,
3163 p_cur->CellInfo.lte.cellIdentityLte.mcc,
3164 p_cur->CellInfo.lte.cellIdentityLte.mnc,
3165 p_cur->CellInfo.lte.cellIdentityLte.ci,
3166 p_cur->CellInfo.lte.cellIdentityLte.pci,
3167 p_cur->CellInfo.lte.cellIdentityLte.tac);
3168
3169 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
3170 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
3171 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
3172 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
3173 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
3174
3175 appendPrintBuf("%s lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d", printBuf,
3176 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
3177 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
3178 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
3179 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
3180 p_cur->CellInfo.lte.signalStrengthLte.cqi,
3181 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3182 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
3183 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
3184 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
3185 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
3186 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
3187 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3188 break;
3189 }
Etan Cohend3652192014-06-20 08:28:44 -07003190 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
3191 appendPrintBuf("%s TDSCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,cpid=%d,", printBuf,
3192 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc,
3193 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc,
3194 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac,
3195 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid,
3196 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3197 appendPrintBuf("%s tdscdmaSS: rscp=%d],", printBuf,
3198 p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3199
3200 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
3201 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
3202 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
3203 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
3204 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3205 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3206 break;
3207 }
Wink Saville8a9e0212013-04-09 12:11:38 -07003208 }
3209 p_cur += 1;
3210 }
3211 removeLastChar;
3212 closeResponse;
3213
3214 return 0;
3215}
3216
Etan Cohend3652192014-06-20 08:28:44 -07003217static int responseHardwareConfig(Parcel &p, void *response, size_t responselen)
3218{
3219 if (response == NULL && responselen != 0) {
3220 RLOGE("invalid response: NULL");
3221 return RIL_ERRNO_INVALID_RESPONSE;
3222 }
3223
3224 if (responselen % sizeof(RIL_HardwareConfig) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07003225 RLOGE("responseHardwareConfig: invalid response length %d expected multiple of %d",
Etan Cohend3652192014-06-20 08:28:44 -07003226 (int)responselen, (int)sizeof(RIL_HardwareConfig));
3227 return RIL_ERRNO_INVALID_RESPONSE;
3228 }
3229
3230 int num = responselen / sizeof(RIL_HardwareConfig);
3231 int i;
3232 RIL_HardwareConfig *p_cur = (RIL_HardwareConfig *) response;
3233
3234 p.writeInt32(num);
3235
3236 startResponse;
3237 for (i = 0; i < num; i++) {
3238 switch (p_cur[i].type) {
3239 case RIL_HARDWARE_CONFIG_MODEM: {
3240 writeStringToParcel(p, p_cur[i].uuid);
3241 p.writeInt32((int)p_cur[i].state);
3242 p.writeInt32(p_cur[i].cfg.modem.rat);
3243 p.writeInt32(p_cur[i].cfg.modem.maxVoice);
3244 p.writeInt32(p_cur[i].cfg.modem.maxData);
3245 p.writeInt32(p_cur[i].cfg.modem.maxStandby);
3246
3247 appendPrintBuf("%s modem: uuid=%s,state=%d,rat=%08x,maxV=%d,maxD=%d,maxS=%d", printBuf,
3248 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.modem.rat,
3249 p_cur[i].cfg.modem.maxVoice, p_cur[i].cfg.modem.maxData, p_cur[i].cfg.modem.maxStandby);
3250 break;
3251 }
3252 case RIL_HARDWARE_CONFIG_SIM: {
3253 writeStringToParcel(p, p_cur[i].uuid);
3254 p.writeInt32((int)p_cur[i].state);
3255 writeStringToParcel(p, p_cur[i].cfg.sim.modemUuid);
3256
3257 appendPrintBuf("%s sim: uuid=%s,state=%d,modem-uuid=%s", printBuf,
3258 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.sim.modemUuid);
3259 break;
3260 }
3261 }
3262 }
3263 removeLastChar;
3264 closeResponse;
3265 return 0;
3266}
3267
Wink Saville8b4e4f72014-10-17 15:01:45 -07003268static int responseRadioCapability(Parcel &p, void *response, size_t responselen) {
3269 if (response == NULL) {
3270 RLOGE("invalid response: NULL");
3271 return RIL_ERRNO_INVALID_RESPONSE;
3272 }
3273
3274 if (responselen != sizeof (RIL_RadioCapability) ) {
3275 RLOGE("invalid response length was %d expected %d",
3276 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3277 return RIL_ERRNO_INVALID_RESPONSE;
3278 }
3279
3280 RIL_RadioCapability *p_cur = (RIL_RadioCapability *) response;
3281 p.writeInt32(p_cur->version);
3282 p.writeInt32(p_cur->session);
3283 p.writeInt32(p_cur->phase);
3284 p.writeInt32(p_cur->rat);
3285 writeStringToParcel(p, p_cur->logicalModemUuid);
3286 p.writeInt32(p_cur->status);
3287
3288 startResponse;
3289 appendPrintBuf("%s[version=%d,session=%d,phase=%d,\
Legler Wu8caf06f2014-10-29 14:02:14 +08003290 rat=%s,logicalModemUuid=%s,status=%d]",
Wink Saville8b4e4f72014-10-17 15:01:45 -07003291 printBuf,
3292 p_cur->version,
3293 p_cur->session,
3294 p_cur->phase,
3295 p_cur->rat,
Legler Wu8caf06f2014-10-29 14:02:14 +08003296 p_cur->logicalModemUuid,
Wink Saville8b4e4f72014-10-17 15:01:45 -07003297 p_cur->status);
3298 closeResponse;
3299 return 0;
3300}
3301
Amit Mahajan54563d32014-11-22 00:54:49 +00003302static int responseSSData(Parcel &p, void *response, size_t responselen) {
3303 RLOGD("In responseSSData");
3304 int num;
3305
3306 if (response == NULL && responselen != 0) {
3307 RLOGE("invalid response length was %d expected %d",
3308 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3309 return RIL_ERRNO_INVALID_RESPONSE;
3310 }
3311
3312 if (responselen != sizeof(RIL_StkCcUnsolSsResponse)) {
3313 RLOGE("invalid response length %d, expected %d",
3314 (int)responselen, (int)sizeof(RIL_StkCcUnsolSsResponse));
3315 return RIL_ERRNO_INVALID_RESPONSE;
3316 }
3317
3318 startResponse;
3319 RIL_StkCcUnsolSsResponse *p_cur = (RIL_StkCcUnsolSsResponse *) response;
3320 p.writeInt32(p_cur->serviceType);
3321 p.writeInt32(p_cur->requestType);
3322 p.writeInt32(p_cur->teleserviceType);
3323 p.writeInt32(p_cur->serviceClass);
3324 p.writeInt32(p_cur->result);
3325
3326 if (isServiceTypeCfQuery(p_cur->serviceType, p_cur->requestType)) {
3327 RLOGD("responseSSData CF type, num of Cf elements %d", p_cur->cfData.numValidIndexes);
3328 if (p_cur->cfData.numValidIndexes > NUM_SERVICE_CLASSES) {
3329 RLOGE("numValidIndexes is greater than max value %d, "
3330 "truncating it to max value", NUM_SERVICE_CLASSES);
3331 p_cur->cfData.numValidIndexes = NUM_SERVICE_CLASSES;
3332 }
3333 /* number of call info's */
3334 p.writeInt32(p_cur->cfData.numValidIndexes);
3335
3336 for (int i = 0; i < p_cur->cfData.numValidIndexes; i++) {
3337 RIL_CallForwardInfo cf = p_cur->cfData.cfInfo[i];
3338
3339 p.writeInt32(cf.status);
3340 p.writeInt32(cf.reason);
3341 p.writeInt32(cf.serviceClass);
3342 p.writeInt32(cf.toa);
3343 writeStringToParcel(p, cf.number);
3344 p.writeInt32(cf.timeSeconds);
3345 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
3346 (cf.status==1)?"enable":"disable", cf.reason, cf.serviceClass, cf.toa,
3347 (char*)cf.number, cf.timeSeconds);
3348 RLOGD("Data: %d,reason=%d,cls=%d,toa=%d,num=%s,tout=%d],", cf.status,
3349 cf.reason, cf.serviceClass, cf.toa, (char*)cf.number, cf.timeSeconds);
3350 }
3351 } else {
3352 p.writeInt32 (SS_INFO_MAX);
3353
3354 /* each int*/
3355 for (int i = 0; i < SS_INFO_MAX; i++) {
3356 appendPrintBuf("%s%d,", printBuf, p_cur->ssInfo[i]);
3357 RLOGD("Data: %d",p_cur->ssInfo[i]);
3358 p.writeInt32(p_cur->ssInfo[i]);
3359 }
3360 }
3361 removeLastChar;
3362 closeResponse;
3363
3364 return 0;
3365}
3366
3367static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType) {
3368 if ((reqType == SS_INTERROGATION) &&
3369 (serType == SS_CFU ||
3370 serType == SS_CF_BUSY ||
3371 serType == SS_CF_NO_REPLY ||
3372 serType == SS_CF_NOT_REACHABLE ||
3373 serType == SS_CF_ALL ||
3374 serType == SS_CF_ALL_CONDITIONAL)) {
3375 return true;
3376 }
3377 return false;
3378}
3379
Wink Saville3d54e742009-05-18 18:00:44 -07003380static void triggerEvLoop() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003381 int ret;
3382 if (!pthread_equal(pthread_self(), s_tid_dispatch)) {
3383 /* trigger event loop to wakeup. No reason to do this,
3384 * if we're in the event loop thread */
3385 do {
3386 ret = write (s_fdWakeupWrite, " ", 1);
3387 } while (ret < 0 && errno == EINTR);
3388 }
3389}
3390
Wink Saville3d54e742009-05-18 18:00:44 -07003391static void rilEventAddWakeup(struct ril_event *ev) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003392 ril_event_add(ev);
3393 triggerEvLoop();
3394}
3395
Wink Savillefd729372011-02-22 16:19:39 -08003396static void sendSimStatusAppInfo(Parcel &p, int num_apps, RIL_AppStatus appStatus[]) {
3397 p.writeInt32(num_apps);
3398 startResponse;
3399 for (int i = 0; i < num_apps; i++) {
3400 p.writeInt32(appStatus[i].app_type);
3401 p.writeInt32(appStatus[i].app_state);
3402 p.writeInt32(appStatus[i].perso_substate);
3403 writeStringToParcel(p, (const char*)(appStatus[i].aid_ptr));
3404 writeStringToParcel(p, (const char*)
3405 (appStatus[i].app_label_ptr));
3406 p.writeInt32(appStatus[i].pin1_replaced);
3407 p.writeInt32(appStatus[i].pin1);
3408 p.writeInt32(appStatus[i].pin2);
3409 appendPrintBuf("%s[app_type=%d,app_state=%d,perso_substate=%d,\
3410 aid_ptr=%s,app_label_ptr=%s,pin1_replaced=%d,pin1=%d,pin2=%d],",
3411 printBuf,
3412 appStatus[i].app_type,
3413 appStatus[i].app_state,
3414 appStatus[i].perso_substate,
3415 appStatus[i].aid_ptr,
3416 appStatus[i].app_label_ptr,
3417 appStatus[i].pin1_replaced,
3418 appStatus[i].pin1,
3419 appStatus[i].pin2);
3420 }
3421 closeResponse;
3422}
3423
Wink Savillef4c4d362009-04-02 01:37:03 -07003424static int responseSimStatus(Parcel &p, void *response, size_t responselen) {
3425 int i;
3426
3427 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003428 RLOGE("invalid response: NULL");
Wink Savillef4c4d362009-04-02 01:37:03 -07003429 return RIL_ERRNO_INVALID_RESPONSE;
3430 }
3431
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003432 if (responselen == sizeof (RIL_CardStatus_v6)) {
Wink Savillefd729372011-02-22 16:19:39 -08003433 RIL_CardStatus_v6 *p_cur = ((RIL_CardStatus_v6 *) response);
Wink Savillef4c4d362009-04-02 01:37:03 -07003434
Wink Savillefd729372011-02-22 16:19:39 -08003435 p.writeInt32(p_cur->card_state);
3436 p.writeInt32(p_cur->universal_pin_state);
3437 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3438 p.writeInt32(p_cur->cdma_subscription_app_index);
3439 p.writeInt32(p_cur->ims_subscription_app_index);
3440
3441 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003442 } else if (responselen == sizeof (RIL_CardStatus_v5)) {
Wink Savillefd729372011-02-22 16:19:39 -08003443 RIL_CardStatus_v5 *p_cur = ((RIL_CardStatus_v5 *) response);
3444
3445 p.writeInt32(p_cur->card_state);
3446 p.writeInt32(p_cur->universal_pin_state);
3447 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3448 p.writeInt32(p_cur->cdma_subscription_app_index);
3449 p.writeInt32(-1);
3450
3451 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003452 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003453 RLOGE("responseSimStatus: A RilCardStatus_v6 or _v5 expected\n");
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003454 return RIL_ERRNO_INVALID_RESPONSE;
Wink Savillef4c4d362009-04-02 01:37:03 -07003455 }
Wink Savillef4c4d362009-04-02 01:37:03 -07003456
3457 return 0;
Wink Saville3d54e742009-05-18 18:00:44 -07003458}
Wink Savillef4c4d362009-04-02 01:37:03 -07003459
Wink Savillea592eeb2009-05-22 13:26:36 -07003460static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3461 int num = responselen / sizeof(RIL_GSM_BroadcastSmsConfigInfo *);
Wink Savillef4c4d362009-04-02 01:37:03 -07003462 p.writeInt32(num);
3463
Wink Savillef4c4d362009-04-02 01:37:03 -07003464 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07003465 RIL_GSM_BroadcastSmsConfigInfo **p_cur =
3466 (RIL_GSM_BroadcastSmsConfigInfo **) response;
3467 for (int i = 0; i < num; i++) {
3468 p.writeInt32(p_cur[i]->fromServiceId);
3469 p.writeInt32(p_cur[i]->toServiceId);
3470 p.writeInt32(p_cur[i]->fromCodeScheme);
3471 p.writeInt32(p_cur[i]->toCodeScheme);
3472 p.writeInt32(p_cur[i]->selected);
3473
3474 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId=%d, \
3475 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]",
3476 printBuf, i, p_cur[i]->fromServiceId, p_cur[i]->toServiceId,
3477 p_cur[i]->fromCodeScheme, p_cur[i]->toCodeScheme,
3478 p_cur[i]->selected);
3479 }
Wink Savillef4c4d362009-04-02 01:37:03 -07003480 closeResponse;
3481
3482 return 0;
3483}
3484
Wink Savillea592eeb2009-05-22 13:26:36 -07003485static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3486 RIL_CDMA_BroadcastSmsConfigInfo **p_cur =
3487 (RIL_CDMA_BroadcastSmsConfigInfo **) response;
Wink Savillef4c4d362009-04-02 01:37:03 -07003488
Wink Savillea592eeb2009-05-22 13:26:36 -07003489 int num = responselen / sizeof (RIL_CDMA_BroadcastSmsConfigInfo *);
3490 p.writeInt32(num);
Wink Savillef4c4d362009-04-02 01:37:03 -07003491
3492 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07003493 for (int i = 0 ; i < num ; i++ ) {
3494 p.writeInt32(p_cur[i]->service_category);
3495 p.writeInt32(p_cur[i]->language);
3496 p.writeInt32(p_cur[i]->selected);
Wink Savillef4c4d362009-04-02 01:37:03 -07003497
Wink Savillea592eeb2009-05-22 13:26:36 -07003498 appendPrintBuf("%s [%d: srvice_category=%d, language =%d, \
3499 selected =%d], ",
3500 printBuf, i, p_cur[i]->service_category, p_cur[i]->language,
3501 p_cur[i]->selected);
Wink Savillef5903df2009-04-24 11:54:14 -07003502 }
Wink Savillea592eeb2009-05-22 13:26:36 -07003503 closeResponse;
Wink Savillef5903df2009-04-24 11:54:14 -07003504
Wink Savillef4c4d362009-04-02 01:37:03 -07003505 return 0;
3506}
3507
3508static int responseCdmaSms(Parcel &p, void *response, size_t responselen) {
3509 int num;
3510 int digitCount;
3511 int digitLimit;
3512 uint8_t uct;
3513 void* dest;
3514
Wink Saville8eb2a122012-11-19 16:05:13 -08003515 RLOGD("Inside responseCdmaSms");
Wink Savillef5903df2009-04-24 11:54:14 -07003516
Wink Savillef4c4d362009-04-02 01:37:03 -07003517 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003518 RLOGE("invalid response: NULL");
Wink Savillef4c4d362009-04-02 01:37:03 -07003519 return RIL_ERRNO_INVALID_RESPONSE;
3520 }
3521
Wink Savillef5903df2009-04-24 11:54:14 -07003522 if (responselen != sizeof(RIL_CDMA_SMS_Message)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003523 RLOGE("invalid response length was %d expected %d",
Wink Savillef5903df2009-04-24 11:54:14 -07003524 (int)responselen, (int)sizeof(RIL_CDMA_SMS_Message));
Wink Savillef4c4d362009-04-02 01:37:03 -07003525 return RIL_ERRNO_INVALID_RESPONSE;
3526 }
3527
3528 RIL_CDMA_SMS_Message *p_cur = (RIL_CDMA_SMS_Message *) response;
3529 p.writeInt32(p_cur->uTeleserviceID);
3530 p.write(&(p_cur->bIsServicePresent),sizeof(uct));
3531 p.writeInt32(p_cur->uServicecategory);
3532 p.writeInt32(p_cur->sAddress.digit_mode);
3533 p.writeInt32(p_cur->sAddress.number_mode);
3534 p.writeInt32(p_cur->sAddress.number_type);
3535 p.writeInt32(p_cur->sAddress.number_plan);
3536 p.write(&(p_cur->sAddress.number_of_digits), sizeof(uct));
3537 digitLimit= MIN((p_cur->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
3538 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3539 p.write(&(p_cur->sAddress.digits[digitCount]),sizeof(uct));
3540 }
3541
3542 p.writeInt32(p_cur->sSubAddress.subaddressType);
3543 p.write(&(p_cur->sSubAddress.odd),sizeof(uct));
3544 p.write(&(p_cur->sSubAddress.number_of_digits),sizeof(uct));
3545 digitLimit= MIN((p_cur->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
3546 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3547 p.write(&(p_cur->sSubAddress.digits[digitCount]),sizeof(uct));
3548 }
3549
3550 digitLimit= MIN((p_cur->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
3551 p.writeInt32(p_cur->uBearerDataLen);
3552 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3553 p.write(&(p_cur->aBearerData[digitCount]), sizeof(uct));
3554 }
3555
3556 startResponse;
3557 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
Wink Saville1b5fd232009-04-22 14:50:00 -07003558 sAddress.digit_mode=%d, sAddress.number_mode=%d, sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07003559 printBuf, p_cur->uTeleserviceID,p_cur->bIsServicePresent,p_cur->uServicecategory,
3560 p_cur->sAddress.digit_mode, p_cur->sAddress.number_mode,p_cur->sAddress.number_type);
3561 closeResponse;
3562
3563 return 0;
3564}
3565
Wink Savillec29360a2014-07-13 05:17:28 -07003566static int responseDcRtInfo(Parcel &p, void *response, size_t responselen)
3567{
3568 int num = responselen / sizeof(RIL_DcRtInfo);
3569 if ((responselen % sizeof(RIL_DcRtInfo) != 0) || (num != 1)) {
Amit Mahajan52500162014-07-29 17:36:48 -07003570 RLOGE("responseDcRtInfo: invalid response length %d expected multiple of %d",
Wink Savillec29360a2014-07-13 05:17:28 -07003571 (int)responselen, (int)sizeof(RIL_DcRtInfo));
3572 return RIL_ERRNO_INVALID_RESPONSE;
3573 }
3574
3575 startResponse;
3576 RIL_DcRtInfo *pDcRtInfo = (RIL_DcRtInfo *)response;
3577 p.writeInt64(pDcRtInfo->time);
3578 p.writeInt32(pDcRtInfo->powerState);
3579 appendPrintBuf("%s[time=%d,powerState=%d]", printBuf,
3580 pDcRtInfo->time,
3581 pDcRtInfo->powerState);
3582 closeResponse;
3583
3584 return 0;
3585}
3586
fengluf7408292015-04-14 14:53:55 -07003587static int responseLceStatus(Parcel &p, void *response, size_t responselen) {
3588 if (response == NULL || responselen != sizeof(RIL_LceStatusInfo)) {
3589 if (response == NULL) {
3590 RLOGE("invalid response: NULL");
3591 }
3592 else {
3593 RLOGE("responseLceStatus: invalid response length %d expecting len: d%",
3594 sizeof(RIL_LceStatusInfo), responselen);
3595 }
3596 return RIL_ERRNO_INVALID_RESPONSE;
3597 }
3598
3599 RIL_LceStatusInfo *p_cur = (RIL_LceStatusInfo *)response;
3600 p.write((void *)p_cur, 1); // p_cur->lce_status takes one byte.
3601 p.writeInt32(p_cur->actual_interval_ms);
3602
3603 startResponse;
3604 appendPrintBuf("LCE Status: %d, actual_interval_ms: %d",
3605 p_cur->lce_status, p_cur->actual_interval_ms);
3606 closeResponse;
3607
3608 return 0;
3609}
3610
3611static int responseLceData(Parcel &p, void *response, size_t responselen) {
3612 if (response == NULL || responselen != sizeof(RIL_LceDataInfo)) {
3613 if (response == NULL) {
3614 RLOGE("invalid response: NULL");
3615 }
3616 else {
3617 RLOGE("responseLceData: invalid response length %d expecting len: d%",
3618 sizeof(RIL_LceDataInfo), responselen);
3619 }
3620 return RIL_ERRNO_INVALID_RESPONSE;
3621 }
3622
3623 RIL_LceDataInfo *p_cur = (RIL_LceDataInfo *)response;
3624 p.writeInt32(p_cur->last_hop_capacity_kbps);
3625
3626 /* p_cur->confidence_level and p_cur->lce_suspended take 1 byte each.*/
3627 p.write((void *)&(p_cur->confidence_level), 1);
3628 p.write((void *)&(p_cur->lce_suspended), 1);
3629
3630 startResponse;
3631 appendPrintBuf("LCE info received: capacity %d confidence level %d
3632 and suspended %d",
3633 p_cur->last_hop_capacity_kbps, p_cur->confidence_level,
3634 p_cur->lce_suspended);
3635 closeResponse;
3636
3637 return 0;
3638}
3639
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003640/**
3641 * A write on the wakeup fd is done just to pop us out of select()
3642 * We empty the buffer here and then ril_event will reset the timers on the
3643 * way back down
3644 */
Wink Savillef4c4d362009-04-02 01:37:03 -07003645static void processWakeupCallback(int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003646 char buff[16];
3647 int ret;
3648
Wink Saville8eb2a122012-11-19 16:05:13 -08003649 RLOGV("processWakeupCallback");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003650
3651 /* empty our wakeup socket out */
3652 do {
3653 ret = read(s_fdWakeupRead, &buff, sizeof(buff));
Wink Saville7f856802009-06-09 10:23:37 -07003654 } while (ret > 0 || (ret < 0 && errno == EINTR));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003655}
3656
Etan Cohend3652192014-06-20 08:28:44 -07003657static void onCommandsSocketClosed(RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003658 int ret;
3659 RequestInfo *p_cur;
Etan Cohend3652192014-06-20 08:28:44 -07003660 /* Hook for current context
3661 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
3662 pthread_mutex_t * pendingRequestsMutexHook = &s_pendingRequestsMutex;
3663 /* pendingRequestsHook refer to &s_pendingRequests */
3664 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003665
Etan Cohend3652192014-06-20 08:28:44 -07003666#if (SIM_COUNT >= 2)
3667 if (socket_id == RIL_SOCKET_2) {
3668 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
3669 pendingRequestsHook = &s_pendingRequests_socket2;
3670 }
3671#if (SIM_COUNT >= 3)
3672 else if (socket_id == RIL_SOCKET_3) {
3673 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
3674 pendingRequestsHook = &s_pendingRequests_socket3;
3675 }
3676#endif
3677#if (SIM_COUNT >= 4)
3678 else if (socket_id == RIL_SOCKET_4) {
3679 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
3680 pendingRequestsHook = &s_pendingRequests_socket4;
3681 }
3682#endif
3683#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003684 /* mark pending requests as "cancelled" so we dont report responses */
Etan Cohend3652192014-06-20 08:28:44 -07003685 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003686 assert (ret == 0);
3687
Etan Cohend3652192014-06-20 08:28:44 -07003688 p_cur = *pendingRequestsHook;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003689
Etan Cohend3652192014-06-20 08:28:44 -07003690 for (p_cur = *pendingRequestsHook
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003691 ; p_cur != NULL
3692 ; p_cur = p_cur->p_next
3693 ) {
3694 p_cur->cancelled = 1;
3695 }
3696
Etan Cohend3652192014-06-20 08:28:44 -07003697 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003698 assert (ret == 0);
3699}
3700
Wink Savillef4c4d362009-04-02 01:37:03 -07003701static void processCommandsCallback(int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003702 RecordStream *p_rs;
3703 void *p_record;
3704 size_t recordlen;
3705 int ret;
Etan Cohend3652192014-06-20 08:28:44 -07003706 SocketListenParam *p_info = (SocketListenParam *)param;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003707
Etan Cohend3652192014-06-20 08:28:44 -07003708 assert(fd == p_info->fdCommand);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003709
Etan Cohend3652192014-06-20 08:28:44 -07003710 p_rs = p_info->p_rs;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003711
3712 for (;;) {
3713 /* loop until EAGAIN/EINTR, end of stream, or other error */
3714 ret = record_stream_get_next(p_rs, &p_record, &recordlen);
3715
3716 if (ret == 0 && p_record == NULL) {
3717 /* end-of-stream */
3718 break;
3719 } else if (ret < 0) {
3720 break;
3721 } else if (ret == 0) { /* && p_record != NULL */
Etan Cohend3652192014-06-20 08:28:44 -07003722 processCommandBuffer(p_record, recordlen, p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003723 }
3724 }
3725
3726 if (ret == 0 || !(errno == EAGAIN || errno == EINTR)) {
3727 /* fatal error or end-of-stream */
3728 if (ret != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003729 RLOGE("error on reading command socket errno:%d\n", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003730 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003731 RLOGW("EOS. Closing command socket.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003732 }
Wink Saville7f856802009-06-09 10:23:37 -07003733
Etan Cohend3652192014-06-20 08:28:44 -07003734 close(fd);
3735 p_info->fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003736
Etan Cohend3652192014-06-20 08:28:44 -07003737 ril_event_del(p_info->commands_event);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003738
3739 record_stream_free(p_rs);
3740
3741 /* start listening for new connections again */
3742 rilEventAddWakeup(&s_listen_event);
3743
Etan Cohend3652192014-06-20 08:28:44 -07003744 onCommandsSocketClosed(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003745 }
3746}
3747
3748
Etan Cohend3652192014-06-20 08:28:44 -07003749static void onNewCommandConnect(RIL_SOCKET_ID socket_id) {
Wink Saville5b9df332011-04-06 16:24:21 -07003750 // Inform we are connected and the ril version
Jake Hambya9c18d12011-04-12 23:32:08 -07003751 int rilVer = s_callbacks.version;
Etan Cohend3652192014-06-20 08:28:44 -07003752 RIL_UNSOL_RESPONSE(RIL_UNSOL_RIL_CONNECTED,
3753 &rilVer, sizeof(rilVer), socket_id);
Wink Saville5b9df332011-04-06 16:24:21 -07003754
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003755 // implicit radio state changed
Etan Cohend3652192014-06-20 08:28:44 -07003756 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
3757 NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003758
3759 // Send last NITZ time data, in case it was missed
3760 if (s_lastNITZTimeData != NULL) {
Etan Cohend3652192014-06-20 08:28:44 -07003761 sendResponseRaw(s_lastNITZTimeData, s_lastNITZTimeDataSize, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003762
3763 free(s_lastNITZTimeData);
3764 s_lastNITZTimeData = NULL;
3765 }
3766
3767 // Get version string
3768 if (s_callbacks.getVersion != NULL) {
3769 const char *version;
3770 version = s_callbacks.getVersion();
Wink Saville8eb2a122012-11-19 16:05:13 -08003771 RLOGI("RIL Daemon version: %s\n", version);
Wink Saville7f856802009-06-09 10:23:37 -07003772
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003773 property_set(PROPERTY_RIL_IMPL, version);
3774 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003775 RLOGI("RIL Daemon version: unavailable\n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003776 property_set(PROPERTY_RIL_IMPL, "unavailable");
3777 }
3778
3779}
3780
Wink Savillef4c4d362009-04-02 01:37:03 -07003781static void listenCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003782 int ret;
3783 int err;
3784 int is_phone_socket;
Etan Cohend3652192014-06-20 08:28:44 -07003785 int fdCommand = -1;
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003786 char* processName;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003787 RecordStream *p_rs;
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003788 MySocketListenParam* listenParam;
3789 RilSocket *sapSocket = NULL;
3790 socketClient *sClient = NULL;
3791
Etan Cohend3652192014-06-20 08:28:44 -07003792 SocketListenParam *p_info = (SocketListenParam *)param;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003793
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003794 if(RIL_SAP_SOCKET == p_info->type) {
3795 listenParam = (MySocketListenParam *)param;
3796 sapSocket = listenParam->socket;
3797 }
3798
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003799 struct sockaddr_un peeraddr;
3800 socklen_t socklen = sizeof (peeraddr);
3801
3802 struct ucred creds;
3803 socklen_t szCreds = sizeof(creds);
3804
3805 struct passwd *pwd = NULL;
3806
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003807 if(NULL == sapSocket) {
3808 assert (*p_info->fdCommand < 0);
3809 assert (fd == *p_info->fdListen);
3810 processName = PHONE_PROCESS;
3811 } else {
3812 assert (sapSocket->commandFd < 0);
3813 assert (fd == sapSocket->listenFd);
3814 processName = BLUETOOTH_PROCESS;
3815 }
3816
Wink Saville7f856802009-06-09 10:23:37 -07003817
Etan Cohend3652192014-06-20 08:28:44 -07003818 fdCommand = accept(fd, (sockaddr *) &peeraddr, &socklen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003819
Etan Cohend3652192014-06-20 08:28:44 -07003820 if (fdCommand < 0 ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003821 RLOGE("Error on accept() errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003822 /* start listening for new connections again */
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003823 if(NULL == sapSocket) {
3824 rilEventAddWakeup(p_info->listen_event);
3825 } else {
3826 rilEventAddWakeup(sapSocket->getListenEvent());
3827 }
Etan Cohend3652192014-06-20 08:28:44 -07003828 return;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003829 }
3830
3831 /* check the credential of the other side and only accept socket from
3832 * phone process
Wink Saville7f856802009-06-09 10:23:37 -07003833 */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003834 errno = 0;
3835 is_phone_socket = 0;
Wink Savillef4c4d362009-04-02 01:37:03 -07003836
Etan Cohend3652192014-06-20 08:28:44 -07003837 err = getsockopt(fdCommand, SOL_SOCKET, SO_PEERCRED, &creds, &szCreds);
Wink Savillef4c4d362009-04-02 01:37:03 -07003838
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003839 if (err == 0 && szCreds > 0) {
Wink Savillef4c4d362009-04-02 01:37:03 -07003840 errno = 0;
3841 pwd = getpwuid(creds.uid);
3842 if (pwd != NULL) {
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003843 if (strcmp(pwd->pw_name, processName) == 0) {
Wink Savillef4c4d362009-04-02 01:37:03 -07003844 is_phone_socket = 1;
3845 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003846 RLOGE("RILD can't accept socket from process %s", pwd->pw_name);
Wink Savillef4c4d362009-04-02 01:37:03 -07003847 }
3848 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003849 RLOGE("Error on getpwuid() errno: %d", errno);
Wink Savillef4c4d362009-04-02 01:37:03 -07003850 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003851 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003852 RLOGD("Error on getsockopt() errno: %d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003853 }
3854
Etan Cohend3652192014-06-20 08:28:44 -07003855 if (!is_phone_socket) {
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003856 RLOGE("RILD must accept socket from %s", processName);
Wink Saville7f856802009-06-09 10:23:37 -07003857
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003858 close(fdCommand);
3859 fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003860
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003861 if(NULL == sapSocket) {
3862 onCommandsSocketClosed(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003863
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003864 /* start listening for new connections again */
3865 rilEventAddWakeup(p_info->listen_event);
3866 } else {
3867 sapSocket->onCommandsSocketClosed();
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003868
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003869 /* start listening for new connections again */
3870 rilEventAddWakeup(sapSocket->getListenEvent());
3871 }
3872
3873 return;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003874 }
3875
Etan Cohend3652192014-06-20 08:28:44 -07003876 ret = fcntl(fdCommand, F_SETFL, O_NONBLOCK);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003877
3878 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003879 RLOGE ("Error setting O_NONBLOCK errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003880 }
3881
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003882 if(NULL == sapSocket) {
3883 RLOGI("libril: new connection to %s", rilSocketIdToString(p_info->socket_id));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003884
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003885 p_info->fdCommand = fdCommand;
3886 p_rs = record_stream_new(p_info->fdCommand, MAX_COMMAND_BYTES);
3887 p_info->p_rs = p_rs;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003888
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003889 ril_event_set (p_info->commands_event, p_info->fdCommand, 1,
Etan Cohend3652192014-06-20 08:28:44 -07003890 p_info->processCommandsCallback, p_info);
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003891 rilEventAddWakeup (p_info->commands_event);
Etan Cohend3652192014-06-20 08:28:44 -07003892
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003893 onNewCommandConnect(p_info->socket_id);
3894 } else {
3895 RLOGI("libril: new connection");
Etan Cohend3652192014-06-20 08:28:44 -07003896
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003897 sapSocket->setCommandFd(fdCommand);
3898 p_rs = record_stream_new(sapSocket->getCommandFd(), MAX_COMMAND_BYTES);
3899 sClient = new socketClient(sapSocket,p_rs);
3900 ril_event_set (sapSocket->getCallbackEvent(), sapSocket->getCommandFd(), 1,
3901 sapSocket->getCommandCb(), sClient);
3902
3903 rilEventAddWakeup(sapSocket->getCallbackEvent());
3904 sapSocket->onNewCommandConnect();
3905 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003906}
3907
3908static void freeDebugCallbackArgs(int number, char **args) {
3909 for (int i = 0; i < number; i++) {
3910 if (args[i] != NULL) {
3911 free(args[i]);
3912 }
3913 }
3914 free(args);
3915}
3916
Wink Savillef4c4d362009-04-02 01:37:03 -07003917static void debugCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003918 int acceptFD, option;
3919 struct sockaddr_un peeraddr;
3920 socklen_t socklen = sizeof (peeraddr);
3921 int data;
3922 unsigned int qxdm_data[6];
3923 const char *deactData[1] = {"1"};
3924 char *actData[1];
3925 RIL_Dial dialData;
3926 int hangupData[1] = {1};
3927 int number;
3928 char **args;
Etan Cohend3652192014-06-20 08:28:44 -07003929 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
3930 int sim_id = 0;
3931
3932 RLOGI("debugCallback for socket %s", rilSocketIdToString(socket_id));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003933
3934 acceptFD = accept (fd, (sockaddr *) &peeraddr, &socklen);
3935
3936 if (acceptFD < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003937 RLOGE ("error accepting on debug port: %d\n", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003938 return;
3939 }
3940
3941 if (recv(acceptFD, &number, sizeof(int), 0) != sizeof(int)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003942 RLOGE ("error reading on socket: number of Args: \n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003943 return;
3944 }
3945 args = (char **) malloc(sizeof(char*) * number);
3946
3947 for (int i = 0; i < number; i++) {
3948 int len;
3949 if (recv(acceptFD, &len, sizeof(int), 0) != sizeof(int)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003950 RLOGE ("error reading on socket: Len of Args: \n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003951 freeDebugCallbackArgs(i, args);
3952 return;
3953 }
3954 // +1 for null-term
3955 args[i] = (char *) malloc((sizeof(char) * len) + 1);
Wink Saville7f856802009-06-09 10:23:37 -07003956 if (recv(acceptFD, args[i], sizeof(char) * len, 0)
Wink Saville1b5fd232009-04-22 14:50:00 -07003957 != (int)sizeof(char) * len) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003958 RLOGE ("error reading on socket: Args[%d] \n", i);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003959 freeDebugCallbackArgs(i, args);
3960 return;
3961 }
3962 char * buf = args[i];
3963 buf[len] = 0;
Etan Cohend3652192014-06-20 08:28:44 -07003964 if ((i+1) == number) {
3965 /* The last argument should be sim id 0(SIM1)~3(SIM4) */
3966 sim_id = atoi(args[i]);
3967 switch (sim_id) {
3968 case 0:
3969 socket_id = RIL_SOCKET_1;
3970 break;
3971 #if (SIM_COUNT >= 2)
3972 case 1:
3973 socket_id = RIL_SOCKET_2;
3974 break;
3975 #endif
3976 #if (SIM_COUNT >= 3)
3977 case 2:
3978 socket_id = RIL_SOCKET_3;
3979 break;
3980 #endif
3981 #if (SIM_COUNT >= 4)
3982 case 3:
3983 socket_id = RIL_SOCKET_4;
3984 break;
3985 #endif
3986 default:
3987 socket_id = RIL_SOCKET_1;
3988 break;
3989 }
3990 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003991 }
3992
3993 switch (atoi(args[0])) {
3994 case 0:
Wink Saville8eb2a122012-11-19 16:05:13 -08003995 RLOGI ("Connection on debug port: issuing reset.");
Etan Cohend3652192014-06-20 08:28:44 -07003996 issueLocalRequest(RIL_REQUEST_RESET_RADIO, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003997 break;
3998 case 1:
Wink Saville8eb2a122012-11-19 16:05:13 -08003999 RLOGI ("Connection on debug port: issuing radio power off.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004000 data = 0;
Etan Cohend3652192014-06-20 08:28:44 -07004001 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004002 // Close the socket
Etan Cohend3652192014-06-20 08:28:44 -07004003 if (socket_id == RIL_SOCKET_1 && s_ril_param_socket.fdCommand > 0) {
4004 close(s_ril_param_socket.fdCommand);
4005 s_ril_param_socket.fdCommand = -1;
4006 }
4007 #if (SIM_COUNT == 2)
4008 else if (socket_id == RIL_SOCKET_2 && s_ril_param_socket2.fdCommand > 0) {
4009 close(s_ril_param_socket2.fdCommand);
4010 s_ril_param_socket2.fdCommand = -1;
4011 }
4012 #endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004013 break;
4014 case 2:
Wink Saville8eb2a122012-11-19 16:05:13 -08004015 RLOGI ("Debug port: issuing unsolicited voice network change.");
Etan Cohend3652192014-06-20 08:28:44 -07004016 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004017 break;
4018 case 3:
Wink Saville8eb2a122012-11-19 16:05:13 -08004019 RLOGI ("Debug port: QXDM log enable.");
Xia Wangd855ef42010-07-27 17:26:55 -07004020 qxdm_data[0] = 65536; // head.func_tag
4021 qxdm_data[1] = 16; // head.len
4022 qxdm_data[2] = 1; // mode: 1 for 'start logging'
4023 qxdm_data[3] = 32; // log_file_size: 32megabytes
4024 qxdm_data[4] = 0; // log_mask
4025 qxdm_data[5] = 8; // log_max_fileindex
Wink Saville7f856802009-06-09 10:23:37 -07004026 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Etan Cohend3652192014-06-20 08:28:44 -07004027 6 * sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004028 break;
4029 case 4:
Wink Saville8eb2a122012-11-19 16:05:13 -08004030 RLOGI ("Debug port: QXDM log disable.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004031 qxdm_data[0] = 65536;
4032 qxdm_data[1] = 16;
Xia Wangd855ef42010-07-27 17:26:55 -07004033 qxdm_data[2] = 0; // mode: 0 for 'stop logging'
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004034 qxdm_data[3] = 32;
4035 qxdm_data[4] = 0;
Xia Wangd855ef42010-07-27 17:26:55 -07004036 qxdm_data[5] = 8;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004037 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Etan Cohend3652192014-06-20 08:28:44 -07004038 6 * sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004039 break;
4040 case 5:
Wink Saville8eb2a122012-11-19 16:05:13 -08004041 RLOGI("Debug port: Radio On");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004042 data = 1;
Etan Cohend3652192014-06-20 08:28:44 -07004043 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004044 sleep(2);
4045 // Set network selection automatic.
Etan Cohend3652192014-06-20 08:28:44 -07004046 issueLocalRequest(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004047 break;
4048 case 6:
Wink Saville8eb2a122012-11-19 16:05:13 -08004049 RLOGI("Debug port: Setup Data Call, Apn :%s\n", args[1]);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004050 actData[0] = args[1];
Wink Saville7f856802009-06-09 10:23:37 -07004051 issueLocalRequest(RIL_REQUEST_SETUP_DATA_CALL, &actData,
Etan Cohend3652192014-06-20 08:28:44 -07004052 sizeof(actData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004053 break;
4054 case 7:
Wink Saville8eb2a122012-11-19 16:05:13 -08004055 RLOGI("Debug port: Deactivate Data Call");
Wink Saville7f856802009-06-09 10:23:37 -07004056 issueLocalRequest(RIL_REQUEST_DEACTIVATE_DATA_CALL, &deactData,
Etan Cohend3652192014-06-20 08:28:44 -07004057 sizeof(deactData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004058 break;
4059 case 8:
Wink Saville8eb2a122012-11-19 16:05:13 -08004060 RLOGI("Debug port: Dial Call");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004061 dialData.clir = 0;
4062 dialData.address = args[1];
Etan Cohend3652192014-06-20 08:28:44 -07004063 issueLocalRequest(RIL_REQUEST_DIAL, &dialData, sizeof(dialData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004064 break;
4065 case 9:
Wink Saville8eb2a122012-11-19 16:05:13 -08004066 RLOGI("Debug port: Answer Call");
Etan Cohend3652192014-06-20 08:28:44 -07004067 issueLocalRequest(RIL_REQUEST_ANSWER, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004068 break;
4069 case 10:
Wink Saville8eb2a122012-11-19 16:05:13 -08004070 RLOGI("Debug port: End Call");
Wink Saville7f856802009-06-09 10:23:37 -07004071 issueLocalRequest(RIL_REQUEST_HANGUP, &hangupData,
Etan Cohend3652192014-06-20 08:28:44 -07004072 sizeof(hangupData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004073 break;
4074 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004075 RLOGE ("Invalid request");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004076 break;
4077 }
4078 freeDebugCallbackArgs(number, args);
4079 close(acceptFD);
4080}
4081
4082
Wink Savillef4c4d362009-04-02 01:37:03 -07004083static void userTimerCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004084 UserCallbackInfo *p_info;
4085
4086 p_info = (UserCallbackInfo *)param;
4087
4088 p_info->p_callback(p_info->userParam);
4089
4090
4091 // FIXME generalize this...there should be a cancel mechanism
4092 if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) {
4093 s_last_wake_timeout_info = NULL;
4094 }
4095
4096 free(p_info);
4097}
4098
4099
4100static void *
Wink Savillef4c4d362009-04-02 01:37:03 -07004101eventLoop(void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004102 int ret;
4103 int filedes[2];
4104
4105 ril_event_init();
4106
4107 pthread_mutex_lock(&s_startupMutex);
4108
4109 s_started = 1;
4110 pthread_cond_broadcast(&s_startupCond);
4111
4112 pthread_mutex_unlock(&s_startupMutex);
4113
4114 ret = pipe(filedes);
4115
4116 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004117 RLOGE("Error in pipe() errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004118 return NULL;
4119 }
4120
4121 s_fdWakeupRead = filedes[0];
4122 s_fdWakeupWrite = filedes[1];
4123
4124 fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK);
4125
4126 ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,
4127 processWakeupCallback, NULL);
4128
4129 rilEventAddWakeup (&s_wakeupfd_event);
4130
4131 // Only returns on error
4132 ril_event_loop();
Wink Saville8eb2a122012-11-19 16:05:13 -08004133 RLOGE ("error in event_loop_base errno:%d", errno);
Kazuhiro Ondo5cdc1352011-10-14 17:50:58 -05004134 // kill self to restart on error
4135 kill(0, SIGKILL);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004136
4137 return NULL;
4138}
4139
Wink Saville7f856802009-06-09 10:23:37 -07004140extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07004141RIL_startEventLoop(void) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004142 /* spin up eventLoop thread and wait for it to get started */
4143 s_started = 0;
4144 pthread_mutex_lock(&s_startupMutex);
4145
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004146 pthread_attr_t attr;
4147 pthread_attr_init(&attr);
Wink Saville7f856802009-06-09 10:23:37 -07004148 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004149
Elliott Hughesfd81e712014-01-06 12:46:02 -08004150 int result = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
4151 if (result != 0) {
4152 RLOGE("Failed to create dispatch thread: %s", strerror(result));
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004153 goto done;
4154 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004155
4156 while (s_started == 0) {
4157 pthread_cond_wait(&s_startupCond, &s_startupMutex);
4158 }
4159
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004160done:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004161 pthread_mutex_unlock(&s_startupMutex);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004162}
4163
4164// Used for testing purpose only.
4165extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) {
4166 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4167}
4168
Etan Cohend3652192014-06-20 08:28:44 -07004169static void startListen(RIL_SOCKET_ID socket_id, SocketListenParam* socket_listen_p) {
4170 int fdListen = -1;
4171 int ret;
4172 char socket_name[10];
4173
4174 memset(socket_name, 0, sizeof(char)*10);
4175
4176 switch(socket_id) {
4177 case RIL_SOCKET_1:
4178 strncpy(socket_name, RIL_getRilSocketName(), 9);
4179 break;
4180 #if (SIM_COUNT >= 2)
4181 case RIL_SOCKET_2:
4182 strncpy(socket_name, SOCKET2_NAME_RIL, 9);
4183 break;
4184 #endif
4185 #if (SIM_COUNT >= 3)
4186 case RIL_SOCKET_3:
4187 strncpy(socket_name, SOCKET3_NAME_RIL, 9);
4188 break;
4189 #endif
4190 #if (SIM_COUNT >= 4)
4191 case RIL_SOCKET_4:
4192 strncpy(socket_name, SOCKET4_NAME_RIL, 9);
4193 break;
4194 #endif
4195 default:
4196 RLOGE("Socket id is wrong!!");
4197 return;
4198 }
4199
4200 RLOGI("Start to listen %s", rilSocketIdToString(socket_id));
4201
4202 fdListen = android_get_control_socket(socket_name);
4203 if (fdListen < 0) {
4204 RLOGE("Failed to get socket %s", socket_name);
4205 exit(-1);
4206 }
4207
4208 ret = listen(fdListen, 4);
4209
4210 if (ret < 0) {
4211 RLOGE("Failed to listen on control socket '%d': %s",
4212 fdListen, strerror(errno));
4213 exit(-1);
4214 }
4215 socket_listen_p->fdListen = fdListen;
4216
4217 /* note: non-persistent so we can accept only one connection at a time */
4218 ril_event_set (socket_listen_p->listen_event, fdListen, false,
4219 listenCallback, socket_listen_p);
4220
4221 rilEventAddWakeup (socket_listen_p->listen_event);
4222}
4223
Wink Saville7f856802009-06-09 10:23:37 -07004224extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07004225RIL_register (const RIL_RadioFunctions *callbacks) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004226 int ret;
4227 int flags;
4228
Etan Cohend3652192014-06-20 08:28:44 -07004229 RLOGI("SIM_COUNT: %d", SIM_COUNT);
4230
Wink Saville43808972011-01-13 17:39:51 -08004231 if (callbacks == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004232 RLOGE("RIL_register: RIL_RadioFunctions * null");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004233 return;
4234 }
Wink Saville43808972011-01-13 17:39:51 -08004235 if (callbacks->version < RIL_VERSION_MIN) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004236 RLOGE("RIL_register: version %d is to old, min version is %d",
Wink Saville43808972011-01-13 17:39:51 -08004237 callbacks->version, RIL_VERSION_MIN);
4238 return;
Wink Saville3a4840b2010-04-07 13:29:58 -07004239 }
Wink Saville43808972011-01-13 17:39:51 -08004240 if (callbacks->version > RIL_VERSION) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004241 RLOGE("RIL_register: version %d is too new, max version is %d",
Wink Saville43808972011-01-13 17:39:51 -08004242 callbacks->version, RIL_VERSION);
4243 return;
4244 }
Wink Saville8eb2a122012-11-19 16:05:13 -08004245 RLOGE("RIL_register: RIL version %d", callbacks->version);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004246
4247 if (s_registerCalled > 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004248 RLOGE("RIL_register has been called more than once. "
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004249 "Subsequent call ignored");
4250 return;
4251 }
4252
4253 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4254
Etan Cohend3652192014-06-20 08:28:44 -07004255 /* Initialize socket1 parameters */
4256 s_ril_param_socket = {
4257 RIL_SOCKET_1, /* socket_id */
4258 -1, /* fdListen */
4259 -1, /* fdCommand */
4260 PHONE_PROCESS, /* processName */
4261 &s_commands_event, /* commands_event */
4262 &s_listen_event, /* listen_event */
4263 processCommandsCallback, /* processCommandsCallback */
4264 NULL /* p_rs */
4265 };
4266
4267#if (SIM_COUNT >= 2)
4268 s_ril_param_socket2 = {
4269 RIL_SOCKET_2, /* socket_id */
4270 -1, /* fdListen */
4271 -1, /* fdCommand */
4272 PHONE_PROCESS, /* processName */
4273 &s_commands_event_socket2, /* commands_event */
4274 &s_listen_event_socket2, /* listen_event */
4275 processCommandsCallback, /* processCommandsCallback */
4276 NULL /* p_rs */
4277 };
4278#endif
4279
4280#if (SIM_COUNT >= 3)
4281 s_ril_param_socket3 = {
4282 RIL_SOCKET_3, /* socket_id */
4283 -1, /* fdListen */
4284 -1, /* fdCommand */
4285 PHONE_PROCESS, /* processName */
4286 &s_commands_event_socket3, /* commands_event */
4287 &s_listen_event_socket3, /* listen_event */
4288 processCommandsCallback, /* processCommandsCallback */
4289 NULL /* p_rs */
4290 };
4291#endif
4292
4293#if (SIM_COUNT >= 4)
4294 s_ril_param_socket4 = {
4295 RIL_SOCKET_4, /* socket_id */
4296 -1, /* fdListen */
4297 -1, /* fdCommand */
4298 PHONE_PROCESS, /* processName */
4299 &s_commands_event_socket4, /* commands_event */
4300 &s_listen_event_socket4, /* listen_event */
4301 processCommandsCallback, /* processCommandsCallback */
4302 NULL /* p_rs */
4303 };
4304#endif
4305
4306
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004307 s_registerCalled = 1;
4308
Etan Cohend3652192014-06-20 08:28:44 -07004309 RLOGI("s_registerCalled flag set, %d", s_started);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004310 // Little self-check
4311
Wink Savillef4c4d362009-04-02 01:37:03 -07004312 for (int i = 0; i < (int)NUM_ELEMS(s_commands); i++) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004313 assert(i == s_commands[i].requestNumber);
4314 }
4315
Wink Savillef4c4d362009-04-02 01:37:03 -07004316 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses); i++) {
Wink Saville7f856802009-06-09 10:23:37 -07004317 assert(i + RIL_UNSOL_RESPONSE_BASE
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004318 == s_unsolResponses[i].requestNumber);
4319 }
4320
4321 // New rild impl calls RIL_startEventLoop() first
4322 // old standalone impl wants it here.
4323
4324 if (s_started == 0) {
4325 RIL_startEventLoop();
4326 }
4327
Etan Cohend3652192014-06-20 08:28:44 -07004328 // start listen socket1
4329 startListen(RIL_SOCKET_1, &s_ril_param_socket);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004330
Etan Cohend3652192014-06-20 08:28:44 -07004331#if (SIM_COUNT >= 2)
4332 // start listen socket2
4333 startListen(RIL_SOCKET_2, &s_ril_param_socket2);
4334#endif /* (SIM_COUNT == 2) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004335
Etan Cohend3652192014-06-20 08:28:44 -07004336#if (SIM_COUNT >= 3)
4337 // start listen socket3
4338 startListen(RIL_SOCKET_3, &s_ril_param_socket3);
4339#endif /* (SIM_COUNT == 3) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004340
Etan Cohend3652192014-06-20 08:28:44 -07004341#if (SIM_COUNT >= 4)
4342 // start listen socket4
4343 startListen(RIL_SOCKET_4, &s_ril_param_socket4);
4344#endif /* (SIM_COUNT == 4) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004345
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004346
4347#if 1
4348 // start debug interface socket
4349
Etan Cohend3652192014-06-20 08:28:44 -07004350 char *inst = NULL;
4351 if (strlen(RIL_getRilSocketName()) >= strlen(SOCKET_NAME_RIL)) {
4352 inst = RIL_getRilSocketName() + strlen(SOCKET_NAME_RIL);
4353 }
4354
4355 char rildebug[MAX_DEBUG_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL_DEBUG;
4356 if (inst != NULL) {
Nick Kralevichc52e45e2015-02-08 07:54:16 -08004357 strlcat(rildebug, inst, MAX_DEBUG_SOCKET_NAME_LENGTH);
Etan Cohend3652192014-06-20 08:28:44 -07004358 }
4359
4360 s_fdDebug = android_get_control_socket(rildebug);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004361 if (s_fdDebug < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07004362 RLOGE("Failed to get socket : %s errno:%d", rildebug, errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004363 exit(-1);
4364 }
4365
4366 ret = listen(s_fdDebug, 4);
4367
4368 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004369 RLOGE("Failed to listen on ril debug socket '%d': %s",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004370 s_fdDebug, strerror(errno));
4371 exit(-1);
4372 }
4373
4374 ril_event_set (&s_debug_event, s_fdDebug, true,
4375 debugCallback, NULL);
4376
4377 rilEventAddWakeup (&s_debug_event);
4378#endif
4379
4380}
4381
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004382extern "C" void
4383RIL_register_socket (RIL_RadioFunctions *(*Init)(const struct RIL_Env *, int, char **),RIL_SOCKET_TYPE socketType, int argc, char **argv) {
4384
4385 RIL_RadioFunctions* UimFuncs = NULL;
4386
4387 if(Init) {
4388 UimFuncs = Init(&RilSapSocket::uimRilEnv, argc, argv);
4389
4390 switch(socketType) {
4391 case RIL_SAP_SOCKET:
4392 RilSapSocket::initSapSocket("sap_uim_socket1", UimFuncs);
4393
4394#if (SIM_COUNT >= 2)
4395 RilSapSocket::initSapSocket("sap_uim_socket2", UimFuncs);
4396#endif
4397
4398#if (SIM_COUNT >= 3)
4399 RilSapSocket::initSapSocket("sap_uim_socket3", UimFuncs);
4400#endif
4401
4402#if (SIM_COUNT >= 4)
4403 RilSapSocket::initSapSocket("sap_uim_socket4", UimFuncs);
4404#endif
4405 }
4406 }
4407}
4408
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004409static int
Wink Savillef4c4d362009-04-02 01:37:03 -07004410checkAndDequeueRequestInfo(struct RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004411 int ret = 0;
Etan Cohend3652192014-06-20 08:28:44 -07004412 /* Hook for current context
4413 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
4414 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
4415 /* pendingRequestsHook refer to &s_pendingRequests */
4416 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
Wink Saville7f856802009-06-09 10:23:37 -07004417
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004418 if (pRI == NULL) {
4419 return 0;
4420 }
4421
Etan Cohend3652192014-06-20 08:28:44 -07004422#if (SIM_COUNT >= 2)
4423 if (pRI->socket_id == RIL_SOCKET_2) {
4424 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
4425 pendingRequestsHook = &s_pendingRequests_socket2;
4426 }
4427#if (SIM_COUNT >= 3)
4428 if (pRI->socket_id == RIL_SOCKET_3) {
4429 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
4430 pendingRequestsHook = &s_pendingRequests_socket3;
4431 }
4432#endif
4433#if (SIM_COUNT >= 4)
4434 if (pRI->socket_id == RIL_SOCKET_4) {
4435 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
4436 pendingRequestsHook = &s_pendingRequests_socket4;
4437 }
4438#endif
4439#endif
4440 pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004441
Etan Cohend3652192014-06-20 08:28:44 -07004442 for(RequestInfo **ppCur = pendingRequestsHook
Wink Saville7f856802009-06-09 10:23:37 -07004443 ; *ppCur != NULL
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004444 ; ppCur = &((*ppCur)->p_next)
4445 ) {
4446 if (pRI == *ppCur) {
4447 ret = 1;
4448
4449 *ppCur = (*ppCur)->p_next;
4450 break;
4451 }
4452 }
4453
Etan Cohend3652192014-06-20 08:28:44 -07004454 pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004455
4456 return ret;
4457}
4458
4459
4460extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07004461RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004462 RequestInfo *pRI;
4463 int ret;
Etan Cohend3652192014-06-20 08:28:44 -07004464 int fd = s_ril_param_socket.fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004465 size_t errorOffset;
Etan Cohend3652192014-06-20 08:28:44 -07004466 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004467
4468 pRI = (RequestInfo *)t;
4469
Jayachandran C6c607592014-08-04 15:48:01 -07004470 if (!checkAndDequeueRequestInfo(pRI)) {
4471 RLOGE ("RIL_onRequestComplete: invalid RIL_Token");
4472 return;
4473 }
4474
Etan Cohend3652192014-06-20 08:28:44 -07004475 socket_id = pRI->socket_id;
4476#if (SIM_COUNT >= 2)
4477 if (socket_id == RIL_SOCKET_2) {
4478 fd = s_ril_param_socket2.fdCommand;
4479 }
4480#if (SIM_COUNT >= 3)
4481 if (socket_id == RIL_SOCKET_3) {
4482 fd = s_ril_param_socket3.fdCommand;
4483 }
4484#endif
4485#if (SIM_COUNT >= 4)
4486 if (socket_id == RIL_SOCKET_4) {
4487 fd = s_ril_param_socket4.fdCommand;
4488 }
4489#endif
4490#endif
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07004491#if VDBG
Etan Cohend3652192014-06-20 08:28:44 -07004492 RLOGD("RequestComplete, %s", rilSocketIdToString(socket_id));
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07004493#endif
Etan Cohend3652192014-06-20 08:28:44 -07004494
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004495 if (pRI->local > 0) {
4496 // Locally issued command...void only!
4497 // response does not go back up the command socket
Wink Saville8eb2a122012-11-19 16:05:13 -08004498 RLOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004499
4500 goto done;
4501 }
4502
4503 appendPrintBuf("[%04d]< %s",
4504 pRI->token, requestToString(pRI->pCI->requestNumber));
4505
4506 if (pRI->cancelled == 0) {
4507 Parcel p;
4508
4509 p.writeInt32 (RESPONSE_SOLICITED);
4510 p.writeInt32 (pRI->token);
4511 errorOffset = p.dataPosition();
4512
4513 p.writeInt32 (e);
4514
johnwangb2a61842009-06-02 14:55:45 -07004515 if (response != NULL) {
4516 // there is a response payload, no matter success or not.
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004517 ret = pRI->pCI->responseFunction(p, response, responselen);
4518
4519 /* if an error occurred, rewind and mark it */
4520 if (ret != 0) {
Etan Cohend3652192014-06-20 08:28:44 -07004521 RLOGE ("responseFunction error, ret %d", ret);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004522 p.setDataPosition(errorOffset);
4523 p.writeInt32 (ret);
4524 }
johnwangb2a61842009-06-02 14:55:45 -07004525 }
4526
4527 if (e != RIL_E_SUCCESS) {
4528 appendPrintBuf("%s fails by %s", printBuf, failCauseToString(e));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004529 }
4530
Etan Cohend3652192014-06-20 08:28:44 -07004531 if (fd < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004532 RLOGD ("RIL onRequestComplete: Command channel closed");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004533 }
Etan Cohend3652192014-06-20 08:28:44 -07004534 sendResponse(p, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004535 }
4536
4537done:
4538 free(pRI);
4539}
4540
4541
4542static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004543grabPartialWakeLock() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004544 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
4545}
4546
4547static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004548releaseWakeLock() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004549 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
4550}
4551
4552/**
4553 * Timer callback to put us back to sleep before the default timeout
4554 */
4555static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004556wakeTimeoutCallback (void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004557 // We're using "param != NULL" as a cancellation mechanism
4558 if (param == NULL) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004559 releaseWakeLock();
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004560 }
4561}
4562
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004563static int
4564decodeVoiceRadioTechnology (RIL_RadioState radioState) {
4565 switch (radioState) {
4566 case RADIO_STATE_SIM_NOT_READY:
4567 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4568 case RADIO_STATE_SIM_READY:
4569 return RADIO_TECH_UMTS;
4570
4571 case RADIO_STATE_RUIM_NOT_READY:
4572 case RADIO_STATE_RUIM_READY:
4573 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4574 case RADIO_STATE_NV_NOT_READY:
4575 case RADIO_STATE_NV_READY:
4576 return RADIO_TECH_1xRTT;
4577
4578 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004579 RLOGD("decodeVoiceRadioTechnology: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004580 return -1;
4581 }
4582}
4583
4584static int
4585decodeCdmaSubscriptionSource (RIL_RadioState radioState) {
4586 switch (radioState) {
4587 case RADIO_STATE_SIM_NOT_READY:
4588 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4589 case RADIO_STATE_SIM_READY:
4590 case RADIO_STATE_RUIM_NOT_READY:
4591 case RADIO_STATE_RUIM_READY:
4592 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4593 return CDMA_SUBSCRIPTION_SOURCE_RUIM_SIM;
4594
4595 case RADIO_STATE_NV_NOT_READY:
4596 case RADIO_STATE_NV_READY:
4597 return CDMA_SUBSCRIPTION_SOURCE_NV;
4598
4599 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004600 RLOGD("decodeCdmaSubscriptionSource: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004601 return -1;
4602 }
4603}
4604
4605static int
4606decodeSimStatus (RIL_RadioState radioState) {
4607 switch (radioState) {
4608 case RADIO_STATE_SIM_NOT_READY:
4609 case RADIO_STATE_RUIM_NOT_READY:
4610 case RADIO_STATE_NV_NOT_READY:
4611 case RADIO_STATE_NV_READY:
4612 return -1;
4613 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4614 case RADIO_STATE_SIM_READY:
4615 case RADIO_STATE_RUIM_READY:
4616 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4617 return radioState;
4618 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004619 RLOGD("decodeSimStatus: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004620 return -1;
4621 }
4622}
4623
4624static bool is3gpp2(int radioTech) {
4625 switch (radioTech) {
4626 case RADIO_TECH_IS95A:
4627 case RADIO_TECH_IS95B:
4628 case RADIO_TECH_1xRTT:
4629 case RADIO_TECH_EVDO_0:
4630 case RADIO_TECH_EVDO_A:
4631 case RADIO_TECH_EVDO_B:
4632 case RADIO_TECH_EHRPD:
4633 return true;
4634 default:
4635 return false;
4636 }
4637}
4638
4639/* If RIL sends SIM states or RUIM states, store the voice radio
4640 * technology and subscription source information so that they can be
4641 * returned when telephony framework requests them
4642 */
4643static RIL_RadioState
Etan Cohend3652192014-06-20 08:28:44 -07004644processRadioState(RIL_RadioState newRadioState, RIL_SOCKET_ID socket_id) {
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004645
4646 if((newRadioState > RADIO_STATE_UNAVAILABLE) && (newRadioState < RADIO_STATE_ON)) {
4647 int newVoiceRadioTech;
4648 int newCdmaSubscriptionSource;
4649 int newSimStatus;
4650
4651 /* This is old RIL. Decode Subscription source and Voice Radio Technology
4652 from Radio State and send change notifications if there has been a change */
4653 newVoiceRadioTech = decodeVoiceRadioTechnology(newRadioState);
4654 if(newVoiceRadioTech != voiceRadioTech) {
4655 voiceRadioTech = newVoiceRadioTech;
Etan Cohend3652192014-06-20 08:28:44 -07004656 RIL_UNSOL_RESPONSE(RIL_UNSOL_VOICE_RADIO_TECH_CHANGED,
4657 &voiceRadioTech, sizeof(voiceRadioTech), socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004658 }
4659 if(is3gpp2(newVoiceRadioTech)) {
4660 newCdmaSubscriptionSource = decodeCdmaSubscriptionSource(newRadioState);
4661 if(newCdmaSubscriptionSource != cdmaSubscriptionSource) {
4662 cdmaSubscriptionSource = newCdmaSubscriptionSource;
Etan Cohend3652192014-06-20 08:28:44 -07004663 RIL_UNSOL_RESPONSE(RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED,
4664 &cdmaSubscriptionSource, sizeof(cdmaSubscriptionSource), socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004665 }
4666 }
4667 newSimStatus = decodeSimStatus(newRadioState);
4668 if(newSimStatus != simRuimStatus) {
4669 simRuimStatus = newSimStatus;
Etan Cohend3652192014-06-20 08:28:44 -07004670 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0, socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004671 }
4672
4673 /* Send RADIO_ON to telephony */
4674 newRadioState = RADIO_STATE_ON;
4675 }
4676
4677 return newRadioState;
4678}
4679
Etan Cohend3652192014-06-20 08:28:44 -07004680
4681#if defined(ANDROID_MULTI_SIM)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004682extern "C"
Bernhard Rosenkränzerd613b962014-11-17 20:52:09 +01004683void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Etan Cohend3652192014-06-20 08:28:44 -07004684 size_t datalen, RIL_SOCKET_ID socket_id)
4685#else
4686extern "C"
Bernhard Rosenkränzerd613b962014-11-17 20:52:09 +01004687void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004688 size_t datalen)
Etan Cohend3652192014-06-20 08:28:44 -07004689#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004690{
4691 int unsolResponseIndex;
4692 int ret;
4693 int64_t timeReceived = 0;
4694 bool shouldScheduleTimeout = false;
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004695 RIL_RadioState newState;
Etan Cohend3652192014-06-20 08:28:44 -07004696 RIL_SOCKET_ID soc_id = RIL_SOCKET_1;
4697
4698#if defined(ANDROID_MULTI_SIM)
4699 soc_id = socket_id;
4700#endif
4701
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004702
4703 if (s_registerCalled == 0) {
4704 // Ignore RIL_onUnsolicitedResponse before RIL_register
Wink Saville8eb2a122012-11-19 16:05:13 -08004705 RLOGW("RIL_onUnsolicitedResponse called before RIL_register");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004706 return;
4707 }
Wink Saville7f856802009-06-09 10:23:37 -07004708
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004709 unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
4710
4711 if ((unsolResponseIndex < 0)
4712 || (unsolResponseIndex >= (int32_t)NUM_ELEMS(s_unsolResponses))) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004713 RLOGE("unsupported unsolicited response code %d", unsolResponse);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004714 return;
4715 }
4716
4717 // Grab a wake lock if needed for this reponse,
4718 // as we exit we'll either release it immediately
4719 // or set a timer to release it later.
4720 switch (s_unsolResponses[unsolResponseIndex].wakeType) {
4721 case WAKE_PARTIAL:
4722 grabPartialWakeLock();
4723 shouldScheduleTimeout = true;
4724 break;
4725
4726 case DONT_WAKE:
4727 default:
4728 // No wake lock is grabed so don't set timeout
4729 shouldScheduleTimeout = false;
4730 break;
4731 }
4732
4733 // Mark the time this was received, doing this
4734 // after grabing the wakelock incase getting
4735 // the elapsedRealTime might cause us to goto
4736 // sleep.
4737 if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4738 timeReceived = elapsedRealtime();
4739 }
4740
4741 appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
4742
4743 Parcel p;
4744
4745 p.writeInt32 (RESPONSE_UNSOLICITED);
4746 p.writeInt32 (unsolResponse);
4747
4748 ret = s_unsolResponses[unsolResponseIndex]
Bernhard Rosenkränzer6e7c1962013-12-12 10:01:10 +01004749 .responseFunction(p, const_cast<void*>(data), datalen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004750 if (ret != 0) {
4751 // Problem with the response. Don't continue;
4752 goto error_exit;
4753 }
4754
4755 // some things get more payload
4756 switch(unsolResponse) {
4757 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
Etan Cohend3652192014-06-20 08:28:44 -07004758 newState = processRadioState(CALL_ONSTATEREQUEST(soc_id), soc_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004759 p.writeInt32(newState);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004760 appendPrintBuf("%s {%s}", printBuf,
Etan Cohend3652192014-06-20 08:28:44 -07004761 radioStateToString(CALL_ONSTATEREQUEST(soc_id)));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004762 break;
4763
4764
4765 case RIL_UNSOL_NITZ_TIME_RECEIVED:
4766 // Store the time that this was received so the
4767 // handler of this message can account for
4768 // the time it takes to arrive and process. In
4769 // particular the system has been known to sleep
4770 // before this message can be processed.
4771 p.writeInt64(timeReceived);
4772 break;
4773 }
4774
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07004775#if VDBG
Etan Cohend3652192014-06-20 08:28:44 -07004776 RLOGI("%s UNSOLICITED: %s length:%d", rilSocketIdToString(soc_id), requestToString(unsolResponse), p.dataSize());
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07004777#endif
Etan Cohend3652192014-06-20 08:28:44 -07004778 ret = sendResponse(p, soc_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004779 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4780
4781 // Unfortunately, NITZ time is not poll/update like everything
4782 // else in the system. So, if the upstream client isn't connected,
4783 // keep a copy of the last NITZ response (with receive time noted
4784 // above) around so we can deliver it when it is connected
4785
4786 if (s_lastNITZTimeData != NULL) {
4787 free (s_lastNITZTimeData);
4788 s_lastNITZTimeData = NULL;
4789 }
4790
4791 s_lastNITZTimeData = malloc(p.dataSize());
4792 s_lastNITZTimeDataSize = p.dataSize();
4793 memcpy(s_lastNITZTimeData, p.data(), p.dataSize());
4794 }
4795
4796 // For now, we automatically go back to sleep after TIMEVAL_WAKE_TIMEOUT
4797 // FIXME The java code should handshake here to release wake lock
4798
4799 if (shouldScheduleTimeout) {
4800 // Cancel the previous request
4801 if (s_last_wake_timeout_info != NULL) {
4802 s_last_wake_timeout_info->userParam = (void *)1;
4803 }
4804
4805 s_last_wake_timeout_info
4806 = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
4807 &TIMEVAL_WAKE_TIMEOUT);
4808 }
4809
4810 // Normal exit
4811 return;
4812
4813error_exit:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004814 if (shouldScheduleTimeout) {
4815 releaseWakeLock();
4816 }
4817}
4818
Wink Saville7f856802009-06-09 10:23:37 -07004819/** FIXME generalize this if you track UserCAllbackInfo, clear it
4820 when the callback occurs
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004821*/
4822static UserCallbackInfo *
Wink Saville7f856802009-06-09 10:23:37 -07004823internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004824 const struct timeval *relativeTime)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004825{
4826 struct timeval myRelativeTime;
4827 UserCallbackInfo *p_info;
4828
4829 p_info = (UserCallbackInfo *) malloc (sizeof(UserCallbackInfo));
4830
Wink Saville7f856802009-06-09 10:23:37 -07004831 p_info->p_callback = callback;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004832 p_info->userParam = param;
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004833
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004834 if (relativeTime == NULL) {
4835 /* treat null parameter as a 0 relative time */
4836 memset (&myRelativeTime, 0, sizeof(myRelativeTime));
4837 } else {
4838 /* FIXME I think event_add's tv param is really const anyway */
4839 memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
4840 }
4841
4842 ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
4843
4844 ril_timer_add(&(p_info->event), &myRelativeTime);
4845
4846 triggerEvLoop();
4847 return p_info;
4848}
4849
Naveen Kalla7edd07c2010-06-21 18:54:47 -07004850
4851extern "C" void
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004852RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
4853 const struct timeval *relativeTime) {
4854 internalRequestTimedCallback (callback, param, relativeTime);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004855}
4856
4857const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004858failCauseToString(RIL_Errno e) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004859 switch(e) {
4860 case RIL_E_SUCCESS: return "E_SUCCESS";
Robert Greenwalt2126ab22013-04-09 12:20:45 -07004861 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RADIO_NOT_AVAILABLE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004862 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
4863 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
4864 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
4865 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
4866 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
4867 case RIL_E_CANCELLED: return "E_CANCELLED";
4868 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
4869 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
4870 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
Wink Savillef4c4d362009-04-02 01:37:03 -07004871 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
John Wang75534472010-04-20 15:11:42 -07004872 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
Wink Saville7f856802009-06-09 10:23:37 -07004873#ifdef FEATURE_MULTIMODE_ANDROID
Wink Savillef4c4d362009-04-02 01:37:03 -07004874 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
4875 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
4876#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004877 default: return "<unknown error>";
4878 }
4879}
4880
4881const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004882radioStateToString(RIL_RadioState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004883 switch(s) {
4884 case RADIO_STATE_OFF: return "RADIO_OFF";
4885 case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
4886 case RADIO_STATE_SIM_NOT_READY: return "RADIO_SIM_NOT_READY";
4887 case RADIO_STATE_SIM_LOCKED_OR_ABSENT: return "RADIO_SIM_LOCKED_OR_ABSENT";
4888 case RADIO_STATE_SIM_READY: return "RADIO_SIM_READY";
Wink Savillef4c4d362009-04-02 01:37:03 -07004889 case RADIO_STATE_RUIM_NOT_READY:return"RADIO_RUIM_NOT_READY";
4890 case RADIO_STATE_RUIM_READY:return"RADIO_RUIM_READY";
4891 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:return"RADIO_RUIM_LOCKED_OR_ABSENT";
4892 case RADIO_STATE_NV_NOT_READY:return"RADIO_NV_NOT_READY";
4893 case RADIO_STATE_NV_READY:return"RADIO_NV_READY";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004894 case RADIO_STATE_ON:return"RADIO_ON";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004895 default: return "<unknown state>";
4896 }
4897}
4898
4899const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004900callStateToString(RIL_CallState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004901 switch(s) {
4902 case RIL_CALL_ACTIVE : return "ACTIVE";
4903 case RIL_CALL_HOLDING: return "HOLDING";
4904 case RIL_CALL_DIALING: return "DIALING";
4905 case RIL_CALL_ALERTING: return "ALERTING";
4906 case RIL_CALL_INCOMING: return "INCOMING";
4907 case RIL_CALL_WAITING: return "WAITING";
4908 default: return "<unknown state>";
4909 }
4910}
4911
4912const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004913requestToString(int request) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004914/*
4915 cat libs/telephony/ril_commands.h \
4916 | egrep "^ *{RIL_" \
4917 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
4918
4919
4920 cat libs/telephony/ril_unsol_commands.h \
4921 | egrep "^ *{RIL_" \
4922 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
4923
4924*/
4925 switch(request) {
4926 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
4927 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
4928 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
4929 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
4930 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
4931 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
4932 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
4933 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
4934 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
4935 case RIL_REQUEST_DIAL: return "DIAL";
4936 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
4937 case RIL_REQUEST_HANGUP: return "HANGUP";
4938 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
4939 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
4940 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
4941 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
4942 case RIL_REQUEST_UDUB: return "UDUB";
4943 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
4944 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
Wink Savillec0114b32011-02-18 10:14:07 -08004945 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
4946 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004947 case RIL_REQUEST_OPERATOR: return "OPERATOR";
4948 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
4949 case RIL_REQUEST_DTMF: return "DTMF";
4950 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
4951 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
Wink Savillef4c4d362009-04-02 01:37:03 -07004952 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004953 case RIL_REQUEST_SIM_IO: return "SIM_IO";
4954 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
4955 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
4956 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
4957 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
4958 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
4959 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
4960 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
4961 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
4962 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
4963 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
4964 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
4965 case RIL_REQUEST_ANSWER: return "ANSWER";
Wink Savillef4c4d362009-04-02 01:37:03 -07004966 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004967 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
4968 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
4969 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
4970 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
4971 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
4972 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
4973 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";
4974 case RIL_REQUEST_DTMF_START: return "DTMF_START";
4975 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
4976 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
4977 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
4978 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
4979 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
4980 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
4981 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
4982 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
4983 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
Wink Savillef4c4d362009-04-02 01:37:03 -07004984 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
4985 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004986 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
4987 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
4988 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
Wink Savillef4c4d362009-04-02 01:37:03 -07004989 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
4990 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004991 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
4992 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
4993 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
4994 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
4995 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
4996 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
4997 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
4998 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
Wink Savillec0114b32011-02-18 10:14:07 -08004999 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE:return"CDMA_SET_SUBSCRIPTION_SOURCE";
Wink Savillef4c4d362009-04-02 01:37:03 -07005000 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"CDMA_SET_ROAMING_PREFERENCE";
5001 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"CDMA_QUERY_ROAMING_PREFERENCE";
5002 case RIL_REQUEST_SET_TTY_MODE:return"SET_TTY_MODE";
5003 case RIL_REQUEST_QUERY_TTY_MODE:return"QUERY_TTY_MODE";
5004 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
5005 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
5006 case RIL_REQUEST_CDMA_FLASH:return"CDMA_FLASH";
5007 case RIL_REQUEST_CDMA_BURST_DTMF:return"CDMA_BURST_DTMF";
5008 case RIL_REQUEST_CDMA_SEND_SMS:return"CDMA_SEND_SMS";
5009 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:return"CDMA_SMS_ACKNOWLEDGE";
Wink Savillea592eeb2009-05-22 13:26:36 -07005010 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG:return"GSM_GET_BROADCAST_SMS_CONFIG";
5011 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG:return"GSM_SET_BROADCAST_SMS_CONFIG";
5012 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG:return "CDMA_GET_BROADCAST_SMS_CONFIG";
5013 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG:return "CDMA_SET_BROADCAST_SMS_CONFIG";
5014 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION:return "CDMA_SMS_BROADCAST_ACTIVATION";
Naveen Kalla03c1edf2009-09-23 11:18:35 -07005015 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return"CDMA_VALIDATE_AND_WRITE_AKEY";
Wink Savillef4c4d362009-04-02 01:37:03 -07005016 case RIL_REQUEST_CDMA_SUBSCRIPTION: return"CDMA_SUBSCRIPTION";
5017 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
5018 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
5019 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
jsh000a9fe2009-05-11 14:52:35 -07005020 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
5021 case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
5022 case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
jsh09a68ba2009-06-10 11:56:38 -07005023 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
jsh563fd722010-06-08 16:52:24 -07005024 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
Wink Savillec0114b32011-02-18 10:14:07 -08005025 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
Jake Hambyfa8d5842011-08-19 16:22:18 -07005026 case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
Jake Hamby300105d2011-09-26 01:01:44 -07005027 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
5028 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005029 case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
Wink Saville8a9e0212013-04-09 12:11:38 -07005030 case RIL_REQUEST_GET_CELL_INFO_LIST: return"GET_CELL_INFO_LIST";
5031 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return"SET_UNSOL_CELL_INFO_LIST_RATE";
Sungmin Choi75697532013-04-26 15:04:45 -07005032 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "RIL_REQUEST_SET_INITIAL_ATTACH_APN";
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07005033 case RIL_REQUEST_IMS_REGISTRATION_STATE: return "IMS_REGISTRATION_STATE";
5034 case RIL_REQUEST_IMS_SEND_SMS: return "IMS_SEND_SMS";
Shishir Agrawal2458d8d2013-11-27 14:53:05 -08005035 case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "SIM_TRANSMIT_APDU_BASIC";
5036 case RIL_REQUEST_SIM_OPEN_CHANNEL: return "SIM_OPEN_CHANNEL";
5037 case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "SIM_CLOSE_CHANNEL";
5038 case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "SIM_TRANSMIT_APDU_CHANNEL";
Wink Saville8b4e4f72014-10-17 15:01:45 -07005039 case RIL_REQUEST_GET_RADIO_CAPABILITY: return "RIL_REQUEST_GET_RADIO_CAPABILITY";
5040 case RIL_REQUEST_SET_RADIO_CAPABILITY: return "RIL_REQUEST_SET_RADIO_CAPABILITY";
Etan Cohend3652192014-06-20 08:28:44 -07005041 case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "SET_UICC_SUBSCRIPTION";
5042 case RIL_REQUEST_ALLOW_DATA: return "ALLOW_DATA";
Amit Mahajan2b772032014-06-26 14:20:11 -07005043 case RIL_REQUEST_GET_HARDWARE_CONFIG: return "GET_HARDWARE_CONFIG";
5044 case RIL_REQUEST_SIM_AUTHENTICATION: return "SIM_AUTHENTICATION";
Wink Savillec29360a2014-07-13 05:17:28 -07005045 case RIL_REQUEST_GET_DC_RT_INFO: return "GET_DC_RT_INFO";
5046 case RIL_REQUEST_SET_DC_RT_INFO_RATE: return "SET_DC_RT_INFO_RATE";
Amit Mahajanc796e222014-08-13 16:54:01 +00005047 case RIL_REQUEST_SET_DATA_PROFILE: return "SET_DATA_PROFILE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005048 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
5049 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08005050 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 -08005051 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
5052 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
5053 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
5054 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
5055 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)";
5056 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
5057 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
5058 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
5059 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
5060 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
5061 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
5062 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL";
5063 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
Wink Savillef4c4d362009-04-02 01:37:03 -07005064 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005065 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
Wink Savillef4c4d362009-04-02 01:37:03 -07005066 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
5067 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_NEW_CDMA_SMS";
5068 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_NEW_BROADCAST_SMS";
5069 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
Wink Saville3d54e742009-05-18 18:00:44 -07005070 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
5071 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
5072 case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
5073 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
5074 case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
Jaikumar Ganeshaf6ecbf2009-04-29 13:27:51 -07005075 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
John Wang5d621da2009-09-18 17:17:48 -07005076 case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
John Wang5909cf82010-01-29 00:18:54 -08005077 case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
Wink Savilleee274582011-04-16 15:05:49 -07005078 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08005079 case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
5080 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
Wink Saville5b9df332011-04-06 16:24:21 -07005081 case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005082 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
Wink Saville8a9e0212013-04-09 12:11:38 -07005083 case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07005084 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "RESPONSE_IMS_NETWORK_STATE_CHANGED";
Etan Cohend3652192014-06-20 08:28:44 -07005085 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return "UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED";
5086 case RIL_UNSOL_SRVCC_STATE_NOTIFY: return "UNSOL_SRVCC_STATE_NOTIFY";
5087 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return "HARDWARE_CONFIG_CHANGED";
Wink Savillec29360a2014-07-13 05:17:28 -07005088 case RIL_UNSOL_DC_RT_INFO_CHANGED: return "UNSOL_DC_RT_INFO_CHANGED";
Naveen Kallaa65a16a2014-07-31 16:48:31 -07005089 case RIL_REQUEST_SHUTDOWN: return "SHUTDOWN";
Wink Saville8b4e4f72014-10-17 15:01:45 -07005090 case RIL_UNSOL_RADIO_CAPABILITY: return "RIL_UNSOL_RADIO_CAPABILITY";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005091 default: return "<unknown request>";
5092 }
5093}
5094
Etan Cohend3652192014-06-20 08:28:44 -07005095const char *
5096rilSocketIdToString(RIL_SOCKET_ID socket_id)
5097{
5098 switch(socket_id) {
5099 case RIL_SOCKET_1:
5100 return "RIL_SOCKET_1";
5101#if (SIM_COUNT >= 2)
5102 case RIL_SOCKET_2:
5103 return "RIL_SOCKET_2";
5104#endif
5105#if (SIM_COUNT >= 3)
5106 case RIL_SOCKET_3:
5107 return "RIL_SOCKET_3";
5108#endif
5109#if (SIM_COUNT >= 4)
5110 case RIL_SOCKET_4:
5111 return "RIL_SOCKET_4";
5112#endif
5113 default:
5114 return "not a valid RIL";
5115 }
5116}
5117
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005118} /* namespace android */
Dheeraj Shetty27976c42014-07-02 21:27:57 +02005119
5120void rilEventAddWakeup_helper(struct ril_event *ev) {
5121 android::rilEventAddWakeup(ev);
5122}
5123
5124void listenCallback_helper(int fd, short flags, void *param) {
5125 android::listenCallback(fd, flags, param);
5126}
5127
5128int blockingWrite_helper(int fd, void *buffer, size_t len) {
5129 return android::blockingWrite(fd, buffer, len);
5130}