blob: 32c4376e3797e734b9cbc329953888e4e7e54e7e [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);
Prerepa Viswanadham73157492015-05-28 00:37:32 -0700302static int responseActivityData(Parcel &p, void *response, size_t responselen);
Amit Mahajan54563d32014-11-22 00:54:49 +0000303
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800304static int decodeVoiceRadioTechnology (RIL_RadioState radioState);
305static int decodeCdmaSubscriptionSource (RIL_RadioState radioState);
306static RIL_RadioState processRadioState(RIL_RadioState newRadioState);
307
Amit Mahajan54563d32014-11-22 00:54:49 +0000308static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType);
309
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800310#ifdef RIL_SHLIB
Etan Cohend3652192014-06-20 08:28:44 -0700311#if defined(ANDROID_MULTI_SIM)
Vinit Deshpande1b1ec2d2015-04-15 13:31:05 -0700312extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Etan Cohend3652192014-06-20 08:28:44 -0700313 size_t datalen, RIL_SOCKET_ID socket_id);
314#else
Vinit Deshpande1b1ec2d2015-04-15 13:31:05 -0700315extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800316 size_t datalen);
317#endif
Etan Cohend3652192014-06-20 08:28:44 -0700318#endif
319
320#if defined(ANDROID_MULTI_SIM)
321#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c), (d))
322#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d), (e))
323#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest(a)
324#else
325#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c))
326#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d))
327#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest()
328#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800329
Wink Saville7f856802009-06-09 10:23:37 -0700330static UserCallbackInfo * internalRequestTimedCallback
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -0700331 (RIL_TimedCallback callback, void *param,
332 const struct timeval *relativeTime);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800333
334/** Index == requestNumber */
335static CommandInfo s_commands[] = {
336#include "ril_commands.h"
337};
338
339static UnsolResponseInfo s_unsolResponses[] = {
340#include "ril_unsol_commands.h"
341};
342
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800343/* For older RILs that do not support new commands RIL_REQUEST_VOICE_RADIO_TECH and
344 RIL_UNSOL_VOICE_RADIO_TECH_CHANGED messages, decode the voice radio tech from
345 radio state message and store it. Every time there is a change in Radio State
346 check to see if voice radio tech changes and notify telephony
347 */
348int voiceRadioTech = -1;
349
350/* For older RILs that do not support new commands RIL_REQUEST_GET_CDMA_SUBSCRIPTION_SOURCE
351 and RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED messages, decode the subscription
352 source from radio state and store it. Every time there is a change in Radio State
353 check to see if subscription source changed and notify telephony
354 */
355int cdmaSubscriptionSource = -1;
356
357/* For older RILs that do not send RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, decode the
358 SIM/RUIM state from radio state and store it. Every time there is a change in Radio State,
359 check to see if SIM/RUIM status changed and notify telephony
360 */
361int simRuimStatus = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800362
Etan Cohend3652192014-06-20 08:28:44 -0700363static char * RIL_getRilSocketName() {
364 return rild;
365}
366
367extern "C"
Dheeraj Shetty27976c42014-07-02 21:27:57 +0200368void RIL_setRilSocketName(const char * s) {
Etan Cohend3652192014-06-20 08:28:44 -0700369 strncpy(rild, s, MAX_SOCKET_NAME_LENGTH);
370}
371
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800372static char *
Wink Savillef4c4d362009-04-02 01:37:03 -0700373strdupReadString(Parcel &p) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800374 size_t stringlen;
375 const char16_t *s16;
Wink Saville7f856802009-06-09 10:23:37 -0700376
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800377 s16 = p.readString16Inplace(&stringlen);
Wink Saville7f856802009-06-09 10:23:37 -0700378
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800379 return strndup16to8(s16, stringlen);
380}
381
Wink Saville8b4e4f72014-10-17 15:01:45 -0700382static status_t
383readStringFromParcelInplace(Parcel &p, char *str, size_t maxLen) {
384 size_t s16Len;
385 const char16_t *s16;
386
387 s16 = p.readString16Inplace(&s16Len);
388 if (s16 == NULL) {
389 return NO_MEMORY;
390 }
391 size_t strLen = strnlen16to8(s16, s16Len);
392 if ((strLen + 1) > maxLen) {
393 return NO_MEMORY;
394 }
395 if (strncpy16to8(str, s16, strLen) == NULL) {
396 return NO_MEMORY;
397 } else {
398 return NO_ERROR;
399 }
400}
401
Wink Savillef4c4d362009-04-02 01:37:03 -0700402static void writeStringToParcel(Parcel &p, const char *s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800403 char16_t *s16;
404 size_t s16_len;
405 s16 = strdup8to16(s, &s16_len);
406 p.writeString16(s16, s16_len);
407 free(s16);
408}
409
410
411static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700412memsetString (char *s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800413 if (s != NULL) {
414 memset (s, 0, strlen(s));
415 }
416}
417
418void nullParcelReleaseFunction (const uint8_t* data, size_t dataSize,
419 const size_t* objects, size_t objectsSize,
Wink Savillef4c4d362009-04-02 01:37:03 -0700420 void* cookie) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800421 // do nothing -- the data reference lives longer than the Parcel object
422}
423
Wink Saville7f856802009-06-09 10:23:37 -0700424/**
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800425 * To be called from dispatch thread
426 * Issue a single local request, ensuring that the response
Wink Saville7f856802009-06-09 10:23:37 -0700427 * is not sent back up to the command process
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800428 */
429static void
Etan Cohend3652192014-06-20 08:28:44 -0700430issueLocalRequest(int request, void *data, int len, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800431 RequestInfo *pRI;
432 int ret;
Etan Cohend3652192014-06-20 08:28:44 -0700433 /* Hook for current context */
434 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
435 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
436 /* pendingRequestsHook refer to &s_pendingRequests */
437 RequestInfo** pendingRequestsHook = &s_pendingRequests;
438
439#if (SIM_COUNT == 2)
440 if (socket_id == RIL_SOCKET_2) {
441 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
442 pendingRequestsHook = &s_pendingRequests_socket2;
443 }
444#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800445
446 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
447
448 pRI->local = 1;
449 pRI->token = 0xffffffff; // token is not used in this context
450 pRI->pCI = &(s_commands[request]);
Etan Cohend3652192014-06-20 08:28:44 -0700451 pRI->socket_id = socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800452
Etan Cohend3652192014-06-20 08:28:44 -0700453 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800454 assert (ret == 0);
455
Etan Cohend3652192014-06-20 08:28:44 -0700456 pRI->p_next = *pendingRequestsHook;
457 *pendingRequestsHook = pRI;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800458
Etan Cohend3652192014-06-20 08:28:44 -0700459 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800460 assert (ret == 0);
461
Wink Saville8eb2a122012-11-19 16:05:13 -0800462 RLOGD("C[locl]> %s", requestToString(request));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800463
Etan Cohend3652192014-06-20 08:28:44 -0700464 CALL_ONREQUEST(request, data, len, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800465}
466
467
468
469static int
Etan Cohend3652192014-06-20 08:28:44 -0700470processCommandBuffer(void *buffer, size_t buflen, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800471 Parcel p;
472 status_t status;
473 int32_t request;
474 int32_t token;
475 RequestInfo *pRI;
476 int ret;
Etan Cohend3652192014-06-20 08:28:44 -0700477 /* Hook for current context */
478 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
479 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
480 /* pendingRequestsHook refer to &s_pendingRequests */
481 RequestInfo** pendingRequestsHook = &s_pendingRequests;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800482
483 p.setData((uint8_t *) buffer, buflen);
484
485 // status checked at end
486 status = p.readInt32(&request);
487 status = p.readInt32 (&token);
488
Etan Cohend3652192014-06-20 08:28:44 -0700489#if (SIM_COUNT >= 2)
490 if (socket_id == RIL_SOCKET_2) {
491 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
492 pendingRequestsHook = &s_pendingRequests_socket2;
493 }
494#if (SIM_COUNT >= 3)
495 else if (socket_id == RIL_SOCKET_3) {
496 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
497 pendingRequestsHook = &s_pendingRequests_socket3;
498 }
499#endif
500#if (SIM_COUNT >= 4)
501 else if (socket_id == RIL_SOCKET_4) {
502 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
503 pendingRequestsHook = &s_pendingRequests_socket4;
504 }
505#endif
506#endif
507
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800508 if (status != NO_ERROR) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800509 RLOGE("invalid request block");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800510 return 0;
511 }
512
513 if (request < 1 || request >= (int32_t)NUM_ELEMS(s_commands)) {
Etan Cohend3652192014-06-20 08:28:44 -0700514 Parcel pErr;
Wink Saville8eb2a122012-11-19 16:05:13 -0800515 RLOGE("unsupported request code %d token %d", request, token);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800516 // FIXME this should perhaps return a response
Etan Cohend3652192014-06-20 08:28:44 -0700517 pErr.writeInt32 (RESPONSE_SOLICITED);
518 pErr.writeInt32 (token);
519 pErr.writeInt32 (RIL_E_GENERIC_FAILURE);
520
521 sendResponse(pErr, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800522 return 0;
523 }
524
525
526 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
527
528 pRI->token = token;
529 pRI->pCI = &(s_commands[request]);
Etan Cohend3652192014-06-20 08:28:44 -0700530 pRI->socket_id = socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800531
Etan Cohend3652192014-06-20 08:28:44 -0700532 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800533 assert (ret == 0);
534
Etan Cohend3652192014-06-20 08:28:44 -0700535 pRI->p_next = *pendingRequestsHook;
536 *pendingRequestsHook = pRI;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800537
Etan Cohend3652192014-06-20 08:28:44 -0700538 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800539 assert (ret == 0);
540
541/* sLastDispatchedToken = token; */
542
Wink Saville7f856802009-06-09 10:23:37 -0700543 pRI->pCI->dispatchFunction(p, pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800544
545 return 0;
546}
547
548static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700549invalidCommandBlock (RequestInfo *pRI) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800550 RLOGE("invalid command block for token %d request %s",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800551 pRI->token, requestToString(pRI->pCI->requestNumber));
552}
553
554/** Callee expects NULL */
Wink Saville7f856802009-06-09 10:23:37 -0700555static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700556dispatchVoid (Parcel& p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800557 clearPrintBuf;
558 printRequest(pRI->token, pRI->pCI->requestNumber);
Etan Cohend3652192014-06-20 08:28:44 -0700559 CALL_ONREQUEST(pRI->pCI->requestNumber, NULL, 0, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800560}
561
562/** Callee expects const char * */
563static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700564dispatchString (Parcel& p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800565 status_t status;
566 size_t datalen;
567 size_t stringlen;
568 char *string8 = NULL;
569
570 string8 = strdupReadString(p);
571
572 startRequest;
573 appendPrintBuf("%s%s", printBuf, string8);
574 closeRequest;
575 printRequest(pRI->token, pRI->pCI->requestNumber);
576
Etan Cohend3652192014-06-20 08:28:44 -0700577 CALL_ONREQUEST(pRI->pCI->requestNumber, string8,
578 sizeof(char *), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800579
580#ifdef MEMSET_FREED
581 memsetString(string8);
582#endif
583
584 free(string8);
585 return;
586invalid:
587 invalidCommandBlock(pRI);
588 return;
589}
590
591/** Callee expects const char ** */
592static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700593dispatchStrings (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800594 int32_t countStrings;
595 status_t status;
596 size_t datalen;
597 char **pStrings;
598
599 status = p.readInt32 (&countStrings);
600
601 if (status != NO_ERROR) {
602 goto invalid;
603 }
604
605 startRequest;
606 if (countStrings == 0) {
607 // just some non-null pointer
608 pStrings = (char **)alloca(sizeof(char *));
609 datalen = 0;
610 } else if (((int)countStrings) == -1) {
611 pStrings = NULL;
612 datalen = 0;
613 } else {
614 datalen = sizeof(char *) * countStrings;
Wink Saville7f856802009-06-09 10:23:37 -0700615
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800616 pStrings = (char **)alloca(datalen);
617
618 for (int i = 0 ; i < countStrings ; i++) {
619 pStrings[i] = strdupReadString(p);
620 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
621 }
622 }
623 removeLastChar;
624 closeRequest;
625 printRequest(pRI->token, pRI->pCI->requestNumber);
626
Etan Cohend3652192014-06-20 08:28:44 -0700627 CALL_ONREQUEST(pRI->pCI->requestNumber, pStrings, datalen, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800628
629 if (pStrings != NULL) {
630 for (int i = 0 ; i < countStrings ; i++) {
631#ifdef MEMSET_FREED
632 memsetString (pStrings[i]);
633#endif
634 free(pStrings[i]);
635 }
636
637#ifdef MEMSET_FREED
638 memset(pStrings, 0, datalen);
639#endif
640 }
Wink Saville7f856802009-06-09 10:23:37 -0700641
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800642 return;
643invalid:
644 invalidCommandBlock(pRI);
645 return;
646}
647
648/** Callee expects const int * */
649static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700650dispatchInts (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800651 int32_t count;
652 status_t status;
653 size_t datalen;
654 int *pInts;
655
656 status = p.readInt32 (&count);
657
658 if (status != NO_ERROR || count == 0) {
659 goto invalid;
660 }
661
662 datalen = sizeof(int) * count;
663 pInts = (int *)alloca(datalen);
664
665 startRequest;
666 for (int i = 0 ; i < count ; i++) {
667 int32_t t;
668
669 status = p.readInt32(&t);
670 pInts[i] = (int)t;
671 appendPrintBuf("%s%d,", printBuf, t);
672
673 if (status != NO_ERROR) {
674 goto invalid;
675 }
676 }
677 removeLastChar;
678 closeRequest;
679 printRequest(pRI->token, pRI->pCI->requestNumber);
680
Etan Cohend3652192014-06-20 08:28:44 -0700681 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<int *>(pInts),
682 datalen, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800683
684#ifdef MEMSET_FREED
685 memset(pInts, 0, datalen);
686#endif
687
688 return;
689invalid:
690 invalidCommandBlock(pRI);
691 return;
692}
693
694
Wink Saville7f856802009-06-09 10:23:37 -0700695/**
696 * Callee expects const RIL_SMS_WriteArgs *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800697 * Payload is:
698 * int32_t status
699 * String pdu
700 */
701static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700702dispatchSmsWrite (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800703 RIL_SMS_WriteArgs args;
704 int32_t t;
705 status_t status;
706
Mark Salyzyndba25612015-04-09 07:18:35 -0700707 RLOGD("dispatchSmsWrite");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800708 memset (&args, 0, sizeof(args));
709
710 status = p.readInt32(&t);
711 args.status = (int)t;
712
713 args.pdu = strdupReadString(p);
714
715 if (status != NO_ERROR || args.pdu == NULL) {
716 goto invalid;
717 }
718
719 args.smsc = strdupReadString(p);
720
721 startRequest;
722 appendPrintBuf("%s%d,%s,smsc=%s", printBuf, args.status,
723 (char*)args.pdu, (char*)args.smsc);
724 closeRequest;
725 printRequest(pRI->token, pRI->pCI->requestNumber);
Wink Saville7f856802009-06-09 10:23:37 -0700726
Etan Cohend3652192014-06-20 08:28:44 -0700727 CALL_ONREQUEST(pRI->pCI->requestNumber, &args, sizeof(args), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800728
729#ifdef MEMSET_FREED
730 memsetString (args.pdu);
731#endif
732
733 free (args.pdu);
Wink Saville7f856802009-06-09 10:23:37 -0700734
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800735#ifdef MEMSET_FREED
736 memset(&args, 0, sizeof(args));
737#endif
738
739 return;
740invalid:
741 invalidCommandBlock(pRI);
742 return;
743}
744
Wink Saville7f856802009-06-09 10:23:37 -0700745/**
746 * Callee expects const RIL_Dial *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800747 * Payload is:
748 * String address
749 * int32_t clir
750 */
751static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700752dispatchDial (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800753 RIL_Dial dial;
Wink Saville74fa3882009-12-22 15:35:41 -0800754 RIL_UUS_Info uusInfo;
Wink Saville7bce0822010-01-08 15:20:12 -0800755 int32_t sizeOfDial;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800756 int32_t t;
Wink Saville74fa3882009-12-22 15:35:41 -0800757 int32_t uusPresent;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800758 status_t status;
759
Mark Salyzyndba25612015-04-09 07:18:35 -0700760 RLOGD("dispatchDial");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800761 memset (&dial, 0, sizeof(dial));
762
763 dial.address = strdupReadString(p);
764
765 status = p.readInt32(&t);
766 dial.clir = (int)t;
767
768 if (status != NO_ERROR || dial.address == NULL) {
769 goto invalid;
770 }
771
Wink Saville3a4840b2010-04-07 13:29:58 -0700772 if (s_callbacks.version < 3) { // Remove when partners upgrade to version 3
Wink Saville74fa3882009-12-22 15:35:41 -0800773 uusPresent = 0;
Wink Saville7bce0822010-01-08 15:20:12 -0800774 sizeOfDial = sizeof(dial) - sizeof(RIL_UUS_Info *);
Wink Saville74fa3882009-12-22 15:35:41 -0800775 } else {
776 status = p.readInt32(&uusPresent);
777
778 if (status != NO_ERROR) {
779 goto invalid;
780 }
781
782 if (uusPresent == 0) {
783 dial.uusInfo = NULL;
784 } else {
785 int32_t len;
786
787 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
788
789 status = p.readInt32(&t);
790 uusInfo.uusType = (RIL_UUS_Type) t;
791
792 status = p.readInt32(&t);
793 uusInfo.uusDcs = (RIL_UUS_DCS) t;
794
795 status = p.readInt32(&len);
796 if (status != NO_ERROR) {
797 goto invalid;
798 }
799
800 // The java code writes -1 for null arrays
801 if (((int) len) == -1) {
802 uusInfo.uusData = NULL;
803 len = 0;
804 } else {
805 uusInfo.uusData = (char*) p.readInplace(len);
806 }
807
808 uusInfo.uusLength = len;
809 dial.uusInfo = &uusInfo;
810 }
Wink Saville7bce0822010-01-08 15:20:12 -0800811 sizeOfDial = sizeof(dial);
Wink Saville74fa3882009-12-22 15:35:41 -0800812 }
813
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800814 startRequest;
815 appendPrintBuf("%snum=%s,clir=%d", printBuf, dial.address, dial.clir);
Wink Saville74fa3882009-12-22 15:35:41 -0800816 if (uusPresent) {
817 appendPrintBuf("%s,uusType=%d,uusDcs=%d,uusLen=%d", printBuf,
818 dial.uusInfo->uusType, dial.uusInfo->uusDcs,
819 dial.uusInfo->uusLength);
820 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800821 closeRequest;
822 printRequest(pRI->token, pRI->pCI->requestNumber);
823
Etan Cohend3652192014-06-20 08:28:44 -0700824 CALL_ONREQUEST(pRI->pCI->requestNumber, &dial, sizeOfDial, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800825
826#ifdef MEMSET_FREED
827 memsetString (dial.address);
828#endif
829
830 free (dial.address);
Wink Saville7f856802009-06-09 10:23:37 -0700831
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800832#ifdef MEMSET_FREED
Wink Saville74fa3882009-12-22 15:35:41 -0800833 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800834 memset(&dial, 0, sizeof(dial));
835#endif
836
837 return;
838invalid:
839 invalidCommandBlock(pRI);
840 return;
841}
842
Wink Saville7f856802009-06-09 10:23:37 -0700843/**
844 * Callee expects const RIL_SIM_IO *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800845 * Payload is:
846 * int32_t command
847 * int32_t fileid
848 * String path
849 * int32_t p1, p2, p3
Wink Saville7f856802009-06-09 10:23:37 -0700850 * String data
851 * String pin2
Wink Savillec0114b32011-02-18 10:14:07 -0800852 * String aidPtr
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800853 */
854static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700855dispatchSIM_IO (Parcel &p, RequestInfo *pRI) {
Wink Savillec0114b32011-02-18 10:14:07 -0800856 union RIL_SIM_IO {
857 RIL_SIM_IO_v6 v6;
858 RIL_SIM_IO_v5 v5;
859 } simIO;
860
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800861 int32_t t;
Wink Savillec0114b32011-02-18 10:14:07 -0800862 int size;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800863 status_t status;
864
Robert Greenwalt191e4dc2015-04-29 16:57:39 -0700865#if VDBG
Mark Salyzyndba25612015-04-09 07:18:35 -0700866 RLOGD("dispatchSIM_IO");
Robert Greenwalt191e4dc2015-04-29 16:57:39 -0700867#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800868 memset (&simIO, 0, sizeof(simIO));
869
Wink Saville7f856802009-06-09 10:23:37 -0700870 // note we only check status at the end
871
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800872 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800873 simIO.v6.command = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800874
875 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800876 simIO.v6.fileid = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800877
Wink Savillec0114b32011-02-18 10:14:07 -0800878 simIO.v6.path = strdupReadString(p);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800879
880 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800881 simIO.v6.p1 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800882
883 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800884 simIO.v6.p2 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800885
886 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800887 simIO.v6.p3 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800888
Wink Savillec0114b32011-02-18 10:14:07 -0800889 simIO.v6.data = strdupReadString(p);
890 simIO.v6.pin2 = strdupReadString(p);
891 simIO.v6.aidPtr = strdupReadString(p);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800892
893 startRequest;
Wink Savillec0114b32011-02-18 10:14:07 -0800894 appendPrintBuf("%scmd=0x%X,efid=0x%X,path=%s,%d,%d,%d,%s,pin2=%s,aid=%s", printBuf,
895 simIO.v6.command, simIO.v6.fileid, (char*)simIO.v6.path,
896 simIO.v6.p1, simIO.v6.p2, simIO.v6.p3,
897 (char*)simIO.v6.data, (char*)simIO.v6.pin2, simIO.v6.aidPtr);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800898 closeRequest;
899 printRequest(pRI->token, pRI->pCI->requestNumber);
Wink Saville7f856802009-06-09 10:23:37 -0700900
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800901 if (status != NO_ERROR) {
902 goto invalid;
903 }
904
Wink Savillec0114b32011-02-18 10:14:07 -0800905 size = (s_callbacks.version < 6) ? sizeof(simIO.v5) : sizeof(simIO.v6);
Etan Cohend3652192014-06-20 08:28:44 -0700906 CALL_ONREQUEST(pRI->pCI->requestNumber, &simIO, size, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800907
908#ifdef MEMSET_FREED
Wink Savillec0114b32011-02-18 10:14:07 -0800909 memsetString (simIO.v6.path);
910 memsetString (simIO.v6.data);
911 memsetString (simIO.v6.pin2);
912 memsetString (simIO.v6.aidPtr);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800913#endif
914
Wink Savillec0114b32011-02-18 10:14:07 -0800915 free (simIO.v6.path);
916 free (simIO.v6.data);
917 free (simIO.v6.pin2);
918 free (simIO.v6.aidPtr);
Wink Saville7f856802009-06-09 10:23:37 -0700919
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800920#ifdef MEMSET_FREED
921 memset(&simIO, 0, sizeof(simIO));
922#endif
923
924 return;
925invalid:
926 invalidCommandBlock(pRI);
927 return;
928}
929
930/**
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800931 * Callee expects const RIL_SIM_APDU *
932 * Payload is:
933 * int32_t sessionid
934 * int32_t cla
935 * int32_t instruction
936 * int32_t p1, p2, p3
937 * String data
938 */
939static void
940dispatchSIM_APDU (Parcel &p, RequestInfo *pRI) {
941 int32_t t;
942 status_t status;
943 RIL_SIM_APDU apdu;
944
Robert Greenwalt191e4dc2015-04-29 16:57:39 -0700945#if VDBG
Mark Salyzyndba25612015-04-09 07:18:35 -0700946 RLOGD("dispatchSIM_APDU");
Robert Greenwalt191e4dc2015-04-29 16:57:39 -0700947#endif
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800948 memset (&apdu, 0, sizeof(RIL_SIM_APDU));
949
950 // Note we only check status at the end. Any single failure leads to
951 // subsequent reads filing.
952 status = p.readInt32(&t);
953 apdu.sessionid = (int)t;
954
955 status = p.readInt32(&t);
956 apdu.cla = (int)t;
957
958 status = p.readInt32(&t);
959 apdu.instruction = (int)t;
960
961 status = p.readInt32(&t);
962 apdu.p1 = (int)t;
963
964 status = p.readInt32(&t);
965 apdu.p2 = (int)t;
966
967 status = p.readInt32(&t);
968 apdu.p3 = (int)t;
969
970 apdu.data = strdupReadString(p);
971
972 startRequest;
973 appendPrintBuf("%ssessionid=%d,cla=%d,ins=%d,p1=%d,p2=%d,p3=%d,data=%s",
974 printBuf, apdu.sessionid, apdu.cla, apdu.instruction, apdu.p1, apdu.p2,
975 apdu.p3, (char*)apdu.data);
976 closeRequest;
977 printRequest(pRI->token, pRI->pCI->requestNumber);
978
979 if (status != NO_ERROR) {
980 goto invalid;
981 }
982
Etan Cohend3652192014-06-20 08:28:44 -0700983 CALL_ONREQUEST(pRI->pCI->requestNumber, &apdu, sizeof(RIL_SIM_APDU), pRI, pRI->socket_id);
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800984
985#ifdef MEMSET_FREED
986 memsetString(apdu.data);
987#endif
988 free(apdu.data);
989
990#ifdef MEMSET_FREED
991 memset(&apdu, 0, sizeof(RIL_SIM_APDU));
992#endif
993
994 return;
995invalid:
996 invalidCommandBlock(pRI);
997 return;
998}
999
1000
1001/**
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001002 * Callee expects const RIL_CallForwardInfo *
1003 * Payload is:
1004 * int32_t status/action
1005 * int32_t reason
1006 * int32_t serviceCode
1007 * int32_t toa
1008 * String number (0 length -> null)
1009 * int32_t timeSeconds
1010 */
Wink Saville7f856802009-06-09 10:23:37 -07001011static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001012dispatchCallForward(Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001013 RIL_CallForwardInfo cff;
1014 int32_t t;
1015 status_t status;
1016
Mark Salyzyndba25612015-04-09 07:18:35 -07001017 RLOGD("dispatchCallForward");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001018 memset (&cff, 0, sizeof(cff));
1019
Wink Saville7f856802009-06-09 10:23:37 -07001020 // note we only check status at the end
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001021
1022 status = p.readInt32(&t);
1023 cff.status = (int)t;
Wink Saville7f856802009-06-09 10:23:37 -07001024
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001025 status = p.readInt32(&t);
1026 cff.reason = (int)t;
1027
1028 status = p.readInt32(&t);
1029 cff.serviceClass = (int)t;
1030
1031 status = p.readInt32(&t);
1032 cff.toa = (int)t;
1033
1034 cff.number = strdupReadString(p);
1035
1036 status = p.readInt32(&t);
1037 cff.timeSeconds = (int)t;
1038
1039 if (status != NO_ERROR) {
1040 goto invalid;
1041 }
1042
1043 // special case: number 0-length fields is null
1044
1045 if (cff.number != NULL && strlen (cff.number) == 0) {
1046 cff.number = NULL;
1047 }
1048
1049 startRequest;
1050 appendPrintBuf("%sstat=%d,reason=%d,serv=%d,toa=%d,%s,tout=%d", printBuf,
1051 cff.status, cff.reason, cff.serviceClass, cff.toa,
1052 (char*)cff.number, cff.timeSeconds);
1053 closeRequest;
1054 printRequest(pRI->token, pRI->pCI->requestNumber);
1055
Etan Cohend3652192014-06-20 08:28:44 -07001056 CALL_ONREQUEST(pRI->pCI->requestNumber, &cff, sizeof(cff), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001057
1058#ifdef MEMSET_FREED
1059 memsetString(cff.number);
1060#endif
1061
1062 free (cff.number);
1063
1064#ifdef MEMSET_FREED
1065 memset(&cff, 0, sizeof(cff));
1066#endif
1067
1068 return;
1069invalid:
1070 invalidCommandBlock(pRI);
1071 return;
1072}
1073
1074
Wink Saville7f856802009-06-09 10:23:37 -07001075static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001076dispatchRaw(Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001077 int32_t len;
1078 status_t status;
1079 const void *data;
1080
1081 status = p.readInt32(&len);
1082
1083 if (status != NO_ERROR) {
1084 goto invalid;
1085 }
1086
1087 // The java code writes -1 for null arrays
1088 if (((int)len) == -1) {
1089 data = NULL;
1090 len = 0;
Wink Saville7f856802009-06-09 10:23:37 -07001091 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001092
1093 data = p.readInplace(len);
1094
1095 startRequest;
1096 appendPrintBuf("%sraw_size=%d", printBuf, len);
1097 closeRequest;
1098 printRequest(pRI->token, pRI->pCI->requestNumber);
1099
Etan Cohend3652192014-06-20 08:28:44 -07001100 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<void *>(data), len, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001101
1102 return;
1103invalid:
1104 invalidCommandBlock(pRI);
1105 return;
1106}
1107
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001108static status_t
1109constructCdmaSms(Parcel &p, RequestInfo *pRI, RIL_CDMA_SMS_Message& rcsm) {
Wink Savillef4c4d362009-04-02 01:37:03 -07001110 int32_t t;
1111 uint8_t ut;
1112 status_t status;
1113 int32_t digitCount;
1114 int digitLimit;
Wink Saville7f856802009-06-09 10:23:37 -07001115
Wink Savillef4c4d362009-04-02 01:37:03 -07001116 memset(&rcsm, 0, sizeof(rcsm));
1117
1118 status = p.readInt32(&t);
1119 rcsm.uTeleserviceID = (int) t;
1120
1121 status = p.read(&ut,sizeof(ut));
1122 rcsm.bIsServicePresent = (uint8_t) ut;
1123
1124 status = p.readInt32(&t);
1125 rcsm.uServicecategory = (int) t;
1126
1127 status = p.readInt32(&t);
1128 rcsm.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1129
1130 status = p.readInt32(&t);
1131 rcsm.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1132
1133 status = p.readInt32(&t);
1134 rcsm.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1135
1136 status = p.readInt32(&t);
1137 rcsm.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1138
1139 status = p.read(&ut,sizeof(ut));
1140 rcsm.sAddress.number_of_digits= (uint8_t) ut;
1141
1142 digitLimit= MIN((rcsm.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
1143 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1144 status = p.read(&ut,sizeof(ut));
1145 rcsm.sAddress.digits[digitCount] = (uint8_t) ut;
1146 }
1147
Wink Saville7f856802009-06-09 10:23:37 -07001148 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001149 rcsm.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1150
Wink Saville7f856802009-06-09 10:23:37 -07001151 status = p.read(&ut,sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001152 rcsm.sSubAddress.odd = (uint8_t) ut;
1153
1154 status = p.read(&ut,sizeof(ut));
1155 rcsm.sSubAddress.number_of_digits = (uint8_t) ut;
1156
1157 digitLimit= MIN((rcsm.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
Wink Saville7f856802009-06-09 10:23:37 -07001158 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1159 status = p.read(&ut,sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001160 rcsm.sSubAddress.digits[digitCount] = (uint8_t) ut;
1161 }
1162
Wink Saville7f856802009-06-09 10:23:37 -07001163 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001164 rcsm.uBearerDataLen = (int) t;
1165
1166 digitLimit= MIN((rcsm.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
Wink Saville7f856802009-06-09 10:23:37 -07001167 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1168 status = p.read(&ut, sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001169 rcsm.aBearerData[digitCount] = (uint8_t) ut;
1170 }
1171
1172 if (status != NO_ERROR) {
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001173 return status;
Wink Savillef4c4d362009-04-02 01:37:03 -07001174 }
1175
1176 startRequest;
1177 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
Wink Saville1b5fd232009-04-22 14:50:00 -07001178 sAddress.digit_mode=%d, sAddress.Number_mode=%d, sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07001179 printBuf, rcsm.uTeleserviceID,rcsm.bIsServicePresent,rcsm.uServicecategory,
Wink Saville1b5fd232009-04-22 14:50:00 -07001180 rcsm.sAddress.digit_mode, rcsm.sAddress.number_mode,rcsm.sAddress.number_type);
Wink Savillef4c4d362009-04-02 01:37:03 -07001181 closeRequest;
Wink Saville7f856802009-06-09 10:23:37 -07001182
Wink Savillef4c4d362009-04-02 01:37:03 -07001183 printRequest(pRI->token, pRI->pCI->requestNumber);
1184
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001185 return status;
1186}
1187
1188static void
1189dispatchCdmaSms(Parcel &p, RequestInfo *pRI) {
1190 RIL_CDMA_SMS_Message rcsm;
1191
Mark Salyzyndba25612015-04-09 07:18:35 -07001192 RLOGD("dispatchCdmaSms");
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001193 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1194 goto invalid;
1195 }
1196
Etan Cohend3652192014-06-20 08:28:44 -07001197 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001198
1199#ifdef MEMSET_FREED
1200 memset(&rcsm, 0, sizeof(rcsm));
1201#endif
1202
1203 return;
1204
1205invalid:
1206 invalidCommandBlock(pRI);
1207 return;
1208}
1209
Wink Saville7f856802009-06-09 10:23:37 -07001210static void
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001211dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1212 RIL_IMS_SMS_Message rism;
1213 RIL_CDMA_SMS_Message rcsm;
1214
Mark Salyzyndba25612015-04-09 07:18:35 -07001215 RLOGD("dispatchImsCdmaSms: retry=%d, messageRef=%d", retry, messageRef);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001216
1217 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1218 goto invalid;
1219 }
1220 memset(&rism, 0, sizeof(rism));
1221 rism.tech = RADIO_TECH_3GPP2;
1222 rism.retry = retry;
1223 rism.messageRef = messageRef;
1224 rism.message.cdmaMessage = &rcsm;
1225
Etan Cohend3652192014-06-20 08:28:44 -07001226 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001227 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Etan Cohend3652192014-06-20 08:28:44 -07001228 +sizeof(rcsm),pRI, pRI->socket_id);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001229
1230#ifdef MEMSET_FREED
1231 memset(&rcsm, 0, sizeof(rcsm));
1232 memset(&rism, 0, sizeof(rism));
1233#endif
1234
1235 return;
1236
1237invalid:
1238 invalidCommandBlock(pRI);
1239 return;
1240}
1241
1242static void
1243dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1244 RIL_IMS_SMS_Message rism;
1245 int32_t countStrings;
1246 status_t status;
1247 size_t datalen;
1248 char **pStrings;
Mark Salyzyndba25612015-04-09 07:18:35 -07001249 RLOGD("dispatchImsGsmSms: retry=%d, messageRef=%d", retry, messageRef);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001250
1251 status = p.readInt32 (&countStrings);
1252
1253 if (status != NO_ERROR) {
1254 goto invalid;
1255 }
1256
1257 memset(&rism, 0, sizeof(rism));
1258 rism.tech = RADIO_TECH_3GPP;
1259 rism.retry = retry;
1260 rism.messageRef = messageRef;
1261
1262 startRequest;
Etan Cohen5d891b72014-02-27 17:25:17 -08001263 appendPrintBuf("%stech=%d, retry=%d, messageRef=%d, ", printBuf,
1264 (int)rism.tech, (int)rism.retry, rism.messageRef);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001265 if (countStrings == 0) {
1266 // just some non-null pointer
1267 pStrings = (char **)alloca(sizeof(char *));
1268 datalen = 0;
1269 } else if (((int)countStrings) == -1) {
1270 pStrings = NULL;
1271 datalen = 0;
1272 } else {
1273 datalen = sizeof(char *) * countStrings;
1274
1275 pStrings = (char **)alloca(datalen);
1276
1277 for (int i = 0 ; i < countStrings ; i++) {
1278 pStrings[i] = strdupReadString(p);
1279 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
1280 }
1281 }
1282 removeLastChar;
1283 closeRequest;
1284 printRequest(pRI->token, pRI->pCI->requestNumber);
1285
1286 rism.message.gsmMessage = pStrings;
Etan Cohend3652192014-06-20 08:28:44 -07001287 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001288 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Etan Cohend3652192014-06-20 08:28:44 -07001289 +datalen, pRI, pRI->socket_id);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001290
1291 if (pStrings != NULL) {
1292 for (int i = 0 ; i < countStrings ; i++) {
1293#ifdef MEMSET_FREED
1294 memsetString (pStrings[i]);
1295#endif
1296 free(pStrings[i]);
1297 }
1298
1299#ifdef MEMSET_FREED
1300 memset(pStrings, 0, datalen);
1301#endif
1302 }
1303
1304#ifdef MEMSET_FREED
1305 memset(&rism, 0, sizeof(rism));
1306#endif
1307 return;
1308invalid:
1309 ALOGE("dispatchImsGsmSms invalid block");
1310 invalidCommandBlock(pRI);
1311 return;
1312}
1313
1314static void
1315dispatchImsSms(Parcel &p, RequestInfo *pRI) {
1316 int32_t t;
1317 status_t status = p.readInt32(&t);
1318 RIL_RadioTechnologyFamily format;
1319 uint8_t retry;
1320 int32_t messageRef;
1321
Mark Salyzyndba25612015-04-09 07:18:35 -07001322 RLOGD("dispatchImsSms");
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001323 if (status != NO_ERROR) {
1324 goto invalid;
1325 }
1326 format = (RIL_RadioTechnologyFamily) t;
1327
1328 // read retry field
1329 status = p.read(&retry,sizeof(retry));
1330 if (status != NO_ERROR) {
1331 goto invalid;
1332 }
1333 // read messageRef field
1334 status = p.read(&messageRef,sizeof(messageRef));
1335 if (status != NO_ERROR) {
1336 goto invalid;
1337 }
1338
1339 if (RADIO_TECH_3GPP == format) {
1340 dispatchImsGsmSms(p, pRI, retry, messageRef);
1341 } else if (RADIO_TECH_3GPP2 == format) {
1342 dispatchImsCdmaSms(p, pRI, retry, messageRef);
1343 } else {
1344 ALOGE("requestImsSendSMS invalid format value =%d", format);
1345 }
1346
1347 return;
1348
1349invalid:
1350 invalidCommandBlock(pRI);
1351 return;
1352}
1353
1354static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001355dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI) {
1356 RIL_CDMA_SMS_Ack rcsa;
1357 int32_t t;
1358 status_t status;
1359 int32_t digitCount;
1360
Mark Salyzyndba25612015-04-09 07:18:35 -07001361 RLOGD("dispatchCdmaSmsAck");
Wink Savillef4c4d362009-04-02 01:37:03 -07001362 memset(&rcsa, 0, sizeof(rcsa));
1363
1364 status = p.readInt32(&t);
1365 rcsa.uErrorClass = (RIL_CDMA_SMS_ErrorClass) t;
1366
1367 status = p.readInt32(&t);
1368 rcsa.uSMSCauseCode = (int) t;
1369
1370 if (status != NO_ERROR) {
1371 goto invalid;
1372 }
1373
1374 startRequest;
Wink Saville1b5fd232009-04-22 14:50:00 -07001375 appendPrintBuf("%suErrorClass=%d, uTLStatus=%d, ",
1376 printBuf, rcsa.uErrorClass, rcsa.uSMSCauseCode);
Wink Savillef4c4d362009-04-02 01:37:03 -07001377 closeRequest;
1378
1379 printRequest(pRI->token, pRI->pCI->requestNumber);
1380
Etan Cohend3652192014-06-20 08:28:44 -07001381 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsa, sizeof(rcsa),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001382
1383#ifdef MEMSET_FREED
1384 memset(&rcsa, 0, sizeof(rcsa));
1385#endif
1386
1387 return;
1388
1389invalid:
1390 invalidCommandBlock(pRI);
1391 return;
1392}
1393
Wink Savillea592eeb2009-05-22 13:26:36 -07001394static void
1395dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1396 int32_t t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001397 status_t status;
Wink Savillea592eeb2009-05-22 13:26:36 -07001398 int32_t num;
Wink Savillef4c4d362009-04-02 01:37:03 -07001399
Wink Savillea592eeb2009-05-22 13:26:36 -07001400 status = p.readInt32(&num);
Wink Savillef4c4d362009-04-02 01:37:03 -07001401 if (status != NO_ERROR) {
1402 goto invalid;
1403 }
1404
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001405 {
1406 RIL_GSM_BroadcastSmsConfigInfo gsmBci[num];
1407 RIL_GSM_BroadcastSmsConfigInfo *gsmBciPtrs[num];
Wink Savillea592eeb2009-05-22 13:26:36 -07001408
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001409 startRequest;
1410 for (int i = 0 ; i < num ; i++ ) {
1411 gsmBciPtrs[i] = &gsmBci[i];
Wink Savillef4c4d362009-04-02 01:37:03 -07001412
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001413 status = p.readInt32(&t);
1414 gsmBci[i].fromServiceId = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001415
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001416 status = p.readInt32(&t);
1417 gsmBci[i].toServiceId = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001418
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001419 status = p.readInt32(&t);
1420 gsmBci[i].fromCodeScheme = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001421
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001422 status = p.readInt32(&t);
1423 gsmBci[i].toCodeScheme = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001424
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001425 status = p.readInt32(&t);
1426 gsmBci[i].selected = (uint8_t) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001427
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001428 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId =%d, \
1429 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]", printBuf, i,
1430 gsmBci[i].fromServiceId, gsmBci[i].toServiceId,
1431 gsmBci[i].fromCodeScheme, gsmBci[i].toCodeScheme,
1432 gsmBci[i].selected);
1433 }
1434 closeRequest;
Wink Savillef4c4d362009-04-02 01:37:03 -07001435
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001436 if (status != NO_ERROR) {
1437 goto invalid;
1438 }
Wink Savillef4c4d362009-04-02 01:37:03 -07001439
Etan Cohend3652192014-06-20 08:28:44 -07001440 CALL_ONREQUEST(pRI->pCI->requestNumber,
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001441 gsmBciPtrs,
1442 num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *),
Etan Cohend3652192014-06-20 08:28:44 -07001443 pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001444
1445#ifdef MEMSET_FREED
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001446 memset(gsmBci, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo));
1447 memset(gsmBciPtrs, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *));
Wink Savillef4c4d362009-04-02 01:37:03 -07001448#endif
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001449 }
Wink Savillef4c4d362009-04-02 01:37:03 -07001450
1451 return;
1452
1453invalid:
1454 invalidCommandBlock(pRI);
1455 return;
Wink Savillea592eeb2009-05-22 13:26:36 -07001456}
Wink Savillef4c4d362009-04-02 01:37:03 -07001457
Wink Savillea592eeb2009-05-22 13:26:36 -07001458static void
1459dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1460 int32_t t;
1461 status_t status;
1462 int32_t num;
1463
1464 status = p.readInt32(&num);
1465 if (status != NO_ERROR) {
1466 goto invalid;
1467 }
1468
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001469 {
1470 RIL_CDMA_BroadcastSmsConfigInfo cdmaBci[num];
1471 RIL_CDMA_BroadcastSmsConfigInfo *cdmaBciPtrs[num];
Wink Savillea592eeb2009-05-22 13:26:36 -07001472
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001473 startRequest;
1474 for (int i = 0 ; i < num ; i++ ) {
1475 cdmaBciPtrs[i] = &cdmaBci[i];
Wink Savillea592eeb2009-05-22 13:26:36 -07001476
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001477 status = p.readInt32(&t);
1478 cdmaBci[i].service_category = (int) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001479
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001480 status = p.readInt32(&t);
1481 cdmaBci[i].language = (int) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001482
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001483 status = p.readInt32(&t);
1484 cdmaBci[i].selected = (uint8_t) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001485
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001486 appendPrintBuf("%s [%d: service_category=%d, language =%d, \
1487 entries.bSelected =%d]", printBuf, i, cdmaBci[i].service_category,
1488 cdmaBci[i].language, cdmaBci[i].selected);
1489 }
1490 closeRequest;
Wink Savillea592eeb2009-05-22 13:26:36 -07001491
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001492 if (status != NO_ERROR) {
1493 goto invalid;
1494 }
Wink Savillea592eeb2009-05-22 13:26:36 -07001495
Etan Cohend3652192014-06-20 08:28:44 -07001496 CALL_ONREQUEST(pRI->pCI->requestNumber,
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001497 cdmaBciPtrs,
1498 num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *),
Etan Cohend3652192014-06-20 08:28:44 -07001499 pRI, pRI->socket_id);
Wink Savillea592eeb2009-05-22 13:26:36 -07001500
1501#ifdef MEMSET_FREED
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001502 memset(cdmaBci, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo));
1503 memset(cdmaBciPtrs, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *));
Wink Savillea592eeb2009-05-22 13:26:36 -07001504#endif
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001505 }
Wink Savillea592eeb2009-05-22 13:26:36 -07001506
1507 return;
1508
1509invalid:
1510 invalidCommandBlock(pRI);
1511 return;
Wink Savillef4c4d362009-04-02 01:37:03 -07001512}
1513
1514static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI) {
1515 RIL_CDMA_SMS_WriteArgs rcsw;
1516 int32_t t;
1517 uint32_t ut;
1518 uint8_t uct;
1519 status_t status;
1520 int32_t digitCount;
1521
1522 memset(&rcsw, 0, sizeof(rcsw));
1523
1524 status = p.readInt32(&t);
1525 rcsw.status = t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001526
Wink Savillef4c4d362009-04-02 01:37:03 -07001527 status = p.readInt32(&t);
1528 rcsw.message.uTeleserviceID = (int) t;
1529
1530 status = p.read(&uct,sizeof(uct));
1531 rcsw.message.bIsServicePresent = (uint8_t) uct;
1532
1533 status = p.readInt32(&t);
1534 rcsw.message.uServicecategory = (int) t;
1535
1536 status = p.readInt32(&t);
1537 rcsw.message.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1538
1539 status = p.readInt32(&t);
1540 rcsw.message.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1541
1542 status = p.readInt32(&t);
1543 rcsw.message.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1544
1545 status = p.readInt32(&t);
1546 rcsw.message.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1547
1548 status = p.read(&uct,sizeof(uct));
1549 rcsw.message.sAddress.number_of_digits = (uint8_t) uct;
1550
1551 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_ADDRESS_MAX; digitCount ++) {
1552 status = p.read(&uct,sizeof(uct));
1553 rcsw.message.sAddress.digits[digitCount] = (uint8_t) uct;
1554 }
1555
Wink Savillea592eeb2009-05-22 13:26:36 -07001556 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001557 rcsw.message.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1558
Wink Savillea592eeb2009-05-22 13:26:36 -07001559 status = p.read(&uct,sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001560 rcsw.message.sSubAddress.odd = (uint8_t) uct;
1561
1562 status = p.read(&uct,sizeof(uct));
1563 rcsw.message.sSubAddress.number_of_digits = (uint8_t) uct;
1564
1565 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_SUBADDRESS_MAX; digitCount ++) {
Wink Savillea592eeb2009-05-22 13:26:36 -07001566 status = p.read(&uct,sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001567 rcsw.message.sSubAddress.digits[digitCount] = (uint8_t) uct;
1568 }
1569
Wink Savillea592eeb2009-05-22 13:26:36 -07001570 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001571 rcsw.message.uBearerDataLen = (int) t;
1572
1573 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_BEARER_DATA_MAX; digitCount ++) {
Wink Savillea592eeb2009-05-22 13:26:36 -07001574 status = p.read(&uct, sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001575 rcsw.message.aBearerData[digitCount] = (uint8_t) uct;
1576 }
1577
1578 if (status != NO_ERROR) {
1579 goto invalid;
1580 }
1581
1582 startRequest;
Wink Saville1b5fd232009-04-22 14:50:00 -07001583 appendPrintBuf("%sstatus=%d, message.uTeleserviceID=%d, message.bIsServicePresent=%d, \
1584 message.uServicecategory=%d, message.sAddress.digit_mode=%d, \
1585 message.sAddress.number_mode=%d, \
1586 message.sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07001587 printBuf, rcsw.status, rcsw.message.uTeleserviceID, rcsw.message.bIsServicePresent,
Wink Saville1b5fd232009-04-22 14:50:00 -07001588 rcsw.message.uServicecategory, rcsw.message.sAddress.digit_mode,
1589 rcsw.message.sAddress.number_mode,
1590 rcsw.message.sAddress.number_type);
Wink Savillef4c4d362009-04-02 01:37:03 -07001591 closeRequest;
1592
1593 printRequest(pRI->token, pRI->pCI->requestNumber);
1594
Etan Cohend3652192014-06-20 08:28:44 -07001595 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsw, sizeof(rcsw),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001596
1597#ifdef MEMSET_FREED
1598 memset(&rcsw, 0, sizeof(rcsw));
1599#endif
1600
1601 return;
1602
1603invalid:
1604 invalidCommandBlock(pRI);
1605 return;
1606
1607}
1608
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -07001609// For backwards compatibility in RIL_REQUEST_SETUP_DATA_CALL.
1610// Version 4 of the RIL interface adds a new PDP type parameter to support
1611// IPv6 and dual-stack PDP contexts. When dealing with a previous version of
1612// RIL, remove the parameter from the request.
1613static void dispatchDataCall(Parcel& p, RequestInfo *pRI) {
1614 // In RIL v3, REQUEST_SETUP_DATA_CALL takes 6 parameters.
1615 const int numParamsRilV3 = 6;
1616
1617 // The first bytes of the RIL parcel contain the request number and the
1618 // serial number - see processCommandBuffer(). Copy them over too.
1619 int pos = p.dataPosition();
1620
1621 int numParams = p.readInt32();
1622 if (s_callbacks.version < 4 && numParams > numParamsRilV3) {
1623 Parcel p2;
1624 p2.appendFrom(&p, 0, pos);
1625 p2.writeInt32(numParamsRilV3);
1626 for(int i = 0; i < numParamsRilV3; i++) {
1627 p2.writeString16(p.readString16());
1628 }
1629 p2.setDataPosition(pos);
1630 dispatchStrings(p2, pRI);
1631 } else {
Lorenzo Colitti57ce1f22010-09-13 12:23:50 -07001632 p.setDataPosition(pos);
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -07001633 dispatchStrings(p, pRI);
1634 }
1635}
1636
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001637// For backwards compatibility with RILs that dont support RIL_REQUEST_VOICE_RADIO_TECH.
1638// When all RILs handle this request, this function can be removed and
1639// the request can be sent directly to the RIL using dispatchVoid.
1640static void dispatchVoiceRadioTech(Parcel& p, RequestInfo *pRI) {
Etan Cohend3652192014-06-20 08:28:44 -07001641 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001642
1643 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1644 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1645 }
1646
1647 // RILs that support RADIO_STATE_ON should support this request.
1648 if (RADIO_STATE_ON == state) {
1649 dispatchVoid(p, pRI);
1650 return;
1651 }
1652
1653 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1654 // will not support this new request either and decode Voice Radio Technology
1655 // from Radio State
1656 voiceRadioTech = decodeVoiceRadioTechnology(state);
1657
1658 if (voiceRadioTech < 0)
1659 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1660 else
1661 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &voiceRadioTech, sizeof(int));
1662}
1663
1664// For backwards compatibility in RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE:.
1665// When all RILs handle this request, this function can be removed and
1666// the request can be sent directly to the RIL using dispatchVoid.
1667static void dispatchCdmaSubscriptionSource(Parcel& p, RequestInfo *pRI) {
Etan Cohend3652192014-06-20 08:28:44 -07001668 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001669
1670 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1671 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1672 }
1673
1674 // RILs that support RADIO_STATE_ON should support this request.
1675 if (RADIO_STATE_ON == state) {
1676 dispatchVoid(p, pRI);
1677 return;
1678 }
1679
1680 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1681 // will not support this new request either and decode CDMA Subscription Source
1682 // from Radio State
1683 cdmaSubscriptionSource = decodeCdmaSubscriptionSource(state);
1684
1685 if (cdmaSubscriptionSource < 0)
1686 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1687 else
1688 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &cdmaSubscriptionSource, sizeof(int));
1689}
1690
Sungmin Choi75697532013-04-26 15:04:45 -07001691static void dispatchSetInitialAttachApn(Parcel &p, RequestInfo *pRI)
1692{
1693 RIL_InitialAttachApn pf;
1694 int32_t t;
1695 status_t status;
1696
1697 memset(&pf, 0, sizeof(pf));
1698
1699 pf.apn = strdupReadString(p);
1700 pf.protocol = strdupReadString(p);
1701
1702 status = p.readInt32(&t);
1703 pf.authtype = (int) t;
1704
1705 pf.username = strdupReadString(p);
1706 pf.password = strdupReadString(p);
1707
1708 startRequest;
Etan Cohen5d891b72014-02-27 17:25:17 -08001709 appendPrintBuf("%sapn=%s, protocol=%s, authtype=%d, username=%s, password=%s",
1710 printBuf, pf.apn, pf.protocol, pf.authtype, pf.username, pf.password);
Sungmin Choi75697532013-04-26 15:04:45 -07001711 closeRequest;
1712 printRequest(pRI->token, pRI->pCI->requestNumber);
1713
1714 if (status != NO_ERROR) {
1715 goto invalid;
1716 }
Etan Cohend3652192014-06-20 08:28:44 -07001717 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
Sungmin Choi75697532013-04-26 15:04:45 -07001718
1719#ifdef MEMSET_FREED
1720 memsetString(pf.apn);
1721 memsetString(pf.protocol);
1722 memsetString(pf.username);
1723 memsetString(pf.password);
1724#endif
1725
1726 free(pf.apn);
1727 free(pf.protocol);
1728 free(pf.username);
1729 free(pf.password);
1730
1731#ifdef MEMSET_FREED
1732 memset(&pf, 0, sizeof(pf));
1733#endif
1734
1735 return;
1736invalid:
1737 invalidCommandBlock(pRI);
1738 return;
1739}
1740
Jake Hamby8a4a2332014-01-15 13:12:05 -08001741static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI) {
1742 RIL_NV_ReadItem nvri;
1743 int32_t t;
1744 status_t status;
1745
1746 memset(&nvri, 0, sizeof(nvri));
1747
1748 status = p.readInt32(&t);
1749 nvri.itemID = (RIL_NV_Item) t;
1750
1751 if (status != NO_ERROR) {
1752 goto invalid;
1753 }
1754
1755 startRequest;
1756 appendPrintBuf("%snvri.itemID=%d, ", printBuf, nvri.itemID);
1757 closeRequest;
1758
1759 printRequest(pRI->token, pRI->pCI->requestNumber);
1760
Etan Cohend3652192014-06-20 08:28:44 -07001761 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvri, sizeof(nvri), pRI, pRI->socket_id);
Jake Hamby8a4a2332014-01-15 13:12:05 -08001762
1763#ifdef MEMSET_FREED
1764 memset(&nvri, 0, sizeof(nvri));
1765#endif
1766
1767 return;
1768
1769invalid:
1770 invalidCommandBlock(pRI);
1771 return;
1772}
1773
1774static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI) {
1775 RIL_NV_WriteItem nvwi;
1776 int32_t t;
1777 status_t status;
1778
1779 memset(&nvwi, 0, sizeof(nvwi));
1780
1781 status = p.readInt32(&t);
1782 nvwi.itemID = (RIL_NV_Item) t;
1783
1784 nvwi.value = strdupReadString(p);
1785
1786 if (status != NO_ERROR || nvwi.value == NULL) {
1787 goto invalid;
1788 }
1789
1790 startRequest;
1791 appendPrintBuf("%snvwi.itemID=%d, value=%s, ", printBuf, nvwi.itemID,
1792 nvwi.value);
1793 closeRequest;
1794
1795 printRequest(pRI->token, pRI->pCI->requestNumber);
1796
Etan Cohend3652192014-06-20 08:28:44 -07001797 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvwi, sizeof(nvwi), pRI, pRI->socket_id);
Jake Hamby8a4a2332014-01-15 13:12:05 -08001798
1799#ifdef MEMSET_FREED
1800 memsetString(nvwi.value);
1801#endif
1802
1803 free(nvwi.value);
1804
1805#ifdef MEMSET_FREED
1806 memset(&nvwi, 0, sizeof(nvwi));
1807#endif
1808
1809 return;
1810
1811invalid:
1812 invalidCommandBlock(pRI);
1813 return;
1814}
1815
1816
Etan Cohend3652192014-06-20 08:28:44 -07001817static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI) {
1818 RIL_SelectUiccSub uicc_sub;
1819 status_t status;
1820 int32_t t;
1821 memset(&uicc_sub, 0, sizeof(uicc_sub));
1822
1823 status = p.readInt32(&t);
1824 if (status != NO_ERROR) {
1825 goto invalid;
1826 }
1827 uicc_sub.slot = (int) t;
1828
1829 status = p.readInt32(&t);
1830 if (status != NO_ERROR) {
1831 goto invalid;
1832 }
1833 uicc_sub.app_index = (int) t;
1834
1835 status = p.readInt32(&t);
1836 if (status != NO_ERROR) {
1837 goto invalid;
1838 }
1839 uicc_sub.sub_type = (RIL_SubscriptionType) t;
1840
1841 status = p.readInt32(&t);
1842 if (status != NO_ERROR) {
1843 goto invalid;
1844 }
1845 uicc_sub.act_status = (RIL_UiccSubActStatus) t;
1846
1847 startRequest;
1848 appendPrintBuf("slot=%d, app_index=%d, act_status = %d", uicc_sub.slot, uicc_sub.app_index,
1849 uicc_sub.act_status);
1850 RLOGD("dispatchUiccSubscription, slot=%d, app_index=%d, act_status = %d", uicc_sub.slot,
1851 uicc_sub.app_index, uicc_sub.act_status);
1852 closeRequest;
1853 printRequest(pRI->token, pRI->pCI->requestNumber);
1854
1855 CALL_ONREQUEST(pRI->pCI->requestNumber, &uicc_sub, sizeof(uicc_sub), pRI, pRI->socket_id);
1856
1857#ifdef MEMSET_FREED
1858 memset(&uicc_sub, 0, sizeof(uicc_sub));
1859#endif
1860 return;
1861
1862invalid:
1863 invalidCommandBlock(pRI);
1864 return;
1865}
1866
Amit Mahajan90530a62014-07-01 15:54:08 -07001867static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI)
1868{
1869 RIL_SimAuthentication pf;
1870 int32_t t;
1871 status_t status;
1872
1873 memset(&pf, 0, sizeof(pf));
1874
1875 status = p.readInt32(&t);
1876 pf.authContext = (int) t;
1877 pf.authData = strdupReadString(p);
1878 pf.aid = strdupReadString(p);
1879
1880 startRequest;
1881 appendPrintBuf("authContext=%s, authData=%s, aid=%s", pf.authContext, pf.authData, pf.aid);
1882 closeRequest;
1883 printRequest(pRI->token, pRI->pCI->requestNumber);
1884
1885 if (status != NO_ERROR) {
1886 goto invalid;
1887 }
1888 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
1889
1890#ifdef MEMSET_FREED
1891 memsetString(pf.authData);
1892 memsetString(pf.aid);
1893#endif
1894
1895 free(pf.authData);
1896 free(pf.aid);
1897
1898#ifdef MEMSET_FREED
1899 memset(&pf, 0, sizeof(pf));
1900#endif
1901
1902 return;
1903invalid:
1904 invalidCommandBlock(pRI);
1905 return;
1906}
1907
Amit Mahajanc796e222014-08-13 16:54:01 +00001908static void dispatchDataProfile(Parcel &p, RequestInfo *pRI) {
1909 int32_t t;
1910 status_t status;
1911 int32_t num;
1912
1913 status = p.readInt32(&num);
1914 if (status != NO_ERROR) {
1915 goto invalid;
1916 }
1917
1918 {
1919 RIL_DataProfileInfo dataProfiles[num];
1920 RIL_DataProfileInfo *dataProfilePtrs[num];
1921
1922 startRequest;
1923 for (int i = 0 ; i < num ; i++ ) {
1924 dataProfilePtrs[i] = &dataProfiles[i];
1925
1926 status = p.readInt32(&t);
1927 dataProfiles[i].profileId = (int) t;
1928
1929 dataProfiles[i].apn = strdupReadString(p);
1930 dataProfiles[i].protocol = strdupReadString(p);
1931 status = p.readInt32(&t);
1932 dataProfiles[i].authType = (int) t;
1933
1934 dataProfiles[i].user = strdupReadString(p);
1935 dataProfiles[i].password = strdupReadString(p);
1936
1937 status = p.readInt32(&t);
1938 dataProfiles[i].type = (int) t;
1939
1940 status = p.readInt32(&t);
1941 dataProfiles[i].maxConnsTime = (int) t;
1942 status = p.readInt32(&t);
1943 dataProfiles[i].maxConns = (int) t;
1944 status = p.readInt32(&t);
1945 dataProfiles[i].waitTime = (int) t;
1946
1947 status = p.readInt32(&t);
1948 dataProfiles[i].enabled = (int) t;
1949
1950 appendPrintBuf("%s [%d: profileId=%d, apn =%s, protocol =%s, authType =%d, \
1951 user =%s, password =%s, type =%d, maxConnsTime =%d, maxConns =%d, \
1952 waitTime =%d, enabled =%d]", printBuf, i, dataProfiles[i].profileId,
1953 dataProfiles[i].apn, dataProfiles[i].protocol, dataProfiles[i].authType,
1954 dataProfiles[i].user, dataProfiles[i].password, dataProfiles[i].type,
1955 dataProfiles[i].maxConnsTime, dataProfiles[i].maxConns,
1956 dataProfiles[i].waitTime, dataProfiles[i].enabled);
1957 }
1958 closeRequest;
1959 printRequest(pRI->token, pRI->pCI->requestNumber);
1960
1961 if (status != NO_ERROR) {
1962 goto invalid;
1963 }
1964 CALL_ONREQUEST(pRI->pCI->requestNumber,
1965 dataProfilePtrs,
1966 num * sizeof(RIL_DataProfileInfo *),
1967 pRI, pRI->socket_id);
1968
1969#ifdef MEMSET_FREED
1970 memset(dataProfiles, 0, num * sizeof(RIL_DataProfileInfo));
1971 memset(dataProfilePtrs, 0, num * sizeof(RIL_DataProfileInfo *));
1972#endif
1973 }
1974
1975 return;
1976
1977invalid:
1978 invalidCommandBlock(pRI);
1979 return;
1980}
1981
Wink Saville8b4e4f72014-10-17 15:01:45 -07001982static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI){
1983 RIL_RadioCapability rc;
1984 int32_t t;
1985 status_t status;
1986
1987 memset (&rc, 0, sizeof(RIL_RadioCapability));
1988
1989 status = p.readInt32(&t);
1990 rc.version = (int)t;
1991 if (status != NO_ERROR) {
1992 goto invalid;
1993 }
1994
1995 status = p.readInt32(&t);
1996 rc.session= (int)t;
1997 if (status != NO_ERROR) {
1998 goto invalid;
1999 }
2000
2001 status = p.readInt32(&t);
2002 rc.phase= (int)t;
2003 if (status != NO_ERROR) {
2004 goto invalid;
2005 }
2006
2007 status = p.readInt32(&t);
2008 rc.rat = (int)t;
2009 if (status != NO_ERROR) {
2010 goto invalid;
2011 }
2012
2013 status = readStringFromParcelInplace(p, rc.logicalModemUuid, sizeof(rc.logicalModemUuid));
2014 if (status != NO_ERROR) {
2015 goto invalid;
2016 }
2017
2018 status = p.readInt32(&t);
2019 rc.status = (int)t;
2020
2021 if (status != NO_ERROR) {
2022 goto invalid;
2023 }
2024
2025 startRequest;
2026 appendPrintBuf("%s [version:%d, session:%d, phase:%d, rat:%d, \
Legler Wu8caf06f2014-10-29 14:02:14 +08002027 logicalModemUuid:%s, status:%d", printBuf, rc.version, rc.session
2028 rc.phase, rc.rat, rc.logicalModemUuid, rc.session);
Wink Saville8b4e4f72014-10-17 15:01:45 -07002029
2030 closeRequest;
2031 printRequest(pRI->token, pRI->pCI->requestNumber);
2032
2033 CALL_ONREQUEST(pRI->pCI->requestNumber,
2034 &rc,
2035 sizeof(RIL_RadioCapability),
2036 pRI, pRI->socket_id);
2037 return;
2038invalid:
2039 invalidCommandBlock(pRI);
2040 return;
2041}
2042
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002043static int
Wink Savillef4c4d362009-04-02 01:37:03 -07002044blockingWrite(int fd, const void *buffer, size_t len) {
Wink Saville7f856802009-06-09 10:23:37 -07002045 size_t writeOffset = 0;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002046 const uint8_t *toWrite;
2047
2048 toWrite = (const uint8_t *)buffer;
2049
2050 while (writeOffset < len) {
2051 ssize_t written;
2052 do {
2053 written = write (fd, toWrite + writeOffset,
2054 len - writeOffset);
Banavathu, Srinivas Naik38884902011-07-05 20:04:25 +05302055 } while (written < 0 && ((errno == EINTR) || (errno == EAGAIN)));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002056
2057 if (written >= 0) {
2058 writeOffset += written;
2059 } else { // written < 0
Wink Saville8eb2a122012-11-19 16:05:13 -08002060 RLOGE ("RIL Response: unexpected error on write errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002061 close(fd);
2062 return -1;
2063 }
2064 }
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07002065#if VDBG
Dheeraj Shetty27976c42014-07-02 21:27:57 +02002066 RLOGE("RIL Response bytes written:%d", writeOffset);
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07002067#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002068 return 0;
2069}
2070
2071static int
Etan Cohend3652192014-06-20 08:28:44 -07002072sendResponseRaw (const void *data, size_t dataSize, RIL_SOCKET_ID socket_id) {
2073 int fd = s_ril_param_socket.fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002074 int ret;
2075 uint32_t header;
Etan Cohend3652192014-06-20 08:28:44 -07002076 pthread_mutex_t * writeMutexHook = &s_writeMutex;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002077
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07002078#if VDBG
Etan Cohend3652192014-06-20 08:28:44 -07002079 RLOGE("Send Response to %s", rilSocketIdToString(socket_id));
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07002080#endif
Etan Cohend3652192014-06-20 08:28:44 -07002081
2082#if (SIM_COUNT >= 2)
2083 if (socket_id == RIL_SOCKET_2) {
2084 fd = s_ril_param_socket2.fdCommand;
2085 writeMutexHook = &s_writeMutex_socket2;
2086 }
2087#if (SIM_COUNT >= 3)
2088 else if (socket_id == RIL_SOCKET_3) {
2089 fd = s_ril_param_socket3.fdCommand;
2090 writeMutexHook = &s_writeMutex_socket3;
2091 }
2092#endif
2093#if (SIM_COUNT >= 4)
2094 else if (socket_id == RIL_SOCKET_4) {
2095 fd = s_ril_param_socket4.fdCommand;
2096 writeMutexHook = &s_writeMutex_socket4;
2097 }
2098#endif
2099#endif
2100 if (fd < 0) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002101 return -1;
2102 }
2103
2104 if (dataSize > MAX_COMMAND_BYTES) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002105 RLOGE("RIL: packet larger than %u (%u)",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002106 MAX_COMMAND_BYTES, (unsigned int )dataSize);
2107
2108 return -1;
2109 }
Wink Saville7f856802009-06-09 10:23:37 -07002110
Etan Cohend3652192014-06-20 08:28:44 -07002111 pthread_mutex_lock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002112
2113 header = htonl(dataSize);
2114
2115 ret = blockingWrite(fd, (void *)&header, sizeof(header));
2116
2117 if (ret < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002118 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002119 return ret;
2120 }
2121
Kennyee1fadc2009-08-13 00:45:53 +08002122 ret = blockingWrite(fd, data, dataSize);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002123
2124 if (ret < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002125 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002126 return ret;
2127 }
2128
Etan Cohend3652192014-06-20 08:28:44 -07002129 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002130
2131 return 0;
2132}
2133
2134static int
Etan Cohend3652192014-06-20 08:28:44 -07002135sendResponse (Parcel &p, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002136 printResponse;
Etan Cohend3652192014-06-20 08:28:44 -07002137 return sendResponseRaw(p.data(), p.dataSize(), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002138}
2139
Mohamad Ayyash74f7e662014-04-18 11:43:28 -07002140/** response is an int* pointing to an array of ints */
Wink Saville7f856802009-06-09 10:23:37 -07002141
2142static int
Wink Savillef4c4d362009-04-02 01:37:03 -07002143responseInts(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002144 int numInts;
2145
2146 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002147 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002148 return RIL_ERRNO_INVALID_RESPONSE;
2149 }
2150 if (responselen % sizeof(int) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002151 RLOGE("responseInts: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002152 (int)responselen, (int)sizeof(int));
2153 return RIL_ERRNO_INVALID_RESPONSE;
2154 }
2155
2156 int *p_int = (int *) response;
2157
Mohamad Ayyash74f7e662014-04-18 11:43:28 -07002158 numInts = responselen / sizeof(int);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002159 p.writeInt32 (numInts);
2160
2161 /* each int*/
2162 startResponse;
2163 for (int i = 0 ; i < numInts ; i++) {
2164 appendPrintBuf("%s%d,", printBuf, p_int[i]);
2165 p.writeInt32(p_int[i]);
2166 }
2167 removeLastChar;
2168 closeResponse;
2169
2170 return 0;
2171}
2172
Wink Saville43808972011-01-13 17:39:51 -08002173/** response is a char **, pointing to an array of char *'s
2174 The parcel will begin with the version */
2175static int responseStringsWithVersion(int version, Parcel &p, void *response, size_t responselen) {
2176 p.writeInt32(version);
2177 return responseStrings(p, response, responselen);
2178}
2179
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002180/** response is a char **, pointing to an array of char *'s */
Wink Savillef4c4d362009-04-02 01:37:03 -07002181static int responseStrings(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002182 int numStrings;
Wink Saville7f856802009-06-09 10:23:37 -07002183
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002184 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002185 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002186 return RIL_ERRNO_INVALID_RESPONSE;
2187 }
2188 if (responselen % sizeof(char *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002189 RLOGE("responseStrings: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002190 (int)responselen, (int)sizeof(char *));
2191 return RIL_ERRNO_INVALID_RESPONSE;
2192 }
2193
2194 if (response == NULL) {
2195 p.writeInt32 (0);
2196 } else {
2197 char **p_cur = (char **) response;
2198
2199 numStrings = responselen / sizeof(char *);
2200 p.writeInt32 (numStrings);
2201
2202 /* each string*/
2203 startResponse;
2204 for (int i = 0 ; i < numStrings ; i++) {
2205 appendPrintBuf("%s%s,", printBuf, (char*)p_cur[i]);
2206 writeStringToParcel (p, p_cur[i]);
2207 }
2208 removeLastChar;
2209 closeResponse;
2210 }
2211 return 0;
2212}
2213
2214
2215/**
Wink Saville7f856802009-06-09 10:23:37 -07002216 * NULL strings are accepted
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002217 * FIXME currently ignores responselen
2218 */
Wink Savillef4c4d362009-04-02 01:37:03 -07002219static int responseString(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002220 /* one string only */
2221 startResponse;
2222 appendPrintBuf("%s%s", printBuf, (char*)response);
2223 closeResponse;
2224
2225 writeStringToParcel(p, (const char *)response);
2226
2227 return 0;
2228}
2229
Wink Savillef4c4d362009-04-02 01:37:03 -07002230static int responseVoid(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002231 startResponse;
2232 removeLastChar;
2233 return 0;
2234}
2235
Wink Savillef4c4d362009-04-02 01:37:03 -07002236static int responseCallList(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002237 int num;
2238
2239 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002240 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002241 return RIL_ERRNO_INVALID_RESPONSE;
2242 }
2243
2244 if (responselen % sizeof (RIL_Call *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002245 RLOGE("responseCallList: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002246 (int)responselen, (int)sizeof (RIL_Call *));
2247 return RIL_ERRNO_INVALID_RESPONSE;
2248 }
2249
2250 startResponse;
2251 /* number of call info's */
2252 num = responselen / sizeof(RIL_Call *);
2253 p.writeInt32(num);
2254
2255 for (int i = 0 ; i < num ; i++) {
2256 RIL_Call *p_cur = ((RIL_Call **) response)[i];
2257 /* each call info */
2258 p.writeInt32(p_cur->state);
2259 p.writeInt32(p_cur->index);
2260 p.writeInt32(p_cur->toa);
2261 p.writeInt32(p_cur->isMpty);
2262 p.writeInt32(p_cur->isMT);
2263 p.writeInt32(p_cur->als);
2264 p.writeInt32(p_cur->isVoice);
Wink Saville1b5fd232009-04-22 14:50:00 -07002265 p.writeInt32(p_cur->isVoicePrivacy);
2266 writeStringToParcel(p, p_cur->number);
John Wangff368742009-03-24 17:56:29 -07002267 p.writeInt32(p_cur->numberPresentation);
Wink Saville1b5fd232009-04-22 14:50:00 -07002268 writeStringToParcel(p, p_cur->name);
2269 p.writeInt32(p_cur->namePresentation);
Wink Saville3a4840b2010-04-07 13:29:58 -07002270 // Remove when partners upgrade to version 3
Wink Saville74fa3882009-12-22 15:35:41 -08002271 if ((s_callbacks.version < 3) || (p_cur->uusInfo == NULL || p_cur->uusInfo->uusData == NULL)) {
2272 p.writeInt32(0); /* UUS Information is absent */
2273 } else {
2274 RIL_UUS_Info *uusInfo = p_cur->uusInfo;
2275 p.writeInt32(1); /* UUS Information is present */
2276 p.writeInt32(uusInfo->uusType);
2277 p.writeInt32(uusInfo->uusDcs);
2278 p.writeInt32(uusInfo->uusLength);
2279 p.write(uusInfo->uusData, uusInfo->uusLength);
2280 }
Wink Saville3d54e742009-05-18 18:00:44 -07002281 appendPrintBuf("%s[id=%d,%s,toa=%d,",
John Wangff368742009-03-24 17:56:29 -07002282 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002283 p_cur->index,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002284 callStateToString(p_cur->state),
Wink Saville3d54e742009-05-18 18:00:44 -07002285 p_cur->toa);
2286 appendPrintBuf("%s%s,%s,als=%d,%s,%s,",
2287 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002288 (p_cur->isMpty)?"conf":"norm",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002289 (p_cur->isMT)?"mt":"mo",
2290 p_cur->als,
2291 (p_cur->isVoice)?"voc":"nonvoc",
Wink Saville3d54e742009-05-18 18:00:44 -07002292 (p_cur->isVoicePrivacy)?"evp":"noevp");
2293 appendPrintBuf("%s%s,cli=%d,name='%s',%d]",
2294 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002295 p_cur->number,
2296 p_cur->numberPresentation,
2297 p_cur->name,
2298 p_cur->namePresentation);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002299 }
2300 removeLastChar;
2301 closeResponse;
2302
2303 return 0;
2304}
2305
Wink Savillef4c4d362009-04-02 01:37:03 -07002306static int responseSMS(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002307 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002308 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002309 return RIL_ERRNO_INVALID_RESPONSE;
2310 }
2311
2312 if (responselen != sizeof (RIL_SMS_Response) ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002313 RLOGE("invalid response length %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002314 (int)responselen, (int)sizeof (RIL_SMS_Response));
2315 return RIL_ERRNO_INVALID_RESPONSE;
2316 }
2317
2318 RIL_SMS_Response *p_cur = (RIL_SMS_Response *) response;
2319
2320 p.writeInt32(p_cur->messageRef);
2321 writeStringToParcel(p, p_cur->ackPDU);
Jaikumar Ganesh920c78f2009-06-04 10:53:15 -07002322 p.writeInt32(p_cur->errorCode);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002323
2324 startResponse;
Jaikumar Ganesh920c78f2009-06-04 10:53:15 -07002325 appendPrintBuf("%s%d,%s,%d", printBuf, p_cur->messageRef,
2326 (char*)p_cur->ackPDU, p_cur->errorCode);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002327 closeResponse;
2328
2329 return 0;
2330}
2331
Wink Savillec0114b32011-02-18 10:14:07 -08002332static int responseDataCallListV4(Parcel &p, void *response, size_t responselen)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002333{
2334 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002335 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002336 return RIL_ERRNO_INVALID_RESPONSE;
2337 }
2338
Wink Savillec0114b32011-02-18 10:14:07 -08002339 if (responselen % sizeof(RIL_Data_Call_Response_v4) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002340 RLOGE("responseDataCallListV4: invalid response length %d expected multiple of %d",
Wink Savillec0114b32011-02-18 10:14:07 -08002341 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v4));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002342 return RIL_ERRNO_INVALID_RESPONSE;
2343 }
2344
Amit Mahajan52500162014-07-29 17:36:48 -07002345 // Write version
2346 p.writeInt32(4);
2347
Wink Savillec0114b32011-02-18 10:14:07 -08002348 int num = responselen / sizeof(RIL_Data_Call_Response_v4);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002349 p.writeInt32(num);
2350
Wink Savillec0114b32011-02-18 10:14:07 -08002351 RIL_Data_Call_Response_v4 *p_cur = (RIL_Data_Call_Response_v4 *) response;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002352 startResponse;
2353 int i;
2354 for (i = 0; i < num; i++) {
2355 p.writeInt32(p_cur[i].cid);
2356 p.writeInt32(p_cur[i].active);
2357 writeStringToParcel(p, p_cur[i].type);
Wink Savillec0114b32011-02-18 10:14:07 -08002358 // apn is not used, so don't send.
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002359 writeStringToParcel(p, p_cur[i].address);
Wink Savillec0114b32011-02-18 10:14:07 -08002360 appendPrintBuf("%s[cid=%d,%s,%s,%s],", printBuf,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002361 p_cur[i].cid,
2362 (p_cur[i].active==0)?"down":"up",
2363 (char*)p_cur[i].type,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002364 (char*)p_cur[i].address);
2365 }
2366 removeLastChar;
2367 closeResponse;
2368
2369 return 0;
2370}
2371
Etan Cohend3652192014-06-20 08:28:44 -07002372static int responseDataCallListV6(Parcel &p, void *response, size_t responselen)
2373{
Amit Mahajan52500162014-07-29 17:36:48 -07002374 if (response == NULL && responselen != 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002375 RLOGE("invalid response: NULL");
2376 return RIL_ERRNO_INVALID_RESPONSE;
2377 }
2378
2379 if (responselen % sizeof(RIL_Data_Call_Response_v6) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002380 RLOGE("responseDataCallListV6: invalid response length %d expected multiple of %d",
Etan Cohend3652192014-06-20 08:28:44 -07002381 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v6));
2382 return RIL_ERRNO_INVALID_RESPONSE;
2383 }
2384
Amit Mahajan52500162014-07-29 17:36:48 -07002385 // Write version
2386 p.writeInt32(6);
2387
Etan Cohend3652192014-06-20 08:28:44 -07002388 int num = responselen / sizeof(RIL_Data_Call_Response_v6);
2389 p.writeInt32(num);
2390
2391 RIL_Data_Call_Response_v6 *p_cur = (RIL_Data_Call_Response_v6 *) response;
2392 startResponse;
2393 int i;
2394 for (i = 0; i < num; i++) {
2395 p.writeInt32((int)p_cur[i].status);
2396 p.writeInt32(p_cur[i].suggestedRetryTime);
2397 p.writeInt32(p_cur[i].cid);
2398 p.writeInt32(p_cur[i].active);
2399 writeStringToParcel(p, p_cur[i].type);
2400 writeStringToParcel(p, p_cur[i].ifname);
2401 writeStringToParcel(p, p_cur[i].addresses);
2402 writeStringToParcel(p, p_cur[i].dnses);
2403 writeStringToParcel(p, p_cur[i].gateways);
2404 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s],", printBuf,
2405 p_cur[i].status,
2406 p_cur[i].suggestedRetryTime,
2407 p_cur[i].cid,
2408 (p_cur[i].active==0)?"down":"up",
2409 (char*)p_cur[i].type,
2410 (char*)p_cur[i].ifname,
2411 (char*)p_cur[i].addresses,
2412 (char*)p_cur[i].dnses,
2413 (char*)p_cur[i].gateways);
2414 }
2415 removeLastChar;
2416 closeResponse;
2417
2418 return 0;
2419}
2420
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002421static int responseDataCallListV9(Parcel &p, void *response, size_t responselen)
2422{
2423 if (response == NULL && responselen != 0) {
2424 RLOGE("invalid response: NULL");
2425 return RIL_ERRNO_INVALID_RESPONSE;
2426 }
2427
2428 if (responselen % sizeof(RIL_Data_Call_Response_v9) != 0) {
2429 RLOGE("responseDataCallListV9: invalid response length %d expected multiple of %d",
2430 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v9));
2431 return RIL_ERRNO_INVALID_RESPONSE;
2432 }
2433
2434 // Write version
2435 p.writeInt32(10);
2436
2437 int num = responselen / sizeof(RIL_Data_Call_Response_v9);
2438 p.writeInt32(num);
2439
2440 RIL_Data_Call_Response_v9 *p_cur = (RIL_Data_Call_Response_v9 *) response;
2441 startResponse;
2442 int i;
2443 for (i = 0; i < num; i++) {
2444 p.writeInt32((int)p_cur[i].status);
2445 p.writeInt32(p_cur[i].suggestedRetryTime);
2446 p.writeInt32(p_cur[i].cid);
2447 p.writeInt32(p_cur[i].active);
2448 writeStringToParcel(p, p_cur[i].type);
2449 writeStringToParcel(p, p_cur[i].ifname);
2450 writeStringToParcel(p, p_cur[i].addresses);
2451 writeStringToParcel(p, p_cur[i].dnses);
2452 writeStringToParcel(p, p_cur[i].gateways);
2453 writeStringToParcel(p, p_cur[i].pcscf);
2454 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s],", printBuf,
2455 p_cur[i].status,
2456 p_cur[i].suggestedRetryTime,
2457 p_cur[i].cid,
2458 (p_cur[i].active==0)?"down":"up",
2459 (char*)p_cur[i].type,
2460 (char*)p_cur[i].ifname,
2461 (char*)p_cur[i].addresses,
2462 (char*)p_cur[i].dnses,
2463 (char*)p_cur[i].gateways,
2464 (char*)p_cur[i].pcscf);
2465 }
2466 removeLastChar;
2467 closeResponse;
2468
2469 return 0;
2470}
2471
2472
Wink Saville43808972011-01-13 17:39:51 -08002473static int responseDataCallList(Parcel &p, void *response, size_t responselen)
2474{
Wink Saville43808972011-01-13 17:39:51 -08002475 if (s_callbacks.version < 5) {
Amit Mahajan52500162014-07-29 17:36:48 -07002476 RLOGD("responseDataCallList: v4");
Wink Savillec0114b32011-02-18 10:14:07 -08002477 return responseDataCallListV4(p, response, responselen);
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002478 } else if (responselen % sizeof(RIL_Data_Call_Response_v6) == 0) {
2479 return responseDataCallListV6(p, response, responselen);
2480 } else if (responselen % sizeof(RIL_Data_Call_Response_v9) == 0) {
2481 return responseDataCallListV9(p, response, responselen);
Wink Saville43808972011-01-13 17:39:51 -08002482 } else {
2483 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002484 RLOGE("invalid response: NULL");
Wink Saville43808972011-01-13 17:39:51 -08002485 return RIL_ERRNO_INVALID_RESPONSE;
2486 }
2487
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002488 if (responselen % sizeof(RIL_Data_Call_Response_v11) != 0) {
2489 RLOGE("invalid response length %d expected multiple of %d",
2490 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v11));
Wink Saville43808972011-01-13 17:39:51 -08002491 return RIL_ERRNO_INVALID_RESPONSE;
2492 }
2493
Amit Mahajan52500162014-07-29 17:36:48 -07002494 // Write version
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002495 p.writeInt32(11);
Amit Mahajan52500162014-07-29 17:36:48 -07002496
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002497 int num = responselen / sizeof(RIL_Data_Call_Response_v11);
Wink Saville43808972011-01-13 17:39:51 -08002498 p.writeInt32(num);
2499
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002500 RIL_Data_Call_Response_v11 *p_cur = (RIL_Data_Call_Response_v11 *) response;
Wink Saville43808972011-01-13 17:39:51 -08002501 startResponse;
2502 int i;
2503 for (i = 0; i < num; i++) {
2504 p.writeInt32((int)p_cur[i].status);
Kazuhiro Ondobeb25b52011-06-17 16:26:45 -05002505 p.writeInt32(p_cur[i].suggestedRetryTime);
Wink Saville43808972011-01-13 17:39:51 -08002506 p.writeInt32(p_cur[i].cid);
2507 p.writeInt32(p_cur[i].active);
David 'Digit' Turneraf1298d2011-02-04 13:36:47 +01002508 writeStringToParcel(p, p_cur[i].type);
Wink Saville43808972011-01-13 17:39:51 -08002509 writeStringToParcel(p, p_cur[i].ifname);
2510 writeStringToParcel(p, p_cur[i].addresses);
2511 writeStringToParcel(p, p_cur[i].dnses);
Wink Savillec0114b32011-02-18 10:14:07 -08002512 writeStringToParcel(p, p_cur[i].gateways);
Etan Cohend3652192014-06-20 08:28:44 -07002513 writeStringToParcel(p, p_cur[i].pcscf);
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002514 p.writeInt32(p_cur[i].mtu);
2515 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 -08002516 p_cur[i].status,
Kazuhiro Ondobeb25b52011-06-17 16:26:45 -05002517 p_cur[i].suggestedRetryTime,
Wink Saville43808972011-01-13 17:39:51 -08002518 p_cur[i].cid,
2519 (p_cur[i].active==0)?"down":"up",
Naveen Kalla56384152011-11-16 11:12:37 -08002520 (char*)p_cur[i].type,
Wink Saville43808972011-01-13 17:39:51 -08002521 (char*)p_cur[i].ifname,
2522 (char*)p_cur[i].addresses,
Wink Savillec0114b32011-02-18 10:14:07 -08002523 (char*)p_cur[i].dnses,
Etan Cohend3652192014-06-20 08:28:44 -07002524 (char*)p_cur[i].gateways,
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002525 (char*)p_cur[i].pcscf,
2526 p_cur[i].mtu);
Wink Saville43808972011-01-13 17:39:51 -08002527 }
2528 removeLastChar;
2529 closeResponse;
2530 }
2531
2532 return 0;
2533}
2534
2535static int responseSetupDataCall(Parcel &p, void *response, size_t responselen)
2536{
2537 if (s_callbacks.version < 5) {
2538 return responseStringsWithVersion(s_callbacks.version, p, response, responselen);
2539 } else {
2540 return responseDataCallList(p, response, responselen);
2541 }
2542}
2543
Wink Savillef4c4d362009-04-02 01:37:03 -07002544static int responseRaw(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002545 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002546 RLOGE("invalid response: NULL with responselen != 0");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002547 return RIL_ERRNO_INVALID_RESPONSE;
2548 }
2549
2550 // The java code reads -1 size as null byte array
2551 if (response == NULL) {
Wink Saville7f856802009-06-09 10:23:37 -07002552 p.writeInt32(-1);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002553 } else {
2554 p.writeInt32(responselen);
2555 p.write(response, responselen);
2556 }
2557
2558 return 0;
2559}
2560
2561
Wink Savillef4c4d362009-04-02 01:37:03 -07002562static int responseSIM_IO(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002563 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002564 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002565 return RIL_ERRNO_INVALID_RESPONSE;
2566 }
2567
2568 if (responselen != sizeof (RIL_SIM_IO_Response) ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002569 RLOGE("invalid response length was %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002570 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
2571 return RIL_ERRNO_INVALID_RESPONSE;
2572 }
2573
2574 RIL_SIM_IO_Response *p_cur = (RIL_SIM_IO_Response *) response;
2575 p.writeInt32(p_cur->sw1);
2576 p.writeInt32(p_cur->sw2);
2577 writeStringToParcel(p, p_cur->simResponse);
2578
2579 startResponse;
2580 appendPrintBuf("%ssw1=0x%X,sw2=0x%X,%s", printBuf, p_cur->sw1, p_cur->sw2,
2581 (char*)p_cur->simResponse);
2582 closeResponse;
2583
2584
2585 return 0;
2586}
2587
Wink Savillef4c4d362009-04-02 01:37:03 -07002588static int responseCallForwards(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002589 int num;
Wink Saville7f856802009-06-09 10:23:37 -07002590
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002591 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002592 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002593 return RIL_ERRNO_INVALID_RESPONSE;
2594 }
2595
2596 if (responselen % sizeof(RIL_CallForwardInfo *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002597 RLOGE("responseCallForwards: invalid response length %d expected multiple of %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002598 (int)responselen, (int)sizeof(RIL_CallForwardInfo *));
2599 return RIL_ERRNO_INVALID_RESPONSE;
2600 }
2601
2602 /* number of call info's */
2603 num = responselen / sizeof(RIL_CallForwardInfo *);
2604 p.writeInt32(num);
2605
2606 startResponse;
2607 for (int i = 0 ; i < num ; i++) {
2608 RIL_CallForwardInfo *p_cur = ((RIL_CallForwardInfo **) response)[i];
2609
2610 p.writeInt32(p_cur->status);
2611 p.writeInt32(p_cur->reason);
2612 p.writeInt32(p_cur->serviceClass);
2613 p.writeInt32(p_cur->toa);
2614 writeStringToParcel(p, p_cur->number);
2615 p.writeInt32(p_cur->timeSeconds);
2616 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
2617 (p_cur->status==1)?"enable":"disable",
2618 p_cur->reason, p_cur->serviceClass, p_cur->toa,
2619 (char*)p_cur->number,
2620 p_cur->timeSeconds);
2621 }
2622 removeLastChar;
2623 closeResponse;
Wink Saville7f856802009-06-09 10:23:37 -07002624
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002625 return 0;
2626}
2627
Wink Savillef4c4d362009-04-02 01:37:03 -07002628static int responseSsn(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002629 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002630 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002631 return RIL_ERRNO_INVALID_RESPONSE;
2632 }
2633
2634 if (responselen != sizeof(RIL_SuppSvcNotification)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002635 RLOGE("invalid response length was %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002636 (int)responselen, (int)sizeof (RIL_SuppSvcNotification));
2637 return RIL_ERRNO_INVALID_RESPONSE;
2638 }
2639
2640 RIL_SuppSvcNotification *p_cur = (RIL_SuppSvcNotification *) response;
2641 p.writeInt32(p_cur->notificationType);
2642 p.writeInt32(p_cur->code);
2643 p.writeInt32(p_cur->index);
2644 p.writeInt32(p_cur->type);
2645 writeStringToParcel(p, p_cur->number);
2646
2647 startResponse;
2648 appendPrintBuf("%s%s,code=%d,id=%d,type=%d,%s", printBuf,
2649 (p_cur->notificationType==0)?"mo":"mt",
2650 p_cur->code, p_cur->index, p_cur->type,
2651 (char*)p_cur->number);
2652 closeResponse;
2653
2654 return 0;
2655}
2656
Wink Saville3d54e742009-05-18 18:00:44 -07002657static int responseCellList(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002658 int num;
2659
2660 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002661 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002662 return RIL_ERRNO_INVALID_RESPONSE;
2663 }
2664
2665 if (responselen % sizeof (RIL_NeighboringCell *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002666 RLOGE("responseCellList: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002667 (int)responselen, (int)sizeof (RIL_NeighboringCell *));
2668 return RIL_ERRNO_INVALID_RESPONSE;
2669 }
2670
2671 startResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002672 /* number of records */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002673 num = responselen / sizeof(RIL_NeighboringCell *);
2674 p.writeInt32(num);
2675
2676 for (int i = 0 ; i < num ; i++) {
2677 RIL_NeighboringCell *p_cur = ((RIL_NeighboringCell **) response)[i];
2678
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002679 p.writeInt32(p_cur->rssi);
2680 writeStringToParcel (p, p_cur->cid);
2681
2682 appendPrintBuf("%s[cid=%s,rssi=%d],", printBuf,
2683 p_cur->cid, p_cur->rssi);
2684 }
2685 removeLastChar;
2686 closeResponse;
2687
2688 return 0;
2689}
2690
Wink Saville3d54e742009-05-18 18:00:44 -07002691/**
2692 * Marshall the signalInfoRecord into the parcel if it exists.
2693 */
Wink Savillea592eeb2009-05-22 13:26:36 -07002694static void marshallSignalInfoRecord(Parcel &p,
2695 RIL_CDMA_SignalInfoRecord &p_signalInfoRecord) {
Wink Saville3d54e742009-05-18 18:00:44 -07002696 p.writeInt32(p_signalInfoRecord.isPresent);
2697 p.writeInt32(p_signalInfoRecord.signalType);
2698 p.writeInt32(p_signalInfoRecord.alertPitch);
2699 p.writeInt32(p_signalInfoRecord.signal);
2700}
2701
Wink Savillea592eeb2009-05-22 13:26:36 -07002702static int responseCdmaInformationRecords(Parcel &p,
2703 void *response, size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07002704 int num;
Wink Savillea592eeb2009-05-22 13:26:36 -07002705 char* string8 = NULL;
2706 int buffer_lenght;
2707 RIL_CDMA_InformationRecord *infoRec;
Wink Saville3d54e742009-05-18 18:00:44 -07002708
2709 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002710 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002711 return RIL_ERRNO_INVALID_RESPONSE;
2712 }
2713
Wink Savillea592eeb2009-05-22 13:26:36 -07002714 if (responselen != sizeof (RIL_CDMA_InformationRecords)) {
Amit Mahajan52500162014-07-29 17:36:48 -07002715 RLOGE("responseCdmaInformationRecords: invalid response length %d expected multiple of %d\n",
Wink Savillea592eeb2009-05-22 13:26:36 -07002716 (int)responselen, (int)sizeof (RIL_CDMA_InformationRecords *));
Wink Saville3d54e742009-05-18 18:00:44 -07002717 return RIL_ERRNO_INVALID_RESPONSE;
2718 }
2719
Wink Savillea592eeb2009-05-22 13:26:36 -07002720 RIL_CDMA_InformationRecords *p_cur =
2721 (RIL_CDMA_InformationRecords *) response;
2722 num = MIN(p_cur->numberOfInfoRecs, RIL_CDMA_MAX_NUMBER_OF_INFO_RECS);
Wink Saville3d54e742009-05-18 18:00:44 -07002723
2724 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07002725 p.writeInt32(num);
Wink Saville3d54e742009-05-18 18:00:44 -07002726
Wink Savillea592eeb2009-05-22 13:26:36 -07002727 for (int i = 0 ; i < num ; i++) {
2728 infoRec = &p_cur->infoRec[i];
2729 p.writeInt32(infoRec->name);
2730 switch (infoRec->name) {
Wink Saville3d54e742009-05-18 18:00:44 -07002731 case RIL_CDMA_DISPLAY_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002732 case RIL_CDMA_EXTENDED_DISPLAY_INFO_REC:
2733 if (infoRec->rec.display.alpha_len >
2734 CDMA_ALPHA_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002735 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002736 expected not more than %d\n",
2737 (int)infoRec->rec.display.alpha_len,
2738 CDMA_ALPHA_INFO_BUFFER_LENGTH);
2739 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002740 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002741 string8 = (char*) malloc((infoRec->rec.display.alpha_len + 1)
2742 * sizeof(char) );
2743 for (int i = 0 ; i < infoRec->rec.display.alpha_len ; i++) {
2744 string8[i] = infoRec->rec.display.alpha_buf[i];
2745 }
Wink Saville43808972011-01-13 17:39:51 -08002746 string8[(int)infoRec->rec.display.alpha_len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002747 writeStringToParcel(p, (const char*)string8);
2748 free(string8);
2749 string8 = NULL;
Wink Saville3d54e742009-05-18 18:00:44 -07002750 break;
2751 case RIL_CDMA_CALLED_PARTY_NUMBER_INFO_REC:
Wink Saville3d54e742009-05-18 18:00:44 -07002752 case RIL_CDMA_CALLING_PARTY_NUMBER_INFO_REC:
Wink Saville3d54e742009-05-18 18:00:44 -07002753 case RIL_CDMA_CONNECTED_NUMBER_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002754 if (infoRec->rec.number.len > CDMA_NUMBER_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002755 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002756 expected not more than %d\n",
2757 (int)infoRec->rec.number.len,
2758 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2759 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002760 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002761 string8 = (char*) malloc((infoRec->rec.number.len + 1)
2762 * sizeof(char) );
2763 for (int i = 0 ; i < infoRec->rec.number.len; i++) {
2764 string8[i] = infoRec->rec.number.buf[i];
2765 }
Wink Saville43808972011-01-13 17:39:51 -08002766 string8[(int)infoRec->rec.number.len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002767 writeStringToParcel(p, (const char*)string8);
2768 free(string8);
2769 string8 = NULL;
2770 p.writeInt32(infoRec->rec.number.number_type);
2771 p.writeInt32(infoRec->rec.number.number_plan);
2772 p.writeInt32(infoRec->rec.number.pi);
2773 p.writeInt32(infoRec->rec.number.si);
Wink Saville3d54e742009-05-18 18:00:44 -07002774 break;
2775 case RIL_CDMA_SIGNAL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002776 p.writeInt32(infoRec->rec.signal.isPresent);
2777 p.writeInt32(infoRec->rec.signal.signalType);
2778 p.writeInt32(infoRec->rec.signal.alertPitch);
2779 p.writeInt32(infoRec->rec.signal.signal);
2780
2781 appendPrintBuf("%sisPresent=%X, signalType=%X, \
2782 alertPitch=%X, signal=%X, ",
2783 printBuf, (int)infoRec->rec.signal.isPresent,
2784 (int)infoRec->rec.signal.signalType,
2785 (int)infoRec->rec.signal.alertPitch,
2786 (int)infoRec->rec.signal.signal);
2787 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002788 break;
2789 case RIL_CDMA_REDIRECTING_NUMBER_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002790 if (infoRec->rec.redir.redirectingNumber.len >
2791 CDMA_NUMBER_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002792 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002793 expected not more than %d\n",
2794 (int)infoRec->rec.redir.redirectingNumber.len,
2795 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2796 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002797 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002798 string8 = (char*) malloc((infoRec->rec.redir.redirectingNumber
2799 .len + 1) * sizeof(char) );
2800 for (int i = 0;
2801 i < infoRec->rec.redir.redirectingNumber.len;
2802 i++) {
2803 string8[i] = infoRec->rec.redir.redirectingNumber.buf[i];
2804 }
Wink Saville43808972011-01-13 17:39:51 -08002805 string8[(int)infoRec->rec.redir.redirectingNumber.len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002806 writeStringToParcel(p, (const char*)string8);
2807 free(string8);
2808 string8 = NULL;
2809 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_type);
2810 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_plan);
2811 p.writeInt32(infoRec->rec.redir.redirectingNumber.pi);
2812 p.writeInt32(infoRec->rec.redir.redirectingNumber.si);
2813 p.writeInt32(infoRec->rec.redir.redirectingReason);
Wink Saville3d54e742009-05-18 18:00:44 -07002814 break;
2815 case RIL_CDMA_LINE_CONTROL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002816 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPolarityIncluded);
2817 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlToggle);
2818 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlReverse);
2819 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2820
2821 appendPrintBuf("%slineCtrlPolarityIncluded=%d, \
2822 lineCtrlToggle=%d, lineCtrlReverse=%d, \
2823 lineCtrlPowerDenial=%d, ", printBuf,
2824 (int)infoRec->rec.lineCtrl.lineCtrlPolarityIncluded,
2825 (int)infoRec->rec.lineCtrl.lineCtrlToggle,
2826 (int)infoRec->rec.lineCtrl.lineCtrlReverse,
2827 (int)infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2828 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002829 break;
2830 case RIL_CDMA_T53_CLIR_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002831 p.writeInt32((int)(infoRec->rec.clir.cause));
Wink Saville3d54e742009-05-18 18:00:44 -07002832
Wink Savillea592eeb2009-05-22 13:26:36 -07002833 appendPrintBuf("%scause%d", printBuf, infoRec->rec.clir.cause);
2834 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002835 break;
2836 case RIL_CDMA_T53_AUDIO_CONTROL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002837 p.writeInt32(infoRec->rec.audioCtrl.upLink);
2838 p.writeInt32(infoRec->rec.audioCtrl.downLink);
2839
2840 appendPrintBuf("%supLink=%d, downLink=%d, ", printBuf,
2841 infoRec->rec.audioCtrl.upLink,
2842 infoRec->rec.audioCtrl.downLink);
2843 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002844 break;
Wink Savillea592eeb2009-05-22 13:26:36 -07002845 case RIL_CDMA_T53_RELEASE_INFO_REC:
2846 // TODO(Moto): See David Krause, he has the answer:)
Wink Saville8eb2a122012-11-19 16:05:13 -08002847 RLOGE("RIL_CDMA_T53_RELEASE_INFO_REC: return INVALID_RESPONSE");
Wink Savillea592eeb2009-05-22 13:26:36 -07002848 return RIL_ERRNO_INVALID_RESPONSE;
2849 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08002850 RLOGE("Incorrect name value");
Wink Savillea592eeb2009-05-22 13:26:36 -07002851 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002852 }
2853 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002854 closeResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002855
Wink Savillea592eeb2009-05-22 13:26:36 -07002856 return 0;
Wink Saville3d54e742009-05-18 18:00:44 -07002857}
2858
Wink Savillea592eeb2009-05-22 13:26:36 -07002859static int responseRilSignalStrength(Parcel &p,
2860 void *response, size_t responselen) {
2861 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002862 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002863 return RIL_ERRNO_INVALID_RESPONSE;
2864 }
2865
Wink Savillec0114b32011-02-18 10:14:07 -08002866 if (responselen >= sizeof (RIL_SignalStrength_v5)) {
Etan Cohend3652192014-06-20 08:28:44 -07002867 RIL_SignalStrength_v10 *p_cur = ((RIL_SignalStrength_v10 *) response);
Wink Saville3d54e742009-05-18 18:00:44 -07002868
Wink Saville3d54e742009-05-18 18:00:44 -07002869 p.writeInt32(p_cur->GW_SignalStrength.signalStrength);
2870 p.writeInt32(p_cur->GW_SignalStrength.bitErrorRate);
2871 p.writeInt32(p_cur->CDMA_SignalStrength.dbm);
2872 p.writeInt32(p_cur->CDMA_SignalStrength.ecio);
2873 p.writeInt32(p_cur->EVDO_SignalStrength.dbm);
2874 p.writeInt32(p_cur->EVDO_SignalStrength.ecio);
2875 p.writeInt32(p_cur->EVDO_SignalStrength.signalNoiseRatio);
Wink Savillec0114b32011-02-18 10:14:07 -08002876 if (responselen >= sizeof (RIL_SignalStrength_v6)) {
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002877 /*
Wink Saville18e4ab12013-04-07 17:31:04 -07002878 * Fixup LTE for backwards compatibility
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002879 */
Wink Saville18e4ab12013-04-07 17:31:04 -07002880 if (s_callbacks.version <= 6) {
2881 // signalStrength: -1 -> 99
2882 if (p_cur->LTE_SignalStrength.signalStrength == -1) {
2883 p_cur->LTE_SignalStrength.signalStrength = 99;
2884 }
2885 // rsrp: -1 -> INT_MAX all other negative value to positive.
2886 // So remap here
2887 if (p_cur->LTE_SignalStrength.rsrp == -1) {
2888 p_cur->LTE_SignalStrength.rsrp = INT_MAX;
2889 } else if (p_cur->LTE_SignalStrength.rsrp < -1) {
2890 p_cur->LTE_SignalStrength.rsrp = -p_cur->LTE_SignalStrength.rsrp;
2891 }
2892 // rsrq: -1 -> INT_MAX
2893 if (p_cur->LTE_SignalStrength.rsrq == -1) {
2894 p_cur->LTE_SignalStrength.rsrq = INT_MAX;
2895 }
2896 // Not remapping rssnr is already using INT_MAX
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002897
Wink Saville18e4ab12013-04-07 17:31:04 -07002898 // cqi: -1 -> INT_MAX
2899 if (p_cur->LTE_SignalStrength.cqi == -1) {
2900 p_cur->LTE_SignalStrength.cqi = INT_MAX;
2901 }
2902 }
2903 p.writeInt32(p_cur->LTE_SignalStrength.signalStrength);
Wink Savillec0114b32011-02-18 10:14:07 -08002904 p.writeInt32(p_cur->LTE_SignalStrength.rsrp);
2905 p.writeInt32(p_cur->LTE_SignalStrength.rsrq);
2906 p.writeInt32(p_cur->LTE_SignalStrength.rssnr);
2907 p.writeInt32(p_cur->LTE_SignalStrength.cqi);
Etan Cohend3652192014-06-20 08:28:44 -07002908 if (responselen >= sizeof (RIL_SignalStrength_v10)) {
2909 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
2910 } else {
2911 p.writeInt32(INT_MAX);
2912 }
Wink Savillec0114b32011-02-18 10:14:07 -08002913 } else {
Wink Saville18e4ab12013-04-07 17:31:04 -07002914 p.writeInt32(99);
2915 p.writeInt32(INT_MAX);
2916 p.writeInt32(INT_MAX);
2917 p.writeInt32(INT_MAX);
2918 p.writeInt32(INT_MAX);
Etan Cohend3652192014-06-20 08:28:44 -07002919 p.writeInt32(INT_MAX);
Wink Savillec0114b32011-02-18 10:14:07 -08002920 }
johnwangfdf825f2009-05-22 15:50:34 -07002921
2922 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07002923 appendPrintBuf("%s[signalStrength=%d,bitErrorRate=%d,\
Wink Savillec0114b32011-02-18 10:14:07 -08002924 CDMA_SS.dbm=%d,CDMA_SSecio=%d,\
2925 EVDO_SS.dbm=%d,EVDO_SS.ecio=%d,\
2926 EVDO_SS.signalNoiseRatio=%d,\
2927 LTE_SS.signalStrength=%d,LTE_SS.rsrp=%d,LTE_SS.rsrq=%d,\
Etan Cohend3652192014-06-20 08:28:44 -07002928 LTE_SS.rssnr=%d,LTE_SS.cqi=%d,TDSCDMA_SS.rscp=%d]",
Wink Savillea592eeb2009-05-22 13:26:36 -07002929 printBuf,
2930 p_cur->GW_SignalStrength.signalStrength,
2931 p_cur->GW_SignalStrength.bitErrorRate,
2932 p_cur->CDMA_SignalStrength.dbm,
2933 p_cur->CDMA_SignalStrength.ecio,
2934 p_cur->EVDO_SignalStrength.dbm,
2935 p_cur->EVDO_SignalStrength.ecio,
Wink Savillec0114b32011-02-18 10:14:07 -08002936 p_cur->EVDO_SignalStrength.signalNoiseRatio,
2937 p_cur->LTE_SignalStrength.signalStrength,
2938 p_cur->LTE_SignalStrength.rsrp,
2939 p_cur->LTE_SignalStrength.rsrq,
2940 p_cur->LTE_SignalStrength.rssnr,
Etan Cohend3652192014-06-20 08:28:44 -07002941 p_cur->LTE_SignalStrength.cqi,
2942 p_cur->TD_SCDMA_SignalStrength.rscp);
Wink Savillea592eeb2009-05-22 13:26:36 -07002943 closeResponse;
2944
Wink Saville3d54e742009-05-18 18:00:44 -07002945 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08002946 RLOGE("invalid response length");
Wink Saville3d54e742009-05-18 18:00:44 -07002947 return RIL_ERRNO_INVALID_RESPONSE;
2948 }
2949
Wink Saville3d54e742009-05-18 18:00:44 -07002950 return 0;
2951}
2952
2953static int responseCallRing(Parcel &p, void *response, size_t responselen) {
2954 if ((response == NULL) || (responselen == 0)) {
2955 return responseVoid(p, response, responselen);
2956 } else {
2957 return responseCdmaSignalInfoRecord(p, response, responselen);
2958 }
2959}
2960
2961static int responseCdmaSignalInfoRecord(Parcel &p, void *response, size_t responselen) {
2962 if (response == NULL || responselen == 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002963 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002964 return RIL_ERRNO_INVALID_RESPONSE;
2965 }
2966
2967 if (responselen != sizeof (RIL_CDMA_SignalInfoRecord)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002968 RLOGE("invalid response length %d expected sizeof (RIL_CDMA_SignalInfoRecord) of %d\n",
Wink Saville3d54e742009-05-18 18:00:44 -07002969 (int)responselen, (int)sizeof (RIL_CDMA_SignalInfoRecord));
2970 return RIL_ERRNO_INVALID_RESPONSE;
2971 }
2972
2973 startResponse;
2974
2975 RIL_CDMA_SignalInfoRecord *p_cur = ((RIL_CDMA_SignalInfoRecord *) response);
2976 marshallSignalInfoRecord(p, *p_cur);
2977
2978 appendPrintBuf("%s[isPresent=%d,signalType=%d,alertPitch=%d\
2979 signal=%d]",
2980 printBuf,
2981 p_cur->isPresent,
2982 p_cur->signalType,
2983 p_cur->alertPitch,
2984 p_cur->signal);
2985
2986 closeResponse;
2987 return 0;
2988}
2989
Wink Savillea592eeb2009-05-22 13:26:36 -07002990static int responseCdmaCallWaiting(Parcel &p, void *response,
2991 size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07002992 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002993 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002994 return RIL_ERRNO_INVALID_RESPONSE;
2995 }
2996
Wink Savillec0114b32011-02-18 10:14:07 -08002997 if (responselen < sizeof(RIL_CDMA_CallWaiting_v6)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002998 RLOGW("Upgrade to ril version %d\n", RIL_VERSION);
Wink Savillec0114b32011-02-18 10:14:07 -08002999 }
3000
3001 RIL_CDMA_CallWaiting_v6 *p_cur = ((RIL_CDMA_CallWaiting_v6 *) response);
3002
3003 writeStringToParcel(p, p_cur->number);
3004 p.writeInt32(p_cur->numberPresentation);
3005 writeStringToParcel(p, p_cur->name);
3006 marshallSignalInfoRecord(p, p_cur->signalInfoRecord);
3007
3008 if (responselen >= sizeof(RIL_CDMA_CallWaiting_v6)) {
3009 p.writeInt32(p_cur->number_type);
3010 p.writeInt32(p_cur->number_plan);
3011 } else {
3012 p.writeInt32(0);
3013 p.writeInt32(0);
Wink Saville3d54e742009-05-18 18:00:44 -07003014 }
3015
3016 startResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07003017 appendPrintBuf("%snumber=%s,numberPresentation=%d, name=%s,\
3018 signalInfoRecord[isPresent=%d,signalType=%d,alertPitch=%d\
Wink Savillec0114b32011-02-18 10:14:07 -08003019 signal=%d,number_type=%d,number_plan=%d]",
Wink Saville3d54e742009-05-18 18:00:44 -07003020 printBuf,
3021 p_cur->number,
3022 p_cur->numberPresentation,
3023 p_cur->name,
3024 p_cur->signalInfoRecord.isPresent,
3025 p_cur->signalInfoRecord.signalType,
3026 p_cur->signalInfoRecord.alertPitch,
Wink Savillec0114b32011-02-18 10:14:07 -08003027 p_cur->signalInfoRecord.signal,
3028 p_cur->number_type,
3029 p_cur->number_plan);
Wink Saville3d54e742009-05-18 18:00:44 -07003030 closeResponse;
3031
3032 return 0;
3033}
3034
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003035static int responseSimRefresh(Parcel &p, void *response, size_t responselen) {
3036 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003037 RLOGE("responseSimRefresh: invalid response: NULL");
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003038 return RIL_ERRNO_INVALID_RESPONSE;
3039 }
3040
3041 startResponse;
3042 if (s_callbacks.version == 7) {
3043 RIL_SimRefreshResponse_v7 *p_cur = ((RIL_SimRefreshResponse_v7 *) response);
3044 p.writeInt32(p_cur->result);
3045 p.writeInt32(p_cur->ef_id);
3046 writeStringToParcel(p, p_cur->aid);
3047
3048 appendPrintBuf("%sresult=%d, ef_id=%d, aid=%s",
3049 printBuf,
3050 p_cur->result,
3051 p_cur->ef_id,
3052 p_cur->aid);
3053 } else {
3054 int *p_cur = ((int *) response);
3055 p.writeInt32(p_cur[0]);
3056 p.writeInt32(p_cur[1]);
3057 writeStringToParcel(p, NULL);
3058
3059 appendPrintBuf("%sresult=%d, ef_id=%d",
3060 printBuf,
3061 p_cur[0],
3062 p_cur[1]);
3063 }
3064 closeResponse;
3065
3066 return 0;
3067}
3068
Wink Saville8a9e0212013-04-09 12:11:38 -07003069static int responseCellInfoList(Parcel &p, void *response, size_t responselen)
3070{
3071 if (response == NULL && responselen != 0) {
3072 RLOGE("invalid response: NULL");
3073 return RIL_ERRNO_INVALID_RESPONSE;
3074 }
3075
3076 if (responselen % sizeof(RIL_CellInfo) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07003077 RLOGE("responseCellInfoList: invalid response length %d expected multiple of %d",
Wink Saville8a9e0212013-04-09 12:11:38 -07003078 (int)responselen, (int)sizeof(RIL_CellInfo));
3079 return RIL_ERRNO_INVALID_RESPONSE;
3080 }
3081
3082 int num = responselen / sizeof(RIL_CellInfo);
3083 p.writeInt32(num);
3084
3085 RIL_CellInfo *p_cur = (RIL_CellInfo *) response;
3086 startResponse;
3087 int i;
3088 for (i = 0; i < num; i++) {
3089 appendPrintBuf("%s[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", printBuf, i,
3090 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
3091 p.writeInt32((int)p_cur->cellInfoType);
3092 p.writeInt32(p_cur->registered);
3093 p.writeInt32(p_cur->timeStampType);
3094 p.writeInt64(p_cur->timeStamp);
3095 switch(p_cur->cellInfoType) {
3096 case RIL_CELL_INFO_TYPE_GSM: {
Wink Savillec57b3eb2013-04-17 12:51:41 -07003097 appendPrintBuf("%s GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,", printBuf,
Wink Saville8a9e0212013-04-09 12:11:38 -07003098 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
3099 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
3100 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
Wink Savillec57b3eb2013-04-17 12:51:41 -07003101 p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3102 appendPrintBuf("%s gsmSS: ss=%d,ber=%d],", printBuf,
Wink Saville8a9e0212013-04-09 12:11:38 -07003103 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
3104 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3105
3106 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
3107 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
3108 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
3109 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
Wink Saville8a9e0212013-04-09 12:11:38 -07003110 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
3111 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3112 break;
3113 }
Wink Savillec57b3eb2013-04-17 12:51:41 -07003114 case RIL_CELL_INFO_TYPE_WCDMA: {
3115 appendPrintBuf("%s WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,", printBuf,
3116 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
3117 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
3118 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
3119 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
3120 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3121 appendPrintBuf("%s wcdmaSS: ss=%d,ber=%d],", printBuf,
3122 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
3123 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3124
3125 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
3126 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
3127 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
3128 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
3129 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3130 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
3131 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3132 break;
3133 }
Wink Saville8a9e0212013-04-09 12:11:38 -07003134 case RIL_CELL_INFO_TYPE_CDMA: {
3135 appendPrintBuf("%s CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d", printBuf,
3136 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
3137 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
3138 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
3139 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
3140 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3141
3142 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
3143 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
3144 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
3145 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
3146 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3147
3148 appendPrintBuf("%s cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d", printBuf,
3149 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
3150 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
3151 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
3152 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
3153 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3154
3155 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
3156 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
3157 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
3158 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
3159 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3160 break;
3161 }
3162 case RIL_CELL_INFO_TYPE_LTE: {
3163 appendPrintBuf("%s LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d", printBuf,
3164 p_cur->CellInfo.lte.cellIdentityLte.mcc,
3165 p_cur->CellInfo.lte.cellIdentityLte.mnc,
3166 p_cur->CellInfo.lte.cellIdentityLte.ci,
3167 p_cur->CellInfo.lte.cellIdentityLte.pci,
3168 p_cur->CellInfo.lte.cellIdentityLte.tac);
3169
3170 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
3171 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
3172 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
3173 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
3174 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
3175
3176 appendPrintBuf("%s lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d", printBuf,
3177 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
3178 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
3179 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
3180 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
3181 p_cur->CellInfo.lte.signalStrengthLte.cqi,
3182 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3183 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
3184 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
3185 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
3186 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
3187 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
3188 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3189 break;
3190 }
Etan Cohend3652192014-06-20 08:28:44 -07003191 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
3192 appendPrintBuf("%s TDSCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,cpid=%d,", printBuf,
3193 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc,
3194 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc,
3195 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac,
3196 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid,
3197 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3198 appendPrintBuf("%s tdscdmaSS: rscp=%d],", printBuf,
3199 p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3200
3201 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
3202 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
3203 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
3204 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
3205 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3206 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3207 break;
3208 }
Wink Saville8a9e0212013-04-09 12:11:38 -07003209 }
3210 p_cur += 1;
3211 }
3212 removeLastChar;
3213 closeResponse;
3214
3215 return 0;
3216}
3217
Etan Cohend3652192014-06-20 08:28:44 -07003218static int responseHardwareConfig(Parcel &p, void *response, size_t responselen)
3219{
3220 if (response == NULL && responselen != 0) {
3221 RLOGE("invalid response: NULL");
3222 return RIL_ERRNO_INVALID_RESPONSE;
3223 }
3224
3225 if (responselen % sizeof(RIL_HardwareConfig) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07003226 RLOGE("responseHardwareConfig: invalid response length %d expected multiple of %d",
Etan Cohend3652192014-06-20 08:28:44 -07003227 (int)responselen, (int)sizeof(RIL_HardwareConfig));
3228 return RIL_ERRNO_INVALID_RESPONSE;
3229 }
3230
3231 int num = responselen / sizeof(RIL_HardwareConfig);
3232 int i;
3233 RIL_HardwareConfig *p_cur = (RIL_HardwareConfig *) response;
3234
3235 p.writeInt32(num);
3236
3237 startResponse;
3238 for (i = 0; i < num; i++) {
3239 switch (p_cur[i].type) {
3240 case RIL_HARDWARE_CONFIG_MODEM: {
3241 writeStringToParcel(p, p_cur[i].uuid);
3242 p.writeInt32((int)p_cur[i].state);
3243 p.writeInt32(p_cur[i].cfg.modem.rat);
3244 p.writeInt32(p_cur[i].cfg.modem.maxVoice);
3245 p.writeInt32(p_cur[i].cfg.modem.maxData);
3246 p.writeInt32(p_cur[i].cfg.modem.maxStandby);
3247
3248 appendPrintBuf("%s modem: uuid=%s,state=%d,rat=%08x,maxV=%d,maxD=%d,maxS=%d", printBuf,
3249 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.modem.rat,
3250 p_cur[i].cfg.modem.maxVoice, p_cur[i].cfg.modem.maxData, p_cur[i].cfg.modem.maxStandby);
3251 break;
3252 }
3253 case RIL_HARDWARE_CONFIG_SIM: {
3254 writeStringToParcel(p, p_cur[i].uuid);
3255 p.writeInt32((int)p_cur[i].state);
3256 writeStringToParcel(p, p_cur[i].cfg.sim.modemUuid);
3257
3258 appendPrintBuf("%s sim: uuid=%s,state=%d,modem-uuid=%s", printBuf,
3259 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.sim.modemUuid);
3260 break;
3261 }
3262 }
3263 }
3264 removeLastChar;
3265 closeResponse;
3266 return 0;
3267}
3268
Wink Saville8b4e4f72014-10-17 15:01:45 -07003269static int responseRadioCapability(Parcel &p, void *response, size_t responselen) {
3270 if (response == NULL) {
3271 RLOGE("invalid response: NULL");
3272 return RIL_ERRNO_INVALID_RESPONSE;
3273 }
3274
3275 if (responselen != sizeof (RIL_RadioCapability) ) {
3276 RLOGE("invalid response length was %d expected %d",
3277 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3278 return RIL_ERRNO_INVALID_RESPONSE;
3279 }
3280
3281 RIL_RadioCapability *p_cur = (RIL_RadioCapability *) response;
3282 p.writeInt32(p_cur->version);
3283 p.writeInt32(p_cur->session);
3284 p.writeInt32(p_cur->phase);
3285 p.writeInt32(p_cur->rat);
3286 writeStringToParcel(p, p_cur->logicalModemUuid);
3287 p.writeInt32(p_cur->status);
3288
3289 startResponse;
3290 appendPrintBuf("%s[version=%d,session=%d,phase=%d,\
Legler Wu8caf06f2014-10-29 14:02:14 +08003291 rat=%s,logicalModemUuid=%s,status=%d]",
Wink Saville8b4e4f72014-10-17 15:01:45 -07003292 printBuf,
3293 p_cur->version,
3294 p_cur->session,
3295 p_cur->phase,
3296 p_cur->rat,
Legler Wu8caf06f2014-10-29 14:02:14 +08003297 p_cur->logicalModemUuid,
Wink Saville8b4e4f72014-10-17 15:01:45 -07003298 p_cur->status);
3299 closeResponse;
3300 return 0;
3301}
3302
Amit Mahajan54563d32014-11-22 00:54:49 +00003303static int responseSSData(Parcel &p, void *response, size_t responselen) {
3304 RLOGD("In responseSSData");
3305 int num;
3306
3307 if (response == NULL && responselen != 0) {
3308 RLOGE("invalid response length was %d expected %d",
3309 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3310 return RIL_ERRNO_INVALID_RESPONSE;
3311 }
3312
3313 if (responselen != sizeof(RIL_StkCcUnsolSsResponse)) {
3314 RLOGE("invalid response length %d, expected %d",
3315 (int)responselen, (int)sizeof(RIL_StkCcUnsolSsResponse));
3316 return RIL_ERRNO_INVALID_RESPONSE;
3317 }
3318
3319 startResponse;
3320 RIL_StkCcUnsolSsResponse *p_cur = (RIL_StkCcUnsolSsResponse *) response;
3321 p.writeInt32(p_cur->serviceType);
3322 p.writeInt32(p_cur->requestType);
3323 p.writeInt32(p_cur->teleserviceType);
3324 p.writeInt32(p_cur->serviceClass);
3325 p.writeInt32(p_cur->result);
3326
3327 if (isServiceTypeCfQuery(p_cur->serviceType, p_cur->requestType)) {
3328 RLOGD("responseSSData CF type, num of Cf elements %d", p_cur->cfData.numValidIndexes);
3329 if (p_cur->cfData.numValidIndexes > NUM_SERVICE_CLASSES) {
3330 RLOGE("numValidIndexes is greater than max value %d, "
3331 "truncating it to max value", NUM_SERVICE_CLASSES);
3332 p_cur->cfData.numValidIndexes = NUM_SERVICE_CLASSES;
3333 }
3334 /* number of call info's */
3335 p.writeInt32(p_cur->cfData.numValidIndexes);
3336
3337 for (int i = 0; i < p_cur->cfData.numValidIndexes; i++) {
3338 RIL_CallForwardInfo cf = p_cur->cfData.cfInfo[i];
3339
3340 p.writeInt32(cf.status);
3341 p.writeInt32(cf.reason);
3342 p.writeInt32(cf.serviceClass);
3343 p.writeInt32(cf.toa);
3344 writeStringToParcel(p, cf.number);
3345 p.writeInt32(cf.timeSeconds);
3346 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
3347 (cf.status==1)?"enable":"disable", cf.reason, cf.serviceClass, cf.toa,
3348 (char*)cf.number, cf.timeSeconds);
3349 RLOGD("Data: %d,reason=%d,cls=%d,toa=%d,num=%s,tout=%d],", cf.status,
3350 cf.reason, cf.serviceClass, cf.toa, (char*)cf.number, cf.timeSeconds);
3351 }
3352 } else {
3353 p.writeInt32 (SS_INFO_MAX);
3354
3355 /* each int*/
3356 for (int i = 0; i < SS_INFO_MAX; i++) {
3357 appendPrintBuf("%s%d,", printBuf, p_cur->ssInfo[i]);
3358 RLOGD("Data: %d",p_cur->ssInfo[i]);
3359 p.writeInt32(p_cur->ssInfo[i]);
3360 }
3361 }
3362 removeLastChar;
3363 closeResponse;
3364
3365 return 0;
3366}
3367
3368static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType) {
3369 if ((reqType == SS_INTERROGATION) &&
3370 (serType == SS_CFU ||
3371 serType == SS_CF_BUSY ||
3372 serType == SS_CF_NO_REPLY ||
3373 serType == SS_CF_NOT_REACHABLE ||
3374 serType == SS_CF_ALL ||
3375 serType == SS_CF_ALL_CONDITIONAL)) {
3376 return true;
3377 }
3378 return false;
3379}
3380
Wink Saville3d54e742009-05-18 18:00:44 -07003381static void triggerEvLoop() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003382 int ret;
3383 if (!pthread_equal(pthread_self(), s_tid_dispatch)) {
3384 /* trigger event loop to wakeup. No reason to do this,
3385 * if we're in the event loop thread */
3386 do {
3387 ret = write (s_fdWakeupWrite, " ", 1);
3388 } while (ret < 0 && errno == EINTR);
3389 }
3390}
3391
Wink Saville3d54e742009-05-18 18:00:44 -07003392static void rilEventAddWakeup(struct ril_event *ev) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003393 ril_event_add(ev);
3394 triggerEvLoop();
3395}
3396
Wink Savillefd729372011-02-22 16:19:39 -08003397static void sendSimStatusAppInfo(Parcel &p, int num_apps, RIL_AppStatus appStatus[]) {
3398 p.writeInt32(num_apps);
3399 startResponse;
3400 for (int i = 0; i < num_apps; i++) {
3401 p.writeInt32(appStatus[i].app_type);
3402 p.writeInt32(appStatus[i].app_state);
3403 p.writeInt32(appStatus[i].perso_substate);
3404 writeStringToParcel(p, (const char*)(appStatus[i].aid_ptr));
3405 writeStringToParcel(p, (const char*)
3406 (appStatus[i].app_label_ptr));
3407 p.writeInt32(appStatus[i].pin1_replaced);
3408 p.writeInt32(appStatus[i].pin1);
3409 p.writeInt32(appStatus[i].pin2);
3410 appendPrintBuf("%s[app_type=%d,app_state=%d,perso_substate=%d,\
3411 aid_ptr=%s,app_label_ptr=%s,pin1_replaced=%d,pin1=%d,pin2=%d],",
3412 printBuf,
3413 appStatus[i].app_type,
3414 appStatus[i].app_state,
3415 appStatus[i].perso_substate,
3416 appStatus[i].aid_ptr,
3417 appStatus[i].app_label_ptr,
3418 appStatus[i].pin1_replaced,
3419 appStatus[i].pin1,
3420 appStatus[i].pin2);
3421 }
3422 closeResponse;
3423}
3424
Wink Savillef4c4d362009-04-02 01:37:03 -07003425static int responseSimStatus(Parcel &p, void *response, size_t responselen) {
3426 int i;
3427
3428 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003429 RLOGE("invalid response: NULL");
Wink Savillef4c4d362009-04-02 01:37:03 -07003430 return RIL_ERRNO_INVALID_RESPONSE;
3431 }
3432
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003433 if (responselen == sizeof (RIL_CardStatus_v6)) {
Wink Savillefd729372011-02-22 16:19:39 -08003434 RIL_CardStatus_v6 *p_cur = ((RIL_CardStatus_v6 *) response);
Wink Savillef4c4d362009-04-02 01:37:03 -07003435
Wink Savillefd729372011-02-22 16:19:39 -08003436 p.writeInt32(p_cur->card_state);
3437 p.writeInt32(p_cur->universal_pin_state);
3438 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3439 p.writeInt32(p_cur->cdma_subscription_app_index);
3440 p.writeInt32(p_cur->ims_subscription_app_index);
3441
3442 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003443 } else if (responselen == sizeof (RIL_CardStatus_v5)) {
Wink Savillefd729372011-02-22 16:19:39 -08003444 RIL_CardStatus_v5 *p_cur = ((RIL_CardStatus_v5 *) response);
3445
3446 p.writeInt32(p_cur->card_state);
3447 p.writeInt32(p_cur->universal_pin_state);
3448 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3449 p.writeInt32(p_cur->cdma_subscription_app_index);
3450 p.writeInt32(-1);
3451
3452 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003453 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003454 RLOGE("responseSimStatus: A RilCardStatus_v6 or _v5 expected\n");
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003455 return RIL_ERRNO_INVALID_RESPONSE;
Wink Savillef4c4d362009-04-02 01:37:03 -07003456 }
Wink Savillef4c4d362009-04-02 01:37:03 -07003457
3458 return 0;
Wink Saville3d54e742009-05-18 18:00:44 -07003459}
Wink Savillef4c4d362009-04-02 01:37:03 -07003460
Wink Savillea592eeb2009-05-22 13:26:36 -07003461static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3462 int num = responselen / sizeof(RIL_GSM_BroadcastSmsConfigInfo *);
Wink Savillef4c4d362009-04-02 01:37:03 -07003463 p.writeInt32(num);
3464
Wink Savillef4c4d362009-04-02 01:37:03 -07003465 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07003466 RIL_GSM_BroadcastSmsConfigInfo **p_cur =
3467 (RIL_GSM_BroadcastSmsConfigInfo **) response;
3468 for (int i = 0; i < num; i++) {
3469 p.writeInt32(p_cur[i]->fromServiceId);
3470 p.writeInt32(p_cur[i]->toServiceId);
3471 p.writeInt32(p_cur[i]->fromCodeScheme);
3472 p.writeInt32(p_cur[i]->toCodeScheme);
3473 p.writeInt32(p_cur[i]->selected);
3474
3475 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId=%d, \
3476 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]",
3477 printBuf, i, p_cur[i]->fromServiceId, p_cur[i]->toServiceId,
3478 p_cur[i]->fromCodeScheme, p_cur[i]->toCodeScheme,
3479 p_cur[i]->selected);
3480 }
Wink Savillef4c4d362009-04-02 01:37:03 -07003481 closeResponse;
3482
3483 return 0;
3484}
3485
Wink Savillea592eeb2009-05-22 13:26:36 -07003486static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3487 RIL_CDMA_BroadcastSmsConfigInfo **p_cur =
3488 (RIL_CDMA_BroadcastSmsConfigInfo **) response;
Wink Savillef4c4d362009-04-02 01:37:03 -07003489
Wink Savillea592eeb2009-05-22 13:26:36 -07003490 int num = responselen / sizeof (RIL_CDMA_BroadcastSmsConfigInfo *);
3491 p.writeInt32(num);
Wink Savillef4c4d362009-04-02 01:37:03 -07003492
3493 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07003494 for (int i = 0 ; i < num ; i++ ) {
3495 p.writeInt32(p_cur[i]->service_category);
3496 p.writeInt32(p_cur[i]->language);
3497 p.writeInt32(p_cur[i]->selected);
Wink Savillef4c4d362009-04-02 01:37:03 -07003498
Wink Savillea592eeb2009-05-22 13:26:36 -07003499 appendPrintBuf("%s [%d: srvice_category=%d, language =%d, \
3500 selected =%d], ",
3501 printBuf, i, p_cur[i]->service_category, p_cur[i]->language,
3502 p_cur[i]->selected);
Wink Savillef5903df2009-04-24 11:54:14 -07003503 }
Wink Savillea592eeb2009-05-22 13:26:36 -07003504 closeResponse;
Wink Savillef5903df2009-04-24 11:54:14 -07003505
Wink Savillef4c4d362009-04-02 01:37:03 -07003506 return 0;
3507}
3508
3509static int responseCdmaSms(Parcel &p, void *response, size_t responselen) {
3510 int num;
3511 int digitCount;
3512 int digitLimit;
3513 uint8_t uct;
3514 void* dest;
3515
Wink Saville8eb2a122012-11-19 16:05:13 -08003516 RLOGD("Inside responseCdmaSms");
Wink Savillef5903df2009-04-24 11:54:14 -07003517
Wink Savillef4c4d362009-04-02 01:37:03 -07003518 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003519 RLOGE("invalid response: NULL");
Wink Savillef4c4d362009-04-02 01:37:03 -07003520 return RIL_ERRNO_INVALID_RESPONSE;
3521 }
3522
Wink Savillef5903df2009-04-24 11:54:14 -07003523 if (responselen != sizeof(RIL_CDMA_SMS_Message)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003524 RLOGE("invalid response length was %d expected %d",
Wink Savillef5903df2009-04-24 11:54:14 -07003525 (int)responselen, (int)sizeof(RIL_CDMA_SMS_Message));
Wink Savillef4c4d362009-04-02 01:37:03 -07003526 return RIL_ERRNO_INVALID_RESPONSE;
3527 }
3528
3529 RIL_CDMA_SMS_Message *p_cur = (RIL_CDMA_SMS_Message *) response;
3530 p.writeInt32(p_cur->uTeleserviceID);
3531 p.write(&(p_cur->bIsServicePresent),sizeof(uct));
3532 p.writeInt32(p_cur->uServicecategory);
3533 p.writeInt32(p_cur->sAddress.digit_mode);
3534 p.writeInt32(p_cur->sAddress.number_mode);
3535 p.writeInt32(p_cur->sAddress.number_type);
3536 p.writeInt32(p_cur->sAddress.number_plan);
3537 p.write(&(p_cur->sAddress.number_of_digits), sizeof(uct));
3538 digitLimit= MIN((p_cur->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
3539 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3540 p.write(&(p_cur->sAddress.digits[digitCount]),sizeof(uct));
3541 }
3542
3543 p.writeInt32(p_cur->sSubAddress.subaddressType);
3544 p.write(&(p_cur->sSubAddress.odd),sizeof(uct));
3545 p.write(&(p_cur->sSubAddress.number_of_digits),sizeof(uct));
3546 digitLimit= MIN((p_cur->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
3547 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3548 p.write(&(p_cur->sSubAddress.digits[digitCount]),sizeof(uct));
3549 }
3550
3551 digitLimit= MIN((p_cur->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
3552 p.writeInt32(p_cur->uBearerDataLen);
3553 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3554 p.write(&(p_cur->aBearerData[digitCount]), sizeof(uct));
3555 }
3556
3557 startResponse;
3558 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
Wink Saville1b5fd232009-04-22 14:50:00 -07003559 sAddress.digit_mode=%d, sAddress.number_mode=%d, sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07003560 printBuf, p_cur->uTeleserviceID,p_cur->bIsServicePresent,p_cur->uServicecategory,
3561 p_cur->sAddress.digit_mode, p_cur->sAddress.number_mode,p_cur->sAddress.number_type);
3562 closeResponse;
3563
3564 return 0;
3565}
3566
Wink Savillec29360a2014-07-13 05:17:28 -07003567static int responseDcRtInfo(Parcel &p, void *response, size_t responselen)
3568{
3569 int num = responselen / sizeof(RIL_DcRtInfo);
3570 if ((responselen % sizeof(RIL_DcRtInfo) != 0) || (num != 1)) {
Amit Mahajan52500162014-07-29 17:36:48 -07003571 RLOGE("responseDcRtInfo: invalid response length %d expected multiple of %d",
Wink Savillec29360a2014-07-13 05:17:28 -07003572 (int)responselen, (int)sizeof(RIL_DcRtInfo));
3573 return RIL_ERRNO_INVALID_RESPONSE;
3574 }
3575
3576 startResponse;
3577 RIL_DcRtInfo *pDcRtInfo = (RIL_DcRtInfo *)response;
3578 p.writeInt64(pDcRtInfo->time);
3579 p.writeInt32(pDcRtInfo->powerState);
3580 appendPrintBuf("%s[time=%d,powerState=%d]", printBuf,
3581 pDcRtInfo->time,
3582 pDcRtInfo->powerState);
3583 closeResponse;
3584
3585 return 0;
3586}
3587
fengluf7408292015-04-14 14:53:55 -07003588static int responseLceStatus(Parcel &p, void *response, size_t responselen) {
3589 if (response == NULL || responselen != sizeof(RIL_LceStatusInfo)) {
3590 if (response == NULL) {
3591 RLOGE("invalid response: NULL");
3592 }
3593 else {
3594 RLOGE("responseLceStatus: invalid response length %d expecting len: d%",
3595 sizeof(RIL_LceStatusInfo), responselen);
3596 }
3597 return RIL_ERRNO_INVALID_RESPONSE;
3598 }
3599
3600 RIL_LceStatusInfo *p_cur = (RIL_LceStatusInfo *)response;
3601 p.write((void *)p_cur, 1); // p_cur->lce_status takes one byte.
3602 p.writeInt32(p_cur->actual_interval_ms);
3603
3604 startResponse;
3605 appendPrintBuf("LCE Status: %d, actual_interval_ms: %d",
3606 p_cur->lce_status, p_cur->actual_interval_ms);
3607 closeResponse;
3608
3609 return 0;
3610}
3611
3612static int responseLceData(Parcel &p, void *response, size_t responselen) {
3613 if (response == NULL || responselen != sizeof(RIL_LceDataInfo)) {
3614 if (response == NULL) {
3615 RLOGE("invalid response: NULL");
3616 }
3617 else {
3618 RLOGE("responseLceData: invalid response length %d expecting len: d%",
3619 sizeof(RIL_LceDataInfo), responselen);
3620 }
3621 return RIL_ERRNO_INVALID_RESPONSE;
3622 }
3623
3624 RIL_LceDataInfo *p_cur = (RIL_LceDataInfo *)response;
3625 p.writeInt32(p_cur->last_hop_capacity_kbps);
3626
3627 /* p_cur->confidence_level and p_cur->lce_suspended take 1 byte each.*/
3628 p.write((void *)&(p_cur->confidence_level), 1);
3629 p.write((void *)&(p_cur->lce_suspended), 1);
3630
3631 startResponse;
3632 appendPrintBuf("LCE info received: capacity %d confidence level %d
3633 and suspended %d",
3634 p_cur->last_hop_capacity_kbps, p_cur->confidence_level,
3635 p_cur->lce_suspended);
3636 closeResponse;
3637
3638 return 0;
3639}
3640
Prerepa Viswanadham73157492015-05-28 00:37:32 -07003641static int responseActivityData(Parcel &p, void *response, size_t responselen) {
3642 if (response == NULL || responselen != sizeof(RIL_ActivityStatsInfo)) {
3643 if (response == NULL) {
3644 RLOGE("invalid response: NULL");
3645 }
3646 else {
3647 RLOGE("responseActivityData: invalid response length %d expecting len: d%",
3648 sizeof(RIL_ActivityStatsInfo), responselen);
3649 }
3650 return RIL_ERRNO_INVALID_RESPONSE;
3651 }
3652
3653 RIL_ActivityStatsInfo *p_cur = (RIL_ActivityStatsInfo *)response;
3654 p.writeInt32(p_cur->sleep_mode_time_ms);
3655 p.writeInt32(p_cur->idle_mode_time_ms);
3656 for(int i = 0; i < RIL_NUM_TX_POWER_LEVELS; i++) {
3657 p.writeInt32(p_cur->tx_mode_time_ms[i]);
3658 }
3659 p.writeInt32(p_cur->rx_mode_time_ms);
3660
3661 startResponse;
3662 appendPrintBuf("Modem activity info received: sleep_mode_time_ms %d idle_mode_time_ms %d
3663 tx_mode_time_ms %d %d %d %d %d and rx_mode_time_ms %d",
3664 p_cur->sleep_mode_time_ms, p_cur->idle_mode_time_ms, p_cur->tx_mode_time_ms[0],
3665 p_cur->tx_mode_time_ms[1], p_cur->tx_mode_time_ms[2], p_cur->tx_mode_time_ms[3],
3666 p_cur->tx_mode_time_ms[4], p_cur->rx_mode_time_ms);
3667 closeResponse;
3668
3669 return 0;
3670}
3671
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003672/**
3673 * A write on the wakeup fd is done just to pop us out of select()
3674 * We empty the buffer here and then ril_event will reset the timers on the
3675 * way back down
3676 */
Wink Savillef4c4d362009-04-02 01:37:03 -07003677static void processWakeupCallback(int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003678 char buff[16];
3679 int ret;
3680
Wink Saville8eb2a122012-11-19 16:05:13 -08003681 RLOGV("processWakeupCallback");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003682
3683 /* empty our wakeup socket out */
3684 do {
3685 ret = read(s_fdWakeupRead, &buff, sizeof(buff));
Wink Saville7f856802009-06-09 10:23:37 -07003686 } while (ret > 0 || (ret < 0 && errno == EINTR));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003687}
3688
Etan Cohend3652192014-06-20 08:28:44 -07003689static void onCommandsSocketClosed(RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003690 int ret;
3691 RequestInfo *p_cur;
Etan Cohend3652192014-06-20 08:28:44 -07003692 /* Hook for current context
3693 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
3694 pthread_mutex_t * pendingRequestsMutexHook = &s_pendingRequestsMutex;
3695 /* pendingRequestsHook refer to &s_pendingRequests */
3696 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003697
Etan Cohend3652192014-06-20 08:28:44 -07003698#if (SIM_COUNT >= 2)
3699 if (socket_id == RIL_SOCKET_2) {
3700 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
3701 pendingRequestsHook = &s_pendingRequests_socket2;
3702 }
3703#if (SIM_COUNT >= 3)
3704 else if (socket_id == RIL_SOCKET_3) {
3705 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
3706 pendingRequestsHook = &s_pendingRequests_socket3;
3707 }
3708#endif
3709#if (SIM_COUNT >= 4)
3710 else if (socket_id == RIL_SOCKET_4) {
3711 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
3712 pendingRequestsHook = &s_pendingRequests_socket4;
3713 }
3714#endif
3715#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003716 /* mark pending requests as "cancelled" so we dont report responses */
Etan Cohend3652192014-06-20 08:28:44 -07003717 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003718 assert (ret == 0);
3719
Etan Cohend3652192014-06-20 08:28:44 -07003720 p_cur = *pendingRequestsHook;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003721
Etan Cohend3652192014-06-20 08:28:44 -07003722 for (p_cur = *pendingRequestsHook
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003723 ; p_cur != NULL
3724 ; p_cur = p_cur->p_next
3725 ) {
3726 p_cur->cancelled = 1;
3727 }
3728
Etan Cohend3652192014-06-20 08:28:44 -07003729 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003730 assert (ret == 0);
3731}
3732
Wink Savillef4c4d362009-04-02 01:37:03 -07003733static void processCommandsCallback(int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003734 RecordStream *p_rs;
3735 void *p_record;
3736 size_t recordlen;
3737 int ret;
Etan Cohend3652192014-06-20 08:28:44 -07003738 SocketListenParam *p_info = (SocketListenParam *)param;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003739
Etan Cohend3652192014-06-20 08:28:44 -07003740 assert(fd == p_info->fdCommand);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003741
Etan Cohend3652192014-06-20 08:28:44 -07003742 p_rs = p_info->p_rs;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003743
3744 for (;;) {
3745 /* loop until EAGAIN/EINTR, end of stream, or other error */
3746 ret = record_stream_get_next(p_rs, &p_record, &recordlen);
3747
3748 if (ret == 0 && p_record == NULL) {
3749 /* end-of-stream */
3750 break;
3751 } else if (ret < 0) {
3752 break;
3753 } else if (ret == 0) { /* && p_record != NULL */
Etan Cohend3652192014-06-20 08:28:44 -07003754 processCommandBuffer(p_record, recordlen, p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003755 }
3756 }
3757
3758 if (ret == 0 || !(errno == EAGAIN || errno == EINTR)) {
3759 /* fatal error or end-of-stream */
3760 if (ret != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003761 RLOGE("error on reading command socket errno:%d\n", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003762 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003763 RLOGW("EOS. Closing command socket.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003764 }
Wink Saville7f856802009-06-09 10:23:37 -07003765
Etan Cohend3652192014-06-20 08:28:44 -07003766 close(fd);
3767 p_info->fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003768
Etan Cohend3652192014-06-20 08:28:44 -07003769 ril_event_del(p_info->commands_event);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003770
3771 record_stream_free(p_rs);
3772
3773 /* start listening for new connections again */
3774 rilEventAddWakeup(&s_listen_event);
3775
Etan Cohend3652192014-06-20 08:28:44 -07003776 onCommandsSocketClosed(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003777 }
3778}
3779
3780
Etan Cohend3652192014-06-20 08:28:44 -07003781static void onNewCommandConnect(RIL_SOCKET_ID socket_id) {
Wink Saville5b9df332011-04-06 16:24:21 -07003782 // Inform we are connected and the ril version
Jake Hambya9c18d12011-04-12 23:32:08 -07003783 int rilVer = s_callbacks.version;
Etan Cohend3652192014-06-20 08:28:44 -07003784 RIL_UNSOL_RESPONSE(RIL_UNSOL_RIL_CONNECTED,
3785 &rilVer, sizeof(rilVer), socket_id);
Wink Saville5b9df332011-04-06 16:24:21 -07003786
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003787 // implicit radio state changed
Etan Cohend3652192014-06-20 08:28:44 -07003788 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
3789 NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003790
3791 // Send last NITZ time data, in case it was missed
3792 if (s_lastNITZTimeData != NULL) {
Etan Cohend3652192014-06-20 08:28:44 -07003793 sendResponseRaw(s_lastNITZTimeData, s_lastNITZTimeDataSize, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003794
3795 free(s_lastNITZTimeData);
3796 s_lastNITZTimeData = NULL;
3797 }
3798
3799 // Get version string
3800 if (s_callbacks.getVersion != NULL) {
3801 const char *version;
3802 version = s_callbacks.getVersion();
Wink Saville8eb2a122012-11-19 16:05:13 -08003803 RLOGI("RIL Daemon version: %s\n", version);
Wink Saville7f856802009-06-09 10:23:37 -07003804
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003805 property_set(PROPERTY_RIL_IMPL, version);
3806 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003807 RLOGI("RIL Daemon version: unavailable\n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003808 property_set(PROPERTY_RIL_IMPL, "unavailable");
3809 }
3810
3811}
3812
Wink Savillef4c4d362009-04-02 01:37:03 -07003813static void listenCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003814 int ret;
3815 int err;
3816 int is_phone_socket;
Etan Cohend3652192014-06-20 08:28:44 -07003817 int fdCommand = -1;
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003818 char* processName;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003819 RecordStream *p_rs;
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003820 MySocketListenParam* listenParam;
3821 RilSocket *sapSocket = NULL;
3822 socketClient *sClient = NULL;
3823
Etan Cohend3652192014-06-20 08:28:44 -07003824 SocketListenParam *p_info = (SocketListenParam *)param;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003825
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003826 if(RIL_SAP_SOCKET == p_info->type) {
3827 listenParam = (MySocketListenParam *)param;
3828 sapSocket = listenParam->socket;
3829 }
3830
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003831 struct sockaddr_un peeraddr;
3832 socklen_t socklen = sizeof (peeraddr);
3833
3834 struct ucred creds;
3835 socklen_t szCreds = sizeof(creds);
3836
3837 struct passwd *pwd = NULL;
3838
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003839 if(NULL == sapSocket) {
3840 assert (*p_info->fdCommand < 0);
3841 assert (fd == *p_info->fdListen);
3842 processName = PHONE_PROCESS;
3843 } else {
3844 assert (sapSocket->commandFd < 0);
3845 assert (fd == sapSocket->listenFd);
3846 processName = BLUETOOTH_PROCESS;
3847 }
3848
Wink Saville7f856802009-06-09 10:23:37 -07003849
Etan Cohend3652192014-06-20 08:28:44 -07003850 fdCommand = accept(fd, (sockaddr *) &peeraddr, &socklen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003851
Etan Cohend3652192014-06-20 08:28:44 -07003852 if (fdCommand < 0 ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003853 RLOGE("Error on accept() errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003854 /* start listening for new connections again */
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003855 if(NULL == sapSocket) {
3856 rilEventAddWakeup(p_info->listen_event);
3857 } else {
3858 rilEventAddWakeup(sapSocket->getListenEvent());
3859 }
Etan Cohend3652192014-06-20 08:28:44 -07003860 return;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003861 }
3862
3863 /* check the credential of the other side and only accept socket from
3864 * phone process
Wink Saville7f856802009-06-09 10:23:37 -07003865 */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003866 errno = 0;
3867 is_phone_socket = 0;
Wink Savillef4c4d362009-04-02 01:37:03 -07003868
Etan Cohend3652192014-06-20 08:28:44 -07003869 err = getsockopt(fdCommand, SOL_SOCKET, SO_PEERCRED, &creds, &szCreds);
Wink Savillef4c4d362009-04-02 01:37:03 -07003870
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003871 if (err == 0 && szCreds > 0) {
Wink Savillef4c4d362009-04-02 01:37:03 -07003872 errno = 0;
3873 pwd = getpwuid(creds.uid);
3874 if (pwd != NULL) {
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003875 if (strcmp(pwd->pw_name, processName) == 0) {
Wink Savillef4c4d362009-04-02 01:37:03 -07003876 is_phone_socket = 1;
3877 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003878 RLOGE("RILD can't accept socket from process %s", pwd->pw_name);
Wink Savillef4c4d362009-04-02 01:37:03 -07003879 }
3880 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003881 RLOGE("Error on getpwuid() errno: %d", errno);
Wink Savillef4c4d362009-04-02 01:37:03 -07003882 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003883 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003884 RLOGD("Error on getsockopt() errno: %d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003885 }
3886
Etan Cohend3652192014-06-20 08:28:44 -07003887 if (!is_phone_socket) {
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003888 RLOGE("RILD must accept socket from %s", processName);
Wink Saville7f856802009-06-09 10:23:37 -07003889
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003890 close(fdCommand);
3891 fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003892
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003893 if(NULL == sapSocket) {
3894 onCommandsSocketClosed(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003895
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003896 /* start listening for new connections again */
3897 rilEventAddWakeup(p_info->listen_event);
3898 } else {
3899 sapSocket->onCommandsSocketClosed();
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003900
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003901 /* start listening for new connections again */
3902 rilEventAddWakeup(sapSocket->getListenEvent());
3903 }
3904
3905 return;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003906 }
3907
Etan Cohend3652192014-06-20 08:28:44 -07003908 ret = fcntl(fdCommand, F_SETFL, O_NONBLOCK);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003909
3910 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003911 RLOGE ("Error setting O_NONBLOCK errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003912 }
3913
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003914 if(NULL == sapSocket) {
3915 RLOGI("libril: new connection to %s", rilSocketIdToString(p_info->socket_id));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003916
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003917 p_info->fdCommand = fdCommand;
3918 p_rs = record_stream_new(p_info->fdCommand, MAX_COMMAND_BYTES);
3919 p_info->p_rs = p_rs;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003920
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003921 ril_event_set (p_info->commands_event, p_info->fdCommand, 1,
Etan Cohend3652192014-06-20 08:28:44 -07003922 p_info->processCommandsCallback, p_info);
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003923 rilEventAddWakeup (p_info->commands_event);
Etan Cohend3652192014-06-20 08:28:44 -07003924
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003925 onNewCommandConnect(p_info->socket_id);
3926 } else {
3927 RLOGI("libril: new connection");
Etan Cohend3652192014-06-20 08:28:44 -07003928
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003929 sapSocket->setCommandFd(fdCommand);
3930 p_rs = record_stream_new(sapSocket->getCommandFd(), MAX_COMMAND_BYTES);
3931 sClient = new socketClient(sapSocket,p_rs);
3932 ril_event_set (sapSocket->getCallbackEvent(), sapSocket->getCommandFd(), 1,
3933 sapSocket->getCommandCb(), sClient);
3934
3935 rilEventAddWakeup(sapSocket->getCallbackEvent());
3936 sapSocket->onNewCommandConnect();
3937 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003938}
3939
3940static void freeDebugCallbackArgs(int number, char **args) {
3941 for (int i = 0; i < number; i++) {
3942 if (args[i] != NULL) {
3943 free(args[i]);
3944 }
3945 }
3946 free(args);
3947}
3948
Wink Savillef4c4d362009-04-02 01:37:03 -07003949static void debugCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003950 int acceptFD, option;
3951 struct sockaddr_un peeraddr;
3952 socklen_t socklen = sizeof (peeraddr);
3953 int data;
3954 unsigned int qxdm_data[6];
3955 const char *deactData[1] = {"1"};
3956 char *actData[1];
3957 RIL_Dial dialData;
3958 int hangupData[1] = {1};
3959 int number;
3960 char **args;
Etan Cohend3652192014-06-20 08:28:44 -07003961 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
3962 int sim_id = 0;
3963
3964 RLOGI("debugCallback for socket %s", rilSocketIdToString(socket_id));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003965
3966 acceptFD = accept (fd, (sockaddr *) &peeraddr, &socklen);
3967
3968 if (acceptFD < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003969 RLOGE ("error accepting on debug port: %d\n", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003970 return;
3971 }
3972
3973 if (recv(acceptFD, &number, sizeof(int), 0) != sizeof(int)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003974 RLOGE ("error reading on socket: number of Args: \n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003975 return;
3976 }
3977 args = (char **) malloc(sizeof(char*) * number);
3978
3979 for (int i = 0; i < number; i++) {
3980 int len;
3981 if (recv(acceptFD, &len, sizeof(int), 0) != sizeof(int)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003982 RLOGE ("error reading on socket: Len of Args: \n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003983 freeDebugCallbackArgs(i, args);
3984 return;
3985 }
3986 // +1 for null-term
3987 args[i] = (char *) malloc((sizeof(char) * len) + 1);
Wink Saville7f856802009-06-09 10:23:37 -07003988 if (recv(acceptFD, args[i], sizeof(char) * len, 0)
Wink Saville1b5fd232009-04-22 14:50:00 -07003989 != (int)sizeof(char) * len) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003990 RLOGE ("error reading on socket: Args[%d] \n", i);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003991 freeDebugCallbackArgs(i, args);
3992 return;
3993 }
3994 char * buf = args[i];
3995 buf[len] = 0;
Etan Cohend3652192014-06-20 08:28:44 -07003996 if ((i+1) == number) {
3997 /* The last argument should be sim id 0(SIM1)~3(SIM4) */
3998 sim_id = atoi(args[i]);
3999 switch (sim_id) {
4000 case 0:
4001 socket_id = RIL_SOCKET_1;
4002 break;
4003 #if (SIM_COUNT >= 2)
4004 case 1:
4005 socket_id = RIL_SOCKET_2;
4006 break;
4007 #endif
4008 #if (SIM_COUNT >= 3)
4009 case 2:
4010 socket_id = RIL_SOCKET_3;
4011 break;
4012 #endif
4013 #if (SIM_COUNT >= 4)
4014 case 3:
4015 socket_id = RIL_SOCKET_4;
4016 break;
4017 #endif
4018 default:
4019 socket_id = RIL_SOCKET_1;
4020 break;
4021 }
4022 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004023 }
4024
4025 switch (atoi(args[0])) {
4026 case 0:
Wink Saville8eb2a122012-11-19 16:05:13 -08004027 RLOGI ("Connection on debug port: issuing reset.");
Etan Cohend3652192014-06-20 08:28:44 -07004028 issueLocalRequest(RIL_REQUEST_RESET_RADIO, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004029 break;
4030 case 1:
Wink Saville8eb2a122012-11-19 16:05:13 -08004031 RLOGI ("Connection on debug port: issuing radio power off.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004032 data = 0;
Etan Cohend3652192014-06-20 08:28:44 -07004033 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004034 // Close the socket
Etan Cohend3652192014-06-20 08:28:44 -07004035 if (socket_id == RIL_SOCKET_1 && s_ril_param_socket.fdCommand > 0) {
4036 close(s_ril_param_socket.fdCommand);
4037 s_ril_param_socket.fdCommand = -1;
4038 }
4039 #if (SIM_COUNT == 2)
4040 else if (socket_id == RIL_SOCKET_2 && s_ril_param_socket2.fdCommand > 0) {
4041 close(s_ril_param_socket2.fdCommand);
4042 s_ril_param_socket2.fdCommand = -1;
4043 }
4044 #endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004045 break;
4046 case 2:
Wink Saville8eb2a122012-11-19 16:05:13 -08004047 RLOGI ("Debug port: issuing unsolicited voice network change.");
Etan Cohend3652192014-06-20 08:28:44 -07004048 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004049 break;
4050 case 3:
Wink Saville8eb2a122012-11-19 16:05:13 -08004051 RLOGI ("Debug port: QXDM log enable.");
Xia Wangd855ef42010-07-27 17:26:55 -07004052 qxdm_data[0] = 65536; // head.func_tag
4053 qxdm_data[1] = 16; // head.len
4054 qxdm_data[2] = 1; // mode: 1 for 'start logging'
4055 qxdm_data[3] = 32; // log_file_size: 32megabytes
4056 qxdm_data[4] = 0; // log_mask
4057 qxdm_data[5] = 8; // log_max_fileindex
Wink Saville7f856802009-06-09 10:23:37 -07004058 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Etan Cohend3652192014-06-20 08:28:44 -07004059 6 * sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004060 break;
4061 case 4:
Wink Saville8eb2a122012-11-19 16:05:13 -08004062 RLOGI ("Debug port: QXDM log disable.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004063 qxdm_data[0] = 65536;
4064 qxdm_data[1] = 16;
Xia Wangd855ef42010-07-27 17:26:55 -07004065 qxdm_data[2] = 0; // mode: 0 for 'stop logging'
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004066 qxdm_data[3] = 32;
4067 qxdm_data[4] = 0;
Xia Wangd855ef42010-07-27 17:26:55 -07004068 qxdm_data[5] = 8;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004069 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Etan Cohend3652192014-06-20 08:28:44 -07004070 6 * sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004071 break;
4072 case 5:
Wink Saville8eb2a122012-11-19 16:05:13 -08004073 RLOGI("Debug port: Radio On");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004074 data = 1;
Etan Cohend3652192014-06-20 08:28:44 -07004075 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004076 sleep(2);
4077 // Set network selection automatic.
Etan Cohend3652192014-06-20 08:28:44 -07004078 issueLocalRequest(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004079 break;
4080 case 6:
Wink Saville8eb2a122012-11-19 16:05:13 -08004081 RLOGI("Debug port: Setup Data Call, Apn :%s\n", args[1]);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004082 actData[0] = args[1];
Wink Saville7f856802009-06-09 10:23:37 -07004083 issueLocalRequest(RIL_REQUEST_SETUP_DATA_CALL, &actData,
Etan Cohend3652192014-06-20 08:28:44 -07004084 sizeof(actData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004085 break;
4086 case 7:
Wink Saville8eb2a122012-11-19 16:05:13 -08004087 RLOGI("Debug port: Deactivate Data Call");
Wink Saville7f856802009-06-09 10:23:37 -07004088 issueLocalRequest(RIL_REQUEST_DEACTIVATE_DATA_CALL, &deactData,
Etan Cohend3652192014-06-20 08:28:44 -07004089 sizeof(deactData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004090 break;
4091 case 8:
Wink Saville8eb2a122012-11-19 16:05:13 -08004092 RLOGI("Debug port: Dial Call");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004093 dialData.clir = 0;
4094 dialData.address = args[1];
Etan Cohend3652192014-06-20 08:28:44 -07004095 issueLocalRequest(RIL_REQUEST_DIAL, &dialData, sizeof(dialData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004096 break;
4097 case 9:
Wink Saville8eb2a122012-11-19 16:05:13 -08004098 RLOGI("Debug port: Answer Call");
Etan Cohend3652192014-06-20 08:28:44 -07004099 issueLocalRequest(RIL_REQUEST_ANSWER, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004100 break;
4101 case 10:
Wink Saville8eb2a122012-11-19 16:05:13 -08004102 RLOGI("Debug port: End Call");
Wink Saville7f856802009-06-09 10:23:37 -07004103 issueLocalRequest(RIL_REQUEST_HANGUP, &hangupData,
Etan Cohend3652192014-06-20 08:28:44 -07004104 sizeof(hangupData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004105 break;
4106 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004107 RLOGE ("Invalid request");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004108 break;
4109 }
4110 freeDebugCallbackArgs(number, args);
4111 close(acceptFD);
4112}
4113
4114
Wink Savillef4c4d362009-04-02 01:37:03 -07004115static void userTimerCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004116 UserCallbackInfo *p_info;
4117
4118 p_info = (UserCallbackInfo *)param;
4119
4120 p_info->p_callback(p_info->userParam);
4121
4122
4123 // FIXME generalize this...there should be a cancel mechanism
4124 if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) {
4125 s_last_wake_timeout_info = NULL;
4126 }
4127
4128 free(p_info);
4129}
4130
4131
4132static void *
Wink Savillef4c4d362009-04-02 01:37:03 -07004133eventLoop(void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004134 int ret;
4135 int filedes[2];
4136
4137 ril_event_init();
4138
4139 pthread_mutex_lock(&s_startupMutex);
4140
4141 s_started = 1;
4142 pthread_cond_broadcast(&s_startupCond);
4143
4144 pthread_mutex_unlock(&s_startupMutex);
4145
4146 ret = pipe(filedes);
4147
4148 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004149 RLOGE("Error in pipe() errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004150 return NULL;
4151 }
4152
4153 s_fdWakeupRead = filedes[0];
4154 s_fdWakeupWrite = filedes[1];
4155
4156 fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK);
4157
4158 ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,
4159 processWakeupCallback, NULL);
4160
4161 rilEventAddWakeup (&s_wakeupfd_event);
4162
4163 // Only returns on error
4164 ril_event_loop();
Wink Saville8eb2a122012-11-19 16:05:13 -08004165 RLOGE ("error in event_loop_base errno:%d", errno);
Kazuhiro Ondo5cdc1352011-10-14 17:50:58 -05004166 // kill self to restart on error
4167 kill(0, SIGKILL);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004168
4169 return NULL;
4170}
4171
Wink Saville7f856802009-06-09 10:23:37 -07004172extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07004173RIL_startEventLoop(void) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004174 /* spin up eventLoop thread and wait for it to get started */
4175 s_started = 0;
4176 pthread_mutex_lock(&s_startupMutex);
4177
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004178 pthread_attr_t attr;
4179 pthread_attr_init(&attr);
Wink Saville7f856802009-06-09 10:23:37 -07004180 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004181
Elliott Hughesfd81e712014-01-06 12:46:02 -08004182 int result = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
4183 if (result != 0) {
4184 RLOGE("Failed to create dispatch thread: %s", strerror(result));
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004185 goto done;
4186 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004187
4188 while (s_started == 0) {
4189 pthread_cond_wait(&s_startupCond, &s_startupMutex);
4190 }
4191
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004192done:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004193 pthread_mutex_unlock(&s_startupMutex);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004194}
4195
4196// Used for testing purpose only.
4197extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) {
4198 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4199}
4200
Etan Cohend3652192014-06-20 08:28:44 -07004201static void startListen(RIL_SOCKET_ID socket_id, SocketListenParam* socket_listen_p) {
4202 int fdListen = -1;
4203 int ret;
4204 char socket_name[10];
4205
4206 memset(socket_name, 0, sizeof(char)*10);
4207
4208 switch(socket_id) {
4209 case RIL_SOCKET_1:
4210 strncpy(socket_name, RIL_getRilSocketName(), 9);
4211 break;
4212 #if (SIM_COUNT >= 2)
4213 case RIL_SOCKET_2:
4214 strncpy(socket_name, SOCKET2_NAME_RIL, 9);
4215 break;
4216 #endif
4217 #if (SIM_COUNT >= 3)
4218 case RIL_SOCKET_3:
4219 strncpy(socket_name, SOCKET3_NAME_RIL, 9);
4220 break;
4221 #endif
4222 #if (SIM_COUNT >= 4)
4223 case RIL_SOCKET_4:
4224 strncpy(socket_name, SOCKET4_NAME_RIL, 9);
4225 break;
4226 #endif
4227 default:
4228 RLOGE("Socket id is wrong!!");
4229 return;
4230 }
4231
4232 RLOGI("Start to listen %s", rilSocketIdToString(socket_id));
4233
4234 fdListen = android_get_control_socket(socket_name);
4235 if (fdListen < 0) {
4236 RLOGE("Failed to get socket %s", socket_name);
4237 exit(-1);
4238 }
4239
4240 ret = listen(fdListen, 4);
4241
4242 if (ret < 0) {
4243 RLOGE("Failed to listen on control socket '%d': %s",
4244 fdListen, strerror(errno));
4245 exit(-1);
4246 }
4247 socket_listen_p->fdListen = fdListen;
4248
4249 /* note: non-persistent so we can accept only one connection at a time */
4250 ril_event_set (socket_listen_p->listen_event, fdListen, false,
4251 listenCallback, socket_listen_p);
4252
4253 rilEventAddWakeup (socket_listen_p->listen_event);
4254}
4255
Wink Saville7f856802009-06-09 10:23:37 -07004256extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07004257RIL_register (const RIL_RadioFunctions *callbacks) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004258 int ret;
4259 int flags;
4260
Etan Cohend3652192014-06-20 08:28:44 -07004261 RLOGI("SIM_COUNT: %d", SIM_COUNT);
4262
Wink Saville43808972011-01-13 17:39:51 -08004263 if (callbacks == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004264 RLOGE("RIL_register: RIL_RadioFunctions * null");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004265 return;
4266 }
Wink Saville43808972011-01-13 17:39:51 -08004267 if (callbacks->version < RIL_VERSION_MIN) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004268 RLOGE("RIL_register: version %d is to old, min version is %d",
Wink Saville43808972011-01-13 17:39:51 -08004269 callbacks->version, RIL_VERSION_MIN);
4270 return;
Wink Saville3a4840b2010-04-07 13:29:58 -07004271 }
Wink Saville43808972011-01-13 17:39:51 -08004272 if (callbacks->version > RIL_VERSION) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004273 RLOGE("RIL_register: version %d is too new, max version is %d",
Wink Saville43808972011-01-13 17:39:51 -08004274 callbacks->version, RIL_VERSION);
4275 return;
4276 }
Wink Saville8eb2a122012-11-19 16:05:13 -08004277 RLOGE("RIL_register: RIL version %d", callbacks->version);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004278
4279 if (s_registerCalled > 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004280 RLOGE("RIL_register has been called more than once. "
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004281 "Subsequent call ignored");
4282 return;
4283 }
4284
4285 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4286
Etan Cohend3652192014-06-20 08:28:44 -07004287 /* Initialize socket1 parameters */
4288 s_ril_param_socket = {
4289 RIL_SOCKET_1, /* socket_id */
4290 -1, /* fdListen */
4291 -1, /* fdCommand */
4292 PHONE_PROCESS, /* processName */
4293 &s_commands_event, /* commands_event */
4294 &s_listen_event, /* listen_event */
4295 processCommandsCallback, /* processCommandsCallback */
4296 NULL /* p_rs */
4297 };
4298
4299#if (SIM_COUNT >= 2)
4300 s_ril_param_socket2 = {
4301 RIL_SOCKET_2, /* socket_id */
4302 -1, /* fdListen */
4303 -1, /* fdCommand */
4304 PHONE_PROCESS, /* processName */
4305 &s_commands_event_socket2, /* commands_event */
4306 &s_listen_event_socket2, /* listen_event */
4307 processCommandsCallback, /* processCommandsCallback */
4308 NULL /* p_rs */
4309 };
4310#endif
4311
4312#if (SIM_COUNT >= 3)
4313 s_ril_param_socket3 = {
4314 RIL_SOCKET_3, /* socket_id */
4315 -1, /* fdListen */
4316 -1, /* fdCommand */
4317 PHONE_PROCESS, /* processName */
4318 &s_commands_event_socket3, /* commands_event */
4319 &s_listen_event_socket3, /* listen_event */
4320 processCommandsCallback, /* processCommandsCallback */
4321 NULL /* p_rs */
4322 };
4323#endif
4324
4325#if (SIM_COUNT >= 4)
4326 s_ril_param_socket4 = {
4327 RIL_SOCKET_4, /* socket_id */
4328 -1, /* fdListen */
4329 -1, /* fdCommand */
4330 PHONE_PROCESS, /* processName */
4331 &s_commands_event_socket4, /* commands_event */
4332 &s_listen_event_socket4, /* listen_event */
4333 processCommandsCallback, /* processCommandsCallback */
4334 NULL /* p_rs */
4335 };
4336#endif
4337
4338
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004339 s_registerCalled = 1;
4340
Etan Cohend3652192014-06-20 08:28:44 -07004341 RLOGI("s_registerCalled flag set, %d", s_started);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004342 // Little self-check
4343
Wink Savillef4c4d362009-04-02 01:37:03 -07004344 for (int i = 0; i < (int)NUM_ELEMS(s_commands); i++) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004345 assert(i == s_commands[i].requestNumber);
4346 }
4347
Wink Savillef4c4d362009-04-02 01:37:03 -07004348 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses); i++) {
Wink Saville7f856802009-06-09 10:23:37 -07004349 assert(i + RIL_UNSOL_RESPONSE_BASE
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004350 == s_unsolResponses[i].requestNumber);
4351 }
4352
4353 // New rild impl calls RIL_startEventLoop() first
4354 // old standalone impl wants it here.
4355
4356 if (s_started == 0) {
4357 RIL_startEventLoop();
4358 }
4359
Etan Cohend3652192014-06-20 08:28:44 -07004360 // start listen socket1
4361 startListen(RIL_SOCKET_1, &s_ril_param_socket);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004362
Etan Cohend3652192014-06-20 08:28:44 -07004363#if (SIM_COUNT >= 2)
4364 // start listen socket2
4365 startListen(RIL_SOCKET_2, &s_ril_param_socket2);
4366#endif /* (SIM_COUNT == 2) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004367
Etan Cohend3652192014-06-20 08:28:44 -07004368#if (SIM_COUNT >= 3)
4369 // start listen socket3
4370 startListen(RIL_SOCKET_3, &s_ril_param_socket3);
4371#endif /* (SIM_COUNT == 3) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004372
Etan Cohend3652192014-06-20 08:28:44 -07004373#if (SIM_COUNT >= 4)
4374 // start listen socket4
4375 startListen(RIL_SOCKET_4, &s_ril_param_socket4);
4376#endif /* (SIM_COUNT == 4) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004377
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004378
4379#if 1
4380 // start debug interface socket
4381
Etan Cohend3652192014-06-20 08:28:44 -07004382 char *inst = NULL;
4383 if (strlen(RIL_getRilSocketName()) >= strlen(SOCKET_NAME_RIL)) {
4384 inst = RIL_getRilSocketName() + strlen(SOCKET_NAME_RIL);
4385 }
4386
4387 char rildebug[MAX_DEBUG_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL_DEBUG;
4388 if (inst != NULL) {
Nick Kralevichc52e45e2015-02-08 07:54:16 -08004389 strlcat(rildebug, inst, MAX_DEBUG_SOCKET_NAME_LENGTH);
Etan Cohend3652192014-06-20 08:28:44 -07004390 }
4391
4392 s_fdDebug = android_get_control_socket(rildebug);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004393 if (s_fdDebug < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07004394 RLOGE("Failed to get socket : %s errno:%d", rildebug, errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004395 exit(-1);
4396 }
4397
4398 ret = listen(s_fdDebug, 4);
4399
4400 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004401 RLOGE("Failed to listen on ril debug socket '%d': %s",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004402 s_fdDebug, strerror(errno));
4403 exit(-1);
4404 }
4405
4406 ril_event_set (&s_debug_event, s_fdDebug, true,
4407 debugCallback, NULL);
4408
4409 rilEventAddWakeup (&s_debug_event);
4410#endif
4411
4412}
4413
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004414extern "C" void
4415RIL_register_socket (RIL_RadioFunctions *(*Init)(const struct RIL_Env *, int, char **),RIL_SOCKET_TYPE socketType, int argc, char **argv) {
4416
4417 RIL_RadioFunctions* UimFuncs = NULL;
4418
4419 if(Init) {
4420 UimFuncs = Init(&RilSapSocket::uimRilEnv, argc, argv);
4421
4422 switch(socketType) {
4423 case RIL_SAP_SOCKET:
4424 RilSapSocket::initSapSocket("sap_uim_socket1", UimFuncs);
4425
4426#if (SIM_COUNT >= 2)
4427 RilSapSocket::initSapSocket("sap_uim_socket2", UimFuncs);
4428#endif
4429
4430#if (SIM_COUNT >= 3)
4431 RilSapSocket::initSapSocket("sap_uim_socket3", UimFuncs);
4432#endif
4433
4434#if (SIM_COUNT >= 4)
4435 RilSapSocket::initSapSocket("sap_uim_socket4", UimFuncs);
4436#endif
4437 }
4438 }
4439}
4440
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004441static int
Wink Savillef4c4d362009-04-02 01:37:03 -07004442checkAndDequeueRequestInfo(struct RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004443 int ret = 0;
Etan Cohend3652192014-06-20 08:28:44 -07004444 /* Hook for current context
4445 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
4446 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
4447 /* pendingRequestsHook refer to &s_pendingRequests */
4448 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
Wink Saville7f856802009-06-09 10:23:37 -07004449
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004450 if (pRI == NULL) {
4451 return 0;
4452 }
4453
Etan Cohend3652192014-06-20 08:28:44 -07004454#if (SIM_COUNT >= 2)
4455 if (pRI->socket_id == RIL_SOCKET_2) {
4456 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
4457 pendingRequestsHook = &s_pendingRequests_socket2;
4458 }
4459#if (SIM_COUNT >= 3)
4460 if (pRI->socket_id == RIL_SOCKET_3) {
4461 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
4462 pendingRequestsHook = &s_pendingRequests_socket3;
4463 }
4464#endif
4465#if (SIM_COUNT >= 4)
4466 if (pRI->socket_id == RIL_SOCKET_4) {
4467 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
4468 pendingRequestsHook = &s_pendingRequests_socket4;
4469 }
4470#endif
4471#endif
4472 pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004473
Etan Cohend3652192014-06-20 08:28:44 -07004474 for(RequestInfo **ppCur = pendingRequestsHook
Wink Saville7f856802009-06-09 10:23:37 -07004475 ; *ppCur != NULL
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004476 ; ppCur = &((*ppCur)->p_next)
4477 ) {
4478 if (pRI == *ppCur) {
4479 ret = 1;
4480
4481 *ppCur = (*ppCur)->p_next;
4482 break;
4483 }
4484 }
4485
Etan Cohend3652192014-06-20 08:28:44 -07004486 pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004487
4488 return ret;
4489}
4490
4491
4492extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07004493RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004494 RequestInfo *pRI;
4495 int ret;
Etan Cohend3652192014-06-20 08:28:44 -07004496 int fd = s_ril_param_socket.fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004497 size_t errorOffset;
Etan Cohend3652192014-06-20 08:28:44 -07004498 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004499
4500 pRI = (RequestInfo *)t;
4501
Jayachandran C6c607592014-08-04 15:48:01 -07004502 if (!checkAndDequeueRequestInfo(pRI)) {
4503 RLOGE ("RIL_onRequestComplete: invalid RIL_Token");
4504 return;
4505 }
4506
Etan Cohend3652192014-06-20 08:28:44 -07004507 socket_id = pRI->socket_id;
4508#if (SIM_COUNT >= 2)
4509 if (socket_id == RIL_SOCKET_2) {
4510 fd = s_ril_param_socket2.fdCommand;
4511 }
4512#if (SIM_COUNT >= 3)
4513 if (socket_id == RIL_SOCKET_3) {
4514 fd = s_ril_param_socket3.fdCommand;
4515 }
4516#endif
4517#if (SIM_COUNT >= 4)
4518 if (socket_id == RIL_SOCKET_4) {
4519 fd = s_ril_param_socket4.fdCommand;
4520 }
4521#endif
4522#endif
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07004523#if VDBG
Etan Cohend3652192014-06-20 08:28:44 -07004524 RLOGD("RequestComplete, %s", rilSocketIdToString(socket_id));
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07004525#endif
Etan Cohend3652192014-06-20 08:28:44 -07004526
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004527 if (pRI->local > 0) {
4528 // Locally issued command...void only!
4529 // response does not go back up the command socket
Wink Saville8eb2a122012-11-19 16:05:13 -08004530 RLOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004531
4532 goto done;
4533 }
4534
4535 appendPrintBuf("[%04d]< %s",
4536 pRI->token, requestToString(pRI->pCI->requestNumber));
4537
4538 if (pRI->cancelled == 0) {
4539 Parcel p;
4540
4541 p.writeInt32 (RESPONSE_SOLICITED);
4542 p.writeInt32 (pRI->token);
4543 errorOffset = p.dataPosition();
4544
4545 p.writeInt32 (e);
4546
johnwangb2a61842009-06-02 14:55:45 -07004547 if (response != NULL) {
4548 // there is a response payload, no matter success or not.
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004549 ret = pRI->pCI->responseFunction(p, response, responselen);
4550
4551 /* if an error occurred, rewind and mark it */
4552 if (ret != 0) {
Etan Cohend3652192014-06-20 08:28:44 -07004553 RLOGE ("responseFunction error, ret %d", ret);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004554 p.setDataPosition(errorOffset);
4555 p.writeInt32 (ret);
4556 }
johnwangb2a61842009-06-02 14:55:45 -07004557 }
4558
4559 if (e != RIL_E_SUCCESS) {
4560 appendPrintBuf("%s fails by %s", printBuf, failCauseToString(e));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004561 }
4562
Etan Cohend3652192014-06-20 08:28:44 -07004563 if (fd < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004564 RLOGD ("RIL onRequestComplete: Command channel closed");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004565 }
Etan Cohend3652192014-06-20 08:28:44 -07004566 sendResponse(p, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004567 }
4568
4569done:
4570 free(pRI);
4571}
4572
4573
4574static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004575grabPartialWakeLock() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004576 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
4577}
4578
4579static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004580releaseWakeLock() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004581 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
4582}
4583
4584/**
4585 * Timer callback to put us back to sleep before the default timeout
4586 */
4587static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004588wakeTimeoutCallback (void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004589 // We're using "param != NULL" as a cancellation mechanism
4590 if (param == NULL) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004591 releaseWakeLock();
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004592 }
4593}
4594
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004595static int
4596decodeVoiceRadioTechnology (RIL_RadioState radioState) {
4597 switch (radioState) {
4598 case RADIO_STATE_SIM_NOT_READY:
4599 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4600 case RADIO_STATE_SIM_READY:
4601 return RADIO_TECH_UMTS;
4602
4603 case RADIO_STATE_RUIM_NOT_READY:
4604 case RADIO_STATE_RUIM_READY:
4605 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4606 case RADIO_STATE_NV_NOT_READY:
4607 case RADIO_STATE_NV_READY:
4608 return RADIO_TECH_1xRTT;
4609
4610 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004611 RLOGD("decodeVoiceRadioTechnology: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004612 return -1;
4613 }
4614}
4615
4616static int
4617decodeCdmaSubscriptionSource (RIL_RadioState radioState) {
4618 switch (radioState) {
4619 case RADIO_STATE_SIM_NOT_READY:
4620 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4621 case RADIO_STATE_SIM_READY:
4622 case RADIO_STATE_RUIM_NOT_READY:
4623 case RADIO_STATE_RUIM_READY:
4624 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4625 return CDMA_SUBSCRIPTION_SOURCE_RUIM_SIM;
4626
4627 case RADIO_STATE_NV_NOT_READY:
4628 case RADIO_STATE_NV_READY:
4629 return CDMA_SUBSCRIPTION_SOURCE_NV;
4630
4631 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004632 RLOGD("decodeCdmaSubscriptionSource: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004633 return -1;
4634 }
4635}
4636
4637static int
4638decodeSimStatus (RIL_RadioState radioState) {
4639 switch (radioState) {
4640 case RADIO_STATE_SIM_NOT_READY:
4641 case RADIO_STATE_RUIM_NOT_READY:
4642 case RADIO_STATE_NV_NOT_READY:
4643 case RADIO_STATE_NV_READY:
4644 return -1;
4645 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4646 case RADIO_STATE_SIM_READY:
4647 case RADIO_STATE_RUIM_READY:
4648 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4649 return radioState;
4650 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004651 RLOGD("decodeSimStatus: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004652 return -1;
4653 }
4654}
4655
4656static bool is3gpp2(int radioTech) {
4657 switch (radioTech) {
4658 case RADIO_TECH_IS95A:
4659 case RADIO_TECH_IS95B:
4660 case RADIO_TECH_1xRTT:
4661 case RADIO_TECH_EVDO_0:
4662 case RADIO_TECH_EVDO_A:
4663 case RADIO_TECH_EVDO_B:
4664 case RADIO_TECH_EHRPD:
4665 return true;
4666 default:
4667 return false;
4668 }
4669}
4670
4671/* If RIL sends SIM states or RUIM states, store the voice radio
4672 * technology and subscription source information so that they can be
4673 * returned when telephony framework requests them
4674 */
4675static RIL_RadioState
Etan Cohend3652192014-06-20 08:28:44 -07004676processRadioState(RIL_RadioState newRadioState, RIL_SOCKET_ID socket_id) {
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004677
4678 if((newRadioState > RADIO_STATE_UNAVAILABLE) && (newRadioState < RADIO_STATE_ON)) {
4679 int newVoiceRadioTech;
4680 int newCdmaSubscriptionSource;
4681 int newSimStatus;
4682
4683 /* This is old RIL. Decode Subscription source and Voice Radio Technology
4684 from Radio State and send change notifications if there has been a change */
4685 newVoiceRadioTech = decodeVoiceRadioTechnology(newRadioState);
4686 if(newVoiceRadioTech != voiceRadioTech) {
4687 voiceRadioTech = newVoiceRadioTech;
Etan Cohend3652192014-06-20 08:28:44 -07004688 RIL_UNSOL_RESPONSE(RIL_UNSOL_VOICE_RADIO_TECH_CHANGED,
4689 &voiceRadioTech, sizeof(voiceRadioTech), socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004690 }
4691 if(is3gpp2(newVoiceRadioTech)) {
4692 newCdmaSubscriptionSource = decodeCdmaSubscriptionSource(newRadioState);
4693 if(newCdmaSubscriptionSource != cdmaSubscriptionSource) {
4694 cdmaSubscriptionSource = newCdmaSubscriptionSource;
Etan Cohend3652192014-06-20 08:28:44 -07004695 RIL_UNSOL_RESPONSE(RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED,
4696 &cdmaSubscriptionSource, sizeof(cdmaSubscriptionSource), socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004697 }
4698 }
4699 newSimStatus = decodeSimStatus(newRadioState);
4700 if(newSimStatus != simRuimStatus) {
4701 simRuimStatus = newSimStatus;
Etan Cohend3652192014-06-20 08:28:44 -07004702 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0, socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004703 }
4704
4705 /* Send RADIO_ON to telephony */
4706 newRadioState = RADIO_STATE_ON;
4707 }
4708
4709 return newRadioState;
4710}
4711
Etan Cohend3652192014-06-20 08:28:44 -07004712
4713#if defined(ANDROID_MULTI_SIM)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004714extern "C"
Bernhard Rosenkränzerd613b962014-11-17 20:52:09 +01004715void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Etan Cohend3652192014-06-20 08:28:44 -07004716 size_t datalen, RIL_SOCKET_ID socket_id)
4717#else
4718extern "C"
Bernhard Rosenkränzerd613b962014-11-17 20:52:09 +01004719void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004720 size_t datalen)
Etan Cohend3652192014-06-20 08:28:44 -07004721#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004722{
4723 int unsolResponseIndex;
4724 int ret;
4725 int64_t timeReceived = 0;
4726 bool shouldScheduleTimeout = false;
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004727 RIL_RadioState newState;
Etan Cohend3652192014-06-20 08:28:44 -07004728 RIL_SOCKET_ID soc_id = RIL_SOCKET_1;
4729
4730#if defined(ANDROID_MULTI_SIM)
4731 soc_id = socket_id;
4732#endif
4733
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004734
4735 if (s_registerCalled == 0) {
4736 // Ignore RIL_onUnsolicitedResponse before RIL_register
Wink Saville8eb2a122012-11-19 16:05:13 -08004737 RLOGW("RIL_onUnsolicitedResponse called before RIL_register");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004738 return;
4739 }
Wink Saville7f856802009-06-09 10:23:37 -07004740
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004741 unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
4742
4743 if ((unsolResponseIndex < 0)
4744 || (unsolResponseIndex >= (int32_t)NUM_ELEMS(s_unsolResponses))) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004745 RLOGE("unsupported unsolicited response code %d", unsolResponse);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004746 return;
4747 }
4748
4749 // Grab a wake lock if needed for this reponse,
4750 // as we exit we'll either release it immediately
4751 // or set a timer to release it later.
4752 switch (s_unsolResponses[unsolResponseIndex].wakeType) {
4753 case WAKE_PARTIAL:
4754 grabPartialWakeLock();
4755 shouldScheduleTimeout = true;
4756 break;
4757
4758 case DONT_WAKE:
4759 default:
4760 // No wake lock is grabed so don't set timeout
4761 shouldScheduleTimeout = false;
4762 break;
4763 }
4764
4765 // Mark the time this was received, doing this
4766 // after grabing the wakelock incase getting
4767 // the elapsedRealTime might cause us to goto
4768 // sleep.
4769 if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4770 timeReceived = elapsedRealtime();
4771 }
4772
4773 appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
4774
4775 Parcel p;
4776
4777 p.writeInt32 (RESPONSE_UNSOLICITED);
4778 p.writeInt32 (unsolResponse);
4779
4780 ret = s_unsolResponses[unsolResponseIndex]
Bernhard Rosenkränzer6e7c1962013-12-12 10:01:10 +01004781 .responseFunction(p, const_cast<void*>(data), datalen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004782 if (ret != 0) {
4783 // Problem with the response. Don't continue;
4784 goto error_exit;
4785 }
4786
4787 // some things get more payload
4788 switch(unsolResponse) {
4789 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
Etan Cohend3652192014-06-20 08:28:44 -07004790 newState = processRadioState(CALL_ONSTATEREQUEST(soc_id), soc_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004791 p.writeInt32(newState);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004792 appendPrintBuf("%s {%s}", printBuf,
Etan Cohend3652192014-06-20 08:28:44 -07004793 radioStateToString(CALL_ONSTATEREQUEST(soc_id)));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004794 break;
4795
4796
4797 case RIL_UNSOL_NITZ_TIME_RECEIVED:
4798 // Store the time that this was received so the
4799 // handler of this message can account for
4800 // the time it takes to arrive and process. In
4801 // particular the system has been known to sleep
4802 // before this message can be processed.
4803 p.writeInt64(timeReceived);
4804 break;
4805 }
4806
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07004807#if VDBG
Etan Cohend3652192014-06-20 08:28:44 -07004808 RLOGI("%s UNSOLICITED: %s length:%d", rilSocketIdToString(soc_id), requestToString(unsolResponse), p.dataSize());
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07004809#endif
Etan Cohend3652192014-06-20 08:28:44 -07004810 ret = sendResponse(p, soc_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004811 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4812
4813 // Unfortunately, NITZ time is not poll/update like everything
4814 // else in the system. So, if the upstream client isn't connected,
4815 // keep a copy of the last NITZ response (with receive time noted
4816 // above) around so we can deliver it when it is connected
4817
4818 if (s_lastNITZTimeData != NULL) {
4819 free (s_lastNITZTimeData);
4820 s_lastNITZTimeData = NULL;
4821 }
4822
4823 s_lastNITZTimeData = malloc(p.dataSize());
4824 s_lastNITZTimeDataSize = p.dataSize();
4825 memcpy(s_lastNITZTimeData, p.data(), p.dataSize());
4826 }
4827
4828 // For now, we automatically go back to sleep after TIMEVAL_WAKE_TIMEOUT
4829 // FIXME The java code should handshake here to release wake lock
4830
4831 if (shouldScheduleTimeout) {
4832 // Cancel the previous request
4833 if (s_last_wake_timeout_info != NULL) {
4834 s_last_wake_timeout_info->userParam = (void *)1;
4835 }
4836
4837 s_last_wake_timeout_info
4838 = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
4839 &TIMEVAL_WAKE_TIMEOUT);
4840 }
4841
4842 // Normal exit
4843 return;
4844
4845error_exit:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004846 if (shouldScheduleTimeout) {
4847 releaseWakeLock();
4848 }
4849}
4850
Wink Saville7f856802009-06-09 10:23:37 -07004851/** FIXME generalize this if you track UserCAllbackInfo, clear it
4852 when the callback occurs
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004853*/
4854static UserCallbackInfo *
Wink Saville7f856802009-06-09 10:23:37 -07004855internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004856 const struct timeval *relativeTime)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004857{
4858 struct timeval myRelativeTime;
4859 UserCallbackInfo *p_info;
4860
4861 p_info = (UserCallbackInfo *) malloc (sizeof(UserCallbackInfo));
4862
Wink Saville7f856802009-06-09 10:23:37 -07004863 p_info->p_callback = callback;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004864 p_info->userParam = param;
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004865
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004866 if (relativeTime == NULL) {
4867 /* treat null parameter as a 0 relative time */
4868 memset (&myRelativeTime, 0, sizeof(myRelativeTime));
4869 } else {
4870 /* FIXME I think event_add's tv param is really const anyway */
4871 memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
4872 }
4873
4874 ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
4875
4876 ril_timer_add(&(p_info->event), &myRelativeTime);
4877
4878 triggerEvLoop();
4879 return p_info;
4880}
4881
Naveen Kalla7edd07c2010-06-21 18:54:47 -07004882
4883extern "C" void
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004884RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
4885 const struct timeval *relativeTime) {
4886 internalRequestTimedCallback (callback, param, relativeTime);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004887}
4888
4889const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004890failCauseToString(RIL_Errno e) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004891 switch(e) {
4892 case RIL_E_SUCCESS: return "E_SUCCESS";
Robert Greenwalt2126ab22013-04-09 12:20:45 -07004893 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RADIO_NOT_AVAILABLE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004894 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
4895 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
4896 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
4897 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
4898 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
4899 case RIL_E_CANCELLED: return "E_CANCELLED";
4900 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
4901 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
4902 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
Wink Savillef4c4d362009-04-02 01:37:03 -07004903 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
John Wang75534472010-04-20 15:11:42 -07004904 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
Wink Saville7f856802009-06-09 10:23:37 -07004905#ifdef FEATURE_MULTIMODE_ANDROID
Wink Savillef4c4d362009-04-02 01:37:03 -07004906 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
4907 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
4908#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004909 default: return "<unknown error>";
4910 }
4911}
4912
4913const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004914radioStateToString(RIL_RadioState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004915 switch(s) {
4916 case RADIO_STATE_OFF: return "RADIO_OFF";
4917 case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
4918 case RADIO_STATE_SIM_NOT_READY: return "RADIO_SIM_NOT_READY";
4919 case RADIO_STATE_SIM_LOCKED_OR_ABSENT: return "RADIO_SIM_LOCKED_OR_ABSENT";
4920 case RADIO_STATE_SIM_READY: return "RADIO_SIM_READY";
Wink Savillef4c4d362009-04-02 01:37:03 -07004921 case RADIO_STATE_RUIM_NOT_READY:return"RADIO_RUIM_NOT_READY";
4922 case RADIO_STATE_RUIM_READY:return"RADIO_RUIM_READY";
4923 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:return"RADIO_RUIM_LOCKED_OR_ABSENT";
4924 case RADIO_STATE_NV_NOT_READY:return"RADIO_NV_NOT_READY";
4925 case RADIO_STATE_NV_READY:return"RADIO_NV_READY";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004926 case RADIO_STATE_ON:return"RADIO_ON";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004927 default: return "<unknown state>";
4928 }
4929}
4930
4931const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004932callStateToString(RIL_CallState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004933 switch(s) {
4934 case RIL_CALL_ACTIVE : return "ACTIVE";
4935 case RIL_CALL_HOLDING: return "HOLDING";
4936 case RIL_CALL_DIALING: return "DIALING";
4937 case RIL_CALL_ALERTING: return "ALERTING";
4938 case RIL_CALL_INCOMING: return "INCOMING";
4939 case RIL_CALL_WAITING: return "WAITING";
4940 default: return "<unknown state>";
4941 }
4942}
4943
4944const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004945requestToString(int request) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004946/*
4947 cat libs/telephony/ril_commands.h \
4948 | egrep "^ *{RIL_" \
4949 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
4950
4951
4952 cat libs/telephony/ril_unsol_commands.h \
4953 | egrep "^ *{RIL_" \
4954 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
4955
4956*/
4957 switch(request) {
4958 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
4959 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
4960 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
4961 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
4962 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
4963 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
4964 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
4965 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
4966 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
4967 case RIL_REQUEST_DIAL: return "DIAL";
4968 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
4969 case RIL_REQUEST_HANGUP: return "HANGUP";
4970 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
4971 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
4972 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
4973 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
4974 case RIL_REQUEST_UDUB: return "UDUB";
4975 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
4976 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
Wink Savillec0114b32011-02-18 10:14:07 -08004977 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
4978 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004979 case RIL_REQUEST_OPERATOR: return "OPERATOR";
4980 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
4981 case RIL_REQUEST_DTMF: return "DTMF";
4982 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
4983 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
Wink Savillef4c4d362009-04-02 01:37:03 -07004984 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004985 case RIL_REQUEST_SIM_IO: return "SIM_IO";
4986 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
4987 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
4988 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
4989 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
4990 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
4991 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
4992 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
4993 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
4994 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
4995 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
4996 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
4997 case RIL_REQUEST_ANSWER: return "ANSWER";
Wink Savillef4c4d362009-04-02 01:37:03 -07004998 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004999 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
5000 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
5001 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
5002 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
5003 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
5004 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
5005 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";
5006 case RIL_REQUEST_DTMF_START: return "DTMF_START";
5007 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
5008 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
5009 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
5010 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
5011 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
5012 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
5013 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
5014 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
5015 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
Wink Savillef4c4d362009-04-02 01:37:03 -07005016 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
5017 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005018 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
5019 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
5020 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
Wink Savillef4c4d362009-04-02 01:37:03 -07005021 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
5022 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005023 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
5024 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
5025 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
5026 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
5027 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
5028 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
5029 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
5030 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
Wink Savillec0114b32011-02-18 10:14:07 -08005031 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE:return"CDMA_SET_SUBSCRIPTION_SOURCE";
Wink Savillef4c4d362009-04-02 01:37:03 -07005032 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"CDMA_SET_ROAMING_PREFERENCE";
5033 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"CDMA_QUERY_ROAMING_PREFERENCE";
5034 case RIL_REQUEST_SET_TTY_MODE:return"SET_TTY_MODE";
5035 case RIL_REQUEST_QUERY_TTY_MODE:return"QUERY_TTY_MODE";
5036 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
5037 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
5038 case RIL_REQUEST_CDMA_FLASH:return"CDMA_FLASH";
5039 case RIL_REQUEST_CDMA_BURST_DTMF:return"CDMA_BURST_DTMF";
5040 case RIL_REQUEST_CDMA_SEND_SMS:return"CDMA_SEND_SMS";
5041 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:return"CDMA_SMS_ACKNOWLEDGE";
Wink Savillea592eeb2009-05-22 13:26:36 -07005042 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG:return"GSM_GET_BROADCAST_SMS_CONFIG";
5043 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG:return"GSM_SET_BROADCAST_SMS_CONFIG";
5044 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG:return "CDMA_GET_BROADCAST_SMS_CONFIG";
5045 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG:return "CDMA_SET_BROADCAST_SMS_CONFIG";
5046 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION:return "CDMA_SMS_BROADCAST_ACTIVATION";
Naveen Kalla03c1edf2009-09-23 11:18:35 -07005047 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return"CDMA_VALIDATE_AND_WRITE_AKEY";
Wink Savillef4c4d362009-04-02 01:37:03 -07005048 case RIL_REQUEST_CDMA_SUBSCRIPTION: return"CDMA_SUBSCRIPTION";
5049 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
5050 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
5051 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
jsh000a9fe2009-05-11 14:52:35 -07005052 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
5053 case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
5054 case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
jsh09a68ba2009-06-10 11:56:38 -07005055 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
jsh563fd722010-06-08 16:52:24 -07005056 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
Wink Savillec0114b32011-02-18 10:14:07 -08005057 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
Jake Hambyfa8d5842011-08-19 16:22:18 -07005058 case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
Jake Hamby300105d2011-09-26 01:01:44 -07005059 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
5060 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005061 case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
Wink Saville8a9e0212013-04-09 12:11:38 -07005062 case RIL_REQUEST_GET_CELL_INFO_LIST: return"GET_CELL_INFO_LIST";
5063 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return"SET_UNSOL_CELL_INFO_LIST_RATE";
Sungmin Choi75697532013-04-26 15:04:45 -07005064 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "RIL_REQUEST_SET_INITIAL_ATTACH_APN";
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07005065 case RIL_REQUEST_IMS_REGISTRATION_STATE: return "IMS_REGISTRATION_STATE";
5066 case RIL_REQUEST_IMS_SEND_SMS: return "IMS_SEND_SMS";
Shishir Agrawal2458d8d2013-11-27 14:53:05 -08005067 case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "SIM_TRANSMIT_APDU_BASIC";
5068 case RIL_REQUEST_SIM_OPEN_CHANNEL: return "SIM_OPEN_CHANNEL";
5069 case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "SIM_CLOSE_CHANNEL";
5070 case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "SIM_TRANSMIT_APDU_CHANNEL";
Wink Saville8b4e4f72014-10-17 15:01:45 -07005071 case RIL_REQUEST_GET_RADIO_CAPABILITY: return "RIL_REQUEST_GET_RADIO_CAPABILITY";
5072 case RIL_REQUEST_SET_RADIO_CAPABILITY: return "RIL_REQUEST_SET_RADIO_CAPABILITY";
Etan Cohend3652192014-06-20 08:28:44 -07005073 case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "SET_UICC_SUBSCRIPTION";
5074 case RIL_REQUEST_ALLOW_DATA: return "ALLOW_DATA";
Amit Mahajan2b772032014-06-26 14:20:11 -07005075 case RIL_REQUEST_GET_HARDWARE_CONFIG: return "GET_HARDWARE_CONFIG";
5076 case RIL_REQUEST_SIM_AUTHENTICATION: return "SIM_AUTHENTICATION";
Wink Savillec29360a2014-07-13 05:17:28 -07005077 case RIL_REQUEST_GET_DC_RT_INFO: return "GET_DC_RT_INFO";
5078 case RIL_REQUEST_SET_DC_RT_INFO_RATE: return "SET_DC_RT_INFO_RATE";
Amit Mahajanc796e222014-08-13 16:54:01 +00005079 case RIL_REQUEST_SET_DATA_PROFILE: return "SET_DATA_PROFILE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005080 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
5081 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08005082 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 -08005083 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
5084 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
5085 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
5086 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
5087 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)";
5088 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
5089 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
5090 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
5091 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
5092 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
5093 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
5094 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL";
5095 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
Wink Savillef4c4d362009-04-02 01:37:03 -07005096 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005097 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
Wink Savillef4c4d362009-04-02 01:37:03 -07005098 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
5099 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_NEW_CDMA_SMS";
5100 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_NEW_BROADCAST_SMS";
5101 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
Wink Saville3d54e742009-05-18 18:00:44 -07005102 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
5103 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
5104 case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
5105 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
5106 case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
Jaikumar Ganeshaf6ecbf2009-04-29 13:27:51 -07005107 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
John Wang5d621da2009-09-18 17:17:48 -07005108 case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
John Wang5909cf82010-01-29 00:18:54 -08005109 case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
Wink Savilleee274582011-04-16 15:05:49 -07005110 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08005111 case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
5112 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
Wink Saville5b9df332011-04-06 16:24:21 -07005113 case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005114 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
Wink Saville8a9e0212013-04-09 12:11:38 -07005115 case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07005116 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "RESPONSE_IMS_NETWORK_STATE_CHANGED";
Etan Cohend3652192014-06-20 08:28:44 -07005117 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return "UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED";
5118 case RIL_UNSOL_SRVCC_STATE_NOTIFY: return "UNSOL_SRVCC_STATE_NOTIFY";
5119 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return "HARDWARE_CONFIG_CHANGED";
Wink Savillec29360a2014-07-13 05:17:28 -07005120 case RIL_UNSOL_DC_RT_INFO_CHANGED: return "UNSOL_DC_RT_INFO_CHANGED";
Naveen Kallaa65a16a2014-07-31 16:48:31 -07005121 case RIL_REQUEST_SHUTDOWN: return "SHUTDOWN";
Wink Saville8b4e4f72014-10-17 15:01:45 -07005122 case RIL_UNSOL_RADIO_CAPABILITY: return "RIL_UNSOL_RADIO_CAPABILITY";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005123 default: return "<unknown request>";
5124 }
5125}
5126
Etan Cohend3652192014-06-20 08:28:44 -07005127const char *
5128rilSocketIdToString(RIL_SOCKET_ID socket_id)
5129{
5130 switch(socket_id) {
5131 case RIL_SOCKET_1:
5132 return "RIL_SOCKET_1";
5133#if (SIM_COUNT >= 2)
5134 case RIL_SOCKET_2:
5135 return "RIL_SOCKET_2";
5136#endif
5137#if (SIM_COUNT >= 3)
5138 case RIL_SOCKET_3:
5139 return "RIL_SOCKET_3";
5140#endif
5141#if (SIM_COUNT >= 4)
5142 case RIL_SOCKET_4:
5143 return "RIL_SOCKET_4";
5144#endif
5145 default:
5146 return "not a valid RIL";
5147 }
5148}
5149
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005150} /* namespace android */
Dheeraj Shetty27976c42014-07-02 21:27:57 +02005151
5152void rilEventAddWakeup_helper(struct ril_event *ev) {
5153 android::rilEventAddWakeup(ev);
5154}
5155
5156void listenCallback_helper(int fd, short flags, void *param) {
5157 android::listenCallback(fd, flags, param);
5158}
5159
5160int blockingWrite_helper(int fd, void *buffer, size_t len) {
5161 return android::blockingWrite(fd, buffer, len);
5162}