blob: fc4ea51889681750b307d055bccfac49fde15779 [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)) {
Sungmin Choia408c252015-07-01 16:22:46 +09002184 startResponse;
2185 int *p_int = (int *) response;
2186 appendPrintBuf("%s%d,", printBuf, p_int[0]);
2187 p.writeInt32(p_int[0]);
2188 removeLastChar;
2189 closeResponse;
Chao Liu548a81e2015-05-14 16:13:46 -07002190 } else if (responselen == sizeof(RIL_LastCallFailCauseInfo)) {
2191 startResponse;
2192 RIL_LastCallFailCauseInfo *p_fail_cause_info = (RIL_LastCallFailCauseInfo *) response;
2193 appendPrintBuf("%s[cause_code=%d,vendor_cause=%s]", printBuf, p_fail_cause_info->cause_code,
2194 p_fail_cause_info->vendor_cause);
2195 p.writeInt32(p_fail_cause_info->cause_code);
2196 writeStringToParcel(p, p_fail_cause_info->vendor_cause);
2197 removeLastChar;
2198 closeResponse;
2199 } else {
2200 RLOGE("responseFailCause: invalid response length %d expected an int or "
2201 "RIL_LastCallFailCauseInfo", (int)responselen);
2202 return RIL_ERRNO_INVALID_RESPONSE;
2203 }
2204
2205 return 0;
2206}
2207
Wink Saville43808972011-01-13 17:39:51 -08002208/** response is a char **, pointing to an array of char *'s
2209 The parcel will begin with the version */
2210static int responseStringsWithVersion(int version, Parcel &p, void *response, size_t responselen) {
2211 p.writeInt32(version);
2212 return responseStrings(p, response, responselen);
2213}
2214
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002215/** response is a char **, pointing to an array of char *'s */
Wink Savillef4c4d362009-04-02 01:37:03 -07002216static int responseStrings(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002217 int numStrings;
Wink Saville7f856802009-06-09 10:23:37 -07002218
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002219 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002220 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002221 return RIL_ERRNO_INVALID_RESPONSE;
2222 }
2223 if (responselen % sizeof(char *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002224 RLOGE("responseStrings: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002225 (int)responselen, (int)sizeof(char *));
2226 return RIL_ERRNO_INVALID_RESPONSE;
2227 }
2228
2229 if (response == NULL) {
2230 p.writeInt32 (0);
2231 } else {
2232 char **p_cur = (char **) response;
2233
2234 numStrings = responselen / sizeof(char *);
2235 p.writeInt32 (numStrings);
2236
2237 /* each string*/
2238 startResponse;
2239 for (int i = 0 ; i < numStrings ; i++) {
2240 appendPrintBuf("%s%s,", printBuf, (char*)p_cur[i]);
2241 writeStringToParcel (p, p_cur[i]);
2242 }
2243 removeLastChar;
2244 closeResponse;
2245 }
2246 return 0;
2247}
2248
2249
2250/**
Wink Saville7f856802009-06-09 10:23:37 -07002251 * NULL strings are accepted
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002252 * FIXME currently ignores responselen
2253 */
Wink Savillef4c4d362009-04-02 01:37:03 -07002254static int responseString(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002255 /* one string only */
2256 startResponse;
2257 appendPrintBuf("%s%s", printBuf, (char*)response);
2258 closeResponse;
2259
2260 writeStringToParcel(p, (const char *)response);
2261
2262 return 0;
2263}
2264
Wink Savillef4c4d362009-04-02 01:37:03 -07002265static int responseVoid(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002266 startResponse;
2267 removeLastChar;
2268 return 0;
2269}
2270
Wink Savillef4c4d362009-04-02 01:37:03 -07002271static int responseCallList(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002272 int num;
2273
2274 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002275 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002276 return RIL_ERRNO_INVALID_RESPONSE;
2277 }
2278
2279 if (responselen % sizeof (RIL_Call *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002280 RLOGE("responseCallList: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002281 (int)responselen, (int)sizeof (RIL_Call *));
2282 return RIL_ERRNO_INVALID_RESPONSE;
2283 }
2284
2285 startResponse;
2286 /* number of call info's */
2287 num = responselen / sizeof(RIL_Call *);
2288 p.writeInt32(num);
2289
2290 for (int i = 0 ; i < num ; i++) {
2291 RIL_Call *p_cur = ((RIL_Call **) response)[i];
2292 /* each call info */
2293 p.writeInt32(p_cur->state);
2294 p.writeInt32(p_cur->index);
2295 p.writeInt32(p_cur->toa);
2296 p.writeInt32(p_cur->isMpty);
2297 p.writeInt32(p_cur->isMT);
2298 p.writeInt32(p_cur->als);
2299 p.writeInt32(p_cur->isVoice);
Wink Saville1b5fd232009-04-22 14:50:00 -07002300 p.writeInt32(p_cur->isVoicePrivacy);
2301 writeStringToParcel(p, p_cur->number);
John Wangff368742009-03-24 17:56:29 -07002302 p.writeInt32(p_cur->numberPresentation);
Wink Saville1b5fd232009-04-22 14:50:00 -07002303 writeStringToParcel(p, p_cur->name);
2304 p.writeInt32(p_cur->namePresentation);
Wink Saville3a4840b2010-04-07 13:29:58 -07002305 // Remove when partners upgrade to version 3
Wink Saville74fa3882009-12-22 15:35:41 -08002306 if ((s_callbacks.version < 3) || (p_cur->uusInfo == NULL || p_cur->uusInfo->uusData == NULL)) {
2307 p.writeInt32(0); /* UUS Information is absent */
2308 } else {
2309 RIL_UUS_Info *uusInfo = p_cur->uusInfo;
2310 p.writeInt32(1); /* UUS Information is present */
2311 p.writeInt32(uusInfo->uusType);
2312 p.writeInt32(uusInfo->uusDcs);
2313 p.writeInt32(uusInfo->uusLength);
2314 p.write(uusInfo->uusData, uusInfo->uusLength);
2315 }
Wink Saville3d54e742009-05-18 18:00:44 -07002316 appendPrintBuf("%s[id=%d,%s,toa=%d,",
John Wangff368742009-03-24 17:56:29 -07002317 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002318 p_cur->index,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002319 callStateToString(p_cur->state),
Wink Saville3d54e742009-05-18 18:00:44 -07002320 p_cur->toa);
2321 appendPrintBuf("%s%s,%s,als=%d,%s,%s,",
2322 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002323 (p_cur->isMpty)?"conf":"norm",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002324 (p_cur->isMT)?"mt":"mo",
2325 p_cur->als,
2326 (p_cur->isVoice)?"voc":"nonvoc",
Wink Saville3d54e742009-05-18 18:00:44 -07002327 (p_cur->isVoicePrivacy)?"evp":"noevp");
2328 appendPrintBuf("%s%s,cli=%d,name='%s',%d]",
2329 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002330 p_cur->number,
2331 p_cur->numberPresentation,
2332 p_cur->name,
2333 p_cur->namePresentation);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002334 }
2335 removeLastChar;
2336 closeResponse;
2337
2338 return 0;
2339}
2340
Wink Savillef4c4d362009-04-02 01:37:03 -07002341static int responseSMS(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002342 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002343 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002344 return RIL_ERRNO_INVALID_RESPONSE;
2345 }
2346
2347 if (responselen != sizeof (RIL_SMS_Response) ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002348 RLOGE("invalid response length %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002349 (int)responselen, (int)sizeof (RIL_SMS_Response));
2350 return RIL_ERRNO_INVALID_RESPONSE;
2351 }
2352
2353 RIL_SMS_Response *p_cur = (RIL_SMS_Response *) response;
2354
2355 p.writeInt32(p_cur->messageRef);
2356 writeStringToParcel(p, p_cur->ackPDU);
Jaikumar Ganesh920c78f2009-06-04 10:53:15 -07002357 p.writeInt32(p_cur->errorCode);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002358
2359 startResponse;
Jaikumar Ganesh920c78f2009-06-04 10:53:15 -07002360 appendPrintBuf("%s%d,%s,%d", printBuf, p_cur->messageRef,
2361 (char*)p_cur->ackPDU, p_cur->errorCode);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002362 closeResponse;
2363
2364 return 0;
2365}
2366
Wink Savillec0114b32011-02-18 10:14:07 -08002367static int responseDataCallListV4(Parcel &p, void *response, size_t responselen)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002368{
2369 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002370 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002371 return RIL_ERRNO_INVALID_RESPONSE;
2372 }
2373
Wink Savillec0114b32011-02-18 10:14:07 -08002374 if (responselen % sizeof(RIL_Data_Call_Response_v4) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002375 RLOGE("responseDataCallListV4: invalid response length %d expected multiple of %d",
Wink Savillec0114b32011-02-18 10:14:07 -08002376 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v4));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002377 return RIL_ERRNO_INVALID_RESPONSE;
2378 }
2379
Amit Mahajan52500162014-07-29 17:36:48 -07002380 // Write version
2381 p.writeInt32(4);
2382
Wink Savillec0114b32011-02-18 10:14:07 -08002383 int num = responselen / sizeof(RIL_Data_Call_Response_v4);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002384 p.writeInt32(num);
2385
Wink Savillec0114b32011-02-18 10:14:07 -08002386 RIL_Data_Call_Response_v4 *p_cur = (RIL_Data_Call_Response_v4 *) response;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002387 startResponse;
2388 int i;
2389 for (i = 0; i < num; i++) {
2390 p.writeInt32(p_cur[i].cid);
2391 p.writeInt32(p_cur[i].active);
2392 writeStringToParcel(p, p_cur[i].type);
Wink Savillec0114b32011-02-18 10:14:07 -08002393 // apn is not used, so don't send.
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002394 writeStringToParcel(p, p_cur[i].address);
Wink Savillec0114b32011-02-18 10:14:07 -08002395 appendPrintBuf("%s[cid=%d,%s,%s,%s],", printBuf,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002396 p_cur[i].cid,
2397 (p_cur[i].active==0)?"down":"up",
2398 (char*)p_cur[i].type,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002399 (char*)p_cur[i].address);
2400 }
2401 removeLastChar;
2402 closeResponse;
2403
2404 return 0;
2405}
2406
Etan Cohend3652192014-06-20 08:28:44 -07002407static int responseDataCallListV6(Parcel &p, void *response, size_t responselen)
2408{
Amit Mahajan52500162014-07-29 17:36:48 -07002409 if (response == NULL && responselen != 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002410 RLOGE("invalid response: NULL");
2411 return RIL_ERRNO_INVALID_RESPONSE;
2412 }
2413
2414 if (responselen % sizeof(RIL_Data_Call_Response_v6) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002415 RLOGE("responseDataCallListV6: invalid response length %d expected multiple of %d",
Etan Cohend3652192014-06-20 08:28:44 -07002416 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v6));
2417 return RIL_ERRNO_INVALID_RESPONSE;
2418 }
2419
Amit Mahajan52500162014-07-29 17:36:48 -07002420 // Write version
2421 p.writeInt32(6);
2422
Etan Cohend3652192014-06-20 08:28:44 -07002423 int num = responselen / sizeof(RIL_Data_Call_Response_v6);
2424 p.writeInt32(num);
2425
2426 RIL_Data_Call_Response_v6 *p_cur = (RIL_Data_Call_Response_v6 *) response;
2427 startResponse;
2428 int i;
2429 for (i = 0; i < num; i++) {
2430 p.writeInt32((int)p_cur[i].status);
2431 p.writeInt32(p_cur[i].suggestedRetryTime);
2432 p.writeInt32(p_cur[i].cid);
2433 p.writeInt32(p_cur[i].active);
2434 writeStringToParcel(p, p_cur[i].type);
2435 writeStringToParcel(p, p_cur[i].ifname);
2436 writeStringToParcel(p, p_cur[i].addresses);
2437 writeStringToParcel(p, p_cur[i].dnses);
2438 writeStringToParcel(p, p_cur[i].gateways);
2439 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s],", printBuf,
2440 p_cur[i].status,
2441 p_cur[i].suggestedRetryTime,
2442 p_cur[i].cid,
2443 (p_cur[i].active==0)?"down":"up",
2444 (char*)p_cur[i].type,
2445 (char*)p_cur[i].ifname,
2446 (char*)p_cur[i].addresses,
2447 (char*)p_cur[i].dnses,
2448 (char*)p_cur[i].gateways);
2449 }
2450 removeLastChar;
2451 closeResponse;
2452
2453 return 0;
2454}
2455
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002456static int responseDataCallListV9(Parcel &p, void *response, size_t responselen)
2457{
2458 if (response == NULL && responselen != 0) {
2459 RLOGE("invalid response: NULL");
2460 return RIL_ERRNO_INVALID_RESPONSE;
2461 }
2462
2463 if (responselen % sizeof(RIL_Data_Call_Response_v9) != 0) {
2464 RLOGE("responseDataCallListV9: invalid response length %d expected multiple of %d",
2465 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v9));
2466 return RIL_ERRNO_INVALID_RESPONSE;
2467 }
2468
2469 // Write version
2470 p.writeInt32(10);
2471
2472 int num = responselen / sizeof(RIL_Data_Call_Response_v9);
2473 p.writeInt32(num);
2474
2475 RIL_Data_Call_Response_v9 *p_cur = (RIL_Data_Call_Response_v9 *) response;
2476 startResponse;
2477 int i;
2478 for (i = 0; i < num; i++) {
2479 p.writeInt32((int)p_cur[i].status);
2480 p.writeInt32(p_cur[i].suggestedRetryTime);
2481 p.writeInt32(p_cur[i].cid);
2482 p.writeInt32(p_cur[i].active);
2483 writeStringToParcel(p, p_cur[i].type);
2484 writeStringToParcel(p, p_cur[i].ifname);
2485 writeStringToParcel(p, p_cur[i].addresses);
2486 writeStringToParcel(p, p_cur[i].dnses);
2487 writeStringToParcel(p, p_cur[i].gateways);
2488 writeStringToParcel(p, p_cur[i].pcscf);
2489 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s],", printBuf,
2490 p_cur[i].status,
2491 p_cur[i].suggestedRetryTime,
2492 p_cur[i].cid,
2493 (p_cur[i].active==0)?"down":"up",
2494 (char*)p_cur[i].type,
2495 (char*)p_cur[i].ifname,
2496 (char*)p_cur[i].addresses,
2497 (char*)p_cur[i].dnses,
2498 (char*)p_cur[i].gateways,
2499 (char*)p_cur[i].pcscf);
2500 }
2501 removeLastChar;
2502 closeResponse;
2503
2504 return 0;
2505}
2506
2507
Wink Saville43808972011-01-13 17:39:51 -08002508static int responseDataCallList(Parcel &p, void *response, size_t responselen)
2509{
Wink Saville43808972011-01-13 17:39:51 -08002510 if (s_callbacks.version < 5) {
Amit Mahajan52500162014-07-29 17:36:48 -07002511 RLOGD("responseDataCallList: v4");
Wink Savillec0114b32011-02-18 10:14:07 -08002512 return responseDataCallListV4(p, response, responselen);
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002513 } else if (responselen % sizeof(RIL_Data_Call_Response_v6) == 0) {
2514 return responseDataCallListV6(p, response, responselen);
2515 } else if (responselen % sizeof(RIL_Data_Call_Response_v9) == 0) {
2516 return responseDataCallListV9(p, response, responselen);
Wink Saville43808972011-01-13 17:39:51 -08002517 } else {
2518 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002519 RLOGE("invalid response: NULL");
Wink Saville43808972011-01-13 17:39:51 -08002520 return RIL_ERRNO_INVALID_RESPONSE;
2521 }
2522
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002523 if (responselen % sizeof(RIL_Data_Call_Response_v11) != 0) {
2524 RLOGE("invalid response length %d expected multiple of %d",
2525 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v11));
Wink Saville43808972011-01-13 17:39:51 -08002526 return RIL_ERRNO_INVALID_RESPONSE;
2527 }
2528
Amit Mahajan52500162014-07-29 17:36:48 -07002529 // Write version
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002530 p.writeInt32(11);
Amit Mahajan52500162014-07-29 17:36:48 -07002531
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002532 int num = responselen / sizeof(RIL_Data_Call_Response_v11);
Wink Saville43808972011-01-13 17:39:51 -08002533 p.writeInt32(num);
2534
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002535 RIL_Data_Call_Response_v11 *p_cur = (RIL_Data_Call_Response_v11 *) response;
Wink Saville43808972011-01-13 17:39:51 -08002536 startResponse;
2537 int i;
2538 for (i = 0; i < num; i++) {
2539 p.writeInt32((int)p_cur[i].status);
Kazuhiro Ondobeb25b52011-06-17 16:26:45 -05002540 p.writeInt32(p_cur[i].suggestedRetryTime);
Wink Saville43808972011-01-13 17:39:51 -08002541 p.writeInt32(p_cur[i].cid);
2542 p.writeInt32(p_cur[i].active);
David 'Digit' Turneraf1298d2011-02-04 13:36:47 +01002543 writeStringToParcel(p, p_cur[i].type);
Wink Saville43808972011-01-13 17:39:51 -08002544 writeStringToParcel(p, p_cur[i].ifname);
2545 writeStringToParcel(p, p_cur[i].addresses);
2546 writeStringToParcel(p, p_cur[i].dnses);
Wink Savillec0114b32011-02-18 10:14:07 -08002547 writeStringToParcel(p, p_cur[i].gateways);
Etan Cohend3652192014-06-20 08:28:44 -07002548 writeStringToParcel(p, p_cur[i].pcscf);
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002549 p.writeInt32(p_cur[i].mtu);
2550 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 -08002551 p_cur[i].status,
Kazuhiro Ondobeb25b52011-06-17 16:26:45 -05002552 p_cur[i].suggestedRetryTime,
Wink Saville43808972011-01-13 17:39:51 -08002553 p_cur[i].cid,
2554 (p_cur[i].active==0)?"down":"up",
Naveen Kalla56384152011-11-16 11:12:37 -08002555 (char*)p_cur[i].type,
Wink Saville43808972011-01-13 17:39:51 -08002556 (char*)p_cur[i].ifname,
2557 (char*)p_cur[i].addresses,
Wink Savillec0114b32011-02-18 10:14:07 -08002558 (char*)p_cur[i].dnses,
Etan Cohend3652192014-06-20 08:28:44 -07002559 (char*)p_cur[i].gateways,
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002560 (char*)p_cur[i].pcscf,
2561 p_cur[i].mtu);
Wink Saville43808972011-01-13 17:39:51 -08002562 }
2563 removeLastChar;
2564 closeResponse;
2565 }
2566
2567 return 0;
2568}
2569
2570static int responseSetupDataCall(Parcel &p, void *response, size_t responselen)
2571{
2572 if (s_callbacks.version < 5) {
2573 return responseStringsWithVersion(s_callbacks.version, p, response, responselen);
2574 } else {
2575 return responseDataCallList(p, response, responselen);
2576 }
2577}
2578
Wink Savillef4c4d362009-04-02 01:37:03 -07002579static int responseRaw(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002580 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002581 RLOGE("invalid response: NULL with responselen != 0");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002582 return RIL_ERRNO_INVALID_RESPONSE;
2583 }
2584
2585 // The java code reads -1 size as null byte array
2586 if (response == NULL) {
Wink Saville7f856802009-06-09 10:23:37 -07002587 p.writeInt32(-1);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002588 } else {
2589 p.writeInt32(responselen);
2590 p.write(response, responselen);
2591 }
2592
2593 return 0;
2594}
2595
2596
Wink Savillef4c4d362009-04-02 01:37:03 -07002597static int responseSIM_IO(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002598 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002599 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002600 return RIL_ERRNO_INVALID_RESPONSE;
2601 }
2602
2603 if (responselen != sizeof (RIL_SIM_IO_Response) ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002604 RLOGE("invalid response length was %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002605 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
2606 return RIL_ERRNO_INVALID_RESPONSE;
2607 }
2608
2609 RIL_SIM_IO_Response *p_cur = (RIL_SIM_IO_Response *) response;
2610 p.writeInt32(p_cur->sw1);
2611 p.writeInt32(p_cur->sw2);
2612 writeStringToParcel(p, p_cur->simResponse);
2613
2614 startResponse;
2615 appendPrintBuf("%ssw1=0x%X,sw2=0x%X,%s", printBuf, p_cur->sw1, p_cur->sw2,
2616 (char*)p_cur->simResponse);
2617 closeResponse;
2618
2619
2620 return 0;
2621}
2622
Wink Savillef4c4d362009-04-02 01:37:03 -07002623static int responseCallForwards(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002624 int num;
Wink Saville7f856802009-06-09 10:23:37 -07002625
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002626 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002627 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002628 return RIL_ERRNO_INVALID_RESPONSE;
2629 }
2630
2631 if (responselen % sizeof(RIL_CallForwardInfo *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002632 RLOGE("responseCallForwards: invalid response length %d expected multiple of %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002633 (int)responselen, (int)sizeof(RIL_CallForwardInfo *));
2634 return RIL_ERRNO_INVALID_RESPONSE;
2635 }
2636
2637 /* number of call info's */
2638 num = responselen / sizeof(RIL_CallForwardInfo *);
2639 p.writeInt32(num);
2640
2641 startResponse;
2642 for (int i = 0 ; i < num ; i++) {
2643 RIL_CallForwardInfo *p_cur = ((RIL_CallForwardInfo **) response)[i];
2644
2645 p.writeInt32(p_cur->status);
2646 p.writeInt32(p_cur->reason);
2647 p.writeInt32(p_cur->serviceClass);
2648 p.writeInt32(p_cur->toa);
2649 writeStringToParcel(p, p_cur->number);
2650 p.writeInt32(p_cur->timeSeconds);
2651 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
2652 (p_cur->status==1)?"enable":"disable",
2653 p_cur->reason, p_cur->serviceClass, p_cur->toa,
2654 (char*)p_cur->number,
2655 p_cur->timeSeconds);
2656 }
2657 removeLastChar;
2658 closeResponse;
Wink Saville7f856802009-06-09 10:23:37 -07002659
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002660 return 0;
2661}
2662
Wink Savillef4c4d362009-04-02 01:37:03 -07002663static int responseSsn(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002664 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002665 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002666 return RIL_ERRNO_INVALID_RESPONSE;
2667 }
2668
2669 if (responselen != sizeof(RIL_SuppSvcNotification)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002670 RLOGE("invalid response length was %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002671 (int)responselen, (int)sizeof (RIL_SuppSvcNotification));
2672 return RIL_ERRNO_INVALID_RESPONSE;
2673 }
2674
2675 RIL_SuppSvcNotification *p_cur = (RIL_SuppSvcNotification *) response;
2676 p.writeInt32(p_cur->notificationType);
2677 p.writeInt32(p_cur->code);
2678 p.writeInt32(p_cur->index);
2679 p.writeInt32(p_cur->type);
2680 writeStringToParcel(p, p_cur->number);
2681
2682 startResponse;
2683 appendPrintBuf("%s%s,code=%d,id=%d,type=%d,%s", printBuf,
2684 (p_cur->notificationType==0)?"mo":"mt",
2685 p_cur->code, p_cur->index, p_cur->type,
2686 (char*)p_cur->number);
2687 closeResponse;
2688
2689 return 0;
2690}
2691
Wink Saville3d54e742009-05-18 18:00:44 -07002692static int responseCellList(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002693 int num;
2694
2695 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002696 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002697 return RIL_ERRNO_INVALID_RESPONSE;
2698 }
2699
2700 if (responselen % sizeof (RIL_NeighboringCell *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002701 RLOGE("responseCellList: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002702 (int)responselen, (int)sizeof (RIL_NeighboringCell *));
2703 return RIL_ERRNO_INVALID_RESPONSE;
2704 }
2705
2706 startResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002707 /* number of records */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002708 num = responselen / sizeof(RIL_NeighboringCell *);
2709 p.writeInt32(num);
2710
2711 for (int i = 0 ; i < num ; i++) {
2712 RIL_NeighboringCell *p_cur = ((RIL_NeighboringCell **) response)[i];
2713
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002714 p.writeInt32(p_cur->rssi);
2715 writeStringToParcel (p, p_cur->cid);
2716
2717 appendPrintBuf("%s[cid=%s,rssi=%d],", printBuf,
2718 p_cur->cid, p_cur->rssi);
2719 }
2720 removeLastChar;
2721 closeResponse;
2722
2723 return 0;
2724}
2725
Wink Saville3d54e742009-05-18 18:00:44 -07002726/**
2727 * Marshall the signalInfoRecord into the parcel if it exists.
2728 */
Wink Savillea592eeb2009-05-22 13:26:36 -07002729static void marshallSignalInfoRecord(Parcel &p,
2730 RIL_CDMA_SignalInfoRecord &p_signalInfoRecord) {
Wink Saville3d54e742009-05-18 18:00:44 -07002731 p.writeInt32(p_signalInfoRecord.isPresent);
2732 p.writeInt32(p_signalInfoRecord.signalType);
2733 p.writeInt32(p_signalInfoRecord.alertPitch);
2734 p.writeInt32(p_signalInfoRecord.signal);
2735}
2736
Wink Savillea592eeb2009-05-22 13:26:36 -07002737static int responseCdmaInformationRecords(Parcel &p,
2738 void *response, size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07002739 int num;
Wink Savillea592eeb2009-05-22 13:26:36 -07002740 char* string8 = NULL;
2741 int buffer_lenght;
2742 RIL_CDMA_InformationRecord *infoRec;
Wink Saville3d54e742009-05-18 18:00:44 -07002743
2744 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002745 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002746 return RIL_ERRNO_INVALID_RESPONSE;
2747 }
2748
Wink Savillea592eeb2009-05-22 13:26:36 -07002749 if (responselen != sizeof (RIL_CDMA_InformationRecords)) {
Amit Mahajan52500162014-07-29 17:36:48 -07002750 RLOGE("responseCdmaInformationRecords: invalid response length %d expected multiple of %d\n",
Wink Savillea592eeb2009-05-22 13:26:36 -07002751 (int)responselen, (int)sizeof (RIL_CDMA_InformationRecords *));
Wink Saville3d54e742009-05-18 18:00:44 -07002752 return RIL_ERRNO_INVALID_RESPONSE;
2753 }
2754
Wink Savillea592eeb2009-05-22 13:26:36 -07002755 RIL_CDMA_InformationRecords *p_cur =
2756 (RIL_CDMA_InformationRecords *) response;
2757 num = MIN(p_cur->numberOfInfoRecs, RIL_CDMA_MAX_NUMBER_OF_INFO_RECS);
Wink Saville3d54e742009-05-18 18:00:44 -07002758
2759 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07002760 p.writeInt32(num);
Wink Saville3d54e742009-05-18 18:00:44 -07002761
Wink Savillea592eeb2009-05-22 13:26:36 -07002762 for (int i = 0 ; i < num ; i++) {
2763 infoRec = &p_cur->infoRec[i];
2764 p.writeInt32(infoRec->name);
2765 switch (infoRec->name) {
Wink Saville3d54e742009-05-18 18:00:44 -07002766 case RIL_CDMA_DISPLAY_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002767 case RIL_CDMA_EXTENDED_DISPLAY_INFO_REC:
2768 if (infoRec->rec.display.alpha_len >
2769 CDMA_ALPHA_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002770 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002771 expected not more than %d\n",
2772 (int)infoRec->rec.display.alpha_len,
2773 CDMA_ALPHA_INFO_BUFFER_LENGTH);
2774 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002775 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002776 string8 = (char*) malloc((infoRec->rec.display.alpha_len + 1)
2777 * sizeof(char) );
2778 for (int i = 0 ; i < infoRec->rec.display.alpha_len ; i++) {
2779 string8[i] = infoRec->rec.display.alpha_buf[i];
2780 }
Wink Saville43808972011-01-13 17:39:51 -08002781 string8[(int)infoRec->rec.display.alpha_len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002782 writeStringToParcel(p, (const char*)string8);
2783 free(string8);
2784 string8 = NULL;
Wink Saville3d54e742009-05-18 18:00:44 -07002785 break;
2786 case RIL_CDMA_CALLED_PARTY_NUMBER_INFO_REC:
Wink Saville3d54e742009-05-18 18:00:44 -07002787 case RIL_CDMA_CALLING_PARTY_NUMBER_INFO_REC:
Wink Saville3d54e742009-05-18 18:00:44 -07002788 case RIL_CDMA_CONNECTED_NUMBER_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002789 if (infoRec->rec.number.len > CDMA_NUMBER_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002790 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002791 expected not more than %d\n",
2792 (int)infoRec->rec.number.len,
2793 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2794 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002795 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002796 string8 = (char*) malloc((infoRec->rec.number.len + 1)
2797 * sizeof(char) );
2798 for (int i = 0 ; i < infoRec->rec.number.len; i++) {
2799 string8[i] = infoRec->rec.number.buf[i];
2800 }
Wink Saville43808972011-01-13 17:39:51 -08002801 string8[(int)infoRec->rec.number.len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002802 writeStringToParcel(p, (const char*)string8);
2803 free(string8);
2804 string8 = NULL;
2805 p.writeInt32(infoRec->rec.number.number_type);
2806 p.writeInt32(infoRec->rec.number.number_plan);
2807 p.writeInt32(infoRec->rec.number.pi);
2808 p.writeInt32(infoRec->rec.number.si);
Wink Saville3d54e742009-05-18 18:00:44 -07002809 break;
2810 case RIL_CDMA_SIGNAL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002811 p.writeInt32(infoRec->rec.signal.isPresent);
2812 p.writeInt32(infoRec->rec.signal.signalType);
2813 p.writeInt32(infoRec->rec.signal.alertPitch);
2814 p.writeInt32(infoRec->rec.signal.signal);
2815
2816 appendPrintBuf("%sisPresent=%X, signalType=%X, \
2817 alertPitch=%X, signal=%X, ",
2818 printBuf, (int)infoRec->rec.signal.isPresent,
2819 (int)infoRec->rec.signal.signalType,
2820 (int)infoRec->rec.signal.alertPitch,
2821 (int)infoRec->rec.signal.signal);
2822 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002823 break;
2824 case RIL_CDMA_REDIRECTING_NUMBER_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002825 if (infoRec->rec.redir.redirectingNumber.len >
2826 CDMA_NUMBER_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002827 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002828 expected not more than %d\n",
2829 (int)infoRec->rec.redir.redirectingNumber.len,
2830 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2831 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002832 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002833 string8 = (char*) malloc((infoRec->rec.redir.redirectingNumber
2834 .len + 1) * sizeof(char) );
2835 for (int i = 0;
2836 i < infoRec->rec.redir.redirectingNumber.len;
2837 i++) {
2838 string8[i] = infoRec->rec.redir.redirectingNumber.buf[i];
2839 }
Wink Saville43808972011-01-13 17:39:51 -08002840 string8[(int)infoRec->rec.redir.redirectingNumber.len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002841 writeStringToParcel(p, (const char*)string8);
2842 free(string8);
2843 string8 = NULL;
2844 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_type);
2845 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_plan);
2846 p.writeInt32(infoRec->rec.redir.redirectingNumber.pi);
2847 p.writeInt32(infoRec->rec.redir.redirectingNumber.si);
2848 p.writeInt32(infoRec->rec.redir.redirectingReason);
Wink Saville3d54e742009-05-18 18:00:44 -07002849 break;
2850 case RIL_CDMA_LINE_CONTROL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002851 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPolarityIncluded);
2852 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlToggle);
2853 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlReverse);
2854 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2855
2856 appendPrintBuf("%slineCtrlPolarityIncluded=%d, \
2857 lineCtrlToggle=%d, lineCtrlReverse=%d, \
2858 lineCtrlPowerDenial=%d, ", printBuf,
2859 (int)infoRec->rec.lineCtrl.lineCtrlPolarityIncluded,
2860 (int)infoRec->rec.lineCtrl.lineCtrlToggle,
2861 (int)infoRec->rec.lineCtrl.lineCtrlReverse,
2862 (int)infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2863 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002864 break;
2865 case RIL_CDMA_T53_CLIR_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002866 p.writeInt32((int)(infoRec->rec.clir.cause));
Wink Saville3d54e742009-05-18 18:00:44 -07002867
Wink Savillea592eeb2009-05-22 13:26:36 -07002868 appendPrintBuf("%scause%d", printBuf, infoRec->rec.clir.cause);
2869 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002870 break;
2871 case RIL_CDMA_T53_AUDIO_CONTROL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002872 p.writeInt32(infoRec->rec.audioCtrl.upLink);
2873 p.writeInt32(infoRec->rec.audioCtrl.downLink);
2874
2875 appendPrintBuf("%supLink=%d, downLink=%d, ", printBuf,
2876 infoRec->rec.audioCtrl.upLink,
2877 infoRec->rec.audioCtrl.downLink);
2878 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002879 break;
Wink Savillea592eeb2009-05-22 13:26:36 -07002880 case RIL_CDMA_T53_RELEASE_INFO_REC:
2881 // TODO(Moto): See David Krause, he has the answer:)
Wink Saville8eb2a122012-11-19 16:05:13 -08002882 RLOGE("RIL_CDMA_T53_RELEASE_INFO_REC: return INVALID_RESPONSE");
Wink Savillea592eeb2009-05-22 13:26:36 -07002883 return RIL_ERRNO_INVALID_RESPONSE;
2884 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08002885 RLOGE("Incorrect name value");
Wink Savillea592eeb2009-05-22 13:26:36 -07002886 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002887 }
2888 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002889 closeResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002890
Wink Savillea592eeb2009-05-22 13:26:36 -07002891 return 0;
Wink Saville3d54e742009-05-18 18:00:44 -07002892}
2893
Wink Savillea592eeb2009-05-22 13:26:36 -07002894static int responseRilSignalStrength(Parcel &p,
2895 void *response, size_t responselen) {
2896 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002897 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002898 return RIL_ERRNO_INVALID_RESPONSE;
2899 }
2900
Wink Savillec0114b32011-02-18 10:14:07 -08002901 if (responselen >= sizeof (RIL_SignalStrength_v5)) {
Etan Cohend3652192014-06-20 08:28:44 -07002902 RIL_SignalStrength_v10 *p_cur = ((RIL_SignalStrength_v10 *) response);
Wink Saville3d54e742009-05-18 18:00:44 -07002903
Wink Saville3d54e742009-05-18 18:00:44 -07002904 p.writeInt32(p_cur->GW_SignalStrength.signalStrength);
2905 p.writeInt32(p_cur->GW_SignalStrength.bitErrorRate);
2906 p.writeInt32(p_cur->CDMA_SignalStrength.dbm);
2907 p.writeInt32(p_cur->CDMA_SignalStrength.ecio);
2908 p.writeInt32(p_cur->EVDO_SignalStrength.dbm);
2909 p.writeInt32(p_cur->EVDO_SignalStrength.ecio);
2910 p.writeInt32(p_cur->EVDO_SignalStrength.signalNoiseRatio);
Wink Savillec0114b32011-02-18 10:14:07 -08002911 if (responselen >= sizeof (RIL_SignalStrength_v6)) {
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002912 /*
Wink Saville18e4ab12013-04-07 17:31:04 -07002913 * Fixup LTE for backwards compatibility
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002914 */
Wink Saville18e4ab12013-04-07 17:31:04 -07002915 if (s_callbacks.version <= 6) {
2916 // signalStrength: -1 -> 99
2917 if (p_cur->LTE_SignalStrength.signalStrength == -1) {
2918 p_cur->LTE_SignalStrength.signalStrength = 99;
2919 }
2920 // rsrp: -1 -> INT_MAX all other negative value to positive.
2921 // So remap here
2922 if (p_cur->LTE_SignalStrength.rsrp == -1) {
2923 p_cur->LTE_SignalStrength.rsrp = INT_MAX;
2924 } else if (p_cur->LTE_SignalStrength.rsrp < -1) {
2925 p_cur->LTE_SignalStrength.rsrp = -p_cur->LTE_SignalStrength.rsrp;
2926 }
2927 // rsrq: -1 -> INT_MAX
2928 if (p_cur->LTE_SignalStrength.rsrq == -1) {
2929 p_cur->LTE_SignalStrength.rsrq = INT_MAX;
2930 }
2931 // Not remapping rssnr is already using INT_MAX
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002932
Wink Saville18e4ab12013-04-07 17:31:04 -07002933 // cqi: -1 -> INT_MAX
2934 if (p_cur->LTE_SignalStrength.cqi == -1) {
2935 p_cur->LTE_SignalStrength.cqi = INT_MAX;
2936 }
2937 }
2938 p.writeInt32(p_cur->LTE_SignalStrength.signalStrength);
Wink Savillec0114b32011-02-18 10:14:07 -08002939 p.writeInt32(p_cur->LTE_SignalStrength.rsrp);
2940 p.writeInt32(p_cur->LTE_SignalStrength.rsrq);
2941 p.writeInt32(p_cur->LTE_SignalStrength.rssnr);
2942 p.writeInt32(p_cur->LTE_SignalStrength.cqi);
Etan Cohend3652192014-06-20 08:28:44 -07002943 if (responselen >= sizeof (RIL_SignalStrength_v10)) {
2944 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
2945 } else {
2946 p.writeInt32(INT_MAX);
2947 }
Wink Savillec0114b32011-02-18 10:14:07 -08002948 } else {
Wink Saville18e4ab12013-04-07 17:31:04 -07002949 p.writeInt32(99);
2950 p.writeInt32(INT_MAX);
2951 p.writeInt32(INT_MAX);
2952 p.writeInt32(INT_MAX);
2953 p.writeInt32(INT_MAX);
Etan Cohend3652192014-06-20 08:28:44 -07002954 p.writeInt32(INT_MAX);
Wink Savillec0114b32011-02-18 10:14:07 -08002955 }
johnwangfdf825f2009-05-22 15:50:34 -07002956
2957 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07002958 appendPrintBuf("%s[signalStrength=%d,bitErrorRate=%d,\
Wink Savillec0114b32011-02-18 10:14:07 -08002959 CDMA_SS.dbm=%d,CDMA_SSecio=%d,\
2960 EVDO_SS.dbm=%d,EVDO_SS.ecio=%d,\
2961 EVDO_SS.signalNoiseRatio=%d,\
2962 LTE_SS.signalStrength=%d,LTE_SS.rsrp=%d,LTE_SS.rsrq=%d,\
Etan Cohend3652192014-06-20 08:28:44 -07002963 LTE_SS.rssnr=%d,LTE_SS.cqi=%d,TDSCDMA_SS.rscp=%d]",
Wink Savillea592eeb2009-05-22 13:26:36 -07002964 printBuf,
2965 p_cur->GW_SignalStrength.signalStrength,
2966 p_cur->GW_SignalStrength.bitErrorRate,
2967 p_cur->CDMA_SignalStrength.dbm,
2968 p_cur->CDMA_SignalStrength.ecio,
2969 p_cur->EVDO_SignalStrength.dbm,
2970 p_cur->EVDO_SignalStrength.ecio,
Wink Savillec0114b32011-02-18 10:14:07 -08002971 p_cur->EVDO_SignalStrength.signalNoiseRatio,
2972 p_cur->LTE_SignalStrength.signalStrength,
2973 p_cur->LTE_SignalStrength.rsrp,
2974 p_cur->LTE_SignalStrength.rsrq,
2975 p_cur->LTE_SignalStrength.rssnr,
Etan Cohend3652192014-06-20 08:28:44 -07002976 p_cur->LTE_SignalStrength.cqi,
2977 p_cur->TD_SCDMA_SignalStrength.rscp);
Wink Savillea592eeb2009-05-22 13:26:36 -07002978 closeResponse;
2979
Wink Saville3d54e742009-05-18 18:00:44 -07002980 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08002981 RLOGE("invalid response length");
Wink Saville3d54e742009-05-18 18:00:44 -07002982 return RIL_ERRNO_INVALID_RESPONSE;
2983 }
2984
Wink Saville3d54e742009-05-18 18:00:44 -07002985 return 0;
2986}
2987
2988static int responseCallRing(Parcel &p, void *response, size_t responselen) {
2989 if ((response == NULL) || (responselen == 0)) {
2990 return responseVoid(p, response, responselen);
2991 } else {
2992 return responseCdmaSignalInfoRecord(p, response, responselen);
2993 }
2994}
2995
2996static int responseCdmaSignalInfoRecord(Parcel &p, void *response, size_t responselen) {
2997 if (response == NULL || responselen == 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002998 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002999 return RIL_ERRNO_INVALID_RESPONSE;
3000 }
3001
3002 if (responselen != sizeof (RIL_CDMA_SignalInfoRecord)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003003 RLOGE("invalid response length %d expected sizeof (RIL_CDMA_SignalInfoRecord) of %d\n",
Wink Saville3d54e742009-05-18 18:00:44 -07003004 (int)responselen, (int)sizeof (RIL_CDMA_SignalInfoRecord));
3005 return RIL_ERRNO_INVALID_RESPONSE;
3006 }
3007
3008 startResponse;
3009
3010 RIL_CDMA_SignalInfoRecord *p_cur = ((RIL_CDMA_SignalInfoRecord *) response);
3011 marshallSignalInfoRecord(p, *p_cur);
3012
3013 appendPrintBuf("%s[isPresent=%d,signalType=%d,alertPitch=%d\
3014 signal=%d]",
3015 printBuf,
3016 p_cur->isPresent,
3017 p_cur->signalType,
3018 p_cur->alertPitch,
3019 p_cur->signal);
3020
3021 closeResponse;
3022 return 0;
3023}
3024
Wink Savillea592eeb2009-05-22 13:26:36 -07003025static int responseCdmaCallWaiting(Parcel &p, void *response,
3026 size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07003027 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003028 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07003029 return RIL_ERRNO_INVALID_RESPONSE;
3030 }
3031
Wink Savillec0114b32011-02-18 10:14:07 -08003032 if (responselen < sizeof(RIL_CDMA_CallWaiting_v6)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003033 RLOGW("Upgrade to ril version %d\n", RIL_VERSION);
Wink Savillec0114b32011-02-18 10:14:07 -08003034 }
3035
3036 RIL_CDMA_CallWaiting_v6 *p_cur = ((RIL_CDMA_CallWaiting_v6 *) response);
3037
3038 writeStringToParcel(p, p_cur->number);
3039 p.writeInt32(p_cur->numberPresentation);
3040 writeStringToParcel(p, p_cur->name);
3041 marshallSignalInfoRecord(p, p_cur->signalInfoRecord);
3042
3043 if (responselen >= sizeof(RIL_CDMA_CallWaiting_v6)) {
3044 p.writeInt32(p_cur->number_type);
3045 p.writeInt32(p_cur->number_plan);
3046 } else {
3047 p.writeInt32(0);
3048 p.writeInt32(0);
Wink Saville3d54e742009-05-18 18:00:44 -07003049 }
3050
3051 startResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07003052 appendPrintBuf("%snumber=%s,numberPresentation=%d, name=%s,\
3053 signalInfoRecord[isPresent=%d,signalType=%d,alertPitch=%d\
Wink Savillec0114b32011-02-18 10:14:07 -08003054 signal=%d,number_type=%d,number_plan=%d]",
Wink Saville3d54e742009-05-18 18:00:44 -07003055 printBuf,
3056 p_cur->number,
3057 p_cur->numberPresentation,
3058 p_cur->name,
3059 p_cur->signalInfoRecord.isPresent,
3060 p_cur->signalInfoRecord.signalType,
3061 p_cur->signalInfoRecord.alertPitch,
Wink Savillec0114b32011-02-18 10:14:07 -08003062 p_cur->signalInfoRecord.signal,
3063 p_cur->number_type,
3064 p_cur->number_plan);
Wink Saville3d54e742009-05-18 18:00:44 -07003065 closeResponse;
3066
3067 return 0;
3068}
3069
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003070static int responseSimRefresh(Parcel &p, void *response, size_t responselen) {
3071 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003072 RLOGE("responseSimRefresh: invalid response: NULL");
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003073 return RIL_ERRNO_INVALID_RESPONSE;
3074 }
3075
3076 startResponse;
3077 if (s_callbacks.version == 7) {
3078 RIL_SimRefreshResponse_v7 *p_cur = ((RIL_SimRefreshResponse_v7 *) response);
3079 p.writeInt32(p_cur->result);
3080 p.writeInt32(p_cur->ef_id);
3081 writeStringToParcel(p, p_cur->aid);
3082
3083 appendPrintBuf("%sresult=%d, ef_id=%d, aid=%s",
3084 printBuf,
3085 p_cur->result,
3086 p_cur->ef_id,
3087 p_cur->aid);
3088 } else {
3089 int *p_cur = ((int *) response);
3090 p.writeInt32(p_cur[0]);
3091 p.writeInt32(p_cur[1]);
3092 writeStringToParcel(p, NULL);
3093
3094 appendPrintBuf("%sresult=%d, ef_id=%d",
3095 printBuf,
3096 p_cur[0],
3097 p_cur[1]);
3098 }
3099 closeResponse;
3100
3101 return 0;
3102}
3103
Wink Saville8a9e0212013-04-09 12:11:38 -07003104static int responseCellInfoList(Parcel &p, void *response, size_t responselen)
3105{
3106 if (response == NULL && responselen != 0) {
3107 RLOGE("invalid response: NULL");
3108 return RIL_ERRNO_INVALID_RESPONSE;
3109 }
3110
3111 if (responselen % sizeof(RIL_CellInfo) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07003112 RLOGE("responseCellInfoList: invalid response length %d expected multiple of %d",
Wink Saville8a9e0212013-04-09 12:11:38 -07003113 (int)responselen, (int)sizeof(RIL_CellInfo));
3114 return RIL_ERRNO_INVALID_RESPONSE;
3115 }
3116
3117 int num = responselen / sizeof(RIL_CellInfo);
3118 p.writeInt32(num);
3119
3120 RIL_CellInfo *p_cur = (RIL_CellInfo *) response;
3121 startResponse;
3122 int i;
3123 for (i = 0; i < num; i++) {
3124 appendPrintBuf("%s[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", printBuf, i,
3125 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
3126 p.writeInt32((int)p_cur->cellInfoType);
3127 p.writeInt32(p_cur->registered);
3128 p.writeInt32(p_cur->timeStampType);
3129 p.writeInt64(p_cur->timeStamp);
3130 switch(p_cur->cellInfoType) {
3131 case RIL_CELL_INFO_TYPE_GSM: {
Wink Savillec57b3eb2013-04-17 12:51:41 -07003132 appendPrintBuf("%s GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,", printBuf,
Wink Saville8a9e0212013-04-09 12:11:38 -07003133 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
3134 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
3135 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
Wink Savillec57b3eb2013-04-17 12:51:41 -07003136 p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3137 appendPrintBuf("%s gsmSS: ss=%d,ber=%d],", printBuf,
Wink Saville8a9e0212013-04-09 12:11:38 -07003138 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
3139 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3140
3141 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
3142 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
3143 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
3144 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
Wink Saville8a9e0212013-04-09 12:11:38 -07003145 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
3146 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3147 break;
3148 }
Wink Savillec57b3eb2013-04-17 12:51:41 -07003149 case RIL_CELL_INFO_TYPE_WCDMA: {
3150 appendPrintBuf("%s WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,", printBuf,
3151 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
3152 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
3153 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
3154 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
3155 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3156 appendPrintBuf("%s wcdmaSS: ss=%d,ber=%d],", printBuf,
3157 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
3158 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3159
3160 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
3161 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
3162 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
3163 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
3164 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3165 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
3166 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3167 break;
3168 }
Wink Saville8a9e0212013-04-09 12:11:38 -07003169 case RIL_CELL_INFO_TYPE_CDMA: {
3170 appendPrintBuf("%s CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d", printBuf,
3171 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
3172 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
3173 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
3174 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
3175 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3176
3177 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
3178 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
3179 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
3180 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
3181 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3182
3183 appendPrintBuf("%s cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d", printBuf,
3184 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
3185 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
3186 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
3187 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
3188 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3189
3190 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
3191 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
3192 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
3193 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
3194 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3195 break;
3196 }
3197 case RIL_CELL_INFO_TYPE_LTE: {
3198 appendPrintBuf("%s LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d", printBuf,
3199 p_cur->CellInfo.lte.cellIdentityLte.mcc,
3200 p_cur->CellInfo.lte.cellIdentityLte.mnc,
3201 p_cur->CellInfo.lte.cellIdentityLte.ci,
3202 p_cur->CellInfo.lte.cellIdentityLte.pci,
3203 p_cur->CellInfo.lte.cellIdentityLte.tac);
3204
3205 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
3206 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
3207 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
3208 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
3209 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
3210
3211 appendPrintBuf("%s lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d", printBuf,
3212 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
3213 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
3214 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
3215 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
3216 p_cur->CellInfo.lte.signalStrengthLte.cqi,
3217 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3218 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
3219 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
3220 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
3221 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
3222 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
3223 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3224 break;
3225 }
Etan Cohend3652192014-06-20 08:28:44 -07003226 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
3227 appendPrintBuf("%s TDSCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,cpid=%d,", printBuf,
3228 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc,
3229 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc,
3230 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac,
3231 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid,
3232 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3233 appendPrintBuf("%s tdscdmaSS: rscp=%d],", printBuf,
3234 p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3235
3236 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
3237 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
3238 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
3239 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
3240 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3241 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3242 break;
3243 }
Wink Saville8a9e0212013-04-09 12:11:38 -07003244 }
3245 p_cur += 1;
3246 }
3247 removeLastChar;
3248 closeResponse;
3249
3250 return 0;
3251}
3252
Etan Cohend3652192014-06-20 08:28:44 -07003253static int responseHardwareConfig(Parcel &p, void *response, size_t responselen)
3254{
3255 if (response == NULL && responselen != 0) {
3256 RLOGE("invalid response: NULL");
3257 return RIL_ERRNO_INVALID_RESPONSE;
3258 }
3259
3260 if (responselen % sizeof(RIL_HardwareConfig) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07003261 RLOGE("responseHardwareConfig: invalid response length %d expected multiple of %d",
Etan Cohend3652192014-06-20 08:28:44 -07003262 (int)responselen, (int)sizeof(RIL_HardwareConfig));
3263 return RIL_ERRNO_INVALID_RESPONSE;
3264 }
3265
3266 int num = responselen / sizeof(RIL_HardwareConfig);
3267 int i;
3268 RIL_HardwareConfig *p_cur = (RIL_HardwareConfig *) response;
3269
3270 p.writeInt32(num);
3271
3272 startResponse;
3273 for (i = 0; i < num; i++) {
3274 switch (p_cur[i].type) {
3275 case RIL_HARDWARE_CONFIG_MODEM: {
3276 writeStringToParcel(p, p_cur[i].uuid);
3277 p.writeInt32((int)p_cur[i].state);
3278 p.writeInt32(p_cur[i].cfg.modem.rat);
3279 p.writeInt32(p_cur[i].cfg.modem.maxVoice);
3280 p.writeInt32(p_cur[i].cfg.modem.maxData);
3281 p.writeInt32(p_cur[i].cfg.modem.maxStandby);
3282
3283 appendPrintBuf("%s modem: uuid=%s,state=%d,rat=%08x,maxV=%d,maxD=%d,maxS=%d", printBuf,
3284 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.modem.rat,
3285 p_cur[i].cfg.modem.maxVoice, p_cur[i].cfg.modem.maxData, p_cur[i].cfg.modem.maxStandby);
3286 break;
3287 }
3288 case RIL_HARDWARE_CONFIG_SIM: {
3289 writeStringToParcel(p, p_cur[i].uuid);
3290 p.writeInt32((int)p_cur[i].state);
3291 writeStringToParcel(p, p_cur[i].cfg.sim.modemUuid);
3292
3293 appendPrintBuf("%s sim: uuid=%s,state=%d,modem-uuid=%s", printBuf,
3294 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.sim.modemUuid);
3295 break;
3296 }
3297 }
3298 }
3299 removeLastChar;
3300 closeResponse;
3301 return 0;
3302}
3303
Wink Saville8b4e4f72014-10-17 15:01:45 -07003304static int responseRadioCapability(Parcel &p, void *response, size_t responselen) {
3305 if (response == NULL) {
3306 RLOGE("invalid response: NULL");
3307 return RIL_ERRNO_INVALID_RESPONSE;
3308 }
3309
3310 if (responselen != sizeof (RIL_RadioCapability) ) {
3311 RLOGE("invalid response length was %d expected %d",
3312 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3313 return RIL_ERRNO_INVALID_RESPONSE;
3314 }
3315
3316 RIL_RadioCapability *p_cur = (RIL_RadioCapability *) response;
3317 p.writeInt32(p_cur->version);
3318 p.writeInt32(p_cur->session);
3319 p.writeInt32(p_cur->phase);
3320 p.writeInt32(p_cur->rat);
3321 writeStringToParcel(p, p_cur->logicalModemUuid);
3322 p.writeInt32(p_cur->status);
3323
3324 startResponse;
3325 appendPrintBuf("%s[version=%d,session=%d,phase=%d,\
Legler Wu8caf06f2014-10-29 14:02:14 +08003326 rat=%s,logicalModemUuid=%s,status=%d]",
Wink Saville8b4e4f72014-10-17 15:01:45 -07003327 printBuf,
3328 p_cur->version,
3329 p_cur->session,
3330 p_cur->phase,
3331 p_cur->rat,
Legler Wu8caf06f2014-10-29 14:02:14 +08003332 p_cur->logicalModemUuid,
Wink Saville8b4e4f72014-10-17 15:01:45 -07003333 p_cur->status);
3334 closeResponse;
3335 return 0;
3336}
3337
Amit Mahajan54563d32014-11-22 00:54:49 +00003338static int responseSSData(Parcel &p, void *response, size_t responselen) {
3339 RLOGD("In responseSSData");
3340 int num;
3341
3342 if (response == NULL && responselen != 0) {
3343 RLOGE("invalid response length was %d expected %d",
3344 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3345 return RIL_ERRNO_INVALID_RESPONSE;
3346 }
3347
3348 if (responselen != sizeof(RIL_StkCcUnsolSsResponse)) {
3349 RLOGE("invalid response length %d, expected %d",
3350 (int)responselen, (int)sizeof(RIL_StkCcUnsolSsResponse));
3351 return RIL_ERRNO_INVALID_RESPONSE;
3352 }
3353
3354 startResponse;
3355 RIL_StkCcUnsolSsResponse *p_cur = (RIL_StkCcUnsolSsResponse *) response;
3356 p.writeInt32(p_cur->serviceType);
3357 p.writeInt32(p_cur->requestType);
3358 p.writeInt32(p_cur->teleserviceType);
3359 p.writeInt32(p_cur->serviceClass);
3360 p.writeInt32(p_cur->result);
3361
3362 if (isServiceTypeCfQuery(p_cur->serviceType, p_cur->requestType)) {
3363 RLOGD("responseSSData CF type, num of Cf elements %d", p_cur->cfData.numValidIndexes);
3364 if (p_cur->cfData.numValidIndexes > NUM_SERVICE_CLASSES) {
3365 RLOGE("numValidIndexes is greater than max value %d, "
3366 "truncating it to max value", NUM_SERVICE_CLASSES);
3367 p_cur->cfData.numValidIndexes = NUM_SERVICE_CLASSES;
3368 }
3369 /* number of call info's */
3370 p.writeInt32(p_cur->cfData.numValidIndexes);
3371
3372 for (int i = 0; i < p_cur->cfData.numValidIndexes; i++) {
3373 RIL_CallForwardInfo cf = p_cur->cfData.cfInfo[i];
3374
3375 p.writeInt32(cf.status);
3376 p.writeInt32(cf.reason);
3377 p.writeInt32(cf.serviceClass);
3378 p.writeInt32(cf.toa);
3379 writeStringToParcel(p, cf.number);
3380 p.writeInt32(cf.timeSeconds);
3381 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
3382 (cf.status==1)?"enable":"disable", cf.reason, cf.serviceClass, cf.toa,
3383 (char*)cf.number, cf.timeSeconds);
3384 RLOGD("Data: %d,reason=%d,cls=%d,toa=%d,num=%s,tout=%d],", cf.status,
3385 cf.reason, cf.serviceClass, cf.toa, (char*)cf.number, cf.timeSeconds);
3386 }
3387 } else {
3388 p.writeInt32 (SS_INFO_MAX);
3389
3390 /* each int*/
3391 for (int i = 0; i < SS_INFO_MAX; i++) {
3392 appendPrintBuf("%s%d,", printBuf, p_cur->ssInfo[i]);
3393 RLOGD("Data: %d",p_cur->ssInfo[i]);
3394 p.writeInt32(p_cur->ssInfo[i]);
3395 }
3396 }
3397 removeLastChar;
3398 closeResponse;
3399
3400 return 0;
3401}
3402
3403static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType) {
3404 if ((reqType == SS_INTERROGATION) &&
3405 (serType == SS_CFU ||
3406 serType == SS_CF_BUSY ||
3407 serType == SS_CF_NO_REPLY ||
3408 serType == SS_CF_NOT_REACHABLE ||
3409 serType == SS_CF_ALL ||
3410 serType == SS_CF_ALL_CONDITIONAL)) {
3411 return true;
3412 }
3413 return false;
3414}
3415
Wink Saville3d54e742009-05-18 18:00:44 -07003416static void triggerEvLoop() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003417 int ret;
3418 if (!pthread_equal(pthread_self(), s_tid_dispatch)) {
3419 /* trigger event loop to wakeup. No reason to do this,
3420 * if we're in the event loop thread */
3421 do {
3422 ret = write (s_fdWakeupWrite, " ", 1);
3423 } while (ret < 0 && errno == EINTR);
3424 }
3425}
3426
Wink Saville3d54e742009-05-18 18:00:44 -07003427static void rilEventAddWakeup(struct ril_event *ev) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003428 ril_event_add(ev);
3429 triggerEvLoop();
3430}
3431
Wink Savillefd729372011-02-22 16:19:39 -08003432static void sendSimStatusAppInfo(Parcel &p, int num_apps, RIL_AppStatus appStatus[]) {
3433 p.writeInt32(num_apps);
3434 startResponse;
3435 for (int i = 0; i < num_apps; i++) {
3436 p.writeInt32(appStatus[i].app_type);
3437 p.writeInt32(appStatus[i].app_state);
3438 p.writeInt32(appStatus[i].perso_substate);
3439 writeStringToParcel(p, (const char*)(appStatus[i].aid_ptr));
3440 writeStringToParcel(p, (const char*)
3441 (appStatus[i].app_label_ptr));
3442 p.writeInt32(appStatus[i].pin1_replaced);
3443 p.writeInt32(appStatus[i].pin1);
3444 p.writeInt32(appStatus[i].pin2);
3445 appendPrintBuf("%s[app_type=%d,app_state=%d,perso_substate=%d,\
3446 aid_ptr=%s,app_label_ptr=%s,pin1_replaced=%d,pin1=%d,pin2=%d],",
3447 printBuf,
3448 appStatus[i].app_type,
3449 appStatus[i].app_state,
3450 appStatus[i].perso_substate,
3451 appStatus[i].aid_ptr,
3452 appStatus[i].app_label_ptr,
3453 appStatus[i].pin1_replaced,
3454 appStatus[i].pin1,
3455 appStatus[i].pin2);
3456 }
3457 closeResponse;
3458}
3459
Wink Savillef4c4d362009-04-02 01:37:03 -07003460static int responseSimStatus(Parcel &p, void *response, size_t responselen) {
3461 int i;
3462
3463 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003464 RLOGE("invalid response: NULL");
Wink Savillef4c4d362009-04-02 01:37:03 -07003465 return RIL_ERRNO_INVALID_RESPONSE;
3466 }
3467
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003468 if (responselen == sizeof (RIL_CardStatus_v6)) {
Wink Savillefd729372011-02-22 16:19:39 -08003469 RIL_CardStatus_v6 *p_cur = ((RIL_CardStatus_v6 *) response);
Wink Savillef4c4d362009-04-02 01:37:03 -07003470
Wink Savillefd729372011-02-22 16:19:39 -08003471 p.writeInt32(p_cur->card_state);
3472 p.writeInt32(p_cur->universal_pin_state);
3473 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3474 p.writeInt32(p_cur->cdma_subscription_app_index);
3475 p.writeInt32(p_cur->ims_subscription_app_index);
3476
3477 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003478 } else if (responselen == sizeof (RIL_CardStatus_v5)) {
Wink Savillefd729372011-02-22 16:19:39 -08003479 RIL_CardStatus_v5 *p_cur = ((RIL_CardStatus_v5 *) response);
3480
3481 p.writeInt32(p_cur->card_state);
3482 p.writeInt32(p_cur->universal_pin_state);
3483 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3484 p.writeInt32(p_cur->cdma_subscription_app_index);
3485 p.writeInt32(-1);
3486
3487 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003488 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003489 RLOGE("responseSimStatus: A RilCardStatus_v6 or _v5 expected\n");
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003490 return RIL_ERRNO_INVALID_RESPONSE;
Wink Savillef4c4d362009-04-02 01:37:03 -07003491 }
Wink Savillef4c4d362009-04-02 01:37:03 -07003492
3493 return 0;
Wink Saville3d54e742009-05-18 18:00:44 -07003494}
Wink Savillef4c4d362009-04-02 01:37:03 -07003495
Wink Savillea592eeb2009-05-22 13:26:36 -07003496static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3497 int num = responselen / sizeof(RIL_GSM_BroadcastSmsConfigInfo *);
Wink Savillef4c4d362009-04-02 01:37:03 -07003498 p.writeInt32(num);
3499
Wink Savillef4c4d362009-04-02 01:37:03 -07003500 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07003501 RIL_GSM_BroadcastSmsConfigInfo **p_cur =
3502 (RIL_GSM_BroadcastSmsConfigInfo **) response;
3503 for (int i = 0; i < num; i++) {
3504 p.writeInt32(p_cur[i]->fromServiceId);
3505 p.writeInt32(p_cur[i]->toServiceId);
3506 p.writeInt32(p_cur[i]->fromCodeScheme);
3507 p.writeInt32(p_cur[i]->toCodeScheme);
3508 p.writeInt32(p_cur[i]->selected);
3509
3510 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId=%d, \
3511 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]",
3512 printBuf, i, p_cur[i]->fromServiceId, p_cur[i]->toServiceId,
3513 p_cur[i]->fromCodeScheme, p_cur[i]->toCodeScheme,
3514 p_cur[i]->selected);
3515 }
Wink Savillef4c4d362009-04-02 01:37:03 -07003516 closeResponse;
3517
3518 return 0;
3519}
3520
Wink Savillea592eeb2009-05-22 13:26:36 -07003521static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3522 RIL_CDMA_BroadcastSmsConfigInfo **p_cur =
3523 (RIL_CDMA_BroadcastSmsConfigInfo **) response;
Wink Savillef4c4d362009-04-02 01:37:03 -07003524
Wink Savillea592eeb2009-05-22 13:26:36 -07003525 int num = responselen / sizeof (RIL_CDMA_BroadcastSmsConfigInfo *);
3526 p.writeInt32(num);
Wink Savillef4c4d362009-04-02 01:37:03 -07003527
3528 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07003529 for (int i = 0 ; i < num ; i++ ) {
3530 p.writeInt32(p_cur[i]->service_category);
3531 p.writeInt32(p_cur[i]->language);
3532 p.writeInt32(p_cur[i]->selected);
Wink Savillef4c4d362009-04-02 01:37:03 -07003533
Wink Savillea592eeb2009-05-22 13:26:36 -07003534 appendPrintBuf("%s [%d: srvice_category=%d, language =%d, \
3535 selected =%d], ",
3536 printBuf, i, p_cur[i]->service_category, p_cur[i]->language,
3537 p_cur[i]->selected);
Wink Savillef5903df2009-04-24 11:54:14 -07003538 }
Wink Savillea592eeb2009-05-22 13:26:36 -07003539 closeResponse;
Wink Savillef5903df2009-04-24 11:54:14 -07003540
Wink Savillef4c4d362009-04-02 01:37:03 -07003541 return 0;
3542}
3543
3544static int responseCdmaSms(Parcel &p, void *response, size_t responselen) {
3545 int num;
3546 int digitCount;
3547 int digitLimit;
3548 uint8_t uct;
3549 void* dest;
3550
Wink Saville8eb2a122012-11-19 16:05:13 -08003551 RLOGD("Inside responseCdmaSms");
Wink Savillef5903df2009-04-24 11:54:14 -07003552
Wink Savillef4c4d362009-04-02 01:37:03 -07003553 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003554 RLOGE("invalid response: NULL");
Wink Savillef4c4d362009-04-02 01:37:03 -07003555 return RIL_ERRNO_INVALID_RESPONSE;
3556 }
3557
Wink Savillef5903df2009-04-24 11:54:14 -07003558 if (responselen != sizeof(RIL_CDMA_SMS_Message)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003559 RLOGE("invalid response length was %d expected %d",
Wink Savillef5903df2009-04-24 11:54:14 -07003560 (int)responselen, (int)sizeof(RIL_CDMA_SMS_Message));
Wink Savillef4c4d362009-04-02 01:37:03 -07003561 return RIL_ERRNO_INVALID_RESPONSE;
3562 }
3563
3564 RIL_CDMA_SMS_Message *p_cur = (RIL_CDMA_SMS_Message *) response;
3565 p.writeInt32(p_cur->uTeleserviceID);
3566 p.write(&(p_cur->bIsServicePresent),sizeof(uct));
3567 p.writeInt32(p_cur->uServicecategory);
3568 p.writeInt32(p_cur->sAddress.digit_mode);
3569 p.writeInt32(p_cur->sAddress.number_mode);
3570 p.writeInt32(p_cur->sAddress.number_type);
3571 p.writeInt32(p_cur->sAddress.number_plan);
3572 p.write(&(p_cur->sAddress.number_of_digits), sizeof(uct));
3573 digitLimit= MIN((p_cur->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
3574 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3575 p.write(&(p_cur->sAddress.digits[digitCount]),sizeof(uct));
3576 }
3577
3578 p.writeInt32(p_cur->sSubAddress.subaddressType);
3579 p.write(&(p_cur->sSubAddress.odd),sizeof(uct));
3580 p.write(&(p_cur->sSubAddress.number_of_digits),sizeof(uct));
3581 digitLimit= MIN((p_cur->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
3582 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3583 p.write(&(p_cur->sSubAddress.digits[digitCount]),sizeof(uct));
3584 }
3585
3586 digitLimit= MIN((p_cur->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
3587 p.writeInt32(p_cur->uBearerDataLen);
3588 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3589 p.write(&(p_cur->aBearerData[digitCount]), sizeof(uct));
3590 }
3591
3592 startResponse;
3593 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
Wink Saville1b5fd232009-04-22 14:50:00 -07003594 sAddress.digit_mode=%d, sAddress.number_mode=%d, sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07003595 printBuf, p_cur->uTeleserviceID,p_cur->bIsServicePresent,p_cur->uServicecategory,
3596 p_cur->sAddress.digit_mode, p_cur->sAddress.number_mode,p_cur->sAddress.number_type);
3597 closeResponse;
3598
3599 return 0;
3600}
3601
Wink Savillec29360a2014-07-13 05:17:28 -07003602static int responseDcRtInfo(Parcel &p, void *response, size_t responselen)
3603{
3604 int num = responselen / sizeof(RIL_DcRtInfo);
3605 if ((responselen % sizeof(RIL_DcRtInfo) != 0) || (num != 1)) {
Amit Mahajan52500162014-07-29 17:36:48 -07003606 RLOGE("responseDcRtInfo: invalid response length %d expected multiple of %d",
Wink Savillec29360a2014-07-13 05:17:28 -07003607 (int)responselen, (int)sizeof(RIL_DcRtInfo));
3608 return RIL_ERRNO_INVALID_RESPONSE;
3609 }
3610
3611 startResponse;
3612 RIL_DcRtInfo *pDcRtInfo = (RIL_DcRtInfo *)response;
3613 p.writeInt64(pDcRtInfo->time);
3614 p.writeInt32(pDcRtInfo->powerState);
3615 appendPrintBuf("%s[time=%d,powerState=%d]", printBuf,
3616 pDcRtInfo->time,
3617 pDcRtInfo->powerState);
3618 closeResponse;
3619
3620 return 0;
3621}
3622
fengluf7408292015-04-14 14:53:55 -07003623static int responseLceStatus(Parcel &p, void *response, size_t responselen) {
3624 if (response == NULL || responselen != sizeof(RIL_LceStatusInfo)) {
3625 if (response == NULL) {
3626 RLOGE("invalid response: NULL");
3627 }
3628 else {
3629 RLOGE("responseLceStatus: invalid response length %d expecting len: d%",
3630 sizeof(RIL_LceStatusInfo), responselen);
3631 }
3632 return RIL_ERRNO_INVALID_RESPONSE;
3633 }
3634
3635 RIL_LceStatusInfo *p_cur = (RIL_LceStatusInfo *)response;
3636 p.write((void *)p_cur, 1); // p_cur->lce_status takes one byte.
3637 p.writeInt32(p_cur->actual_interval_ms);
3638
3639 startResponse;
3640 appendPrintBuf("LCE Status: %d, actual_interval_ms: %d",
3641 p_cur->lce_status, p_cur->actual_interval_ms);
3642 closeResponse;
3643
3644 return 0;
3645}
3646
3647static int responseLceData(Parcel &p, void *response, size_t responselen) {
3648 if (response == NULL || responselen != sizeof(RIL_LceDataInfo)) {
3649 if (response == NULL) {
3650 RLOGE("invalid response: NULL");
3651 }
3652 else {
3653 RLOGE("responseLceData: invalid response length %d expecting len: d%",
3654 sizeof(RIL_LceDataInfo), responselen);
3655 }
3656 return RIL_ERRNO_INVALID_RESPONSE;
3657 }
3658
3659 RIL_LceDataInfo *p_cur = (RIL_LceDataInfo *)response;
3660 p.writeInt32(p_cur->last_hop_capacity_kbps);
3661
3662 /* p_cur->confidence_level and p_cur->lce_suspended take 1 byte each.*/
3663 p.write((void *)&(p_cur->confidence_level), 1);
3664 p.write((void *)&(p_cur->lce_suspended), 1);
3665
3666 startResponse;
3667 appendPrintBuf("LCE info received: capacity %d confidence level %d
3668 and suspended %d",
3669 p_cur->last_hop_capacity_kbps, p_cur->confidence_level,
3670 p_cur->lce_suspended);
3671 closeResponse;
3672
3673 return 0;
3674}
3675
Prerepa Viswanadham73157492015-05-28 00:37:32 -07003676static int responseActivityData(Parcel &p, void *response, size_t responselen) {
3677 if (response == NULL || responselen != sizeof(RIL_ActivityStatsInfo)) {
3678 if (response == NULL) {
3679 RLOGE("invalid response: NULL");
3680 }
3681 else {
3682 RLOGE("responseActivityData: invalid response length %d expecting len: d%",
3683 sizeof(RIL_ActivityStatsInfo), responselen);
3684 }
3685 return RIL_ERRNO_INVALID_RESPONSE;
3686 }
3687
3688 RIL_ActivityStatsInfo *p_cur = (RIL_ActivityStatsInfo *)response;
3689 p.writeInt32(p_cur->sleep_mode_time_ms);
3690 p.writeInt32(p_cur->idle_mode_time_ms);
3691 for(int i = 0; i < RIL_NUM_TX_POWER_LEVELS; i++) {
3692 p.writeInt32(p_cur->tx_mode_time_ms[i]);
3693 }
3694 p.writeInt32(p_cur->rx_mode_time_ms);
3695
3696 startResponse;
3697 appendPrintBuf("Modem activity info received: sleep_mode_time_ms %d idle_mode_time_ms %d
3698 tx_mode_time_ms %d %d %d %d %d and rx_mode_time_ms %d",
3699 p_cur->sleep_mode_time_ms, p_cur->idle_mode_time_ms, p_cur->tx_mode_time_ms[0],
3700 p_cur->tx_mode_time_ms[1], p_cur->tx_mode_time_ms[2], p_cur->tx_mode_time_ms[3],
3701 p_cur->tx_mode_time_ms[4], p_cur->rx_mode_time_ms);
3702 closeResponse;
3703
3704 return 0;
3705}
3706
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003707/**
3708 * A write on the wakeup fd is done just to pop us out of select()
3709 * We empty the buffer here and then ril_event will reset the timers on the
3710 * way back down
3711 */
Wink Savillef4c4d362009-04-02 01:37:03 -07003712static void processWakeupCallback(int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003713 char buff[16];
3714 int ret;
3715
Wink Saville8eb2a122012-11-19 16:05:13 -08003716 RLOGV("processWakeupCallback");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003717
3718 /* empty our wakeup socket out */
3719 do {
3720 ret = read(s_fdWakeupRead, &buff, sizeof(buff));
Wink Saville7f856802009-06-09 10:23:37 -07003721 } while (ret > 0 || (ret < 0 && errno == EINTR));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003722}
3723
Etan Cohend3652192014-06-20 08:28:44 -07003724static void onCommandsSocketClosed(RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003725 int ret;
3726 RequestInfo *p_cur;
Etan Cohend3652192014-06-20 08:28:44 -07003727 /* Hook for current context
3728 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
3729 pthread_mutex_t * pendingRequestsMutexHook = &s_pendingRequestsMutex;
3730 /* pendingRequestsHook refer to &s_pendingRequests */
3731 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003732
Etan Cohend3652192014-06-20 08:28:44 -07003733#if (SIM_COUNT >= 2)
3734 if (socket_id == RIL_SOCKET_2) {
3735 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
3736 pendingRequestsHook = &s_pendingRequests_socket2;
3737 }
3738#if (SIM_COUNT >= 3)
3739 else if (socket_id == RIL_SOCKET_3) {
3740 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
3741 pendingRequestsHook = &s_pendingRequests_socket3;
3742 }
3743#endif
3744#if (SIM_COUNT >= 4)
3745 else if (socket_id == RIL_SOCKET_4) {
3746 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
3747 pendingRequestsHook = &s_pendingRequests_socket4;
3748 }
3749#endif
3750#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003751 /* mark pending requests as "cancelled" so we dont report responses */
Etan Cohend3652192014-06-20 08:28:44 -07003752 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003753 assert (ret == 0);
3754
Etan Cohend3652192014-06-20 08:28:44 -07003755 p_cur = *pendingRequestsHook;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003756
Etan Cohend3652192014-06-20 08:28:44 -07003757 for (p_cur = *pendingRequestsHook
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003758 ; p_cur != NULL
3759 ; p_cur = p_cur->p_next
3760 ) {
3761 p_cur->cancelled = 1;
3762 }
3763
Etan Cohend3652192014-06-20 08:28:44 -07003764 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003765 assert (ret == 0);
3766}
3767
Wink Savillef4c4d362009-04-02 01:37:03 -07003768static void processCommandsCallback(int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003769 RecordStream *p_rs;
3770 void *p_record;
3771 size_t recordlen;
3772 int ret;
Etan Cohend3652192014-06-20 08:28:44 -07003773 SocketListenParam *p_info = (SocketListenParam *)param;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003774
Etan Cohend3652192014-06-20 08:28:44 -07003775 assert(fd == p_info->fdCommand);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003776
Etan Cohend3652192014-06-20 08:28:44 -07003777 p_rs = p_info->p_rs;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003778
3779 for (;;) {
3780 /* loop until EAGAIN/EINTR, end of stream, or other error */
3781 ret = record_stream_get_next(p_rs, &p_record, &recordlen);
3782
3783 if (ret == 0 && p_record == NULL) {
3784 /* end-of-stream */
3785 break;
3786 } else if (ret < 0) {
3787 break;
3788 } else if (ret == 0) { /* && p_record != NULL */
Etan Cohend3652192014-06-20 08:28:44 -07003789 processCommandBuffer(p_record, recordlen, p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003790 }
3791 }
3792
3793 if (ret == 0 || !(errno == EAGAIN || errno == EINTR)) {
3794 /* fatal error or end-of-stream */
3795 if (ret != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003796 RLOGE("error on reading command socket errno:%d\n", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003797 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003798 RLOGW("EOS. Closing command socket.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003799 }
Wink Saville7f856802009-06-09 10:23:37 -07003800
Etan Cohend3652192014-06-20 08:28:44 -07003801 close(fd);
3802 p_info->fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003803
Etan Cohend3652192014-06-20 08:28:44 -07003804 ril_event_del(p_info->commands_event);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003805
3806 record_stream_free(p_rs);
3807
3808 /* start listening for new connections again */
3809 rilEventAddWakeup(&s_listen_event);
3810
Etan Cohend3652192014-06-20 08:28:44 -07003811 onCommandsSocketClosed(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003812 }
3813}
3814
3815
Etan Cohend3652192014-06-20 08:28:44 -07003816static void onNewCommandConnect(RIL_SOCKET_ID socket_id) {
Wink Saville5b9df332011-04-06 16:24:21 -07003817 // Inform we are connected and the ril version
Jake Hambya9c18d12011-04-12 23:32:08 -07003818 int rilVer = s_callbacks.version;
Etan Cohend3652192014-06-20 08:28:44 -07003819 RIL_UNSOL_RESPONSE(RIL_UNSOL_RIL_CONNECTED,
3820 &rilVer, sizeof(rilVer), socket_id);
Wink Saville5b9df332011-04-06 16:24:21 -07003821
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003822 // implicit radio state changed
Etan Cohend3652192014-06-20 08:28:44 -07003823 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
3824 NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003825
3826 // Send last NITZ time data, in case it was missed
3827 if (s_lastNITZTimeData != NULL) {
Etan Cohend3652192014-06-20 08:28:44 -07003828 sendResponseRaw(s_lastNITZTimeData, s_lastNITZTimeDataSize, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003829
3830 free(s_lastNITZTimeData);
3831 s_lastNITZTimeData = NULL;
3832 }
3833
3834 // Get version string
3835 if (s_callbacks.getVersion != NULL) {
3836 const char *version;
3837 version = s_callbacks.getVersion();
Wink Saville8eb2a122012-11-19 16:05:13 -08003838 RLOGI("RIL Daemon version: %s\n", version);
Wink Saville7f856802009-06-09 10:23:37 -07003839
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003840 property_set(PROPERTY_RIL_IMPL, version);
3841 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003842 RLOGI("RIL Daemon version: unavailable\n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003843 property_set(PROPERTY_RIL_IMPL, "unavailable");
3844 }
3845
3846}
3847
Wink Savillef4c4d362009-04-02 01:37:03 -07003848static void listenCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003849 int ret;
3850 int err;
3851 int is_phone_socket;
Etan Cohend3652192014-06-20 08:28:44 -07003852 int fdCommand = -1;
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003853 char* processName;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003854 RecordStream *p_rs;
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003855 MySocketListenParam* listenParam;
3856 RilSocket *sapSocket = NULL;
3857 socketClient *sClient = NULL;
3858
Etan Cohend3652192014-06-20 08:28:44 -07003859 SocketListenParam *p_info = (SocketListenParam *)param;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003860
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003861 if(RIL_SAP_SOCKET == p_info->type) {
3862 listenParam = (MySocketListenParam *)param;
3863 sapSocket = listenParam->socket;
3864 }
3865
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003866 struct sockaddr_un peeraddr;
3867 socklen_t socklen = sizeof (peeraddr);
3868
3869 struct ucred creds;
3870 socklen_t szCreds = sizeof(creds);
3871
3872 struct passwd *pwd = NULL;
3873
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003874 if(NULL == sapSocket) {
3875 assert (*p_info->fdCommand < 0);
3876 assert (fd == *p_info->fdListen);
3877 processName = PHONE_PROCESS;
3878 } else {
3879 assert (sapSocket->commandFd < 0);
3880 assert (fd == sapSocket->listenFd);
3881 processName = BLUETOOTH_PROCESS;
3882 }
3883
Wink Saville7f856802009-06-09 10:23:37 -07003884
Etan Cohend3652192014-06-20 08:28:44 -07003885 fdCommand = accept(fd, (sockaddr *) &peeraddr, &socklen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003886
Etan Cohend3652192014-06-20 08:28:44 -07003887 if (fdCommand < 0 ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003888 RLOGE("Error on accept() errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003889 /* start listening for new connections again */
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003890 if(NULL == sapSocket) {
3891 rilEventAddWakeup(p_info->listen_event);
3892 } else {
3893 rilEventAddWakeup(sapSocket->getListenEvent());
3894 }
Etan Cohend3652192014-06-20 08:28:44 -07003895 return;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003896 }
3897
3898 /* check the credential of the other side and only accept socket from
3899 * phone process
Wink Saville7f856802009-06-09 10:23:37 -07003900 */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003901 errno = 0;
3902 is_phone_socket = 0;
Wink Savillef4c4d362009-04-02 01:37:03 -07003903
Etan Cohend3652192014-06-20 08:28:44 -07003904 err = getsockopt(fdCommand, SOL_SOCKET, SO_PEERCRED, &creds, &szCreds);
Wink Savillef4c4d362009-04-02 01:37:03 -07003905
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003906 if (err == 0 && szCreds > 0) {
Wink Savillef4c4d362009-04-02 01:37:03 -07003907 errno = 0;
3908 pwd = getpwuid(creds.uid);
3909 if (pwd != NULL) {
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003910 if (strcmp(pwd->pw_name, processName) == 0) {
Wink Savillef4c4d362009-04-02 01:37:03 -07003911 is_phone_socket = 1;
3912 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003913 RLOGE("RILD can't accept socket from process %s", pwd->pw_name);
Wink Savillef4c4d362009-04-02 01:37:03 -07003914 }
3915 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003916 RLOGE("Error on getpwuid() errno: %d", errno);
Wink Savillef4c4d362009-04-02 01:37:03 -07003917 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003918 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003919 RLOGD("Error on getsockopt() errno: %d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003920 }
3921
Etan Cohend3652192014-06-20 08:28:44 -07003922 if (!is_phone_socket) {
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003923 RLOGE("RILD must accept socket from %s", processName);
Wink Saville7f856802009-06-09 10:23:37 -07003924
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003925 close(fdCommand);
3926 fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003927
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003928 if(NULL == sapSocket) {
3929 onCommandsSocketClosed(p_info->socket_id);
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(p_info->listen_event);
3933 } else {
3934 sapSocket->onCommandsSocketClosed();
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003935
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003936 /* start listening for new connections again */
3937 rilEventAddWakeup(sapSocket->getListenEvent());
3938 }
3939
3940 return;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003941 }
3942
Etan Cohend3652192014-06-20 08:28:44 -07003943 ret = fcntl(fdCommand, F_SETFL, O_NONBLOCK);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003944
3945 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003946 RLOGE ("Error setting O_NONBLOCK errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003947 }
3948
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003949 if(NULL == sapSocket) {
3950 RLOGI("libril: new connection to %s", rilSocketIdToString(p_info->socket_id));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003951
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003952 p_info->fdCommand = fdCommand;
3953 p_rs = record_stream_new(p_info->fdCommand, MAX_COMMAND_BYTES);
3954 p_info->p_rs = p_rs;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003955
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003956 ril_event_set (p_info->commands_event, p_info->fdCommand, 1,
Etan Cohend3652192014-06-20 08:28:44 -07003957 p_info->processCommandsCallback, p_info);
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003958 rilEventAddWakeup (p_info->commands_event);
Etan Cohend3652192014-06-20 08:28:44 -07003959
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003960 onNewCommandConnect(p_info->socket_id);
3961 } else {
3962 RLOGI("libril: new connection");
Etan Cohend3652192014-06-20 08:28:44 -07003963
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003964 sapSocket->setCommandFd(fdCommand);
3965 p_rs = record_stream_new(sapSocket->getCommandFd(), MAX_COMMAND_BYTES);
3966 sClient = new socketClient(sapSocket,p_rs);
3967 ril_event_set (sapSocket->getCallbackEvent(), sapSocket->getCommandFd(), 1,
3968 sapSocket->getCommandCb(), sClient);
3969
3970 rilEventAddWakeup(sapSocket->getCallbackEvent());
3971 sapSocket->onNewCommandConnect();
3972 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003973}
3974
3975static void freeDebugCallbackArgs(int number, char **args) {
3976 for (int i = 0; i < number; i++) {
3977 if (args[i] != NULL) {
3978 free(args[i]);
3979 }
3980 }
3981 free(args);
3982}
3983
Wink Savillef4c4d362009-04-02 01:37:03 -07003984static void debugCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003985 int acceptFD, option;
3986 struct sockaddr_un peeraddr;
3987 socklen_t socklen = sizeof (peeraddr);
3988 int data;
3989 unsigned int qxdm_data[6];
3990 const char *deactData[1] = {"1"};
3991 char *actData[1];
3992 RIL_Dial dialData;
3993 int hangupData[1] = {1};
3994 int number;
3995 char **args;
Etan Cohend3652192014-06-20 08:28:44 -07003996 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
3997 int sim_id = 0;
3998
3999 RLOGI("debugCallback for socket %s", rilSocketIdToString(socket_id));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004000
4001 acceptFD = accept (fd, (sockaddr *) &peeraddr, &socklen);
4002
4003 if (acceptFD < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004004 RLOGE ("error accepting on debug port: %d\n", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004005 return;
4006 }
4007
4008 if (recv(acceptFD, &number, sizeof(int), 0) != sizeof(int)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004009 RLOGE ("error reading on socket: number of Args: \n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004010 return;
4011 }
4012 args = (char **) malloc(sizeof(char*) * number);
4013
4014 for (int i = 0; i < number; i++) {
4015 int len;
4016 if (recv(acceptFD, &len, sizeof(int), 0) != sizeof(int)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004017 RLOGE ("error reading on socket: Len of Args: \n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004018 freeDebugCallbackArgs(i, args);
4019 return;
4020 }
4021 // +1 for null-term
4022 args[i] = (char *) malloc((sizeof(char) * len) + 1);
Wink Saville7f856802009-06-09 10:23:37 -07004023 if (recv(acceptFD, args[i], sizeof(char) * len, 0)
Wink Saville1b5fd232009-04-22 14:50:00 -07004024 != (int)sizeof(char) * len) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004025 RLOGE ("error reading on socket: Args[%d] \n", i);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004026 freeDebugCallbackArgs(i, args);
4027 return;
4028 }
4029 char * buf = args[i];
4030 buf[len] = 0;
Etan Cohend3652192014-06-20 08:28:44 -07004031 if ((i+1) == number) {
4032 /* The last argument should be sim id 0(SIM1)~3(SIM4) */
4033 sim_id = atoi(args[i]);
4034 switch (sim_id) {
4035 case 0:
4036 socket_id = RIL_SOCKET_1;
4037 break;
4038 #if (SIM_COUNT >= 2)
4039 case 1:
4040 socket_id = RIL_SOCKET_2;
4041 break;
4042 #endif
4043 #if (SIM_COUNT >= 3)
4044 case 2:
4045 socket_id = RIL_SOCKET_3;
4046 break;
4047 #endif
4048 #if (SIM_COUNT >= 4)
4049 case 3:
4050 socket_id = RIL_SOCKET_4;
4051 break;
4052 #endif
4053 default:
4054 socket_id = RIL_SOCKET_1;
4055 break;
4056 }
4057 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004058 }
4059
4060 switch (atoi(args[0])) {
4061 case 0:
Wink Saville8eb2a122012-11-19 16:05:13 -08004062 RLOGI ("Connection on debug port: issuing reset.");
Etan Cohend3652192014-06-20 08:28:44 -07004063 issueLocalRequest(RIL_REQUEST_RESET_RADIO, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004064 break;
4065 case 1:
Wink Saville8eb2a122012-11-19 16:05:13 -08004066 RLOGI ("Connection on debug port: issuing radio power off.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004067 data = 0;
Etan Cohend3652192014-06-20 08:28:44 -07004068 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004069 // Close the socket
Etan Cohend3652192014-06-20 08:28:44 -07004070 if (socket_id == RIL_SOCKET_1 && s_ril_param_socket.fdCommand > 0) {
4071 close(s_ril_param_socket.fdCommand);
4072 s_ril_param_socket.fdCommand = -1;
4073 }
4074 #if (SIM_COUNT == 2)
4075 else if (socket_id == RIL_SOCKET_2 && s_ril_param_socket2.fdCommand > 0) {
4076 close(s_ril_param_socket2.fdCommand);
4077 s_ril_param_socket2.fdCommand = -1;
4078 }
4079 #endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004080 break;
4081 case 2:
Wink Saville8eb2a122012-11-19 16:05:13 -08004082 RLOGI ("Debug port: issuing unsolicited voice network change.");
Etan Cohend3652192014-06-20 08:28:44 -07004083 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004084 break;
4085 case 3:
Wink Saville8eb2a122012-11-19 16:05:13 -08004086 RLOGI ("Debug port: QXDM log enable.");
Xia Wangd855ef42010-07-27 17:26:55 -07004087 qxdm_data[0] = 65536; // head.func_tag
4088 qxdm_data[1] = 16; // head.len
4089 qxdm_data[2] = 1; // mode: 1 for 'start logging'
4090 qxdm_data[3] = 32; // log_file_size: 32megabytes
4091 qxdm_data[4] = 0; // log_mask
4092 qxdm_data[5] = 8; // log_max_fileindex
Wink Saville7f856802009-06-09 10:23:37 -07004093 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Etan Cohend3652192014-06-20 08:28:44 -07004094 6 * sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004095 break;
4096 case 4:
Wink Saville8eb2a122012-11-19 16:05:13 -08004097 RLOGI ("Debug port: QXDM log disable.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004098 qxdm_data[0] = 65536;
4099 qxdm_data[1] = 16;
Xia Wangd855ef42010-07-27 17:26:55 -07004100 qxdm_data[2] = 0; // mode: 0 for 'stop logging'
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004101 qxdm_data[3] = 32;
4102 qxdm_data[4] = 0;
Xia Wangd855ef42010-07-27 17:26:55 -07004103 qxdm_data[5] = 8;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004104 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Etan Cohend3652192014-06-20 08:28:44 -07004105 6 * sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004106 break;
4107 case 5:
Wink Saville8eb2a122012-11-19 16:05:13 -08004108 RLOGI("Debug port: Radio On");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004109 data = 1;
Etan Cohend3652192014-06-20 08:28:44 -07004110 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004111 sleep(2);
4112 // Set network selection automatic.
Etan Cohend3652192014-06-20 08:28:44 -07004113 issueLocalRequest(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004114 break;
4115 case 6:
Wink Saville8eb2a122012-11-19 16:05:13 -08004116 RLOGI("Debug port: Setup Data Call, Apn :%s\n", args[1]);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004117 actData[0] = args[1];
Wink Saville7f856802009-06-09 10:23:37 -07004118 issueLocalRequest(RIL_REQUEST_SETUP_DATA_CALL, &actData,
Etan Cohend3652192014-06-20 08:28:44 -07004119 sizeof(actData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004120 break;
4121 case 7:
Wink Saville8eb2a122012-11-19 16:05:13 -08004122 RLOGI("Debug port: Deactivate Data Call");
Wink Saville7f856802009-06-09 10:23:37 -07004123 issueLocalRequest(RIL_REQUEST_DEACTIVATE_DATA_CALL, &deactData,
Etan Cohend3652192014-06-20 08:28:44 -07004124 sizeof(deactData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004125 break;
4126 case 8:
Wink Saville8eb2a122012-11-19 16:05:13 -08004127 RLOGI("Debug port: Dial Call");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004128 dialData.clir = 0;
4129 dialData.address = args[1];
Etan Cohend3652192014-06-20 08:28:44 -07004130 issueLocalRequest(RIL_REQUEST_DIAL, &dialData, sizeof(dialData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004131 break;
4132 case 9:
Wink Saville8eb2a122012-11-19 16:05:13 -08004133 RLOGI("Debug port: Answer Call");
Etan Cohend3652192014-06-20 08:28:44 -07004134 issueLocalRequest(RIL_REQUEST_ANSWER, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004135 break;
4136 case 10:
Wink Saville8eb2a122012-11-19 16:05:13 -08004137 RLOGI("Debug port: End Call");
Wink Saville7f856802009-06-09 10:23:37 -07004138 issueLocalRequest(RIL_REQUEST_HANGUP, &hangupData,
Etan Cohend3652192014-06-20 08:28:44 -07004139 sizeof(hangupData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004140 break;
4141 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004142 RLOGE ("Invalid request");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004143 break;
4144 }
4145 freeDebugCallbackArgs(number, args);
4146 close(acceptFD);
4147}
4148
4149
Wink Savillef4c4d362009-04-02 01:37:03 -07004150static void userTimerCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004151 UserCallbackInfo *p_info;
4152
4153 p_info = (UserCallbackInfo *)param;
4154
4155 p_info->p_callback(p_info->userParam);
4156
4157
4158 // FIXME generalize this...there should be a cancel mechanism
4159 if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) {
4160 s_last_wake_timeout_info = NULL;
4161 }
4162
4163 free(p_info);
4164}
4165
4166
4167static void *
Wink Savillef4c4d362009-04-02 01:37:03 -07004168eventLoop(void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004169 int ret;
4170 int filedes[2];
4171
4172 ril_event_init();
4173
4174 pthread_mutex_lock(&s_startupMutex);
4175
4176 s_started = 1;
4177 pthread_cond_broadcast(&s_startupCond);
4178
4179 pthread_mutex_unlock(&s_startupMutex);
4180
4181 ret = pipe(filedes);
4182
4183 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004184 RLOGE("Error in pipe() errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004185 return NULL;
4186 }
4187
4188 s_fdWakeupRead = filedes[0];
4189 s_fdWakeupWrite = filedes[1];
4190
4191 fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK);
4192
4193 ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,
4194 processWakeupCallback, NULL);
4195
4196 rilEventAddWakeup (&s_wakeupfd_event);
4197
4198 // Only returns on error
4199 ril_event_loop();
Wink Saville8eb2a122012-11-19 16:05:13 -08004200 RLOGE ("error in event_loop_base errno:%d", errno);
Kazuhiro Ondo5cdc1352011-10-14 17:50:58 -05004201 // kill self to restart on error
4202 kill(0, SIGKILL);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004203
4204 return NULL;
4205}
4206
Wink Saville7f856802009-06-09 10:23:37 -07004207extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07004208RIL_startEventLoop(void) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004209 /* spin up eventLoop thread and wait for it to get started */
4210 s_started = 0;
4211 pthread_mutex_lock(&s_startupMutex);
4212
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004213 pthread_attr_t attr;
4214 pthread_attr_init(&attr);
Wink Saville7f856802009-06-09 10:23:37 -07004215 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004216
Elliott Hughesfd81e712014-01-06 12:46:02 -08004217 int result = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
4218 if (result != 0) {
4219 RLOGE("Failed to create dispatch thread: %s", strerror(result));
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004220 goto done;
4221 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004222
4223 while (s_started == 0) {
4224 pthread_cond_wait(&s_startupCond, &s_startupMutex);
4225 }
4226
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004227done:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004228 pthread_mutex_unlock(&s_startupMutex);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004229}
4230
4231// Used for testing purpose only.
4232extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) {
4233 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4234}
4235
Etan Cohend3652192014-06-20 08:28:44 -07004236static void startListen(RIL_SOCKET_ID socket_id, SocketListenParam* socket_listen_p) {
4237 int fdListen = -1;
4238 int ret;
4239 char socket_name[10];
4240
4241 memset(socket_name, 0, sizeof(char)*10);
4242
4243 switch(socket_id) {
4244 case RIL_SOCKET_1:
4245 strncpy(socket_name, RIL_getRilSocketName(), 9);
4246 break;
4247 #if (SIM_COUNT >= 2)
4248 case RIL_SOCKET_2:
4249 strncpy(socket_name, SOCKET2_NAME_RIL, 9);
4250 break;
4251 #endif
4252 #if (SIM_COUNT >= 3)
4253 case RIL_SOCKET_3:
4254 strncpy(socket_name, SOCKET3_NAME_RIL, 9);
4255 break;
4256 #endif
4257 #if (SIM_COUNT >= 4)
4258 case RIL_SOCKET_4:
4259 strncpy(socket_name, SOCKET4_NAME_RIL, 9);
4260 break;
4261 #endif
4262 default:
4263 RLOGE("Socket id is wrong!!");
4264 return;
4265 }
4266
4267 RLOGI("Start to listen %s", rilSocketIdToString(socket_id));
4268
4269 fdListen = android_get_control_socket(socket_name);
4270 if (fdListen < 0) {
4271 RLOGE("Failed to get socket %s", socket_name);
4272 exit(-1);
4273 }
4274
4275 ret = listen(fdListen, 4);
4276
4277 if (ret < 0) {
4278 RLOGE("Failed to listen on control socket '%d': %s",
4279 fdListen, strerror(errno));
4280 exit(-1);
4281 }
4282 socket_listen_p->fdListen = fdListen;
4283
4284 /* note: non-persistent so we can accept only one connection at a time */
4285 ril_event_set (socket_listen_p->listen_event, fdListen, false,
4286 listenCallback, socket_listen_p);
4287
4288 rilEventAddWakeup (socket_listen_p->listen_event);
4289}
4290
Wink Saville7f856802009-06-09 10:23:37 -07004291extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07004292RIL_register (const RIL_RadioFunctions *callbacks) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004293 int ret;
4294 int flags;
4295
Etan Cohend3652192014-06-20 08:28:44 -07004296 RLOGI("SIM_COUNT: %d", SIM_COUNT);
4297
Wink Saville43808972011-01-13 17:39:51 -08004298 if (callbacks == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004299 RLOGE("RIL_register: RIL_RadioFunctions * null");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004300 return;
4301 }
Wink Saville43808972011-01-13 17:39:51 -08004302 if (callbacks->version < RIL_VERSION_MIN) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004303 RLOGE("RIL_register: version %d is to old, min version is %d",
Wink Saville43808972011-01-13 17:39:51 -08004304 callbacks->version, RIL_VERSION_MIN);
4305 return;
Wink Saville3a4840b2010-04-07 13:29:58 -07004306 }
Wink Saville43808972011-01-13 17:39:51 -08004307 if (callbacks->version > RIL_VERSION) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004308 RLOGE("RIL_register: version %d is too new, max version is %d",
Wink Saville43808972011-01-13 17:39:51 -08004309 callbacks->version, RIL_VERSION);
4310 return;
4311 }
Wink Saville8eb2a122012-11-19 16:05:13 -08004312 RLOGE("RIL_register: RIL version %d", callbacks->version);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004313
4314 if (s_registerCalled > 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004315 RLOGE("RIL_register has been called more than once. "
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004316 "Subsequent call ignored");
4317 return;
4318 }
4319
4320 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4321
Etan Cohend3652192014-06-20 08:28:44 -07004322 /* Initialize socket1 parameters */
4323 s_ril_param_socket = {
4324 RIL_SOCKET_1, /* socket_id */
4325 -1, /* fdListen */
4326 -1, /* fdCommand */
4327 PHONE_PROCESS, /* processName */
4328 &s_commands_event, /* commands_event */
4329 &s_listen_event, /* listen_event */
4330 processCommandsCallback, /* processCommandsCallback */
4331 NULL /* p_rs */
4332 };
4333
4334#if (SIM_COUNT >= 2)
4335 s_ril_param_socket2 = {
4336 RIL_SOCKET_2, /* socket_id */
4337 -1, /* fdListen */
4338 -1, /* fdCommand */
4339 PHONE_PROCESS, /* processName */
4340 &s_commands_event_socket2, /* commands_event */
4341 &s_listen_event_socket2, /* listen_event */
4342 processCommandsCallback, /* processCommandsCallback */
4343 NULL /* p_rs */
4344 };
4345#endif
4346
4347#if (SIM_COUNT >= 3)
4348 s_ril_param_socket3 = {
4349 RIL_SOCKET_3, /* socket_id */
4350 -1, /* fdListen */
4351 -1, /* fdCommand */
4352 PHONE_PROCESS, /* processName */
4353 &s_commands_event_socket3, /* commands_event */
4354 &s_listen_event_socket3, /* listen_event */
4355 processCommandsCallback, /* processCommandsCallback */
4356 NULL /* p_rs */
4357 };
4358#endif
4359
4360#if (SIM_COUNT >= 4)
4361 s_ril_param_socket4 = {
4362 RIL_SOCKET_4, /* socket_id */
4363 -1, /* fdListen */
4364 -1, /* fdCommand */
4365 PHONE_PROCESS, /* processName */
4366 &s_commands_event_socket4, /* commands_event */
4367 &s_listen_event_socket4, /* listen_event */
4368 processCommandsCallback, /* processCommandsCallback */
4369 NULL /* p_rs */
4370 };
4371#endif
4372
4373
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004374 s_registerCalled = 1;
4375
Etan Cohend3652192014-06-20 08:28:44 -07004376 RLOGI("s_registerCalled flag set, %d", s_started);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004377 // Little self-check
4378
Wink Savillef4c4d362009-04-02 01:37:03 -07004379 for (int i = 0; i < (int)NUM_ELEMS(s_commands); i++) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004380 assert(i == s_commands[i].requestNumber);
4381 }
4382
Wink Savillef4c4d362009-04-02 01:37:03 -07004383 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses); i++) {
Wink Saville7f856802009-06-09 10:23:37 -07004384 assert(i + RIL_UNSOL_RESPONSE_BASE
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004385 == s_unsolResponses[i].requestNumber);
4386 }
4387
4388 // New rild impl calls RIL_startEventLoop() first
4389 // old standalone impl wants it here.
4390
4391 if (s_started == 0) {
4392 RIL_startEventLoop();
4393 }
4394
Etan Cohend3652192014-06-20 08:28:44 -07004395 // start listen socket1
4396 startListen(RIL_SOCKET_1, &s_ril_param_socket);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004397
Etan Cohend3652192014-06-20 08:28:44 -07004398#if (SIM_COUNT >= 2)
4399 // start listen socket2
4400 startListen(RIL_SOCKET_2, &s_ril_param_socket2);
4401#endif /* (SIM_COUNT == 2) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004402
Etan Cohend3652192014-06-20 08:28:44 -07004403#if (SIM_COUNT >= 3)
4404 // start listen socket3
4405 startListen(RIL_SOCKET_3, &s_ril_param_socket3);
4406#endif /* (SIM_COUNT == 3) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004407
Etan Cohend3652192014-06-20 08:28:44 -07004408#if (SIM_COUNT >= 4)
4409 // start listen socket4
4410 startListen(RIL_SOCKET_4, &s_ril_param_socket4);
4411#endif /* (SIM_COUNT == 4) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004412
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004413
4414#if 1
4415 // start debug interface socket
4416
Etan Cohend3652192014-06-20 08:28:44 -07004417 char *inst = NULL;
4418 if (strlen(RIL_getRilSocketName()) >= strlen(SOCKET_NAME_RIL)) {
4419 inst = RIL_getRilSocketName() + strlen(SOCKET_NAME_RIL);
4420 }
4421
4422 char rildebug[MAX_DEBUG_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL_DEBUG;
4423 if (inst != NULL) {
Nick Kralevichc52e45e2015-02-08 07:54:16 -08004424 strlcat(rildebug, inst, MAX_DEBUG_SOCKET_NAME_LENGTH);
Etan Cohend3652192014-06-20 08:28:44 -07004425 }
4426
4427 s_fdDebug = android_get_control_socket(rildebug);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004428 if (s_fdDebug < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07004429 RLOGE("Failed to get socket : %s errno:%d", rildebug, errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004430 exit(-1);
4431 }
4432
4433 ret = listen(s_fdDebug, 4);
4434
4435 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004436 RLOGE("Failed to listen on ril debug socket '%d': %s",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004437 s_fdDebug, strerror(errno));
4438 exit(-1);
4439 }
4440
4441 ril_event_set (&s_debug_event, s_fdDebug, true,
4442 debugCallback, NULL);
4443
4444 rilEventAddWakeup (&s_debug_event);
4445#endif
4446
4447}
4448
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004449extern "C" void
4450RIL_register_socket (RIL_RadioFunctions *(*Init)(const struct RIL_Env *, int, char **),RIL_SOCKET_TYPE socketType, int argc, char **argv) {
4451
4452 RIL_RadioFunctions* UimFuncs = NULL;
4453
4454 if(Init) {
4455 UimFuncs = Init(&RilSapSocket::uimRilEnv, argc, argv);
4456
4457 switch(socketType) {
4458 case RIL_SAP_SOCKET:
4459 RilSapSocket::initSapSocket("sap_uim_socket1", UimFuncs);
4460
4461#if (SIM_COUNT >= 2)
4462 RilSapSocket::initSapSocket("sap_uim_socket2", UimFuncs);
4463#endif
4464
4465#if (SIM_COUNT >= 3)
4466 RilSapSocket::initSapSocket("sap_uim_socket3", UimFuncs);
4467#endif
4468
4469#if (SIM_COUNT >= 4)
4470 RilSapSocket::initSapSocket("sap_uim_socket4", UimFuncs);
4471#endif
4472 }
4473 }
4474}
4475
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004476static int
Wink Savillef4c4d362009-04-02 01:37:03 -07004477checkAndDequeueRequestInfo(struct RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004478 int ret = 0;
Etan Cohend3652192014-06-20 08:28:44 -07004479 /* Hook for current context
4480 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
4481 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
4482 /* pendingRequestsHook refer to &s_pendingRequests */
4483 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
Wink Saville7f856802009-06-09 10:23:37 -07004484
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004485 if (pRI == NULL) {
4486 return 0;
4487 }
4488
Etan Cohend3652192014-06-20 08:28:44 -07004489#if (SIM_COUNT >= 2)
4490 if (pRI->socket_id == RIL_SOCKET_2) {
4491 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
4492 pendingRequestsHook = &s_pendingRequests_socket2;
4493 }
4494#if (SIM_COUNT >= 3)
4495 if (pRI->socket_id == RIL_SOCKET_3) {
4496 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
4497 pendingRequestsHook = &s_pendingRequests_socket3;
4498 }
4499#endif
4500#if (SIM_COUNT >= 4)
4501 if (pRI->socket_id == RIL_SOCKET_4) {
4502 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
4503 pendingRequestsHook = &s_pendingRequests_socket4;
4504 }
4505#endif
4506#endif
4507 pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004508
Etan Cohend3652192014-06-20 08:28:44 -07004509 for(RequestInfo **ppCur = pendingRequestsHook
Wink Saville7f856802009-06-09 10:23:37 -07004510 ; *ppCur != NULL
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004511 ; ppCur = &((*ppCur)->p_next)
4512 ) {
4513 if (pRI == *ppCur) {
4514 ret = 1;
4515
4516 *ppCur = (*ppCur)->p_next;
4517 break;
4518 }
4519 }
4520
Etan Cohend3652192014-06-20 08:28:44 -07004521 pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004522
4523 return ret;
4524}
4525
4526
4527extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07004528RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004529 RequestInfo *pRI;
4530 int ret;
Etan Cohend3652192014-06-20 08:28:44 -07004531 int fd = s_ril_param_socket.fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004532 size_t errorOffset;
Etan Cohend3652192014-06-20 08:28:44 -07004533 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004534
4535 pRI = (RequestInfo *)t;
4536
Jayachandran C6c607592014-08-04 15:48:01 -07004537 if (!checkAndDequeueRequestInfo(pRI)) {
4538 RLOGE ("RIL_onRequestComplete: invalid RIL_Token");
4539 return;
4540 }
4541
Etan Cohend3652192014-06-20 08:28:44 -07004542 socket_id = pRI->socket_id;
4543#if (SIM_COUNT >= 2)
4544 if (socket_id == RIL_SOCKET_2) {
4545 fd = s_ril_param_socket2.fdCommand;
4546 }
4547#if (SIM_COUNT >= 3)
4548 if (socket_id == RIL_SOCKET_3) {
4549 fd = s_ril_param_socket3.fdCommand;
4550 }
4551#endif
4552#if (SIM_COUNT >= 4)
4553 if (socket_id == RIL_SOCKET_4) {
4554 fd = s_ril_param_socket4.fdCommand;
4555 }
4556#endif
4557#endif
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07004558#if VDBG
Etan Cohend3652192014-06-20 08:28:44 -07004559 RLOGD("RequestComplete, %s", rilSocketIdToString(socket_id));
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07004560#endif
Etan Cohend3652192014-06-20 08:28:44 -07004561
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004562 if (pRI->local > 0) {
4563 // Locally issued command...void only!
4564 // response does not go back up the command socket
Wink Saville8eb2a122012-11-19 16:05:13 -08004565 RLOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004566
4567 goto done;
4568 }
4569
4570 appendPrintBuf("[%04d]< %s",
4571 pRI->token, requestToString(pRI->pCI->requestNumber));
4572
4573 if (pRI->cancelled == 0) {
4574 Parcel p;
4575
4576 p.writeInt32 (RESPONSE_SOLICITED);
4577 p.writeInt32 (pRI->token);
4578 errorOffset = p.dataPosition();
4579
4580 p.writeInt32 (e);
4581
johnwangb2a61842009-06-02 14:55:45 -07004582 if (response != NULL) {
4583 // there is a response payload, no matter success or not.
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004584 ret = pRI->pCI->responseFunction(p, response, responselen);
4585
4586 /* if an error occurred, rewind and mark it */
4587 if (ret != 0) {
Etan Cohend3652192014-06-20 08:28:44 -07004588 RLOGE ("responseFunction error, ret %d", ret);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004589 p.setDataPosition(errorOffset);
4590 p.writeInt32 (ret);
4591 }
johnwangb2a61842009-06-02 14:55:45 -07004592 }
4593
4594 if (e != RIL_E_SUCCESS) {
4595 appendPrintBuf("%s fails by %s", printBuf, failCauseToString(e));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004596 }
4597
Etan Cohend3652192014-06-20 08:28:44 -07004598 if (fd < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004599 RLOGD ("RIL onRequestComplete: Command channel closed");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004600 }
Etan Cohend3652192014-06-20 08:28:44 -07004601 sendResponse(p, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004602 }
4603
4604done:
4605 free(pRI);
4606}
4607
4608
4609static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004610grabPartialWakeLock() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004611 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
4612}
4613
4614static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004615releaseWakeLock() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004616 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
4617}
4618
4619/**
4620 * Timer callback to put us back to sleep before the default timeout
4621 */
4622static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004623wakeTimeoutCallback (void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004624 // We're using "param != NULL" as a cancellation mechanism
4625 if (param == NULL) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004626 releaseWakeLock();
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004627 }
4628}
4629
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004630static int
4631decodeVoiceRadioTechnology (RIL_RadioState radioState) {
4632 switch (radioState) {
4633 case RADIO_STATE_SIM_NOT_READY:
4634 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4635 case RADIO_STATE_SIM_READY:
4636 return RADIO_TECH_UMTS;
4637
4638 case RADIO_STATE_RUIM_NOT_READY:
4639 case RADIO_STATE_RUIM_READY:
4640 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4641 case RADIO_STATE_NV_NOT_READY:
4642 case RADIO_STATE_NV_READY:
4643 return RADIO_TECH_1xRTT;
4644
4645 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004646 RLOGD("decodeVoiceRadioTechnology: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004647 return -1;
4648 }
4649}
4650
4651static int
4652decodeCdmaSubscriptionSource (RIL_RadioState radioState) {
4653 switch (radioState) {
4654 case RADIO_STATE_SIM_NOT_READY:
4655 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4656 case RADIO_STATE_SIM_READY:
4657 case RADIO_STATE_RUIM_NOT_READY:
4658 case RADIO_STATE_RUIM_READY:
4659 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4660 return CDMA_SUBSCRIPTION_SOURCE_RUIM_SIM;
4661
4662 case RADIO_STATE_NV_NOT_READY:
4663 case RADIO_STATE_NV_READY:
4664 return CDMA_SUBSCRIPTION_SOURCE_NV;
4665
4666 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004667 RLOGD("decodeCdmaSubscriptionSource: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004668 return -1;
4669 }
4670}
4671
4672static int
4673decodeSimStatus (RIL_RadioState radioState) {
4674 switch (radioState) {
4675 case RADIO_STATE_SIM_NOT_READY:
4676 case RADIO_STATE_RUIM_NOT_READY:
4677 case RADIO_STATE_NV_NOT_READY:
4678 case RADIO_STATE_NV_READY:
4679 return -1;
4680 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4681 case RADIO_STATE_SIM_READY:
4682 case RADIO_STATE_RUIM_READY:
4683 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4684 return radioState;
4685 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004686 RLOGD("decodeSimStatus: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004687 return -1;
4688 }
4689}
4690
4691static bool is3gpp2(int radioTech) {
4692 switch (radioTech) {
4693 case RADIO_TECH_IS95A:
4694 case RADIO_TECH_IS95B:
4695 case RADIO_TECH_1xRTT:
4696 case RADIO_TECH_EVDO_0:
4697 case RADIO_TECH_EVDO_A:
4698 case RADIO_TECH_EVDO_B:
4699 case RADIO_TECH_EHRPD:
4700 return true;
4701 default:
4702 return false;
4703 }
4704}
4705
4706/* If RIL sends SIM states or RUIM states, store the voice radio
4707 * technology and subscription source information so that they can be
4708 * returned when telephony framework requests them
4709 */
4710static RIL_RadioState
Etan Cohend3652192014-06-20 08:28:44 -07004711processRadioState(RIL_RadioState newRadioState, RIL_SOCKET_ID socket_id) {
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004712
4713 if((newRadioState > RADIO_STATE_UNAVAILABLE) && (newRadioState < RADIO_STATE_ON)) {
4714 int newVoiceRadioTech;
4715 int newCdmaSubscriptionSource;
4716 int newSimStatus;
4717
4718 /* This is old RIL. Decode Subscription source and Voice Radio Technology
4719 from Radio State and send change notifications if there has been a change */
4720 newVoiceRadioTech = decodeVoiceRadioTechnology(newRadioState);
4721 if(newVoiceRadioTech != voiceRadioTech) {
4722 voiceRadioTech = newVoiceRadioTech;
Etan Cohend3652192014-06-20 08:28:44 -07004723 RIL_UNSOL_RESPONSE(RIL_UNSOL_VOICE_RADIO_TECH_CHANGED,
4724 &voiceRadioTech, sizeof(voiceRadioTech), socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004725 }
4726 if(is3gpp2(newVoiceRadioTech)) {
4727 newCdmaSubscriptionSource = decodeCdmaSubscriptionSource(newRadioState);
4728 if(newCdmaSubscriptionSource != cdmaSubscriptionSource) {
4729 cdmaSubscriptionSource = newCdmaSubscriptionSource;
Etan Cohend3652192014-06-20 08:28:44 -07004730 RIL_UNSOL_RESPONSE(RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED,
4731 &cdmaSubscriptionSource, sizeof(cdmaSubscriptionSource), socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004732 }
4733 }
4734 newSimStatus = decodeSimStatus(newRadioState);
4735 if(newSimStatus != simRuimStatus) {
4736 simRuimStatus = newSimStatus;
Etan Cohend3652192014-06-20 08:28:44 -07004737 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0, socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004738 }
4739
4740 /* Send RADIO_ON to telephony */
4741 newRadioState = RADIO_STATE_ON;
4742 }
4743
4744 return newRadioState;
4745}
4746
Etan Cohend3652192014-06-20 08:28:44 -07004747
4748#if defined(ANDROID_MULTI_SIM)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004749extern "C"
Bernhard Rosenkränzerd613b962014-11-17 20:52:09 +01004750void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Etan Cohend3652192014-06-20 08:28:44 -07004751 size_t datalen, RIL_SOCKET_ID socket_id)
4752#else
4753extern "C"
Bernhard Rosenkränzerd613b962014-11-17 20:52:09 +01004754void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004755 size_t datalen)
Etan Cohend3652192014-06-20 08:28:44 -07004756#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004757{
4758 int unsolResponseIndex;
4759 int ret;
4760 int64_t timeReceived = 0;
4761 bool shouldScheduleTimeout = false;
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004762 RIL_RadioState newState;
Etan Cohend3652192014-06-20 08:28:44 -07004763 RIL_SOCKET_ID soc_id = RIL_SOCKET_1;
4764
4765#if defined(ANDROID_MULTI_SIM)
4766 soc_id = socket_id;
4767#endif
4768
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004769
4770 if (s_registerCalled == 0) {
4771 // Ignore RIL_onUnsolicitedResponse before RIL_register
Wink Saville8eb2a122012-11-19 16:05:13 -08004772 RLOGW("RIL_onUnsolicitedResponse called before RIL_register");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004773 return;
4774 }
Wink Saville7f856802009-06-09 10:23:37 -07004775
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004776 unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
4777
4778 if ((unsolResponseIndex < 0)
4779 || (unsolResponseIndex >= (int32_t)NUM_ELEMS(s_unsolResponses))) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004780 RLOGE("unsupported unsolicited response code %d", unsolResponse);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004781 return;
4782 }
4783
4784 // Grab a wake lock if needed for this reponse,
4785 // as we exit we'll either release it immediately
4786 // or set a timer to release it later.
4787 switch (s_unsolResponses[unsolResponseIndex].wakeType) {
4788 case WAKE_PARTIAL:
4789 grabPartialWakeLock();
4790 shouldScheduleTimeout = true;
4791 break;
4792
4793 case DONT_WAKE:
4794 default:
4795 // No wake lock is grabed so don't set timeout
4796 shouldScheduleTimeout = false;
4797 break;
4798 }
4799
4800 // Mark the time this was received, doing this
4801 // after grabing the wakelock incase getting
4802 // the elapsedRealTime might cause us to goto
4803 // sleep.
4804 if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4805 timeReceived = elapsedRealtime();
4806 }
4807
4808 appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
4809
4810 Parcel p;
4811
4812 p.writeInt32 (RESPONSE_UNSOLICITED);
4813 p.writeInt32 (unsolResponse);
4814
4815 ret = s_unsolResponses[unsolResponseIndex]
Bernhard Rosenkränzer6e7c1962013-12-12 10:01:10 +01004816 .responseFunction(p, const_cast<void*>(data), datalen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004817 if (ret != 0) {
4818 // Problem with the response. Don't continue;
4819 goto error_exit;
4820 }
4821
4822 // some things get more payload
4823 switch(unsolResponse) {
4824 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
Etan Cohend3652192014-06-20 08:28:44 -07004825 newState = processRadioState(CALL_ONSTATEREQUEST(soc_id), soc_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004826 p.writeInt32(newState);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004827 appendPrintBuf("%s {%s}", printBuf,
Etan Cohend3652192014-06-20 08:28:44 -07004828 radioStateToString(CALL_ONSTATEREQUEST(soc_id)));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004829 break;
4830
4831
4832 case RIL_UNSOL_NITZ_TIME_RECEIVED:
4833 // Store the time that this was received so the
4834 // handler of this message can account for
4835 // the time it takes to arrive and process. In
4836 // particular the system has been known to sleep
4837 // before this message can be processed.
4838 p.writeInt64(timeReceived);
4839 break;
4840 }
4841
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07004842#if VDBG
Etan Cohend3652192014-06-20 08:28:44 -07004843 RLOGI("%s UNSOLICITED: %s length:%d", rilSocketIdToString(soc_id), requestToString(unsolResponse), p.dataSize());
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07004844#endif
Etan Cohend3652192014-06-20 08:28:44 -07004845 ret = sendResponse(p, soc_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004846 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4847
4848 // Unfortunately, NITZ time is not poll/update like everything
4849 // else in the system. So, if the upstream client isn't connected,
4850 // keep a copy of the last NITZ response (with receive time noted
4851 // above) around so we can deliver it when it is connected
4852
4853 if (s_lastNITZTimeData != NULL) {
4854 free (s_lastNITZTimeData);
4855 s_lastNITZTimeData = NULL;
4856 }
4857
4858 s_lastNITZTimeData = malloc(p.dataSize());
4859 s_lastNITZTimeDataSize = p.dataSize();
4860 memcpy(s_lastNITZTimeData, p.data(), p.dataSize());
4861 }
4862
4863 // For now, we automatically go back to sleep after TIMEVAL_WAKE_TIMEOUT
4864 // FIXME The java code should handshake here to release wake lock
4865
4866 if (shouldScheduleTimeout) {
4867 // Cancel the previous request
4868 if (s_last_wake_timeout_info != NULL) {
4869 s_last_wake_timeout_info->userParam = (void *)1;
4870 }
4871
4872 s_last_wake_timeout_info
4873 = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
4874 &TIMEVAL_WAKE_TIMEOUT);
4875 }
4876
4877 // Normal exit
4878 return;
4879
4880error_exit:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004881 if (shouldScheduleTimeout) {
4882 releaseWakeLock();
4883 }
4884}
4885
Wink Saville7f856802009-06-09 10:23:37 -07004886/** FIXME generalize this if you track UserCAllbackInfo, clear it
4887 when the callback occurs
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004888*/
4889static UserCallbackInfo *
Wink Saville7f856802009-06-09 10:23:37 -07004890internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004891 const struct timeval *relativeTime)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004892{
4893 struct timeval myRelativeTime;
4894 UserCallbackInfo *p_info;
4895
4896 p_info = (UserCallbackInfo *) malloc (sizeof(UserCallbackInfo));
4897
Wink Saville7f856802009-06-09 10:23:37 -07004898 p_info->p_callback = callback;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004899 p_info->userParam = param;
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004900
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004901 if (relativeTime == NULL) {
4902 /* treat null parameter as a 0 relative time */
4903 memset (&myRelativeTime, 0, sizeof(myRelativeTime));
4904 } else {
4905 /* FIXME I think event_add's tv param is really const anyway */
4906 memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
4907 }
4908
4909 ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
4910
4911 ril_timer_add(&(p_info->event), &myRelativeTime);
4912
4913 triggerEvLoop();
4914 return p_info;
4915}
4916
Naveen Kalla7edd07c2010-06-21 18:54:47 -07004917
4918extern "C" void
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004919RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
4920 const struct timeval *relativeTime) {
4921 internalRequestTimedCallback (callback, param, relativeTime);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004922}
4923
4924const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004925failCauseToString(RIL_Errno e) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004926 switch(e) {
4927 case RIL_E_SUCCESS: return "E_SUCCESS";
Robert Greenwalt2126ab22013-04-09 12:20:45 -07004928 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RADIO_NOT_AVAILABLE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004929 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
4930 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
4931 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
4932 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
4933 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
4934 case RIL_E_CANCELLED: return "E_CANCELLED";
4935 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
4936 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
4937 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
Wink Savillef4c4d362009-04-02 01:37:03 -07004938 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
John Wang75534472010-04-20 15:11:42 -07004939 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
Wink Saville7f856802009-06-09 10:23:37 -07004940#ifdef FEATURE_MULTIMODE_ANDROID
Wink Savillef4c4d362009-04-02 01:37:03 -07004941 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
4942 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
4943#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004944 default: return "<unknown error>";
4945 }
4946}
4947
4948const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004949radioStateToString(RIL_RadioState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004950 switch(s) {
4951 case RADIO_STATE_OFF: return "RADIO_OFF";
4952 case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
4953 case RADIO_STATE_SIM_NOT_READY: return "RADIO_SIM_NOT_READY";
4954 case RADIO_STATE_SIM_LOCKED_OR_ABSENT: return "RADIO_SIM_LOCKED_OR_ABSENT";
4955 case RADIO_STATE_SIM_READY: return "RADIO_SIM_READY";
Wink Savillef4c4d362009-04-02 01:37:03 -07004956 case RADIO_STATE_RUIM_NOT_READY:return"RADIO_RUIM_NOT_READY";
4957 case RADIO_STATE_RUIM_READY:return"RADIO_RUIM_READY";
4958 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:return"RADIO_RUIM_LOCKED_OR_ABSENT";
4959 case RADIO_STATE_NV_NOT_READY:return"RADIO_NV_NOT_READY";
4960 case RADIO_STATE_NV_READY:return"RADIO_NV_READY";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004961 case RADIO_STATE_ON:return"RADIO_ON";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004962 default: return "<unknown state>";
4963 }
4964}
4965
4966const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004967callStateToString(RIL_CallState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004968 switch(s) {
4969 case RIL_CALL_ACTIVE : return "ACTIVE";
4970 case RIL_CALL_HOLDING: return "HOLDING";
4971 case RIL_CALL_DIALING: return "DIALING";
4972 case RIL_CALL_ALERTING: return "ALERTING";
4973 case RIL_CALL_INCOMING: return "INCOMING";
4974 case RIL_CALL_WAITING: return "WAITING";
4975 default: return "<unknown state>";
4976 }
4977}
4978
4979const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004980requestToString(int request) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004981/*
4982 cat libs/telephony/ril_commands.h \
4983 | egrep "^ *{RIL_" \
4984 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
4985
4986
4987 cat libs/telephony/ril_unsol_commands.h \
4988 | egrep "^ *{RIL_" \
4989 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
4990
4991*/
4992 switch(request) {
4993 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
4994 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
4995 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
4996 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
4997 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
4998 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
4999 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
5000 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
5001 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
5002 case RIL_REQUEST_DIAL: return "DIAL";
5003 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
5004 case RIL_REQUEST_HANGUP: return "HANGUP";
5005 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
5006 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
5007 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
5008 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
5009 case RIL_REQUEST_UDUB: return "UDUB";
5010 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
5011 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
Wink Savillec0114b32011-02-18 10:14:07 -08005012 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
5013 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005014 case RIL_REQUEST_OPERATOR: return "OPERATOR";
5015 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
5016 case RIL_REQUEST_DTMF: return "DTMF";
5017 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
5018 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
Wink Savillef4c4d362009-04-02 01:37:03 -07005019 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005020 case RIL_REQUEST_SIM_IO: return "SIM_IO";
5021 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
5022 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
5023 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
5024 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
5025 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
5026 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
5027 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
5028 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
5029 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
5030 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
5031 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
5032 case RIL_REQUEST_ANSWER: return "ANSWER";
Wink Savillef4c4d362009-04-02 01:37:03 -07005033 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005034 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
5035 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
5036 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
5037 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
5038 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
5039 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
5040 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";
5041 case RIL_REQUEST_DTMF_START: return "DTMF_START";
5042 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
5043 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
5044 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
5045 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
5046 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
5047 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
5048 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
5049 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
5050 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
Wink Savillef4c4d362009-04-02 01:37:03 -07005051 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
5052 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005053 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
5054 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
5055 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
Wink Savillef4c4d362009-04-02 01:37:03 -07005056 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
5057 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005058 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
5059 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
5060 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
5061 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
5062 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
5063 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
5064 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
5065 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
Wink Savillec0114b32011-02-18 10:14:07 -08005066 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE:return"CDMA_SET_SUBSCRIPTION_SOURCE";
Wink Savillef4c4d362009-04-02 01:37:03 -07005067 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"CDMA_SET_ROAMING_PREFERENCE";
5068 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"CDMA_QUERY_ROAMING_PREFERENCE";
5069 case RIL_REQUEST_SET_TTY_MODE:return"SET_TTY_MODE";
5070 case RIL_REQUEST_QUERY_TTY_MODE:return"QUERY_TTY_MODE";
5071 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
5072 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
5073 case RIL_REQUEST_CDMA_FLASH:return"CDMA_FLASH";
5074 case RIL_REQUEST_CDMA_BURST_DTMF:return"CDMA_BURST_DTMF";
5075 case RIL_REQUEST_CDMA_SEND_SMS:return"CDMA_SEND_SMS";
5076 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:return"CDMA_SMS_ACKNOWLEDGE";
Wink Savillea592eeb2009-05-22 13:26:36 -07005077 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG:return"GSM_GET_BROADCAST_SMS_CONFIG";
5078 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG:return"GSM_SET_BROADCAST_SMS_CONFIG";
5079 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG:return "CDMA_GET_BROADCAST_SMS_CONFIG";
5080 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG:return "CDMA_SET_BROADCAST_SMS_CONFIG";
5081 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION:return "CDMA_SMS_BROADCAST_ACTIVATION";
Naveen Kalla03c1edf2009-09-23 11:18:35 -07005082 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return"CDMA_VALIDATE_AND_WRITE_AKEY";
Wink Savillef4c4d362009-04-02 01:37:03 -07005083 case RIL_REQUEST_CDMA_SUBSCRIPTION: return"CDMA_SUBSCRIPTION";
5084 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
5085 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
5086 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
jsh000a9fe2009-05-11 14:52:35 -07005087 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
5088 case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
5089 case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
jsh09a68ba2009-06-10 11:56:38 -07005090 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
jsh563fd722010-06-08 16:52:24 -07005091 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
Wink Savillec0114b32011-02-18 10:14:07 -08005092 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
Jake Hambyfa8d5842011-08-19 16:22:18 -07005093 case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
Jake Hamby300105d2011-09-26 01:01:44 -07005094 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
5095 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005096 case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
Wink Saville8a9e0212013-04-09 12:11:38 -07005097 case RIL_REQUEST_GET_CELL_INFO_LIST: return"GET_CELL_INFO_LIST";
5098 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return"SET_UNSOL_CELL_INFO_LIST_RATE";
Sungmin Choi75697532013-04-26 15:04:45 -07005099 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "RIL_REQUEST_SET_INITIAL_ATTACH_APN";
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07005100 case RIL_REQUEST_IMS_REGISTRATION_STATE: return "IMS_REGISTRATION_STATE";
5101 case RIL_REQUEST_IMS_SEND_SMS: return "IMS_SEND_SMS";
Shishir Agrawal2458d8d2013-11-27 14:53:05 -08005102 case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "SIM_TRANSMIT_APDU_BASIC";
5103 case RIL_REQUEST_SIM_OPEN_CHANNEL: return "SIM_OPEN_CHANNEL";
5104 case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "SIM_CLOSE_CHANNEL";
5105 case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "SIM_TRANSMIT_APDU_CHANNEL";
Wink Saville8b4e4f72014-10-17 15:01:45 -07005106 case RIL_REQUEST_GET_RADIO_CAPABILITY: return "RIL_REQUEST_GET_RADIO_CAPABILITY";
5107 case RIL_REQUEST_SET_RADIO_CAPABILITY: return "RIL_REQUEST_SET_RADIO_CAPABILITY";
Etan Cohend3652192014-06-20 08:28:44 -07005108 case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "SET_UICC_SUBSCRIPTION";
5109 case RIL_REQUEST_ALLOW_DATA: return "ALLOW_DATA";
Amit Mahajan2b772032014-06-26 14:20:11 -07005110 case RIL_REQUEST_GET_HARDWARE_CONFIG: return "GET_HARDWARE_CONFIG";
5111 case RIL_REQUEST_SIM_AUTHENTICATION: return "SIM_AUTHENTICATION";
Wink Savillec29360a2014-07-13 05:17:28 -07005112 case RIL_REQUEST_GET_DC_RT_INFO: return "GET_DC_RT_INFO";
5113 case RIL_REQUEST_SET_DC_RT_INFO_RATE: return "SET_DC_RT_INFO_RATE";
Amit Mahajanc796e222014-08-13 16:54:01 +00005114 case RIL_REQUEST_SET_DATA_PROFILE: return "SET_DATA_PROFILE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005115 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
5116 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08005117 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 -08005118 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
5119 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
5120 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
5121 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
5122 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)";
5123 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
5124 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
5125 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
5126 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
5127 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
5128 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
5129 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL";
5130 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
Wink Savillef4c4d362009-04-02 01:37:03 -07005131 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005132 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
Wink Savillef4c4d362009-04-02 01:37:03 -07005133 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
5134 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_NEW_CDMA_SMS";
5135 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_NEW_BROADCAST_SMS";
5136 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
Wink Saville3d54e742009-05-18 18:00:44 -07005137 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
5138 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
5139 case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
5140 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
5141 case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
Jaikumar Ganeshaf6ecbf2009-04-29 13:27:51 -07005142 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
John Wang5d621da2009-09-18 17:17:48 -07005143 case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
John Wang5909cf82010-01-29 00:18:54 -08005144 case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
Wink Savilleee274582011-04-16 15:05:49 -07005145 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08005146 case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
5147 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
Wink Saville5b9df332011-04-06 16:24:21 -07005148 case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005149 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
Wink Saville8a9e0212013-04-09 12:11:38 -07005150 case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07005151 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "RESPONSE_IMS_NETWORK_STATE_CHANGED";
Etan Cohend3652192014-06-20 08:28:44 -07005152 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return "UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED";
5153 case RIL_UNSOL_SRVCC_STATE_NOTIFY: return "UNSOL_SRVCC_STATE_NOTIFY";
5154 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return "HARDWARE_CONFIG_CHANGED";
Wink Savillec29360a2014-07-13 05:17:28 -07005155 case RIL_UNSOL_DC_RT_INFO_CHANGED: return "UNSOL_DC_RT_INFO_CHANGED";
Naveen Kallaa65a16a2014-07-31 16:48:31 -07005156 case RIL_REQUEST_SHUTDOWN: return "SHUTDOWN";
Wink Saville8b4e4f72014-10-17 15:01:45 -07005157 case RIL_UNSOL_RADIO_CAPABILITY: return "RIL_UNSOL_RADIO_CAPABILITY";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005158 default: return "<unknown request>";
5159 }
5160}
5161
Etan Cohend3652192014-06-20 08:28:44 -07005162const char *
5163rilSocketIdToString(RIL_SOCKET_ID socket_id)
5164{
5165 switch(socket_id) {
5166 case RIL_SOCKET_1:
5167 return "RIL_SOCKET_1";
5168#if (SIM_COUNT >= 2)
5169 case RIL_SOCKET_2:
5170 return "RIL_SOCKET_2";
5171#endif
5172#if (SIM_COUNT >= 3)
5173 case RIL_SOCKET_3:
5174 return "RIL_SOCKET_3";
5175#endif
5176#if (SIM_COUNT >= 4)
5177 case RIL_SOCKET_4:
5178 return "RIL_SOCKET_4";
5179#endif
5180 default:
5181 return "not a valid RIL";
5182 }
5183}
5184
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005185} /* namespace android */
Dheeraj Shetty27976c42014-07-02 21:27:57 +02005186
5187void rilEventAddWakeup_helper(struct ril_event *ev) {
5188 android::rilEventAddWakeup(ev);
5189}
5190
5191void listenCallback_helper(int fd, short flags, void *param) {
5192 android::listenCallback(fd, flags, param);
5193}
5194
5195int blockingWrite_helper(int fd, void *buffer, size_t len) {
5196 return android::blockingWrite(fd, buffer, len);
5197}