blob: a27495e52cdcdc2daf6a25249d35dcee9e34eb76 [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);
Chao Liu548a81e2015-05-14 16:13:46 -0700273static int responseFailCause(Parcel &p, void *response, size_t responselen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800274static int responseStrings(Parcel &p, void *response, size_t responselen);
275static int responseString(Parcel &p, void *response, size_t responselen);
276static int responseVoid(Parcel &p, void *response, size_t responselen);
277static int responseCallList(Parcel &p, void *response, size_t responselen);
278static int responseSMS(Parcel &p, void *response, size_t responselen);
279static int responseSIM_IO(Parcel &p, void *response, size_t responselen);
280static int responseCallForwards(Parcel &p, void *response, size_t responselen);
Wink Savillef4c4d362009-04-02 01:37:03 -0700281static int responseDataCallList(Parcel &p, void *response, size_t responselen);
Wink Saville43808972011-01-13 17:39:51 -0800282static int responseSetupDataCall(Parcel &p, void *response, size_t responselen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800283static int responseRaw(Parcel &p, void *response, size_t responselen);
284static int responseSsn(Parcel &p, void *response, size_t responselen);
Wink Savillef4c4d362009-04-02 01:37:03 -0700285static int responseSimStatus(Parcel &p, void *response, size_t responselen);
Wink Savillea592eeb2009-05-22 13:26:36 -0700286static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen);
287static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen);
Wink Savillef4c4d362009-04-02 01:37:03 -0700288static int responseCdmaSms(Parcel &p, void *response, size_t responselen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800289static int responseCellList(Parcel &p, void *response, size_t responselen);
Wink Saville3d54e742009-05-18 18:00:44 -0700290static int responseCdmaInformationRecords(Parcel &p,void *response, size_t responselen);
291static int responseRilSignalStrength(Parcel &p,void *response, size_t responselen);
292static int responseCallRing(Parcel &p, void *response, size_t responselen);
293static int responseCdmaSignalInfoRecord(Parcel &p,void *response, size_t responselen);
294static int responseCdmaCallWaiting(Parcel &p,void *response, size_t responselen);
Alex Yakavenka45e740e2012-01-31 11:48:27 -0800295static int responseSimRefresh(Parcel &p, void *response, size_t responselen);
Wink Saville8a9e0212013-04-09 12:11:38 -0700296static int responseCellInfoList(Parcel &p, void *response, size_t responselen);
Etan Cohend3652192014-06-20 08:28:44 -0700297static int responseHardwareConfig(Parcel &p, void *response, size_t responselen);
Wink Savillec29360a2014-07-13 05:17:28 -0700298static int responseDcRtInfo(Parcel &p, void *response, size_t responselen);
Wink Saville8b4e4f72014-10-17 15:01:45 -0700299static int responseRadioCapability(Parcel &p, void *response, size_t responselen);
Amit Mahajan54563d32014-11-22 00:54:49 +0000300static int responseSSData(Parcel &p, void *response, size_t responselen);
fengluf7408292015-04-14 14:53:55 -0700301static int responseLceStatus(Parcel &p, void *response, size_t responselen);
302static int responseLceData(Parcel &p, void *response, size_t responselen);
Prerepa Viswanadham73157492015-05-28 00:37:32 -0700303static int responseActivityData(Parcel &p, void *response, size_t responselen);
Amit Mahajan54563d32014-11-22 00:54:49 +0000304
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800305static int decodeVoiceRadioTechnology (RIL_RadioState radioState);
306static int decodeCdmaSubscriptionSource (RIL_RadioState radioState);
307static RIL_RadioState processRadioState(RIL_RadioState newRadioState);
308
Amit Mahajan54563d32014-11-22 00:54:49 +0000309static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType);
310
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800311#ifdef RIL_SHLIB
Etan Cohend3652192014-06-20 08:28:44 -0700312#if defined(ANDROID_MULTI_SIM)
Vinit Deshpande1b1ec2d2015-04-15 13:31:05 -0700313extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Etan Cohend3652192014-06-20 08:28:44 -0700314 size_t datalen, RIL_SOCKET_ID socket_id);
315#else
Vinit Deshpande1b1ec2d2015-04-15 13:31:05 -0700316extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800317 size_t datalen);
318#endif
Etan Cohend3652192014-06-20 08:28:44 -0700319#endif
320
321#if defined(ANDROID_MULTI_SIM)
322#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c), (d))
323#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d), (e))
324#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest(a)
325#else
326#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c))
327#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d))
328#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest()
329#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800330
Wink Saville7f856802009-06-09 10:23:37 -0700331static UserCallbackInfo * internalRequestTimedCallback
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -0700332 (RIL_TimedCallback callback, void *param,
333 const struct timeval *relativeTime);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800334
335/** Index == requestNumber */
336static CommandInfo s_commands[] = {
337#include "ril_commands.h"
338};
339
340static UnsolResponseInfo s_unsolResponses[] = {
341#include "ril_unsol_commands.h"
342};
343
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800344/* For older RILs that do not support new commands RIL_REQUEST_VOICE_RADIO_TECH and
345 RIL_UNSOL_VOICE_RADIO_TECH_CHANGED messages, decode the voice radio tech from
346 radio state message and store it. Every time there is a change in Radio State
347 check to see if voice radio tech changes and notify telephony
348 */
349int voiceRadioTech = -1;
350
351/* For older RILs that do not support new commands RIL_REQUEST_GET_CDMA_SUBSCRIPTION_SOURCE
352 and RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED messages, decode the subscription
353 source from radio state and store it. Every time there is a change in Radio State
354 check to see if subscription source changed and notify telephony
355 */
356int cdmaSubscriptionSource = -1;
357
358/* For older RILs that do not send RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, decode the
359 SIM/RUIM state from radio state and store it. Every time there is a change in Radio State,
360 check to see if SIM/RUIM status changed and notify telephony
361 */
362int simRuimStatus = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800363
Etan Cohend3652192014-06-20 08:28:44 -0700364static char * RIL_getRilSocketName() {
365 return rild;
366}
367
368extern "C"
Dheeraj Shetty27976c42014-07-02 21:27:57 +0200369void RIL_setRilSocketName(const char * s) {
Etan Cohend3652192014-06-20 08:28:44 -0700370 strncpy(rild, s, MAX_SOCKET_NAME_LENGTH);
371}
372
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800373static char *
Wink Savillef4c4d362009-04-02 01:37:03 -0700374strdupReadString(Parcel &p) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800375 size_t stringlen;
376 const char16_t *s16;
Wink Saville7f856802009-06-09 10:23:37 -0700377
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800378 s16 = p.readString16Inplace(&stringlen);
Wink Saville7f856802009-06-09 10:23:37 -0700379
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800380 return strndup16to8(s16, stringlen);
381}
382
Wink Saville8b4e4f72014-10-17 15:01:45 -0700383static status_t
384readStringFromParcelInplace(Parcel &p, char *str, size_t maxLen) {
385 size_t s16Len;
386 const char16_t *s16;
387
388 s16 = p.readString16Inplace(&s16Len);
389 if (s16 == NULL) {
390 return NO_MEMORY;
391 }
392 size_t strLen = strnlen16to8(s16, s16Len);
393 if ((strLen + 1) > maxLen) {
394 return NO_MEMORY;
395 }
396 if (strncpy16to8(str, s16, strLen) == NULL) {
397 return NO_MEMORY;
398 } else {
399 return NO_ERROR;
400 }
401}
402
Wink Savillef4c4d362009-04-02 01:37:03 -0700403static void writeStringToParcel(Parcel &p, const char *s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800404 char16_t *s16;
405 size_t s16_len;
406 s16 = strdup8to16(s, &s16_len);
407 p.writeString16(s16, s16_len);
408 free(s16);
409}
410
411
412static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700413memsetString (char *s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800414 if (s != NULL) {
415 memset (s, 0, strlen(s));
416 }
417}
418
419void nullParcelReleaseFunction (const uint8_t* data, size_t dataSize,
420 const size_t* objects, size_t objectsSize,
Wink Savillef4c4d362009-04-02 01:37:03 -0700421 void* cookie) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800422 // do nothing -- the data reference lives longer than the Parcel object
423}
424
Wink Saville7f856802009-06-09 10:23:37 -0700425/**
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800426 * To be called from dispatch thread
427 * Issue a single local request, ensuring that the response
Wink Saville7f856802009-06-09 10:23:37 -0700428 * is not sent back up to the command process
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800429 */
430static void
Etan Cohend3652192014-06-20 08:28:44 -0700431issueLocalRequest(int request, void *data, int len, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800432 RequestInfo *pRI;
433 int ret;
Etan Cohend3652192014-06-20 08:28:44 -0700434 /* Hook for current context */
435 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
436 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
437 /* pendingRequestsHook refer to &s_pendingRequests */
438 RequestInfo** pendingRequestsHook = &s_pendingRequests;
439
440#if (SIM_COUNT == 2)
441 if (socket_id == RIL_SOCKET_2) {
442 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
443 pendingRequestsHook = &s_pendingRequests_socket2;
444 }
445#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800446
447 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
448
449 pRI->local = 1;
450 pRI->token = 0xffffffff; // token is not used in this context
451 pRI->pCI = &(s_commands[request]);
Etan Cohend3652192014-06-20 08:28:44 -0700452 pRI->socket_id = socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800453
Etan Cohend3652192014-06-20 08:28:44 -0700454 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800455 assert (ret == 0);
456
Etan Cohend3652192014-06-20 08:28:44 -0700457 pRI->p_next = *pendingRequestsHook;
458 *pendingRequestsHook = pRI;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800459
Etan Cohend3652192014-06-20 08:28:44 -0700460 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800461 assert (ret == 0);
462
Wink Saville8eb2a122012-11-19 16:05:13 -0800463 RLOGD("C[locl]> %s", requestToString(request));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800464
Etan Cohend3652192014-06-20 08:28:44 -0700465 CALL_ONREQUEST(request, data, len, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800466}
467
468
469
470static int
Etan Cohend3652192014-06-20 08:28:44 -0700471processCommandBuffer(void *buffer, size_t buflen, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800472 Parcel p;
473 status_t status;
474 int32_t request;
475 int32_t token;
476 RequestInfo *pRI;
477 int ret;
Etan Cohend3652192014-06-20 08:28:44 -0700478 /* Hook for current context */
479 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
480 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
481 /* pendingRequestsHook refer to &s_pendingRequests */
482 RequestInfo** pendingRequestsHook = &s_pendingRequests;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800483
484 p.setData((uint8_t *) buffer, buflen);
485
486 // status checked at end
487 status = p.readInt32(&request);
488 status = p.readInt32 (&token);
489
Etan Cohend3652192014-06-20 08:28:44 -0700490#if (SIM_COUNT >= 2)
491 if (socket_id == RIL_SOCKET_2) {
492 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
493 pendingRequestsHook = &s_pendingRequests_socket2;
494 }
495#if (SIM_COUNT >= 3)
496 else if (socket_id == RIL_SOCKET_3) {
497 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
498 pendingRequestsHook = &s_pendingRequests_socket3;
499 }
500#endif
501#if (SIM_COUNT >= 4)
502 else if (socket_id == RIL_SOCKET_4) {
503 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
504 pendingRequestsHook = &s_pendingRequests_socket4;
505 }
506#endif
507#endif
508
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800509 if (status != NO_ERROR) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800510 RLOGE("invalid request block");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800511 return 0;
512 }
513
514 if (request < 1 || request >= (int32_t)NUM_ELEMS(s_commands)) {
Etan Cohend3652192014-06-20 08:28:44 -0700515 Parcel pErr;
Wink Saville8eb2a122012-11-19 16:05:13 -0800516 RLOGE("unsupported request code %d token %d", request, token);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800517 // FIXME this should perhaps return a response
Etan Cohend3652192014-06-20 08:28:44 -0700518 pErr.writeInt32 (RESPONSE_SOLICITED);
519 pErr.writeInt32 (token);
520 pErr.writeInt32 (RIL_E_GENERIC_FAILURE);
521
522 sendResponse(pErr, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800523 return 0;
524 }
525
526
527 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
528
529 pRI->token = token;
530 pRI->pCI = &(s_commands[request]);
Etan Cohend3652192014-06-20 08:28:44 -0700531 pRI->socket_id = socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800532
Etan Cohend3652192014-06-20 08:28:44 -0700533 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800534 assert (ret == 0);
535
Etan Cohend3652192014-06-20 08:28:44 -0700536 pRI->p_next = *pendingRequestsHook;
537 *pendingRequestsHook = pRI;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800538
Etan Cohend3652192014-06-20 08:28:44 -0700539 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800540 assert (ret == 0);
541
542/* sLastDispatchedToken = token; */
543
Wink Saville7f856802009-06-09 10:23:37 -0700544 pRI->pCI->dispatchFunction(p, pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800545
546 return 0;
547}
548
549static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700550invalidCommandBlock (RequestInfo *pRI) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800551 RLOGE("invalid command block for token %d request %s",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800552 pRI->token, requestToString(pRI->pCI->requestNumber));
553}
554
555/** Callee expects NULL */
Wink Saville7f856802009-06-09 10:23:37 -0700556static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700557dispatchVoid (Parcel& p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800558 clearPrintBuf;
559 printRequest(pRI->token, pRI->pCI->requestNumber);
Etan Cohend3652192014-06-20 08:28:44 -0700560 CALL_ONREQUEST(pRI->pCI->requestNumber, NULL, 0, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800561}
562
563/** Callee expects const char * */
564static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700565dispatchString (Parcel& p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800566 status_t status;
567 size_t datalen;
568 size_t stringlen;
569 char *string8 = NULL;
570
571 string8 = strdupReadString(p);
572
573 startRequest;
574 appendPrintBuf("%s%s", printBuf, string8);
575 closeRequest;
576 printRequest(pRI->token, pRI->pCI->requestNumber);
577
Etan Cohend3652192014-06-20 08:28:44 -0700578 CALL_ONREQUEST(pRI->pCI->requestNumber, string8,
579 sizeof(char *), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800580
581#ifdef MEMSET_FREED
582 memsetString(string8);
583#endif
584
585 free(string8);
586 return;
587invalid:
588 invalidCommandBlock(pRI);
589 return;
590}
591
592/** Callee expects const char ** */
593static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700594dispatchStrings (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800595 int32_t countStrings;
596 status_t status;
597 size_t datalen;
598 char **pStrings;
599
600 status = p.readInt32 (&countStrings);
601
602 if (status != NO_ERROR) {
603 goto invalid;
604 }
605
606 startRequest;
607 if (countStrings == 0) {
608 // just some non-null pointer
609 pStrings = (char **)alloca(sizeof(char *));
610 datalen = 0;
611 } else if (((int)countStrings) == -1) {
612 pStrings = NULL;
613 datalen = 0;
614 } else {
615 datalen = sizeof(char *) * countStrings;
Wink Saville7f856802009-06-09 10:23:37 -0700616
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800617 pStrings = (char **)alloca(datalen);
618
619 for (int i = 0 ; i < countStrings ; i++) {
620 pStrings[i] = strdupReadString(p);
621 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
622 }
623 }
624 removeLastChar;
625 closeRequest;
626 printRequest(pRI->token, pRI->pCI->requestNumber);
627
Etan Cohend3652192014-06-20 08:28:44 -0700628 CALL_ONREQUEST(pRI->pCI->requestNumber, pStrings, datalen, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800629
630 if (pStrings != NULL) {
631 for (int i = 0 ; i < countStrings ; i++) {
632#ifdef MEMSET_FREED
633 memsetString (pStrings[i]);
634#endif
635 free(pStrings[i]);
636 }
637
638#ifdef MEMSET_FREED
639 memset(pStrings, 0, datalen);
640#endif
641 }
Wink Saville7f856802009-06-09 10:23:37 -0700642
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800643 return;
644invalid:
645 invalidCommandBlock(pRI);
646 return;
647}
648
649/** Callee expects const int * */
650static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700651dispatchInts (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800652 int32_t count;
653 status_t status;
654 size_t datalen;
655 int *pInts;
656
657 status = p.readInt32 (&count);
658
659 if (status != NO_ERROR || count == 0) {
660 goto invalid;
661 }
662
663 datalen = sizeof(int) * count;
664 pInts = (int *)alloca(datalen);
665
666 startRequest;
667 for (int i = 0 ; i < count ; i++) {
668 int32_t t;
669
670 status = p.readInt32(&t);
671 pInts[i] = (int)t;
672 appendPrintBuf("%s%d,", printBuf, t);
673
674 if (status != NO_ERROR) {
675 goto invalid;
676 }
677 }
678 removeLastChar;
679 closeRequest;
680 printRequest(pRI->token, pRI->pCI->requestNumber);
681
Etan Cohend3652192014-06-20 08:28:44 -0700682 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<int *>(pInts),
683 datalen, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800684
685#ifdef MEMSET_FREED
686 memset(pInts, 0, datalen);
687#endif
688
689 return;
690invalid:
691 invalidCommandBlock(pRI);
692 return;
693}
694
695
Wink Saville7f856802009-06-09 10:23:37 -0700696/**
697 * Callee expects const RIL_SMS_WriteArgs *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800698 * Payload is:
699 * int32_t status
700 * String pdu
701 */
702static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700703dispatchSmsWrite (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800704 RIL_SMS_WriteArgs args;
705 int32_t t;
706 status_t status;
707
Mark Salyzyndba25612015-04-09 07:18:35 -0700708 RLOGD("dispatchSmsWrite");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800709 memset (&args, 0, sizeof(args));
710
711 status = p.readInt32(&t);
712 args.status = (int)t;
713
714 args.pdu = strdupReadString(p);
715
716 if (status != NO_ERROR || args.pdu == NULL) {
717 goto invalid;
718 }
719
720 args.smsc = strdupReadString(p);
721
722 startRequest;
723 appendPrintBuf("%s%d,%s,smsc=%s", printBuf, args.status,
724 (char*)args.pdu, (char*)args.smsc);
725 closeRequest;
726 printRequest(pRI->token, pRI->pCI->requestNumber);
Wink Saville7f856802009-06-09 10:23:37 -0700727
Etan Cohend3652192014-06-20 08:28:44 -0700728 CALL_ONREQUEST(pRI->pCI->requestNumber, &args, sizeof(args), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800729
730#ifdef MEMSET_FREED
731 memsetString (args.pdu);
732#endif
733
734 free (args.pdu);
Wink Saville7f856802009-06-09 10:23:37 -0700735
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800736#ifdef MEMSET_FREED
737 memset(&args, 0, sizeof(args));
738#endif
739
740 return;
741invalid:
742 invalidCommandBlock(pRI);
743 return;
744}
745
Wink Saville7f856802009-06-09 10:23:37 -0700746/**
747 * Callee expects const RIL_Dial *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800748 * Payload is:
749 * String address
750 * int32_t clir
751 */
752static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700753dispatchDial (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800754 RIL_Dial dial;
Wink Saville74fa3882009-12-22 15:35:41 -0800755 RIL_UUS_Info uusInfo;
Wink Saville7bce0822010-01-08 15:20:12 -0800756 int32_t sizeOfDial;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800757 int32_t t;
Wink Saville74fa3882009-12-22 15:35:41 -0800758 int32_t uusPresent;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800759 status_t status;
760
Mark Salyzyndba25612015-04-09 07:18:35 -0700761 RLOGD("dispatchDial");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800762 memset (&dial, 0, sizeof(dial));
763
764 dial.address = strdupReadString(p);
765
766 status = p.readInt32(&t);
767 dial.clir = (int)t;
768
769 if (status != NO_ERROR || dial.address == NULL) {
770 goto invalid;
771 }
772
Wink Saville3a4840b2010-04-07 13:29:58 -0700773 if (s_callbacks.version < 3) { // Remove when partners upgrade to version 3
Wink Saville74fa3882009-12-22 15:35:41 -0800774 uusPresent = 0;
Wink Saville7bce0822010-01-08 15:20:12 -0800775 sizeOfDial = sizeof(dial) - sizeof(RIL_UUS_Info *);
Wink Saville74fa3882009-12-22 15:35:41 -0800776 } else {
777 status = p.readInt32(&uusPresent);
778
779 if (status != NO_ERROR) {
780 goto invalid;
781 }
782
783 if (uusPresent == 0) {
784 dial.uusInfo = NULL;
785 } else {
786 int32_t len;
787
788 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
789
790 status = p.readInt32(&t);
791 uusInfo.uusType = (RIL_UUS_Type) t;
792
793 status = p.readInt32(&t);
794 uusInfo.uusDcs = (RIL_UUS_DCS) t;
795
796 status = p.readInt32(&len);
797 if (status != NO_ERROR) {
798 goto invalid;
799 }
800
801 // The java code writes -1 for null arrays
802 if (((int) len) == -1) {
803 uusInfo.uusData = NULL;
804 len = 0;
805 } else {
806 uusInfo.uusData = (char*) p.readInplace(len);
807 }
808
809 uusInfo.uusLength = len;
810 dial.uusInfo = &uusInfo;
811 }
Wink Saville7bce0822010-01-08 15:20:12 -0800812 sizeOfDial = sizeof(dial);
Wink Saville74fa3882009-12-22 15:35:41 -0800813 }
814
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800815 startRequest;
816 appendPrintBuf("%snum=%s,clir=%d", printBuf, dial.address, dial.clir);
Wink Saville74fa3882009-12-22 15:35:41 -0800817 if (uusPresent) {
818 appendPrintBuf("%s,uusType=%d,uusDcs=%d,uusLen=%d", printBuf,
819 dial.uusInfo->uusType, dial.uusInfo->uusDcs,
820 dial.uusInfo->uusLength);
821 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800822 closeRequest;
823 printRequest(pRI->token, pRI->pCI->requestNumber);
824
Etan Cohend3652192014-06-20 08:28:44 -0700825 CALL_ONREQUEST(pRI->pCI->requestNumber, &dial, sizeOfDial, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800826
827#ifdef MEMSET_FREED
828 memsetString (dial.address);
829#endif
830
831 free (dial.address);
Wink Saville7f856802009-06-09 10:23:37 -0700832
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800833#ifdef MEMSET_FREED
Wink Saville74fa3882009-12-22 15:35:41 -0800834 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800835 memset(&dial, 0, sizeof(dial));
836#endif
837
838 return;
839invalid:
840 invalidCommandBlock(pRI);
841 return;
842}
843
Wink Saville7f856802009-06-09 10:23:37 -0700844/**
845 * Callee expects const RIL_SIM_IO *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800846 * Payload is:
847 * int32_t command
848 * int32_t fileid
849 * String path
850 * int32_t p1, p2, p3
Wink Saville7f856802009-06-09 10:23:37 -0700851 * String data
852 * String pin2
Wink Savillec0114b32011-02-18 10:14:07 -0800853 * String aidPtr
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800854 */
855static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700856dispatchSIM_IO (Parcel &p, RequestInfo *pRI) {
Wink Savillec0114b32011-02-18 10:14:07 -0800857 union RIL_SIM_IO {
858 RIL_SIM_IO_v6 v6;
859 RIL_SIM_IO_v5 v5;
860 } simIO;
861
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800862 int32_t t;
Wink Savillec0114b32011-02-18 10:14:07 -0800863 int size;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800864 status_t status;
865
Robert Greenwalt191e4dc2015-04-29 16:57:39 -0700866#if VDBG
Mark Salyzyndba25612015-04-09 07:18:35 -0700867 RLOGD("dispatchSIM_IO");
Robert Greenwalt191e4dc2015-04-29 16:57:39 -0700868#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800869 memset (&simIO, 0, sizeof(simIO));
870
Wink Saville7f856802009-06-09 10:23:37 -0700871 // note we only check status at the end
872
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800873 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800874 simIO.v6.command = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800875
876 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800877 simIO.v6.fileid = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800878
Wink Savillec0114b32011-02-18 10:14:07 -0800879 simIO.v6.path = strdupReadString(p);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800880
881 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800882 simIO.v6.p1 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800883
884 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800885 simIO.v6.p2 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800886
887 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800888 simIO.v6.p3 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800889
Wink Savillec0114b32011-02-18 10:14:07 -0800890 simIO.v6.data = strdupReadString(p);
891 simIO.v6.pin2 = strdupReadString(p);
892 simIO.v6.aidPtr = strdupReadString(p);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800893
894 startRequest;
Wink Savillec0114b32011-02-18 10:14:07 -0800895 appendPrintBuf("%scmd=0x%X,efid=0x%X,path=%s,%d,%d,%d,%s,pin2=%s,aid=%s", printBuf,
896 simIO.v6.command, simIO.v6.fileid, (char*)simIO.v6.path,
897 simIO.v6.p1, simIO.v6.p2, simIO.v6.p3,
898 (char*)simIO.v6.data, (char*)simIO.v6.pin2, simIO.v6.aidPtr);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800899 closeRequest;
900 printRequest(pRI->token, pRI->pCI->requestNumber);
Wink Saville7f856802009-06-09 10:23:37 -0700901
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800902 if (status != NO_ERROR) {
903 goto invalid;
904 }
905
Wink Savillec0114b32011-02-18 10:14:07 -0800906 size = (s_callbacks.version < 6) ? sizeof(simIO.v5) : sizeof(simIO.v6);
Etan Cohend3652192014-06-20 08:28:44 -0700907 CALL_ONREQUEST(pRI->pCI->requestNumber, &simIO, size, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800908
909#ifdef MEMSET_FREED
Wink Savillec0114b32011-02-18 10:14:07 -0800910 memsetString (simIO.v6.path);
911 memsetString (simIO.v6.data);
912 memsetString (simIO.v6.pin2);
913 memsetString (simIO.v6.aidPtr);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800914#endif
915
Wink Savillec0114b32011-02-18 10:14:07 -0800916 free (simIO.v6.path);
917 free (simIO.v6.data);
918 free (simIO.v6.pin2);
919 free (simIO.v6.aidPtr);
Wink Saville7f856802009-06-09 10:23:37 -0700920
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800921#ifdef MEMSET_FREED
922 memset(&simIO, 0, sizeof(simIO));
923#endif
924
925 return;
926invalid:
927 invalidCommandBlock(pRI);
928 return;
929}
930
931/**
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800932 * Callee expects const RIL_SIM_APDU *
933 * Payload is:
934 * int32_t sessionid
935 * int32_t cla
936 * int32_t instruction
937 * int32_t p1, p2, p3
938 * String data
939 */
940static void
941dispatchSIM_APDU (Parcel &p, RequestInfo *pRI) {
942 int32_t t;
943 status_t status;
944 RIL_SIM_APDU apdu;
945
Robert Greenwalt191e4dc2015-04-29 16:57:39 -0700946#if VDBG
Mark Salyzyndba25612015-04-09 07:18:35 -0700947 RLOGD("dispatchSIM_APDU");
Robert Greenwalt191e4dc2015-04-29 16:57:39 -0700948#endif
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800949 memset (&apdu, 0, sizeof(RIL_SIM_APDU));
950
951 // Note we only check status at the end. Any single failure leads to
952 // subsequent reads filing.
953 status = p.readInt32(&t);
954 apdu.sessionid = (int)t;
955
956 status = p.readInt32(&t);
957 apdu.cla = (int)t;
958
959 status = p.readInt32(&t);
960 apdu.instruction = (int)t;
961
962 status = p.readInt32(&t);
963 apdu.p1 = (int)t;
964
965 status = p.readInt32(&t);
966 apdu.p2 = (int)t;
967
968 status = p.readInt32(&t);
969 apdu.p3 = (int)t;
970
971 apdu.data = strdupReadString(p);
972
973 startRequest;
974 appendPrintBuf("%ssessionid=%d,cla=%d,ins=%d,p1=%d,p2=%d,p3=%d,data=%s",
975 printBuf, apdu.sessionid, apdu.cla, apdu.instruction, apdu.p1, apdu.p2,
976 apdu.p3, (char*)apdu.data);
977 closeRequest;
978 printRequest(pRI->token, pRI->pCI->requestNumber);
979
980 if (status != NO_ERROR) {
981 goto invalid;
982 }
983
Etan Cohend3652192014-06-20 08:28:44 -0700984 CALL_ONREQUEST(pRI->pCI->requestNumber, &apdu, sizeof(RIL_SIM_APDU), pRI, pRI->socket_id);
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800985
986#ifdef MEMSET_FREED
987 memsetString(apdu.data);
988#endif
989 free(apdu.data);
990
991#ifdef MEMSET_FREED
992 memset(&apdu, 0, sizeof(RIL_SIM_APDU));
993#endif
994
995 return;
996invalid:
997 invalidCommandBlock(pRI);
998 return;
999}
1000
1001
1002/**
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001003 * Callee expects const RIL_CallForwardInfo *
1004 * Payload is:
1005 * int32_t status/action
1006 * int32_t reason
1007 * int32_t serviceCode
1008 * int32_t toa
1009 * String number (0 length -> null)
1010 * int32_t timeSeconds
1011 */
Wink Saville7f856802009-06-09 10:23:37 -07001012static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001013dispatchCallForward(Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001014 RIL_CallForwardInfo cff;
1015 int32_t t;
1016 status_t status;
1017
Mark Salyzyndba25612015-04-09 07:18:35 -07001018 RLOGD("dispatchCallForward");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001019 memset (&cff, 0, sizeof(cff));
1020
Wink Saville7f856802009-06-09 10:23:37 -07001021 // note we only check status at the end
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001022
1023 status = p.readInt32(&t);
1024 cff.status = (int)t;
Wink Saville7f856802009-06-09 10:23:37 -07001025
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001026 status = p.readInt32(&t);
1027 cff.reason = (int)t;
1028
1029 status = p.readInt32(&t);
1030 cff.serviceClass = (int)t;
1031
1032 status = p.readInt32(&t);
1033 cff.toa = (int)t;
1034
1035 cff.number = strdupReadString(p);
1036
1037 status = p.readInt32(&t);
1038 cff.timeSeconds = (int)t;
1039
1040 if (status != NO_ERROR) {
1041 goto invalid;
1042 }
1043
1044 // special case: number 0-length fields is null
1045
1046 if (cff.number != NULL && strlen (cff.number) == 0) {
1047 cff.number = NULL;
1048 }
1049
1050 startRequest;
1051 appendPrintBuf("%sstat=%d,reason=%d,serv=%d,toa=%d,%s,tout=%d", printBuf,
1052 cff.status, cff.reason, cff.serviceClass, cff.toa,
1053 (char*)cff.number, cff.timeSeconds);
1054 closeRequest;
1055 printRequest(pRI->token, pRI->pCI->requestNumber);
1056
Etan Cohend3652192014-06-20 08:28:44 -07001057 CALL_ONREQUEST(pRI->pCI->requestNumber, &cff, sizeof(cff), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001058
1059#ifdef MEMSET_FREED
1060 memsetString(cff.number);
1061#endif
1062
1063 free (cff.number);
1064
1065#ifdef MEMSET_FREED
1066 memset(&cff, 0, sizeof(cff));
1067#endif
1068
1069 return;
1070invalid:
1071 invalidCommandBlock(pRI);
1072 return;
1073}
1074
1075
Wink Saville7f856802009-06-09 10:23:37 -07001076static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001077dispatchRaw(Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001078 int32_t len;
1079 status_t status;
1080 const void *data;
1081
1082 status = p.readInt32(&len);
1083
1084 if (status != NO_ERROR) {
1085 goto invalid;
1086 }
1087
1088 // The java code writes -1 for null arrays
1089 if (((int)len) == -1) {
1090 data = NULL;
1091 len = 0;
Wink Saville7f856802009-06-09 10:23:37 -07001092 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001093
1094 data = p.readInplace(len);
1095
1096 startRequest;
1097 appendPrintBuf("%sraw_size=%d", printBuf, len);
1098 closeRequest;
1099 printRequest(pRI->token, pRI->pCI->requestNumber);
1100
Etan Cohend3652192014-06-20 08:28:44 -07001101 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<void *>(data), len, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001102
1103 return;
1104invalid:
1105 invalidCommandBlock(pRI);
1106 return;
1107}
1108
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001109static status_t
1110constructCdmaSms(Parcel &p, RequestInfo *pRI, RIL_CDMA_SMS_Message& rcsm) {
Wink Savillef4c4d362009-04-02 01:37:03 -07001111 int32_t t;
1112 uint8_t ut;
1113 status_t status;
1114 int32_t digitCount;
1115 int digitLimit;
Wink Saville7f856802009-06-09 10:23:37 -07001116
Wink Savillef4c4d362009-04-02 01:37:03 -07001117 memset(&rcsm, 0, sizeof(rcsm));
1118
1119 status = p.readInt32(&t);
1120 rcsm.uTeleserviceID = (int) t;
1121
1122 status = p.read(&ut,sizeof(ut));
1123 rcsm.bIsServicePresent = (uint8_t) ut;
1124
1125 status = p.readInt32(&t);
1126 rcsm.uServicecategory = (int) t;
1127
1128 status = p.readInt32(&t);
1129 rcsm.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1130
1131 status = p.readInt32(&t);
1132 rcsm.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1133
1134 status = p.readInt32(&t);
1135 rcsm.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1136
1137 status = p.readInt32(&t);
1138 rcsm.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1139
1140 status = p.read(&ut,sizeof(ut));
1141 rcsm.sAddress.number_of_digits= (uint8_t) ut;
1142
1143 digitLimit= MIN((rcsm.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
1144 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1145 status = p.read(&ut,sizeof(ut));
1146 rcsm.sAddress.digits[digitCount] = (uint8_t) ut;
1147 }
1148
Wink Saville7f856802009-06-09 10:23:37 -07001149 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001150 rcsm.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1151
Wink Saville7f856802009-06-09 10:23:37 -07001152 status = p.read(&ut,sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001153 rcsm.sSubAddress.odd = (uint8_t) ut;
1154
1155 status = p.read(&ut,sizeof(ut));
1156 rcsm.sSubAddress.number_of_digits = (uint8_t) ut;
1157
1158 digitLimit= MIN((rcsm.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
Wink Saville7f856802009-06-09 10:23:37 -07001159 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1160 status = p.read(&ut,sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001161 rcsm.sSubAddress.digits[digitCount] = (uint8_t) ut;
1162 }
1163
Wink Saville7f856802009-06-09 10:23:37 -07001164 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001165 rcsm.uBearerDataLen = (int) t;
1166
1167 digitLimit= MIN((rcsm.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
Wink Saville7f856802009-06-09 10:23:37 -07001168 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1169 status = p.read(&ut, sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001170 rcsm.aBearerData[digitCount] = (uint8_t) ut;
1171 }
1172
1173 if (status != NO_ERROR) {
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001174 return status;
Wink Savillef4c4d362009-04-02 01:37:03 -07001175 }
1176
1177 startRequest;
1178 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
Wink Saville1b5fd232009-04-22 14:50:00 -07001179 sAddress.digit_mode=%d, sAddress.Number_mode=%d, sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07001180 printBuf, rcsm.uTeleserviceID,rcsm.bIsServicePresent,rcsm.uServicecategory,
Wink Saville1b5fd232009-04-22 14:50:00 -07001181 rcsm.sAddress.digit_mode, rcsm.sAddress.number_mode,rcsm.sAddress.number_type);
Wink Savillef4c4d362009-04-02 01:37:03 -07001182 closeRequest;
Wink Saville7f856802009-06-09 10:23:37 -07001183
Wink Savillef4c4d362009-04-02 01:37:03 -07001184 printRequest(pRI->token, pRI->pCI->requestNumber);
1185
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001186 return status;
1187}
1188
1189static void
1190dispatchCdmaSms(Parcel &p, RequestInfo *pRI) {
1191 RIL_CDMA_SMS_Message rcsm;
1192
Mark Salyzyndba25612015-04-09 07:18:35 -07001193 RLOGD("dispatchCdmaSms");
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001194 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1195 goto invalid;
1196 }
1197
Etan Cohend3652192014-06-20 08:28:44 -07001198 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001199
1200#ifdef MEMSET_FREED
1201 memset(&rcsm, 0, sizeof(rcsm));
1202#endif
1203
1204 return;
1205
1206invalid:
1207 invalidCommandBlock(pRI);
1208 return;
1209}
1210
Wink Saville7f856802009-06-09 10:23:37 -07001211static void
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001212dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1213 RIL_IMS_SMS_Message rism;
1214 RIL_CDMA_SMS_Message rcsm;
1215
Mark Salyzyndba25612015-04-09 07:18:35 -07001216 RLOGD("dispatchImsCdmaSms: retry=%d, messageRef=%d", retry, messageRef);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001217
1218 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1219 goto invalid;
1220 }
1221 memset(&rism, 0, sizeof(rism));
1222 rism.tech = RADIO_TECH_3GPP2;
1223 rism.retry = retry;
1224 rism.messageRef = messageRef;
1225 rism.message.cdmaMessage = &rcsm;
1226
Etan Cohend3652192014-06-20 08:28:44 -07001227 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001228 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Etan Cohend3652192014-06-20 08:28:44 -07001229 +sizeof(rcsm),pRI, pRI->socket_id);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001230
1231#ifdef MEMSET_FREED
1232 memset(&rcsm, 0, sizeof(rcsm));
1233 memset(&rism, 0, sizeof(rism));
1234#endif
1235
1236 return;
1237
1238invalid:
1239 invalidCommandBlock(pRI);
1240 return;
1241}
1242
1243static void
1244dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1245 RIL_IMS_SMS_Message rism;
1246 int32_t countStrings;
1247 status_t status;
1248 size_t datalen;
1249 char **pStrings;
Mark Salyzyndba25612015-04-09 07:18:35 -07001250 RLOGD("dispatchImsGsmSms: retry=%d, messageRef=%d", retry, messageRef);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001251
1252 status = p.readInt32 (&countStrings);
1253
1254 if (status != NO_ERROR) {
1255 goto invalid;
1256 }
1257
1258 memset(&rism, 0, sizeof(rism));
1259 rism.tech = RADIO_TECH_3GPP;
1260 rism.retry = retry;
1261 rism.messageRef = messageRef;
1262
1263 startRequest;
Etan Cohen5d891b72014-02-27 17:25:17 -08001264 appendPrintBuf("%stech=%d, retry=%d, messageRef=%d, ", printBuf,
1265 (int)rism.tech, (int)rism.retry, rism.messageRef);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001266 if (countStrings == 0) {
1267 // just some non-null pointer
1268 pStrings = (char **)alloca(sizeof(char *));
1269 datalen = 0;
1270 } else if (((int)countStrings) == -1) {
1271 pStrings = NULL;
1272 datalen = 0;
1273 } else {
1274 datalen = sizeof(char *) * countStrings;
1275
1276 pStrings = (char **)alloca(datalen);
1277
1278 for (int i = 0 ; i < countStrings ; i++) {
1279 pStrings[i] = strdupReadString(p);
1280 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
1281 }
1282 }
1283 removeLastChar;
1284 closeRequest;
1285 printRequest(pRI->token, pRI->pCI->requestNumber);
1286
1287 rism.message.gsmMessage = pStrings;
Etan Cohend3652192014-06-20 08:28:44 -07001288 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001289 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Etan Cohend3652192014-06-20 08:28:44 -07001290 +datalen, pRI, pRI->socket_id);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001291
1292 if (pStrings != NULL) {
1293 for (int i = 0 ; i < countStrings ; i++) {
1294#ifdef MEMSET_FREED
1295 memsetString (pStrings[i]);
1296#endif
1297 free(pStrings[i]);
1298 }
1299
1300#ifdef MEMSET_FREED
1301 memset(pStrings, 0, datalen);
1302#endif
1303 }
1304
1305#ifdef MEMSET_FREED
1306 memset(&rism, 0, sizeof(rism));
1307#endif
1308 return;
1309invalid:
1310 ALOGE("dispatchImsGsmSms invalid block");
1311 invalidCommandBlock(pRI);
1312 return;
1313}
1314
1315static void
1316dispatchImsSms(Parcel &p, RequestInfo *pRI) {
1317 int32_t t;
1318 status_t status = p.readInt32(&t);
1319 RIL_RadioTechnologyFamily format;
1320 uint8_t retry;
1321 int32_t messageRef;
1322
Mark Salyzyndba25612015-04-09 07:18:35 -07001323 RLOGD("dispatchImsSms");
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001324 if (status != NO_ERROR) {
1325 goto invalid;
1326 }
1327 format = (RIL_RadioTechnologyFamily) t;
1328
1329 // read retry field
1330 status = p.read(&retry,sizeof(retry));
1331 if (status != NO_ERROR) {
1332 goto invalid;
1333 }
1334 // read messageRef field
1335 status = p.read(&messageRef,sizeof(messageRef));
1336 if (status != NO_ERROR) {
1337 goto invalid;
1338 }
1339
1340 if (RADIO_TECH_3GPP == format) {
1341 dispatchImsGsmSms(p, pRI, retry, messageRef);
1342 } else if (RADIO_TECH_3GPP2 == format) {
1343 dispatchImsCdmaSms(p, pRI, retry, messageRef);
1344 } else {
1345 ALOGE("requestImsSendSMS invalid format value =%d", format);
1346 }
1347
1348 return;
1349
1350invalid:
1351 invalidCommandBlock(pRI);
1352 return;
1353}
1354
1355static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001356dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI) {
1357 RIL_CDMA_SMS_Ack rcsa;
1358 int32_t t;
1359 status_t status;
1360 int32_t digitCount;
1361
Mark Salyzyndba25612015-04-09 07:18:35 -07001362 RLOGD("dispatchCdmaSmsAck");
Wink Savillef4c4d362009-04-02 01:37:03 -07001363 memset(&rcsa, 0, sizeof(rcsa));
1364
1365 status = p.readInt32(&t);
1366 rcsa.uErrorClass = (RIL_CDMA_SMS_ErrorClass) t;
1367
1368 status = p.readInt32(&t);
1369 rcsa.uSMSCauseCode = (int) t;
1370
1371 if (status != NO_ERROR) {
1372 goto invalid;
1373 }
1374
1375 startRequest;
Wink Saville1b5fd232009-04-22 14:50:00 -07001376 appendPrintBuf("%suErrorClass=%d, uTLStatus=%d, ",
1377 printBuf, rcsa.uErrorClass, rcsa.uSMSCauseCode);
Wink Savillef4c4d362009-04-02 01:37:03 -07001378 closeRequest;
1379
1380 printRequest(pRI->token, pRI->pCI->requestNumber);
1381
Etan Cohend3652192014-06-20 08:28:44 -07001382 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsa, sizeof(rcsa),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001383
1384#ifdef MEMSET_FREED
1385 memset(&rcsa, 0, sizeof(rcsa));
1386#endif
1387
1388 return;
1389
1390invalid:
1391 invalidCommandBlock(pRI);
1392 return;
1393}
1394
Wink Savillea592eeb2009-05-22 13:26:36 -07001395static void
1396dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1397 int32_t t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001398 status_t status;
Wink Savillea592eeb2009-05-22 13:26:36 -07001399 int32_t num;
Wink Savillef4c4d362009-04-02 01:37:03 -07001400
Wink Savillea592eeb2009-05-22 13:26:36 -07001401 status = p.readInt32(&num);
Wink Savillef4c4d362009-04-02 01:37:03 -07001402 if (status != NO_ERROR) {
1403 goto invalid;
1404 }
1405
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001406 {
1407 RIL_GSM_BroadcastSmsConfigInfo gsmBci[num];
1408 RIL_GSM_BroadcastSmsConfigInfo *gsmBciPtrs[num];
Wink Savillea592eeb2009-05-22 13:26:36 -07001409
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001410 startRequest;
1411 for (int i = 0 ; i < num ; i++ ) {
1412 gsmBciPtrs[i] = &gsmBci[i];
Wink Savillef4c4d362009-04-02 01:37:03 -07001413
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001414 status = p.readInt32(&t);
1415 gsmBci[i].fromServiceId = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001416
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001417 status = p.readInt32(&t);
1418 gsmBci[i].toServiceId = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001419
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001420 status = p.readInt32(&t);
1421 gsmBci[i].fromCodeScheme = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001422
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001423 status = p.readInt32(&t);
1424 gsmBci[i].toCodeScheme = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001425
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001426 status = p.readInt32(&t);
1427 gsmBci[i].selected = (uint8_t) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001428
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001429 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId =%d, \
1430 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]", printBuf, i,
1431 gsmBci[i].fromServiceId, gsmBci[i].toServiceId,
1432 gsmBci[i].fromCodeScheme, gsmBci[i].toCodeScheme,
1433 gsmBci[i].selected);
1434 }
1435 closeRequest;
Wink Savillef4c4d362009-04-02 01:37:03 -07001436
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001437 if (status != NO_ERROR) {
1438 goto invalid;
1439 }
Wink Savillef4c4d362009-04-02 01:37:03 -07001440
Etan Cohend3652192014-06-20 08:28:44 -07001441 CALL_ONREQUEST(pRI->pCI->requestNumber,
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001442 gsmBciPtrs,
1443 num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *),
Etan Cohend3652192014-06-20 08:28:44 -07001444 pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001445
1446#ifdef MEMSET_FREED
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001447 memset(gsmBci, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo));
1448 memset(gsmBciPtrs, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *));
Wink Savillef4c4d362009-04-02 01:37:03 -07001449#endif
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001450 }
Wink Savillef4c4d362009-04-02 01:37:03 -07001451
1452 return;
1453
1454invalid:
1455 invalidCommandBlock(pRI);
1456 return;
Wink Savillea592eeb2009-05-22 13:26:36 -07001457}
Wink Savillef4c4d362009-04-02 01:37:03 -07001458
Wink Savillea592eeb2009-05-22 13:26:36 -07001459static void
1460dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1461 int32_t t;
1462 status_t status;
1463 int32_t num;
1464
1465 status = p.readInt32(&num);
1466 if (status != NO_ERROR) {
1467 goto invalid;
1468 }
1469
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001470 {
1471 RIL_CDMA_BroadcastSmsConfigInfo cdmaBci[num];
1472 RIL_CDMA_BroadcastSmsConfigInfo *cdmaBciPtrs[num];
Wink Savillea592eeb2009-05-22 13:26:36 -07001473
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001474 startRequest;
1475 for (int i = 0 ; i < num ; i++ ) {
1476 cdmaBciPtrs[i] = &cdmaBci[i];
Wink Savillea592eeb2009-05-22 13:26:36 -07001477
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001478 status = p.readInt32(&t);
1479 cdmaBci[i].service_category = (int) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001480
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001481 status = p.readInt32(&t);
1482 cdmaBci[i].language = (int) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001483
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001484 status = p.readInt32(&t);
1485 cdmaBci[i].selected = (uint8_t) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001486
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001487 appendPrintBuf("%s [%d: service_category=%d, language =%d, \
1488 entries.bSelected =%d]", printBuf, i, cdmaBci[i].service_category,
1489 cdmaBci[i].language, cdmaBci[i].selected);
1490 }
1491 closeRequest;
Wink Savillea592eeb2009-05-22 13:26:36 -07001492
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001493 if (status != NO_ERROR) {
1494 goto invalid;
1495 }
Wink Savillea592eeb2009-05-22 13:26:36 -07001496
Etan Cohend3652192014-06-20 08:28:44 -07001497 CALL_ONREQUEST(pRI->pCI->requestNumber,
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001498 cdmaBciPtrs,
1499 num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *),
Etan Cohend3652192014-06-20 08:28:44 -07001500 pRI, pRI->socket_id);
Wink Savillea592eeb2009-05-22 13:26:36 -07001501
1502#ifdef MEMSET_FREED
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001503 memset(cdmaBci, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo));
1504 memset(cdmaBciPtrs, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *));
Wink Savillea592eeb2009-05-22 13:26:36 -07001505#endif
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001506 }
Wink Savillea592eeb2009-05-22 13:26:36 -07001507
1508 return;
1509
1510invalid:
1511 invalidCommandBlock(pRI);
1512 return;
Wink Savillef4c4d362009-04-02 01:37:03 -07001513}
1514
1515static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI) {
1516 RIL_CDMA_SMS_WriteArgs rcsw;
1517 int32_t t;
1518 uint32_t ut;
1519 uint8_t uct;
1520 status_t status;
1521 int32_t digitCount;
1522
1523 memset(&rcsw, 0, sizeof(rcsw));
1524
1525 status = p.readInt32(&t);
1526 rcsw.status = t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001527
Wink Savillef4c4d362009-04-02 01:37:03 -07001528 status = p.readInt32(&t);
1529 rcsw.message.uTeleserviceID = (int) t;
1530
1531 status = p.read(&uct,sizeof(uct));
1532 rcsw.message.bIsServicePresent = (uint8_t) uct;
1533
1534 status = p.readInt32(&t);
1535 rcsw.message.uServicecategory = (int) t;
1536
1537 status = p.readInt32(&t);
1538 rcsw.message.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1539
1540 status = p.readInt32(&t);
1541 rcsw.message.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1542
1543 status = p.readInt32(&t);
1544 rcsw.message.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1545
1546 status = p.readInt32(&t);
1547 rcsw.message.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1548
1549 status = p.read(&uct,sizeof(uct));
1550 rcsw.message.sAddress.number_of_digits = (uint8_t) uct;
1551
1552 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_ADDRESS_MAX; digitCount ++) {
1553 status = p.read(&uct,sizeof(uct));
1554 rcsw.message.sAddress.digits[digitCount] = (uint8_t) uct;
1555 }
1556
Wink Savillea592eeb2009-05-22 13:26:36 -07001557 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001558 rcsw.message.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1559
Wink Savillea592eeb2009-05-22 13:26:36 -07001560 status = p.read(&uct,sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001561 rcsw.message.sSubAddress.odd = (uint8_t) uct;
1562
1563 status = p.read(&uct,sizeof(uct));
1564 rcsw.message.sSubAddress.number_of_digits = (uint8_t) uct;
1565
1566 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_SUBADDRESS_MAX; digitCount ++) {
Wink Savillea592eeb2009-05-22 13:26:36 -07001567 status = p.read(&uct,sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001568 rcsw.message.sSubAddress.digits[digitCount] = (uint8_t) uct;
1569 }
1570
Wink Savillea592eeb2009-05-22 13:26:36 -07001571 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001572 rcsw.message.uBearerDataLen = (int) t;
1573
1574 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_BEARER_DATA_MAX; digitCount ++) {
Wink Savillea592eeb2009-05-22 13:26:36 -07001575 status = p.read(&uct, sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001576 rcsw.message.aBearerData[digitCount] = (uint8_t) uct;
1577 }
1578
1579 if (status != NO_ERROR) {
1580 goto invalid;
1581 }
1582
1583 startRequest;
Wink Saville1b5fd232009-04-22 14:50:00 -07001584 appendPrintBuf("%sstatus=%d, message.uTeleserviceID=%d, message.bIsServicePresent=%d, \
1585 message.uServicecategory=%d, message.sAddress.digit_mode=%d, \
1586 message.sAddress.number_mode=%d, \
1587 message.sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07001588 printBuf, rcsw.status, rcsw.message.uTeleserviceID, rcsw.message.bIsServicePresent,
Wink Saville1b5fd232009-04-22 14:50:00 -07001589 rcsw.message.uServicecategory, rcsw.message.sAddress.digit_mode,
1590 rcsw.message.sAddress.number_mode,
1591 rcsw.message.sAddress.number_type);
Wink Savillef4c4d362009-04-02 01:37:03 -07001592 closeRequest;
1593
1594 printRequest(pRI->token, pRI->pCI->requestNumber);
1595
Etan Cohend3652192014-06-20 08:28:44 -07001596 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsw, sizeof(rcsw),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001597
1598#ifdef MEMSET_FREED
1599 memset(&rcsw, 0, sizeof(rcsw));
1600#endif
1601
1602 return;
1603
1604invalid:
1605 invalidCommandBlock(pRI);
1606 return;
1607
1608}
1609
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -07001610// For backwards compatibility in RIL_REQUEST_SETUP_DATA_CALL.
1611// Version 4 of the RIL interface adds a new PDP type parameter to support
1612// IPv6 and dual-stack PDP contexts. When dealing with a previous version of
1613// RIL, remove the parameter from the request.
1614static void dispatchDataCall(Parcel& p, RequestInfo *pRI) {
1615 // In RIL v3, REQUEST_SETUP_DATA_CALL takes 6 parameters.
1616 const int numParamsRilV3 = 6;
1617
1618 // The first bytes of the RIL parcel contain the request number and the
1619 // serial number - see processCommandBuffer(). Copy them over too.
1620 int pos = p.dataPosition();
1621
1622 int numParams = p.readInt32();
1623 if (s_callbacks.version < 4 && numParams > numParamsRilV3) {
1624 Parcel p2;
1625 p2.appendFrom(&p, 0, pos);
1626 p2.writeInt32(numParamsRilV3);
1627 for(int i = 0; i < numParamsRilV3; i++) {
1628 p2.writeString16(p.readString16());
1629 }
1630 p2.setDataPosition(pos);
1631 dispatchStrings(p2, pRI);
1632 } else {
Lorenzo Colitti57ce1f22010-09-13 12:23:50 -07001633 p.setDataPosition(pos);
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -07001634 dispatchStrings(p, pRI);
1635 }
1636}
1637
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001638// For backwards compatibility with RILs that dont support RIL_REQUEST_VOICE_RADIO_TECH.
1639// When all RILs handle this request, this function can be removed and
1640// the request can be sent directly to the RIL using dispatchVoid.
1641static void dispatchVoiceRadioTech(Parcel& p, RequestInfo *pRI) {
Etan Cohend3652192014-06-20 08:28:44 -07001642 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001643
1644 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1645 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1646 }
1647
1648 // RILs that support RADIO_STATE_ON should support this request.
1649 if (RADIO_STATE_ON == state) {
1650 dispatchVoid(p, pRI);
1651 return;
1652 }
1653
1654 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1655 // will not support this new request either and decode Voice Radio Technology
1656 // from Radio State
1657 voiceRadioTech = decodeVoiceRadioTechnology(state);
1658
1659 if (voiceRadioTech < 0)
1660 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1661 else
1662 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &voiceRadioTech, sizeof(int));
1663}
1664
1665// For backwards compatibility in RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE:.
1666// When all RILs handle this request, this function can be removed and
1667// the request can be sent directly to the RIL using dispatchVoid.
1668static void dispatchCdmaSubscriptionSource(Parcel& p, RequestInfo *pRI) {
Etan Cohend3652192014-06-20 08:28:44 -07001669 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001670
1671 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1672 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1673 }
1674
1675 // RILs that support RADIO_STATE_ON should support this request.
1676 if (RADIO_STATE_ON == state) {
1677 dispatchVoid(p, pRI);
1678 return;
1679 }
1680
1681 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1682 // will not support this new request either and decode CDMA Subscription Source
1683 // from Radio State
1684 cdmaSubscriptionSource = decodeCdmaSubscriptionSource(state);
1685
1686 if (cdmaSubscriptionSource < 0)
1687 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1688 else
1689 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &cdmaSubscriptionSource, sizeof(int));
1690}
1691
Sungmin Choi75697532013-04-26 15:04:45 -07001692static void dispatchSetInitialAttachApn(Parcel &p, RequestInfo *pRI)
1693{
1694 RIL_InitialAttachApn pf;
1695 int32_t t;
1696 status_t status;
1697
1698 memset(&pf, 0, sizeof(pf));
1699
1700 pf.apn = strdupReadString(p);
1701 pf.protocol = strdupReadString(p);
1702
1703 status = p.readInt32(&t);
1704 pf.authtype = (int) t;
1705
1706 pf.username = strdupReadString(p);
1707 pf.password = strdupReadString(p);
1708
1709 startRequest;
Etan Cohen5d891b72014-02-27 17:25:17 -08001710 appendPrintBuf("%sapn=%s, protocol=%s, authtype=%d, username=%s, password=%s",
1711 printBuf, pf.apn, pf.protocol, pf.authtype, pf.username, pf.password);
Sungmin Choi75697532013-04-26 15:04:45 -07001712 closeRequest;
1713 printRequest(pRI->token, pRI->pCI->requestNumber);
1714
1715 if (status != NO_ERROR) {
1716 goto invalid;
1717 }
Etan Cohend3652192014-06-20 08:28:44 -07001718 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
Sungmin Choi75697532013-04-26 15:04:45 -07001719
1720#ifdef MEMSET_FREED
1721 memsetString(pf.apn);
1722 memsetString(pf.protocol);
1723 memsetString(pf.username);
1724 memsetString(pf.password);
1725#endif
1726
1727 free(pf.apn);
1728 free(pf.protocol);
1729 free(pf.username);
1730 free(pf.password);
1731
1732#ifdef MEMSET_FREED
1733 memset(&pf, 0, sizeof(pf));
1734#endif
1735
1736 return;
1737invalid:
1738 invalidCommandBlock(pRI);
1739 return;
1740}
1741
Jake Hamby8a4a2332014-01-15 13:12:05 -08001742static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI) {
1743 RIL_NV_ReadItem nvri;
1744 int32_t t;
1745 status_t status;
1746
1747 memset(&nvri, 0, sizeof(nvri));
1748
1749 status = p.readInt32(&t);
1750 nvri.itemID = (RIL_NV_Item) t;
1751
1752 if (status != NO_ERROR) {
1753 goto invalid;
1754 }
1755
1756 startRequest;
1757 appendPrintBuf("%snvri.itemID=%d, ", printBuf, nvri.itemID);
1758 closeRequest;
1759
1760 printRequest(pRI->token, pRI->pCI->requestNumber);
1761
Etan Cohend3652192014-06-20 08:28:44 -07001762 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvri, sizeof(nvri), pRI, pRI->socket_id);
Jake Hamby8a4a2332014-01-15 13:12:05 -08001763
1764#ifdef MEMSET_FREED
1765 memset(&nvri, 0, sizeof(nvri));
1766#endif
1767
1768 return;
1769
1770invalid:
1771 invalidCommandBlock(pRI);
1772 return;
1773}
1774
1775static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI) {
1776 RIL_NV_WriteItem nvwi;
1777 int32_t t;
1778 status_t status;
1779
1780 memset(&nvwi, 0, sizeof(nvwi));
1781
1782 status = p.readInt32(&t);
1783 nvwi.itemID = (RIL_NV_Item) t;
1784
1785 nvwi.value = strdupReadString(p);
1786
1787 if (status != NO_ERROR || nvwi.value == NULL) {
1788 goto invalid;
1789 }
1790
1791 startRequest;
1792 appendPrintBuf("%snvwi.itemID=%d, value=%s, ", printBuf, nvwi.itemID,
1793 nvwi.value);
1794 closeRequest;
1795
1796 printRequest(pRI->token, pRI->pCI->requestNumber);
1797
Etan Cohend3652192014-06-20 08:28:44 -07001798 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvwi, sizeof(nvwi), pRI, pRI->socket_id);
Jake Hamby8a4a2332014-01-15 13:12:05 -08001799
1800#ifdef MEMSET_FREED
1801 memsetString(nvwi.value);
1802#endif
1803
1804 free(nvwi.value);
1805
1806#ifdef MEMSET_FREED
1807 memset(&nvwi, 0, sizeof(nvwi));
1808#endif
1809
1810 return;
1811
1812invalid:
1813 invalidCommandBlock(pRI);
1814 return;
1815}
1816
1817
Etan Cohend3652192014-06-20 08:28:44 -07001818static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI) {
1819 RIL_SelectUiccSub uicc_sub;
1820 status_t status;
1821 int32_t t;
1822 memset(&uicc_sub, 0, sizeof(uicc_sub));
1823
1824 status = p.readInt32(&t);
1825 if (status != NO_ERROR) {
1826 goto invalid;
1827 }
1828 uicc_sub.slot = (int) t;
1829
1830 status = p.readInt32(&t);
1831 if (status != NO_ERROR) {
1832 goto invalid;
1833 }
1834 uicc_sub.app_index = (int) t;
1835
1836 status = p.readInt32(&t);
1837 if (status != NO_ERROR) {
1838 goto invalid;
1839 }
1840 uicc_sub.sub_type = (RIL_SubscriptionType) t;
1841
1842 status = p.readInt32(&t);
1843 if (status != NO_ERROR) {
1844 goto invalid;
1845 }
1846 uicc_sub.act_status = (RIL_UiccSubActStatus) t;
1847
1848 startRequest;
1849 appendPrintBuf("slot=%d, app_index=%d, act_status = %d", uicc_sub.slot, uicc_sub.app_index,
1850 uicc_sub.act_status);
1851 RLOGD("dispatchUiccSubscription, slot=%d, app_index=%d, act_status = %d", uicc_sub.slot,
1852 uicc_sub.app_index, uicc_sub.act_status);
1853 closeRequest;
1854 printRequest(pRI->token, pRI->pCI->requestNumber);
1855
1856 CALL_ONREQUEST(pRI->pCI->requestNumber, &uicc_sub, sizeof(uicc_sub), pRI, pRI->socket_id);
1857
1858#ifdef MEMSET_FREED
1859 memset(&uicc_sub, 0, sizeof(uicc_sub));
1860#endif
1861 return;
1862
1863invalid:
1864 invalidCommandBlock(pRI);
1865 return;
1866}
1867
Amit Mahajan90530a62014-07-01 15:54:08 -07001868static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI)
1869{
1870 RIL_SimAuthentication pf;
1871 int32_t t;
1872 status_t status;
1873
1874 memset(&pf, 0, sizeof(pf));
1875
1876 status = p.readInt32(&t);
1877 pf.authContext = (int) t;
1878 pf.authData = strdupReadString(p);
1879 pf.aid = strdupReadString(p);
1880
1881 startRequest;
1882 appendPrintBuf("authContext=%s, authData=%s, aid=%s", pf.authContext, pf.authData, pf.aid);
1883 closeRequest;
1884 printRequest(pRI->token, pRI->pCI->requestNumber);
1885
1886 if (status != NO_ERROR) {
1887 goto invalid;
1888 }
1889 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
1890
1891#ifdef MEMSET_FREED
1892 memsetString(pf.authData);
1893 memsetString(pf.aid);
1894#endif
1895
1896 free(pf.authData);
1897 free(pf.aid);
1898
1899#ifdef MEMSET_FREED
1900 memset(&pf, 0, sizeof(pf));
1901#endif
1902
1903 return;
1904invalid:
1905 invalidCommandBlock(pRI);
1906 return;
1907}
1908
Amit Mahajanc796e222014-08-13 16:54:01 +00001909static void dispatchDataProfile(Parcel &p, RequestInfo *pRI) {
1910 int32_t t;
1911 status_t status;
1912 int32_t num;
1913
1914 status = p.readInt32(&num);
1915 if (status != NO_ERROR) {
1916 goto invalid;
1917 }
1918
1919 {
1920 RIL_DataProfileInfo dataProfiles[num];
1921 RIL_DataProfileInfo *dataProfilePtrs[num];
1922
1923 startRequest;
1924 for (int i = 0 ; i < num ; i++ ) {
1925 dataProfilePtrs[i] = &dataProfiles[i];
1926
1927 status = p.readInt32(&t);
1928 dataProfiles[i].profileId = (int) t;
1929
1930 dataProfiles[i].apn = strdupReadString(p);
1931 dataProfiles[i].protocol = strdupReadString(p);
1932 status = p.readInt32(&t);
1933 dataProfiles[i].authType = (int) t;
1934
1935 dataProfiles[i].user = strdupReadString(p);
1936 dataProfiles[i].password = strdupReadString(p);
1937
1938 status = p.readInt32(&t);
1939 dataProfiles[i].type = (int) t;
1940
1941 status = p.readInt32(&t);
1942 dataProfiles[i].maxConnsTime = (int) t;
1943 status = p.readInt32(&t);
1944 dataProfiles[i].maxConns = (int) t;
1945 status = p.readInt32(&t);
1946 dataProfiles[i].waitTime = (int) t;
1947
1948 status = p.readInt32(&t);
1949 dataProfiles[i].enabled = (int) t;
1950
1951 appendPrintBuf("%s [%d: profileId=%d, apn =%s, protocol =%s, authType =%d, \
1952 user =%s, password =%s, type =%d, maxConnsTime =%d, maxConns =%d, \
1953 waitTime =%d, enabled =%d]", printBuf, i, dataProfiles[i].profileId,
1954 dataProfiles[i].apn, dataProfiles[i].protocol, dataProfiles[i].authType,
1955 dataProfiles[i].user, dataProfiles[i].password, dataProfiles[i].type,
1956 dataProfiles[i].maxConnsTime, dataProfiles[i].maxConns,
1957 dataProfiles[i].waitTime, dataProfiles[i].enabled);
1958 }
1959 closeRequest;
1960 printRequest(pRI->token, pRI->pCI->requestNumber);
1961
1962 if (status != NO_ERROR) {
1963 goto invalid;
1964 }
1965 CALL_ONREQUEST(pRI->pCI->requestNumber,
1966 dataProfilePtrs,
1967 num * sizeof(RIL_DataProfileInfo *),
1968 pRI, pRI->socket_id);
1969
1970#ifdef MEMSET_FREED
1971 memset(dataProfiles, 0, num * sizeof(RIL_DataProfileInfo));
1972 memset(dataProfilePtrs, 0, num * sizeof(RIL_DataProfileInfo *));
1973#endif
1974 }
1975
1976 return;
1977
1978invalid:
1979 invalidCommandBlock(pRI);
1980 return;
1981}
1982
Wink Saville8b4e4f72014-10-17 15:01:45 -07001983static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI){
1984 RIL_RadioCapability rc;
1985 int32_t t;
1986 status_t status;
1987
1988 memset (&rc, 0, sizeof(RIL_RadioCapability));
1989
1990 status = p.readInt32(&t);
1991 rc.version = (int)t;
1992 if (status != NO_ERROR) {
1993 goto invalid;
1994 }
1995
1996 status = p.readInt32(&t);
1997 rc.session= (int)t;
1998 if (status != NO_ERROR) {
1999 goto invalid;
2000 }
2001
2002 status = p.readInt32(&t);
2003 rc.phase= (int)t;
2004 if (status != NO_ERROR) {
2005 goto invalid;
2006 }
2007
2008 status = p.readInt32(&t);
2009 rc.rat = (int)t;
2010 if (status != NO_ERROR) {
2011 goto invalid;
2012 }
2013
2014 status = readStringFromParcelInplace(p, rc.logicalModemUuid, sizeof(rc.logicalModemUuid));
2015 if (status != NO_ERROR) {
2016 goto invalid;
2017 }
2018
2019 status = p.readInt32(&t);
2020 rc.status = (int)t;
2021
2022 if (status != NO_ERROR) {
2023 goto invalid;
2024 }
2025
2026 startRequest;
2027 appendPrintBuf("%s [version:%d, session:%d, phase:%d, rat:%d, \
Legler Wu8caf06f2014-10-29 14:02:14 +08002028 logicalModemUuid:%s, status:%d", printBuf, rc.version, rc.session
2029 rc.phase, rc.rat, rc.logicalModemUuid, rc.session);
Wink Saville8b4e4f72014-10-17 15:01:45 -07002030
2031 closeRequest;
2032 printRequest(pRI->token, pRI->pCI->requestNumber);
2033
2034 CALL_ONREQUEST(pRI->pCI->requestNumber,
2035 &rc,
2036 sizeof(RIL_RadioCapability),
2037 pRI, pRI->socket_id);
2038 return;
2039invalid:
2040 invalidCommandBlock(pRI);
2041 return;
2042}
2043
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002044static int
Wink Savillef4c4d362009-04-02 01:37:03 -07002045blockingWrite(int fd, const void *buffer, size_t len) {
Wink Saville7f856802009-06-09 10:23:37 -07002046 size_t writeOffset = 0;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002047 const uint8_t *toWrite;
2048
2049 toWrite = (const uint8_t *)buffer;
2050
2051 while (writeOffset < len) {
2052 ssize_t written;
2053 do {
2054 written = write (fd, toWrite + writeOffset,
2055 len - writeOffset);
Banavathu, Srinivas Naik38884902011-07-05 20:04:25 +05302056 } while (written < 0 && ((errno == EINTR) || (errno == EAGAIN)));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002057
2058 if (written >= 0) {
2059 writeOffset += written;
2060 } else { // written < 0
Wink Saville8eb2a122012-11-19 16:05:13 -08002061 RLOGE ("RIL Response: unexpected error on write errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002062 close(fd);
2063 return -1;
2064 }
2065 }
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07002066#if VDBG
Dheeraj Shetty27976c42014-07-02 21:27:57 +02002067 RLOGE("RIL Response bytes written:%d", writeOffset);
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07002068#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002069 return 0;
2070}
2071
2072static int
Etan Cohend3652192014-06-20 08:28:44 -07002073sendResponseRaw (const void *data, size_t dataSize, RIL_SOCKET_ID socket_id) {
2074 int fd = s_ril_param_socket.fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002075 int ret;
2076 uint32_t header;
Etan Cohend3652192014-06-20 08:28:44 -07002077 pthread_mutex_t * writeMutexHook = &s_writeMutex;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002078
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07002079#if VDBG
Etan Cohend3652192014-06-20 08:28:44 -07002080 RLOGE("Send Response to %s", rilSocketIdToString(socket_id));
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07002081#endif
Etan Cohend3652192014-06-20 08:28:44 -07002082
2083#if (SIM_COUNT >= 2)
2084 if (socket_id == RIL_SOCKET_2) {
2085 fd = s_ril_param_socket2.fdCommand;
2086 writeMutexHook = &s_writeMutex_socket2;
2087 }
2088#if (SIM_COUNT >= 3)
2089 else if (socket_id == RIL_SOCKET_3) {
2090 fd = s_ril_param_socket3.fdCommand;
2091 writeMutexHook = &s_writeMutex_socket3;
2092 }
2093#endif
2094#if (SIM_COUNT >= 4)
2095 else if (socket_id == RIL_SOCKET_4) {
2096 fd = s_ril_param_socket4.fdCommand;
2097 writeMutexHook = &s_writeMutex_socket4;
2098 }
2099#endif
2100#endif
2101 if (fd < 0) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002102 return -1;
2103 }
2104
2105 if (dataSize > MAX_COMMAND_BYTES) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002106 RLOGE("RIL: packet larger than %u (%u)",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002107 MAX_COMMAND_BYTES, (unsigned int )dataSize);
2108
2109 return -1;
2110 }
Wink Saville7f856802009-06-09 10:23:37 -07002111
Etan Cohend3652192014-06-20 08:28:44 -07002112 pthread_mutex_lock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002113
2114 header = htonl(dataSize);
2115
2116 ret = blockingWrite(fd, (void *)&header, sizeof(header));
2117
2118 if (ret < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002119 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002120 return ret;
2121 }
2122
Kennyee1fadc2009-08-13 00:45:53 +08002123 ret = blockingWrite(fd, data, dataSize);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002124
2125 if (ret < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002126 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002127 return ret;
2128 }
2129
Etan Cohend3652192014-06-20 08:28:44 -07002130 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002131
2132 return 0;
2133}
2134
2135static int
Etan Cohend3652192014-06-20 08:28:44 -07002136sendResponse (Parcel &p, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002137 printResponse;
Etan Cohend3652192014-06-20 08:28:44 -07002138 return sendResponseRaw(p.data(), p.dataSize(), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002139}
2140
Mohamad Ayyash74f7e662014-04-18 11:43:28 -07002141/** response is an int* pointing to an array of ints */
Wink Saville7f856802009-06-09 10:23:37 -07002142
2143static int
Wink Savillef4c4d362009-04-02 01:37:03 -07002144responseInts(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002145 int numInts;
2146
2147 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002148 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002149 return RIL_ERRNO_INVALID_RESPONSE;
2150 }
2151 if (responselen % sizeof(int) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002152 RLOGE("responseInts: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002153 (int)responselen, (int)sizeof(int));
2154 return RIL_ERRNO_INVALID_RESPONSE;
2155 }
2156
2157 int *p_int = (int *) response;
2158
Mohamad Ayyash74f7e662014-04-18 11:43:28 -07002159 numInts = responselen / sizeof(int);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002160 p.writeInt32 (numInts);
2161
2162 /* each int*/
2163 startResponse;
2164 for (int i = 0 ; i < numInts ; i++) {
2165 appendPrintBuf("%s%d,", printBuf, p_int[i]);
2166 p.writeInt32(p_int[i]);
2167 }
2168 removeLastChar;
2169 closeResponse;
2170
2171 return 0;
2172}
2173
Chao Liu548a81e2015-05-14 16:13:46 -07002174// Response is an int or RIL_LastCallFailCauseInfo.
2175// Currently, only Shamu plans to use RIL_LastCallFailCauseInfo.
2176// TODO(yjl): Let all implementations use RIL_LastCallFailCauseInfo.
2177static int responseFailCause(Parcel &p, void *response, size_t responselen) {
2178 if (response == NULL && responselen != 0) {
2179 RLOGE("invalid response: NULL");
2180 return RIL_ERRNO_INVALID_RESPONSE;
2181 }
2182
2183 if (responselen == sizeof(int)) {
2184 return responseInts(p, response, responselen);
2185 } else if (responselen == sizeof(RIL_LastCallFailCauseInfo)) {
2186 startResponse;
2187 RIL_LastCallFailCauseInfo *p_fail_cause_info = (RIL_LastCallFailCauseInfo *) response;
2188 appendPrintBuf("%s[cause_code=%d,vendor_cause=%s]", printBuf, p_fail_cause_info->cause_code,
2189 p_fail_cause_info->vendor_cause);
2190 p.writeInt32(p_fail_cause_info->cause_code);
2191 writeStringToParcel(p, p_fail_cause_info->vendor_cause);
2192 removeLastChar;
2193 closeResponse;
2194 } else {
2195 RLOGE("responseFailCause: invalid response length %d expected an int or "
2196 "RIL_LastCallFailCauseInfo", (int)responselen);
2197 return RIL_ERRNO_INVALID_RESPONSE;
2198 }
2199
2200 return 0;
2201}
2202
Wink Saville43808972011-01-13 17:39:51 -08002203/** response is a char **, pointing to an array of char *'s
2204 The parcel will begin with the version */
2205static int responseStringsWithVersion(int version, Parcel &p, void *response, size_t responselen) {
2206 p.writeInt32(version);
2207 return responseStrings(p, response, responselen);
2208}
2209
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002210/** response is a char **, pointing to an array of char *'s */
Wink Savillef4c4d362009-04-02 01:37:03 -07002211static int responseStrings(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002212 int numStrings;
Wink Saville7f856802009-06-09 10:23:37 -07002213
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002214 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002215 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002216 return RIL_ERRNO_INVALID_RESPONSE;
2217 }
2218 if (responselen % sizeof(char *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002219 RLOGE("responseStrings: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002220 (int)responselen, (int)sizeof(char *));
2221 return RIL_ERRNO_INVALID_RESPONSE;
2222 }
2223
2224 if (response == NULL) {
2225 p.writeInt32 (0);
2226 } else {
2227 char **p_cur = (char **) response;
2228
2229 numStrings = responselen / sizeof(char *);
2230 p.writeInt32 (numStrings);
2231
2232 /* each string*/
2233 startResponse;
2234 for (int i = 0 ; i < numStrings ; i++) {
2235 appendPrintBuf("%s%s,", printBuf, (char*)p_cur[i]);
2236 writeStringToParcel (p, p_cur[i]);
2237 }
2238 removeLastChar;
2239 closeResponse;
2240 }
2241 return 0;
2242}
2243
2244
2245/**
Wink Saville7f856802009-06-09 10:23:37 -07002246 * NULL strings are accepted
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002247 * FIXME currently ignores responselen
2248 */
Wink Savillef4c4d362009-04-02 01:37:03 -07002249static int responseString(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002250 /* one string only */
2251 startResponse;
2252 appendPrintBuf("%s%s", printBuf, (char*)response);
2253 closeResponse;
2254
2255 writeStringToParcel(p, (const char *)response);
2256
2257 return 0;
2258}
2259
Wink Savillef4c4d362009-04-02 01:37:03 -07002260static int responseVoid(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002261 startResponse;
2262 removeLastChar;
2263 return 0;
2264}
2265
Wink Savillef4c4d362009-04-02 01:37:03 -07002266static int responseCallList(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002267 int num;
2268
2269 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002270 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002271 return RIL_ERRNO_INVALID_RESPONSE;
2272 }
2273
2274 if (responselen % sizeof (RIL_Call *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002275 RLOGE("responseCallList: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002276 (int)responselen, (int)sizeof (RIL_Call *));
2277 return RIL_ERRNO_INVALID_RESPONSE;
2278 }
2279
2280 startResponse;
2281 /* number of call info's */
2282 num = responselen / sizeof(RIL_Call *);
2283 p.writeInt32(num);
2284
2285 for (int i = 0 ; i < num ; i++) {
2286 RIL_Call *p_cur = ((RIL_Call **) response)[i];
2287 /* each call info */
2288 p.writeInt32(p_cur->state);
2289 p.writeInt32(p_cur->index);
2290 p.writeInt32(p_cur->toa);
2291 p.writeInt32(p_cur->isMpty);
2292 p.writeInt32(p_cur->isMT);
2293 p.writeInt32(p_cur->als);
2294 p.writeInt32(p_cur->isVoice);
Wink Saville1b5fd232009-04-22 14:50:00 -07002295 p.writeInt32(p_cur->isVoicePrivacy);
2296 writeStringToParcel(p, p_cur->number);
John Wangff368742009-03-24 17:56:29 -07002297 p.writeInt32(p_cur->numberPresentation);
Wink Saville1b5fd232009-04-22 14:50:00 -07002298 writeStringToParcel(p, p_cur->name);
2299 p.writeInt32(p_cur->namePresentation);
Wink Saville3a4840b2010-04-07 13:29:58 -07002300 // Remove when partners upgrade to version 3
Wink Saville74fa3882009-12-22 15:35:41 -08002301 if ((s_callbacks.version < 3) || (p_cur->uusInfo == NULL || p_cur->uusInfo->uusData == NULL)) {
2302 p.writeInt32(0); /* UUS Information is absent */
2303 } else {
2304 RIL_UUS_Info *uusInfo = p_cur->uusInfo;
2305 p.writeInt32(1); /* UUS Information is present */
2306 p.writeInt32(uusInfo->uusType);
2307 p.writeInt32(uusInfo->uusDcs);
2308 p.writeInt32(uusInfo->uusLength);
2309 p.write(uusInfo->uusData, uusInfo->uusLength);
2310 }
Wink Saville3d54e742009-05-18 18:00:44 -07002311 appendPrintBuf("%s[id=%d,%s,toa=%d,",
John Wangff368742009-03-24 17:56:29 -07002312 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002313 p_cur->index,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002314 callStateToString(p_cur->state),
Wink Saville3d54e742009-05-18 18:00:44 -07002315 p_cur->toa);
2316 appendPrintBuf("%s%s,%s,als=%d,%s,%s,",
2317 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002318 (p_cur->isMpty)?"conf":"norm",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002319 (p_cur->isMT)?"mt":"mo",
2320 p_cur->als,
2321 (p_cur->isVoice)?"voc":"nonvoc",
Wink Saville3d54e742009-05-18 18:00:44 -07002322 (p_cur->isVoicePrivacy)?"evp":"noevp");
2323 appendPrintBuf("%s%s,cli=%d,name='%s',%d]",
2324 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002325 p_cur->number,
2326 p_cur->numberPresentation,
2327 p_cur->name,
2328 p_cur->namePresentation);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002329 }
2330 removeLastChar;
2331 closeResponse;
2332
2333 return 0;
2334}
2335
Wink Savillef4c4d362009-04-02 01:37:03 -07002336static int responseSMS(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002337 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002338 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002339 return RIL_ERRNO_INVALID_RESPONSE;
2340 }
2341
2342 if (responselen != sizeof (RIL_SMS_Response) ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002343 RLOGE("invalid response length %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002344 (int)responselen, (int)sizeof (RIL_SMS_Response));
2345 return RIL_ERRNO_INVALID_RESPONSE;
2346 }
2347
2348 RIL_SMS_Response *p_cur = (RIL_SMS_Response *) response;
2349
2350 p.writeInt32(p_cur->messageRef);
2351 writeStringToParcel(p, p_cur->ackPDU);
Jaikumar Ganesh920c78f2009-06-04 10:53:15 -07002352 p.writeInt32(p_cur->errorCode);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002353
2354 startResponse;
Jaikumar Ganesh920c78f2009-06-04 10:53:15 -07002355 appendPrintBuf("%s%d,%s,%d", printBuf, p_cur->messageRef,
2356 (char*)p_cur->ackPDU, p_cur->errorCode);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002357 closeResponse;
2358
2359 return 0;
2360}
2361
Wink Savillec0114b32011-02-18 10:14:07 -08002362static int responseDataCallListV4(Parcel &p, void *response, size_t responselen)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002363{
2364 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002365 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002366 return RIL_ERRNO_INVALID_RESPONSE;
2367 }
2368
Wink Savillec0114b32011-02-18 10:14:07 -08002369 if (responselen % sizeof(RIL_Data_Call_Response_v4) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002370 RLOGE("responseDataCallListV4: invalid response length %d expected multiple of %d",
Wink Savillec0114b32011-02-18 10:14:07 -08002371 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v4));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002372 return RIL_ERRNO_INVALID_RESPONSE;
2373 }
2374
Amit Mahajan52500162014-07-29 17:36:48 -07002375 // Write version
2376 p.writeInt32(4);
2377
Wink Savillec0114b32011-02-18 10:14:07 -08002378 int num = responselen / sizeof(RIL_Data_Call_Response_v4);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002379 p.writeInt32(num);
2380
Wink Savillec0114b32011-02-18 10:14:07 -08002381 RIL_Data_Call_Response_v4 *p_cur = (RIL_Data_Call_Response_v4 *) response;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002382 startResponse;
2383 int i;
2384 for (i = 0; i < num; i++) {
2385 p.writeInt32(p_cur[i].cid);
2386 p.writeInt32(p_cur[i].active);
2387 writeStringToParcel(p, p_cur[i].type);
Wink Savillec0114b32011-02-18 10:14:07 -08002388 // apn is not used, so don't send.
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002389 writeStringToParcel(p, p_cur[i].address);
Wink Savillec0114b32011-02-18 10:14:07 -08002390 appendPrintBuf("%s[cid=%d,%s,%s,%s],", printBuf,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002391 p_cur[i].cid,
2392 (p_cur[i].active==0)?"down":"up",
2393 (char*)p_cur[i].type,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002394 (char*)p_cur[i].address);
2395 }
2396 removeLastChar;
2397 closeResponse;
2398
2399 return 0;
2400}
2401
Etan Cohend3652192014-06-20 08:28:44 -07002402static int responseDataCallListV6(Parcel &p, void *response, size_t responselen)
2403{
Amit Mahajan52500162014-07-29 17:36:48 -07002404 if (response == NULL && responselen != 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002405 RLOGE("invalid response: NULL");
2406 return RIL_ERRNO_INVALID_RESPONSE;
2407 }
2408
2409 if (responselen % sizeof(RIL_Data_Call_Response_v6) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002410 RLOGE("responseDataCallListV6: invalid response length %d expected multiple of %d",
Etan Cohend3652192014-06-20 08:28:44 -07002411 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v6));
2412 return RIL_ERRNO_INVALID_RESPONSE;
2413 }
2414
Amit Mahajan52500162014-07-29 17:36:48 -07002415 // Write version
2416 p.writeInt32(6);
2417
Etan Cohend3652192014-06-20 08:28:44 -07002418 int num = responselen / sizeof(RIL_Data_Call_Response_v6);
2419 p.writeInt32(num);
2420
2421 RIL_Data_Call_Response_v6 *p_cur = (RIL_Data_Call_Response_v6 *) response;
2422 startResponse;
2423 int i;
2424 for (i = 0; i < num; i++) {
2425 p.writeInt32((int)p_cur[i].status);
2426 p.writeInt32(p_cur[i].suggestedRetryTime);
2427 p.writeInt32(p_cur[i].cid);
2428 p.writeInt32(p_cur[i].active);
2429 writeStringToParcel(p, p_cur[i].type);
2430 writeStringToParcel(p, p_cur[i].ifname);
2431 writeStringToParcel(p, p_cur[i].addresses);
2432 writeStringToParcel(p, p_cur[i].dnses);
2433 writeStringToParcel(p, p_cur[i].gateways);
2434 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s],", printBuf,
2435 p_cur[i].status,
2436 p_cur[i].suggestedRetryTime,
2437 p_cur[i].cid,
2438 (p_cur[i].active==0)?"down":"up",
2439 (char*)p_cur[i].type,
2440 (char*)p_cur[i].ifname,
2441 (char*)p_cur[i].addresses,
2442 (char*)p_cur[i].dnses,
2443 (char*)p_cur[i].gateways);
2444 }
2445 removeLastChar;
2446 closeResponse;
2447
2448 return 0;
2449}
2450
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002451static int responseDataCallListV9(Parcel &p, void *response, size_t responselen)
2452{
2453 if (response == NULL && responselen != 0) {
2454 RLOGE("invalid response: NULL");
2455 return RIL_ERRNO_INVALID_RESPONSE;
2456 }
2457
2458 if (responselen % sizeof(RIL_Data_Call_Response_v9) != 0) {
2459 RLOGE("responseDataCallListV9: invalid response length %d expected multiple of %d",
2460 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v9));
2461 return RIL_ERRNO_INVALID_RESPONSE;
2462 }
2463
2464 // Write version
2465 p.writeInt32(10);
2466
2467 int num = responselen / sizeof(RIL_Data_Call_Response_v9);
2468 p.writeInt32(num);
2469
2470 RIL_Data_Call_Response_v9 *p_cur = (RIL_Data_Call_Response_v9 *) response;
2471 startResponse;
2472 int i;
2473 for (i = 0; i < num; i++) {
2474 p.writeInt32((int)p_cur[i].status);
2475 p.writeInt32(p_cur[i].suggestedRetryTime);
2476 p.writeInt32(p_cur[i].cid);
2477 p.writeInt32(p_cur[i].active);
2478 writeStringToParcel(p, p_cur[i].type);
2479 writeStringToParcel(p, p_cur[i].ifname);
2480 writeStringToParcel(p, p_cur[i].addresses);
2481 writeStringToParcel(p, p_cur[i].dnses);
2482 writeStringToParcel(p, p_cur[i].gateways);
2483 writeStringToParcel(p, p_cur[i].pcscf);
2484 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s],", printBuf,
2485 p_cur[i].status,
2486 p_cur[i].suggestedRetryTime,
2487 p_cur[i].cid,
2488 (p_cur[i].active==0)?"down":"up",
2489 (char*)p_cur[i].type,
2490 (char*)p_cur[i].ifname,
2491 (char*)p_cur[i].addresses,
2492 (char*)p_cur[i].dnses,
2493 (char*)p_cur[i].gateways,
2494 (char*)p_cur[i].pcscf);
2495 }
2496 removeLastChar;
2497 closeResponse;
2498
2499 return 0;
2500}
2501
2502
Wink Saville43808972011-01-13 17:39:51 -08002503static int responseDataCallList(Parcel &p, void *response, size_t responselen)
2504{
Wink Saville43808972011-01-13 17:39:51 -08002505 if (s_callbacks.version < 5) {
Amit Mahajan52500162014-07-29 17:36:48 -07002506 RLOGD("responseDataCallList: v4");
Wink Savillec0114b32011-02-18 10:14:07 -08002507 return responseDataCallListV4(p, response, responselen);
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002508 } else if (responselen % sizeof(RIL_Data_Call_Response_v6) == 0) {
2509 return responseDataCallListV6(p, response, responselen);
2510 } else if (responselen % sizeof(RIL_Data_Call_Response_v9) == 0) {
2511 return responseDataCallListV9(p, response, responselen);
Wink Saville43808972011-01-13 17:39:51 -08002512 } else {
2513 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002514 RLOGE("invalid response: NULL");
Wink Saville43808972011-01-13 17:39:51 -08002515 return RIL_ERRNO_INVALID_RESPONSE;
2516 }
2517
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002518 if (responselen % sizeof(RIL_Data_Call_Response_v11) != 0) {
2519 RLOGE("invalid response length %d expected multiple of %d",
2520 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v11));
Wink Saville43808972011-01-13 17:39:51 -08002521 return RIL_ERRNO_INVALID_RESPONSE;
2522 }
2523
Amit Mahajan52500162014-07-29 17:36:48 -07002524 // Write version
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002525 p.writeInt32(11);
Amit Mahajan52500162014-07-29 17:36:48 -07002526
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002527 int num = responselen / sizeof(RIL_Data_Call_Response_v11);
Wink Saville43808972011-01-13 17:39:51 -08002528 p.writeInt32(num);
2529
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002530 RIL_Data_Call_Response_v11 *p_cur = (RIL_Data_Call_Response_v11 *) response;
Wink Saville43808972011-01-13 17:39:51 -08002531 startResponse;
2532 int i;
2533 for (i = 0; i < num; i++) {
2534 p.writeInt32((int)p_cur[i].status);
Kazuhiro Ondobeb25b52011-06-17 16:26:45 -05002535 p.writeInt32(p_cur[i].suggestedRetryTime);
Wink Saville43808972011-01-13 17:39:51 -08002536 p.writeInt32(p_cur[i].cid);
2537 p.writeInt32(p_cur[i].active);
David 'Digit' Turneraf1298d2011-02-04 13:36:47 +01002538 writeStringToParcel(p, p_cur[i].type);
Wink Saville43808972011-01-13 17:39:51 -08002539 writeStringToParcel(p, p_cur[i].ifname);
2540 writeStringToParcel(p, p_cur[i].addresses);
2541 writeStringToParcel(p, p_cur[i].dnses);
Wink Savillec0114b32011-02-18 10:14:07 -08002542 writeStringToParcel(p, p_cur[i].gateways);
Etan Cohend3652192014-06-20 08:28:44 -07002543 writeStringToParcel(p, p_cur[i].pcscf);
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002544 p.writeInt32(p_cur[i].mtu);
2545 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 -08002546 p_cur[i].status,
Kazuhiro Ondobeb25b52011-06-17 16:26:45 -05002547 p_cur[i].suggestedRetryTime,
Wink Saville43808972011-01-13 17:39:51 -08002548 p_cur[i].cid,
2549 (p_cur[i].active==0)?"down":"up",
Naveen Kalla56384152011-11-16 11:12:37 -08002550 (char*)p_cur[i].type,
Wink Saville43808972011-01-13 17:39:51 -08002551 (char*)p_cur[i].ifname,
2552 (char*)p_cur[i].addresses,
Wink Savillec0114b32011-02-18 10:14:07 -08002553 (char*)p_cur[i].dnses,
Etan Cohend3652192014-06-20 08:28:44 -07002554 (char*)p_cur[i].gateways,
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002555 (char*)p_cur[i].pcscf,
2556 p_cur[i].mtu);
Wink Saville43808972011-01-13 17:39:51 -08002557 }
2558 removeLastChar;
2559 closeResponse;
2560 }
2561
2562 return 0;
2563}
2564
2565static int responseSetupDataCall(Parcel &p, void *response, size_t responselen)
2566{
2567 if (s_callbacks.version < 5) {
2568 return responseStringsWithVersion(s_callbacks.version, p, response, responselen);
2569 } else {
2570 return responseDataCallList(p, response, responselen);
2571 }
2572}
2573
Wink Savillef4c4d362009-04-02 01:37:03 -07002574static int responseRaw(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002575 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002576 RLOGE("invalid response: NULL with responselen != 0");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002577 return RIL_ERRNO_INVALID_RESPONSE;
2578 }
2579
2580 // The java code reads -1 size as null byte array
2581 if (response == NULL) {
Wink Saville7f856802009-06-09 10:23:37 -07002582 p.writeInt32(-1);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002583 } else {
2584 p.writeInt32(responselen);
2585 p.write(response, responselen);
2586 }
2587
2588 return 0;
2589}
2590
2591
Wink Savillef4c4d362009-04-02 01:37:03 -07002592static int responseSIM_IO(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002593 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002594 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002595 return RIL_ERRNO_INVALID_RESPONSE;
2596 }
2597
2598 if (responselen != sizeof (RIL_SIM_IO_Response) ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002599 RLOGE("invalid response length was %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002600 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
2601 return RIL_ERRNO_INVALID_RESPONSE;
2602 }
2603
2604 RIL_SIM_IO_Response *p_cur = (RIL_SIM_IO_Response *) response;
2605 p.writeInt32(p_cur->sw1);
2606 p.writeInt32(p_cur->sw2);
2607 writeStringToParcel(p, p_cur->simResponse);
2608
2609 startResponse;
2610 appendPrintBuf("%ssw1=0x%X,sw2=0x%X,%s", printBuf, p_cur->sw1, p_cur->sw2,
2611 (char*)p_cur->simResponse);
2612 closeResponse;
2613
2614
2615 return 0;
2616}
2617
Wink Savillef4c4d362009-04-02 01:37:03 -07002618static int responseCallForwards(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002619 int num;
Wink Saville7f856802009-06-09 10:23:37 -07002620
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002621 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002622 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002623 return RIL_ERRNO_INVALID_RESPONSE;
2624 }
2625
2626 if (responselen % sizeof(RIL_CallForwardInfo *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002627 RLOGE("responseCallForwards: invalid response length %d expected multiple of %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002628 (int)responselen, (int)sizeof(RIL_CallForwardInfo *));
2629 return RIL_ERRNO_INVALID_RESPONSE;
2630 }
2631
2632 /* number of call info's */
2633 num = responselen / sizeof(RIL_CallForwardInfo *);
2634 p.writeInt32(num);
2635
2636 startResponse;
2637 for (int i = 0 ; i < num ; i++) {
2638 RIL_CallForwardInfo *p_cur = ((RIL_CallForwardInfo **) response)[i];
2639
2640 p.writeInt32(p_cur->status);
2641 p.writeInt32(p_cur->reason);
2642 p.writeInt32(p_cur->serviceClass);
2643 p.writeInt32(p_cur->toa);
2644 writeStringToParcel(p, p_cur->number);
2645 p.writeInt32(p_cur->timeSeconds);
2646 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
2647 (p_cur->status==1)?"enable":"disable",
2648 p_cur->reason, p_cur->serviceClass, p_cur->toa,
2649 (char*)p_cur->number,
2650 p_cur->timeSeconds);
2651 }
2652 removeLastChar;
2653 closeResponse;
Wink Saville7f856802009-06-09 10:23:37 -07002654
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002655 return 0;
2656}
2657
Wink Savillef4c4d362009-04-02 01:37:03 -07002658static int responseSsn(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002659 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002660 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002661 return RIL_ERRNO_INVALID_RESPONSE;
2662 }
2663
2664 if (responselen != sizeof(RIL_SuppSvcNotification)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002665 RLOGE("invalid response length was %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002666 (int)responselen, (int)sizeof (RIL_SuppSvcNotification));
2667 return RIL_ERRNO_INVALID_RESPONSE;
2668 }
2669
2670 RIL_SuppSvcNotification *p_cur = (RIL_SuppSvcNotification *) response;
2671 p.writeInt32(p_cur->notificationType);
2672 p.writeInt32(p_cur->code);
2673 p.writeInt32(p_cur->index);
2674 p.writeInt32(p_cur->type);
2675 writeStringToParcel(p, p_cur->number);
2676
2677 startResponse;
2678 appendPrintBuf("%s%s,code=%d,id=%d,type=%d,%s", printBuf,
2679 (p_cur->notificationType==0)?"mo":"mt",
2680 p_cur->code, p_cur->index, p_cur->type,
2681 (char*)p_cur->number);
2682 closeResponse;
2683
2684 return 0;
2685}
2686
Wink Saville3d54e742009-05-18 18:00:44 -07002687static int responseCellList(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002688 int num;
2689
2690 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002691 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002692 return RIL_ERRNO_INVALID_RESPONSE;
2693 }
2694
2695 if (responselen % sizeof (RIL_NeighboringCell *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002696 RLOGE("responseCellList: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002697 (int)responselen, (int)sizeof (RIL_NeighboringCell *));
2698 return RIL_ERRNO_INVALID_RESPONSE;
2699 }
2700
2701 startResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002702 /* number of records */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002703 num = responselen / sizeof(RIL_NeighboringCell *);
2704 p.writeInt32(num);
2705
2706 for (int i = 0 ; i < num ; i++) {
2707 RIL_NeighboringCell *p_cur = ((RIL_NeighboringCell **) response)[i];
2708
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002709 p.writeInt32(p_cur->rssi);
2710 writeStringToParcel (p, p_cur->cid);
2711
2712 appendPrintBuf("%s[cid=%s,rssi=%d],", printBuf,
2713 p_cur->cid, p_cur->rssi);
2714 }
2715 removeLastChar;
2716 closeResponse;
2717
2718 return 0;
2719}
2720
Wink Saville3d54e742009-05-18 18:00:44 -07002721/**
2722 * Marshall the signalInfoRecord into the parcel if it exists.
2723 */
Wink Savillea592eeb2009-05-22 13:26:36 -07002724static void marshallSignalInfoRecord(Parcel &p,
2725 RIL_CDMA_SignalInfoRecord &p_signalInfoRecord) {
Wink Saville3d54e742009-05-18 18:00:44 -07002726 p.writeInt32(p_signalInfoRecord.isPresent);
2727 p.writeInt32(p_signalInfoRecord.signalType);
2728 p.writeInt32(p_signalInfoRecord.alertPitch);
2729 p.writeInt32(p_signalInfoRecord.signal);
2730}
2731
Wink Savillea592eeb2009-05-22 13:26:36 -07002732static int responseCdmaInformationRecords(Parcel &p,
2733 void *response, size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07002734 int num;
Wink Savillea592eeb2009-05-22 13:26:36 -07002735 char* string8 = NULL;
2736 int buffer_lenght;
2737 RIL_CDMA_InformationRecord *infoRec;
Wink Saville3d54e742009-05-18 18:00:44 -07002738
2739 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002740 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002741 return RIL_ERRNO_INVALID_RESPONSE;
2742 }
2743
Wink Savillea592eeb2009-05-22 13:26:36 -07002744 if (responselen != sizeof (RIL_CDMA_InformationRecords)) {
Amit Mahajan52500162014-07-29 17:36:48 -07002745 RLOGE("responseCdmaInformationRecords: invalid response length %d expected multiple of %d\n",
Wink Savillea592eeb2009-05-22 13:26:36 -07002746 (int)responselen, (int)sizeof (RIL_CDMA_InformationRecords *));
Wink Saville3d54e742009-05-18 18:00:44 -07002747 return RIL_ERRNO_INVALID_RESPONSE;
2748 }
2749
Wink Savillea592eeb2009-05-22 13:26:36 -07002750 RIL_CDMA_InformationRecords *p_cur =
2751 (RIL_CDMA_InformationRecords *) response;
2752 num = MIN(p_cur->numberOfInfoRecs, RIL_CDMA_MAX_NUMBER_OF_INFO_RECS);
Wink Saville3d54e742009-05-18 18:00:44 -07002753
2754 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07002755 p.writeInt32(num);
Wink Saville3d54e742009-05-18 18:00:44 -07002756
Wink Savillea592eeb2009-05-22 13:26:36 -07002757 for (int i = 0 ; i < num ; i++) {
2758 infoRec = &p_cur->infoRec[i];
2759 p.writeInt32(infoRec->name);
2760 switch (infoRec->name) {
Wink Saville3d54e742009-05-18 18:00:44 -07002761 case RIL_CDMA_DISPLAY_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002762 case RIL_CDMA_EXTENDED_DISPLAY_INFO_REC:
2763 if (infoRec->rec.display.alpha_len >
2764 CDMA_ALPHA_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002765 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002766 expected not more than %d\n",
2767 (int)infoRec->rec.display.alpha_len,
2768 CDMA_ALPHA_INFO_BUFFER_LENGTH);
2769 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002770 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002771 string8 = (char*) malloc((infoRec->rec.display.alpha_len + 1)
2772 * sizeof(char) );
2773 for (int i = 0 ; i < infoRec->rec.display.alpha_len ; i++) {
2774 string8[i] = infoRec->rec.display.alpha_buf[i];
2775 }
Wink Saville43808972011-01-13 17:39:51 -08002776 string8[(int)infoRec->rec.display.alpha_len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002777 writeStringToParcel(p, (const char*)string8);
2778 free(string8);
2779 string8 = NULL;
Wink Saville3d54e742009-05-18 18:00:44 -07002780 break;
2781 case RIL_CDMA_CALLED_PARTY_NUMBER_INFO_REC:
Wink Saville3d54e742009-05-18 18:00:44 -07002782 case RIL_CDMA_CALLING_PARTY_NUMBER_INFO_REC:
Wink Saville3d54e742009-05-18 18:00:44 -07002783 case RIL_CDMA_CONNECTED_NUMBER_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002784 if (infoRec->rec.number.len > CDMA_NUMBER_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002785 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002786 expected not more than %d\n",
2787 (int)infoRec->rec.number.len,
2788 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2789 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002790 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002791 string8 = (char*) malloc((infoRec->rec.number.len + 1)
2792 * sizeof(char) );
2793 for (int i = 0 ; i < infoRec->rec.number.len; i++) {
2794 string8[i] = infoRec->rec.number.buf[i];
2795 }
Wink Saville43808972011-01-13 17:39:51 -08002796 string8[(int)infoRec->rec.number.len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002797 writeStringToParcel(p, (const char*)string8);
2798 free(string8);
2799 string8 = NULL;
2800 p.writeInt32(infoRec->rec.number.number_type);
2801 p.writeInt32(infoRec->rec.number.number_plan);
2802 p.writeInt32(infoRec->rec.number.pi);
2803 p.writeInt32(infoRec->rec.number.si);
Wink Saville3d54e742009-05-18 18:00:44 -07002804 break;
2805 case RIL_CDMA_SIGNAL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002806 p.writeInt32(infoRec->rec.signal.isPresent);
2807 p.writeInt32(infoRec->rec.signal.signalType);
2808 p.writeInt32(infoRec->rec.signal.alertPitch);
2809 p.writeInt32(infoRec->rec.signal.signal);
2810
2811 appendPrintBuf("%sisPresent=%X, signalType=%X, \
2812 alertPitch=%X, signal=%X, ",
2813 printBuf, (int)infoRec->rec.signal.isPresent,
2814 (int)infoRec->rec.signal.signalType,
2815 (int)infoRec->rec.signal.alertPitch,
2816 (int)infoRec->rec.signal.signal);
2817 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002818 break;
2819 case RIL_CDMA_REDIRECTING_NUMBER_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002820 if (infoRec->rec.redir.redirectingNumber.len >
2821 CDMA_NUMBER_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002822 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002823 expected not more than %d\n",
2824 (int)infoRec->rec.redir.redirectingNumber.len,
2825 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2826 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002827 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002828 string8 = (char*) malloc((infoRec->rec.redir.redirectingNumber
2829 .len + 1) * sizeof(char) );
2830 for (int i = 0;
2831 i < infoRec->rec.redir.redirectingNumber.len;
2832 i++) {
2833 string8[i] = infoRec->rec.redir.redirectingNumber.buf[i];
2834 }
Wink Saville43808972011-01-13 17:39:51 -08002835 string8[(int)infoRec->rec.redir.redirectingNumber.len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002836 writeStringToParcel(p, (const char*)string8);
2837 free(string8);
2838 string8 = NULL;
2839 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_type);
2840 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_plan);
2841 p.writeInt32(infoRec->rec.redir.redirectingNumber.pi);
2842 p.writeInt32(infoRec->rec.redir.redirectingNumber.si);
2843 p.writeInt32(infoRec->rec.redir.redirectingReason);
Wink Saville3d54e742009-05-18 18:00:44 -07002844 break;
2845 case RIL_CDMA_LINE_CONTROL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002846 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPolarityIncluded);
2847 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlToggle);
2848 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlReverse);
2849 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2850
2851 appendPrintBuf("%slineCtrlPolarityIncluded=%d, \
2852 lineCtrlToggle=%d, lineCtrlReverse=%d, \
2853 lineCtrlPowerDenial=%d, ", printBuf,
2854 (int)infoRec->rec.lineCtrl.lineCtrlPolarityIncluded,
2855 (int)infoRec->rec.lineCtrl.lineCtrlToggle,
2856 (int)infoRec->rec.lineCtrl.lineCtrlReverse,
2857 (int)infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2858 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002859 break;
2860 case RIL_CDMA_T53_CLIR_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002861 p.writeInt32((int)(infoRec->rec.clir.cause));
Wink Saville3d54e742009-05-18 18:00:44 -07002862
Wink Savillea592eeb2009-05-22 13:26:36 -07002863 appendPrintBuf("%scause%d", printBuf, infoRec->rec.clir.cause);
2864 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002865 break;
2866 case RIL_CDMA_T53_AUDIO_CONTROL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002867 p.writeInt32(infoRec->rec.audioCtrl.upLink);
2868 p.writeInt32(infoRec->rec.audioCtrl.downLink);
2869
2870 appendPrintBuf("%supLink=%d, downLink=%d, ", printBuf,
2871 infoRec->rec.audioCtrl.upLink,
2872 infoRec->rec.audioCtrl.downLink);
2873 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002874 break;
Wink Savillea592eeb2009-05-22 13:26:36 -07002875 case RIL_CDMA_T53_RELEASE_INFO_REC:
2876 // TODO(Moto): See David Krause, he has the answer:)
Wink Saville8eb2a122012-11-19 16:05:13 -08002877 RLOGE("RIL_CDMA_T53_RELEASE_INFO_REC: return INVALID_RESPONSE");
Wink Savillea592eeb2009-05-22 13:26:36 -07002878 return RIL_ERRNO_INVALID_RESPONSE;
2879 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08002880 RLOGE("Incorrect name value");
Wink Savillea592eeb2009-05-22 13:26:36 -07002881 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002882 }
2883 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002884 closeResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002885
Wink Savillea592eeb2009-05-22 13:26:36 -07002886 return 0;
Wink Saville3d54e742009-05-18 18:00:44 -07002887}
2888
Wink Savillea592eeb2009-05-22 13:26:36 -07002889static int responseRilSignalStrength(Parcel &p,
2890 void *response, size_t responselen) {
2891 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002892 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002893 return RIL_ERRNO_INVALID_RESPONSE;
2894 }
2895
Wink Savillec0114b32011-02-18 10:14:07 -08002896 if (responselen >= sizeof (RIL_SignalStrength_v5)) {
Etan Cohend3652192014-06-20 08:28:44 -07002897 RIL_SignalStrength_v10 *p_cur = ((RIL_SignalStrength_v10 *) response);
Wink Saville3d54e742009-05-18 18:00:44 -07002898
Wink Saville3d54e742009-05-18 18:00:44 -07002899 p.writeInt32(p_cur->GW_SignalStrength.signalStrength);
2900 p.writeInt32(p_cur->GW_SignalStrength.bitErrorRate);
2901 p.writeInt32(p_cur->CDMA_SignalStrength.dbm);
2902 p.writeInt32(p_cur->CDMA_SignalStrength.ecio);
2903 p.writeInt32(p_cur->EVDO_SignalStrength.dbm);
2904 p.writeInt32(p_cur->EVDO_SignalStrength.ecio);
2905 p.writeInt32(p_cur->EVDO_SignalStrength.signalNoiseRatio);
Wink Savillec0114b32011-02-18 10:14:07 -08002906 if (responselen >= sizeof (RIL_SignalStrength_v6)) {
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002907 /*
Wink Saville18e4ab12013-04-07 17:31:04 -07002908 * Fixup LTE for backwards compatibility
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002909 */
Wink Saville18e4ab12013-04-07 17:31:04 -07002910 if (s_callbacks.version <= 6) {
2911 // signalStrength: -1 -> 99
2912 if (p_cur->LTE_SignalStrength.signalStrength == -1) {
2913 p_cur->LTE_SignalStrength.signalStrength = 99;
2914 }
2915 // rsrp: -1 -> INT_MAX all other negative value to positive.
2916 // So remap here
2917 if (p_cur->LTE_SignalStrength.rsrp == -1) {
2918 p_cur->LTE_SignalStrength.rsrp = INT_MAX;
2919 } else if (p_cur->LTE_SignalStrength.rsrp < -1) {
2920 p_cur->LTE_SignalStrength.rsrp = -p_cur->LTE_SignalStrength.rsrp;
2921 }
2922 // rsrq: -1 -> INT_MAX
2923 if (p_cur->LTE_SignalStrength.rsrq == -1) {
2924 p_cur->LTE_SignalStrength.rsrq = INT_MAX;
2925 }
2926 // Not remapping rssnr is already using INT_MAX
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002927
Wink Saville18e4ab12013-04-07 17:31:04 -07002928 // cqi: -1 -> INT_MAX
2929 if (p_cur->LTE_SignalStrength.cqi == -1) {
2930 p_cur->LTE_SignalStrength.cqi = INT_MAX;
2931 }
2932 }
2933 p.writeInt32(p_cur->LTE_SignalStrength.signalStrength);
Wink Savillec0114b32011-02-18 10:14:07 -08002934 p.writeInt32(p_cur->LTE_SignalStrength.rsrp);
2935 p.writeInt32(p_cur->LTE_SignalStrength.rsrq);
2936 p.writeInt32(p_cur->LTE_SignalStrength.rssnr);
2937 p.writeInt32(p_cur->LTE_SignalStrength.cqi);
Etan Cohend3652192014-06-20 08:28:44 -07002938 if (responselen >= sizeof (RIL_SignalStrength_v10)) {
2939 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
2940 } else {
2941 p.writeInt32(INT_MAX);
2942 }
Wink Savillec0114b32011-02-18 10:14:07 -08002943 } else {
Wink Saville18e4ab12013-04-07 17:31:04 -07002944 p.writeInt32(99);
2945 p.writeInt32(INT_MAX);
2946 p.writeInt32(INT_MAX);
2947 p.writeInt32(INT_MAX);
2948 p.writeInt32(INT_MAX);
Etan Cohend3652192014-06-20 08:28:44 -07002949 p.writeInt32(INT_MAX);
Wink Savillec0114b32011-02-18 10:14:07 -08002950 }
johnwangfdf825f2009-05-22 15:50:34 -07002951
2952 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07002953 appendPrintBuf("%s[signalStrength=%d,bitErrorRate=%d,\
Wink Savillec0114b32011-02-18 10:14:07 -08002954 CDMA_SS.dbm=%d,CDMA_SSecio=%d,\
2955 EVDO_SS.dbm=%d,EVDO_SS.ecio=%d,\
2956 EVDO_SS.signalNoiseRatio=%d,\
2957 LTE_SS.signalStrength=%d,LTE_SS.rsrp=%d,LTE_SS.rsrq=%d,\
Etan Cohend3652192014-06-20 08:28:44 -07002958 LTE_SS.rssnr=%d,LTE_SS.cqi=%d,TDSCDMA_SS.rscp=%d]",
Wink Savillea592eeb2009-05-22 13:26:36 -07002959 printBuf,
2960 p_cur->GW_SignalStrength.signalStrength,
2961 p_cur->GW_SignalStrength.bitErrorRate,
2962 p_cur->CDMA_SignalStrength.dbm,
2963 p_cur->CDMA_SignalStrength.ecio,
2964 p_cur->EVDO_SignalStrength.dbm,
2965 p_cur->EVDO_SignalStrength.ecio,
Wink Savillec0114b32011-02-18 10:14:07 -08002966 p_cur->EVDO_SignalStrength.signalNoiseRatio,
2967 p_cur->LTE_SignalStrength.signalStrength,
2968 p_cur->LTE_SignalStrength.rsrp,
2969 p_cur->LTE_SignalStrength.rsrq,
2970 p_cur->LTE_SignalStrength.rssnr,
Etan Cohend3652192014-06-20 08:28:44 -07002971 p_cur->LTE_SignalStrength.cqi,
2972 p_cur->TD_SCDMA_SignalStrength.rscp);
Wink Savillea592eeb2009-05-22 13:26:36 -07002973 closeResponse;
2974
Wink Saville3d54e742009-05-18 18:00:44 -07002975 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08002976 RLOGE("invalid response length");
Wink Saville3d54e742009-05-18 18:00:44 -07002977 return RIL_ERRNO_INVALID_RESPONSE;
2978 }
2979
Wink Saville3d54e742009-05-18 18:00:44 -07002980 return 0;
2981}
2982
2983static int responseCallRing(Parcel &p, void *response, size_t responselen) {
2984 if ((response == NULL) || (responselen == 0)) {
2985 return responseVoid(p, response, responselen);
2986 } else {
2987 return responseCdmaSignalInfoRecord(p, response, responselen);
2988 }
2989}
2990
2991static int responseCdmaSignalInfoRecord(Parcel &p, void *response, size_t responselen) {
2992 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
2997 if (responselen != sizeof (RIL_CDMA_SignalInfoRecord)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002998 RLOGE("invalid response length %d expected sizeof (RIL_CDMA_SignalInfoRecord) of %d\n",
Wink Saville3d54e742009-05-18 18:00:44 -07002999 (int)responselen, (int)sizeof (RIL_CDMA_SignalInfoRecord));
3000 return RIL_ERRNO_INVALID_RESPONSE;
3001 }
3002
3003 startResponse;
3004
3005 RIL_CDMA_SignalInfoRecord *p_cur = ((RIL_CDMA_SignalInfoRecord *) response);
3006 marshallSignalInfoRecord(p, *p_cur);
3007
3008 appendPrintBuf("%s[isPresent=%d,signalType=%d,alertPitch=%d\
3009 signal=%d]",
3010 printBuf,
3011 p_cur->isPresent,
3012 p_cur->signalType,
3013 p_cur->alertPitch,
3014 p_cur->signal);
3015
3016 closeResponse;
3017 return 0;
3018}
3019
Wink Savillea592eeb2009-05-22 13:26:36 -07003020static int responseCdmaCallWaiting(Parcel &p, void *response,
3021 size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07003022 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003023 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07003024 return RIL_ERRNO_INVALID_RESPONSE;
3025 }
3026
Wink Savillec0114b32011-02-18 10:14:07 -08003027 if (responselen < sizeof(RIL_CDMA_CallWaiting_v6)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003028 RLOGW("Upgrade to ril version %d\n", RIL_VERSION);
Wink Savillec0114b32011-02-18 10:14:07 -08003029 }
3030
3031 RIL_CDMA_CallWaiting_v6 *p_cur = ((RIL_CDMA_CallWaiting_v6 *) response);
3032
3033 writeStringToParcel(p, p_cur->number);
3034 p.writeInt32(p_cur->numberPresentation);
3035 writeStringToParcel(p, p_cur->name);
3036 marshallSignalInfoRecord(p, p_cur->signalInfoRecord);
3037
3038 if (responselen >= sizeof(RIL_CDMA_CallWaiting_v6)) {
3039 p.writeInt32(p_cur->number_type);
3040 p.writeInt32(p_cur->number_plan);
3041 } else {
3042 p.writeInt32(0);
3043 p.writeInt32(0);
Wink Saville3d54e742009-05-18 18:00:44 -07003044 }
3045
3046 startResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07003047 appendPrintBuf("%snumber=%s,numberPresentation=%d, name=%s,\
3048 signalInfoRecord[isPresent=%d,signalType=%d,alertPitch=%d\
Wink Savillec0114b32011-02-18 10:14:07 -08003049 signal=%d,number_type=%d,number_plan=%d]",
Wink Saville3d54e742009-05-18 18:00:44 -07003050 printBuf,
3051 p_cur->number,
3052 p_cur->numberPresentation,
3053 p_cur->name,
3054 p_cur->signalInfoRecord.isPresent,
3055 p_cur->signalInfoRecord.signalType,
3056 p_cur->signalInfoRecord.alertPitch,
Wink Savillec0114b32011-02-18 10:14:07 -08003057 p_cur->signalInfoRecord.signal,
3058 p_cur->number_type,
3059 p_cur->number_plan);
Wink Saville3d54e742009-05-18 18:00:44 -07003060 closeResponse;
3061
3062 return 0;
3063}
3064
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003065static int responseSimRefresh(Parcel &p, void *response, size_t responselen) {
3066 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003067 RLOGE("responseSimRefresh: invalid response: NULL");
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003068 return RIL_ERRNO_INVALID_RESPONSE;
3069 }
3070
3071 startResponse;
3072 if (s_callbacks.version == 7) {
3073 RIL_SimRefreshResponse_v7 *p_cur = ((RIL_SimRefreshResponse_v7 *) response);
3074 p.writeInt32(p_cur->result);
3075 p.writeInt32(p_cur->ef_id);
3076 writeStringToParcel(p, p_cur->aid);
3077
3078 appendPrintBuf("%sresult=%d, ef_id=%d, aid=%s",
3079 printBuf,
3080 p_cur->result,
3081 p_cur->ef_id,
3082 p_cur->aid);
3083 } else {
3084 int *p_cur = ((int *) response);
3085 p.writeInt32(p_cur[0]);
3086 p.writeInt32(p_cur[1]);
3087 writeStringToParcel(p, NULL);
3088
3089 appendPrintBuf("%sresult=%d, ef_id=%d",
3090 printBuf,
3091 p_cur[0],
3092 p_cur[1]);
3093 }
3094 closeResponse;
3095
3096 return 0;
3097}
3098
Wink Saville8a9e0212013-04-09 12:11:38 -07003099static int responseCellInfoList(Parcel &p, void *response, size_t responselen)
3100{
3101 if (response == NULL && responselen != 0) {
3102 RLOGE("invalid response: NULL");
3103 return RIL_ERRNO_INVALID_RESPONSE;
3104 }
3105
3106 if (responselen % sizeof(RIL_CellInfo) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07003107 RLOGE("responseCellInfoList: invalid response length %d expected multiple of %d",
Wink Saville8a9e0212013-04-09 12:11:38 -07003108 (int)responselen, (int)sizeof(RIL_CellInfo));
3109 return RIL_ERRNO_INVALID_RESPONSE;
3110 }
3111
3112 int num = responselen / sizeof(RIL_CellInfo);
3113 p.writeInt32(num);
3114
3115 RIL_CellInfo *p_cur = (RIL_CellInfo *) response;
3116 startResponse;
3117 int i;
3118 for (i = 0; i < num; i++) {
3119 appendPrintBuf("%s[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", printBuf, i,
3120 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
3121 p.writeInt32((int)p_cur->cellInfoType);
3122 p.writeInt32(p_cur->registered);
3123 p.writeInt32(p_cur->timeStampType);
3124 p.writeInt64(p_cur->timeStamp);
3125 switch(p_cur->cellInfoType) {
3126 case RIL_CELL_INFO_TYPE_GSM: {
Wink Savillec57b3eb2013-04-17 12:51:41 -07003127 appendPrintBuf("%s GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,", printBuf,
Wink Saville8a9e0212013-04-09 12:11:38 -07003128 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
3129 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
3130 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
Wink Savillec57b3eb2013-04-17 12:51:41 -07003131 p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3132 appendPrintBuf("%s gsmSS: ss=%d,ber=%d],", printBuf,
Wink Saville8a9e0212013-04-09 12:11:38 -07003133 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
3134 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3135
3136 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
3137 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
3138 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
3139 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
Wink Saville8a9e0212013-04-09 12:11:38 -07003140 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
3141 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3142 break;
3143 }
Wink Savillec57b3eb2013-04-17 12:51:41 -07003144 case RIL_CELL_INFO_TYPE_WCDMA: {
3145 appendPrintBuf("%s WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,", printBuf,
3146 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
3147 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
3148 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
3149 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
3150 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3151 appendPrintBuf("%s wcdmaSS: ss=%d,ber=%d],", printBuf,
3152 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
3153 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3154
3155 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
3156 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
3157 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
3158 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
3159 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3160 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
3161 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3162 break;
3163 }
Wink Saville8a9e0212013-04-09 12:11:38 -07003164 case RIL_CELL_INFO_TYPE_CDMA: {
3165 appendPrintBuf("%s CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d", printBuf,
3166 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
3167 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
3168 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
3169 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
3170 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3171
3172 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
3173 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
3174 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
3175 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
3176 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3177
3178 appendPrintBuf("%s cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d", printBuf,
3179 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
3180 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
3181 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
3182 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
3183 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3184
3185 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
3186 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
3187 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
3188 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
3189 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3190 break;
3191 }
3192 case RIL_CELL_INFO_TYPE_LTE: {
3193 appendPrintBuf("%s LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d", printBuf,
3194 p_cur->CellInfo.lte.cellIdentityLte.mcc,
3195 p_cur->CellInfo.lte.cellIdentityLte.mnc,
3196 p_cur->CellInfo.lte.cellIdentityLte.ci,
3197 p_cur->CellInfo.lte.cellIdentityLte.pci,
3198 p_cur->CellInfo.lte.cellIdentityLte.tac);
3199
3200 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
3201 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
3202 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
3203 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
3204 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
3205
3206 appendPrintBuf("%s lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d", printBuf,
3207 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
3208 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
3209 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
3210 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
3211 p_cur->CellInfo.lte.signalStrengthLte.cqi,
3212 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3213 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
3214 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
3215 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
3216 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
3217 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
3218 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3219 break;
3220 }
Etan Cohend3652192014-06-20 08:28:44 -07003221 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
3222 appendPrintBuf("%s TDSCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,cpid=%d,", printBuf,
3223 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc,
3224 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc,
3225 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac,
3226 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid,
3227 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3228 appendPrintBuf("%s tdscdmaSS: rscp=%d],", printBuf,
3229 p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3230
3231 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
3232 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
3233 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
3234 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
3235 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3236 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3237 break;
3238 }
Wink Saville8a9e0212013-04-09 12:11:38 -07003239 }
3240 p_cur += 1;
3241 }
3242 removeLastChar;
3243 closeResponse;
3244
3245 return 0;
3246}
3247
Etan Cohend3652192014-06-20 08:28:44 -07003248static int responseHardwareConfig(Parcel &p, void *response, size_t responselen)
3249{
3250 if (response == NULL && responselen != 0) {
3251 RLOGE("invalid response: NULL");
3252 return RIL_ERRNO_INVALID_RESPONSE;
3253 }
3254
3255 if (responselen % sizeof(RIL_HardwareConfig) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07003256 RLOGE("responseHardwareConfig: invalid response length %d expected multiple of %d",
Etan Cohend3652192014-06-20 08:28:44 -07003257 (int)responselen, (int)sizeof(RIL_HardwareConfig));
3258 return RIL_ERRNO_INVALID_RESPONSE;
3259 }
3260
3261 int num = responselen / sizeof(RIL_HardwareConfig);
3262 int i;
3263 RIL_HardwareConfig *p_cur = (RIL_HardwareConfig *) response;
3264
3265 p.writeInt32(num);
3266
3267 startResponse;
3268 for (i = 0; i < num; i++) {
3269 switch (p_cur[i].type) {
3270 case RIL_HARDWARE_CONFIG_MODEM: {
3271 writeStringToParcel(p, p_cur[i].uuid);
3272 p.writeInt32((int)p_cur[i].state);
3273 p.writeInt32(p_cur[i].cfg.modem.rat);
3274 p.writeInt32(p_cur[i].cfg.modem.maxVoice);
3275 p.writeInt32(p_cur[i].cfg.modem.maxData);
3276 p.writeInt32(p_cur[i].cfg.modem.maxStandby);
3277
3278 appendPrintBuf("%s modem: uuid=%s,state=%d,rat=%08x,maxV=%d,maxD=%d,maxS=%d", printBuf,
3279 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.modem.rat,
3280 p_cur[i].cfg.modem.maxVoice, p_cur[i].cfg.modem.maxData, p_cur[i].cfg.modem.maxStandby);
3281 break;
3282 }
3283 case RIL_HARDWARE_CONFIG_SIM: {
3284 writeStringToParcel(p, p_cur[i].uuid);
3285 p.writeInt32((int)p_cur[i].state);
3286 writeStringToParcel(p, p_cur[i].cfg.sim.modemUuid);
3287
3288 appendPrintBuf("%s sim: uuid=%s,state=%d,modem-uuid=%s", printBuf,
3289 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.sim.modemUuid);
3290 break;
3291 }
3292 }
3293 }
3294 removeLastChar;
3295 closeResponse;
3296 return 0;
3297}
3298
Wink Saville8b4e4f72014-10-17 15:01:45 -07003299static int responseRadioCapability(Parcel &p, void *response, size_t responselen) {
3300 if (response == NULL) {
3301 RLOGE("invalid response: NULL");
3302 return RIL_ERRNO_INVALID_RESPONSE;
3303 }
3304
3305 if (responselen != sizeof (RIL_RadioCapability) ) {
3306 RLOGE("invalid response length was %d expected %d",
3307 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3308 return RIL_ERRNO_INVALID_RESPONSE;
3309 }
3310
3311 RIL_RadioCapability *p_cur = (RIL_RadioCapability *) response;
3312 p.writeInt32(p_cur->version);
3313 p.writeInt32(p_cur->session);
3314 p.writeInt32(p_cur->phase);
3315 p.writeInt32(p_cur->rat);
3316 writeStringToParcel(p, p_cur->logicalModemUuid);
3317 p.writeInt32(p_cur->status);
3318
3319 startResponse;
3320 appendPrintBuf("%s[version=%d,session=%d,phase=%d,\
Legler Wu8caf06f2014-10-29 14:02:14 +08003321 rat=%s,logicalModemUuid=%s,status=%d]",
Wink Saville8b4e4f72014-10-17 15:01:45 -07003322 printBuf,
3323 p_cur->version,
3324 p_cur->session,
3325 p_cur->phase,
3326 p_cur->rat,
Legler Wu8caf06f2014-10-29 14:02:14 +08003327 p_cur->logicalModemUuid,
Wink Saville8b4e4f72014-10-17 15:01:45 -07003328 p_cur->status);
3329 closeResponse;
3330 return 0;
3331}
3332
Amit Mahajan54563d32014-11-22 00:54:49 +00003333static int responseSSData(Parcel &p, void *response, size_t responselen) {
3334 RLOGD("In responseSSData");
3335 int num;
3336
3337 if (response == NULL && responselen != 0) {
3338 RLOGE("invalid response length was %d expected %d",
3339 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3340 return RIL_ERRNO_INVALID_RESPONSE;
3341 }
3342
3343 if (responselen != sizeof(RIL_StkCcUnsolSsResponse)) {
3344 RLOGE("invalid response length %d, expected %d",
3345 (int)responselen, (int)sizeof(RIL_StkCcUnsolSsResponse));
3346 return RIL_ERRNO_INVALID_RESPONSE;
3347 }
3348
3349 startResponse;
3350 RIL_StkCcUnsolSsResponse *p_cur = (RIL_StkCcUnsolSsResponse *) response;
3351 p.writeInt32(p_cur->serviceType);
3352 p.writeInt32(p_cur->requestType);
3353 p.writeInt32(p_cur->teleserviceType);
3354 p.writeInt32(p_cur->serviceClass);
3355 p.writeInt32(p_cur->result);
3356
3357 if (isServiceTypeCfQuery(p_cur->serviceType, p_cur->requestType)) {
3358 RLOGD("responseSSData CF type, num of Cf elements %d", p_cur->cfData.numValidIndexes);
3359 if (p_cur->cfData.numValidIndexes > NUM_SERVICE_CLASSES) {
3360 RLOGE("numValidIndexes is greater than max value %d, "
3361 "truncating it to max value", NUM_SERVICE_CLASSES);
3362 p_cur->cfData.numValidIndexes = NUM_SERVICE_CLASSES;
3363 }
3364 /* number of call info's */
3365 p.writeInt32(p_cur->cfData.numValidIndexes);
3366
3367 for (int i = 0; i < p_cur->cfData.numValidIndexes; i++) {
3368 RIL_CallForwardInfo cf = p_cur->cfData.cfInfo[i];
3369
3370 p.writeInt32(cf.status);
3371 p.writeInt32(cf.reason);
3372 p.writeInt32(cf.serviceClass);
3373 p.writeInt32(cf.toa);
3374 writeStringToParcel(p, cf.number);
3375 p.writeInt32(cf.timeSeconds);
3376 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
3377 (cf.status==1)?"enable":"disable", cf.reason, cf.serviceClass, cf.toa,
3378 (char*)cf.number, cf.timeSeconds);
3379 RLOGD("Data: %d,reason=%d,cls=%d,toa=%d,num=%s,tout=%d],", cf.status,
3380 cf.reason, cf.serviceClass, cf.toa, (char*)cf.number, cf.timeSeconds);
3381 }
3382 } else {
3383 p.writeInt32 (SS_INFO_MAX);
3384
3385 /* each int*/
3386 for (int i = 0; i < SS_INFO_MAX; i++) {
3387 appendPrintBuf("%s%d,", printBuf, p_cur->ssInfo[i]);
3388 RLOGD("Data: %d",p_cur->ssInfo[i]);
3389 p.writeInt32(p_cur->ssInfo[i]);
3390 }
3391 }
3392 removeLastChar;
3393 closeResponse;
3394
3395 return 0;
3396}
3397
3398static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType) {
3399 if ((reqType == SS_INTERROGATION) &&
3400 (serType == SS_CFU ||
3401 serType == SS_CF_BUSY ||
3402 serType == SS_CF_NO_REPLY ||
3403 serType == SS_CF_NOT_REACHABLE ||
3404 serType == SS_CF_ALL ||
3405 serType == SS_CF_ALL_CONDITIONAL)) {
3406 return true;
3407 }
3408 return false;
3409}
3410
Wink Saville3d54e742009-05-18 18:00:44 -07003411static void triggerEvLoop() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003412 int ret;
3413 if (!pthread_equal(pthread_self(), s_tid_dispatch)) {
3414 /* trigger event loop to wakeup. No reason to do this,
3415 * if we're in the event loop thread */
3416 do {
3417 ret = write (s_fdWakeupWrite, " ", 1);
3418 } while (ret < 0 && errno == EINTR);
3419 }
3420}
3421
Wink Saville3d54e742009-05-18 18:00:44 -07003422static void rilEventAddWakeup(struct ril_event *ev) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003423 ril_event_add(ev);
3424 triggerEvLoop();
3425}
3426
Wink Savillefd729372011-02-22 16:19:39 -08003427static void sendSimStatusAppInfo(Parcel &p, int num_apps, RIL_AppStatus appStatus[]) {
3428 p.writeInt32(num_apps);
3429 startResponse;
3430 for (int i = 0; i < num_apps; i++) {
3431 p.writeInt32(appStatus[i].app_type);
3432 p.writeInt32(appStatus[i].app_state);
3433 p.writeInt32(appStatus[i].perso_substate);
3434 writeStringToParcel(p, (const char*)(appStatus[i].aid_ptr));
3435 writeStringToParcel(p, (const char*)
3436 (appStatus[i].app_label_ptr));
3437 p.writeInt32(appStatus[i].pin1_replaced);
3438 p.writeInt32(appStatus[i].pin1);
3439 p.writeInt32(appStatus[i].pin2);
3440 appendPrintBuf("%s[app_type=%d,app_state=%d,perso_substate=%d,\
3441 aid_ptr=%s,app_label_ptr=%s,pin1_replaced=%d,pin1=%d,pin2=%d],",
3442 printBuf,
3443 appStatus[i].app_type,
3444 appStatus[i].app_state,
3445 appStatus[i].perso_substate,
3446 appStatus[i].aid_ptr,
3447 appStatus[i].app_label_ptr,
3448 appStatus[i].pin1_replaced,
3449 appStatus[i].pin1,
3450 appStatus[i].pin2);
3451 }
3452 closeResponse;
3453}
3454
Wink Savillef4c4d362009-04-02 01:37:03 -07003455static int responseSimStatus(Parcel &p, void *response, size_t responselen) {
3456 int i;
3457
3458 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003459 RLOGE("invalid response: NULL");
Wink Savillef4c4d362009-04-02 01:37:03 -07003460 return RIL_ERRNO_INVALID_RESPONSE;
3461 }
3462
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003463 if (responselen == sizeof (RIL_CardStatus_v6)) {
Wink Savillefd729372011-02-22 16:19:39 -08003464 RIL_CardStatus_v6 *p_cur = ((RIL_CardStatus_v6 *) response);
Wink Savillef4c4d362009-04-02 01:37:03 -07003465
Wink Savillefd729372011-02-22 16:19:39 -08003466 p.writeInt32(p_cur->card_state);
3467 p.writeInt32(p_cur->universal_pin_state);
3468 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3469 p.writeInt32(p_cur->cdma_subscription_app_index);
3470 p.writeInt32(p_cur->ims_subscription_app_index);
3471
3472 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003473 } else if (responselen == sizeof (RIL_CardStatus_v5)) {
Wink Savillefd729372011-02-22 16:19:39 -08003474 RIL_CardStatus_v5 *p_cur = ((RIL_CardStatus_v5 *) response);
3475
3476 p.writeInt32(p_cur->card_state);
3477 p.writeInt32(p_cur->universal_pin_state);
3478 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3479 p.writeInt32(p_cur->cdma_subscription_app_index);
3480 p.writeInt32(-1);
3481
3482 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003483 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003484 RLOGE("responseSimStatus: A RilCardStatus_v6 or _v5 expected\n");
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003485 return RIL_ERRNO_INVALID_RESPONSE;
Wink Savillef4c4d362009-04-02 01:37:03 -07003486 }
Wink Savillef4c4d362009-04-02 01:37:03 -07003487
3488 return 0;
Wink Saville3d54e742009-05-18 18:00:44 -07003489}
Wink Savillef4c4d362009-04-02 01:37:03 -07003490
Wink Savillea592eeb2009-05-22 13:26:36 -07003491static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3492 int num = responselen / sizeof(RIL_GSM_BroadcastSmsConfigInfo *);
Wink Savillef4c4d362009-04-02 01:37:03 -07003493 p.writeInt32(num);
3494
Wink Savillef4c4d362009-04-02 01:37:03 -07003495 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07003496 RIL_GSM_BroadcastSmsConfigInfo **p_cur =
3497 (RIL_GSM_BroadcastSmsConfigInfo **) response;
3498 for (int i = 0; i < num; i++) {
3499 p.writeInt32(p_cur[i]->fromServiceId);
3500 p.writeInt32(p_cur[i]->toServiceId);
3501 p.writeInt32(p_cur[i]->fromCodeScheme);
3502 p.writeInt32(p_cur[i]->toCodeScheme);
3503 p.writeInt32(p_cur[i]->selected);
3504
3505 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId=%d, \
3506 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]",
3507 printBuf, i, p_cur[i]->fromServiceId, p_cur[i]->toServiceId,
3508 p_cur[i]->fromCodeScheme, p_cur[i]->toCodeScheme,
3509 p_cur[i]->selected);
3510 }
Wink Savillef4c4d362009-04-02 01:37:03 -07003511 closeResponse;
3512
3513 return 0;
3514}
3515
Wink Savillea592eeb2009-05-22 13:26:36 -07003516static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3517 RIL_CDMA_BroadcastSmsConfigInfo **p_cur =
3518 (RIL_CDMA_BroadcastSmsConfigInfo **) response;
Wink Savillef4c4d362009-04-02 01:37:03 -07003519
Wink Savillea592eeb2009-05-22 13:26:36 -07003520 int num = responselen / sizeof (RIL_CDMA_BroadcastSmsConfigInfo *);
3521 p.writeInt32(num);
Wink Savillef4c4d362009-04-02 01:37:03 -07003522
3523 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07003524 for (int i = 0 ; i < num ; i++ ) {
3525 p.writeInt32(p_cur[i]->service_category);
3526 p.writeInt32(p_cur[i]->language);
3527 p.writeInt32(p_cur[i]->selected);
Wink Savillef4c4d362009-04-02 01:37:03 -07003528
Wink Savillea592eeb2009-05-22 13:26:36 -07003529 appendPrintBuf("%s [%d: srvice_category=%d, language =%d, \
3530 selected =%d], ",
3531 printBuf, i, p_cur[i]->service_category, p_cur[i]->language,
3532 p_cur[i]->selected);
Wink Savillef5903df2009-04-24 11:54:14 -07003533 }
Wink Savillea592eeb2009-05-22 13:26:36 -07003534 closeResponse;
Wink Savillef5903df2009-04-24 11:54:14 -07003535
Wink Savillef4c4d362009-04-02 01:37:03 -07003536 return 0;
3537}
3538
3539static int responseCdmaSms(Parcel &p, void *response, size_t responselen) {
3540 int num;
3541 int digitCount;
3542 int digitLimit;
3543 uint8_t uct;
3544 void* dest;
3545
Wink Saville8eb2a122012-11-19 16:05:13 -08003546 RLOGD("Inside responseCdmaSms");
Wink Savillef5903df2009-04-24 11:54:14 -07003547
Wink Savillef4c4d362009-04-02 01:37:03 -07003548 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003549 RLOGE("invalid response: NULL");
Wink Savillef4c4d362009-04-02 01:37:03 -07003550 return RIL_ERRNO_INVALID_RESPONSE;
3551 }
3552
Wink Savillef5903df2009-04-24 11:54:14 -07003553 if (responselen != sizeof(RIL_CDMA_SMS_Message)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003554 RLOGE("invalid response length was %d expected %d",
Wink Savillef5903df2009-04-24 11:54:14 -07003555 (int)responselen, (int)sizeof(RIL_CDMA_SMS_Message));
Wink Savillef4c4d362009-04-02 01:37:03 -07003556 return RIL_ERRNO_INVALID_RESPONSE;
3557 }
3558
3559 RIL_CDMA_SMS_Message *p_cur = (RIL_CDMA_SMS_Message *) response;
3560 p.writeInt32(p_cur->uTeleserviceID);
3561 p.write(&(p_cur->bIsServicePresent),sizeof(uct));
3562 p.writeInt32(p_cur->uServicecategory);
3563 p.writeInt32(p_cur->sAddress.digit_mode);
3564 p.writeInt32(p_cur->sAddress.number_mode);
3565 p.writeInt32(p_cur->sAddress.number_type);
3566 p.writeInt32(p_cur->sAddress.number_plan);
3567 p.write(&(p_cur->sAddress.number_of_digits), sizeof(uct));
3568 digitLimit= MIN((p_cur->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
3569 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3570 p.write(&(p_cur->sAddress.digits[digitCount]),sizeof(uct));
3571 }
3572
3573 p.writeInt32(p_cur->sSubAddress.subaddressType);
3574 p.write(&(p_cur->sSubAddress.odd),sizeof(uct));
3575 p.write(&(p_cur->sSubAddress.number_of_digits),sizeof(uct));
3576 digitLimit= MIN((p_cur->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
3577 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3578 p.write(&(p_cur->sSubAddress.digits[digitCount]),sizeof(uct));
3579 }
3580
3581 digitLimit= MIN((p_cur->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
3582 p.writeInt32(p_cur->uBearerDataLen);
3583 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3584 p.write(&(p_cur->aBearerData[digitCount]), sizeof(uct));
3585 }
3586
3587 startResponse;
3588 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
Wink Saville1b5fd232009-04-22 14:50:00 -07003589 sAddress.digit_mode=%d, sAddress.number_mode=%d, sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07003590 printBuf, p_cur->uTeleserviceID,p_cur->bIsServicePresent,p_cur->uServicecategory,
3591 p_cur->sAddress.digit_mode, p_cur->sAddress.number_mode,p_cur->sAddress.number_type);
3592 closeResponse;
3593
3594 return 0;
3595}
3596
Wink Savillec29360a2014-07-13 05:17:28 -07003597static int responseDcRtInfo(Parcel &p, void *response, size_t responselen)
3598{
3599 int num = responselen / sizeof(RIL_DcRtInfo);
3600 if ((responselen % sizeof(RIL_DcRtInfo) != 0) || (num != 1)) {
Amit Mahajan52500162014-07-29 17:36:48 -07003601 RLOGE("responseDcRtInfo: invalid response length %d expected multiple of %d",
Wink Savillec29360a2014-07-13 05:17:28 -07003602 (int)responselen, (int)sizeof(RIL_DcRtInfo));
3603 return RIL_ERRNO_INVALID_RESPONSE;
3604 }
3605
3606 startResponse;
3607 RIL_DcRtInfo *pDcRtInfo = (RIL_DcRtInfo *)response;
3608 p.writeInt64(pDcRtInfo->time);
3609 p.writeInt32(pDcRtInfo->powerState);
3610 appendPrintBuf("%s[time=%d,powerState=%d]", printBuf,
3611 pDcRtInfo->time,
3612 pDcRtInfo->powerState);
3613 closeResponse;
3614
3615 return 0;
3616}
3617
fengluf7408292015-04-14 14:53:55 -07003618static int responseLceStatus(Parcel &p, void *response, size_t responselen) {
3619 if (response == NULL || responselen != sizeof(RIL_LceStatusInfo)) {
3620 if (response == NULL) {
3621 RLOGE("invalid response: NULL");
3622 }
3623 else {
3624 RLOGE("responseLceStatus: invalid response length %d expecting len: d%",
3625 sizeof(RIL_LceStatusInfo), responselen);
3626 }
3627 return RIL_ERRNO_INVALID_RESPONSE;
3628 }
3629
3630 RIL_LceStatusInfo *p_cur = (RIL_LceStatusInfo *)response;
3631 p.write((void *)p_cur, 1); // p_cur->lce_status takes one byte.
3632 p.writeInt32(p_cur->actual_interval_ms);
3633
3634 startResponse;
3635 appendPrintBuf("LCE Status: %d, actual_interval_ms: %d",
3636 p_cur->lce_status, p_cur->actual_interval_ms);
3637 closeResponse;
3638
3639 return 0;
3640}
3641
3642static int responseLceData(Parcel &p, void *response, size_t responselen) {
3643 if (response == NULL || responselen != sizeof(RIL_LceDataInfo)) {
3644 if (response == NULL) {
3645 RLOGE("invalid response: NULL");
3646 }
3647 else {
3648 RLOGE("responseLceData: invalid response length %d expecting len: d%",
3649 sizeof(RIL_LceDataInfo), responselen);
3650 }
3651 return RIL_ERRNO_INVALID_RESPONSE;
3652 }
3653
3654 RIL_LceDataInfo *p_cur = (RIL_LceDataInfo *)response;
3655 p.writeInt32(p_cur->last_hop_capacity_kbps);
3656
3657 /* p_cur->confidence_level and p_cur->lce_suspended take 1 byte each.*/
3658 p.write((void *)&(p_cur->confidence_level), 1);
3659 p.write((void *)&(p_cur->lce_suspended), 1);
3660
3661 startResponse;
3662 appendPrintBuf("LCE info received: capacity %d confidence level %d
3663 and suspended %d",
3664 p_cur->last_hop_capacity_kbps, p_cur->confidence_level,
3665 p_cur->lce_suspended);
3666 closeResponse;
3667
3668 return 0;
3669}
3670
Prerepa Viswanadham73157492015-05-28 00:37:32 -07003671static int responseActivityData(Parcel &p, void *response, size_t responselen) {
3672 if (response == NULL || responselen != sizeof(RIL_ActivityStatsInfo)) {
3673 if (response == NULL) {
3674 RLOGE("invalid response: NULL");
3675 }
3676 else {
3677 RLOGE("responseActivityData: invalid response length %d expecting len: d%",
3678 sizeof(RIL_ActivityStatsInfo), responselen);
3679 }
3680 return RIL_ERRNO_INVALID_RESPONSE;
3681 }
3682
3683 RIL_ActivityStatsInfo *p_cur = (RIL_ActivityStatsInfo *)response;
3684 p.writeInt32(p_cur->sleep_mode_time_ms);
3685 p.writeInt32(p_cur->idle_mode_time_ms);
3686 for(int i = 0; i < RIL_NUM_TX_POWER_LEVELS; i++) {
3687 p.writeInt32(p_cur->tx_mode_time_ms[i]);
3688 }
3689 p.writeInt32(p_cur->rx_mode_time_ms);
3690
3691 startResponse;
3692 appendPrintBuf("Modem activity info received: sleep_mode_time_ms %d idle_mode_time_ms %d
3693 tx_mode_time_ms %d %d %d %d %d and rx_mode_time_ms %d",
3694 p_cur->sleep_mode_time_ms, p_cur->idle_mode_time_ms, p_cur->tx_mode_time_ms[0],
3695 p_cur->tx_mode_time_ms[1], p_cur->tx_mode_time_ms[2], p_cur->tx_mode_time_ms[3],
3696 p_cur->tx_mode_time_ms[4], p_cur->rx_mode_time_ms);
3697 closeResponse;
3698
3699 return 0;
3700}
3701
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003702/**
3703 * A write on the wakeup fd is done just to pop us out of select()
3704 * We empty the buffer here and then ril_event will reset the timers on the
3705 * way back down
3706 */
Wink Savillef4c4d362009-04-02 01:37:03 -07003707static void processWakeupCallback(int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003708 char buff[16];
3709 int ret;
3710
Wink Saville8eb2a122012-11-19 16:05:13 -08003711 RLOGV("processWakeupCallback");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003712
3713 /* empty our wakeup socket out */
3714 do {
3715 ret = read(s_fdWakeupRead, &buff, sizeof(buff));
Wink Saville7f856802009-06-09 10:23:37 -07003716 } while (ret > 0 || (ret < 0 && errno == EINTR));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003717}
3718
Etan Cohend3652192014-06-20 08:28:44 -07003719static void onCommandsSocketClosed(RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003720 int ret;
3721 RequestInfo *p_cur;
Etan Cohend3652192014-06-20 08:28:44 -07003722 /* Hook for current context
3723 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
3724 pthread_mutex_t * pendingRequestsMutexHook = &s_pendingRequestsMutex;
3725 /* pendingRequestsHook refer to &s_pendingRequests */
3726 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003727
Etan Cohend3652192014-06-20 08:28:44 -07003728#if (SIM_COUNT >= 2)
3729 if (socket_id == RIL_SOCKET_2) {
3730 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
3731 pendingRequestsHook = &s_pendingRequests_socket2;
3732 }
3733#if (SIM_COUNT >= 3)
3734 else if (socket_id == RIL_SOCKET_3) {
3735 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
3736 pendingRequestsHook = &s_pendingRequests_socket3;
3737 }
3738#endif
3739#if (SIM_COUNT >= 4)
3740 else if (socket_id == RIL_SOCKET_4) {
3741 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
3742 pendingRequestsHook = &s_pendingRequests_socket4;
3743 }
3744#endif
3745#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003746 /* mark pending requests as "cancelled" so we dont report responses */
Etan Cohend3652192014-06-20 08:28:44 -07003747 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003748 assert (ret == 0);
3749
Etan Cohend3652192014-06-20 08:28:44 -07003750 p_cur = *pendingRequestsHook;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003751
Etan Cohend3652192014-06-20 08:28:44 -07003752 for (p_cur = *pendingRequestsHook
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003753 ; p_cur != NULL
3754 ; p_cur = p_cur->p_next
3755 ) {
3756 p_cur->cancelled = 1;
3757 }
3758
Etan Cohend3652192014-06-20 08:28:44 -07003759 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003760 assert (ret == 0);
3761}
3762
Wink Savillef4c4d362009-04-02 01:37:03 -07003763static void processCommandsCallback(int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003764 RecordStream *p_rs;
3765 void *p_record;
3766 size_t recordlen;
3767 int ret;
Etan Cohend3652192014-06-20 08:28:44 -07003768 SocketListenParam *p_info = (SocketListenParam *)param;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003769
Etan Cohend3652192014-06-20 08:28:44 -07003770 assert(fd == p_info->fdCommand);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003771
Etan Cohend3652192014-06-20 08:28:44 -07003772 p_rs = p_info->p_rs;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003773
3774 for (;;) {
3775 /* loop until EAGAIN/EINTR, end of stream, or other error */
3776 ret = record_stream_get_next(p_rs, &p_record, &recordlen);
3777
3778 if (ret == 0 && p_record == NULL) {
3779 /* end-of-stream */
3780 break;
3781 } else if (ret < 0) {
3782 break;
3783 } else if (ret == 0) { /* && p_record != NULL */
Etan Cohend3652192014-06-20 08:28:44 -07003784 processCommandBuffer(p_record, recordlen, p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003785 }
3786 }
3787
3788 if (ret == 0 || !(errno == EAGAIN || errno == EINTR)) {
3789 /* fatal error or end-of-stream */
3790 if (ret != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003791 RLOGE("error on reading command socket errno:%d\n", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003792 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003793 RLOGW("EOS. Closing command socket.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003794 }
Wink Saville7f856802009-06-09 10:23:37 -07003795
Etan Cohend3652192014-06-20 08:28:44 -07003796 close(fd);
3797 p_info->fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003798
Etan Cohend3652192014-06-20 08:28:44 -07003799 ril_event_del(p_info->commands_event);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003800
3801 record_stream_free(p_rs);
3802
3803 /* start listening for new connections again */
3804 rilEventAddWakeup(&s_listen_event);
3805
Etan Cohend3652192014-06-20 08:28:44 -07003806 onCommandsSocketClosed(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003807 }
3808}
3809
3810
Etan Cohend3652192014-06-20 08:28:44 -07003811static void onNewCommandConnect(RIL_SOCKET_ID socket_id) {
Wink Saville5b9df332011-04-06 16:24:21 -07003812 // Inform we are connected and the ril version
Jake Hambya9c18d12011-04-12 23:32:08 -07003813 int rilVer = s_callbacks.version;
Etan Cohend3652192014-06-20 08:28:44 -07003814 RIL_UNSOL_RESPONSE(RIL_UNSOL_RIL_CONNECTED,
3815 &rilVer, sizeof(rilVer), socket_id);
Wink Saville5b9df332011-04-06 16:24:21 -07003816
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003817 // implicit radio state changed
Etan Cohend3652192014-06-20 08:28:44 -07003818 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
3819 NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003820
3821 // Send last NITZ time data, in case it was missed
3822 if (s_lastNITZTimeData != NULL) {
Etan Cohend3652192014-06-20 08:28:44 -07003823 sendResponseRaw(s_lastNITZTimeData, s_lastNITZTimeDataSize, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003824
3825 free(s_lastNITZTimeData);
3826 s_lastNITZTimeData = NULL;
3827 }
3828
3829 // Get version string
3830 if (s_callbacks.getVersion != NULL) {
3831 const char *version;
3832 version = s_callbacks.getVersion();
Wink Saville8eb2a122012-11-19 16:05:13 -08003833 RLOGI("RIL Daemon version: %s\n", version);
Wink Saville7f856802009-06-09 10:23:37 -07003834
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003835 property_set(PROPERTY_RIL_IMPL, version);
3836 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003837 RLOGI("RIL Daemon version: unavailable\n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003838 property_set(PROPERTY_RIL_IMPL, "unavailable");
3839 }
3840
3841}
3842
Wink Savillef4c4d362009-04-02 01:37:03 -07003843static void listenCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003844 int ret;
3845 int err;
3846 int is_phone_socket;
Etan Cohend3652192014-06-20 08:28:44 -07003847 int fdCommand = -1;
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003848 char* processName;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003849 RecordStream *p_rs;
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003850 MySocketListenParam* listenParam;
3851 RilSocket *sapSocket = NULL;
3852 socketClient *sClient = NULL;
3853
Etan Cohend3652192014-06-20 08:28:44 -07003854 SocketListenParam *p_info = (SocketListenParam *)param;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003855
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003856 if(RIL_SAP_SOCKET == p_info->type) {
3857 listenParam = (MySocketListenParam *)param;
3858 sapSocket = listenParam->socket;
3859 }
3860
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003861 struct sockaddr_un peeraddr;
3862 socklen_t socklen = sizeof (peeraddr);
3863
3864 struct ucred creds;
3865 socklen_t szCreds = sizeof(creds);
3866
3867 struct passwd *pwd = NULL;
3868
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003869 if(NULL == sapSocket) {
3870 assert (*p_info->fdCommand < 0);
3871 assert (fd == *p_info->fdListen);
3872 processName = PHONE_PROCESS;
3873 } else {
3874 assert (sapSocket->commandFd < 0);
3875 assert (fd == sapSocket->listenFd);
3876 processName = BLUETOOTH_PROCESS;
3877 }
3878
Wink Saville7f856802009-06-09 10:23:37 -07003879
Etan Cohend3652192014-06-20 08:28:44 -07003880 fdCommand = accept(fd, (sockaddr *) &peeraddr, &socklen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003881
Etan Cohend3652192014-06-20 08:28:44 -07003882 if (fdCommand < 0 ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003883 RLOGE("Error on accept() errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003884 /* start listening for new connections again */
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003885 if(NULL == sapSocket) {
3886 rilEventAddWakeup(p_info->listen_event);
3887 } else {
3888 rilEventAddWakeup(sapSocket->getListenEvent());
3889 }
Etan Cohend3652192014-06-20 08:28:44 -07003890 return;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003891 }
3892
3893 /* check the credential of the other side and only accept socket from
3894 * phone process
Wink Saville7f856802009-06-09 10:23:37 -07003895 */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003896 errno = 0;
3897 is_phone_socket = 0;
Wink Savillef4c4d362009-04-02 01:37:03 -07003898
Etan Cohend3652192014-06-20 08:28:44 -07003899 err = getsockopt(fdCommand, SOL_SOCKET, SO_PEERCRED, &creds, &szCreds);
Wink Savillef4c4d362009-04-02 01:37:03 -07003900
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003901 if (err == 0 && szCreds > 0) {
Wink Savillef4c4d362009-04-02 01:37:03 -07003902 errno = 0;
3903 pwd = getpwuid(creds.uid);
3904 if (pwd != NULL) {
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003905 if (strcmp(pwd->pw_name, processName) == 0) {
Wink Savillef4c4d362009-04-02 01:37:03 -07003906 is_phone_socket = 1;
3907 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003908 RLOGE("RILD can't accept socket from process %s", pwd->pw_name);
Wink Savillef4c4d362009-04-02 01:37:03 -07003909 }
3910 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003911 RLOGE("Error on getpwuid() errno: %d", errno);
Wink Savillef4c4d362009-04-02 01:37:03 -07003912 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003913 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003914 RLOGD("Error on getsockopt() errno: %d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003915 }
3916
Etan Cohend3652192014-06-20 08:28:44 -07003917 if (!is_phone_socket) {
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003918 RLOGE("RILD must accept socket from %s", processName);
Wink Saville7f856802009-06-09 10:23:37 -07003919
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003920 close(fdCommand);
3921 fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003922
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003923 if(NULL == sapSocket) {
3924 onCommandsSocketClosed(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003925
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003926 /* start listening for new connections again */
3927 rilEventAddWakeup(p_info->listen_event);
3928 } else {
3929 sapSocket->onCommandsSocketClosed();
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003930
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003931 /* start listening for new connections again */
3932 rilEventAddWakeup(sapSocket->getListenEvent());
3933 }
3934
3935 return;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003936 }
3937
Etan Cohend3652192014-06-20 08:28:44 -07003938 ret = fcntl(fdCommand, F_SETFL, O_NONBLOCK);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003939
3940 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003941 RLOGE ("Error setting O_NONBLOCK errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003942 }
3943
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003944 if(NULL == sapSocket) {
3945 RLOGI("libril: new connection to %s", rilSocketIdToString(p_info->socket_id));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003946
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003947 p_info->fdCommand = fdCommand;
3948 p_rs = record_stream_new(p_info->fdCommand, MAX_COMMAND_BYTES);
3949 p_info->p_rs = p_rs;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003950
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003951 ril_event_set (p_info->commands_event, p_info->fdCommand, 1,
Etan Cohend3652192014-06-20 08:28:44 -07003952 p_info->processCommandsCallback, p_info);
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003953 rilEventAddWakeup (p_info->commands_event);
Etan Cohend3652192014-06-20 08:28:44 -07003954
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003955 onNewCommandConnect(p_info->socket_id);
3956 } else {
3957 RLOGI("libril: new connection");
Etan Cohend3652192014-06-20 08:28:44 -07003958
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003959 sapSocket->setCommandFd(fdCommand);
3960 p_rs = record_stream_new(sapSocket->getCommandFd(), MAX_COMMAND_BYTES);
3961 sClient = new socketClient(sapSocket,p_rs);
3962 ril_event_set (sapSocket->getCallbackEvent(), sapSocket->getCommandFd(), 1,
3963 sapSocket->getCommandCb(), sClient);
3964
3965 rilEventAddWakeup(sapSocket->getCallbackEvent());
3966 sapSocket->onNewCommandConnect();
3967 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003968}
3969
3970static void freeDebugCallbackArgs(int number, char **args) {
3971 for (int i = 0; i < number; i++) {
3972 if (args[i] != NULL) {
3973 free(args[i]);
3974 }
3975 }
3976 free(args);
3977}
3978
Wink Savillef4c4d362009-04-02 01:37:03 -07003979static void debugCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003980 int acceptFD, option;
3981 struct sockaddr_un peeraddr;
3982 socklen_t socklen = sizeof (peeraddr);
3983 int data;
3984 unsigned int qxdm_data[6];
3985 const char *deactData[1] = {"1"};
3986 char *actData[1];
3987 RIL_Dial dialData;
3988 int hangupData[1] = {1};
3989 int number;
3990 char **args;
Etan Cohend3652192014-06-20 08:28:44 -07003991 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
3992 int sim_id = 0;
3993
3994 RLOGI("debugCallback for socket %s", rilSocketIdToString(socket_id));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003995
3996 acceptFD = accept (fd, (sockaddr *) &peeraddr, &socklen);
3997
3998 if (acceptFD < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003999 RLOGE ("error accepting on debug port: %d\n", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004000 return;
4001 }
4002
4003 if (recv(acceptFD, &number, sizeof(int), 0) != sizeof(int)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004004 RLOGE ("error reading on socket: number of Args: \n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004005 return;
4006 }
4007 args = (char **) malloc(sizeof(char*) * number);
4008
4009 for (int i = 0; i < number; i++) {
4010 int len;
4011 if (recv(acceptFD, &len, sizeof(int), 0) != sizeof(int)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004012 RLOGE ("error reading on socket: Len of Args: \n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004013 freeDebugCallbackArgs(i, args);
4014 return;
4015 }
4016 // +1 for null-term
4017 args[i] = (char *) malloc((sizeof(char) * len) + 1);
Wink Saville7f856802009-06-09 10:23:37 -07004018 if (recv(acceptFD, args[i], sizeof(char) * len, 0)
Wink Saville1b5fd232009-04-22 14:50:00 -07004019 != (int)sizeof(char) * len) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004020 RLOGE ("error reading on socket: Args[%d] \n", i);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004021 freeDebugCallbackArgs(i, args);
4022 return;
4023 }
4024 char * buf = args[i];
4025 buf[len] = 0;
Etan Cohend3652192014-06-20 08:28:44 -07004026 if ((i+1) == number) {
4027 /* The last argument should be sim id 0(SIM1)~3(SIM4) */
4028 sim_id = atoi(args[i]);
4029 switch (sim_id) {
4030 case 0:
4031 socket_id = RIL_SOCKET_1;
4032 break;
4033 #if (SIM_COUNT >= 2)
4034 case 1:
4035 socket_id = RIL_SOCKET_2;
4036 break;
4037 #endif
4038 #if (SIM_COUNT >= 3)
4039 case 2:
4040 socket_id = RIL_SOCKET_3;
4041 break;
4042 #endif
4043 #if (SIM_COUNT >= 4)
4044 case 3:
4045 socket_id = RIL_SOCKET_4;
4046 break;
4047 #endif
4048 default:
4049 socket_id = RIL_SOCKET_1;
4050 break;
4051 }
4052 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004053 }
4054
4055 switch (atoi(args[0])) {
4056 case 0:
Wink Saville8eb2a122012-11-19 16:05:13 -08004057 RLOGI ("Connection on debug port: issuing reset.");
Etan Cohend3652192014-06-20 08:28:44 -07004058 issueLocalRequest(RIL_REQUEST_RESET_RADIO, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004059 break;
4060 case 1:
Wink Saville8eb2a122012-11-19 16:05:13 -08004061 RLOGI ("Connection on debug port: issuing radio power off.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004062 data = 0;
Etan Cohend3652192014-06-20 08:28:44 -07004063 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004064 // Close the socket
Etan Cohend3652192014-06-20 08:28:44 -07004065 if (socket_id == RIL_SOCKET_1 && s_ril_param_socket.fdCommand > 0) {
4066 close(s_ril_param_socket.fdCommand);
4067 s_ril_param_socket.fdCommand = -1;
4068 }
4069 #if (SIM_COUNT == 2)
4070 else if (socket_id == RIL_SOCKET_2 && s_ril_param_socket2.fdCommand > 0) {
4071 close(s_ril_param_socket2.fdCommand);
4072 s_ril_param_socket2.fdCommand = -1;
4073 }
4074 #endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004075 break;
4076 case 2:
Wink Saville8eb2a122012-11-19 16:05:13 -08004077 RLOGI ("Debug port: issuing unsolicited voice network change.");
Etan Cohend3652192014-06-20 08:28:44 -07004078 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004079 break;
4080 case 3:
Wink Saville8eb2a122012-11-19 16:05:13 -08004081 RLOGI ("Debug port: QXDM log enable.");
Xia Wangd855ef42010-07-27 17:26:55 -07004082 qxdm_data[0] = 65536; // head.func_tag
4083 qxdm_data[1] = 16; // head.len
4084 qxdm_data[2] = 1; // mode: 1 for 'start logging'
4085 qxdm_data[3] = 32; // log_file_size: 32megabytes
4086 qxdm_data[4] = 0; // log_mask
4087 qxdm_data[5] = 8; // log_max_fileindex
Wink Saville7f856802009-06-09 10:23:37 -07004088 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Etan Cohend3652192014-06-20 08:28:44 -07004089 6 * sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004090 break;
4091 case 4:
Wink Saville8eb2a122012-11-19 16:05:13 -08004092 RLOGI ("Debug port: QXDM log disable.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004093 qxdm_data[0] = 65536;
4094 qxdm_data[1] = 16;
Xia Wangd855ef42010-07-27 17:26:55 -07004095 qxdm_data[2] = 0; // mode: 0 for 'stop logging'
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004096 qxdm_data[3] = 32;
4097 qxdm_data[4] = 0;
Xia Wangd855ef42010-07-27 17:26:55 -07004098 qxdm_data[5] = 8;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004099 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Etan Cohend3652192014-06-20 08:28:44 -07004100 6 * sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004101 break;
4102 case 5:
Wink Saville8eb2a122012-11-19 16:05:13 -08004103 RLOGI("Debug port: Radio On");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004104 data = 1;
Etan Cohend3652192014-06-20 08:28:44 -07004105 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004106 sleep(2);
4107 // Set network selection automatic.
Etan Cohend3652192014-06-20 08:28:44 -07004108 issueLocalRequest(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004109 break;
4110 case 6:
Wink Saville8eb2a122012-11-19 16:05:13 -08004111 RLOGI("Debug port: Setup Data Call, Apn :%s\n", args[1]);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004112 actData[0] = args[1];
Wink Saville7f856802009-06-09 10:23:37 -07004113 issueLocalRequest(RIL_REQUEST_SETUP_DATA_CALL, &actData,
Etan Cohend3652192014-06-20 08:28:44 -07004114 sizeof(actData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004115 break;
4116 case 7:
Wink Saville8eb2a122012-11-19 16:05:13 -08004117 RLOGI("Debug port: Deactivate Data Call");
Wink Saville7f856802009-06-09 10:23:37 -07004118 issueLocalRequest(RIL_REQUEST_DEACTIVATE_DATA_CALL, &deactData,
Etan Cohend3652192014-06-20 08:28:44 -07004119 sizeof(deactData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004120 break;
4121 case 8:
Wink Saville8eb2a122012-11-19 16:05:13 -08004122 RLOGI("Debug port: Dial Call");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004123 dialData.clir = 0;
4124 dialData.address = args[1];
Etan Cohend3652192014-06-20 08:28:44 -07004125 issueLocalRequest(RIL_REQUEST_DIAL, &dialData, sizeof(dialData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004126 break;
4127 case 9:
Wink Saville8eb2a122012-11-19 16:05:13 -08004128 RLOGI("Debug port: Answer Call");
Etan Cohend3652192014-06-20 08:28:44 -07004129 issueLocalRequest(RIL_REQUEST_ANSWER, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004130 break;
4131 case 10:
Wink Saville8eb2a122012-11-19 16:05:13 -08004132 RLOGI("Debug port: End Call");
Wink Saville7f856802009-06-09 10:23:37 -07004133 issueLocalRequest(RIL_REQUEST_HANGUP, &hangupData,
Etan Cohend3652192014-06-20 08:28:44 -07004134 sizeof(hangupData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004135 break;
4136 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004137 RLOGE ("Invalid request");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004138 break;
4139 }
4140 freeDebugCallbackArgs(number, args);
4141 close(acceptFD);
4142}
4143
4144
Wink Savillef4c4d362009-04-02 01:37:03 -07004145static void userTimerCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004146 UserCallbackInfo *p_info;
4147
4148 p_info = (UserCallbackInfo *)param;
4149
4150 p_info->p_callback(p_info->userParam);
4151
4152
4153 // FIXME generalize this...there should be a cancel mechanism
4154 if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) {
4155 s_last_wake_timeout_info = NULL;
4156 }
4157
4158 free(p_info);
4159}
4160
4161
4162static void *
Wink Savillef4c4d362009-04-02 01:37:03 -07004163eventLoop(void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004164 int ret;
4165 int filedes[2];
4166
4167 ril_event_init();
4168
4169 pthread_mutex_lock(&s_startupMutex);
4170
4171 s_started = 1;
4172 pthread_cond_broadcast(&s_startupCond);
4173
4174 pthread_mutex_unlock(&s_startupMutex);
4175
4176 ret = pipe(filedes);
4177
4178 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004179 RLOGE("Error in pipe() errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004180 return NULL;
4181 }
4182
4183 s_fdWakeupRead = filedes[0];
4184 s_fdWakeupWrite = filedes[1];
4185
4186 fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK);
4187
4188 ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,
4189 processWakeupCallback, NULL);
4190
4191 rilEventAddWakeup (&s_wakeupfd_event);
4192
4193 // Only returns on error
4194 ril_event_loop();
Wink Saville8eb2a122012-11-19 16:05:13 -08004195 RLOGE ("error in event_loop_base errno:%d", errno);
Kazuhiro Ondo5cdc1352011-10-14 17:50:58 -05004196 // kill self to restart on error
4197 kill(0, SIGKILL);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004198
4199 return NULL;
4200}
4201
Wink Saville7f856802009-06-09 10:23:37 -07004202extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07004203RIL_startEventLoop(void) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004204 /* spin up eventLoop thread and wait for it to get started */
4205 s_started = 0;
4206 pthread_mutex_lock(&s_startupMutex);
4207
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004208 pthread_attr_t attr;
4209 pthread_attr_init(&attr);
Wink Saville7f856802009-06-09 10:23:37 -07004210 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004211
Elliott Hughesfd81e712014-01-06 12:46:02 -08004212 int result = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
4213 if (result != 0) {
4214 RLOGE("Failed to create dispatch thread: %s", strerror(result));
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004215 goto done;
4216 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004217
4218 while (s_started == 0) {
4219 pthread_cond_wait(&s_startupCond, &s_startupMutex);
4220 }
4221
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004222done:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004223 pthread_mutex_unlock(&s_startupMutex);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004224}
4225
4226// Used for testing purpose only.
4227extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) {
4228 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4229}
4230
Etan Cohend3652192014-06-20 08:28:44 -07004231static void startListen(RIL_SOCKET_ID socket_id, SocketListenParam* socket_listen_p) {
4232 int fdListen = -1;
4233 int ret;
4234 char socket_name[10];
4235
4236 memset(socket_name, 0, sizeof(char)*10);
4237
4238 switch(socket_id) {
4239 case RIL_SOCKET_1:
4240 strncpy(socket_name, RIL_getRilSocketName(), 9);
4241 break;
4242 #if (SIM_COUNT >= 2)
4243 case RIL_SOCKET_2:
4244 strncpy(socket_name, SOCKET2_NAME_RIL, 9);
4245 break;
4246 #endif
4247 #if (SIM_COUNT >= 3)
4248 case RIL_SOCKET_3:
4249 strncpy(socket_name, SOCKET3_NAME_RIL, 9);
4250 break;
4251 #endif
4252 #if (SIM_COUNT >= 4)
4253 case RIL_SOCKET_4:
4254 strncpy(socket_name, SOCKET4_NAME_RIL, 9);
4255 break;
4256 #endif
4257 default:
4258 RLOGE("Socket id is wrong!!");
4259 return;
4260 }
4261
4262 RLOGI("Start to listen %s", rilSocketIdToString(socket_id));
4263
4264 fdListen = android_get_control_socket(socket_name);
4265 if (fdListen < 0) {
4266 RLOGE("Failed to get socket %s", socket_name);
4267 exit(-1);
4268 }
4269
4270 ret = listen(fdListen, 4);
4271
4272 if (ret < 0) {
4273 RLOGE("Failed to listen on control socket '%d': %s",
4274 fdListen, strerror(errno));
4275 exit(-1);
4276 }
4277 socket_listen_p->fdListen = fdListen;
4278
4279 /* note: non-persistent so we can accept only one connection at a time */
4280 ril_event_set (socket_listen_p->listen_event, fdListen, false,
4281 listenCallback, socket_listen_p);
4282
4283 rilEventAddWakeup (socket_listen_p->listen_event);
4284}
4285
Wink Saville7f856802009-06-09 10:23:37 -07004286extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07004287RIL_register (const RIL_RadioFunctions *callbacks) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004288 int ret;
4289 int flags;
4290
Etan Cohend3652192014-06-20 08:28:44 -07004291 RLOGI("SIM_COUNT: %d", SIM_COUNT);
4292
Wink Saville43808972011-01-13 17:39:51 -08004293 if (callbacks == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004294 RLOGE("RIL_register: RIL_RadioFunctions * null");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004295 return;
4296 }
Wink Saville43808972011-01-13 17:39:51 -08004297 if (callbacks->version < RIL_VERSION_MIN) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004298 RLOGE("RIL_register: version %d is to old, min version is %d",
Wink Saville43808972011-01-13 17:39:51 -08004299 callbacks->version, RIL_VERSION_MIN);
4300 return;
Wink Saville3a4840b2010-04-07 13:29:58 -07004301 }
Wink Saville43808972011-01-13 17:39:51 -08004302 if (callbacks->version > RIL_VERSION) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004303 RLOGE("RIL_register: version %d is too new, max version is %d",
Wink Saville43808972011-01-13 17:39:51 -08004304 callbacks->version, RIL_VERSION);
4305 return;
4306 }
Wink Saville8eb2a122012-11-19 16:05:13 -08004307 RLOGE("RIL_register: RIL version %d", callbacks->version);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004308
4309 if (s_registerCalled > 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004310 RLOGE("RIL_register has been called more than once. "
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004311 "Subsequent call ignored");
4312 return;
4313 }
4314
4315 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4316
Etan Cohend3652192014-06-20 08:28:44 -07004317 /* Initialize socket1 parameters */
4318 s_ril_param_socket = {
4319 RIL_SOCKET_1, /* socket_id */
4320 -1, /* fdListen */
4321 -1, /* fdCommand */
4322 PHONE_PROCESS, /* processName */
4323 &s_commands_event, /* commands_event */
4324 &s_listen_event, /* listen_event */
4325 processCommandsCallback, /* processCommandsCallback */
4326 NULL /* p_rs */
4327 };
4328
4329#if (SIM_COUNT >= 2)
4330 s_ril_param_socket2 = {
4331 RIL_SOCKET_2, /* socket_id */
4332 -1, /* fdListen */
4333 -1, /* fdCommand */
4334 PHONE_PROCESS, /* processName */
4335 &s_commands_event_socket2, /* commands_event */
4336 &s_listen_event_socket2, /* listen_event */
4337 processCommandsCallback, /* processCommandsCallback */
4338 NULL /* p_rs */
4339 };
4340#endif
4341
4342#if (SIM_COUNT >= 3)
4343 s_ril_param_socket3 = {
4344 RIL_SOCKET_3, /* socket_id */
4345 -1, /* fdListen */
4346 -1, /* fdCommand */
4347 PHONE_PROCESS, /* processName */
4348 &s_commands_event_socket3, /* commands_event */
4349 &s_listen_event_socket3, /* listen_event */
4350 processCommandsCallback, /* processCommandsCallback */
4351 NULL /* p_rs */
4352 };
4353#endif
4354
4355#if (SIM_COUNT >= 4)
4356 s_ril_param_socket4 = {
4357 RIL_SOCKET_4, /* socket_id */
4358 -1, /* fdListen */
4359 -1, /* fdCommand */
4360 PHONE_PROCESS, /* processName */
4361 &s_commands_event_socket4, /* commands_event */
4362 &s_listen_event_socket4, /* listen_event */
4363 processCommandsCallback, /* processCommandsCallback */
4364 NULL /* p_rs */
4365 };
4366#endif
4367
4368
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004369 s_registerCalled = 1;
4370
Etan Cohend3652192014-06-20 08:28:44 -07004371 RLOGI("s_registerCalled flag set, %d", s_started);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004372 // Little self-check
4373
Wink Savillef4c4d362009-04-02 01:37:03 -07004374 for (int i = 0; i < (int)NUM_ELEMS(s_commands); i++) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004375 assert(i == s_commands[i].requestNumber);
4376 }
4377
Wink Savillef4c4d362009-04-02 01:37:03 -07004378 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses); i++) {
Wink Saville7f856802009-06-09 10:23:37 -07004379 assert(i + RIL_UNSOL_RESPONSE_BASE
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004380 == s_unsolResponses[i].requestNumber);
4381 }
4382
4383 // New rild impl calls RIL_startEventLoop() first
4384 // old standalone impl wants it here.
4385
4386 if (s_started == 0) {
4387 RIL_startEventLoop();
4388 }
4389
Etan Cohend3652192014-06-20 08:28:44 -07004390 // start listen socket1
4391 startListen(RIL_SOCKET_1, &s_ril_param_socket);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004392
Etan Cohend3652192014-06-20 08:28:44 -07004393#if (SIM_COUNT >= 2)
4394 // start listen socket2
4395 startListen(RIL_SOCKET_2, &s_ril_param_socket2);
4396#endif /* (SIM_COUNT == 2) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004397
Etan Cohend3652192014-06-20 08:28:44 -07004398#if (SIM_COUNT >= 3)
4399 // start listen socket3
4400 startListen(RIL_SOCKET_3, &s_ril_param_socket3);
4401#endif /* (SIM_COUNT == 3) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004402
Etan Cohend3652192014-06-20 08:28:44 -07004403#if (SIM_COUNT >= 4)
4404 // start listen socket4
4405 startListen(RIL_SOCKET_4, &s_ril_param_socket4);
4406#endif /* (SIM_COUNT == 4) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004407
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004408
4409#if 1
4410 // start debug interface socket
4411
Etan Cohend3652192014-06-20 08:28:44 -07004412 char *inst = NULL;
4413 if (strlen(RIL_getRilSocketName()) >= strlen(SOCKET_NAME_RIL)) {
4414 inst = RIL_getRilSocketName() + strlen(SOCKET_NAME_RIL);
4415 }
4416
4417 char rildebug[MAX_DEBUG_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL_DEBUG;
4418 if (inst != NULL) {
Nick Kralevichc52e45e2015-02-08 07:54:16 -08004419 strlcat(rildebug, inst, MAX_DEBUG_SOCKET_NAME_LENGTH);
Etan Cohend3652192014-06-20 08:28:44 -07004420 }
4421
4422 s_fdDebug = android_get_control_socket(rildebug);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004423 if (s_fdDebug < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07004424 RLOGE("Failed to get socket : %s errno:%d", rildebug, errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004425 exit(-1);
4426 }
4427
4428 ret = listen(s_fdDebug, 4);
4429
4430 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004431 RLOGE("Failed to listen on ril debug socket '%d': %s",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004432 s_fdDebug, strerror(errno));
4433 exit(-1);
4434 }
4435
4436 ril_event_set (&s_debug_event, s_fdDebug, true,
4437 debugCallback, NULL);
4438
4439 rilEventAddWakeup (&s_debug_event);
4440#endif
4441
4442}
4443
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004444extern "C" void
4445RIL_register_socket (RIL_RadioFunctions *(*Init)(const struct RIL_Env *, int, char **),RIL_SOCKET_TYPE socketType, int argc, char **argv) {
4446
4447 RIL_RadioFunctions* UimFuncs = NULL;
4448
4449 if(Init) {
4450 UimFuncs = Init(&RilSapSocket::uimRilEnv, argc, argv);
4451
4452 switch(socketType) {
4453 case RIL_SAP_SOCKET:
4454 RilSapSocket::initSapSocket("sap_uim_socket1", UimFuncs);
4455
4456#if (SIM_COUNT >= 2)
4457 RilSapSocket::initSapSocket("sap_uim_socket2", UimFuncs);
4458#endif
4459
4460#if (SIM_COUNT >= 3)
4461 RilSapSocket::initSapSocket("sap_uim_socket3", UimFuncs);
4462#endif
4463
4464#if (SIM_COUNT >= 4)
4465 RilSapSocket::initSapSocket("sap_uim_socket4", UimFuncs);
4466#endif
4467 }
4468 }
4469}
4470
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004471static int
Wink Savillef4c4d362009-04-02 01:37:03 -07004472checkAndDequeueRequestInfo(struct RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004473 int ret = 0;
Etan Cohend3652192014-06-20 08:28:44 -07004474 /* Hook for current context
4475 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
4476 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
4477 /* pendingRequestsHook refer to &s_pendingRequests */
4478 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
Wink Saville7f856802009-06-09 10:23:37 -07004479
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004480 if (pRI == NULL) {
4481 return 0;
4482 }
4483
Etan Cohend3652192014-06-20 08:28:44 -07004484#if (SIM_COUNT >= 2)
4485 if (pRI->socket_id == RIL_SOCKET_2) {
4486 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
4487 pendingRequestsHook = &s_pendingRequests_socket2;
4488 }
4489#if (SIM_COUNT >= 3)
4490 if (pRI->socket_id == RIL_SOCKET_3) {
4491 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
4492 pendingRequestsHook = &s_pendingRequests_socket3;
4493 }
4494#endif
4495#if (SIM_COUNT >= 4)
4496 if (pRI->socket_id == RIL_SOCKET_4) {
4497 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
4498 pendingRequestsHook = &s_pendingRequests_socket4;
4499 }
4500#endif
4501#endif
4502 pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004503
Etan Cohend3652192014-06-20 08:28:44 -07004504 for(RequestInfo **ppCur = pendingRequestsHook
Wink Saville7f856802009-06-09 10:23:37 -07004505 ; *ppCur != NULL
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004506 ; ppCur = &((*ppCur)->p_next)
4507 ) {
4508 if (pRI == *ppCur) {
4509 ret = 1;
4510
4511 *ppCur = (*ppCur)->p_next;
4512 break;
4513 }
4514 }
4515
Etan Cohend3652192014-06-20 08:28:44 -07004516 pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004517
4518 return ret;
4519}
4520
4521
4522extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07004523RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004524 RequestInfo *pRI;
4525 int ret;
Etan Cohend3652192014-06-20 08:28:44 -07004526 int fd = s_ril_param_socket.fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004527 size_t errorOffset;
Etan Cohend3652192014-06-20 08:28:44 -07004528 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004529
4530 pRI = (RequestInfo *)t;
4531
Jayachandran C6c607592014-08-04 15:48:01 -07004532 if (!checkAndDequeueRequestInfo(pRI)) {
4533 RLOGE ("RIL_onRequestComplete: invalid RIL_Token");
4534 return;
4535 }
4536
Etan Cohend3652192014-06-20 08:28:44 -07004537 socket_id = pRI->socket_id;
4538#if (SIM_COUNT >= 2)
4539 if (socket_id == RIL_SOCKET_2) {
4540 fd = s_ril_param_socket2.fdCommand;
4541 }
4542#if (SIM_COUNT >= 3)
4543 if (socket_id == RIL_SOCKET_3) {
4544 fd = s_ril_param_socket3.fdCommand;
4545 }
4546#endif
4547#if (SIM_COUNT >= 4)
4548 if (socket_id == RIL_SOCKET_4) {
4549 fd = s_ril_param_socket4.fdCommand;
4550 }
4551#endif
4552#endif
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07004553#if VDBG
Etan Cohend3652192014-06-20 08:28:44 -07004554 RLOGD("RequestComplete, %s", rilSocketIdToString(socket_id));
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07004555#endif
Etan Cohend3652192014-06-20 08:28:44 -07004556
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004557 if (pRI->local > 0) {
4558 // Locally issued command...void only!
4559 // response does not go back up the command socket
Wink Saville8eb2a122012-11-19 16:05:13 -08004560 RLOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004561
4562 goto done;
4563 }
4564
4565 appendPrintBuf("[%04d]< %s",
4566 pRI->token, requestToString(pRI->pCI->requestNumber));
4567
4568 if (pRI->cancelled == 0) {
4569 Parcel p;
4570
4571 p.writeInt32 (RESPONSE_SOLICITED);
4572 p.writeInt32 (pRI->token);
4573 errorOffset = p.dataPosition();
4574
4575 p.writeInt32 (e);
4576
johnwangb2a61842009-06-02 14:55:45 -07004577 if (response != NULL) {
4578 // there is a response payload, no matter success or not.
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004579 ret = pRI->pCI->responseFunction(p, response, responselen);
4580
4581 /* if an error occurred, rewind and mark it */
4582 if (ret != 0) {
Etan Cohend3652192014-06-20 08:28:44 -07004583 RLOGE ("responseFunction error, ret %d", ret);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004584 p.setDataPosition(errorOffset);
4585 p.writeInt32 (ret);
4586 }
johnwangb2a61842009-06-02 14:55:45 -07004587 }
4588
4589 if (e != RIL_E_SUCCESS) {
4590 appendPrintBuf("%s fails by %s", printBuf, failCauseToString(e));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004591 }
4592
Etan Cohend3652192014-06-20 08:28:44 -07004593 if (fd < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004594 RLOGD ("RIL onRequestComplete: Command channel closed");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004595 }
Etan Cohend3652192014-06-20 08:28:44 -07004596 sendResponse(p, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004597 }
4598
4599done:
4600 free(pRI);
4601}
4602
4603
4604static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004605grabPartialWakeLock() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004606 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
4607}
4608
4609static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004610releaseWakeLock() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004611 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
4612}
4613
4614/**
4615 * Timer callback to put us back to sleep before the default timeout
4616 */
4617static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004618wakeTimeoutCallback (void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004619 // We're using "param != NULL" as a cancellation mechanism
4620 if (param == NULL) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004621 releaseWakeLock();
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004622 }
4623}
4624
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004625static int
4626decodeVoiceRadioTechnology (RIL_RadioState radioState) {
4627 switch (radioState) {
4628 case RADIO_STATE_SIM_NOT_READY:
4629 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4630 case RADIO_STATE_SIM_READY:
4631 return RADIO_TECH_UMTS;
4632
4633 case RADIO_STATE_RUIM_NOT_READY:
4634 case RADIO_STATE_RUIM_READY:
4635 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4636 case RADIO_STATE_NV_NOT_READY:
4637 case RADIO_STATE_NV_READY:
4638 return RADIO_TECH_1xRTT;
4639
4640 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004641 RLOGD("decodeVoiceRadioTechnology: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004642 return -1;
4643 }
4644}
4645
4646static int
4647decodeCdmaSubscriptionSource (RIL_RadioState radioState) {
4648 switch (radioState) {
4649 case RADIO_STATE_SIM_NOT_READY:
4650 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4651 case RADIO_STATE_SIM_READY:
4652 case RADIO_STATE_RUIM_NOT_READY:
4653 case RADIO_STATE_RUIM_READY:
4654 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4655 return CDMA_SUBSCRIPTION_SOURCE_RUIM_SIM;
4656
4657 case RADIO_STATE_NV_NOT_READY:
4658 case RADIO_STATE_NV_READY:
4659 return CDMA_SUBSCRIPTION_SOURCE_NV;
4660
4661 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004662 RLOGD("decodeCdmaSubscriptionSource: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004663 return -1;
4664 }
4665}
4666
4667static int
4668decodeSimStatus (RIL_RadioState radioState) {
4669 switch (radioState) {
4670 case RADIO_STATE_SIM_NOT_READY:
4671 case RADIO_STATE_RUIM_NOT_READY:
4672 case RADIO_STATE_NV_NOT_READY:
4673 case RADIO_STATE_NV_READY:
4674 return -1;
4675 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4676 case RADIO_STATE_SIM_READY:
4677 case RADIO_STATE_RUIM_READY:
4678 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4679 return radioState;
4680 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004681 RLOGD("decodeSimStatus: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004682 return -1;
4683 }
4684}
4685
4686static bool is3gpp2(int radioTech) {
4687 switch (radioTech) {
4688 case RADIO_TECH_IS95A:
4689 case RADIO_TECH_IS95B:
4690 case RADIO_TECH_1xRTT:
4691 case RADIO_TECH_EVDO_0:
4692 case RADIO_TECH_EVDO_A:
4693 case RADIO_TECH_EVDO_B:
4694 case RADIO_TECH_EHRPD:
4695 return true;
4696 default:
4697 return false;
4698 }
4699}
4700
4701/* If RIL sends SIM states or RUIM states, store the voice radio
4702 * technology and subscription source information so that they can be
4703 * returned when telephony framework requests them
4704 */
4705static RIL_RadioState
Etan Cohend3652192014-06-20 08:28:44 -07004706processRadioState(RIL_RadioState newRadioState, RIL_SOCKET_ID socket_id) {
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004707
4708 if((newRadioState > RADIO_STATE_UNAVAILABLE) && (newRadioState < RADIO_STATE_ON)) {
4709 int newVoiceRadioTech;
4710 int newCdmaSubscriptionSource;
4711 int newSimStatus;
4712
4713 /* This is old RIL. Decode Subscription source and Voice Radio Technology
4714 from Radio State and send change notifications if there has been a change */
4715 newVoiceRadioTech = decodeVoiceRadioTechnology(newRadioState);
4716 if(newVoiceRadioTech != voiceRadioTech) {
4717 voiceRadioTech = newVoiceRadioTech;
Etan Cohend3652192014-06-20 08:28:44 -07004718 RIL_UNSOL_RESPONSE(RIL_UNSOL_VOICE_RADIO_TECH_CHANGED,
4719 &voiceRadioTech, sizeof(voiceRadioTech), socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004720 }
4721 if(is3gpp2(newVoiceRadioTech)) {
4722 newCdmaSubscriptionSource = decodeCdmaSubscriptionSource(newRadioState);
4723 if(newCdmaSubscriptionSource != cdmaSubscriptionSource) {
4724 cdmaSubscriptionSource = newCdmaSubscriptionSource;
Etan Cohend3652192014-06-20 08:28:44 -07004725 RIL_UNSOL_RESPONSE(RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED,
4726 &cdmaSubscriptionSource, sizeof(cdmaSubscriptionSource), socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004727 }
4728 }
4729 newSimStatus = decodeSimStatus(newRadioState);
4730 if(newSimStatus != simRuimStatus) {
4731 simRuimStatus = newSimStatus;
Etan Cohend3652192014-06-20 08:28:44 -07004732 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0, socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004733 }
4734
4735 /* Send RADIO_ON to telephony */
4736 newRadioState = RADIO_STATE_ON;
4737 }
4738
4739 return newRadioState;
4740}
4741
Etan Cohend3652192014-06-20 08:28:44 -07004742
4743#if defined(ANDROID_MULTI_SIM)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004744extern "C"
Bernhard Rosenkränzerd613b962014-11-17 20:52:09 +01004745void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Etan Cohend3652192014-06-20 08:28:44 -07004746 size_t datalen, RIL_SOCKET_ID socket_id)
4747#else
4748extern "C"
Bernhard Rosenkränzerd613b962014-11-17 20:52:09 +01004749void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004750 size_t datalen)
Etan Cohend3652192014-06-20 08:28:44 -07004751#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004752{
4753 int unsolResponseIndex;
4754 int ret;
4755 int64_t timeReceived = 0;
4756 bool shouldScheduleTimeout = false;
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004757 RIL_RadioState newState;
Etan Cohend3652192014-06-20 08:28:44 -07004758 RIL_SOCKET_ID soc_id = RIL_SOCKET_1;
4759
4760#if defined(ANDROID_MULTI_SIM)
4761 soc_id = socket_id;
4762#endif
4763
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004764
4765 if (s_registerCalled == 0) {
4766 // Ignore RIL_onUnsolicitedResponse before RIL_register
Wink Saville8eb2a122012-11-19 16:05:13 -08004767 RLOGW("RIL_onUnsolicitedResponse called before RIL_register");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004768 return;
4769 }
Wink Saville7f856802009-06-09 10:23:37 -07004770
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004771 unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
4772
4773 if ((unsolResponseIndex < 0)
4774 || (unsolResponseIndex >= (int32_t)NUM_ELEMS(s_unsolResponses))) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004775 RLOGE("unsupported unsolicited response code %d", unsolResponse);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004776 return;
4777 }
4778
4779 // Grab a wake lock if needed for this reponse,
4780 // as we exit we'll either release it immediately
4781 // or set a timer to release it later.
4782 switch (s_unsolResponses[unsolResponseIndex].wakeType) {
4783 case WAKE_PARTIAL:
4784 grabPartialWakeLock();
4785 shouldScheduleTimeout = true;
4786 break;
4787
4788 case DONT_WAKE:
4789 default:
4790 // No wake lock is grabed so don't set timeout
4791 shouldScheduleTimeout = false;
4792 break;
4793 }
4794
4795 // Mark the time this was received, doing this
4796 // after grabing the wakelock incase getting
4797 // the elapsedRealTime might cause us to goto
4798 // sleep.
4799 if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4800 timeReceived = elapsedRealtime();
4801 }
4802
4803 appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
4804
4805 Parcel p;
4806
4807 p.writeInt32 (RESPONSE_UNSOLICITED);
4808 p.writeInt32 (unsolResponse);
4809
4810 ret = s_unsolResponses[unsolResponseIndex]
Bernhard Rosenkränzer6e7c1962013-12-12 10:01:10 +01004811 .responseFunction(p, const_cast<void*>(data), datalen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004812 if (ret != 0) {
4813 // Problem with the response. Don't continue;
4814 goto error_exit;
4815 }
4816
4817 // some things get more payload
4818 switch(unsolResponse) {
4819 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
Etan Cohend3652192014-06-20 08:28:44 -07004820 newState = processRadioState(CALL_ONSTATEREQUEST(soc_id), soc_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004821 p.writeInt32(newState);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004822 appendPrintBuf("%s {%s}", printBuf,
Etan Cohend3652192014-06-20 08:28:44 -07004823 radioStateToString(CALL_ONSTATEREQUEST(soc_id)));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004824 break;
4825
4826
4827 case RIL_UNSOL_NITZ_TIME_RECEIVED:
4828 // Store the time that this was received so the
4829 // handler of this message can account for
4830 // the time it takes to arrive and process. In
4831 // particular the system has been known to sleep
4832 // before this message can be processed.
4833 p.writeInt64(timeReceived);
4834 break;
4835 }
4836
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07004837#if VDBG
Etan Cohend3652192014-06-20 08:28:44 -07004838 RLOGI("%s UNSOLICITED: %s length:%d", rilSocketIdToString(soc_id), requestToString(unsolResponse), p.dataSize());
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07004839#endif
Etan Cohend3652192014-06-20 08:28:44 -07004840 ret = sendResponse(p, soc_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004841 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4842
4843 // Unfortunately, NITZ time is not poll/update like everything
4844 // else in the system. So, if the upstream client isn't connected,
4845 // keep a copy of the last NITZ response (with receive time noted
4846 // above) around so we can deliver it when it is connected
4847
4848 if (s_lastNITZTimeData != NULL) {
4849 free (s_lastNITZTimeData);
4850 s_lastNITZTimeData = NULL;
4851 }
4852
4853 s_lastNITZTimeData = malloc(p.dataSize());
4854 s_lastNITZTimeDataSize = p.dataSize();
4855 memcpy(s_lastNITZTimeData, p.data(), p.dataSize());
4856 }
4857
4858 // For now, we automatically go back to sleep after TIMEVAL_WAKE_TIMEOUT
4859 // FIXME The java code should handshake here to release wake lock
4860
4861 if (shouldScheduleTimeout) {
4862 // Cancel the previous request
4863 if (s_last_wake_timeout_info != NULL) {
4864 s_last_wake_timeout_info->userParam = (void *)1;
4865 }
4866
4867 s_last_wake_timeout_info
4868 = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
4869 &TIMEVAL_WAKE_TIMEOUT);
4870 }
4871
4872 // Normal exit
4873 return;
4874
4875error_exit:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004876 if (shouldScheduleTimeout) {
4877 releaseWakeLock();
4878 }
4879}
4880
Wink Saville7f856802009-06-09 10:23:37 -07004881/** FIXME generalize this if you track UserCAllbackInfo, clear it
4882 when the callback occurs
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004883*/
4884static UserCallbackInfo *
Wink Saville7f856802009-06-09 10:23:37 -07004885internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004886 const struct timeval *relativeTime)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004887{
4888 struct timeval myRelativeTime;
4889 UserCallbackInfo *p_info;
4890
4891 p_info = (UserCallbackInfo *) malloc (sizeof(UserCallbackInfo));
4892
Wink Saville7f856802009-06-09 10:23:37 -07004893 p_info->p_callback = callback;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004894 p_info->userParam = param;
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004895
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004896 if (relativeTime == NULL) {
4897 /* treat null parameter as a 0 relative time */
4898 memset (&myRelativeTime, 0, sizeof(myRelativeTime));
4899 } else {
4900 /* FIXME I think event_add's tv param is really const anyway */
4901 memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
4902 }
4903
4904 ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
4905
4906 ril_timer_add(&(p_info->event), &myRelativeTime);
4907
4908 triggerEvLoop();
4909 return p_info;
4910}
4911
Naveen Kalla7edd07c2010-06-21 18:54:47 -07004912
4913extern "C" void
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004914RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
4915 const struct timeval *relativeTime) {
4916 internalRequestTimedCallback (callback, param, relativeTime);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004917}
4918
4919const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004920failCauseToString(RIL_Errno e) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004921 switch(e) {
4922 case RIL_E_SUCCESS: return "E_SUCCESS";
Robert Greenwalt2126ab22013-04-09 12:20:45 -07004923 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RADIO_NOT_AVAILABLE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004924 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
4925 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
4926 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
4927 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
4928 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
4929 case RIL_E_CANCELLED: return "E_CANCELLED";
4930 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
4931 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
4932 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
Wink Savillef4c4d362009-04-02 01:37:03 -07004933 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
John Wang75534472010-04-20 15:11:42 -07004934 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
Wink Saville7f856802009-06-09 10:23:37 -07004935#ifdef FEATURE_MULTIMODE_ANDROID
Wink Savillef4c4d362009-04-02 01:37:03 -07004936 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
4937 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
4938#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004939 default: return "<unknown error>";
4940 }
4941}
4942
4943const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004944radioStateToString(RIL_RadioState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004945 switch(s) {
4946 case RADIO_STATE_OFF: return "RADIO_OFF";
4947 case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
4948 case RADIO_STATE_SIM_NOT_READY: return "RADIO_SIM_NOT_READY";
4949 case RADIO_STATE_SIM_LOCKED_OR_ABSENT: return "RADIO_SIM_LOCKED_OR_ABSENT";
4950 case RADIO_STATE_SIM_READY: return "RADIO_SIM_READY";
Wink Savillef4c4d362009-04-02 01:37:03 -07004951 case RADIO_STATE_RUIM_NOT_READY:return"RADIO_RUIM_NOT_READY";
4952 case RADIO_STATE_RUIM_READY:return"RADIO_RUIM_READY";
4953 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:return"RADIO_RUIM_LOCKED_OR_ABSENT";
4954 case RADIO_STATE_NV_NOT_READY:return"RADIO_NV_NOT_READY";
4955 case RADIO_STATE_NV_READY:return"RADIO_NV_READY";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004956 case RADIO_STATE_ON:return"RADIO_ON";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004957 default: return "<unknown state>";
4958 }
4959}
4960
4961const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004962callStateToString(RIL_CallState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004963 switch(s) {
4964 case RIL_CALL_ACTIVE : return "ACTIVE";
4965 case RIL_CALL_HOLDING: return "HOLDING";
4966 case RIL_CALL_DIALING: return "DIALING";
4967 case RIL_CALL_ALERTING: return "ALERTING";
4968 case RIL_CALL_INCOMING: return "INCOMING";
4969 case RIL_CALL_WAITING: return "WAITING";
4970 default: return "<unknown state>";
4971 }
4972}
4973
4974const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004975requestToString(int request) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004976/*
4977 cat libs/telephony/ril_commands.h \
4978 | egrep "^ *{RIL_" \
4979 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
4980
4981
4982 cat libs/telephony/ril_unsol_commands.h \
4983 | egrep "^ *{RIL_" \
4984 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
4985
4986*/
4987 switch(request) {
4988 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
4989 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
4990 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
4991 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
4992 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
4993 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
4994 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
4995 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
4996 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
4997 case RIL_REQUEST_DIAL: return "DIAL";
4998 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
4999 case RIL_REQUEST_HANGUP: return "HANGUP";
5000 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
5001 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
5002 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
5003 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
5004 case RIL_REQUEST_UDUB: return "UDUB";
5005 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
5006 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
Wink Savillec0114b32011-02-18 10:14:07 -08005007 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
5008 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005009 case RIL_REQUEST_OPERATOR: return "OPERATOR";
5010 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
5011 case RIL_REQUEST_DTMF: return "DTMF";
5012 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
5013 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
Wink Savillef4c4d362009-04-02 01:37:03 -07005014 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005015 case RIL_REQUEST_SIM_IO: return "SIM_IO";
5016 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
5017 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
5018 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
5019 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
5020 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
5021 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
5022 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
5023 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
5024 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
5025 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
5026 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
5027 case RIL_REQUEST_ANSWER: return "ANSWER";
Wink Savillef4c4d362009-04-02 01:37:03 -07005028 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005029 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
5030 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
5031 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
5032 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
5033 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
5034 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
5035 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";
5036 case RIL_REQUEST_DTMF_START: return "DTMF_START";
5037 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
5038 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
5039 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
5040 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
5041 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
5042 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
5043 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
5044 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
5045 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
Wink Savillef4c4d362009-04-02 01:37:03 -07005046 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
5047 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005048 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
5049 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
5050 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
Wink Savillef4c4d362009-04-02 01:37:03 -07005051 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
5052 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005053 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
5054 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
5055 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
5056 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
5057 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
5058 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
5059 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
5060 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
Wink Savillec0114b32011-02-18 10:14:07 -08005061 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE:return"CDMA_SET_SUBSCRIPTION_SOURCE";
Wink Savillef4c4d362009-04-02 01:37:03 -07005062 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"CDMA_SET_ROAMING_PREFERENCE";
5063 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"CDMA_QUERY_ROAMING_PREFERENCE";
5064 case RIL_REQUEST_SET_TTY_MODE:return"SET_TTY_MODE";
5065 case RIL_REQUEST_QUERY_TTY_MODE:return"QUERY_TTY_MODE";
5066 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
5067 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
5068 case RIL_REQUEST_CDMA_FLASH:return"CDMA_FLASH";
5069 case RIL_REQUEST_CDMA_BURST_DTMF:return"CDMA_BURST_DTMF";
5070 case RIL_REQUEST_CDMA_SEND_SMS:return"CDMA_SEND_SMS";
5071 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:return"CDMA_SMS_ACKNOWLEDGE";
Wink Savillea592eeb2009-05-22 13:26:36 -07005072 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG:return"GSM_GET_BROADCAST_SMS_CONFIG";
5073 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG:return"GSM_SET_BROADCAST_SMS_CONFIG";
5074 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG:return "CDMA_GET_BROADCAST_SMS_CONFIG";
5075 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG:return "CDMA_SET_BROADCAST_SMS_CONFIG";
5076 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION:return "CDMA_SMS_BROADCAST_ACTIVATION";
Naveen Kalla03c1edf2009-09-23 11:18:35 -07005077 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return"CDMA_VALIDATE_AND_WRITE_AKEY";
Wink Savillef4c4d362009-04-02 01:37:03 -07005078 case RIL_REQUEST_CDMA_SUBSCRIPTION: return"CDMA_SUBSCRIPTION";
5079 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
5080 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
5081 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
jsh000a9fe2009-05-11 14:52:35 -07005082 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
5083 case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
5084 case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
jsh09a68ba2009-06-10 11:56:38 -07005085 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
jsh563fd722010-06-08 16:52:24 -07005086 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
Wink Savillec0114b32011-02-18 10:14:07 -08005087 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
Jake Hambyfa8d5842011-08-19 16:22:18 -07005088 case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
Jake Hamby300105d2011-09-26 01:01:44 -07005089 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
5090 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005091 case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
Wink Saville8a9e0212013-04-09 12:11:38 -07005092 case RIL_REQUEST_GET_CELL_INFO_LIST: return"GET_CELL_INFO_LIST";
5093 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return"SET_UNSOL_CELL_INFO_LIST_RATE";
Sungmin Choi75697532013-04-26 15:04:45 -07005094 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "RIL_REQUEST_SET_INITIAL_ATTACH_APN";
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07005095 case RIL_REQUEST_IMS_REGISTRATION_STATE: return "IMS_REGISTRATION_STATE";
5096 case RIL_REQUEST_IMS_SEND_SMS: return "IMS_SEND_SMS";
Shishir Agrawal2458d8d2013-11-27 14:53:05 -08005097 case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "SIM_TRANSMIT_APDU_BASIC";
5098 case RIL_REQUEST_SIM_OPEN_CHANNEL: return "SIM_OPEN_CHANNEL";
5099 case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "SIM_CLOSE_CHANNEL";
5100 case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "SIM_TRANSMIT_APDU_CHANNEL";
Wink Saville8b4e4f72014-10-17 15:01:45 -07005101 case RIL_REQUEST_GET_RADIO_CAPABILITY: return "RIL_REQUEST_GET_RADIO_CAPABILITY";
5102 case RIL_REQUEST_SET_RADIO_CAPABILITY: return "RIL_REQUEST_SET_RADIO_CAPABILITY";
Etan Cohend3652192014-06-20 08:28:44 -07005103 case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "SET_UICC_SUBSCRIPTION";
5104 case RIL_REQUEST_ALLOW_DATA: return "ALLOW_DATA";
Amit Mahajan2b772032014-06-26 14:20:11 -07005105 case RIL_REQUEST_GET_HARDWARE_CONFIG: return "GET_HARDWARE_CONFIG";
5106 case RIL_REQUEST_SIM_AUTHENTICATION: return "SIM_AUTHENTICATION";
Wink Savillec29360a2014-07-13 05:17:28 -07005107 case RIL_REQUEST_GET_DC_RT_INFO: return "GET_DC_RT_INFO";
5108 case RIL_REQUEST_SET_DC_RT_INFO_RATE: return "SET_DC_RT_INFO_RATE";
Amit Mahajanc796e222014-08-13 16:54:01 +00005109 case RIL_REQUEST_SET_DATA_PROFILE: return "SET_DATA_PROFILE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005110 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
5111 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08005112 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 -08005113 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
5114 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
5115 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
5116 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
5117 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)";
5118 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
5119 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
5120 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
5121 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
5122 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
5123 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
5124 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL";
5125 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
Wink Savillef4c4d362009-04-02 01:37:03 -07005126 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005127 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
Wink Savillef4c4d362009-04-02 01:37:03 -07005128 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
5129 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_NEW_CDMA_SMS";
5130 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_NEW_BROADCAST_SMS";
5131 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
Wink Saville3d54e742009-05-18 18:00:44 -07005132 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
5133 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
5134 case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
5135 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
5136 case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
Jaikumar Ganeshaf6ecbf2009-04-29 13:27:51 -07005137 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
John Wang5d621da2009-09-18 17:17:48 -07005138 case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
John Wang5909cf82010-01-29 00:18:54 -08005139 case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
Wink Savilleee274582011-04-16 15:05:49 -07005140 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08005141 case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
5142 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
Wink Saville5b9df332011-04-06 16:24:21 -07005143 case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005144 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
Wink Saville8a9e0212013-04-09 12:11:38 -07005145 case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07005146 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "RESPONSE_IMS_NETWORK_STATE_CHANGED";
Etan Cohend3652192014-06-20 08:28:44 -07005147 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return "UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED";
5148 case RIL_UNSOL_SRVCC_STATE_NOTIFY: return "UNSOL_SRVCC_STATE_NOTIFY";
5149 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return "HARDWARE_CONFIG_CHANGED";
Wink Savillec29360a2014-07-13 05:17:28 -07005150 case RIL_UNSOL_DC_RT_INFO_CHANGED: return "UNSOL_DC_RT_INFO_CHANGED";
Naveen Kallaa65a16a2014-07-31 16:48:31 -07005151 case RIL_REQUEST_SHUTDOWN: return "SHUTDOWN";
Wink Saville8b4e4f72014-10-17 15:01:45 -07005152 case RIL_UNSOL_RADIO_CAPABILITY: return "RIL_UNSOL_RADIO_CAPABILITY";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005153 default: return "<unknown request>";
5154 }
5155}
5156
Etan Cohend3652192014-06-20 08:28:44 -07005157const char *
5158rilSocketIdToString(RIL_SOCKET_ID socket_id)
5159{
5160 switch(socket_id) {
5161 case RIL_SOCKET_1:
5162 return "RIL_SOCKET_1";
5163#if (SIM_COUNT >= 2)
5164 case RIL_SOCKET_2:
5165 return "RIL_SOCKET_2";
5166#endif
5167#if (SIM_COUNT >= 3)
5168 case RIL_SOCKET_3:
5169 return "RIL_SOCKET_3";
5170#endif
5171#if (SIM_COUNT >= 4)
5172 case RIL_SOCKET_4:
5173 return "RIL_SOCKET_4";
5174#endif
5175 default:
5176 return "not a valid RIL";
5177 }
5178}
5179
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005180} /* namespace android */
Dheeraj Shetty27976c42014-07-02 21:27:57 +02005181
5182void rilEventAddWakeup_helper(struct ril_event *ev) {
5183 android::rilEventAddWakeup(ev);
5184}
5185
5186void listenCallback_helper(int fd, short flags, void *param) {
5187 android::listenCallback(fd, flags, param);
5188}
5189
5190int blockingWrite_helper(int fd, void *buffer, size_t len) {
5191 return android::blockingWrite(fd, buffer, len);
5192}